From d17fdf3ab6abdc68d5a6524fce7683bd302d3cad Mon Sep 17 00:00:00 2001 From: Andrew Poor Date: Wed, 27 Jul 2016 16:31:51 +0100 Subject: [PATCH] Updated primitive shape generation to allow for back face culling. Change-Id: I99fd9d4ae844cd66bb6621de6adb7f701f19c339 --- .../visuals/primitive/primitive-visual.cpp | 91 +++++++++++----------- .../internal/visuals/primitive/primitive-visual.h | 2 + .../visuals.md | 2 + 3 files changed, 50 insertions(+), 45 deletions(-) diff --git a/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp b/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp index 7634ce5..47fa010 100644 --- a/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp +++ b/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp @@ -424,6 +424,7 @@ void PrimitiveVisual::InitializeRenderer() } mImpl->mRenderer = Renderer::New( mGeometry, mShader ); + mImpl->mRenderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK ); } void PrimitiveVisual::UpdateShaderUniforms() @@ -644,16 +645,16 @@ void PrimitiveVisual::FormSphereTriangles( Vector& indices, int for( int i = 1; i <= slices; i++, indiceIndex += 3 ) { indices[indiceIndex] = 0; - indices[indiceIndex + 1] = i; if( i == slices ) { //End, so loop around. - indices[indiceIndex + 2] = 1; + indices[indiceIndex + 1] = 1; } else { - indices[indiceIndex + 2] = i + 1; + indices[indiceIndex + 1] = i + 1; } + indices[indiceIndex + 2] = i; } //Middle Stacks. Want to form triangles between the top and bottom stacks, so loop up to the number of stacks - 2. @@ -665,20 +666,20 @@ void PrimitiveVisual::FormSphereTriangles( Vector& indices, int { //End, so loop around. indices[indiceIndex] = previousCycleBeginning + j; - indices[indiceIndex + 1] = currentCycleBeginning + j; - indices[indiceIndex + 2] = previousCycleBeginning; + indices[indiceIndex + 1] = previousCycleBeginning; + indices[indiceIndex + 2] = currentCycleBeginning + j; indices[indiceIndex + 3] = currentCycleBeginning + j; - indices[indiceIndex + 4] = currentCycleBeginning; - indices[indiceIndex + 5] = previousCycleBeginning; + indices[indiceIndex + 4] = previousCycleBeginning; + indices[indiceIndex + 5] = currentCycleBeginning; } else { indices[indiceIndex] = previousCycleBeginning + j; - indices[indiceIndex + 1] = currentCycleBeginning + j; - indices[indiceIndex + 2] = previousCycleBeginning + 1 + j; + indices[indiceIndex + 1] = previousCycleBeginning + 1 + j; + indices[indiceIndex + 2] = currentCycleBeginning + j; indices[indiceIndex + 3] = currentCycleBeginning + j; - indices[indiceIndex + 4] = currentCycleBeginning + 1 + j; - indices[indiceIndex + 5] = previousCycleBeginning + 1 + j; + indices[indiceIndex + 4] = previousCycleBeginning + 1 + j; + indices[indiceIndex + 5] = currentCycleBeginning + 1 + j; } } } @@ -866,16 +867,16 @@ void PrimitiveVisual::FormConicTriangles( Vector& indices, float for( int i = 0; i < slices; i++, indiceIndex += 3 ) { indices[indiceIndex] = bottomFaceCycleBeginning; - indices[indiceIndex + 1] = bottomFaceCycleBeginning + i; if( i == slices - 1 ) { //End, so loop around. - indices[indiceIndex + 2] = bottomFaceCycleBeginning; + indices[indiceIndex + 1] = bottomFaceCycleBeginning; } else { - indices[indiceIndex + 2] = bottomFaceCycleBeginning + i + 1; + indices[indiceIndex + 1] = bottomFaceCycleBeginning + i + 1; } + indices[indiceIndex + 2] = bottomFaceCycleBeginning + i; } } else if( !coneTop || !coneBottom ) @@ -900,16 +901,16 @@ void PrimitiveVisual::FormConicTriangles( Vector& indices, float for( int i = 1; i <= slices; i++, indiceIndex += 3 ) { indices[indiceIndex] = 2 * slices + 1; - indices[indiceIndex + 1] = slices + i; if( i == slices ) { //End, so loop around. - indices[indiceIndex + 2] = slices + 1; + indices[indiceIndex + 1] = slices + 1; } else { - indices[indiceIndex + 2] = slices + i + 1; + indices[indiceIndex + 1] = slices + i + 1; } + indices[indiceIndex + 2] = slices + i; } } } @@ -1006,11 +1007,11 @@ void PrimitiveVisual::FormCubeTriangles( Vector& indices ) //Top face. indices[triangleIndex] = 0; - indices[triangleIndex + 1] = 1; - indices[triangleIndex + 2] = 2; + indices[triangleIndex + 1] = 2; + indices[triangleIndex + 2] = 1; indices[triangleIndex + 3] = 2; - indices[triangleIndex + 4] = 3; - indices[triangleIndex + 5] = 0; + indices[triangleIndex + 4] = 0; + indices[triangleIndex + 5] = 3; triangleIndex += 6; int topFaceStart = 4; @@ -1020,11 +1021,11 @@ void PrimitiveVisual::FormCubeTriangles( Vector& indices ) for( int i = 0; i < 8; i += 2, triangleIndex += 6 ) { indices[triangleIndex ] = i + topFaceStart; - indices[triangleIndex + 1] = i + bottomFaceStart + 1; - indices[triangleIndex + 2] = i + topFaceStart + 1; + indices[triangleIndex + 1] = i + topFaceStart + 1; + indices[triangleIndex + 2] = i + bottomFaceStart + 1; indices[triangleIndex + 3] = i + topFaceStart; - indices[triangleIndex + 4] = i + bottomFaceStart; - indices[triangleIndex + 5] = i + bottomFaceStart + 1; + indices[triangleIndex + 4] = i + bottomFaceStart + 1; + indices[triangleIndex + 5] = i + bottomFaceStart; } //Bottom face. @@ -1084,19 +1085,19 @@ void PrimitiveVisual::ComputeOctahedronVertices( Vector& vertices, Vecto //End, so loop around. vertices[vertexIndex ].position = positions[0]; vertices[vertexIndex ].normal = outerNormals[0] * smoothness + normals[i] * (1 - smoothness); - vertices[vertexIndex + 1].position = positions[i + 1]; - vertices[vertexIndex + 1].normal = outerNormals[i + 1] * smoothness + normals[i] * (1 - smoothness); - vertices[vertexIndex + 2].position = positions[1]; - vertices[vertexIndex + 2].normal = outerNormals[1] * smoothness + normals[i] * (1 - smoothness); + vertices[vertexIndex + 1].position = positions[1]; + vertices[vertexIndex + 1].normal = outerNormals[1] * smoothness + normals[i] * (1 - smoothness); + vertices[vertexIndex + 2].position = positions[i + 1]; + vertices[vertexIndex + 2].normal = outerNormals[i + 1] * smoothness + normals[i] * (1 - smoothness); } else { vertices[vertexIndex ].position = positions[0]; vertices[vertexIndex ].normal = outerNormals[0] * smoothness + normals[i] * (1 - smoothness); - vertices[vertexIndex + 1].position = positions[i + 1]; - vertices[vertexIndex + 1].normal = outerNormals[i + 1] * smoothness + normals[i] * (1 - smoothness); - vertices[vertexIndex + 2].position = positions[i + 2]; - vertices[vertexIndex + 2].normal = outerNormals[i + 2] * smoothness + normals[i] * (1 - smoothness); + vertices[vertexIndex + 1].position = positions[i + 2]; + vertices[vertexIndex + 1].normal = outerNormals[i + 2] * smoothness + normals[i] * (1 - smoothness); + vertices[vertexIndex + 2].position = positions[i + 1]; + vertices[vertexIndex + 2].normal = outerNormals[i + 1] * smoothness + normals[i] * (1 - smoothness); } } @@ -1392,11 +1393,11 @@ void PrimitiveVisual::FormBevelledCubeTriangles( Vector& indices //Top face. indices[indiceIndex ] = vertexIndex; - indices[indiceIndex + 1] = vertexIndex + 1; - indices[indiceIndex + 2] = vertexIndex + 2; + indices[indiceIndex + 1] = vertexIndex + 2; + indices[indiceIndex + 2] = vertexIndex + 1; indices[indiceIndex + 3] = vertexIndex + 0; - indices[indiceIndex + 4] = vertexIndex + 2; - indices[indiceIndex + 5] = vertexIndex + 3; + indices[indiceIndex + 4] = vertexIndex + 3; + indices[indiceIndex + 5] = vertexIndex + 2; indiceIndex += 6; vertexIndex += 4; @@ -1405,16 +1406,16 @@ void PrimitiveVisual::FormBevelledCubeTriangles( Vector& indices { //Triangle part. indices[indiceIndex ] = vertexIndex; - indices[indiceIndex + 1] = vertexIndex + 1; - indices[indiceIndex + 2] = vertexIndex + 2; + indices[indiceIndex + 1] = vertexIndex + 2; + indices[indiceIndex + 2] = vertexIndex + 1; //Rectangle part. indices[indiceIndex + 3] = vertexIndex + 3; indices[indiceIndex + 4] = vertexIndex + 4; indices[indiceIndex + 5] = vertexIndex + 5; indices[indiceIndex + 6] = vertexIndex + 4; - indices[indiceIndex + 7] = vertexIndex + 5; - indices[indiceIndex + 8] = vertexIndex + 6; + indices[indiceIndex + 7] = vertexIndex + 6; + indices[indiceIndex + 8] = vertexIndex + 5; } //Side faces. @@ -1424,8 +1425,8 @@ void PrimitiveVisual::FormBevelledCubeTriangles( Vector& indices indices[indiceIndex + 1] = vertexIndex + 1; indices[indiceIndex + 2] = vertexIndex + 2; indices[indiceIndex + 3] = vertexIndex + 1; - indices[indiceIndex + 4] = vertexIndex + 2; - indices[indiceIndex + 5] = vertexIndex + 3; + indices[indiceIndex + 4] = vertexIndex + 3; + indices[indiceIndex + 5] = vertexIndex + 2; } //Bottom slopes. @@ -1441,8 +1442,8 @@ void PrimitiveVisual::FormBevelledCubeTriangles( Vector& indices indices[indiceIndex + 4] = vertexIndex + 4; indices[indiceIndex + 5] = vertexIndex + 5; indices[indiceIndex + 6] = vertexIndex + 4; - indices[indiceIndex + 7] = vertexIndex + 5; - indices[indiceIndex + 8] = vertexIndex + 6; + indices[indiceIndex + 7] = vertexIndex + 6; + indices[indiceIndex + 8] = vertexIndex + 5; } //Bottom face. diff --git a/dali-toolkit/internal/visuals/primitive/primitive-visual.h b/dali-toolkit/internal/visuals/primitive/primitive-visual.h index 8c75394..bc57a9b 100644 --- a/dali-toolkit/internal/visuals/primitive/primitive-visual.h +++ b/dali-toolkit/internal/visuals/primitive/primitive-visual.h @@ -60,6 +60,8 @@ namespace Internal /** * The visual which renders a simple 3D shape to the control's quad * + * Primitives are created with clockwise winding and back-face culling by default. + * * The following properties are required to create a PrimitiveRender * * | %Property Name | Type | diff --git a/docs/content/shared-javascript-and-cpp-documentation/visuals.md b/docs/content/shared-javascript-and-cpp-documentation/visuals.md index 4051b07..cff96d1 100644 --- a/docs/content/shared-javascript-and-cpp-documentation/visuals.md +++ b/docs/content/shared-javascript-and-cpp-documentation/visuals.md @@ -484,6 +484,8 @@ ________________________________________________________________________________ Renders a simple 3D shape, such as a cube or sphere. Scaled to fit the control. +The shapes are generated with clockwise winding and back-face culling on by default. + ![ ](../assets/img/visuals/cube.png) ![ ](visuals/cube.png) -- 2.7.4