Commit e1bf40ab8acb88564499ab287c7275602e62e7fd
1 parent
396d6abe
Use PropertyBuffers in the mesh example.
Change-Id: I63bd826f3b0cff77baceef0db81c0b1f11d4de4e
Showing
1 changed file
with
35 additions
and
2 deletions
examples/mesh/mesh-example.cpp
| ... | ... | @@ -60,6 +60,39 @@ void main() |
| 60 | 60 | } |
| 61 | 61 | ); |
| 62 | 62 | |
| 63 | +Geometry CreateGeometry() | |
| 64 | +{ | |
| 65 | + | |
| 66 | + // Create vertices | |
| 67 | + const float halfQuadSize = .5f; | |
| 68 | + struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; }; | |
| 69 | + TexturedQuadVertex texturedQuadVertexData[4] = { | |
| 70 | + { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) }, | |
| 71 | + { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) }, | |
| 72 | + { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) }, | |
| 73 | + { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } }; | |
| 74 | + | |
| 75 | + Property::Map texturedQuadVertexFormat; | |
| 76 | + texturedQuadVertexFormat["aPosition"] = Property::VECTOR2; | |
| 77 | + texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2; | |
| 78 | + PropertyBuffer texturedQuadVertices = PropertyBuffer::New( PropertyBuffer::STATIC, texturedQuadVertexFormat, 4 ); | |
| 79 | + texturedQuadVertices.SetData(texturedQuadVertexData); | |
| 80 | + | |
| 81 | + // Create indices | |
| 82 | + unsigned short indexData[6] = { 0, 3, 1, 0, 2, 3 }; | |
| 83 | + Property::Map indexFormat; | |
| 84 | + indexFormat["indices"] = Property::UNSIGNED_INTEGER; | |
| 85 | + PropertyBuffer indices = PropertyBuffer::New( PropertyBuffer::STATIC, indexFormat, 3 ); | |
| 86 | + indices.SetData(indexData); | |
| 87 | + | |
| 88 | + // Create the geometry object | |
| 89 | + Geometry texturedQuadGeometry = Geometry::New(); | |
| 90 | + texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices ); | |
| 91 | + texturedQuadGeometry.SetIndexBuffer( indices ); | |
| 92 | + | |
| 93 | + return texturedQuadGeometry; | |
| 94 | +} | |
| 95 | + | |
| 63 | 96 | } // anonymous namespace |
| 64 | 97 | |
| 65 | 98 | // This example shows how to use a simple mesh |
| ... | ... | @@ -104,13 +137,13 @@ public: |
| 104 | 137 | application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); |
| 105 | 138 | |
| 106 | 139 | mImage = ResourceImage::New( MATERIAL_SAMPLE ); |
| 107 | - mSampler = Sampler::New( mImage, "sTexture"); | |
| 140 | + mSampler = Sampler::New(mImage, "sTexture"); | |
| 108 | 141 | mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); |
| 109 | 142 | |
| 110 | 143 | mMaterial = Material::New( mShader ); |
| 111 | 144 | mMaterial.AddSampler( mSampler ); |
| 112 | 145 | |
| 113 | - mGeometry = Geometry::New(); // Don't need to set a vertex buffer - it's a quad by default. | |
| 146 | + mGeometry = CreateGeometry(); | |
| 114 | 147 | |
| 115 | 148 | mRenderer = Renderer::New( mGeometry, mMaterial ); |
| 116 | 149 | ... | ... |