diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index 15d6043f5..9e45f415d 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -412,8 +412,8 @@ bool CIrrDeviceSDL::createWindow() break; case video::EDT_OPENGL3: SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); break; case video::EDT_OGLES1: SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1); diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index d404735f3..c8054520f 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -272,7 +272,7 @@ endif() if(ENABLE_GLES2) find_package(OpenGLES2 REQUIRED) endif() -if(ENABLE_OPENGL OR ENABLE_OPENGL3) +if(ENABLE_OPENGL) find_package(OpenGL REQUIRED) endif() if(USE_SDL2) @@ -320,7 +320,7 @@ set(link_libs "${PNG_LIBRARY}" "$<$:${SDL2_LIBRARIES}>" - ${OPENGL_LIBRARIES} + "$<$:${OPENGL_LIBRARIES}>" ${OPENGLES_LIBRARY} ${OPENGLES2_LIBRARIES} ${EGL_LIBRARY} diff --git a/source/Irrlicht/COGLESCoreExtensionHandler.h b/source/Irrlicht/COGLESCoreExtensionHandler.h index 1b4a2bb3b..4f897483a 100644 --- a/source/Irrlicht/COGLESCoreExtensionHandler.h +++ b/source/Irrlicht/COGLESCoreExtensionHandler.h @@ -10,6 +10,8 @@ #include "irrMath.h" #include "COpenGLCoreFeature.h" +#include + namespace irr { namespace video @@ -697,7 +699,7 @@ namespace video Version = 0; s32 multiplier = 100; - core::stringc version(glGetString(GL_VERSION)); + core::stringc version(GL.GetString(GL.VERSION)); for (u32 i = 0; i < version.size(); ++i) { @@ -718,7 +720,7 @@ namespace video void getGLExtensions() { - core::stringc extensions = glGetString(GL_EXTENSIONS); + core::stringc extensions = GL.GetString(GL.EXTENSIONS); os::Printer::log(extensions.c_str()); // typo in the simulator (note the postfixed s) diff --git a/source/Irrlicht/COpenGLCoreCacheHandler.h b/source/Irrlicht/COpenGLCoreCacheHandler.h index 85054832e..7cf56ec56 100644 --- a/source/Irrlicht/COpenGLCoreCacheHandler.h +++ b/source/Irrlicht/COpenGLCoreCacheHandler.h @@ -64,14 +64,14 @@ class COpenGLCoreCacheHandler if (index < MATERIAL_MAX_TEXTURES && index < TextureCount) { if ( esa == EST_ACTIVE_ALWAYS ) - CacheHandler.setActiveTexture(GL_TEXTURE0 + index); + CacheHandler.setActiveTexture(GL.TEXTURE0 + index); const TOpenGLTexture* prevTexture = Texture[index]; if (texture != prevTexture) { if ( esa == EST_ACTIVE_ON_CHANGE ) - CacheHandler.setActiveTexture(GL_TEXTURE0 + index); + CacheHandler.setActiveTexture(GL.TEXTURE0 + index); if (texture) { @@ -82,24 +82,24 @@ class COpenGLCoreCacheHandler texture->grab(); const TOpenGLTexture* curTexture = static_cast(texture); - const GLenum curTextureType = curTexture->getOpenGLTextureType(); - const GLenum prevTextureType = (prevTexture) ? prevTexture->getOpenGLTextureType() : curTextureType; + const unsigned int curTextureType = curTexture->getOpenGLTextureType(); + const unsigned int prevTextureType = (prevTexture) ? prevTexture->getOpenGLTextureType() : curTextureType; if (curTextureType != prevTextureType) { - glBindTexture(prevTextureType, 0); + GL.BindTexture(prevTextureType, 0); #if ( defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON) ) - glDisable(prevTextureType); - glEnable(curTextureType); + GL.Disable(prevTextureType); + GL.Enable(curTextureType); #endif } #if ( defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON) ) else if (!prevTexture) - glEnable(curTextureType); + GL.Enable(curTextureType); #endif - glBindTexture(curTextureType, static_cast(texture)->getOpenGLTextureName()); + GL.BindTexture(curTextureType, static_cast(texture)->getOpenGLTextureName()); } else { @@ -113,12 +113,12 @@ class COpenGLCoreCacheHandler if (!texture && prevTexture) { - const GLenum prevTextureType = prevTexture->getOpenGLTextureType(); + const unsigned int prevTextureType = prevTexture->getOpenGLTextureType(); - glBindTexture(prevTextureType, 0); + GL.BindTexture(prevTextureType, 0); #if ( defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON) ) - glDisable(prevTextureType); + GL.Disable(prevTextureType); #endif } @@ -187,18 +187,18 @@ class COpenGLCoreCacheHandler #endif FrameBufferCount(0), BlendEquation(0), BlendSourceRGB(0), BlendDestinationRGB(0), BlendSourceAlpha(0), BlendDestinationAlpha(0), Blend(0), BlendEquationInvalid(false), BlendFuncInvalid(false), BlendInvalid(false), - ColorMask(0), ColorMaskInvalid(false), CullFaceMode(GL_BACK), CullFace(false), DepthFunc(GL_LESS), DepthMask(true), DepthTest(false), FrameBufferID(0), - ProgramID(0), ActiveTexture(GL_TEXTURE0), ViewportX(0), ViewportY(0) + ColorMask(0), ColorMaskInvalid(false), CullFaceMode(GL.BACK), CullFace(false), DepthFunc(GL.LESS), DepthMask(true), DepthTest(false), FrameBufferID(0), + ProgramID(0), ActiveTexture(GL.TEXTURE0), ViewportX(0), ViewportY(0) { const COpenGLCoreFeature& feature = Driver->getFeature(); - FrameBufferCount = core::max_(static_cast(1), static_cast(feature.MultipleRenderTarget)); + FrameBufferCount = core::max_(static_cast(1), static_cast(feature.MultipleRenderTarget)); - BlendEquation = new GLenum[FrameBufferCount]; - BlendSourceRGB = new GLenum[FrameBufferCount]; - BlendDestinationRGB = new GLenum[FrameBufferCount]; - BlendSourceAlpha = new GLenum[FrameBufferCount]; - BlendDestinationAlpha = new GLenum[FrameBufferCount]; + BlendEquation = new unsigned int[FrameBufferCount]; + BlendSourceRGB = new unsigned int[FrameBufferCount]; + BlendDestinationRGB = new unsigned int[FrameBufferCount]; + BlendSourceAlpha = new unsigned int[FrameBufferCount]; + BlendDestinationAlpha = new unsigned int[FrameBufferCount]; Blend = new bool[FrameBufferCount]; ColorMask = new u8[FrameBufferCount]; @@ -206,44 +206,44 @@ class COpenGLCoreCacheHandler if (feature.BlendOperation) { - Driver->irrGlBlendEquation(GL_FUNC_ADD); + Driver->irrGlBlendEquation(GL.FUNC_ADD); } for (u32 i = 0; i < FrameBufferCount; ++i) { - BlendEquation[i] = GL_FUNC_ADD; + BlendEquation[i] = GL.FUNC_ADD; - BlendSourceRGB[i] = GL_ONE; - BlendDestinationRGB[i] = GL_ZERO; - BlendSourceAlpha[i] = GL_ONE; - BlendDestinationAlpha[i] = GL_ZERO; + BlendSourceRGB[i] = GL.ONE; + BlendDestinationRGB[i] = GL.ZERO; + BlendSourceAlpha[i] = GL.ONE; + BlendDestinationAlpha[i] = GL.ZERO; Blend[i] = false; ColorMask[i] = ECP_ALL; } - glBlendFunc(GL_ONE, GL_ZERO); - glDisable(GL_BLEND); + GL.BlendFunc(GL.ONE, GL.ZERO); + GL.Disable(GL.BLEND); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + GL.ColorMask(true, true, true, true); - glCullFace(CullFaceMode); - glDisable(GL_CULL_FACE); + GL.CullFace(CullFaceMode); + GL.Disable(GL.CULL_FACE); - glDepthFunc(DepthFunc); - glDepthMask(GL_TRUE); - glDisable(GL_DEPTH_TEST); + GL.DepthFunc(DepthFunc); + GL.DepthMask(true); + GL.Disable(GL.DEPTH_TEST); Driver->irrGlActiveTexture(ActiveTexture); #if ( defined(IRR_COMPILE_GL_COMMON) || defined(IRR_COMPILE_GLES_COMMON) ) - glDisable(GL_TEXTURE_2D); + GL.Disable(GL.TEXTURE_2D); #endif const core::dimension2d ScreenSize = Driver->getScreenSize(); ViewportWidth = ScreenSize.Width; ViewportHeight = ScreenSize.Height; - glViewport(ViewportX, ViewportY, ViewportWidth, ViewportHeight); + GL.Viewport(ViewportX, ViewportY, ViewportWidth, ViewportHeight); } virtual ~COpenGLCoreCacheHandler() @@ -270,20 +270,20 @@ class COpenGLCoreCacheHandler // Blending calls. - void setBlendEquation(GLenum mode) + void setBlendEquation(unsigned int mode) { if (BlendEquation[0] != mode || BlendEquationInvalid) { Driver->irrGlBlendEquation(mode); - for (GLuint i = 0; i < FrameBufferCount; ++i) + for (unsigned int i = 0; i < FrameBufferCount; ++i) BlendEquation[i] = mode; BlendEquationInvalid = false; } } - void setBlendEquationIndexed(GLuint index, GLenum mode) + void setBlendEquationIndexed(unsigned int index, unsigned int mode) { if (index < FrameBufferCount && BlendEquation[index] != mode) { @@ -294,15 +294,15 @@ class COpenGLCoreCacheHandler } } - void setBlendFunc(GLenum source, GLenum destination) + void setBlendFunc(unsigned int source, unsigned int destination) { if (BlendSourceRGB[0] != source || BlendDestinationRGB[0] != destination || BlendSourceAlpha[0] != source || BlendDestinationAlpha[0] != destination || BlendFuncInvalid) { - glBlendFunc(source, destination); + GL.BlendFunc(source, destination); - for (GLuint i = 0; i < FrameBufferCount; ++i) + for (unsigned int i = 0; i < FrameBufferCount; ++i) { BlendSourceRGB[i] = source; BlendDestinationRGB[i] = destination; @@ -314,7 +314,7 @@ class COpenGLCoreCacheHandler } } - void setBlendFuncSeparate(GLenum sourceRGB, GLenum destinationRGB, GLenum sourceAlpha, GLenum destinationAlpha) + void setBlendFuncSeparate(unsigned int sourceRGB, unsigned int destinationRGB, unsigned int sourceAlpha, unsigned int destinationAlpha) { if (sourceRGB != sourceAlpha || destinationRGB != destinationAlpha) { @@ -324,7 +324,7 @@ class COpenGLCoreCacheHandler { Driver->irrGlBlendFuncSeparate(sourceRGB, destinationRGB, sourceAlpha, destinationAlpha); - for (GLuint i = 0; i < FrameBufferCount; ++i) + for (unsigned int i = 0; i < FrameBufferCount; ++i) { BlendSourceRGB[i] = sourceRGB; BlendDestinationRGB[i] = destinationRGB; @@ -341,7 +341,7 @@ class COpenGLCoreCacheHandler } } - void setBlendFuncIndexed(GLuint index, GLenum source, GLenum destination) + void setBlendFuncIndexed(unsigned int index, unsigned int source, unsigned int destination) { if (index < FrameBufferCount && (BlendSourceRGB[index] != source || BlendDestinationRGB[index] != destination || BlendSourceAlpha[index] != source || BlendDestinationAlpha[index] != destination)) @@ -356,7 +356,7 @@ class COpenGLCoreCacheHandler } } - void setBlendFuncSeparateIndexed(GLuint index, GLenum sourceRGB, GLenum destinationRGB, GLenum sourceAlpha, GLenum destinationAlpha) + void setBlendFuncSeparateIndexed(unsigned int index, unsigned int sourceRGB, unsigned int destinationRGB, unsigned int sourceAlpha, unsigned int destinationAlpha) { if (sourceRGB != sourceAlpha || destinationRGB != destinationAlpha) { @@ -383,25 +383,25 @@ class COpenGLCoreCacheHandler if (Blend[0] != enable || BlendInvalid) { if (enable) - glEnable(GL_BLEND); + GL.Enable(GL.BLEND); else - glDisable(GL_BLEND); + GL.Disable(GL.BLEND); - for (GLuint i = 0; i < FrameBufferCount; ++i) + for (unsigned int i = 0; i < FrameBufferCount; ++i) Blend[i] = enable; BlendInvalid = false; } } - void setBlendIndexed(GLuint index, bool enable) + void setBlendIndexed(unsigned int index, bool enable) { if (index < FrameBufferCount && Blend[index] != enable) { if (enable) - Driver->irrGlEnableIndexed(GL_BLEND, index); + Driver->irrGlEnableIndexed(GL.BLEND, index); else - Driver->irrGlDisableIndexed(GL_BLEND, index); + Driver->irrGlDisableIndexed(GL.BLEND, index); Blend[index] = enable; BlendInvalid = true; @@ -419,20 +419,20 @@ class COpenGLCoreCacheHandler { if (ColorMask[0] != mask || ColorMaskInvalid) { - glColorMask((mask & ECP_RED) ? GL_TRUE : GL_FALSE, (mask & ECP_GREEN) ? GL_TRUE : GL_FALSE, (mask & ECP_BLUE) ? GL_TRUE : GL_FALSE, (mask & ECP_ALPHA) ? GL_TRUE : GL_FALSE); + GL.ColorMask((mask & ECP_RED) ? true : false, (mask & ECP_GREEN) ? true : false, (mask & ECP_BLUE) ? true : false, (mask & ECP_ALPHA) ? true : false); - for (GLuint i = 0; i < FrameBufferCount; ++i) + for (unsigned int i = 0; i < FrameBufferCount; ++i) ColorMask[i] = mask; ColorMaskInvalid = false; } } - void setColorMaskIndexed(GLuint index, u8 mask) + void setColorMaskIndexed(unsigned int index, u8 mask) { if (index < FrameBufferCount && ColorMask[index] != mask) { - Driver->irrGlColorMaskIndexed(index, (mask & ECP_RED) ? GL_TRUE : GL_FALSE, (mask & ECP_GREEN) ? GL_TRUE : GL_FALSE, (mask & ECP_BLUE) ? GL_TRUE : GL_FALSE, (mask & ECP_ALPHA) ? GL_TRUE : GL_FALSE); + Driver->irrGlColorMaskIndexed(index, (mask & ECP_RED) ? true : false, (mask & ECP_GREEN) ? true : false, (mask & ECP_BLUE) ? true : false, (mask & ECP_ALPHA) ? true : false); ColorMask[index] = mask; ColorMaskInvalid = true; @@ -441,11 +441,11 @@ class COpenGLCoreCacheHandler // Cull face calls. - void setCullFaceFunc(GLenum mode) + void setCullFaceFunc(unsigned int mode) { if (CullFaceMode != mode) { - glCullFace(mode); + GL.CullFace(mode); CullFaceMode = mode; } } @@ -455,9 +455,9 @@ class COpenGLCoreCacheHandler if (CullFace != enable) { if (enable) - glEnable(GL_CULL_FACE); + GL.Enable(GL.CULL_FACE); else - glDisable(GL_CULL_FACE); + GL.Disable(GL.CULL_FACE); CullFace = enable; } @@ -465,11 +465,11 @@ class COpenGLCoreCacheHandler // Depth calls. - void setDepthFunc(GLenum mode) + void setDepthFunc(unsigned int mode) { if (DepthFunc != mode) { - glDepthFunc(mode); + GL.DepthFunc(mode); DepthFunc = mode; } } @@ -484,9 +484,9 @@ class COpenGLCoreCacheHandler if (DepthMask != enable) { if (enable) - glDepthMask(GL_TRUE); + GL.DepthMask(true); else - glDepthMask(GL_FALSE); + GL.DepthMask(false); DepthMask = enable; } @@ -502,9 +502,9 @@ class COpenGLCoreCacheHandler if (DepthTest != enable) { if (enable) - glEnable(GL_DEPTH_TEST); + GL.Enable(GL.DEPTH_TEST); else - glDisable(GL_DEPTH_TEST); + GL.Disable(GL.DEPTH_TEST); DepthTest = enable; } @@ -512,28 +512,28 @@ class COpenGLCoreCacheHandler // FBO calls. - void getFBO(GLuint& frameBufferID) const + void getFBO(unsigned int& frameBufferID) const { frameBufferID = FrameBufferID; } - void setFBO(GLuint frameBufferID) + void setFBO(unsigned int frameBufferID) { if (FrameBufferID != frameBufferID) { - Driver->irrGlBindFramebuffer(GL_FRAMEBUFFER, frameBufferID); + Driver->irrGlBindFramebuffer(GL.FRAMEBUFFER, frameBufferID); FrameBufferID = frameBufferID; } } // Shaders calls. - void getProgram(GLuint& programID) const + void getProgram(unsigned int& programID) const { programID = ProgramID; } - void setProgram(GLuint programID) + void setProgram(unsigned int programID) { if (ProgramID != programID) { @@ -544,12 +544,12 @@ class COpenGLCoreCacheHandler // Texture calls. - void getActiveTexture(GLenum& texture) const + void getActiveTexture(unsigned int& texture) const { texture = ActiveTexture; } - void setActiveTexture(GLenum texture) + void setActiveTexture(unsigned int texture) { if (ActiveTexture != texture) { @@ -560,7 +560,7 @@ class COpenGLCoreCacheHandler // Viewport calls. - void getViewport(GLint& viewportX, GLint& viewportY, GLsizei& viewportWidth, GLsizei& viewportHeight) const + void getViewport(int& viewportX, int& viewportY, int& viewportWidth, int& viewportHeight) const { viewportX = ViewportX; viewportY = ViewportY; @@ -568,11 +568,11 @@ class COpenGLCoreCacheHandler viewportHeight = ViewportHeight; } - void setViewport(GLint viewportX, GLint viewportY, GLsizei viewportWidth, GLsizei viewportHeight) + void setViewport(int viewportX, int viewportY, int viewportWidth, int viewportHeight) { if (ViewportX != viewportX || ViewportY != viewportY || ViewportWidth != viewportWidth || ViewportHeight != viewportHeight) { - glViewport(viewportX, viewportY, viewportWidth, viewportHeight); + GL.Viewport(viewportX, viewportY, viewportWidth, viewportHeight); ViewportX = viewportX; ViewportY = viewportY; ViewportWidth = viewportWidth; @@ -600,13 +600,13 @@ class COpenGLCoreCacheHandler STextureCache TextureCache; - GLuint FrameBufferCount; + unsigned int FrameBufferCount; - GLenum* BlendEquation; - GLenum* BlendSourceRGB; - GLenum* BlendDestinationRGB; - GLenum* BlendSourceAlpha; - GLenum* BlendDestinationAlpha; + unsigned int* BlendEquation; + unsigned int* BlendSourceRGB; + unsigned int* BlendDestinationRGB; + unsigned int* BlendSourceAlpha; + unsigned int* BlendDestinationAlpha; bool* Blend; bool BlendEquationInvalid; bool BlendFuncInvalid; @@ -616,23 +616,23 @@ class COpenGLCoreCacheHandler u8* ColorMask; bool ColorMaskInvalid; - GLenum CullFaceMode; + unsigned int CullFaceMode; bool CullFace; - GLenum DepthFunc; + unsigned int DepthFunc; bool DepthMask; bool DepthTest; - GLuint FrameBufferID; + unsigned int FrameBufferID; - GLuint ProgramID; + unsigned int ProgramID; - GLenum ActiveTexture; + unsigned int ActiveTexture; - GLint ViewportX; - GLint ViewportY; - GLsizei ViewportWidth; - GLsizei ViewportHeight; + int ViewportX; + int ViewportY; + int ViewportWidth; + int ViewportHeight; }; } diff --git a/source/Irrlicht/COpenGLCoreRenderTarget.h b/source/Irrlicht/COpenGLCoreRenderTarget.h index 7d6ee4bfb..78123790d 100644 --- a/source/Irrlicht/COpenGLCoreRenderTarget.h +++ b/source/Irrlicht/COpenGLCoreRenderTarget.h @@ -43,7 +43,7 @@ class COpenGLCoreRenderTarget : public IRenderTarget AssignedTextures.set_used(static_cast(ColorAttachment)); for (u32 i = 0; i < AssignedTextures.size(); ++i) - AssignedTextures[i] = GL_NONE; + AssignedTextures[i] = GL.NONE; } virtual ~COpenGLCoreRenderTarget() @@ -87,7 +87,7 @@ class COpenGLCoreRenderTarget : public IRenderTarget { TOpenGLTexture* currentTexture = (textures[i] && textures[i]->getDriverType() == DriverType) ? static_cast(textures[i]) : 0; - GLuint textureID = 0; + unsigned int textureID = 0; if (currentTexture) { @@ -136,7 +136,7 @@ class COpenGLCoreRenderTarget : public IRenderTarget { if (currentTexture->getType() == ETT_2D) { - GLuint textureID = currentTexture->getOpenGLTextureName(); + unsigned int textureID = currentTexture->getOpenGLTextureName(); const ECOLOR_FORMAT textureFormat = (textureID != 0) ? depthStencil->getColorFormat() : ECF_UNKNOWN; if (IImage::isDepthFormat(textureFormat)) @@ -191,21 +191,21 @@ class COpenGLCoreRenderTarget : public IRenderTarget for (u32 i = 0; i < textureSize; ++i) { TOpenGLTexture* currentTexture = static_cast(Textures[i]); - GLuint textureID = currentTexture ? currentTexture->getOpenGLTextureName() : 0; + unsigned int textureID = currentTexture ? currentTexture->getOpenGLTextureName() : 0; if (textureID != 0) { - AssignedTextures[i] = GL_COLOR_ATTACHMENT0 + i; - GLenum textarget = currentTexture->getType() == ETT_2D ? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int)CubeSurfaces[i]; - Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, AssignedTextures[i], textarget, textureID, 0); + AssignedTextures[i] = GL.COLOR_ATTACHMENT0 + i; + unsigned int textarget = currentTexture->getType() == ETT_2D ? GL.TEXTURE_2D : GL.TEXTURE_CUBE_MAP_POSITIVE_X + (int)CubeSurfaces[i]; + Driver->irrGlFramebufferTexture2D(GL.FRAMEBUFFER, AssignedTextures[i], textarget, textureID, 0); #ifdef _DEBUG Driver->testGLError(__LINE__); #endif } - else if (AssignedTextures[i] != GL_NONE) + else if (AssignedTextures[i] != GL.NONE) { - AssignedTextures[i] = GL_NONE; - Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, AssignedTextures[i], GL_TEXTURE_2D, 0, 0); + AssignedTextures[i] = GL.NONE; + Driver->irrGlFramebufferTexture2D(GL.FRAMEBUFFER, AssignedTextures[i], GL.TEXTURE_2D, 0, 0); os::Printer::log("Error: Could not set render target.", ELL_ERROR); } @@ -215,10 +215,10 @@ class COpenGLCoreRenderTarget : public IRenderTarget for (u32 i = textureSize; i < AssignedTextures.size(); ++i) { - if (AssignedTextures[i] != GL_NONE) + if (AssignedTextures[i] != GL.NONE) { - Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, AssignedTextures[i], GL_TEXTURE_2D, 0, 0); - AssignedTextures[i] = GL_NONE; + Driver->irrGlFramebufferTexture2D(GL.FRAMEBUFFER, AssignedTextures[i], GL.TEXTURE_2D, 0, 0); + AssignedTextures[i] = GL.NONE; } } @@ -233,33 +233,33 @@ class COpenGLCoreRenderTarget : public IRenderTarget if (IImage::isDepthFormat(textureFormat)) { - GLuint textureID = static_cast(DepthStencil)->getOpenGLTextureName(); + unsigned int textureID = static_cast(DepthStencil)->getOpenGLTextureName(); #ifdef _IRR_EMSCRIPTEN_PLATFORM_ // The WEBGL_depth_texture extension does not allow attaching stencil+depth separate. if (textureFormat == ECF_D24S8) { - GLenum attachment = 0x821A; // GL_DEPTH_STENCIL_ATTACHMENT - Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, textureID, 0); + unsigned int attachment = 0x821A; // GL_DEPTH_STENCIL_ATTACHMENT + Driver->irrGlFramebufferTexture2D(GL.FRAMEBUFFER, attachment, GL.TEXTURE_2D, textureID, 0); AssignedStencil = true; } else { - Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, textureID, 0); + Driver->irrGlFramebufferTexture2D(GL.FRAMEBUFFER, GL.DEPTH_ATTACHMENT, GL.TEXTURE_2D, textureID, 0); AssignedStencil = false; } #else - Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, textureID, 0); + Driver->irrGlFramebufferTexture2D(GL.FRAMEBUFFER, GL.DEPTH_ATTACHMENT, GL.TEXTURE_2D, textureID, 0); if (textureFormat == ECF_D24S8) { - Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, textureID, 0); + Driver->irrGlFramebufferTexture2D(GL.FRAMEBUFFER, GL.STENCIL_ATTACHMENT, GL.TEXTURE_2D, textureID, 0); AssignedStencil = true; } else { if (AssignedStencil) - Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0); + Driver->irrGlFramebufferTexture2D(GL.FRAMEBUFFER, GL.STENCIL_ATTACHMENT, GL.TEXTURE_2D, 0, 0); AssignedStencil = false; } @@ -269,10 +269,10 @@ class COpenGLCoreRenderTarget : public IRenderTarget else { if (AssignedDepth) - Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0); + Driver->irrGlFramebufferTexture2D(GL.FRAMEBUFFER, GL.DEPTH_ATTACHMENT, GL.TEXTURE_2D, 0, 0); if (AssignedStencil) - Driver->irrGlFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0); + Driver->irrGlFramebufferTexture2D(GL.FRAMEBUFFER, GL.STENCIL_ATTACHMENT, GL.TEXTURE_2D, 0, 0); AssignedDepth = false; AssignedStencil = false; @@ -291,9 +291,9 @@ class COpenGLCoreRenderTarget : public IRenderTarget const u32 textureSize = Textures.size(); if (textureSize == 0) - Driver->irrGlDrawBuffer(GL_NONE); + Driver->irrGlDrawBuffer(GL.NONE); else if (textureSize == 1 || MultipleRenderTarget == 0) - Driver->irrGlDrawBuffer(GL_COLOR_ATTACHMENT0); + Driver->irrGlDrawBuffer(GL.COLOR_ATTACHMENT0); else { const u32 bufferCount = core::min_(MultipleRenderTarget, core::min_(textureSize, AssignedTextures.size())); @@ -313,7 +313,7 @@ class COpenGLCoreRenderTarget : public IRenderTarget } } - GLuint getBufferID() const + unsigned int getBufferID() const { return BufferID; } @@ -340,31 +340,31 @@ class COpenGLCoreRenderTarget : public IRenderTarget if (ColorAttachment == 0) return true; - GLenum status = driver->irrGlCheckFramebufferStatus(GL_FRAMEBUFFER); + unsigned int status = driver->irrGlCheckFramebufferStatus(GL.FRAMEBUFFER); switch (status) { - case GL_FRAMEBUFFER_COMPLETE: + case OpenGLProcedures::FRAMEBUFFER_COMPLETE: return true; - case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: + case OpenGLProcedures::FRAMEBUFFER_INCOMPLETE_READ_BUFFER: os::Printer::log("FBO has invalid read buffer", ELL_ERROR); break; - case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: + case OpenGLProcedures::FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: os::Printer::log("FBO has invalid draw buffer", ELL_ERROR); break; - case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: + case OpenGLProcedures::FRAMEBUFFER_INCOMPLETE_ATTACHMENT: os::Printer::log("FBO has one or several incomplete image attachments", ELL_ERROR); break; - case GL_FRAMEBUFFER_INCOMPLETE_FORMATS: - os::Printer::log("FBO has one or several image attachments with different internal formats", ELL_ERROR); - break; - case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: - os::Printer::log("FBO has one or several image attachments with different dimensions", ELL_ERROR); - break; - case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: +// case OpenGLProcedures::FRAMEBUFFER_INCOMPLETE_FORMATS: +// os::Printer::log("FBO has one or several image attachments with different internal formats", ELL_ERROR); +// break; +// case OpenGLProcedures::FRAMEBUFFER_INCOMPLETE_DIMENSIONS: +// os::Printer::log("FBO has one or several image attachments with different dimensions", ELL_ERROR); +// break; + case OpenGLProcedures::FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: os::Printer::log("FBO missing an image attachment", ELL_ERROR); break; - case GL_FRAMEBUFFER_UNSUPPORTED: + case OpenGLProcedures::FRAMEBUFFER_UNSUPPORTED: os::Printer::log("FBO format unsupported", ELL_ERROR); break; default: @@ -375,14 +375,14 @@ class COpenGLCoreRenderTarget : public IRenderTarget return false; } - core::array AssignedTextures; + core::array AssignedTextures; bool AssignedDepth; bool AssignedStencil; bool RequestTextureUpdate; bool RequestDepthStencilUpdate; - GLuint BufferID; + unsigned int BufferID; core::dimension2d Size; diff --git a/source/Irrlicht/COpenGLCoreTexture.h b/source/Irrlicht/COpenGLCoreTexture.h index 984d2ecc8..653c9ab41 100644 --- a/source/Irrlicht/COpenGLCoreTexture.h +++ b/source/Irrlicht/COpenGLCoreTexture.h @@ -12,6 +12,8 @@ #include "CImage.h" #include "CColorConverter.h" +#include + // Check if GL version we compile with should have the glGenerateMipmap function. #if defined(GL_VERSION_3_0) || defined(GL_ES_VERSION_2_0) #define IRR_OPENGL_HAS_glGenerateMipmap @@ -45,8 +47,8 @@ class COpenGLCoreTexture : public ITexture bool IsCached; }; - COpenGLCoreTexture(const io::path& name, const core::array& images, E_TEXTURE_TYPE type, TOpenGLDriver* driver) : ITexture(name, type), Driver(driver), TextureType(GL_TEXTURE_2D), - TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_RGBA), PixelType(GL_UNSIGNED_BYTE), Converter(0), LockReadOnly(false), LockImage(0), LockLayer(0), + COpenGLCoreTexture(const io::path& name, const core::array& images, E_TEXTURE_TYPE type, TOpenGLDriver* driver) : ITexture(name, type), Driver(driver), TextureType(GL.TEXTURE_2D), + TextureName(0), InternalFormat(GL.RGBA), PixelFormat(GL.RGBA), PixelType(GL.UNSIGNED_BYTE), Converter(0), LockReadOnly(false), LockImage(0), LockLayer(0), KeepImage(false), MipLevelStored(0), LegacyAutoGenerateMipMaps(false) { _IRR_DEBUG_BREAK_IF(images.size() == 0) @@ -90,15 +92,15 @@ class COpenGLCoreTexture : public ITexture tmpImages = &Images; } - glGenTextures(1, &TextureName); + GL.GenTextures(1, &TextureName); const COpenGLCoreTexture* prevTexture = Driver->getCacheHandler()->getTextureCache().get(0); Driver->getCacheHandler()->getTextureCache().set(0, this); - glTexParameteri(TextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + GL.TexParameteri(TextureType, GL.TEXTURE_MIN_FILTER, GL.NEAREST); + GL.TexParameteri(TextureType, GL.TEXTURE_MAG_FILTER, GL.NEAREST); -#ifdef GL_GENERATE_MIPMAP_HINT +#if 0 if (HasMipMaps) { if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED)) @@ -148,8 +150,8 @@ class COpenGLCoreTexture : public ITexture COpenGLCoreTexture(const io::path& name, const core::dimension2d& size, E_TEXTURE_TYPE type, ECOLOR_FORMAT format, TOpenGLDriver* driver) : ITexture(name, type), - Driver(driver), TextureType(GL_TEXTURE_2D), - TextureName(0), InternalFormat(GL_RGBA), PixelFormat(GL_RGBA), PixelType(GL_UNSIGNED_BYTE), Converter(0), LockReadOnly(false), LockImage(0), LockLayer(0), KeepImage(false), + Driver(driver), TextureType(GL.TEXTURE_2D), + TextureName(0), InternalFormat(GL.RGBA), PixelFormat(GL.RGBA), PixelType(GL.UNSIGNED_BYTE), Converter(0), LockReadOnly(false), LockImage(0), LockLayer(0), KeepImage(false), MipLevelStored(0), LegacyAutoGenerateMipMaps(false) { DriverType = Driver->getDriverType(); @@ -174,16 +176,16 @@ class COpenGLCoreTexture : public ITexture os::Printer::log("COpenGLCoreTexture: Color format is not supported", ColorFormatNames[ColorFormat < ECF_UNKNOWN?ColorFormat:ECF_UNKNOWN], ELL_ERROR); } - glGenTextures(1, &TextureName); + GL.GenTextures(1, &TextureName); const COpenGLCoreTexture* prevTexture = Driver->getCacheHandler()->getTextureCache().get(0); Driver->getCacheHandler()->getTextureCache().set(0, this); - glTexParameteri(TextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(TextureType, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(TextureType, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + GL.TexParameteri(TextureType, GL.TEXTURE_MIN_FILTER, GL.NEAREST); + GL.TexParameteri(TextureType, GL.TEXTURE_MAG_FILTER, GL.NEAREST); + GL.TexParameteri(TextureType, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_EDGE); + GL.TexParameteri(TextureType, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_EDGE); #if defined(GL_VERSION_1_2) glTexParameteri(TextureType, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); @@ -196,15 +198,15 @@ class COpenGLCoreTexture : public ITexture switch (Type) { case ETT_2D: - glTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + GL.TexImage2D(GL.TEXTURE_2D, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); break; case ETT_CUBEMAP: - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + GL.TexImage2D(GL.TEXTURE_CUBE_MAP_POSITIVE_X, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + GL.TexImage2D(GL.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + GL.TexImage2D(GL.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + GL.TexImage2D(GL.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + GL.TexImage2D(GL.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); + GL.TexImage2D(GL.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, InternalFormat, Size.Width, Size.Height, 0, PixelFormat, PixelType, 0); break; } @@ -220,7 +222,7 @@ class COpenGLCoreTexture : public ITexture virtual ~COpenGLCoreTexture() { if (TextureName) - glDeleteTextures(1, &TextureName); + GL.DeleteTextures(1, &TextureName); if (LockImage) LockImage->drop(); @@ -269,7 +271,7 @@ class COpenGLCoreTexture : public ITexture Driver->getCacheHandler()->getTextureCache().set(0, this); Driver->testGLError(__LINE__); - GLenum tmpTextureType = TextureType; + unsigned int tmpTextureType = TextureType; if (tmpTextureType == GL_TEXTURE_CUBE_MAP) { @@ -305,17 +307,17 @@ class COpenGLCoreTexture : public ITexture // TODO: on ES2 we can likely also work with glCopyTexImage2D instead of rendering which should be faster. COpenGLCoreTexture* tmpTexture = new COpenGLCoreTexture("OGL_CORE_LOCK_TEXTURE", Size, ETT_2D, ColorFormat, Driver); - GLuint tmpFBO = 0; + unsigned int tmpFBO = 0; Driver->irrGlGenFramebuffers(1, &tmpFBO); - GLint prevViewportX = 0; - GLint prevViewportY = 0; + int prevViewportX = 0; + int prevViewportY = 0; GLsizei prevViewportWidth = 0; GLsizei prevViewportHeight = 0; Driver->getCacheHandler()->getViewport(prevViewportX, prevViewportY, prevViewportWidth, prevViewportHeight); Driver->getCacheHandler()->setViewport(0, 0, Size.Width, Size.Height); - GLuint prevFBO = 0; + unsigned int prevFBO = 0; Driver->getCacheHandler()->getFBO(prevFBO); Driver->getCacheHandler()->setFBO(tmpFBO); @@ -436,12 +438,12 @@ class COpenGLCoreTexture : public ITexture Driver->getCacheHandler()->getTextureCache().set(0, prevTexture); } - GLenum getOpenGLTextureType() const + unsigned int getOpenGLTextureType() const { return TextureType; } - GLuint getOpenGLTextureName() const + unsigned int getOpenGLTextureName() const { return TextureName; } @@ -562,13 +564,13 @@ class COpenGLCoreTexture : public ITexture u32 width = Size.Width >> level; u32 height = Size.Height >> level; - GLenum tmpTextureType = TextureType; + unsigned int tmpTextureType = TextureType; - if (tmpTextureType == GL_TEXTURE_CUBE_MAP) + if (tmpTextureType == GL.TEXTURE_CUBE_MAP) { _IRR_DEBUG_BREAK_IF(layer > 5) - tmpTextureType = GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer; + tmpTextureType = GL.TEXTURE_CUBE_MAP_POSITIVE_X + layer; } if (!IImage::isCompressedFormat(ColorFormat)) @@ -588,12 +590,12 @@ class COpenGLCoreTexture : public ITexture switch (TextureType) { - case GL_TEXTURE_2D: - case GL_TEXTURE_CUBE_MAP: + case OpenGLProcedures::TEXTURE_2D: + case OpenGLProcedures::TEXTURE_CUBE_MAP: if (initTexture) - glTexImage2D(tmpTextureType, level, InternalFormat, width, height, 0, PixelFormat, PixelType, tmpData); + GL.TexImage2D(tmpTextureType, level, InternalFormat, width, height, 0, PixelFormat, PixelType, tmpData); else - glTexSubImage2D(tmpTextureType, level, 0, 0, width, height, PixelFormat, PixelType, tmpData); + GL.TexSubImage2D(tmpTextureType, level, 0, 0, width, height, PixelFormat, PixelType, tmpData); Driver->testGLError(__LINE__); break; default: @@ -608,8 +610,8 @@ class COpenGLCoreTexture : public ITexture switch (TextureType) { - case GL_TEXTURE_2D: - case GL_TEXTURE_CUBE_MAP: + case OpenGLProcedures::TEXTURE_2D: + case OpenGLProcedures::TEXTURE_CUBE_MAP: if (initTexture) Driver->irrGlCompressedTexImage2D(tmpTextureType, level, InternalFormat, width, height, 0, dataSize, data); else @@ -622,27 +624,27 @@ class COpenGLCoreTexture : public ITexture } } - GLenum TextureTypeIrrToGL(E_TEXTURE_TYPE type) const + unsigned int TextureTypeIrrToGL(E_TEXTURE_TYPE type) const { switch ( type) { case ETT_2D: - return GL_TEXTURE_2D; + return GL.TEXTURE_2D; case ETT_CUBEMAP: - return GL_TEXTURE_CUBE_MAP; + return GL.TEXTURE_CUBE_MAP; } os::Printer::log("COpenGLCoreTexture::TextureTypeIrrToGL unknown texture type", ELL_WARNING); - return GL_TEXTURE_2D; + return GL.TEXTURE_2D; } TOpenGLDriver* Driver; - GLenum TextureType; - GLuint TextureName; - GLint InternalFormat; - GLenum PixelFormat; - GLenum PixelType; + unsigned int TextureType; + unsigned int TextureName; + int InternalFormat; + unsigned int PixelFormat; + unsigned int PixelType; void (*Converter)(const void*, s32, void*); bool LockReadOnly; diff --git a/source/Irrlicht/OpenGL/Common.h b/source/Irrlicht/OpenGL/Common.h index 2155a9a91..ac32a02e2 100644 --- a/source/Irrlicht/OpenGL/Common.h +++ b/source/Irrlicht/OpenGL/Common.h @@ -7,7 +7,8 @@ #define GL_GLEXT_PROTOTYPES #include -#include + +#include namespace irr { diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index fdc091f8a..bd92ad17e 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -39,7 +39,7 @@ namespace video }; int Index; int ComponentCount; - GLenum ComponentType; + unsigned int ComponentType; Mode mode; int Offset; }; @@ -65,10 +65,10 @@ namespace video static constexpr VertexType vtStandard = { sizeof(S3DVertex), 4, { - {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, - {EVA_NORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Normal)}, - {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, - {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, TCoords)}, + {EVA_POSITION, 3, GL.FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, + {EVA_NORMAL, 3, GL.FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Normal)}, + {EVA_COLOR, 4, GL.UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, + {EVA_TCOORD0, 2, GL.FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, TCoords)}, }, }; @@ -77,22 +77,22 @@ namespace video static constexpr VertexType vt2TCoords = { sizeof(S3DVertex2TCoords), 5, { - {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, Pos)}, - {EVA_NORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, Normal)}, - {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex2TCoords, Color)}, - {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, TCoords)}, - {EVA_TCOORD1, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, TCoords2)}, + {EVA_POSITION, 3, GL.FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, Pos)}, + {EVA_NORMAL, 3, GL.FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, Normal)}, + {EVA_COLOR, 4, GL.UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex2TCoords, Color)}, + {EVA_TCOORD0, 2, GL.FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, TCoords)}, + {EVA_TCOORD1, 2, GL.FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex2TCoords, TCoords2)}, }, }; static constexpr VertexType vtTangents = { sizeof(S3DVertexTangents), 6, { - {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Pos)}, - {EVA_NORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Normal)}, - {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertexTangents, Color)}, - {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, TCoords)}, - {EVA_TANGENT, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Tangent)}, - {EVA_BINORMAL, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Binormal)}, + {EVA_POSITION, 3, GL.FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Pos)}, + {EVA_NORMAL, 3, GL.FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Normal)}, + {EVA_COLOR, 4, GL.UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertexTangents, Color)}, + {EVA_TCOORD0, 2, GL.FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, TCoords)}, + {EVA_TANGENT, 3, GL.FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Tangent)}, + {EVA_BINORMAL, 3, GL.FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertexTangents, Binormal)}, }, }; @@ -110,37 +110,39 @@ namespace video static constexpr VertexType vt2DImage = { sizeof(S3DVertex), 3, { - {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, - {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, - {EVA_TCOORD0, 2, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, TCoords)}, + {EVA_POSITION, 3, GL.FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, + {EVA_COLOR, 4, GL.UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, + {EVA_TCOORD0, 2, GL.FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, TCoords)}, }, }; static constexpr VertexType vtPrimitive = { sizeof(S3DVertex), 2, { - {EVA_POSITION, 3, GL_FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, - {EVA_COLOR, 4, GL_UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, + {EVA_POSITION, 3, GL.FLOAT, VertexAttribute::Mode::Regular, offsetof(S3DVertex, Pos)}, + {EVA_COLOR, 4, GL.UNSIGNED_BYTE, VertexAttribute::Mode::Normalized, offsetof(S3DVertex, Color)}, }, }; -void APIENTRY COpenGL3DriverBase::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) +void APIENTRY COpenGL3DriverBase::debugCb(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, int length, const char *message, const void *userParam) { ((COpenGL3DriverBase *)userParam)->debugCb(source, type, id, severity, length, message); } -void COpenGL3DriverBase::debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message) +void COpenGL3DriverBase::debugCb(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, int length, const char *message) { printf("%04x %04x %x %x %.*s\n", source, type, id, severity, length, message); } -COpenGL3DriverBase::COpenGL3DriverBase(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager) : - CNullDriver(io, params.WindowSize), COpenGL3ExtensionHandler(), CacheHandler(0), - Params(params), ResetRenderStates(true), LockRenderStateMode(false), AntiAlias(params.AntiAlias), - MaterialRenderer2DActive(0), MaterialRenderer2DTexture(0), MaterialRenderer2DNoTexture(0), - CurrentRenderMode(ERM_NONE), Transformation3DChanged(true), - OGLES2ShaderPath(params.OGLES2ShaderPath), - ColorFormat(ECF_R8G8B8), ContextManager(contextManager) +COpenGL3DriverBase::COpenGL3DriverBase(const SIrrlichtCreationParameters ¶ms, + io::IFileSystem *io, IContextManager *contextManager) : + CNullDriver(io, params.WindowSize), + COpenGL3ExtensionHandler(), CacheHandler(0), Params(params), + ResetRenderStates(true), LockRenderStateMode(false), AntiAlias(params.AntiAlias), + MaterialRenderer2DActive(0), MaterialRenderer2DTexture(0), + MaterialRenderer2DNoTexture(0), CurrentRenderMode(ERM_NONE), + Transformation3DChanged(true), OGLES2ShaderPath(params.OGLES2ShaderPath), + UseGlobalVBO(true), ColorFormat(ECF_R8G8B8), ContextManager(contextManager) { #ifdef _DEBUG setDebugName("Driver"); @@ -156,6 +158,12 @@ COpenGL3DriverBase::COpenGL3DriverBase(const SIrrlichtCreationParameters& params ContextManager->activateContext(ExposedData, false); GL.LoadAllProcedures(ContextManager); GL.DebugMessageCallback(debugCb, this); + + GL.GenVertexArrays(1, &GlobalVAO); + GL.BindVertexArray(GlobalVAO); + + GL.GenBuffers(1, &GlobalVBO); + initQuadsIndices(); } @@ -186,7 +194,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() void COpenGL3DriverBase::initQuadsIndices(int max_vertex_count) { int max_quad_count = max_vertex_count / 4; - std::vector QuadsIndices; + std::vector QuadsIndices; QuadsIndices.reserve(6 * max_quad_count); for (int k = 0; k < max_quad_count; k++) { QuadsIndices.push_back(4 * k + 0); @@ -196,19 +204,19 @@ COpenGL3DriverBase::~COpenGL3DriverBase() QuadsIndices.push_back(4 * k + 2); QuadsIndices.push_back(4 * k + 3); } - glGenBuffers(1, &QuadIndexBuffer); - glBindBuffer(GL_ARRAY_BUFFER, QuadIndexBuffer); - glBufferData(GL_ARRAY_BUFFER, sizeof(QuadsIndices[0]) * QuadsIndices.size(), QuadsIndices.data(), GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); + GL.GenBuffers(1, &QuadIndexBuffer); + GL.BindBuffer(GL.ARRAY_BUFFER, QuadIndexBuffer); + GL.BufferData(GL.ARRAY_BUFFER, sizeof(QuadsIndices[0]) * QuadsIndices.size(), QuadsIndices.data(), GL.STATIC_DRAW); + GL.BindBuffer(GL.ARRAY_BUFFER, 0); QuadIndexCount = QuadsIndices.size(); } void COpenGL3DriverBase::initVersion() { - Name = glGetString(GL_VERSION); + Name = GL.GetString(GL.VERSION); printVersion(); // print renderer information - VendorName = glGetString(GL_VENDOR); + VendorName = GL.GetString(GL.VENDOR); os::Printer::log(VendorName.c_str(), ELL_INFORMATION); Version = getVersionFromOpenGL(); @@ -246,7 +254,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() DriverAttributes->setAttribute("Version", 100 * Version.Major + Version.Minor); DriverAttributes->setAttribute("AntiAlias", AntiAlias); - glPixelStorei(GL_PACK_ALIGNMENT, 1); + GL.PixelStorei(GL.PACK_ALIGNMENT, 1); UserClipPlane.reallocate(0); @@ -254,10 +262,10 @@ COpenGL3DriverBase::~COpenGL3DriverBase() setTransform(static_cast(i), core::IdentityMatrix); setAmbientLight(SColorf(0.0f, 0.0f, 0.0f, 0.0f)); - glClearDepthf(1.0f); + GL.ClearDepthf(1.0); - glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); - glFrontFace(GL_CW); + //glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); + GL.FrontFace(GL.CW); // create material renderers createMaterialRenderers(); @@ -422,7 +430,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() { CNullDriver::endScene(); - glFlush(); + GL.Flush(); if (ContextManager) return ContextManager->swapBuffers(); @@ -464,7 +472,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() bool newBuffer = false; if (!HWBuffer->vbo_verticesID) { - glGenBuffers(1, &HWBuffer->vbo_verticesID); + GL.GenBuffers(1, &HWBuffer->vbo_verticesID); if (!HWBuffer->vbo_verticesID) return false; newBuffer = true; } @@ -473,22 +481,22 @@ COpenGL3DriverBase::~COpenGL3DriverBase() newBuffer = true; } - glBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID); + GL.BindBuffer(GL.ARRAY_BUFFER, HWBuffer->vbo_verticesID); // copy data to graphics card if (!newBuffer) - glBufferSubData(GL_ARRAY_BUFFER, 0, bufferSize, buffer); + GL.BufferSubData(GL.ARRAY_BUFFER, 0, bufferSize, buffer); else { HWBuffer->vbo_verticesSize = bufferSize; if (HWBuffer->Mapped_Vertex == scene::EHM_STATIC) - glBufferData(GL_ARRAY_BUFFER, bufferSize, buffer, GL_STATIC_DRAW); + GL.BufferData(GL.ARRAY_BUFFER, bufferSize, buffer, GL.STATIC_DRAW); else - glBufferData(GL_ARRAY_BUFFER, bufferSize, buffer, GL_DYNAMIC_DRAW); + GL.BufferData(GL.ARRAY_BUFFER, bufferSize, buffer, GL.DYNAMIC_DRAW); } - glBindBuffer(GL_ARRAY_BUFFER, 0); + GL.BindBuffer(GL.ARRAY_BUFFER, 0); return (!testGLError(__LINE__)); } @@ -504,7 +512,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() const void* indices = mb->getIndices(); u32 indexCount = mb->getIndexCount(); - GLenum indexSize; + unsigned int indexSize; switch (mb->getIndexType()) { case(EIT_16BIT): @@ -527,7 +535,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() bool newBuffer = false; if (!HWBuffer->vbo_indicesID) { - glGenBuffers(1, &HWBuffer->vbo_indicesID); + GL.GenBuffers(1, &HWBuffer->vbo_indicesID); if (!HWBuffer->vbo_indicesID) return false; newBuffer = true; } @@ -536,22 +544,22 @@ COpenGL3DriverBase::~COpenGL3DriverBase() newBuffer = true; } - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID); + GL.BindBuffer(GL.ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID); // copy data to graphics card if (!newBuffer) - glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexCount * indexSize, indices); + GL.BufferSubData(GL.ELEMENT_ARRAY_BUFFER, 0, indexCount * indexSize, indices); else { HWBuffer->vbo_indicesSize = indexCount * indexSize; if (HWBuffer->Mapped_Index == scene::EHM_STATIC) - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_STATIC_DRAW); + GL.BufferData(GL.ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL.STATIC_DRAW); else - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL_DYNAMIC_DRAW); + GL.BufferData(GL.ELEMENT_ARRAY_BUFFER, indexCount * indexSize, indices, GL.DYNAMIC_DRAW); } - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + GL.BindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0); return (!testGLError(__LINE__)); } @@ -631,12 +639,12 @@ COpenGL3DriverBase::~COpenGL3DriverBase() SHWBufferLink_opengl *HWBuffer = static_cast(_HWBuffer); if (HWBuffer->vbo_verticesID) { - glDeleteBuffers(1, &HWBuffer->vbo_verticesID); + GL.DeleteBuffers(1, &HWBuffer->vbo_verticesID); HWBuffer->vbo_verticesID = 0; } if (HWBuffer->vbo_indicesID) { - glDeleteBuffers(1, &HWBuffer->vbo_indicesID); + GL.DeleteBuffers(1, &HWBuffer->vbo_indicesID); HWBuffer->vbo_indicesID = 0; } @@ -660,27 +668,30 @@ COpenGL3DriverBase::~COpenGL3DriverBase() if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) { - glBindBuffer(GL_ARRAY_BUFFER, HWBuffer->vbo_verticesID); + GL.BindBuffer(GL.ARRAY_BUFFER, HWBuffer->vbo_verticesID); vertices = 0; } if (HWBuffer->Mapped_Index != scene::EHM_NEVER) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID); + GL.BindBuffer(GL.ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID); indexList = 0; } + UseGlobalVBO = false; drawVertexPrimitiveList(vertices, mb->getVertexCount(), indexList, mb->getPrimitiveCount(), mb->getVertexType(), mb->getPrimitiveType(), mb->getIndexType()); + UseGlobalVBO = true; + if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) - glBindBuffer(GL_ARRAY_BUFFER, 0); + GL.BindBuffer(GL.ARRAY_BUFFER, 0); if (HWBuffer->Mapped_Index != scene::EHM_NEVER) - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + GL.BindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0); } @@ -716,14 +727,13 @@ COpenGL3DriverBase::~COpenGL3DriverBase() setRenderStates3DMode(); auto &vTypeDesc = getVertexTypeDescription(vType); - beginDraw(vTypeDesc, reinterpret_cast(vertices)); - GLenum indexSize = 0; + unsigned int indexSize = 0; switch (iType) { case(EIT_16BIT): { - indexSize = GL_UNSIGNED_SHORT; + indexSize = GL.UNSIGNED_SHORT; break; } case(EIT_32BIT): @@ -736,34 +746,36 @@ COpenGL3DriverBase::~COpenGL3DriverBase() indexSize = GL_UNSIGNED_INT; else #endif - indexSize = GL_UNSIGNED_SHORT; + indexSize = GL.UNSIGNED_SHORT; break; } } + beginDraw(vTypeDesc, vertexCount, reinterpret_cast(vertices)); + switch (pType) { case scene::EPT_POINTS: case scene::EPT_POINT_SPRITES: - glDrawArrays(GL_POINTS, 0, primitiveCount); + GL.DrawArrays(GL.POINTS, 0, primitiveCount); break; case scene::EPT_LINE_STRIP: - glDrawElements(GL_LINE_STRIP, primitiveCount + 1, indexSize, indexList); + GL.DrawElements(GL.LINE_STRIP, primitiveCount + 1, indexSize, indexList); break; case scene::EPT_LINE_LOOP: - glDrawElements(GL_LINE_LOOP, primitiveCount, indexSize, indexList); + GL.DrawElements(GL.LINE_LOOP, primitiveCount, indexSize, indexList); break; case scene::EPT_LINES: - glDrawElements(GL_LINES, primitiveCount*2, indexSize, indexList); + GL.DrawElements(GL.LINES, primitiveCount*2, indexSize, indexList); break; case scene::EPT_TRIANGLE_STRIP: - glDrawElements(GL_TRIANGLE_STRIP, primitiveCount + 2, indexSize, indexList); + GL.DrawElements(GL.TRIANGLE_STRIP, primitiveCount + 2, indexSize, indexList); break; case scene::EPT_TRIANGLE_FAN: - glDrawElements(GL_TRIANGLE_FAN, primitiveCount + 2, indexSize, indexList); + GL.DrawElements(GL.TRIANGLE_FAN, primitiveCount + 2, indexSize, indexList); break; case scene::EPT_TRIANGLES: - glDrawElements((LastMaterial.Wireframe) ? GL_LINES : (LastMaterial.PointCloud) ? GL_POINTS : GL_TRIANGLES, primitiveCount*3, indexSize, indexList); + GL.DrawElements((LastMaterial.Wireframe) ? GL.LINES : (LastMaterial.PointCloud) ? GL.POINTS : GL.TRIANGLES, primitiveCount*3, indexSize, indexList); break; default: break; @@ -831,8 +843,8 @@ COpenGL3DriverBase::~COpenGL3DriverBase() if (!clipRect->isValid()) return; - glEnable(GL_SCISSOR_TEST); - glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, + GL.Enable(GL.SCISSOR_TEST); + GL.Scissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, clipRect->getWidth(), clipRect->getHeight()); } @@ -850,7 +862,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() drawQuad(vt2DImage, vertices); if (clipRect) - glDisable(GL_SCISSOR_TEST); + GL.Disable(GL.SCISSOR_TEST); testGLError(__LINE__); } @@ -910,8 +922,8 @@ COpenGL3DriverBase::~COpenGL3DriverBase() if (!clipRect->isValid()) return; - glEnable(GL_SCISSOR_TEST); - glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, + GL.Enable(GL.SCISSOR_TEST); + GL.Scissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, clipRect->getWidth(), clipRect->getHeight()); } @@ -956,12 +968,12 @@ COpenGL3DriverBase::~COpenGL3DriverBase() tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y)); } - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, QuadIndexBuffer); - drawElements(GL_TRIANGLES, vt2DImage, vtx.const_pointer(), vtx.size(), 0, 6 * drawCount); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + GL.BindBuffer(GL.ELEMENT_ARRAY_BUFFER, QuadIndexBuffer); + drawElements(GL.TRIANGLES, vt2DImage, vtx.const_pointer(), vtx.size(), 0, 6 * drawCount); + GL.BindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0); if (clipRect) - glDisable(GL_SCISSOR_TEST); + GL.Disable(GL.SCISSOR_TEST); } @@ -1063,7 +1075,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() vertices[0] = S3DVertex(startX, startY, 0, 0, 0, 1, color, 0, 0); vertices[1] = S3DVertex(endX, endY, 0, 0, 0, 1, color, 1, 1); - drawArrays(GL_LINES, vtPrimitive, vertices, 2); + drawArrays(GL.LINES, vtPrimitive, vertices, 2); } } @@ -1086,36 +1098,49 @@ COpenGL3DriverBase::~COpenGL3DriverBase() S3DVertex vertices[1]; vertices[0] = S3DVertex(X, Y, 0, 0, 0, 1, color, 0, 0); - drawArrays(GL_POINTS, vtPrimitive, vertices, 1); + drawArrays(GL.POINTS, vtPrimitive, vertices, 1); } void COpenGL3DriverBase::drawQuad(const VertexType &vertexType, const S3DVertex (&vertices)[4]) { - drawArrays(GL_TRIANGLE_FAN, vertexType, vertices, 4); + drawArrays(GL.TRIANGLE_FAN, vertexType, vertices, 4); } - void COpenGL3DriverBase::drawArrays(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount) + void COpenGL3DriverBase::drawArrays(unsigned int primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount) { - beginDraw(vertexType, reinterpret_cast(vertices)); - glDrawArrays(primitiveType, 0, vertexCount); + beginDraw(vertexType, vertexCount, reinterpret_cast(vertices)); + GL.DrawArrays(primitiveType, 0, vertexCount); endDraw(vertexType); } - void COpenGL3DriverBase::drawElements(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount, const u16 *indices, int indexCount) + void COpenGL3DriverBase::drawElements(unsigned int primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount, const u16 *indices, int indexCount) { - beginDraw(vertexType, reinterpret_cast(vertices)); - glDrawRangeElements(primitiveType, 0, vertexCount - 1, indexCount, GL_UNSIGNED_SHORT, indices); + beginDraw(vertexType, vertexCount, reinterpret_cast(vertices)); + GL.DrawRangeElements(primitiveType, 0, vertexCount - 1, indexCount, GL.UNSIGNED_SHORT, indices); endDraw(vertexType); } - void COpenGL3DriverBase::beginDraw(const VertexType &vertexType, uintptr_t verticesBase) + void COpenGL3DriverBase::beginDraw(const VertexType &vertexType, int vertexCount, uintptr_t verticesBase) { - for (auto attr: vertexType) { - glEnableVertexAttribArray(attr.Index); - switch (attr.mode) { - case VertexAttribute::Mode::Regular: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_FALSE, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); break; - case VertexAttribute::Mode::Normalized: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_TRUE, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); break; - case VertexAttribute::Mode::Integral: glVertexAttribIPointer(attr.Index, attr.ComponentCount, attr.ComponentType, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); break; + if (UseGlobalVBO) { + GL.BindBuffer(GL.ARRAY_BUFFER, GlobalVBO); + GL.BufferData(GL.ARRAY_BUFFER, vertexType.VertexSize * vertexCount, reinterpret_cast(verticesBase), GL.DYNAMIC_DRAW); + for (auto attr: vertexType) { + GL.EnableVertexAttribArray(attr.Index); + switch (attr.mode) { + case VertexAttribute::Mode::Regular: GL.VertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, false, vertexType.VertexSize, reinterpret_cast(attr.Offset)); break; + case VertexAttribute::Mode::Normalized: GL.VertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, true, vertexType.VertexSize, reinterpret_cast(attr.Offset)); break; + case VertexAttribute::Mode::Integral: GL.VertexAttribIPointer(attr.Index, attr.ComponentCount, attr.ComponentType, vertexType.VertexSize, reinterpret_cast(attr.Offset)); break; + } + } + } else { + for (auto attr: vertexType) { + GL.EnableVertexAttribArray(attr.Index); + switch (attr.mode) { + case VertexAttribute::Mode::Regular: GL.VertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, false, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); break; + case VertexAttribute::Mode::Normalized: GL.VertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, true, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); break; + case VertexAttribute::Mode::Integral: GL.VertexAttribIPointer(attr.Index, attr.ComponentCount, attr.ComponentType, vertexType.VertexSize, reinterpret_cast(verticesBase + attr.Offset)); break; + } } } } @@ -1123,7 +1148,9 @@ COpenGL3DriverBase::~COpenGL3DriverBase() void COpenGL3DriverBase::endDraw(const VertexType &vertexType) { for (auto attr: vertexType) - glDisableVertexAttribArray(attr.Index); + GL.DisableVertexAttribArray(attr.Index); + if (UseGlobalVBO) + GL.BindBuffer(GL.ARRAY_BUFFER, 0); } ITexture* COpenGL3DriverBase::createDeviceDependentTexture(const io::path& name, IImage* image) @@ -1160,23 +1187,23 @@ COpenGL3DriverBase::~COpenGL3DriverBase() bool COpenGL3DriverBase::testGLError(int code) { #ifdef _DEBUG - GLenum g = glGetError(); + unsigned int g = GL.GetError(); switch (g) { - case GL_NO_ERROR: - return false; - case GL_INVALID_ENUM: + case OpenGLProcedures::INVALID_ENUM: os::Printer::log("GL_INVALID_ENUM", core::stringc(code).c_str(), ELL_ERROR); break; - case GL_INVALID_VALUE: + case OpenGLProcedures::INVALID_VALUE: os::Printer::log("GL_INVALID_VALUE", core::stringc(code).c_str(), ELL_ERROR); break; - case GL_INVALID_OPERATION: + case OpenGLProcedures::INVALID_OPERATION: os::Printer::log("GL_INVALID_OPERATION", core::stringc(code).c_str(), ELL_ERROR); break; - case GL_OUT_OF_MEMORY: + case OpenGLProcedures::OUT_OF_MEMORY: os::Printer::log("GL_OUT_OF_MEMORY", core::stringc(code).c_str(), ELL_ERROR); break; + default: + return false; }; return true; #else @@ -1252,7 +1279,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() { // Reset Texture Stages CacheHandler->setBlend(false); - CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + CacheHandler->setBlendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA); ResetRenderStates = true; } @@ -1298,35 +1325,35 @@ COpenGL3DriverBase::~COpenGL3DriverBase() break; case ECFN_LESSEQUAL: CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_LEQUAL); + CacheHandler->setDepthFunc(GL.LEQUAL); break; case ECFN_EQUAL: CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_EQUAL); + CacheHandler->setDepthFunc(GL.EQUAL); break; case ECFN_LESS: CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_LESS); + CacheHandler->setDepthFunc(GL.LESS); break; case ECFN_NOTEQUAL: CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_NOTEQUAL); + CacheHandler->setDepthFunc(GL.NOTEQUAL); break; case ECFN_GREATEREQUAL: CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_GEQUAL); + CacheHandler->setDepthFunc(GL.GEQUAL); break; case ECFN_GREATER: CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_GREATER); + CacheHandler->setDepthFunc(GL.GREATER); break; case ECFN_ALWAYS: CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_ALWAYS); + CacheHandler->setDepthFunc(GL.ALWAYS); break; case ECFN_NEVER: CacheHandler->setDepthTest(true); - CacheHandler->setDepthFunc(GL_NEVER); + CacheHandler->setDepthFunc(GL.NEVER); break; default: break; @@ -1345,17 +1372,17 @@ COpenGL3DriverBase::~COpenGL3DriverBase() // Back face culling if ((material.FrontfaceCulling) && (material.BackfaceCulling)) { - CacheHandler->setCullFaceFunc(GL_FRONT_AND_BACK); + CacheHandler->setCullFaceFunc(GL.FRONT_AND_BACK); CacheHandler->setCullFace(true); } else if (material.BackfaceCulling) { - CacheHandler->setCullFaceFunc(GL_BACK); + CacheHandler->setCullFaceFunc(GL.BACK); CacheHandler->setCullFace(true); } else if (material.FrontfaceCulling) { - CacheHandler->setCullFaceFunc(GL_FRONT); + CacheHandler->setCullFaceFunc(GL.FRONT); CacheHandler->setCullFace(true); } else @@ -1376,23 +1403,23 @@ COpenGL3DriverBase::~COpenGL3DriverBase() switch (material.BlendOperation) { case EBO_ADD: - CacheHandler->setBlendEquation(GL_FUNC_ADD); + CacheHandler->setBlendEquation(GL.FUNC_ADD); break; case EBO_SUBTRACT: - CacheHandler->setBlendEquation(GL_FUNC_SUBTRACT); + CacheHandler->setBlendEquation(GL.FUNC_SUBTRACT); break; case EBO_REVSUBTRACT: - CacheHandler->setBlendEquation(GL_FUNC_REVERSE_SUBTRACT); + CacheHandler->setBlendEquation(GL.FUNC_REVERSE_SUBTRACT); break; case EBO_MIN: if (BlendMinMaxSupported) - CacheHandler->setBlendEquation(GL_MIN); + CacheHandler->setBlendEquation(GL.MIN); else os::Printer::log("Attempt to use EBO_MIN without driver support", ELL_WARNING); break; case EBO_MAX: if (BlendMinMaxSupported) - CacheHandler->setBlendEquation(GL_MAX); + CacheHandler->setBlendEquation(GL.MAX); else os::Printer::log("Attempt to use EBO_MAX without driver support", ELL_WARNING); break; @@ -1422,15 +1449,15 @@ COpenGL3DriverBase::~COpenGL3DriverBase() // TODO: Polygon Offset. Not sure if it was left out deliberately or if it won't work with this driver. if (resetAllRenderStates || lastmaterial.Thickness != material.Thickness) - glLineWidth(core::clamp(static_cast(material.Thickness), DimAliasedLine[0], DimAliasedLine[1])); + GL.LineWidth(core::clamp(static_cast(material.Thickness), DimAliasedLine[0], DimAliasedLine[1])); // Anti aliasing if (resetAllRenderStates || lastmaterial.AntiAliasing != material.AntiAliasing) { if (material.AntiAliasing & EAAM_ALPHA_TO_COVERAGE) - glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); + GL.Enable(GL.SAMPLE_ALPHA_TO_COVERAGE); else if (lastmaterial.AntiAliasing & EAAM_ALPHA_TO_COVERAGE) - glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); + GL.Disable(GL.SAMPLE_ALPHA_TO_COVERAGE); } // Texture parameters @@ -1449,9 +1476,9 @@ COpenGL3DriverBase::~COpenGL3DriverBase() if (!tmpTexture) continue; - GLenum tmpTextureType = tmpTexture->getOpenGLTextureType(); + unsigned int tmpTextureType = tmpTexture->getOpenGLTextureType(); - CacheHandler->setActiveTexture(GL_TEXTURE0 + i); + CacheHandler->setActiveTexture(GL.TEXTURE0 + i); if (resetAllRenderstates) tmpTexture->getStatesCache().IsCached = false; @@ -1459,9 +1486,9 @@ COpenGL3DriverBase::~COpenGL3DriverBase() if (!tmpTexture->getStatesCache().IsCached || material.TextureLayers[i].MagFilter != tmpTexture->getStatesCache().MagFilter) { E_TEXTURE_MAG_FILTER magFilter = material.TextureLayers[i].MagFilter; - glTexParameteri(tmpTextureType, GL_TEXTURE_MAG_FILTER, - magFilter == ETMAGF_NEAREST ? GL_NEAREST : - (assert(magFilter == ETMAGF_LINEAR), GL_LINEAR)); + GL.TexParameteri(tmpTextureType, GL.TEXTURE_MAG_FILTER, + magFilter == ETMAGF_NEAREST ? GL.NEAREST : + (assert(magFilter == ETMAGF_LINEAR), GL.LINEAR)); tmpTexture->getStatesCache().MagFilter = magFilter; } @@ -1472,11 +1499,11 @@ COpenGL3DriverBase::~COpenGL3DriverBase() !tmpTexture->getStatesCache().MipMapStatus) { E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter; - glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER, - minFilter == ETMINF_NEAREST_MIPMAP_NEAREST ? GL_NEAREST_MIPMAP_NEAREST : - minFilter == ETMINF_LINEAR_MIPMAP_NEAREST ? GL_LINEAR_MIPMAP_NEAREST : - minFilter == ETMINF_NEAREST_MIPMAP_LINEAR ? GL_NEAREST_MIPMAP_LINEAR : - (assert(minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR_MIPMAP_LINEAR)); + GL.TexParameteri(tmpTextureType, GL.TEXTURE_MIN_FILTER, + minFilter == ETMINF_NEAREST_MIPMAP_NEAREST ? GL.NEAREST_MIPMAP_NEAREST : + minFilter == ETMINF_LINEAR_MIPMAP_NEAREST ? GL.LINEAR_MIPMAP_NEAREST : + minFilter == ETMINF_NEAREST_MIPMAP_LINEAR ? GL.NEAREST_MIPMAP_LINEAR : + (assert(minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL.LINEAR_MIPMAP_LINEAR)); tmpTexture->getStatesCache().MinFilter = minFilter; tmpTexture->getStatesCache().MipMapStatus = true; @@ -1488,9 +1515,9 @@ COpenGL3DriverBase::~COpenGL3DriverBase() tmpTexture->getStatesCache().MipMapStatus) { E_TEXTURE_MIN_FILTER minFilter = material.TextureLayers[i].MinFilter; - glTexParameteri(tmpTextureType, GL_TEXTURE_MIN_FILTER, - (minFilter == ETMINF_NEAREST_MIPMAP_NEAREST || minFilter == ETMINF_NEAREST_MIPMAP_LINEAR) ? GL_NEAREST : - (assert(minFilter == ETMINF_LINEAR_MIPMAP_NEAREST || minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL_LINEAR)); + GL.TexParameteri(tmpTextureType, GL.TEXTURE_MIN_FILTER, + (minFilter == ETMINF_NEAREST_MIPMAP_NEAREST || minFilter == ETMINF_NEAREST_MIPMAP_LINEAR) ? GL.NEAREST : + (assert(minFilter == ETMINF_LINEAR_MIPMAP_NEAREST || minFilter == ETMINF_LINEAR_MIPMAP_LINEAR), GL.LINEAR)); tmpTexture->getStatesCache().MinFilter = minFilter; tmpTexture->getStatesCache().MipMapStatus = false; @@ -1500,7 +1527,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() if (AnisotropicFilterSupported && (!tmpTexture->getStatesCache().IsCached || material.TextureLayers[i].AnisotropicFilter != tmpTexture->getStatesCache().AnisotropicFilter)) { - glTexParameteri(tmpTextureType, GL.TEXTURE_MAX_ANISOTROPY, + GL.TexParameteri(tmpTextureType, GL.TEXTURE_MAX_ANISOTROPY, material.TextureLayers[i].AnisotropicFilter>1 ? core::min_(MaxAnisotropy, material.TextureLayers[i].AnisotropicFilter) : 1); tmpTexture->getStatesCache().AnisotropicFilter = material.TextureLayers[i].AnisotropicFilter; @@ -1508,13 +1535,13 @@ COpenGL3DriverBase::~COpenGL3DriverBase() if (!tmpTexture->getStatesCache().IsCached || material.TextureLayers[i].TextureWrapU != tmpTexture->getStatesCache().WrapU) { - glTexParameteri(tmpTextureType, GL_TEXTURE_WRAP_S, getTextureWrapMode(material.TextureLayers[i].TextureWrapU)); + GL.TexParameteri(tmpTextureType, GL.TEXTURE_WRAP_S, getTextureWrapMode(material.TextureLayers[i].TextureWrapU)); tmpTexture->getStatesCache().WrapU = material.TextureLayers[i].TextureWrapU; } if (!tmpTexture->getStatesCache().IsCached || material.TextureLayers[i].TextureWrapV != tmpTexture->getStatesCache().WrapV) { - glTexParameteri(tmpTextureType, GL_TEXTURE_WRAP_T, getTextureWrapMode(material.TextureLayers[i].TextureWrapV)); + GL.TexParameteri(tmpTextureType, GL.TEXTURE_WRAP_T, getTextureWrapMode(material.TextureLayers[i].TextureWrapV)); tmpTexture->getStatesCache().WrapV = material.TextureLayers[i].TextureWrapV; } @@ -1524,18 +1551,18 @@ COpenGL3DriverBase::~COpenGL3DriverBase() // Get OpenGL ES2.0 texture wrap mode from Irrlicht wrap mode. - GLint COpenGL3DriverBase::getTextureWrapMode(u8 clamp) const + int COpenGL3DriverBase::getTextureWrapMode(u8 clamp) const { switch (clamp) { case ETC_CLAMP: case ETC_CLAMP_TO_EDGE: case ETC_CLAMP_TO_BORDER: - return GL_CLAMP_TO_EDGE; + return GL.CLAMP_TO_EDGE; case ETC_MIRROR: - return GL_REPEAT; + return GL.REPEAT; default: - return GL_REPEAT; + return GL.REPEAT; } } @@ -1576,8 +1603,8 @@ COpenGL3DriverBase::~COpenGL3DriverBase() if (alphaChannel || alpha) { CacheHandler->setBlend(true); - CacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - CacheHandler->setBlendEquation(GL_FUNC_ADD); + CacheHandler->setBlendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA); + CacheHandler->setBlendEquation(GL.FUNC_ADD); } else CacheHandler->setBlend(false); @@ -1650,7 +1677,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() vertices[0] = S3DVertex(start.X, start.Y, start.Z, 0, 0, 1, color, 0, 0); vertices[1] = S3DVertex(end.X, end.Y, end.Z, 0, 0, 1, color, 0, 0); - drawArrays(GL_LINES, vtPrimitive, vertices, 2); + drawArrays(GL.LINES, vtPrimitive, vertices, 2); } @@ -1894,7 +1921,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() void COpenGL3DriverBase::clearBuffers(u16 flag, SColor color, f32 depth, u8 stencil) { - GLbitfield mask = 0; + unsigned int mask = 0; u8 colorMask = 0; bool depthMask = false; @@ -1906,27 +1933,27 @@ COpenGL3DriverBase::~COpenGL3DriverBase() CacheHandler->setColorMask(ECP_ALL); const f32 inv = 1.0f / 255.0f; - glClearColor(color.getRed() * inv, color.getGreen() * inv, + GL.ClearColor(color.getRed() * inv, color.getGreen() * inv, color.getBlue() * inv, color.getAlpha() * inv); - mask |= GL_COLOR_BUFFER_BIT; + mask |= GL.COLOR_BUFFER_BIT; } if (flag & ECBF_DEPTH) { CacheHandler->setDepthMask(true); - glClearDepthf(depth); - mask |= GL_DEPTH_BUFFER_BIT; + GL.ClearDepthf(depth); + mask |= GL.DEPTH_BUFFER_BIT; } if (flag & ECBF_STENCIL) { - glClearStencil(stencil); - mask |= GL_STENCIL_BUFFER_BIT; + GL.ClearStencil(stencil); + mask |= GL.STENCIL_BUFFER_BIT; } if (mask) - glClear(mask); + GL.Clear(mask); CacheHandler->setColorMask(colorMask); CacheHandler->setDepthMask(depthMask); @@ -1942,30 +1969,30 @@ COpenGL3DriverBase::~COpenGL3DriverBase() if (target==video::ERT_MULTI_RENDER_TEXTURES || target==video::ERT_RENDER_TEXTURE || target==video::ERT_STEREO_BOTH_BUFFERS) return 0; - GLint internalformat = GL_RGBA; - GLint type = GL_UNSIGNED_BYTE; + int internalformat = GL.RGBA; + int type = GL.UNSIGNED_BYTE; { // glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &internalformat); // glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &type); // there's a format we don't support ATM - if (GL_UNSIGNED_SHORT_4_4_4_4 == type) + if (GL.UNSIGNED_SHORT_4_4_4_4 == type) { - internalformat = GL_RGBA; - type = GL_UNSIGNED_BYTE; + internalformat = GL.RGBA; + type = GL.UNSIGNED_BYTE; } } IImage* newImage = 0; - if (GL_RGBA == internalformat) + if (GL.RGBA == internalformat) { - if (GL_UNSIGNED_BYTE == type) + if (GL.UNSIGNED_BYTE == type) newImage = new CImage(ECF_A8R8G8B8, ScreenSize); else newImage = new CImage(ECF_A1R5G5B5, ScreenSize); } else { - if (GL_UNSIGNED_BYTE == type) + if (GL.UNSIGNED_BYTE == type) newImage = new CImage(ECF_R8G8B8, ScreenSize); else newImage = new CImage(ECF_R5G6B5, ScreenSize); @@ -1981,7 +2008,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() return 0; } - glReadPixels(0, 0, ScreenSize.Width, ScreenSize.Height, internalformat, type, pixels); + GL.ReadPixels(0, 0, ScreenSize.Width, ScreenSize.Height, internalformat, type, pixels); testGLError(__LINE__); // opengl images are horizontally flipped, so we have to fix that here. @@ -1998,8 +2025,8 @@ COpenGL3DriverBase::~COpenGL3DriverBase() } delete [] tmpBuffer; - // also GL_RGBA doesn't match the internal encoding of the image (which is BGRA) - if (GL_RGBA == internalformat && GL_UNSIGNED_BYTE == type) + // also GL.RGBA doesn't match the internal encoding of the image (which is BGRA) + if (GL.RGBA == internalformat && GL.UNSIGNED_BYTE == type) { pixels = static_cast(newImage->getData()); for (u32 i = 0; i < ScreenSize.Height; i++) @@ -2069,28 +2096,28 @@ COpenGL3DriverBase::~COpenGL3DriverBase() return core::dimension2du(MaxTextureSize, MaxTextureSize); } - GLenum COpenGL3DriverBase::getGLBlend(E_BLEND_FACTOR factor) const + unsigned int COpenGL3DriverBase::getGLBlend(E_BLEND_FACTOR factor) const { - static GLenum const blendTable[] = + static unsigned int const blendTable[] = { - GL_ZERO, - GL_ONE, - GL_DST_COLOR, - GL_ONE_MINUS_DST_COLOR, - GL_SRC_COLOR, - GL_ONE_MINUS_SRC_COLOR, - GL_SRC_ALPHA, - GL_ONE_MINUS_SRC_ALPHA, - GL_DST_ALPHA, - GL_ONE_MINUS_DST_ALPHA, - GL_SRC_ALPHA_SATURATE + GL.ZERO, + GL.ONE, + GL.DST_COLOR, + GL.ONE_MINUS_DST_COLOR, + GL.SRC_COLOR, + GL.ONE_MINUS_SRC_COLOR, + GL.SRC_ALPHA, + GL.ONE_MINUS_SRC_ALPHA, + GL.DST_ALPHA, + GL.ONE_MINUS_DST_ALPHA, + GL.SRC_ALPHA_SATURATE }; return blendTable[factor]; } - bool COpenGL3DriverBase::getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat, - GLenum& pixelType, void(**converter)(const void*, s32, void*)) const + bool COpenGL3DriverBase::getColorFormatParameters(ECOLOR_FORMAT format, int& internalFormat, unsigned int& pixelFormat, + unsigned int& pixelType, void(**converter)(const void*, s32, void*)) const { auto &info = TextureFormats[format]; internalFormat = info.InternalFormat; diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index 862c79d5e..5392fa6b4 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -271,10 +271,10 @@ namespace video bool needsTransparentRenderPass(const irr::video::SMaterial& material) const override; //! Convert E_BLEND_FACTOR to OpenGL equivalent - GLenum getGLBlend(E_BLEND_FACTOR factor) const; + unsigned int getGLBlend(E_BLEND_FACTOR factor) const; - virtual bool getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat, - GLenum& pixelType, void(**converter)(const void*, s32, void*)) const; + virtual bool getColorFormatParameters(ECOLOR_FORMAT format, int& internalFormat, unsigned int& pixelFormat, + unsigned int& pixelType, void(**converter)(const void*, s32, void*)) const; //! Get current material. const SMaterial& getCurrentMaterial() const; @@ -299,7 +299,7 @@ namespace video ITexture* createDeviceDependentTextureCubemap(const io::path& name, const core::array& image) override; //! Map Irrlicht wrap mode to OpenGL enum - GLint getTextureWrapMode(u8 clamp) const; + int getTextureWrapMode(u8 clamp) const; //! sets the needed renderstates void setRenderStates3DMode(); @@ -337,11 +337,11 @@ namespace video virtual void setViewPortRaw(u32 width, u32 height); void drawQuad(const VertexType &vertexType, const S3DVertex (&vertices)[4]); - void drawArrays(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount); - void drawElements(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount, const u16 *indices, int indexCount); - void drawElements(GLenum primitiveType, const VertexType &vertexType, uintptr_t vertices, uintptr_t indices, int indexCount); + void drawArrays(unsigned int primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount); + void drawElements(unsigned int primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount, const u16 *indices, int indexCount); + void drawElements(unsigned int primitiveType, const VertexType &vertexType, uintptr_t vertices, uintptr_t indices, int indexCount); - void beginDraw(const VertexType &vertexType, uintptr_t verticesBase); + void beginDraw(const VertexType &vertexType, int vertexCount, uintptr_t verticesBase); void endDraw(const VertexType &vertexType); COpenGL3CacheHandler* CacheHandler; @@ -367,9 +367,9 @@ namespace video using FColorConverter = void(*)(const void *source, s32 count, void *dest); struct STextureFormatInfo { - GLenum InternalFormat; - GLenum PixelFormat; - GLenum PixelType; + unsigned int InternalFormat; + unsigned int PixelFormat; + unsigned int PixelType; FColorConverter Converter; }; STextureFormatInfo TextureFormats[ECF_UNKNOWN] = {}; @@ -394,6 +394,15 @@ namespace video bool Transformation3DChanged; irr::io::path OGLES2ShaderPath; + // Changes the behavior of the beginDraw and endDraw methods. If true, the + // beginDraw method uses the global VBO, and if false, it uses the currently bound + // VBO. + bool UseGlobalVBO; + + // A nice global VAO and VBO to implement modern OpenGL as simply as possible + unsigned int GlobalVAO; + unsigned int GlobalVBO; + SMaterial Material, LastMaterial; //! Color buffer format @@ -404,11 +413,11 @@ namespace video void addDummyMaterial(E_MATERIAL_TYPE type); unsigned QuadIndexCount; - GLuint QuadIndexBuffer = 0; + unsigned int QuadIndexBuffer = 0; void initQuadsIndices(int max_vertex_count = 65536); - void debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message); - static void APIENTRY debugCb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam); + void debugCb(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, int length, const char *message); + static void APIENTRY debugCb(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, int length, const char *message, const void *userParam); }; } // end namespace video diff --git a/source/Irrlicht/OpenGL/ExtensionHandler.cpp b/source/Irrlicht/OpenGL/ExtensionHandler.cpp index 2e9757bad..1f183b9c9 100644 --- a/source/Irrlicht/OpenGL/ExtensionHandler.cpp +++ b/source/Irrlicht/OpenGL/ExtensionHandler.cpp @@ -17,7 +17,7 @@ namespace video { void COpenGL3ExtensionHandler::initExtensionsOld() { - auto extensions_string = reinterpret_cast(glGetString(GL_EXTENSIONS)); + auto extensions_string = reinterpret_cast(GL.GetString(GL.EXTENSIONS)); const char *pos = extensions_string; while (const char *next = strchr(pos, ' ')) { addExtension(std::string{pos, next}); @@ -29,9 +29,9 @@ namespace video void COpenGL3ExtensionHandler::initExtensionsNew() { - int ext_count = GetInteger(GL_NUM_EXTENSIONS); + int ext_count = GetInteger(GL.NUM_EXTENSIONS); for (int k = 0; k < ext_count; k++) - addExtension(reinterpret_cast(GL.GetStringi(GL_EXTENSIONS, k))); + addExtension(reinterpret_cast(GL.GetStringi(GL.EXTENSIONS, k))); updateLegacyExtensionList(); } diff --git a/source/Irrlicht/OpenGL/ExtensionHandler.h b/source/Irrlicht/OpenGL/ExtensionHandler.h index 84641dd48..fd27a5f04 100644 --- a/source/Irrlicht/OpenGL/ExtensionHandler.h +++ b/source/Irrlicht/OpenGL/ExtensionHandler.h @@ -77,82 +77,82 @@ namespace video }; } - static GLint GetInteger(GLenum key) { - GLint val = 0; - glGetIntegerv(key, &val); + static int GetInteger(unsigned int key) { + int val = 0; + GL.GetIntegerv(key, &val); return val; }; - inline void irrGlActiveTexture(GLenum texture) + inline void irrGlActiveTexture(unsigned int texture) { - glActiveTexture(texture); + GL.ActiveTexture(texture); } - inline void irrGlCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, - GLsizei imageSize, const void* data) + inline void irrGlCompressedTexImage2D(unsigned int target, int level, unsigned int internalformat, int width, int height, int border, + int imageSize, const void* data) { os::Printer::log("Compressed textures aren't supported", ELL_ERROR); } - inline void irrGlCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, - GLenum format, GLsizei imageSize, const void* data) + inline void irrGlCompressedTexSubImage2D(unsigned int target, int level, int xoffset, int yoffset, int width, int height, + unsigned int format, int imageSize, const void* data) { os::Printer::log("Compressed textures aren't supported", ELL_ERROR); } - inline void irrGlUseProgram(GLuint prog) + inline void irrGlUseProgram(unsigned int prog) { - glUseProgram(prog); + GL.UseProgram(prog); } - inline void irrGlBindFramebuffer(GLenum target, GLuint framebuffer) + inline void irrGlBindFramebuffer(unsigned int target, unsigned int framebuffer) { - glBindFramebuffer(target, framebuffer); + GL.BindFramebuffer(target, framebuffer); } - inline void irrGlDeleteFramebuffers(GLsizei n, const GLuint *framebuffers) + inline void irrGlDeleteFramebuffers(int n, const unsigned int *framebuffers) { - glDeleteFramebuffers(n, framebuffers); + GL.DeleteFramebuffers(n, framebuffers); } - inline void irrGlGenFramebuffers(GLsizei n, GLuint *framebuffers) + inline void irrGlGenFramebuffers(int n, unsigned int *framebuffers) { - glGenFramebuffers(n, framebuffers); + GL.GenFramebuffers(n, framebuffers); } - inline GLenum irrGlCheckFramebufferStatus(GLenum target) + inline unsigned int irrGlCheckFramebufferStatus(unsigned int target) { - return glCheckFramebufferStatus(target); + return GL.CheckFramebufferStatus(target); } - inline void irrGlFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) + inline void irrGlFramebufferTexture2D(unsigned int target, unsigned int attachment, unsigned int textarget, unsigned int texture, int level) { - glFramebufferTexture2D(target, attachment, textarget, texture, level); + GL.FramebufferTexture2D(target, attachment, textarget, texture, level); } - inline void irrGlGenerateMipmap(GLenum target) + inline void irrGlGenerateMipmap(unsigned int target) { - glGenerateMipmap(target); + GL.GenerateMipmap(target); } - inline void irrGlDrawBuffer(GLenum mode) + inline void irrGlDrawBuffer(unsigned int mode) { GL.DrawBuffer(mode); } - inline void irrGlDrawBuffers(GLsizei n, const GLenum *bufs) + inline void irrGlDrawBuffers(int n, const unsigned int *bufs) { GL.DrawBuffers(n, bufs); } - inline void irrGlBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) + inline void irrGlBlendFuncSeparate(unsigned int sfactorRGB, unsigned int dfactorRGB, unsigned int sfactorAlpha, unsigned int dfactorAlpha) { - glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha); + GL.BlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha); } - inline void irrGlBlendEquation(GLenum mode) + inline void irrGlBlendEquation(unsigned int mode) { - glBlendEquation(mode); + GL.BlendEquation(mode); } bool AnisotropicFilterSupported = false; diff --git a/source/Irrlicht/OpenGL/MaterialRenderer.cpp b/source/Irrlicht/OpenGL/MaterialRenderer.cpp index ab79ee538..ec0fe6bf7 100644 --- a/source/Irrlicht/OpenGL/MaterialRenderer.cpp +++ b/source/Irrlicht/OpenGL/MaterialRenderer.cpp @@ -84,21 +84,21 @@ COpenGL3MaterialRenderer::~COpenGL3MaterialRenderer() if (Program) { - GLuint shaders[8]; - GLint count; - glGetAttachedShaders(Program, 8, &count, shaders); + unsigned int shaders[8]; + int count; + GL.GetAttachedShaders(Program, 8, &count, shaders); count=core::min_(count,8); - for (GLint i=0; isetBlend(true); - cacheHandler->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + cacheHandler->setBlendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA); } else if (Blending) { @@ -194,32 +194,32 @@ s32 COpenGL3MaterialRenderer::getRenderCapability() const } -bool COpenGL3MaterialRenderer::createShader(GLenum shaderType, const char* shader) +bool COpenGL3MaterialRenderer::createShader(unsigned int shaderType, const char* shader) { if (Program) { - GLuint shaderHandle = glCreateShader(shaderType); - glShaderSource(shaderHandle, 1, &shader, NULL); - glCompileShader(shaderHandle); + unsigned int shaderHandle = GL.CreateShader(shaderType); + GL.ShaderSource(shaderHandle, 1, &shader, NULL); + GL.CompileShader(shaderHandle); - GLint status = 0; + int status = 0; - glGetShaderiv(shaderHandle, GL_COMPILE_STATUS, &status); + GL.GetShaderiv(shaderHandle, GL.COMPILE_STATUS, &status); - if (status != GL_TRUE) + if (status != true) { os::Printer::log("GLSL shader failed to compile", ELL_ERROR); - GLint maxLength=0; - GLint length; + int maxLength=0; + int length; - glGetShaderiv(shaderHandle, GL_INFO_LOG_LENGTH, + GL.GetShaderiv(shaderHandle, GL.INFO_LOG_LENGTH, &maxLength); if (maxLength) { - GLchar *infoLog = new GLchar[maxLength]; - glGetShaderInfoLog(shaderHandle, maxLength, &length, infoLog); + char *infoLog = new char[maxLength]; + GL.GetShaderInfoLog(shaderHandle, maxLength, &length, infoLog); os::Printer::log(reinterpret_cast(infoLog), ELL_ERROR); delete [] infoLog; } @@ -227,7 +227,7 @@ bool COpenGL3MaterialRenderer::createShader(GLenum shaderType, const char* shade return false; } - glAttachShader(Program, shaderHandle); + GL.AttachShader(Program, shaderHandle); } return true; @@ -238,25 +238,25 @@ bool COpenGL3MaterialRenderer::linkProgram() { if (Program) { - glLinkProgram(Program); + GL.LinkProgram(Program); - GLint status = 0; + int status = 0; - glGetProgramiv(Program, GL_LINK_STATUS, &status); + GL.GetProgramiv(Program, GL.LINK_STATUS, &status); if (!status) { os::Printer::log("GLSL shader program failed to link", ELL_ERROR); - GLint maxLength=0; - GLsizei length; + int maxLength=0; + int length; - glGetProgramiv(Program, GL_INFO_LOG_LENGTH, &maxLength); + GL.GetProgramiv(Program, GL.INFO_LOG_LENGTH, &maxLength); if (maxLength) { - GLchar *infoLog = new GLchar[maxLength]; - glGetProgramInfoLog(Program, maxLength, &length, infoLog); + char *infoLog = new char[maxLength]; + GL.GetProgramInfoLog(Program, maxLength, &length, infoLog); os::Printer::log(reinterpret_cast(infoLog), ELL_ERROR); delete [] infoLog; } @@ -264,16 +264,16 @@ bool COpenGL3MaterialRenderer::linkProgram() return false; } - GLint num = 0; + int num = 0; - glGetProgramiv(Program, GL_ACTIVE_UNIFORMS, &num); + GL.GetProgramiv(Program, GL.ACTIVE_UNIFORMS, &num); if (num == 0) return true; - GLint maxlen = 0; + int maxlen = 0; - glGetProgramiv(Program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxlen); + GL.GetProgramiv(Program, GL.ACTIVE_UNIFORM_MAX_LENGTH, &maxlen); if (maxlen == 0) { @@ -288,13 +288,13 @@ bool COpenGL3MaterialRenderer::linkProgram() UniformInfo.clear(); UniformInfo.reallocate(num); - for (GLint i=0; i < num; ++i) + for (int i=0; i < num; ++i) { SUniformInfo ui; memset(buf, 0, maxlen); - GLint size; - glGetActiveUniform(Program, i, maxlen, 0, &size, &ui.type, reinterpret_cast(buf)); + int size; + GL.GetActiveUniform(Program, i, maxlen, 0, &size, &ui.type, reinterpret_cast(buf)); core::stringc name = ""; @@ -308,7 +308,7 @@ bool COpenGL3MaterialRenderer::linkProgram() } ui.name = name; - ui.location = glGetUniformLocation(Program, buf); + ui.location = GL.GetUniformLocation(Program, buf); UniformInfo.push_back(ui); } @@ -377,34 +377,34 @@ bool COpenGL3MaterialRenderer::setPixelShaderConstant(s32 index, const f32* floa switch (UniformInfo[index].type) { - case GL_FLOAT: - glUniform1fv(UniformInfo[index].location, count, floats); + case OpenGLProcedures::FLOAT: + GL.Uniform1fv(UniformInfo[index].location, count, floats); break; - case GL_FLOAT_VEC2: - glUniform2fv(UniformInfo[index].location, count/2, floats); + case OpenGLProcedures::FLOAT_VEC2: + GL.Uniform2fv(UniformInfo[index].location, count/2, floats); break; - case GL_FLOAT_VEC3: - glUniform3fv(UniformInfo[index].location, count/3, floats); + case OpenGLProcedures::FLOAT_VEC3: + GL.Uniform3fv(UniformInfo[index].location, count/3, floats); break; - case GL_FLOAT_VEC4: - glUniform4fv(UniformInfo[index].location, count/4, floats); + case OpenGLProcedures::FLOAT_VEC4: + GL.Uniform4fv(UniformInfo[index].location, count/4, floats); break; - case GL_FLOAT_MAT2: - glUniformMatrix2fv(UniformInfo[index].location, count/4, false, floats); + case OpenGLProcedures::FLOAT_MAT2: + GL.UniformMatrix2fv(UniformInfo[index].location, count/4, false, floats); break; - case GL_FLOAT_MAT3: - glUniformMatrix3fv(UniformInfo[index].location, count/9, false, floats); + case OpenGLProcedures::FLOAT_MAT3: + GL.UniformMatrix3fv(UniformInfo[index].location, count/9, false, floats); break; - case GL_FLOAT_MAT4: - glUniformMatrix4fv(UniformInfo[index].location, count/16, false, floats); + case OpenGLProcedures::FLOAT_MAT4: + GL.UniformMatrix4fv(UniformInfo[index].location, count/16, false, floats); break; - case GL_SAMPLER_2D: - case GL_SAMPLER_CUBE: + case OpenGLProcedures::SAMPLER_2D: + case OpenGLProcedures::SAMPLER_CUBE: { if(floats) { - const GLint id = (GLint)(*floats); - glUniform1iv(UniformInfo[index].location, 1, &id); + const int id = (int)(*floats); + GL.Uniform1iv(UniformInfo[index].location, 1, &id); } else status = false; @@ -427,25 +427,25 @@ bool COpenGL3MaterialRenderer::setPixelShaderConstant(s32 index, const s32* ints switch (UniformInfo[index].type) { - case GL_INT: - case GL_BOOL: - glUniform1iv(UniformInfo[index].location, count, ints); + case OpenGLProcedures::INT: + case OpenGLProcedures::BOOL: + GL.Uniform1iv(UniformInfo[index].location, count, ints); break; - case GL_INT_VEC2: - case GL_BOOL_VEC2: - glUniform2iv(UniformInfo[index].location, count/2, ints); + case OpenGLProcedures::INT_VEC2: + case OpenGLProcedures::BOOL_VEC2: + GL.Uniform2iv(UniformInfo[index].location, count/2, ints); break; - case GL_INT_VEC3: - case GL_BOOL_VEC3: - glUniform3iv(UniformInfo[index].location, count/3, ints); + case OpenGLProcedures::INT_VEC3: + case OpenGLProcedures::BOOL_VEC3: + GL.Uniform3iv(UniformInfo[index].location, count/3, ints); break; - case GL_INT_VEC4: - case GL_BOOL_VEC4: - glUniform4iv(UniformInfo[index].location, count/4, ints); + case OpenGLProcedures::INT_VEC4: + case OpenGLProcedures::BOOL_VEC4: + GL.Uniform4iv(UniformInfo[index].location, count/4, ints); break; - case GL_SAMPLER_2D: - case GL_SAMPLER_CUBE: - glUniform1iv(UniformInfo[index].location, 1, ints); + case OpenGLProcedures::SAMPLER_2D: + case OpenGLProcedures::SAMPLER_CUBE: + GL.Uniform1iv(UniformInfo[index].location, 1, ints); break; default: status = false; diff --git a/source/Irrlicht/OpenGL/MaterialRenderer.h b/source/Irrlicht/OpenGL/MaterialRenderer.h index 5690ae674..8ada26d83 100644 --- a/source/Irrlicht/OpenGL/MaterialRenderer.h +++ b/source/Irrlicht/OpenGL/MaterialRenderer.h @@ -35,7 +35,7 @@ class COpenGL3MaterialRenderer : public IMaterialRenderer, public IMaterialRende virtual ~COpenGL3MaterialRenderer(); - GLuint getProgram() const; + unsigned int getProgram() const; virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates, IMaterialRendererServices* services); @@ -72,7 +72,7 @@ class COpenGL3MaterialRenderer : public IMaterialRenderer, public IMaterialRende void init(s32& outMaterialTypeNr, const c8* vertexShaderProgram, const c8* pixelShaderProgram, bool addMaterial = true); - bool createShader(GLenum shaderType, const char* shader); + bool createShader(unsigned int shaderType, const char* shader); bool linkProgram(); COpenGL3DriverBase* Driver; @@ -84,11 +84,11 @@ class COpenGL3MaterialRenderer : public IMaterialRenderer, public IMaterialRende struct SUniformInfo { core::stringc name; - GLenum type; - GLint location; + unsigned int type; + int location; }; - GLuint Program; + unsigned int Program; core::array UniformInfo; s32 UserData; }; diff --git a/source/Irrlicht/OpenGL3/Driver.cpp b/source/Irrlicht/OpenGL3/Driver.cpp index 70343a85a..79417a72b 100644 --- a/source/Irrlicht/OpenGL3/Driver.cpp +++ b/source/Irrlicht/OpenGL3/Driver.cpp @@ -14,42 +14,42 @@ namespace video { } OpenGLVersion COpenGL3Driver::getVersionFromOpenGL() const { - GLint major, minor, profile; - glGetIntegerv(GL_MAJOR_VERSION, &major); - glGetIntegerv(GL_MINOR_VERSION, &minor); - glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &profile); + int major, minor, profile; + GL.GetIntegerv(GL.MAJOR_VERSION, &major); + GL.GetIntegerv(GL.MINOR_VERSION, &minor); + GL.GetIntegerv(GL.CONTEXT_PROFILE_MASK, &profile); // The spec is clear a context can’t be both core and compatibility at the same time. // However, the returned value is a mask. Ask Khronos why. -- numzero - if (profile & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) + if (profile & GL.CONTEXT_COMPATIBILITY_PROFILE_BIT) return {OpenGLSpec::Compat, (u8)major, (u8)minor, 0}; - if (profile & GL_CONTEXT_CORE_PROFILE_BIT) + if (profile & GL.CONTEXT_CORE_PROFILE_BIT) return {OpenGLSpec::Core, (u8)major, (u8)minor, 0}; os::Printer::log("Got unrecognized OpenGL profile", ELL_ERROR); return {OpenGLSpec::Core, (u8)major, (u8)minor, 0}; } void COpenGL3Driver::initFeatures() { - assert (Version.Spec == OpenGLSpec::Compat); - assert (isVersionAtLeast(3, 2)); + assert (Version.Spec == OpenGLSpec::Core); + assert (isVersionAtLeast(3, 3)); initExtensionsNew(); - TextureFormats[ECF_A1R5G5B5] = {GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}; // WARNING: may not be renderable - TextureFormats[ECF_R5G6B5] = {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}; // GL_RGB565 is an extension until 4.1 - TextureFormats[ECF_R8G8B8] = {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}; // WARNING: may not be renderable - TextureFormats[ECF_A8R8G8B8] = {GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV}; - TextureFormats[ECF_R16F] = {GL_R16F, GL_RED, GL_HALF_FLOAT}; - TextureFormats[ECF_G16R16F] = {GL_RG16F, GL_RG, GL_HALF_FLOAT}; - TextureFormats[ECF_A16B16G16R16F] = {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT}; - TextureFormats[ECF_R32F] = {GL_R32F, GL_RED, GL_FLOAT}; - TextureFormats[ECF_G32R32F] = {GL_RG32F, GL_RG, GL_FLOAT}; - TextureFormats[ECF_A32B32G32R32F] = {GL_RGBA32F, GL_RGBA, GL_FLOAT}; - TextureFormats[ECF_R8] = {GL_R8, GL_RED, GL_UNSIGNED_BYTE}; - TextureFormats[ECF_R8G8] = {GL_RG8, GL_RG, GL_UNSIGNED_BYTE}; - TextureFormats[ECF_R16] = {GL_R16, GL_RED, GL_UNSIGNED_SHORT}; - TextureFormats[ECF_R16G16] = {GL_RG16, GL_RG, GL_UNSIGNED_SHORT}; - TextureFormats[ECF_D16] = {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}; - TextureFormats[ECF_D32] = {GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}; // WARNING: may not be renderable (?!) - TextureFormats[ECF_D24S8] = {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}; + TextureFormats[ECF_A1R5G5B5] = {GL.RGB5_A1, GL.BGRA, GL.UNSIGNED_SHORT_1_5_5_5_REV}; // WARNING: may not be renderable + TextureFormats[ECF_R5G6B5] = {GL.RGB, GL.RGB, GL.UNSIGNED_SHORT_5_6_5}; // GL_RGB565 is an extension until 4.1 + TextureFormats[ECF_R8G8B8] = {GL.RGB8, GL.RGB, GL.UNSIGNED_BYTE}; // WARNING: may not be renderable + TextureFormats[ECF_A8R8G8B8] = {GL.RGBA8, GL.BGRA, GL.UNSIGNED_INT_8_8_8_8_REV}; + TextureFormats[ECF_R16F] = {GL.R16F, GL.RED, GL.HALF_FLOAT}; + TextureFormats[ECF_G16R16F] = {GL.RG16F, GL.RG, GL.HALF_FLOAT}; + TextureFormats[ECF_A16B16G16R16F] = {GL.RGBA16F, GL.RGBA, GL.HALF_FLOAT}; + TextureFormats[ECF_R32F] = {GL.R32F, GL.RED, GL.FLOAT}; + TextureFormats[ECF_G32R32F] = {GL.RG32F, GL.RG, GL.FLOAT}; + TextureFormats[ECF_A32B32G32R32F] = {GL.RGBA32F, GL.RGBA, GL.FLOAT}; + TextureFormats[ECF_R8] = {GL.R8, GL.RED, GL.UNSIGNED_BYTE}; + TextureFormats[ECF_R8G8] = {GL.RG8, GL.RG, GL.UNSIGNED_BYTE}; + TextureFormats[ECF_R16] = {GL.R16, GL.RED, GL.UNSIGNED_SHORT}; + TextureFormats[ECF_R16G16] = {GL.RG16, GL.RG, GL.UNSIGNED_SHORT}; + TextureFormats[ECF_D16] = {GL.DEPTH_COMPONENT16, GL.DEPTH_COMPONENT, GL.UNSIGNED_SHORT}; + TextureFormats[ECF_D32] = {GL.DEPTH_COMPONENT32, GL.DEPTH_COMPONENT, GL.UNSIGNED_INT}; // WARNING: may not be renderable (?!) + TextureFormats[ECF_D24S8] = {GL.DEPTH24_STENCIL8, GL.DEPTH_STENCIL, GL.UNSIGNED_INT_24_8}; AnisotropicFilterSupported = isVersionAtLeast(4, 6) || queryExtension("GL_ARB_texture_filter_anisotropic") || queryExtension("GL_EXT_texture_filter_anisotropic"); BlendMinMaxSupported = true; @@ -57,17 +57,17 @@ namespace video { // COGLESCoreExtensionHandler::Feature static_assert(MATERIAL_MAX_TEXTURES <= 16, "Only up to 16 textures are guaranteed"); Feature.BlendOperation = true; - Feature.ColorAttachment = GetInteger(GL_MAX_COLOR_ATTACHMENTS); + Feature.ColorAttachment = GetInteger(GL.MAX_COLOR_ATTACHMENTS); Feature.MaxTextureUnits = MATERIAL_MAX_TEXTURES; - Feature.MultipleRenderTarget = GetInteger(GL_MAX_DRAW_BUFFERS); + Feature.MultipleRenderTarget = GetInteger(GL.MAX_DRAW_BUFFERS); // COGLESCoreExtensionHandler if (AnisotropicFilterSupported) MaxAnisotropy = GetInteger(GL.MAX_TEXTURE_MAX_ANISOTROPY); - MaxIndices = GetInteger(GL_MAX_ELEMENTS_INDICES); - MaxTextureSize = GetInteger(GL_MAX_TEXTURE_SIZE); - glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias); - glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); + MaxIndices = GetInteger(GL.MAX_ELEMENTS_INDICES); + MaxTextureSize = GetInteger(GL.MAX_TEXTURE_SIZE); + GL.GetFloatv(GL.MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias); + GL.GetFloatv(GL.ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); DimAliasedPoint[0] = 1.0f; DimAliasedPoint[1] = 1.0f; } diff --git a/source/Irrlicht/OpenGLES2/Driver.cpp b/source/Irrlicht/OpenGLES2/Driver.cpp index 2e80e1be9..963893e23 100644 --- a/source/Irrlicht/OpenGLES2/Driver.cpp +++ b/source/Irrlicht/OpenGLES2/Driver.cpp @@ -14,7 +14,7 @@ namespace video { } OpenGLVersion COpenGLES2Driver::getVersionFromOpenGL() const { - auto version_string = reinterpret_cast(glGetString(GL_VERSION)); + auto version_string = reinterpret_cast(GL.GetString(GL.VERSION)); int major, minor; if (sscanf(version_string, "OpenGL ES %d.%d", &major, &minor) != 2) { os::Printer::log("Failed to parse OpenGL ES version string", version_string, ELL_ERROR); @@ -33,71 +33,71 @@ namespace video { if (Version.Major >= 3) { // NOTE floating-point formats may not be suitable for render targets. - TextureFormats[ECF_A1R5G5B5] = {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, CColorConverter::convert_A1R5G5B5toR5G5B5A1}; - TextureFormats[ECF_R5G6B5] = {GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}; - TextureFormats[ECF_R8G8B8] = {GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}; - TextureFormats[ECF_A8R8G8B8] = {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, CColorConverter::convert_A8R8G8B8toA8B8G8R8}; - TextureFormats[ECF_R16F] = {GL_R16F, GL_RED, GL_HALF_FLOAT}; - TextureFormats[ECF_G16R16F] = {GL_RG16F, GL_RG, GL_HALF_FLOAT}; - TextureFormats[ECF_A16B16G16R16F] = {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT}; - TextureFormats[ECF_R32F] = {GL_R32F, GL_RED, GL_FLOAT}; - TextureFormats[ECF_G32R32F] = {GL_RG32F, GL_RG, GL_FLOAT}; - TextureFormats[ECF_A32B32G32R32F] = {GL_RGBA32F, GL_RGBA, GL_FLOAT}; - TextureFormats[ECF_R8] = {GL_R8, GL_RED, GL_UNSIGNED_BYTE}; - TextureFormats[ECF_R8G8] = {GL_RG8, GL_RG, GL_UNSIGNED_BYTE}; - TextureFormats[ECF_D16] = {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}; - TextureFormats[ECF_D24S8] = {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}; + TextureFormats[ECF_A1R5G5B5] = {GL.RGB5_A1, GL.RGBA, GL.UNSIGNED_SHORT_5_5_5_1, CColorConverter::convert_A1R5G5B5toR5G5B5A1}; + TextureFormats[ECF_R5G6B5] = {GL.RGB565, GL.RGB, GL.UNSIGNED_SHORT_5_6_5}; + TextureFormats[ECF_R8G8B8] = {GL.RGB8, GL.RGB, GL.UNSIGNED_BYTE}; + TextureFormats[ECF_A8R8G8B8] = {GL.RGBA8, GL.RGBA, GL.UNSIGNED_BYTE, CColorConverter::convert_A8R8G8B8toA8B8G8R8}; + TextureFormats[ECF_R16F] = {GL.R16F, GL.RED, GL.HALF_FLOAT}; + TextureFormats[ECF_G16R16F] = {GL.RG16F, GL.RG, GL.HALF_FLOAT}; + TextureFormats[ECF_A16B16G16R16F] = {GL.RGBA16F, GL.RGBA, GL.HALF_FLOAT}; + TextureFormats[ECF_R32F] = {GL.R32F, GL.RED, GL.FLOAT}; + TextureFormats[ECF_G32R32F] = {GL.RG32F, GL.RG, GL.FLOAT}; + TextureFormats[ECF_A32B32G32R32F] = {GL.RGBA32F, GL.RGBA, GL.FLOAT}; + TextureFormats[ECF_R8] = {GL.R8, GL.RED, GL.UNSIGNED_BYTE}; + TextureFormats[ECF_R8G8] = {GL.RG8, GL.RG, GL.UNSIGNED_BYTE}; + TextureFormats[ECF_D16] = {GL.DEPTH_COMPONENT16, GL.DEPTH_COMPONENT, GL.UNSIGNED_SHORT}; + TextureFormats[ECF_D24S8] = {GL.DEPTH24_STENCIL8, GL.DEPTH_STENCIL, GL.UNSIGNED_INT_24_8}; if (FeatureAvailable[IRR_GL_EXT_texture_format_BGRA8888]) - TextureFormats[ECF_A8R8G8B8] = {GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_A8R8G8B8] = {GL.RGBA, GL.BGRA, GL.UNSIGNED_BYTE}; else if (FeatureAvailable[IRR_GL_APPLE_texture_format_BGRA8888]) - TextureFormats[ECF_A8R8G8B8] = {GL_BGRA, GL_BGRA, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_A8R8G8B8] = {GL.BGRA, GL.BGRA, GL.UNSIGNED_BYTE}; if (FeatureAvailable[IRR_GL_OES_depth32]) - TextureFormats[ECF_D32] = {GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}; + TextureFormats[ECF_D32] = {GL.DEPTH_COMPONENT32, GL.DEPTH_COMPONENT, GL.UNSIGNED_INT}; } else { // NOTE These are *texture* formats. They may or may not be suitable // for render targets. The specs only talks on *sized* formats for the // latter but forbids creating textures with sized internal formats, // reserving them for renderbuffers. - static const GLenum HALF_FLOAT_OES = 0x8D61; // not equal to GL_HALF_FLOAT - TextureFormats[ECF_A1R5G5B5] = {GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, CColorConverter::convert_A1R5G5B5toR5G5B5A1}; - TextureFormats[ECF_R5G6B5] = {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}; - TextureFormats[ECF_R8G8B8] = {GL_RGB, GL_RGB, GL_UNSIGNED_BYTE}; - TextureFormats[ECF_A8R8G8B8] = {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, CColorConverter::convert_A8R8G8B8toA8B8G8R8}; + static const unsigned int HALF_FLOAT_OES = 0x8D61; // not equal to GL_HALF_FLOAT + TextureFormats[ECF_A1R5G5B5] = {GL.RGBA, GL.RGBA, GL.UNSIGNED_SHORT_5_5_5_1, CColorConverter::convert_A1R5G5B5toR5G5B5A1}; + TextureFormats[ECF_R5G6B5] = {GL.RGB, GL.RGB, GL.UNSIGNED_SHORT_5_6_5}; + TextureFormats[ECF_R8G8B8] = {GL.RGB, GL.RGB, GL.UNSIGNED_BYTE}; + TextureFormats[ECF_A8R8G8B8] = {GL.RGBA, GL.RGBA, GL.UNSIGNED_BYTE, CColorConverter::convert_A8R8G8B8toA8B8G8R8}; if (FeatureAvailable[IRR_GL_EXT_texture_format_BGRA8888]) - TextureFormats[ECF_A8R8G8B8] = {GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_A8R8G8B8] = {GL.RGBA, GL.BGRA, GL.UNSIGNED_BYTE}; else if (FeatureAvailable[IRR_GL_APPLE_texture_format_BGRA8888]) - TextureFormats[ECF_A8R8G8B8] = {GL_BGRA, GL_BGRA, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_A8R8G8B8] = {GL.BGRA, GL.BGRA, GL.UNSIGNED_BYTE}; if (FeatureAvailable[IRR_GL_OES_texture_half_float]) { - TextureFormats[ECF_A16B16G16R16F] = {GL_RGBA, GL_RGBA, HALF_FLOAT_OES}; + TextureFormats[ECF_A16B16G16R16F] = {GL.RGBA, GL.RGBA, HALF_FLOAT_OES}; } if (FeatureAvailable[IRR_GL_OES_texture_float]) { - TextureFormats[ECF_A32B32G32R32F] = {GL_RGBA, GL_RGBA, GL_FLOAT}; + TextureFormats[ECF_A32B32G32R32F] = {GL.RGBA, GL.RGBA, GL.FLOAT}; } if (FeatureAvailable[IRR_GL_EXT_texture_rg]) { - TextureFormats[ECF_R8] = {GL_RED, GL_RED, GL_UNSIGNED_BYTE}; - TextureFormats[ECF_R8G8] = {GL_RG, GL_RG, GL_UNSIGNED_BYTE}; + TextureFormats[ECF_R8] = {GL.RED, GL.RED, GL.UNSIGNED_BYTE}; + TextureFormats[ECF_R8G8] = {GL.RG, GL.RG, GL.UNSIGNED_BYTE}; if (FeatureAvailable[IRR_GL_OES_texture_half_float]) { - TextureFormats[ECF_R16F] = {GL_RED, GL_RED, HALF_FLOAT_OES}; - TextureFormats[ECF_G16R16F] = {GL_RG, GL_RG, HALF_FLOAT_OES}; + TextureFormats[ECF_R16F] = {GL.RED, GL.RED, HALF_FLOAT_OES}; + TextureFormats[ECF_G16R16F] = {GL.RG, GL.RG, HALF_FLOAT_OES}; } if (FeatureAvailable[IRR_GL_OES_texture_float]) { - TextureFormats[ECF_R32F] = {GL_RED, GL_RED, GL_FLOAT}; - TextureFormats[ECF_G32R32F] = {GL_RG, GL_RG, GL_FLOAT}; + TextureFormats[ECF_R32F] = {GL.RED, GL.RED, GL.FLOAT}; + TextureFormats[ECF_G32R32F] = {GL.RG, GL.RG, GL.FLOAT}; } } if (FeatureAvailable[IRR_GL_OES_depth_texture]) { - TextureFormats[ECF_D16] = {GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}; + TextureFormats[ECF_D16] = {GL.DEPTH_COMPONENT, GL.DEPTH_COMPONENT, GL.UNSIGNED_SHORT}; if (FeatureAvailable[IRR_GL_OES_depth32]) - TextureFormats[ECF_D32] = {GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT}; + TextureFormats[ECF_D32] = {GL.DEPTH_COMPONENT, GL.DEPTH_COMPONENT, GL.UNSIGNED_INT}; if (FeatureAvailable[IRR_GL_OES_packed_depth_stencil]) - TextureFormats[ECF_D24S8] = {GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}; + TextureFormats[ECF_D24S8] = {GL.DEPTH_STENCIL, GL.DEPTH_STENCIL, GL.UNSIGNED_INT_24_8}; } } @@ -111,21 +111,23 @@ namespace video { Feature.BlendOperation = true; Feature.ColorAttachment = 1; if (MRTSupported) - Feature.ColorAttachment = GetInteger(GL_MAX_COLOR_ATTACHMENTS); + Feature.ColorAttachment = GetInteger(GL.MAX_COLOR_ATTACHMENTS); Feature.MaxTextureUnits = MATERIAL_MAX_TEXTURES; if (MRTSupported) - Feature.MultipleRenderTarget = GetInteger(GL_MAX_DRAW_BUFFERS); + Feature.MultipleRenderTarget = GetInteger(GL.MAX_DRAW_BUFFERS); // COGLESCoreExtensionHandler - if (AnisotropicFilterSupported) - MaxAnisotropy = GetInteger(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT); + // TODO: Replace this with something in mt_opengl.h + //if (AnisotropicFilterSupported) + //MaxAnisotropy = GetInteger(GL.MAX_TEXTURE_MAX_ANISOTROPY_EXT); if (Version.Major >= 3 || queryExtension("GL_EXT_draw_range_elements")) - MaxIndices = GetInteger(GL_MAX_ELEMENTS_INDICES); - MaxTextureSize = GetInteger(GL_MAX_TEXTURE_SIZE); + MaxIndices = GetInteger(GL.MAX_ELEMENTS_INDICES); + MaxTextureSize = GetInteger(GL.MAX_TEXTURE_SIZE); if (TextureLODBiasSupported) - glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias); - glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); // NOTE: this is not in the OpenGL ES 2.0 spec... - glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, DimAliasedPoint); + GL.GetFloatv(GL.MAX_TEXTURE_LOD_BIAS, &MaxTextureLODBias); + GL.GetFloatv(GL.ALIASED_LINE_WIDTH_RANGE, DimAliasedLine); // NOTE: this is not in the OpenGL ES 2.0 spec... + // TODO: Replace this with something in mt_opengl.h + //GL.GetFloatv(GL.ALIASED_POINT_SIZE_RANGE, DimAliasedPoint); } IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)