Skip to content

Commit

Permalink
resize index & vertex optimized with adding copy count
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniTurtle committed Mar 25, 2024
1 parent b002f89 commit d888cf0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion source/Irrlicht/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions source/Irrlicht/CNullDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 10 additions & 6 deletions source/Irrlicht/COpenGLDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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__));
}
Expand Down
4 changes: 2 additions & 2 deletions source/Irrlicht/COpenGLDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit d888cf0

Please sign in to comment.