History

Starting to clean the mesh part of the RenderItem....

samcake committed 11 years ago

Commit 518f5fe1 parent 00e05236 files · +58 −27Browse files

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

Unified · Split

libraries/render-utils/src/Model.cpp+35−6
@@ -754,6 +754,16 @@ public: · 753 unmodified lines
754754 int meshIndex;
755755 int partIndex;
756756 int _shapeID;
757+
758+ render::Item::Bound getBound() const {
759+ if (_isBoundInvalid) {
760+ model->getPartBounds(meshIndex, partIndex);
761+ _isBoundInvalid = false;
762+ }
763+ return _bound;
764+ }
765+ mutable render::Item::Bound _bound;
766+ mutable bool _isBoundInvalid = true;
757767 };
758768
759769 namespace render {
@@ -780,7 +790,7 @@ namespace render { · 20 unmodified lines
780790
781791 template <> const Item::Bound payloadGetBound(const MeshPartPayload::Pointer& payload) {
782792 if (payload) {
783− return payload->model->getPartBounds(payload->meshIndex, payload->partIndex);
793+ return payload->getBound(); // model->getPartBounds(payload->meshIndex, payload->partIndex);
784794 }
785795 return render::Item::Bound();
786796 }
@@ -1486,6 +1496,9 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, int shape · 699 unmodified lines
14861496 const FBXMesh& mesh = geometry.meshes.at(meshIndex);
14871497 const MeshState& state = _meshStates.at(meshIndex);
14881498
1499+ auto drawMesh = networkMesh._mesh;
1500+
1501+
14891502 auto drawMaterialKey = material->getKey();
14901503 bool translucentMesh = drawMaterialKey.isTransparent() || drawMaterialKey.isTransparentMap();
14911504
@@ -1541,7 +1554,9 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, int shape · 49 unmodified lines
15411554 return; // FIXME!
15421555 }
15431556
1544− batch.setIndexBuffer(gpu::UINT32, (networkMesh._indexBuffer), 0);
1557+ // Assign index buffer:
1558+ batch.setIndexBuffer(gpu::UINT32, (drawMesh->getIndexBuffer()._buffer), 0);
1559+ // batch.setIndexBuffer(gpu::UINT32, (networkMesh._indexBuffer), 0);
15451560 int vertexCount = mesh.vertices.size();
15461561 if (vertexCount == 0) {
15471562 // sanity check
@@ -1574,10 +1589,21 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, int shape · 26 unmodified lines
15741589 batch.setModelTransform(_transforms[0]);
15751590
15761591 if (mesh.blendshapes.isEmpty()) {
1577− batch.setInputFormat(networkMesh._vertexFormat);
1578− batch.setInputStream(0, *networkMesh._vertexStream);
1592+ batch.setInputFormat((drawMesh->getVertexFormat()));
1593+ auto inputStream = drawMesh->makeBufferStream();
1594+
1595+ batch.setInputStream(0, inputStream);
1596+
1597+ // batch.setInputFormat(networkMesh._vertexFormat);
1598+ // batch.setInputStream(0, *networkMesh._vertexStream);
15791599 } else {
1600+ /* batch.setInputFormat((drawMesh->getVertexFormat()));
1601+ auto inputStream = drawMesh->makeBufferStream();
1602+
1603+ batch.setInputStream(0, inputStream);
1604+ */
15801605 batch.setInputFormat(networkMesh._vertexFormat);
1606+
15811607 batch.setInputBuffer(0, _blendedVertexBuffers[meshIndex], 0, sizeof(glm::vec3));
15821608 batch.setInputBuffer(1, _blendedVertexBuffers[meshIndex], vertexCount * sizeof(glm::vec3), sizeof(glm::vec3));
15831609 batch.setInputStream(2, *networkMesh._vertexStream);
@@ -1702,9 +1728,12 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, int shape · 118 unmodified lines
17021728 }
17031729 }
17041730
1705− batch.setIndexBuffer(gpu::UINT32, part.getMergedTriangles(), 0);
1706− batch.drawIndexed(gpu::TRIANGLES, part.mergedTrianglesIndicesCount, 0);
1731+ auto& drawPart = drawMesh->getPartBuffer().get<model::Mesh::Part>();
1732+ batch.drawIndexed(model::Mesh::topologyToPrimitive(drawPart._topology), drawPart._numIndices, drawPart._startIndex);
17071733
1734+/* batch.setIndexBuffer(gpu::UINT32, part.getMergedTriangles(), 0);
1735+ batch.drawIndexed(gpu::TRIANGLES, part.mergedTrianglesIndicesCount, 0);
1736+ */
17081737 if (args) {
17091738 const int INDICES_PER_TRIANGLE = 3;
17101739 args->_details._trianglesRendered += part.mergedTrianglesIndicesCount / INDICES_PER_TRIANGLE;