Skip to content

DALi Rendering API Overview

jsr184 edited this page Feb 8, 2017 · 1 revision

DALi Rendering API Overview

Contents:

  1. 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
  2. DALi shader built-ins
    2.1 Shader vertex attributes built-ins
    2.2 Shader uniforms built-ins

1. Rendering API building blocks

Render API building blocks

1. Renderer

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 );

[1] See renderer.h code

Go back to index

2. PropertyBuffer

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

Go back to index

3. Geometry

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.

[3] See geometry.h code

Go back to index

4. Shader

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 );

[4] See shader.h code

Go back to index

5. Texture

TODO

[5] See texture.h code

Go back to index

6. Sampler

TODO

[6] See sampler.h code

Go back to index

7. TextureSet

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.

[7] See texture-set.h code

Go back to index

2. DALi shader built-ins

Shader vertex attributes built-ins

Attribute name Format Descritpion
aPosition Vector2, Vector3 Vertex position
aTexCoord Vector2 Texture coordinates

Shader uniforms built-ins

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

Go back to index