-Renderer CreateRenderer( const char* vertexSrc, const char* fragmentSrc )
-{
- Shader shader = Shader::New( vertexSrc, fragmentSrc );
-
- Geometry texturedQuadGeometry = Geometry::New();
-
- struct VertexPosition { Vector2 position; };
- struct VertexTexture { Vector2 texture; };
-
- VertexPosition positionArray[] =
- {
- { Vector2( -0.5f, -0.5f ) },
- { Vector2( 0.5f, -0.5f ) },
- { Vector2( -0.5f, 0.5f ) },
- { Vector2( 0.5f, 0.5f ) }
- };
- uint32_t numberOfVertices = sizeof(positionArray)/sizeof(VertexPosition);
-
- VertexTexture uvArray[] =
- {
- { Vector2( 0.0f, 0.0f ) },
- { Vector2( 1.0f, 0.0f ) },
- { Vector2( 0.0f, 1.0f ) },
- { Vector2( 1.0f, 1.0f ) }
- };
-
- Property::Map positionVertexFormat;
- positionVertexFormat["aPosition"] = Property::VECTOR2;
- PropertyBuffer positionVertices = PropertyBuffer::New( positionVertexFormat );
- positionVertices.SetData( positionArray, numberOfVertices );
- texturedQuadGeometry.AddVertexBuffer( positionVertices );
-
- Property::Map textureVertexFormat;
- textureVertexFormat["aTexture"] = Property::VECTOR2;
- PropertyBuffer textureVertices = PropertyBuffer::New( textureVertexFormat );
- textureVertices.SetData( uvArray, numberOfVertices );
- texturedQuadGeometry.AddVertexBuffer( textureVertices );
-
- const uint16_t indices[] = { 0, 3, 1, 0, 2, 3 };
- texturedQuadGeometry.SetIndexBuffer ( &indices[0], sizeof( indices )/ sizeof( indices[0] ) );
-
- Renderer renderer = Renderer::New( texturedQuadGeometry, shader );
-
- TextureSet textureSet = TextureSet::New();
- renderer.SetTextures( textureSet );
-
- return renderer;
-}
-
-void SetTexture( Actor actor, Texture texture )
-{
- if( Renderer renderer = actor.GetRendererAt(0) )
- {
- TextureSet textureSet = renderer.GetTextures();
- textureSet.SetTexture( 0u, texture );
- }
-}
-
-void SetTexture( Actor actor, FrameBuffer frameBuffer )
-{
- if( frameBuffer )
- {
- SetTexture( actor, frameBuffer.GetColorTexture() );
- }
-}
-