@@ -169,8 +169,8 @@ namespace glsample {
169169 this ->UBOStructure .material_align_total_size ;
170170
171171 /* */
172- glGenBuffers (1 , &this ->UBOStructure .node_and_common_uniform_buffer );
173- glBindBuffer (GL_UNIFORM_BUFFER , this ->UBOStructure .node_and_common_uniform_buffer );
172+ glGenBuffers (1 , &this ->UBOStructure .shared_uniform_buffer );
173+ glBindBuffer (GL_UNIFORM_BUFFER , this ->UBOStructure .shared_uniform_buffer );
174174
175175 if (glBufferStorage) {
176176
@@ -392,7 +392,7 @@ namespace glsample {
392392 }
393393 }
394394
395- glBindBuffer (GL_UNIFORM_BUFFER , this ->UBOStructure .node_and_common_uniform_buffer );
395+ glBindBuffer (GL_UNIFORM_BUFFER , this ->UBOStructure .shared_uniform_buffer );
396396
397397 /* */
398398 if (useCoherent) {
@@ -659,12 +659,12 @@ namespace glsample {
659659 const size_t light_offset = this ->UBOStructure .light_offsets [this ->getRoundRobinIndex ()];
660660
661661 glBindBufferRange (GL_UNIFORM_BUFFER , this ->UBOStructure .common_buffer_binding ,
662- this ->UBOStructure .node_and_common_uniform_buffer , common_offset,
662+ this ->UBOStructure .shared_uniform_buffer , common_offset,
663663 this ->UBOStructure .common_size_align );
664664
665665 /* */
666666 glBindBufferRange (GL_UNIFORM_BUFFER , this ->UBOStructure .light_buffer_binding ,
667- this ->UBOStructure .node_and_common_uniform_buffer , light_offset,
667+ this ->UBOStructure .shared_uniform_buffer , light_offset,
668668 this ->UBOStructure .light_align_total_size );
669669 }
670670
@@ -918,18 +918,20 @@ namespace glsample {
918918 this ->UBOStructure .node_prev_offsets [this ->getRoundRobinIndex ()] +
919919 (node_block_offset_base * this ->UBOStructure .max_node_per_binding * sizeof (NodeData));
920920
921+ /* */
921922 glBindBufferRange (GL_UNIFORM_BUFFER , this ->UBOStructure .node_buffer_binding ,
922- this ->UBOStructure .node_and_common_uniform_buffer , node_total_offset,
923+ this ->UBOStructure .shared_uniform_buffer , node_total_offset,
923924 this ->UBOStructure .node_size_align );
924925
926+ /* */
925927 glBindBufferRange (GL_UNIFORM_BUFFER , this ->UBOStructure .node_prev_buffer_binding ,
926- this ->UBOStructure .node_and_common_uniform_buffer , node_prev_total_offset,
928+ this ->UBOStructure .shared_uniform_buffer , node_prev_total_offset,
927929 this ->UBOStructure .node_size_align );
928930
929931 /* */
930932 const size_t material_offset = this ->UBOStructure .mateiral_offsets [this ->getRoundRobinIndex ()];
931933 glBindBufferRange (GL_UNIFORM_BUFFER , this ->UBOStructure .material_buffer_binding ,
932- this ->UBOStructure .node_and_common_uniform_buffer , material_offset,
934+ this ->UBOStructure .shared_uniform_buffer , material_offset,
933935 this ->UBOStructure .material_align_size );
934936 }
935937
@@ -946,25 +948,25 @@ namespace glsample {
946948 const MeshObject &refMesh = this ->refGeometry [mesh_index];
947949 glBindVertexArray (refMesh.vao );
948950
949- /* Material, model matrix. */
951+ /* Material index , model matrix index . */
950952 glVertexAttribI2i (8 , material_index, currentNodeIndex % this ->UBOStructure .max_node_per_binding );
951953
952954 /* */
955+ const size_t nrInstances = 1 ;
953956 if (this ->getRenderingSettings ().enabledTessellation && material.isTessellationEnabled ()) {
954957
955958 /* */
956959 glPatchParameteri (GL_PATCH_VERTICES , 3 );
957- glDrawElementsBaseVertex ( fragcore::GLHelper::getPrimitive (Primitive::Patchs), refMesh. nrIndicesElements ,
958- GL_UNSIGNED_INT , ( void *)( sizeof ( unsigned int ) * refMesh.indices_offset ) ,
959- refMesh.vertex_offset );
960+ glDrawElementsInstancedBaseVertex (
961+ fragcore::GLHelper::getPrimitive (Primitive::Patchs), refMesh.nrIndicesElements , GL_UNSIGNED_INT ,
962+ ( void *)( sizeof ( unsigned int ) * refMesh. indices_offset ), nrInstances, refMesh.vertex_offset );
960963 } else {
961964
962965 /* */
963- glDrawElementsBaseVertex (
966+ glDrawElementsInstancedBaseVertex (
964967 fragcore::GLHelper::getPrimitive (refMesh.primitiveType ), refMesh.nrIndicesElements , GL_UNSIGNED_INT ,
965- (void *)(sizeof (unsigned int ) * refMesh.indices_offset ), refMesh.vertex_offset );
968+ (void *)(sizeof (unsigned int ) * refMesh.indices_offset ), nrInstances, refMesh.vertex_offset );
966969 }
967- // glBindVertexArray(0);
968970 }
969971
970972 /* Update internal states*/
@@ -1006,7 +1008,6 @@ namespace glsample {
10061008
10071009 assert (material);
10081010
1009- /* */
10101011 /* TODO domain clamping. */
10111012 const RenderQueue domain = material->getRenderQueue ();
10121013
@@ -1019,50 +1020,31 @@ namespace glsample {
10191020 }
10201021 }
10211022
1022- // multi thread.
1023- // #pragma omp parallel for
1023+ // multi thread.
1024+ // #pragma omp parallel for
10241025 for (size_t domain_index = 0 ; domain_index < getQueueTypesOrdered ().size (); domain_index++) {
10251026 const RenderQueue domain = getQueueTypesOrdered ()[domain_index];
10261027
10271028 std::deque<const Node *> queue = this ->renderQueueDomainBucket [domain];
10281029
1029- std::sort (queue.begin (), queue.end (), [&](const Node *a, const Node *b) {
1030- return getMaterials ()[a->materialIndex [0 ]].getUID () > getMaterials ()[b->materialIndex [0 ]].getUID ();
1031- });
1032-
1033- this ->renderQueue [domain_index] = queue;
1034- }
1030+ if (this ->getRenderingSettings ().sortSharedMaterials ) {
10351031
1036- if (this ->getRenderingSettings ().sortDistance ) {
1032+ std::sort (queue.begin (), queue.end (), [&](const Node *a, const Node *b) {
1033+ return getMaterials ()[a->materialIndex [0 ]].getUID () > getMaterials ()[b->materialIndex [0 ]].getUID ();
1034+ });
1035+ }
10371036
1037+ this ->renderQueue [domain_index] = queue;
10381038 }
10391039
10401040 if (this ->getRenderingSettings ().mergeInstances ) {
1041+ /* Sort based on Shared mesh objects. */
10411042 }
10421043
1043- /* */
1044-
1045- /* Sort Based on Distance from Camera, front to back. */
1046-
1047- /* Sort Transparent Objects. Based on priority. */
1048- // std::sort(vec.begin(), vec.end(), [this, &index, &edges](const int_iter it1, const int_iter it2) -> bool {
1049- // index[it1 - int_vec.begin()] < index[it2 - int_vec.begin()];
1050- // });
1051-
1052- // int priority = computeMaterialPriority(*material);
1053-
1054- // renderQueueDomainBucket[RenderQueue::Transparent];
1055-
1056- /* Sort based on Shared mesh objects. */
1057-
1058- /* Sort Transparent Objects. Based on distance. */
1059- }
1060-
1061- int Scene::computeMaterialPriority (const Material &material) const noexcept {
1062- const bool use_clipping = material.maskTextureIndex >= 0 && material.maskTextureIndex < refTexture.size ();
1063- const bool useBlending = material.opacity < 1 .0f ;
1064-
1065- return (useBlending * 1000 ) + (use_clipping * 100 );
1044+ if (this ->getRenderingSettings ().sortDistance ) {
1045+ /* Sort Opque Objects. Based on distance. */
1046+ /* Sort Transparent Objects. Based on distance. */
1047+ }
10661048 }
10671049
10681050 void Scene::renderUI () { this ->settingUI .draw (); }
0 commit comments