From d888cf047bc11c5e42935c7a8692f229b2843714 Mon Sep 17 00:00:00 2001 From: MiniTurtle Date: Mon, 25 Mar 2024 18:58:18 +0200 Subject: [PATCH] resize index & vertex optimized with adding copy count --- source/Irrlicht/CMakeLists.txt | 2 +- source/Irrlicht/CNullDriver.h | 4 ++-- source/Irrlicht/COpenGLDriver.cpp | 16 ++++++++++------ source/Irrlicht/COpenGLDriver.h | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 1706986b1..7cc85f93f 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -1,5 +1,5 @@ if(NOT ANDROID AND NOT APPLE) - set(DEFAULT_SDL2 ON) + set(DEFAULT_SDL2 FALSE) endif() option(BUILD_SHARED_LIBS "Build shared library" TRUE) diff --git a/source/Irrlicht/CNullDriver.h b/source/Irrlicht/CNullDriver.h index 1c74e9dcd..0edbee0fa 100644 --- a/source/Irrlicht/CNullDriver.h +++ b/source/Irrlicht/CNullDriver.h @@ -380,8 +380,8 @@ namespace video virtual bool getIndexHardwareBufferSubData(SHWBufferLink* HWBuffer, u32 indexCount, u32 offset, c8* resultPtr) { return false; } virtual bool updateVertexHardwareBufferDirect(SHWBufferLink* HWBuffer, c8* vertexBuffer, u32 vertexCount) { return false; } virtual bool updateIndexHardwareBufferDirect(SHWBufferLink* HWBuffer, c8* indices, u32 indexCount) { return false; } - virtual bool resizeIndexHardwareBufferSubData(SHWBufferLink* HWBuffer, u32 indexCount) { return false; } - virtual bool resizeVertexHardwareBufferSubData(SHWBufferLink* HWBuffer, u32 vertexCount) { return false; } + virtual bool resizeIndexHardwareBufferSubData(SHWBufferLink* HWBuffer, u32 indexCount, u32 cpyIndexCount = 0) { return false; } + virtual bool resizeVertexHardwareBufferSubData(SHWBufferLink* HWBuffer, u32 vertexCount, u32 cpyVertexCount = 0) { return false; } protected: //! updates hardware buffer if needed (only some drivers can) diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index d3f0254f4..0adb89d74 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -440,7 +440,7 @@ bool COpenGLDriver::getIndexHardwareBufferSubData(SHWBufferLink* HWBuffer, u32 i return (!testGLError(__LINE__)); } -bool COpenGLDriver::resizeIndexHardwareBufferSubData(SHWBufferLink* _HWBuffer, u32 indexCount) { +bool COpenGLDriver::resizeIndexHardwareBufferSubData(SHWBufferLink* _HWBuffer, u32 indexCount, u32 cpyIndexCount) { SHWBufferLink_opengl* HWBuffer = (SHWBufferLink_opengl*)_HWBuffer; if (!HWBuffer) return false; @@ -494,7 +494,9 @@ bool COpenGLDriver::resizeIndexHardwareBufferSubData(SHWBufferLink* _HWBuffer, u // // Copy data from old buffer to new buffer - GLsizeiptrARB copySize = min(size, HWBuffer->vbo_indicesSize); + if (cpyIndexCount == 0) + cpyIndexCount = (irr::u32)size; + GLsizeiptrARB copySize = min(cpyIndexCount * indexSize, HWBuffer->vbo_indicesSize); extGlBindBuffer(GL_COPY_READ_BUFFER, prev_vbo_indicesID); extGlBindBuffer(GL_COPY_WRITE_BUFFER, HWBuffer->vbo_indicesID); @@ -506,12 +508,12 @@ bool COpenGLDriver::resizeIndexHardwareBufferSubData(SHWBufferLink* _HWBuffer, u // Delete old buffer extGlDeleteBuffers(1, &prev_vbo_indicesID); - HWBuffer->vbo_indicesSize = size; + HWBuffer->vbo_indicesSize = (GLuint)size; return (!testGLError(__LINE__)); } -bool COpenGLDriver::resizeVertexHardwareBufferSubData(SHWBufferLink* _HWBuffer, u32 vertexCount) { +bool COpenGLDriver::resizeVertexHardwareBufferSubData(SHWBufferLink* _HWBuffer, u32 vertexCount, u32 cpyVertexCount) { SHWBufferLink_opengl* HWBuffer = (SHWBufferLink_opengl*)_HWBuffer; if (!HWBuffer) return false; @@ -549,7 +551,9 @@ bool COpenGLDriver::resizeVertexHardwareBufferSubData(SHWBufferLink* _HWBuffer, // // Copy data from old buffer to new buffer - GLsizeiptrARB copySize = min(size, HWBuffer->vbo_verticesSize); + if (cpyVertexCount == 0) + cpyVertexCount = (irr::u32)size; + GLsizeiptrARB copySize = min(cpyVertexCount * vertexSize, HWBuffer->vbo_verticesSize); extGlBindBuffer(GL_COPY_READ_BUFFER, prev_vbo_vertexID); extGlBindBuffer(GL_COPY_WRITE_BUFFER, HWBuffer->vbo_verticesID); @@ -561,7 +565,7 @@ bool COpenGLDriver::resizeVertexHardwareBufferSubData(SHWBufferLink* _HWBuffer, // Delete old buffer extGlDeleteBuffers(1, &prev_vbo_vertexID); - HWBuffer->vbo_verticesSize = size; + HWBuffer->vbo_verticesSize = (GLuint)size; return (!testGLError(__LINE__)); } diff --git a/source/Irrlicht/COpenGLDriver.h b/source/Irrlicht/COpenGLDriver.h index 477f50d52..81d8d8cb2 100644 --- a/source/Irrlicht/COpenGLDriver.h +++ b/source/Irrlicht/COpenGLDriver.h @@ -73,8 +73,8 @@ namespace video virtual bool subUpdateIndexHardwareBuffer(SHWBufferLink* HWBuffer, c8* indices, u32 indexCount, u32 offset) override; virtual bool getVertexHardwareBufferSubData(SHWBufferLink* HWBuffer, u32 vertexCount, u32 offset, c8* resultPtr) override; virtual bool getIndexHardwareBufferSubData(SHWBufferLink* HWBuffer, u32 indexCount, u32 offset, c8* resultPtr) override; - virtual bool resizeIndexHardwareBufferSubData(SHWBufferLink* HWBuffer, u32 indexCount) override; - virtual bool resizeVertexHardwareBufferSubData(SHWBufferLink* HWBuffer, u32 vertexCount) override; + virtual bool resizeIndexHardwareBufferSubData(SHWBufferLink* HWBuffer, u32 indexCount, u32 cpyIndexCount = 0) override; + virtual bool resizeVertexHardwareBufferSubData(SHWBufferLink* HWBuffer, u32 vertexCount, u32 cpyVertexCount = 0) override; virtual bool updateVertexHardwareBufferDirect(SHWBufferLink* HWBuffer, c8* vertexBuffer, u32 vertexCount) override; virtual bool updateIndexHardwareBufferDirect(SHWBufferLink* HWBuffer, c8* indices, u32 indexCount) override;