Skip to content
/ VTK Public

Commit d75b9ab

Browse files
committed
OpenGL: Optimize out unnecessary query for buffer size
- Adds a new method to retrieve the size of allocation of an OpenGL buffer object
1 parent 3bd2e83 commit d75b9ab

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

Rendering/OpenGL2/vtkOpenGLBufferObject.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ struct vtkOpenGLBufferObject::Private
6161
this->Handle = 0;
6262
this->Type = GL_ARRAY_BUFFER;
6363
this->Usage = GL_STATIC_DRAW;
64+
this->Size = 0;
6465
}
6566
GLenum Type;
6667
GLenum Usage;
6768
GLuint Handle;
69+
size_t Size;
6870
};
6971

7072
vtkOpenGLBufferObject::vtkOpenGLBufferObject()
@@ -164,9 +166,15 @@ bool vtkOpenGLBufferObject::Allocate(size_t size, ObjectType objectType, ObjectU
164166
glBufferData(
165167
this->Internal->Type, static_cast<GLsizeiptr>(size), nullptr, convertUsage(objectUsage));
166168
this->Dirty = true;
169+
this->Internal->Size = size;
167170
return true;
168171
}
169172

173+
size_t vtkOpenGLBufferObject::GetSize()
174+
{
175+
return this->Internal->Size;
176+
}
177+
170178
bool vtkOpenGLBufferObject::Bind()
171179
{
172180
if (!this->Internal->Handle)

Rendering/OpenGL2/vtkOpenGLBufferObject.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLBufferObject : public vtkObject
9292
* Allocates a buffer of `type` with `size` bytes.
9393
*/
9494
bool Allocate(size_t size, ObjectType type, ObjectUsage usage);
95+
96+
/**
97+
* Get size of the buffer in bytes.
98+
*/
99+
size_t GetSize();
100+
95101
/**
96102
* Bind the buffer object ready for rendering.
97103
* @note Only one ARRAY_BUFFER and one ELEMENT_ARRAY_BUFFER may be bound at

Rendering/OpenGL2/vtkTextureObject.cxx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,7 @@ bool vtkTextureObject::Create1DFromRaw(unsigned int width, int numComps, int dat
11791179
// Description:
11801180
// Create a texture buffer basically a 1D texture that can be
11811181
// very large for passing data into the fragment shader
1182+
//------------------------------------------------------------------------------
11821183
bool vtkTextureObject::CreateTextureBuffer(
11831184
unsigned int numValues, int numComps, int dataType, vtkOpenGLBufferObject* bo)
11841185
{
@@ -1215,11 +1216,7 @@ bool vtkTextureObject::EmulateTextureBufferWith2DTextures(
12151216
{
12161217
srcTarget = GL_ELEMENT_ARRAY_BUFFER;
12171218
}
1218-
GLint64 srcNumBytes = 0;
12191219
bo->Bind();
1220-
glGetBufferParameteri64v(srcTarget, GL_BUFFER_SIZE, &srcNumBytes);
1221-
vtkOpenGLCheckErrors("glGetBufferParameteri64v ");
1222-
12231220
// issue 3 (https://registry.khronos.org/OpenGL/extensions/ARB/ARB_pixel_buffer_object.txt)
12241221
// says it's alright to bind any b.o (GL_ARRAY_BUFFER, etc) to unpacked buffer
12251222
// and go ahead with glTexImage,
@@ -1230,11 +1227,12 @@ bool vtkTextureObject::EmulateTextureBufferWith2DTextures(
12301227
pbo->Allocate(dataType, width * height, numComps, vtkPixelBufferObject::UNPACKED_BUFFER);
12311228
pbo->BindToUnPackedBuffer();
12321229
// transfers within gpu memory space on most GL driver implementations.
1233-
glCopyBufferSubData(srcTarget, dstTarget, 0, 0, srcNumBytes);
1230+
glCopyBufferSubData(srcTarget, dstTarget, 0, 0, bo->GetSize());
12341231
vtkOpenGLCheckErrors("glCopyBufferSubData ");
12351232

1233+
// Get rid of the original buffer data
1234+
bo->ReleaseGraphicsResources();
12361235
// unbind
1237-
bo->Release();
12381236
pbo->UnBind();
12391237

12401238
// source a 2D texture with the pbo.

0 commit comments

Comments
 (0)