Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. //////////////////////////////////////////////////////////////////////////
  2. // renderPrimitives
  3. class ScnModelComponentRenderNode: public RsRenderNode
  4. {
  5. public:
  6. void render()
  7. {
  8. PSY_PROFILER_SECTION( RenderRoot, "ScnModelComponentRenderNode::render" );
  9. pContext_->setIndexBuffer( IndexBuffer_ );
  10. pContext_->setVertexBuffer( 0, VertexBuffer_, VertexStride_ );
  11. pContext_->setVertexDeclaration( VertexDeclaration_ );
  12. pContext_->drawIndexedPrimitives( Type_, Offset_, NoofIndices_, 0 );
  13. }
  14.  
  15. RsTopologyType Type_;
  16. BcU32 Offset_;
  17. BcU32 NoofIndices_;
  18. RsBuffer* IndexBuffer_;
  19. RsBuffer* VertexBuffer_;
  20. BcU32 VertexStride_;
  21. RsVertexDeclaration* VertexDeclaration_;
  22. };
  23.  
  24. void ScnModelComponent::render( class ScnViewComponent* pViewComponent, RsFrame* pFrame, RsRenderSort Sort )
  25. {
  26. PSY_PROFILER_SECTION( RenderRoot, std::string( "ScnModelComponent::render (" ) + *getName() + std::string( ")" ) );
  27.  
  28. Super::render( pViewComponent, pFrame, Sort );
  29.  
  30. // Wait for model to have updated.
  31. UpdateFence_.wait();
  32.  
  33. // Gather lights.
  34. ScnLightingVisitor LightingVisitor( this );
  35.  
  36. ScnModelMeshRuntimeList& MeshRuntimes = Parent_->MeshRuntimes_;
  37. ScnModelMeshData* pMeshDatas = Parent_->pMeshData_;
  38.  
  39. // Set layer.
  40. Sort.Layer_ = Layer_;
  41. Sort.Pass_ = Pass_;
  42.  
  43. for( BcU32 PrimitiveIdx = 0; PrimitiveIdx < MeshRuntimes.size(); ++PrimitiveIdx )
  44. {
  45. ScnModelMeshRuntime* pMeshRuntime = &MeshRuntimes[ PrimitiveIdx ];
  46. ScnModelMeshData* pMeshData = &pMeshDatas[ pMeshRuntime->MeshDataIndex_ ];
  47. ScnModelNodeTransformData* pNodeTransformData = &pNodeTransformData_[ pMeshData->NodeIndex_ ];
  48. TPerComponentMeshData& PerComponentMeshData = PerComponentMeshDataList_[ PrimitiveIdx ];
  49. BcU32 Offset = 0; // This will change when index buffers are merged.
  50.  
  51. BcAssertMsg( PerComponentMeshData.MaterialComponentRef_.isValid(), "Material not valid for use on ScnModelComponent \"%s\"", (*getName()).c_str() );
  52.  
  53. // Set skinning parameters.
  54. if( pMeshData->IsSkinned_ )
  55. {
  56. PerComponentMeshData.MaterialComponentRef_->setBoneUniformBlock( PerComponentMeshData.UniformBuffer_ );
  57. }
  58. else
  59. {
  60. PerComponentMeshData.MaterialComponentRef_->setObjectUniformBlock( PerComponentMeshData.UniformBuffer_ );
  61. }
  62.  
  63. // Set lighting parameters.
  64. LightingVisitor.setMaterialParameters( PerComponentMeshData.MaterialComponentRef_ );
  65.  
  66. // Set material components for view.
  67. pViewComponent->setMaterialParameters( PerComponentMeshData.MaterialComponentRef_ );
  68.  
  69. // Bind material.
  70. PerComponentMeshData.MaterialComponentRef_->bind( pFrame, Sort );
  71.  
  72. // Render primitive.
  73. ScnModelComponentRenderNode* pRenderNode = pFrame->newObject< ScnModelComponentRenderNode >();
  74.  
  75. pRenderNode->Type_ = pMeshData->Type_;
  76. pRenderNode->Offset_ = Offset;
  77. pRenderNode->NoofIndices_ = pMeshData->NoofIndices_;
  78. pRenderNode->IndexBuffer_ = pMeshRuntime->pIndexBuffer_;
  79. pRenderNode->VertexBuffer_ = pMeshRuntime->pVertexBuffer_;
  80. pRenderNode->VertexStride_ = pMeshData->VertexStride_;
  81. pRenderNode->VertexDeclaration_ = pMeshRuntime->pVertexDeclaration_;
  82. pRenderNode->Sort_ = Sort;
  83.  
  84. pFrame->addRenderNode( pRenderNode );
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement