CpuGLVB: dirty flag to not keep on uploading if data did not change

This commit is contained in:
Aras Pranckevicius 2013-02-04 20:57:19 +02:00
parent 89a75f03fe
commit 58cb40ec5c
2 changed files with 9 additions and 1 deletions

View File

@ -80,7 +80,7 @@ namespace OPENSUBDIV_VERSION {
OsdCpuGLVertexBuffer::OsdCpuGLVertexBuffer(int numElements, int numVertices)
: _numElements(numElements), _numVertices(numVertices),
_vbo(0), _cpuBuffer(0) {
_vbo(0), _cpuBuffer(0), _dataDirty(true) {
}
OsdCpuGLVertexBuffer::~OsdCpuGLVertexBuffer() {
@ -102,6 +102,7 @@ void
OsdCpuGLVertexBuffer::UpdateData(const float *src, int numVertices) {
memcpy(_cpuBuffer, src, _numElements * numVertices * sizeof(float));
_dataDirty = true;
}
int
@ -118,11 +119,15 @@ OsdCpuGLVertexBuffer::GetNumVertices() const {
float*
OsdCpuGLVertexBuffer::BindCpuBuffer() {
_dataDirty = true; // caller might modify data
return _cpuBuffer;
}
GLuint
OsdCpuGLVertexBuffer::BindVBO() {
if (not _dataDirty)
return _vbo;
int size = _numElements * _numVertices * sizeof(float);
GLint prev = 0;
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &prev);
@ -131,12 +136,14 @@ OsdCpuGLVertexBuffer::BindVBO() {
glBufferData(GL_ARRAY_BUFFER, size, _cpuBuffer, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, prev);
_dataDirty = false;
return _vbo;
}
bool
OsdCpuGLVertexBuffer::allocate() {
_cpuBuffer = new float[_numElements * _numVertices];
_dataDirty = true;
int size = _numElements * _numVertices * sizeof(float);
GLint prev = 0;

View File

@ -122,6 +122,7 @@ private:
int _numVertices;
GLuint _vbo;
float *_cpuBuffer;
bool _dataDirty;
};
} // end namespace OPENSUBDIV_VERSION