From 0e27dc6c206c1385da3b5f9d018eb5f07d4ec9e9 Mon Sep 17 00:00:00 2001 From: gelder Date: Wed, 20 Jun 2012 17:11:17 -0700 Subject: [PATCH] Updates for correct complilation with glew found during Presto integration, and change to vertexBuffer ot avoid dynamic cast issues in Presto. --- opensubdiv/osd/vertexBuffer.cpp | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 opensubdiv/osd/vertexBuffer.cpp diff --git a/opensubdiv/osd/vertexBuffer.cpp b/opensubdiv/osd/vertexBuffer.cpp new file mode 100644 index 00000000..c3892d1f --- /dev/null +++ b/opensubdiv/osd/vertexBuffer.cpp @@ -0,0 +1,79 @@ +#include "../version.h" + +#include + +#include "vertexBuffer.h" + +#include +#include + +#include + +namespace OpenSubdiv { +namespace OPENSUBDIV_VERSION { + +OsdVertexBuffer::~OsdVertexBuffer() +{ +} + +OsdGpuVertexBuffer::OsdGpuVertexBuffer(int numElements, int numVertices) : + OsdVertexBuffer(numElements), _vbo(0) +{ + int size = numElements * numVertices * sizeof(float); + glGenBuffers(1, &_vbo); + glBindBuffer(GL_ARRAY_BUFFER, _vbo); + glBufferData(GL_ARRAY_BUFFER, size, 0, GL_STREAM_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); +} + +void +OsdGpuVertexBuffer::UpdateData(const float *src, int numVertices) +{ + glBindBuffer(GL_ARRAY_BUFFER, _vbo); + float * pointer = (float*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); + memcpy(pointer, src, _numElements * numVertices * sizeof(float)); + glUnmapBuffer(GL_ARRAY_BUFFER); + glBindBuffer(GL_ARRAY_BUFFER, 0); +} + +OsdGpuVertexBuffer::~OsdGpuVertexBuffer() +{ + glDeleteBuffers(1, &_vbo); + +} + + +OsdCpuVertexBuffer::OsdCpuVertexBuffer(int numElements, int numVertices) : + OsdVertexBuffer(numElements), _cpuVbo(NULL), _vboSize(0), _vbo(0) +{ + _vboSize = numElements * numVertices; + _cpuVbo = new float[numElements * numVertices]; +} + +OsdCpuVertexBuffer::~OsdCpuVertexBuffer() +{ + delete [] _cpuVbo; + if (_vbo) + glDeleteBuffers(1, &_vbo); +} + +void +OsdCpuVertexBuffer::UpdateData(const float *src, int numVertices) +{ + memcpy(_cpuVbo, src, _numElements * numVertices * sizeof(float)); +} + +GLuint +OsdCpuVertexBuffer::GetGpuBuffer() +{ + if (!_vbo) + glGenBuffers(1, &_vbo); + glBindBuffer(GL_ARRAY_BUFFER, _vbo); + glBufferData(GL_ARRAY_BUFFER, _vboSize * sizeof(float), _cpuVbo, GL_STREAM_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + return _vbo; +} + +} // end namespace OPENSUBDIV_VERSION +} // end namespace OpenSubdiv +