-
Notifications
You must be signed in to change notification settings - Fork 7
DALi Rendering API Overview
-
Rendering API building blocks
1.1 Renderer
1.2 PropertyBuffer
1.3 Geometry
1.4 Shader
1.5 Texture
1.6 Sampler
1.7 TextureSet
-
DALi shader built-ins
2.1 Shader vertex attributes built-ins
2.2 Shader uniforms built-ins
The Renderer is responsible for setting graphics API state ( like blending, depth test etc. ) and most of all - issuing a single draw call.
Renderer requires a geometry and shader program to be known upon initialisation. Sample Renderer initialisation may look like below:
using namespace Dali;
Renderer renderer = Renderer::New( geometry, shader );
renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::ON );
renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL );
renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON );
renderer.SetTextures( textureSet );
PropertyBuffer stores a vertex data. It's an equivalent of the GL buffer object. When used for storing geometry it must be instantiated with known data format defined with use of Property::Map. For example:
Dali::Property::Map vertexFormat;
vertexFormat.Add( "aPosition", Dali::Property::VECTOR3 );
vertexFormat.Add( "aNormal", Dali::Property::VECTOR3 );
vertexFormat.Add( "aTexCoord", Dali::Property::VECTOR2 );
Dali::PropertyBuffer vertexBuffer = Dali::PropertyBuffer::New( vertexFormat );
Example above instantiates a buffer containing data for three vertex shader attributes:
- aPosition - vertex position
- aNormal - vertex normal
- aTexCoord - texture coordinates
[2] See property-buffer.h code
Geometry describes vertex input state and topology of the primitives to be drawn. Geometry requires the PropertyBuffer to be known before the initialisation. The Geometry may have attached more than one PropertyBuffer.
geometry = Dali::Geometry::New();
geometry.AddVertexBuffer( vertexBuffer );
geometry.SetType( Geometry::TRIANGLES );
Optionally, the Geometry may specify an index buffer. Then automatically the indexed draw will be enabled.
Shader represents compiled and linked GLSL program. Only Vertex and Fragment shaders are supported. Shader code may be created with use of macro DALI_COMPOSE_SHADER.
For example the vertex and fragment shader source code and Shader instance could be created as shown below:
// vertex shader code
const char* VERTEX_SHADER = DALI_SHADER_COMPOSER(
attribute mediump vec2 aPosition;
attribute mediump vec2 aTexCoord;
uniform mediump mat4 uMvpMatrix;
varying mediump vec2 vTexCoord;
void main()
{
vTexCoord = aTexCoord;
gl_Position = uMvpMatrix * vec4( aPosition, 0.0, 1.0 );
}
);
// fragment shader code
const char* FRAGMENT_SHADER = DALI_SHADER_COMPOSER(
precision mediump float;
uniform sampler2D sTexture;
varying mediump vec2 vTexCoord;
void main()
{
gl_FragColor = texture2D( sTexture, vTexCoord );
}
);
// new shader instance
Dali::Shader shader = Dali::Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
TODO
TODO
TextureSet contains one or more texture-sampler pairs. Textures are bind to the shader program in order of appearance on the list. No reflection is used to determine the binding order.
Attribute name | Format | Descritpion |
---|---|---|
aPosition | Vector2, Vector3 | Vertex position |
aTexCoord | Vector2 | Texture coordinates |
Uniform name | Format | Descritpion |
---|---|---|
uMvpMatrix | Matrix4 | ModelViewProjection matrix |
uModelView | Matrix4 | View matrix |
uProjection | Matrix4 | Projection matrix |
uModelMatrix | Matrix4 | Model matrix |
uNormalMatrix | Matrix3 | Normal matrix |
uColor | Vector4 | Color RGBA |
sTexture | Sampler2D | Main ( default ) texture sampler |
sTextureRect | Vec4 | Texture rect ( sub-rect ) |
sEffect | Sampler2D | Secondary ( Effect ) texture sampler |
uSize | Vector2, Vector3 | Size of geometry |