diff --git a/src/graphics/gl_headers.hpp b/src/graphics/gl_headers.hpp new file mode 100644 index 000000000..21d092693 --- /dev/null +++ b/src/graphics/gl_headers.hpp @@ -0,0 +1,115 @@ +#ifndef GL_HEADER_HPP +#define GL_HEADER_HPP + +#if defined(__APPLE__) +# include +# include +# define OGL32CTX +# ifdef GL_ARB_instanced_arrays +# define glVertexAttribDivisor glVertexAttribDivisorARB +# endif +# ifndef GL_TEXTURE_SWIZZLE_RGBA +# define GL_TEXTURE_SWIZZLE_RGBA 0x8E46 +# endif +#elif defined(ANDROID) +# include +#elif defined(WIN32) +# define _WINSOCKAPI_ +// has to be included before gl.h because of WINGDIAPI and APIENTRY definitions +# include +# include +# include "../../lib/irrlicht/source/Irrlicht/glext.h" +#else +#define GL_GLEXT_PROTOTYPES +#define DEBUG_OUTPUT_DECLARED +# include +# include +#endif + +#ifdef WIN32 +extern PFNGLGENTRANSFORMFEEDBACKSPROC glGenTransformFeedbacks; +extern PFNGLBINDTRANSFORMFEEDBACKPROC glBindTransformFeedback; +extern PFNGLDRAWTRANSFORMFEEDBACKPROC glDrawTransformFeedback; +extern PFNGLBEGINTRANSFORMFEEDBACKPROC glBeginTransformFeedback; +extern PFNGLENDTRANSFORMFEEDBACKPROC glEndTransformFeedback; +extern PFNGLTRANSFORMFEEDBACKVARYINGSPROC glTransformFeedbackVaryings; +extern PFNGLBINDBUFFERBASEPROC glBindBufferBase; +extern PFNGLGENBUFFERSPROC glGenBuffers; +extern PFNGLBINDBUFFERPROC glBindBuffer; +extern PFNGLBUFFERDATAPROC glBufferData; +extern PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer; +extern PFNGLCREATESHADERPROC glCreateShader; +extern PFNGLCOMPILESHADERPROC glCompileShader; +extern PFNGLSHADERSOURCEPROC glShaderSource; +extern PFNGLCREATEPROGRAMPROC glCreateProgram; +extern PFNGLATTACHSHADERPROC glAttachShader; +extern PFNGLLINKPROGRAMPROC glLinkProgram; +extern PFNGLUSEPROGRAMPROC glUseProgram; +extern PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray; +extern PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray; +extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; +extern PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv; +extern PFNGLUNIFORM1FPROC glUniform1f; +extern PFNGLUNIFORM3FPROC glUniform3f; +extern PFNGLUNIFORM1FVPROC glUniform1fv; +extern PFNGLUNIFORM4FVPROC glUniform4fv; +extern PFNGLDELETESHADERPROC glDeleteShader; +extern PFNGLGETSHADERIVPROC glGetShaderiv; +extern PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; +extern PFNGLACTIVETEXTUREPROC glActiveTexture; +extern PFNGLUNIFORM2FPROC glUniform2f; +extern PFNGLUNIFORM1IPROC glUniform1i; +extern PFNGLUNIFORM3IPROC glUniform3i; +extern PFNGLUNIFORM4IPROC glUniform4i; +extern PFNGLGETPROGRAMIVPROC glGetProgramiv; +extern PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; +extern PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation; +extern PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation; +extern PFNGLBLENDEQUATIONPROC glBlendEquation; +extern PFNGLVERTEXATTRIBDIVISORPROC glVertexAttribDivisor; +extern PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced; +extern PFNGLDRAWELEMENTSBASEVERTEXPROC glDrawElementsBaseVertex; +extern PFNGLDRAWELEMENTSINSTANCEDPROC glDrawElementsInstanced; +extern PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC glDrawElementsInstancedBaseVertex; +extern PFNGLDELETEBUFFERSPROC glDeleteBuffers; +extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays; +extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray; +extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; +extern PFNGLTEXBUFFERPROC glTexBuffer; +extern PFNGLBUFFERSUBDATAPROC glBufferSubData; +extern PFNGLMAPBUFFERPROC glMapBuffer; +extern PFNGLMAPBUFFERRANGEPROC glMapBufferRange; +extern PFNGLUNMAPBUFFERPROC glUnmapBuffer; +extern PFNGLFENCESYNCPROC glFenceSync; +extern PFNGLCLIENTWAITSYNCPROC glClientWaitSync; +extern PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer; +extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; +extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers; +extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; +extern PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; +extern PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture; +extern PFNGLTEXIMAGE3DPROC glTexImage3D; +extern PFNGLGENERATEMIPMAPPROC glGenerateMipmap; +extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; +extern PFNGLTEXIMAGE2DMULTISAMPLEPROC glTexImage2DMultisample; +extern PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer; +extern PFNGLGETUNIFORMBLOCKINDEXPROC glGetUniformBlockIndex; +extern PFNGLUNIFORMBLOCKBINDINGPROC glUniformBlockBinding; +extern PFNGLBLENDCOLORPROC glBlendColor; +extern PFNGLCOMPRESSEDTEXIMAGE2DPROC glCompressedTexImage2D; +extern PFNGLGETCOMPRESSEDTEXIMAGEPROC glGetCompressedTexImage; +extern PFNGLTEXSTORAGE1DPROC glTexStorage1D; +extern PFNGLTEXSTORAGE2DPROC glTexStorage2D; +extern PFNGLTEXSTORAGE3DPROC glTexStorage3D; +extern PFNGLBINDIMAGETEXTUREPROC glBindImageTexture; +extern PFNGLDISPATCHCOMPUTEPROC glDispatchCompute; +extern PFNGLGENSAMPLERSPROC glGenSamplers; +extern PFNGLBINDSAMPLERPROC glBindSampler; +extern PFNGLSAMPLERPARAMETERFPROC glSamplerParameterf; +extern PFNGLSAMPLERPARAMETERIPROC glSamplerParameteri; +#ifdef DEBUG +extern PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARB; +#endif +#endif + +#endif \ No newline at end of file diff --git a/src/graphics/glwrap.hpp b/src/graphics/glwrap.hpp index 9c63f79f2..dea33ae85 100644 --- a/src/graphics/glwrap.hpp +++ b/src/graphics/glwrap.hpp @@ -1,28 +1,7 @@ #ifndef GLWRAP_HEADER_H #define GLWRAP_HEADER_H -#if defined(__APPLE__) -# include -# include -# define OGL32CTX -# ifdef GL_ARB_instanced_arrays -# define glVertexAttribDivisor glVertexAttribDivisorARB -# endif -# ifndef GL_TEXTURE_SWIZZLE_RGBA -# define GL_TEXTURE_SWIZZLE_RGBA 0x8E46 -# endif -#elif defined(ANDROID) -# include -#elif defined(WIN32) -# define _WINSOCKAPI_ -// has to be included before gl.h because of WINGDIAPI and APIENTRY definitions -# include -# include -#else -#define GL_GLEXT_PROTOTYPES -#define DEBUG_OUTPUT_DECLARED -# include -#endif +#include "gl_headers.hpp" #include #include "irr_driver.hpp" @@ -31,91 +10,6 @@ // already includes glext.h, which defines useful GL constants. // COpenGLDriver has already loaded the extension GL functions we use (e.g glBeginQuery) #include "../../lib/irrlicht/source/Irrlicht/COpenGLDriver.h" -#ifdef WIN32 -extern PFNGLGENTRANSFORMFEEDBACKSPROC glGenTransformFeedbacks; -extern PFNGLBINDTRANSFORMFEEDBACKPROC glBindTransformFeedback; -extern PFNGLDRAWTRANSFORMFEEDBACKPROC glDrawTransformFeedback; -extern PFNGLBEGINTRANSFORMFEEDBACKPROC glBeginTransformFeedback; -extern PFNGLENDTRANSFORMFEEDBACKPROC glEndTransformFeedback; -extern PFNGLTRANSFORMFEEDBACKVARYINGSPROC glTransformFeedbackVaryings; -extern PFNGLBINDBUFFERBASEPROC glBindBufferBase; -extern PFNGLGENBUFFERSPROC glGenBuffers; -extern PFNGLBINDBUFFERPROC glBindBuffer; -extern PFNGLBUFFERDATAPROC glBufferData; -extern PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer; -extern PFNGLCREATESHADERPROC glCreateShader; -extern PFNGLCOMPILESHADERPROC glCompileShader; -extern PFNGLSHADERSOURCEPROC glShaderSource; -extern PFNGLCREATEPROGRAMPROC glCreateProgram; -extern PFNGLATTACHSHADERPROC glAttachShader; -extern PFNGLLINKPROGRAMPROC glLinkProgram; -extern PFNGLUSEPROGRAMPROC glUseProgram; -extern PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray; -extern PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray; -extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation; -extern PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv; -extern PFNGLUNIFORM1FPROC glUniform1f; -extern PFNGLUNIFORM3FPROC glUniform3f; -extern PFNGLUNIFORM1FVPROC glUniform1fv; -extern PFNGLUNIFORM4FVPROC glUniform4fv; -extern PFNGLDELETESHADERPROC glDeleteShader; -extern PFNGLGETSHADERIVPROC glGetShaderiv; -extern PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog; -extern PFNGLACTIVETEXTUREPROC glActiveTexture; -extern PFNGLUNIFORM2FPROC glUniform2f; -extern PFNGLUNIFORM1IPROC glUniform1i; -extern PFNGLUNIFORM3IPROC glUniform3i; -extern PFNGLUNIFORM4IPROC glUniform4i; -extern PFNGLGETPROGRAMIVPROC glGetProgramiv; -extern PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog; -extern PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation; -extern PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation; -extern PFNGLBLENDEQUATIONPROC glBlendEquation; -extern PFNGLVERTEXATTRIBDIVISORPROC glVertexAttribDivisor; -extern PFNGLDRAWARRAYSINSTANCEDPROC glDrawArraysInstanced; -extern PFNGLDRAWELEMENTSBASEVERTEXPROC glDrawElementsBaseVertex; -extern PFNGLDRAWELEMENTSINSTANCEDPROC glDrawElementsInstanced; -extern PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC glDrawElementsInstancedBaseVertex; -extern PFNGLDELETEBUFFERSPROC glDeleteBuffers; -extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays; -extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray; -extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; -extern PFNGLTEXBUFFERPROC glTexBuffer; -extern PFNGLBUFFERSUBDATAPROC glBufferSubData; -extern PFNGLMAPBUFFERPROC glMapBuffer; -extern PFNGLMAPBUFFERRANGEPROC glMapBufferRange; -extern PFNGLUNMAPBUFFERPROC glUnmapBuffer; -extern PFNGLFENCESYNCPROC glFenceSync; -extern PFNGLCLIENTWAITSYNCPROC glClientWaitSync; -extern PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer; -extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; -extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers; -extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; -extern PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; -extern PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture; -extern PFNGLTEXIMAGE3DPROC glTexImage3D; -extern PFNGLGENERATEMIPMAPPROC glGenerateMipmap; -extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; -extern PFNGLTEXIMAGE2DMULTISAMPLEPROC glTexImage2DMultisample; -extern PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer; -extern PFNGLGETUNIFORMBLOCKINDEXPROC glGetUniformBlockIndex; -extern PFNGLUNIFORMBLOCKBINDINGPROC glUniformBlockBinding; -extern PFNGLBLENDCOLORPROC glBlendColor; -extern PFNGLCOMPRESSEDTEXIMAGE2DPROC glCompressedTexImage2D; -extern PFNGLGETCOMPRESSEDTEXIMAGEPROC glGetCompressedTexImage; -extern PFNGLTEXSTORAGE1DPROC glTexStorage1D; -extern PFNGLTEXSTORAGE2DPROC glTexStorage2D; -extern PFNGLTEXSTORAGE3DPROC glTexStorage3D; -extern PFNGLBINDIMAGETEXTUREPROC glBindImageTexture; -extern PFNGLDISPATCHCOMPUTEPROC glDispatchCompute; -extern PFNGLGENSAMPLERSPROC glGenSamplers; -extern PFNGLBINDSAMPLERPROC glBindSampler; -extern PFNGLSAMPLERPARAMETERFPROC glSamplerParameterf; -extern PFNGLSAMPLERPARAMETERIPROC glSamplerParameteri; -#ifdef DEBUG -extern PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARB; -#endif -#endif void initGL(); diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index deafb7575..e572257ee 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -600,6 +600,11 @@ bool needsUBO() return irr_driver->needUBOWorkaround(); } +unsigned getGLSLVersion() +{ + return irr_driver->getGLSLVersion(); +} + namespace MeshShader { // Solid Normal and depth pass shaders diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 3f9babc24..7c60455ee 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -23,7 +23,8 @@ #include "config/user_config.hpp" #include "utils/singleton.hpp" -typedef unsigned int GLuint; +#include "gl_headers.hpp" + using namespace irr; class ParticleSystemProxy; @@ -51,14 +52,10 @@ public: }; } -void glUniformMatrix4fvWraper(GLuint, size_t, unsigned, const float *mat); -void glUniform3fWraper(GLuint, float, float, float); -void glUniform4iWraper(GLuint, int, int, int, int); -void glUniform2fWraper(GLuint a, float b, float c); -void glUniform1fWrapper(GLuint, float); -void glUniform1iWrapper(GLuint, int); bool needsUBO(); +unsigned getGLSLVersion(); + struct UniformHelper { template @@ -69,31 +66,28 @@ struct UniformHelper template static void setUniformsHelper(const std::vector &uniforms, const core::matrix4 &mat, Args... arg) { -#ifndef GL_FALSE -#define GL_FALSE 0 -#endif - glUniformMatrix4fvWraper(uniforms[N], 1, GL_FALSE, mat.pointer()); + glUniformMatrix4fv(uniforms[N], 1, GL_FALSE, mat.pointer()); setUniformsHelper(uniforms, arg...); } template static void setUniformsHelper(const std::vector &uniforms, const video::SColorf &col, Args... arg) { - glUniform3fWraper(uniforms[N], col.r, col.g, col.b); + glUniform3f(uniforms[N], col.r, col.g, col.b); setUniformsHelper(uniforms, arg...); } template static void setUniformsHelper(const std::vector &uniforms, const video::SColor &col, Args... arg) { - glUniform4iWraper(uniforms[N], col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha()); + glUniform4i(uniforms[N], col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha()); setUniformsHelper(uniforms, arg...); } template static void setUniformsHelper(const std::vector &uniforms, const core::vector3df &v, Args... arg) { - glUniform3fWraper(uniforms[N], v.X, v.Y, v.Z); + glUniform3f(uniforms[N], v.X, v.Y, v.Z); setUniformsHelper(uniforms, arg...); } @@ -101,35 +95,34 @@ struct UniformHelper template static void setUniformsHelper(const std::vector &uniforms, const core::vector2df &v, Args... arg) { - glUniform2fWraper(uniforms[N], v.X, v.Y); + glUniform2f(uniforms[N], v.X, v.Y); setUniformsHelper(uniforms, arg...); } template static void setUniformsHelper(const std::vector &uniforms, const core::dimension2df &v, Args... arg) { - glUniform2fWraper(uniforms[N], v.Width, v.Height); + glUniform2f(uniforms[N], v.Width, v.Height); setUniformsHelper(uniforms, arg...); } template static void setUniformsHelper(const std::vector &uniforms, float f, Args... arg) { - glUniform1fWrapper(uniforms[N], f); + glUniform1f(uniforms[N], f); setUniformsHelper(uniforms, arg...); } template static void setUniformsHelper(const std::vector &uniforms, int f, Args... arg) { - glUniform1iWrapper(uniforms[N], f); + glUniform1i(uniforms[N], f); setUniformsHelper(uniforms, arg...); } }; void bypassUBO(GLuint Program); -GLuint getUniformLocation(GLuint program, const char* name); template class ShaderHelperSingleton : public Singleton