|
void | addBinaryShader (ShaderType type, ConstByteSpan binary) |
| Adds a binary shader to the program. More...
|
|
void | addFixedUniform (string_view name) |
| Adds a fixed uniform to a shader. More...
|
|
void | addFixedUniform (string_view name, ShaderProgram::UniformTransformation transformation) |
| Adds a fixed uniform to a shader. More...
|
|
void | addFixedUniform (string_view name, ShaderProgram::FixedUniform uniform) |
| Adds a fixed uniform to a shader. More...
|
|
void | addFixedUniform (string_view name, ShaderProgram::FixedUniform uniform, ShaderProgram::UniformTransformation transformation) |
| Adds a fixed uniform to a shader. More...
|
|
void | addSourceShader (ShaderType type, string_view source) |
| Adds a source shader to the program. More...
|
|
void | addSourceShader (ShaderType type, const char *source) |
| Adds a source shader to the program. More...
|
|
void | addUniform (string_view name, PropertyDataType dataType, unsigned int elementCount, optional< AbstractPropertyType > propertyType, UniformBindingType bindingType, optional< FixedUniform > fixedOperation, FixedUniformFunction func, UniformTransformation transform) |
| Adds an uniform to shader. More...
|
|
void | addUniform (AbstractPropertyType propertyType, PropertyDataType dataType, unsigned int elementCount, ShaderProgram::UniformTransformation transformation) |
| Adds a property type uniform to shader. More...
|
|
void | addUniform (AbstractPropertyType propertyType, PropertyDataType dataType, unsigned int elementCount) |
| Adds a property type uniform to shader. More...
|
|
void | addUniform (AbstractPropertyType propertyType, ShaderProgram::UniformTransformation transformation) |
| Adds a property type uniform to shader. More...
|
|
void | addUniform (AbstractPropertyType propertyType) |
| Adds a property type uniform to shader. More...
|
|
void | addUniformAndBinding (AbstractPropertyType propertyType, ShaderProgram::UniformTransformation transformation) |
| Adds a property type uniform to a shader with a given uniform transformation and creates for that uniform a default render value binding. More...
|
|
void | addUniformAndBinding (AbstractPropertyType propertyType) |
| Adds a property type uniform to a shader and creates for that uniform a default render value binding. More...
|
|
| CreateInfo () |
| Constructs empty create info structure for shader program creation. More...
|
|
Status | validate (const Renderer &renderer) const |
| Perform validation of shader creation parameters. More...
|
|
Struct that contains all the parameters that Kanzi needs to create a ShaderProgram.
Kanzi loads ShaderProgram::CreateInfo from the kzb file as part of shader creation. You can also use ShaderProgram::CreateInfo to create shaders manually in code.
To define a shader, you must set these fields of the CreateInfo struct:
- Vertex shader code.
- Fragment shader code.
- Binary shader data and format (if applicable).
- Uniform information for each uniform.
- Vertex attribute information for each attribute.
- Render value bindings for uniform data.
Examples
To create a shader whose bindings are in the default state:
const string testFragmentSource(""
"uniform mediump vec4 Diffuse;\n"
"uniform mediump vec4 Emissive;\n"
"uniform mediump vec4 DirectionalLightColor[3];\n"
"uniform mediump vec3 DirectionalLightDirection[3];\n"
"varying mediump vec3 vNormal;\n"
"void main()\n"
"{"
" precision lowp float;\n"
" vec4 color = vec4(0.0);\n"
" vec3 nor = normalize(vNormal);\n"
" for (int it = 0; it < 3; ++it)\n"
" {\n"
" float angle = max(dot(nor, normalize(DirectionalLightDirection[it])), 0.0);\n"
" color += angle * (DirectionalLightColor[it] * Diffuse);\n"
" }\n"
" gl_FragColor = Emissive + color;\n"
"}");
const string testVertexSource(""
"attribute vec3 kzPosition;\n"
"attribute vec3 kzNormal;\n"
"uniform highp mat4 kzNormalMatrix;\n"
"uniform highp mat4 kzProjectionCameraWorldMatrix;\n"
"varying mediump vec3 vNormal;\n"
"void main()\n"
"{\n"
" precision mediump float;\n"
" vNormal = (kzNormalMatrix * vec4(kzNormal, 1.0)).xyz;\n"
" gl_Position = kzProjectionCameraWorldMatrix * vec4(kzPosition.xyz, 1.0);\n"
"}");
ShaderProgram::CreateInfo createInfo;
createInfo.blendingControl = true;
{
createInfo.bindings.emplace_back(info->binding, info->targetDataType, info->targetRenderValue);
}
{
createInfo.bindings.emplace_back(info->binding, info->targetDataType, info->targetRenderValue);
}
{
createInfo.bindings.emplace_back(info->binding, info->targetDataType, info->targetRenderValue);
}
{
createInfo.bindings.emplace_back(info->binding, info->targetDataType, info->targetRenderValue);
}
When you want to override binding information, instead of relying on the default states for the bindings, create the bindings manually. To manually create bindings for shaders:
const string testFragmentSource(""
"uniform mediump vec4 Diffuse;\n"
"uniform mediump vec4 DirectionalLightColor[3];\n"
"uniform mediump vec3 DirectionalLightDirection[3];\n"
"varying mediump vec3 vNormal;\n"
"void main()\n"
"{"
" precision lowp float;\n"
" vec4 color = vec4(0.0);\n"
" vec3 nor = normalize(vNormal);\n"
" for (int it = 0; it < 3; ++it)\n"
" {\n"
" float angle = max(dot(nor, normalize(DirectionalLightDirection[it])), 0.0);\n"
" color += angle * (DirectionalLightColor[it] * Diffuse);\n"
" }\n"
" gl_FragColor = color;\n"
"}");
const string testVertexSource(""
"attribute vec3 kzPosition;\n"
"attribute vec3 kzNormal;\n"
"uniform highp mat4 kzNormalMatrix;\n"
"uniform highp mat4 kzProjectionCameraWorldMatrix;\n"
"varying mediump vec3 vNormal;\n"
"void main()\n"
"{\n"
" precision mediump float;\n"
" vNormal = (kzNormalMatrix * vec4(kzNormal, 1.0)).xyz;\n"
" gl_Position = kzProjectionCameraWorldMatrix * vec4(kzPosition.xyz, 1.0);\n"
"}");
ShaderProgram::CreateInfo createInfo;
createInfo.blendingControl = true;
{
vector<Variant>(), 1u);
}
{
vector<Variant> constants;
constants.emplace_back(3);
constants, 4u);
}
{
EXPECT_EQ(true, static_cast<bool>(info));
createInfo.bindings.emplace_back(info->binding, info->targetDataType, info->targetRenderValue);
}