History

Fixing the index Offset issue with instanced shapes from Geometry cache

samcake committed 11 years ago

Commit c75c31d1 parent 2b5742b4 files · +6 −36Browse files

Showing the changes to libraries/render-utils/src/GeometryCache.cpp (1 of 4 files). Show all

Unified · Split

libraries/render-utils/src/GeometryCache.cpp+5−4
@@ -59,7 +59,8 @@ static gpu::Stream::FormatPointer INSTANCED_SOLID_STREAM_FORMAT; · 58 unmodified lines
59 59
60static const uint SHAPE_VERTEX_STRIDE = sizeof(glm::vec3) * 2; // vertices and normals60static const uint SHAPE_VERTEX_STRIDE = sizeof(glm::vec3) * 2; // vertices and normals
61static const uint SHAPE_NORMALS_OFFSET = sizeof(glm::vec3);61static const uint SHAPE_NORMALS_OFFSET = sizeof(glm::vec3);
62 62static const gpu::Type SHAPE_INDEX_TYPE = gpu::UINT16;
63static const uint SHAPE_INDEX_SIZE = sizeof(gpu::uint16);
63 64
64void GeometryCache::ShapeData::setupVertices(gpu::BufferPointer& vertexBuffer, const VertexVector& vertices) {65void GeometryCache::ShapeData::setupVertices(gpu::BufferPointer& vertexBuffer, const VertexVector& vertices) {
65 vertexBuffer->append(vertices);66 vertexBuffer->append(vertices);
@@ -73,13 +74,13 @@ void GeometryCache::ShapeData::setupVertices(gpu::BufferPointer& vertexBuffer, c · 7 unmodified lines
73void GeometryCache::ShapeData::setupIndices(gpu::BufferPointer& indexBuffer, const IndexVector& indices, const IndexVector& wireIndices) {74void GeometryCache::ShapeData::setupIndices(gpu::BufferPointer& indexBuffer, const IndexVector& indices, const IndexVector& wireIndices) {
74 _indices = indexBuffer;75 _indices = indexBuffer;
75 if (!indices.empty()) {76 if (!indices.empty()) {
76 _indexOffset = indexBuffer->getSize();77 _indexOffset = indexBuffer->getSize() / SHAPE_INDEX_SIZE;
77 _indexCount = indices.size();78 _indexCount = indices.size();
78 indexBuffer->append(indices);79 indexBuffer->append(indices);
79 }80 }
80 81
81 if (!wireIndices.empty()) {82 if (!wireIndices.empty()) {
82 _wireIndexOffset = indexBuffer->getSize();83 _wireIndexOffset = indexBuffer->getSize() / SHAPE_INDEX_SIZE;
83 _wireIndexCount = wireIndices.size();84 _wireIndexCount = wireIndices.size();
84 indexBuffer->append(wireIndices);85 indexBuffer->append(wireIndices);
85 }86 }
@@ -88,7 +89,7 @@ void GeometryCache::ShapeData::setupIndices(gpu::BufferPointer& indexBuffer, con · 2 unmodified lines
88void GeometryCache::ShapeData::setupBatch(gpu::Batch& batch) const {89void GeometryCache::ShapeData::setupBatch(gpu::Batch& batch) const {
89 batch.setInputBuffer(gpu::Stream::POSITION, _positionView);90 batch.setInputBuffer(gpu::Stream::POSITION, _positionView);
90 batch.setInputBuffer(gpu::Stream::NORMAL, _normalView);91 batch.setInputBuffer(gpu::Stream::NORMAL, _normalView);
91 batch.setIndexBuffer(gpu::UINT16, _indices, 0);92 batch.setIndexBuffer(SHAPE_INDEX_TYPE, _indices, 0);
92}93}
93 94
94void GeometryCache::ShapeData::draw(gpu::Batch& batch) const {95void GeometryCache::ShapeData::draw(gpu::Batch& batch) const {