From 251ac0422723f826e0e01c928de58b2f8c89f5d0 Mon Sep 17 00:00:00 2001 From: Caleb Butler Date: Sun, 10 Sep 2023 23:59:29 -0400 Subject: [PATCH 01/10] Switch to Core OpenGL 3.3 Profile This profile does not allow any pre-modern OpenGL practices, making it a good way to make sure the OpenGL 3 video driver is resilient to different OpenGL implementations (especially the ones that only support modern practices). --- source/Irrlicht/CIrrDeviceSDL.cpp | 4 ++-- source/Irrlicht/OpenGL/Driver.cpp | 2 +- source/Irrlicht/OpenGL3/Driver.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index fdc091f8a..3b5b92865 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -254,7 +254,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() setTransform(static_cast(i), core::IdentityMatrix); setAmbientLight(SColorf(0.0f, 0.0f, 0.0f, 0.0f)); - glClearDepthf(1.0f); + glClearDepthf(1.0); glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); glFrontFace(GL_CW); diff --git a/source/Irrlicht/OpenGL3/Driver.cpp b/source/Irrlicht/OpenGL3/Driver.cpp index 70343a85a..5612fb63c 100644 --- a/source/Irrlicht/OpenGL3/Driver.cpp +++ b/source/Irrlicht/OpenGL3/Driver.cpp @@ -29,7 +29,7 @@ namespace video { } void COpenGL3Driver::initFeatures() { - assert (Version.Spec == OpenGLSpec::Compat); + assert (Version.Spec == OpenGLSpec::Core); assert (isVersionAtLeast(3, 2)); initExtensionsNew(); From fd9e8b9cfe4a64583710949405b937cf1367f164 Mon Sep 17 00:00:00 2001 From: Caleb Butler Date: Mon, 11 Sep 2023 08:38:57 -0400 Subject: [PATCH 02/10] Made the Core Profile render a little more There are still major graphical glitches that make it unplayable, but the GUI is rendering as well as many game objects. --- source/Irrlicht/COpenGLCoreTexture.h | 2 +- source/Irrlicht/OpenGL/Driver.cpp | 39 +++++++++++++++++++--------- source/Irrlicht/OpenGL/Driver.h | 4 +-- source/Irrlicht/OpenGL3/Driver.cpp | 4 +-- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/source/Irrlicht/COpenGLCoreTexture.h b/source/Irrlicht/COpenGLCoreTexture.h index 984d2ecc8..4debc4c10 100644 --- a/source/Irrlicht/COpenGLCoreTexture.h +++ b/source/Irrlicht/COpenGLCoreTexture.h @@ -98,7 +98,7 @@ class COpenGLCoreTexture : public ITexture glTexParameteri(TextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST); -#ifdef GL_GENERATE_MIPMAP_HINT +#if 0 if (HasMipMaps) { if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED)) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 3b5b92865..47c3207ac 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -156,6 +156,11 @@ COpenGL3DriverBase::COpenGL3DriverBase(const SIrrlichtCreationParameters& params ContextManager->activateContext(ExposedData, false); GL.LoadAllProcedures(ContextManager); GL.DebugMessageCallback(debugCb, this); + + unsigned int vao; + GL.GenVertexArrays(1, &vao); + GL.BindVertexArray(vao); + initQuadsIndices(); } @@ -256,7 +261,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() setAmbientLight(SColorf(0.0f, 0.0f, 0.0f, 0.0f)); glClearDepthf(1.0); - glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); + //glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); glFrontFace(GL_CW); // create material renderers @@ -716,7 +721,6 @@ COpenGL3DriverBase::~COpenGL3DriverBase() setRenderStates3DMode(); auto &vTypeDesc = getVertexTypeDescription(vType); - beginDraw(vTypeDesc, reinterpret_cast(vertices)); GLenum indexSize = 0; switch (iType) @@ -741,6 +745,8 @@ COpenGL3DriverBase::~COpenGL3DriverBase() } } + unsigned int vbo = beginDraw(vTypeDesc, vertexCount, reinterpret_cast(vertices)); + switch (pType) { case scene::EPT_POINTS: @@ -769,7 +775,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() break; } - endDraw(vTypeDesc); + endDraw(vTypeDesc, vbo); } @@ -1096,32 +1102,41 @@ COpenGL3DriverBase::~COpenGL3DriverBase() void COpenGL3DriverBase::drawArrays(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount) { - beginDraw(vertexType, reinterpret_cast(vertices)); + unsigned int vbo = beginDraw(vertexType, vertexCount, reinterpret_cast(vertices)); glDrawArrays(primitiveType, 0, vertexCount); - endDraw(vertexType); + endDraw(vertexType, vbo); } void COpenGL3DriverBase::drawElements(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount, const u16 *indices, int indexCount) { - beginDraw(vertexType, reinterpret_cast(vertices)); + unsigned int vbo = beginDraw(vertexType, vertexCount, reinterpret_cast(vertices)); glDrawRangeElements(primitiveType, 0, vertexCount - 1, indexCount, GL_UNSIGNED_SHORT, indices); - endDraw(vertexType); + endDraw(vertexType, vbo); } - void COpenGL3DriverBase::beginDraw(const VertexType &vertexType, uintptr_t verticesBase) + unsigned int COpenGL3DriverBase::beginDraw(const VertexType &vertexType, int vertexCount, uintptr_t verticesBase) { + unsigned int vbo; + glGenBuffers(1, &vbo); + glBindBuffer(GL_ARRAY_BUFFER, vbo); + glBufferData(GL_ARRAY_BUFFER, vertexType.VertexSize * vertexCount, reinterpret_cast(verticesBase), GL_STREAM_DRAW); + 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; + case VertexAttribute::Mode::Regular: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_FALSE, vertexType.VertexSize, reinterpret_cast(attr.Offset)); break; + case VertexAttribute::Mode::Normalized: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_TRUE, vertexType.VertexSize, reinterpret_cast(attr.Offset)); break; + case VertexAttribute::Mode::Integral: glVertexAttribIPointer(attr.Index, attr.ComponentCount, attr.ComponentType, vertexType.VertexSize, reinterpret_cast(attr.Offset)); break; } } + + return vbo; } - void COpenGL3DriverBase::endDraw(const VertexType &vertexType) + void COpenGL3DriverBase::endDraw(const VertexType &vertexType, unsigned int vbo) { + glBindBuffer(GL_ARRAY_BUFFER, 0); + glDeleteBuffers(1, &vbo); for (auto attr: vertexType) glDisableVertexAttribArray(attr.Index); } diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index 862c79d5e..9a4c85fac 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -341,8 +341,8 @@ namespace video 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 beginDraw(const VertexType &vertexType, uintptr_t verticesBase); - void endDraw(const VertexType &vertexType); + unsigned int beginDraw(const VertexType &vertexType, int vertexCount, uintptr_t verticesBase); + void endDraw(const VertexType &vertexType, unsigned int vbo); COpenGL3CacheHandler* CacheHandler; core::stringw Name; diff --git a/source/Irrlicht/OpenGL3/Driver.cpp b/source/Irrlicht/OpenGL3/Driver.cpp index 5612fb63c..d0c3da5fc 100644 --- a/source/Irrlicht/OpenGL3/Driver.cpp +++ b/source/Irrlicht/OpenGL3/Driver.cpp @@ -29,8 +29,8 @@ namespace video { } void COpenGL3Driver::initFeatures() { - assert (Version.Spec == OpenGLSpec::Core); - 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 From d10260e619fa34e50fb99736e9232a28f58e907d Mon Sep 17 00:00:00 2001 From: Caleb Butler Date: Mon, 11 Sep 2023 11:39:09 -0400 Subject: [PATCH 03/10] Fix Graphical Glitches in drawHardwareBuffer The game is now playable and the driver is working correctly! --- source/Irrlicht/OpenGL/Driver.cpp | 58 ++++++++++++++++++++----------- source/Irrlicht/OpenGL/Driver.h | 4 +++ 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 47c3207ac..a49874539 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -134,13 +134,15 @@ void COpenGL3DriverBase::debugCb(GLenum source, GLenum type, GLuint id, GLenum s 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), + CreateNewVBOs(true), ColorFormat(ECF_R8G8B8), ContextManager(contextManager) { #ifdef _DEBUG setDebugName("Driver"); @@ -675,12 +677,15 @@ COpenGL3DriverBase::~COpenGL3DriverBase() indexList = 0; } + CreateNewVBOs = false; drawVertexPrimitiveList(vertices, mb->getVertexCount(), indexList, mb->getPrimitiveCount(), mb->getVertexType(), mb->getPrimitiveType(), mb->getIndexType()); + CreateNewVBOs = true; + if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -1116,17 +1121,28 @@ COpenGL3DriverBase::~COpenGL3DriverBase() unsigned int COpenGL3DriverBase::beginDraw(const VertexType &vertexType, int vertexCount, uintptr_t verticesBase) { - unsigned int vbo; - glGenBuffers(1, &vbo); - glBindBuffer(GL_ARRAY_BUFFER, vbo); - glBufferData(GL_ARRAY_BUFFER, vertexType.VertexSize * vertexCount, reinterpret_cast(verticesBase), GL_STREAM_DRAW); - - 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(attr.Offset)); break; - case VertexAttribute::Mode::Normalized: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_TRUE, vertexType.VertexSize, reinterpret_cast(attr.Offset)); break; - case VertexAttribute::Mode::Integral: glVertexAttribIPointer(attr.Index, attr.ComponentCount, attr.ComponentType, vertexType.VertexSize, reinterpret_cast(attr.Offset)); break; + unsigned int vbo = 0; + + if (CreateNewVBOs) { + glGenBuffers(1, &vbo); + glBindBuffer(GL_ARRAY_BUFFER, vbo); + glBufferData(GL_ARRAY_BUFFER, vertexType.VertexSize * vertexCount, reinterpret_cast(verticesBase), GL_STREAM_DRAW); + 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(attr.Offset)); break; + case VertexAttribute::Mode::Normalized: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_TRUE, vertexType.VertexSize, reinterpret_cast(attr.Offset)); break; + case VertexAttribute::Mode::Integral: glVertexAttribIPointer(attr.Index, attr.ComponentCount, attr.ComponentType, vertexType.VertexSize, reinterpret_cast(attr.Offset)); break; + } + } + } else { + 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; + } } } @@ -1135,10 +1151,12 @@ COpenGL3DriverBase::~COpenGL3DriverBase() void COpenGL3DriverBase::endDraw(const VertexType &vertexType, unsigned int vbo) { - glBindBuffer(GL_ARRAY_BUFFER, 0); - glDeleteBuffers(1, &vbo); for (auto attr: vertexType) glDisableVertexAttribArray(attr.Index); + if (CreateNewVBOs) { + glBindBuffer(GL_ARRAY_BUFFER, 0); + glDeleteBuffers(1, &vbo); + } } ITexture* COpenGL3DriverBase::createDeviceDependentTexture(const io::path& name, IImage* image) diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index 9a4c85fac..f5ff2773d 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -394,6 +394,10 @@ namespace video bool Transformation3DChanged; irr::io::path OGLES2ShaderPath; + // Changes the behavior of the beginDraw and endDraw methods. If true, the + // beginDraw method allocates a VBO, and if false, it uses the already bound VBO. + bool CreateNewVBOs; + SMaterial Material, LastMaterial; //! Color buffer format From 7ab402323a589397f01716a122c97d0bcd2a2063 Mon Sep 17 00:00:00 2001 From: Caleb Butler Date: Mon, 11 Sep 2023 12:02:52 -0400 Subject: [PATCH 04/10] Add minor optimizations I added a minor optimization that removed the allocation of new VBOs every beginDraw call. Instead there is a global VBO used by all beginDraw calls except ones called by drawHardwareBuffer. Still inefficient and can be vastly improved, but at least it's better than before. --- source/Irrlicht/OpenGL/Driver.cpp | 43 ++++++++++++++----------------- source/Irrlicht/OpenGL/Driver.h | 13 +++++++--- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index a49874539..0b5b8375d 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -142,7 +142,7 @@ COpenGL3DriverBase::COpenGL3DriverBase(const SIrrlichtCreationParameters ¶ms MaterialRenderer2DActive(0), MaterialRenderer2DTexture(0), MaterialRenderer2DNoTexture(0), CurrentRenderMode(ERM_NONE), Transformation3DChanged(true), OGLES2ShaderPath(params.OGLES2ShaderPath), - CreateNewVBOs(true), ColorFormat(ECF_R8G8B8), ContextManager(contextManager) + UseGlobalVBO(true), ColorFormat(ECF_R8G8B8), ContextManager(contextManager) { #ifdef _DEBUG setDebugName("Driver"); @@ -159,9 +159,10 @@ COpenGL3DriverBase::COpenGL3DriverBase(const SIrrlichtCreationParameters ¶ms GL.LoadAllProcedures(ContextManager); GL.DebugMessageCallback(debugCb, this); - unsigned int vao; - GL.GenVertexArrays(1, &vao); - GL.BindVertexArray(vao); + GL.GenVertexArrays(1, &GlobalVAO); + GL.BindVertexArray(GlobalVAO); + + GL.GenBuffers(1, &GlobalVBO); initQuadsIndices(); } @@ -677,14 +678,14 @@ COpenGL3DriverBase::~COpenGL3DriverBase() indexList = 0; } - CreateNewVBOs = false; + UseGlobalVBO = false; drawVertexPrimitiveList(vertices, mb->getVertexCount(), indexList, mb->getPrimitiveCount(), mb->getVertexType(), mb->getPrimitiveType(), mb->getIndexType()); - CreateNewVBOs = true; + UseGlobalVBO = true; if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -750,7 +751,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() } } - unsigned int vbo = beginDraw(vTypeDesc, vertexCount, reinterpret_cast(vertices)); + beginDraw(vTypeDesc, vertexCount, reinterpret_cast(vertices)); switch (pType) { @@ -780,7 +781,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() break; } - endDraw(vTypeDesc, vbo); + endDraw(vTypeDesc); } @@ -1107,26 +1108,24 @@ COpenGL3DriverBase::~COpenGL3DriverBase() void COpenGL3DriverBase::drawArrays(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount) { - unsigned int vbo = beginDraw(vertexType, vertexCount, reinterpret_cast(vertices)); + beginDraw(vertexType, vertexCount, reinterpret_cast(vertices)); glDrawArrays(primitiveType, 0, vertexCount); - endDraw(vertexType, vbo); + endDraw(vertexType); } void COpenGL3DriverBase::drawElements(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount, const u16 *indices, int indexCount) { - unsigned int vbo = beginDraw(vertexType, vertexCount, reinterpret_cast(vertices)); + beginDraw(vertexType, vertexCount, reinterpret_cast(vertices)); glDrawRangeElements(primitiveType, 0, vertexCount - 1, indexCount, GL_UNSIGNED_SHORT, indices); - endDraw(vertexType, vbo); + endDraw(vertexType); } - unsigned int COpenGL3DriverBase::beginDraw(const VertexType &vertexType, int vertexCount, uintptr_t verticesBase) + void COpenGL3DriverBase::beginDraw(const VertexType &vertexType, int vertexCount, uintptr_t verticesBase) { - unsigned int vbo = 0; - if (CreateNewVBOs) { - glGenBuffers(1, &vbo); - glBindBuffer(GL_ARRAY_BUFFER, vbo); - glBufferData(GL_ARRAY_BUFFER, vertexType.VertexSize * vertexCount, reinterpret_cast(verticesBase), GL_STREAM_DRAW); + if (UseGlobalVBO) { + glBindBuffer(GL_ARRAY_BUFFER, GlobalVBO); + glBufferData(GL_ARRAY_BUFFER, vertexType.VertexSize * vertexCount, reinterpret_cast(verticesBase), GL_DYNAMIC_DRAW); for (auto attr: vertexType) { glEnableVertexAttribArray(attr.Index); switch (attr.mode) { @@ -1145,18 +1144,14 @@ COpenGL3DriverBase::~COpenGL3DriverBase() } } } - - return vbo; } - void COpenGL3DriverBase::endDraw(const VertexType &vertexType, unsigned int vbo) + void COpenGL3DriverBase::endDraw(const VertexType &vertexType) { for (auto attr: vertexType) glDisableVertexAttribArray(attr.Index); - if (CreateNewVBOs) { + if (UseGlobalVBO) glBindBuffer(GL_ARRAY_BUFFER, 0); - glDeleteBuffers(1, &vbo); - } } ITexture* COpenGL3DriverBase::createDeviceDependentTexture(const io::path& name, IImage* image) diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index f5ff2773d..cee8935c4 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -341,8 +341,8 @@ namespace video 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); - unsigned int beginDraw(const VertexType &vertexType, int vertexCount, uintptr_t verticesBase); - void endDraw(const VertexType &vertexType, unsigned int vbo); + void beginDraw(const VertexType &vertexType, int vertexCount, uintptr_t verticesBase); + void endDraw(const VertexType &vertexType); COpenGL3CacheHandler* CacheHandler; core::stringw Name; @@ -395,8 +395,13 @@ namespace video irr::io::path OGLES2ShaderPath; // Changes the behavior of the beginDraw and endDraw methods. If true, the - // beginDraw method allocates a VBO, and if false, it uses the already bound VBO. - bool CreateNewVBOs; + // 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; From 326107d6fa673ea989998e90e962c68aa9f8a167 Mon Sep 17 00:00:00 2001 From: Caleb Butler Date: Wed, 13 Sep 2023 11:25:00 -0400 Subject: [PATCH 05/10] Clean up beginDraw function --- source/Irrlicht/OpenGL/Driver.cpp | 33 +++++++++++++------------------ 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 0b5b8375d..bc4890473 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -1122,26 +1122,21 @@ COpenGL3DriverBase::~COpenGL3DriverBase() void COpenGL3DriverBase::beginDraw(const VertexType &vertexType, int vertexCount, uintptr_t verticesBase) { - - if (UseGlobalVBO) { - glBindBuffer(GL_ARRAY_BUFFER, GlobalVBO); - glBufferData(GL_ARRAY_BUFFER, vertexType.VertexSize * vertexCount, reinterpret_cast(verticesBase), GL_DYNAMIC_DRAW); - 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(attr.Offset)); break; - case VertexAttribute::Mode::Normalized: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_TRUE, vertexType.VertexSize, reinterpret_cast(attr.Offset)); break; - case VertexAttribute::Mode::Integral: glVertexAttribIPointer(attr.Index, attr.ComponentCount, attr.ComponentType, vertexType.VertexSize, reinterpret_cast(attr.Offset)); break; - } + void *offset; + + for (auto attr: vertexType) { + if (UseGlobalVBO) { + glBindBuffer(GL_ARRAY_BUFFER, GlobalVBO); + glBufferData(GL_ARRAY_BUFFER, vertexType.VertexSize * vertexCount, reinterpret_cast(verticesBase), GL_DYNAMIC_DRAW); + offset = reinterpret_cast(attr.Offset); + } else { + offset = reinterpret_cast(verticesBase + attr.Offset); } - } else { - 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; - } + glEnableVertexAttribArray(attr.Index); + switch (attr.mode) { + case VertexAttribute::Mode::Regular: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_FALSE, vertexType.VertexSize, offset); break; + case VertexAttribute::Mode::Normalized: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_TRUE, vertexType.VertexSize, offset); break; + case VertexAttribute::Mode::Integral: glVertexAttribIPointer(attr.Index, attr.ComponentCount, attr.ComponentType, vertexType.VertexSize, offset); break; } } } From ed437a9bb59093db66c364a04f65182d18ebc8e8 Mon Sep 17 00:00:00 2001 From: Caleb Butler Date: Wed, 13 Sep 2023 11:28:58 -0400 Subject: [PATCH 06/10] Add comments explaining removing certain things I want to explain why I commented out GL_GENERATE_MIPMAP_HINT in case someone knows a good replacement for this hint. I believe there might be a performance regression by me commenting out these lines so a replacement might be needed. --- source/Irrlicht/COpenGLCoreTexture.h | 24 +++++++++++++----------- source/Irrlicht/OpenGL/Driver.cpp | 5 ++++- source/Irrlicht/OpenGL3/Driver.cpp | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/source/Irrlicht/COpenGLCoreTexture.h b/source/Irrlicht/COpenGLCoreTexture.h index 4debc4c10..386081be4 100644 --- a/source/Irrlicht/COpenGLCoreTexture.h +++ b/source/Irrlicht/COpenGLCoreTexture.h @@ -98,17 +98,19 @@ class COpenGLCoreTexture : public ITexture glTexParameteri(TextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST); -#if 0 - if (HasMipMaps) - { - if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED)) - glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST); - else if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_QUALITY)) - glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); - else - glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); - } -#endif + // TODO: The OpenGL core profile does not support GL_GENERATE_MIPMAP_HINT, is + // there a good replacement? + //#ifdef GL_GENERATE_MIPMAP + // if (HasMipMaps) + // { + // if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED)) + // glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST); + // else if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_QUALITY)) + // glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); + // else + // glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); + // } + //#endif #if !defined(IRR_OPENGL_HAS_glGenerateMipmap) && defined(GL_GENERATE_MIPMAP) if (HasMipMaps) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index bc4890473..81dd45ad5 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -264,7 +264,10 @@ COpenGL3DriverBase::~COpenGL3DriverBase() setAmbientLight(SColorf(0.0f, 0.0f, 0.0f, 0.0f)); glClearDepthf(1.0); - //glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); + // TODO: The OpenGL core profile does not support GL_GENERATE_MIPMAP_HINT, is + // there a good replacement? + // glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); + glFrontFace(GL_CW); // create material renderers diff --git a/source/Irrlicht/OpenGL3/Driver.cpp b/source/Irrlicht/OpenGL3/Driver.cpp index d0c3da5fc..515e768fa 100644 --- a/source/Irrlicht/OpenGL3/Driver.cpp +++ b/source/Irrlicht/OpenGL3/Driver.cpp @@ -29,7 +29,7 @@ namespace video { } void COpenGL3Driver::initFeatures() { - //assert (Version.Spec == OpenGLSpec::Core); + assert (Version.Spec == OpenGLSpec::Core); assert (isVersionAtLeast(3, 3)); initExtensionsNew(); From 343d98b29758610a725e6b97b9ec95c30a077482 Mon Sep 17 00:00:00 2001 From: Caleb Butler Date: Sun, 17 Sep 2023 16:55:01 -0400 Subject: [PATCH 07/10] Remove UseGlobalVBO global variable Instead of having a global variable UseGlobalVBO, have multiple versions of beginDraw and drawVertexPrimitiveList that do and do not use GlobalVBO. This is better coding practice and could prevent strange bugs from forming in the future due to UseGlobalVBO being set to an unexpected value. --- source/Irrlicht/OpenGL/Driver.cpp | 61 +++++++++++++++++++------------ source/Irrlicht/OpenGL/Driver.h | 17 ++++++--- 2 files changed, 49 insertions(+), 29 deletions(-) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 81dd45ad5..b8a519728 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -142,7 +142,7 @@ COpenGL3DriverBase::COpenGL3DriverBase(const SIrrlichtCreationParameters ¶ms MaterialRenderer2DActive(0), MaterialRenderer2DTexture(0), MaterialRenderer2DNoTexture(0), CurrentRenderMode(ERM_NONE), Transformation3DChanged(true), OGLES2ShaderPath(params.OGLES2ShaderPath), - UseGlobalVBO(true), ColorFormat(ECF_R8G8B8), ContextManager(contextManager) + ColorFormat(ECF_R8G8B8), ContextManager(contextManager) { #ifdef _DEBUG setDebugName("Driver"); @@ -681,14 +681,9 @@ COpenGL3DriverBase::~COpenGL3DriverBase() indexList = 0; } - UseGlobalVBO = false; - - drawVertexPrimitiveList(vertices, mb->getVertexCount(), - indexList, mb->getPrimitiveCount(), - mb->getVertexType(), mb->getPrimitiveType(), - mb->getIndexType()); - - UseGlobalVBO = true; + drawVertexPrimitiveListWithBoundVBO(vertices, mb->getVertexCount(), indexList, + mb->getPrimitiveCount(), mb->getVertexType(), mb->getPrimitiveType(), + mb->getIndexType(), reinterpret_cast(vertices)); if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -718,6 +713,21 @@ COpenGL3DriverBase::~COpenGL3DriverBase() void COpenGL3DriverBase::drawVertexPrimitiveList(const void* vertices, u32 vertexCount, const void* indexList, u32 primitiveCount, E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) + { + auto &vTypeDesc = getVertexTypeDescription(vType); + + // Use global vbo + glBindBuffer(GL_ARRAY_BUFFER, GlobalVBO); + glBufferData(GL_ARRAY_BUFFER, vTypeDesc.VertexSize * vertexCount, vertices, GL_DYNAMIC_DRAW); + + drawVertexPrimitiveListWithBoundVBO(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType, 0); + } + + + void COpenGL3DriverBase::drawVertexPrimitiveListWithBoundVBO(const void *vertices, + u32 vertexCount, const void *indexList, u32 primitiveCount, + E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType, + uintptr_t offset) { if (!primitiveCount || !vertexCount) return; @@ -754,7 +764,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() } } - beginDraw(vTypeDesc, vertexCount, reinterpret_cast(vertices)); + beginDrawWithBoundVBO(vTypeDesc, offset); switch (pType) { @@ -1123,33 +1133,36 @@ COpenGL3DriverBase::~COpenGL3DriverBase() endDraw(vertexType); } - void COpenGL3DriverBase::beginDraw(const VertexType &vertexType, int vertexCount, uintptr_t verticesBase) + void COpenGL3DriverBase::beginDrawWithBoundVBO(const VertexType &vertexType, uintptr_t offset) { - void *offset; + void *openGLOffset; for (auto attr: vertexType) { - if (UseGlobalVBO) { - glBindBuffer(GL_ARRAY_BUFFER, GlobalVBO); - glBufferData(GL_ARRAY_BUFFER, vertexType.VertexSize * vertexCount, reinterpret_cast(verticesBase), GL_DYNAMIC_DRAW); - offset = reinterpret_cast(attr.Offset); - } else { - offset = reinterpret_cast(verticesBase + attr.Offset); - } + openGLOffset = reinterpret_cast(attr.Offset + offset); + glEnableVertexAttribArray(attr.Index); switch (attr.mode) { - case VertexAttribute::Mode::Regular: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_FALSE, vertexType.VertexSize, offset); break; - case VertexAttribute::Mode::Normalized: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_TRUE, vertexType.VertexSize, offset); break; - case VertexAttribute::Mode::Integral: glVertexAttribIPointer(attr.Index, attr.ComponentCount, attr.ComponentType, vertexType.VertexSize, offset); break; + case VertexAttribute::Mode::Regular: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_FALSE, vertexType.VertexSize, openGLOffset); break; + case VertexAttribute::Mode::Normalized: glVertexAttribPointer(attr.Index, attr.ComponentCount, attr.ComponentType, GL_TRUE, vertexType.VertexSize, openGLOffset); break; + case VertexAttribute::Mode::Integral: glVertexAttribIPointer(attr.Index, attr.ComponentCount, attr.ComponentType, vertexType.VertexSize, openGLOffset); break; } + } } + void COpenGL3DriverBase::beginDraw(const VertexType &vertexType, int vertexCount, uintptr_t verticesBase) + { + glBindBuffer(GL_ARRAY_BUFFER, GlobalVBO); + glBufferData(GL_ARRAY_BUFFER, vertexType.VertexSize * vertexCount, reinterpret_cast(verticesBase), GL_DYNAMIC_DRAW); + beginDrawWithBoundVBO(vertexType, 0); + } + void COpenGL3DriverBase::endDraw(const VertexType &vertexType) { for (auto attr: vertexType) glDisableVertexAttribArray(attr.Index); - if (UseGlobalVBO) - glBindBuffer(GL_ARRAY_BUFFER, 0); + // Unbind GL_ARRAY_BUFFER + glBindBuffer(GL_ARRAY_BUFFER, 0); } ITexture* COpenGL3DriverBase::createDeviceDependentTexture(const io::path& name, IImage* image) diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index cee8935c4..cac466192 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -322,6 +322,13 @@ namespace video LockRenderStateMode = false; } + // This function is like drawVertexPrimitiveList, but it does not use GlobalVBO, + // allowing the user to draw with their own VBOs such as with the + // drawHardwareBuffer function. + void drawVertexPrimitiveListWithBoundVBO(const void *vertices, u32 vertexCount, + const void *indexList, u32 primitiveCount, E_VERTEX_TYPE vType, + scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType, uintptr_t offset); + void draw2D3DVertexPrimitiveList(const void* vertices, u32 vertexCount, const void* indexList, u32 primitiveCount, E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, @@ -341,6 +348,11 @@ namespace video 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); + // This function is like beginDraw, but it does not use GlobalVBO, allowing the + // user to draw with their own VBOs such as with the + // drawHardwareBuffer function. + void beginDrawWithBoundVBO(const VertexType &vertexType, uintptr_t offset); + void beginDraw(const VertexType &vertexType, int vertexCount, uintptr_t verticesBase); void endDraw(const VertexType &vertexType); @@ -394,11 +406,6 @@ 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; From b92c2b3bcf7163249a0baecf2713a9801ba0ab11 Mon Sep 17 00:00:00 2001 From: Caleb Butler Date: Thu, 21 Sep 2023 18:37:48 -0400 Subject: [PATCH 08/10] Replace uintptr_t in beginDraw with void* Replace unnecessary type uintptr_t with an actual pointer type. --- source/Irrlicht/OpenGL/Driver.cpp | 8 ++++---- source/Irrlicht/OpenGL/Driver.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index b8a519728..ba1e0c21b 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -1121,14 +1121,14 @@ COpenGL3DriverBase::~COpenGL3DriverBase() void COpenGL3DriverBase::drawArrays(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount) { - beginDraw(vertexType, vertexCount, reinterpret_cast(vertices)); + beginDraw(vertexType, vertexCount, vertices); glDrawArrays(primitiveType, 0, vertexCount); endDraw(vertexType); } void COpenGL3DriverBase::drawElements(GLenum primitiveType, const VertexType &vertexType, const void *vertices, int vertexCount, const u16 *indices, int indexCount) { - beginDraw(vertexType, vertexCount, reinterpret_cast(vertices)); + beginDraw(vertexType, vertexCount, vertices); glDrawRangeElements(primitiveType, 0, vertexCount - 1, indexCount, GL_UNSIGNED_SHORT, indices); endDraw(vertexType); } @@ -1150,10 +1150,10 @@ COpenGL3DriverBase::~COpenGL3DriverBase() } } - void COpenGL3DriverBase::beginDraw(const VertexType &vertexType, int vertexCount, uintptr_t verticesBase) + void COpenGL3DriverBase::beginDraw(const VertexType &vertexType, int vertexCount, const void *verticesBase) { glBindBuffer(GL_ARRAY_BUFFER, GlobalVBO); - glBufferData(GL_ARRAY_BUFFER, vertexType.VertexSize * vertexCount, reinterpret_cast(verticesBase), GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, vertexType.VertexSize * vertexCount, verticesBase, GL_DYNAMIC_DRAW); beginDrawWithBoundVBO(vertexType, 0); } diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index cac466192..83aea4b66 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -353,7 +353,7 @@ namespace video // drawHardwareBuffer function. void beginDrawWithBoundVBO(const VertexType &vertexType, uintptr_t offset); - void beginDraw(const VertexType &vertexType, int vertexCount, uintptr_t verticesBase); + void beginDraw(const VertexType &vertexType, int vertexCount, const void *verticesBase); void endDraw(const VertexType &vertexType); COpenGL3CacheHandler* CacheHandler; From fbc28719a29fb769694d1bb05657741e56bf06fe Mon Sep 17 00:00:00 2001 From: Caleb Butler Date: Thu, 21 Sep 2023 18:43:51 -0400 Subject: [PATCH 09/10] Handle EHM_NEVER correctly When EHM_NEVER is used, then GL_ARRAY_BUFFER is not bound, so it does not make sense to use drawVertexPrimitiveListWithBoundVBO. On the other hand, since all data is on the GPU anyway now, EHM_NEVER does not make much sense as an option in the first place and doesn't really do what's expected. --- source/Irrlicht/OpenGL/Driver.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index ba1e0c21b..fa2cf2fcb 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -681,9 +681,18 @@ COpenGL3DriverBase::~COpenGL3DriverBase() indexList = 0; } - drawVertexPrimitiveListWithBoundVBO(vertices, mb->getVertexCount(), indexList, - mb->getPrimitiveCount(), mb->getVertexType(), mb->getPrimitiveType(), - mb->getIndexType(), reinterpret_cast(vertices)); + if (HWBuffer->Mapped_Vertex == scene::EHM_NEVER) + { + drawVertexPrimitiveList(vertices, mb->getVertexCount(), indexList, + mb->getPrimitiveCount(), mb->getVertexType(), mb->getPrimitiveType(), + mb->getIndexType()); + } + else + { + drawVertexPrimitiveListWithBoundVBO(vertices, mb->getVertexCount(), indexList, + mb->getPrimitiveCount(), mb->getVertexType(), mb->getPrimitiveType(), + mb->getIndexType(), reinterpret_cast(vertices)); + } if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) glBindBuffer(GL_ARRAY_BUFFER, 0); From 0578c668b3478077f86b235b6f7688f91e8944b7 Mon Sep 17 00:00:00 2001 From: Caleb Butler Date: Thu, 21 Sep 2023 19:27:28 -0400 Subject: [PATCH 10/10] Ignore EHM_NEVER for index buffers --- source/Irrlicht/OpenGL/Driver.cpp | 40 ++++++++++++++++++------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index fa2cf2fcb..3426f4b97 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -587,19 +587,23 @@ COpenGL3DriverBase::~COpenGL3DriverBase() } } - if (HWBuffer->Mapped_Index != scene::EHM_NEVER) + // Should EHM_NEVER for index buffers just be ignored? Does this make sense? + + //if (HWBuffer->Mapped_Index != scene::EHM_NEVER) + //{ + + if (HWBuffer->ChangedID_Index != HWBuffer->MeshBuffer->getChangedID_Index() + || !static_cast(HWBuffer)->vbo_indicesID) { - if (HWBuffer->ChangedID_Index != HWBuffer->MeshBuffer->getChangedID_Index() - || !static_cast(HWBuffer)->vbo_indicesID) - { - HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index(); + HWBuffer->ChangedID_Index = HWBuffer->MeshBuffer->getChangedID_Index(); - if (!updateIndexHardwareBuffer((SHWBufferLink_opengl*)HWBuffer)) - return false; - } + if (!updateIndexHardwareBuffer((SHWBufferLink_opengl*)HWBuffer)) + return false; } + //} + return true; } @@ -607,7 +611,7 @@ COpenGL3DriverBase::~COpenGL3DriverBase() //! Create hardware buffer from meshbuffer COpenGL3DriverBase::SHWBufferLink *COpenGL3DriverBase::createHardwareBuffer(const scene::IMeshBuffer* mb) { - if (!mb || (mb->getHardwareMappingHint_Index() == scene::EHM_NEVER && mb->getHardwareMappingHint_Vertex() == scene::EHM_NEVER)) + if (!mb) return 0; SHWBufferLink_opengl *HWBuffer = new SHWBufferLink_opengl(mb); @@ -675,11 +679,13 @@ COpenGL3DriverBase::~COpenGL3DriverBase() vertices = 0; } - if (HWBuffer->Mapped_Index != scene::EHM_NEVER) - { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID); - indexList = 0; - } + // Should EHM_NEVER for index buffers just be ignored? Does this make sense? + + //if (HWBuffer->Mapped_Index != scene::EHM_NEVER) + //{ + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, HWBuffer->vbo_indicesID); + indexList = 0; + //} if (HWBuffer->Mapped_Vertex == scene::EHM_NEVER) { @@ -697,8 +703,10 @@ COpenGL3DriverBase::~COpenGL3DriverBase() if (HWBuffer->Mapped_Vertex != scene::EHM_NEVER) glBindBuffer(GL_ARRAY_BUFFER, 0); - if (HWBuffer->Mapped_Index != scene::EHM_NEVER) - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + //if (HWBuffer->Mapped_Index != scene::EHM_NEVER) + //{ + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + //} }