ShaderProgram defines programmable vertex and fragment operations done by the GPU for a draw call. More...
#include <kanzi/core.ui/platform/graphics_backend/gl/shader.hpp>
Classes | |
struct | BindingInfo |
Binding info. More... | |
struct | CreateInfo |
Struct that contains all the parameters that Kanzi needs to create a ShaderProgram. More... | |
struct | CreateInfoProgramBinary |
ShaderProgram creation parameters for initialized from vendor specific GL program binary. More... | |
struct | CreateInfoShaderBinary |
ShaderProgram creation parameters for initialized from vendor specific GL shader binary. More... | |
struct | CreateInfoShaderSources |
ShaderProgram creation parameters for initialized from shader source code strings. More... | |
struct | FixedUniformFunctionInfo |
Information on fixed uniform function. More... | |
struct | SamplerInfo |
struct | UniformProperty |
Public Member Functions | |
BindingIterator | beginBindings () const |
Gets an iterator to the beginning of bindings. | |
UniformContainerConstIterator | beginFixedUniforms () const |
Gets a const iterator to the beginning of the fixed uniforms. | |
UniformContainerConstIterator | beginUniforms () const |
Gets an const iterator to the beginning of the property uniforms. | |
void | bind () const |
Binds the shader program for rendering. | |
BindingIterator | endBindings () const |
Gets an iterator to the end of bindings. | |
UniformContainerConstIterator | endFixedUniforms () const |
Gets a const iterator to the end of the fixed uniforms. | |
UniformContainerConstIterator | endUniforms () const |
Gets an const iterator to the end of the property uniforms. | |
bool | getBlendingControl () const |
Get shader blending control. | |
UniformTransformation | getFixedUniformTransformation (FixedUniform fixedUniform) const |
Get uniform transformation for a fixed uniform. | |
unsigned int | getProgramHandle () const |
Get shader program handle. | |
AbstractPropertyType | getPropertyTypeByName (string_view propertyTypeName) const |
Gets property type from shader program by name. Returns 0 if not found. | |
bool | getStrictWarningLogged () const |
ShaderTextureUniform | getTextureUniformLocation (unsigned int textureUnit) const |
Returns texture size uniform locations from shader program. | |
unsigned int | getUniformElementCount (string_view name) |
Get uniform element count from the shader program by name. | |
int | getUniformLocation (string_view name) |
Get uniform location from the shader program by name. | |
const ShaderAttributeCollection & | getVertexFormat () const |
bool | hasSamplersWithoutProperties () const |
Return true if shader program has samplers that have no corresponding texture property. | |
bool | isDeployedOverride () const override |
GpuResoucre::isDeployedOverride() implementation. | |
void | reloadFromKzbOverride (KzbFile &kzbFile, ReadOnlyMemoryFile &file, KzbMemoryParser &parser) override |
Resource::reloadFromKzbOverride() implementation. | |
void | setStrictWarningLogged () |
ShaderProgram (Domain *domain, const CreateInfo &createInfo, string_view name) | |
Constructor. | |
Public Member Functions inherited from kanzi::GPUResource | |
void | destroy () |
Destroys a GPU resource. | |
unsigned int | getGPUMemoryUsage () const |
Renderer * | getRenderer () const |
void | invalidate () |
Notify resource that graphics context was lost and all GPU resources are invalid. | |
bool | isDeployed () const |
~GPUResource () override | |
Public Member Functions inherited from kanzi::Resource | |
virtual unsigned int | getCPUMemoryUsage () const |
Function for getting the memory usage of a resource. | |
const string & | getName () const |
Gets the resource name. | |
const string & | getUrl () const |
Gets the resource URL. | |
bool | isKeepAlive () const |
Tells if the resource has keep alive flag set. | |
void | reload () |
void | reloadFromFile (string_view filePath) |
void | reloadFromKzb (KzbFile &kzbFile, ReadOnlyMemoryFile &file, KzbMemoryParser &parser) |
void | setKeepAlive (bool keepAlive) |
Sets the keep alive flag. | |
void | setUrl (string_view url) |
Sets the resource URL. | |
~Resource () override | |
Destructor. | |
Public Member Functions inherited from kanzi::Object | |
AppliedStyleEntrySharedPtr | applyObjectStyle (kanzi::StyleSharedPtr style) |
Applies a style to an object. | |
void | applyObjectStyles () |
Apply all styles for an object node. | |
Domain * | getDomain () const |
Returns the domain the object belongs to. | |
const Metaclass * | getDynamicMetaclass () const override |
Returns the metaclass of the dynamic type of the object. | |
MainLoopScheduler * | getMainLoopScheduler () const |
Returns the MainLoopScheduler instance of the associated Domain. | |
detail::MessageDispatcher * | getMessageDispatcher () const |
Returns the message dispatcher of the object. | |
ResourceManager * | getResourceManager () const |
Returns the resource manager of the object. | |
ScriptingContextSharedPtr | getScriptingContext () const |
Gets the scripting context of the object. | |
Object (Domain *domain) | |
void | setScriptingContext (ScriptingContextSharedPtr context) |
Sets the scripting context of the object. | |
void | unapplyObjectStyle (AppliedStyleEntrySharedPtr appliedStyleEntry) |
void | unapplyObjectStyles () |
Unapplies and removes all applied styles. | |
~Object () override | |
Public Member Functions inherited from kanzi::MetaObject | |
bool | isTypeOf (const Metaclass *objectType) const |
Determines if the type of this object is the given type or derived from it. | |
virtual | ~MetaObject () |
Public Member Functions inherited from kanzi::PropertyObject | |
template<typename DataType > | |
void | addPropertyModifier (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::ModifierCallback callback, void *owner) |
template<typename DataType > | |
void | addPropertyModifierWithoutNotifyingHandlers (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::ModifierCallback callback, void *owner) |
Adds a property modifier without notifying handlers. | |
template<typename DataType > | |
void | addPropertyNotificationHandler (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::NotificationCallback callback, void *owner) |
template<typename DataType > | |
void | addPropertyValueSource (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::TypedValueSource *valueSource, PropertyValuePrecedence precedence, AbstractPropertyTypeDescriptor::ValueSourceOwner *owner) |
template<typename DataType > | |
void | addPropertyValueSource (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::TypedValueSource *valueSource, PropertyValuePrecedence precedence, void *ownerPointer) |
PropertyStorageContainer::iterator | beginPropertyStorage () |
Returns the begin iterator to the internal property storage container. | |
PropertyStorageContainer::const_iterator | beginPropertyStorage () const |
Returns the begin iterator to the internal property storage container. | |
void | clearPropertyFlag (AbstractPropertyType propertyType, uint32_t flag) |
void | copyLocalValue (const PropertyObject &other, AbstractPropertyType propertyType) |
Copies local value of single property from another object. | |
void | copyLocalValues (const PropertyObject &other) |
Copies all local values from another object. | |
PropertyStorageContainer::iterator | endPropertyStorage () |
Returns the end iterator to the internal property storage container. | |
PropertyStorageContainer::const_iterator | endPropertyStorage () const |
Returns the end iterator to the internal property storage container. | |
template<typename DataType > | |
PropertyType< DataType >::Traits::ReturnType | getAbstractProperty (AbstractPropertyType abstractPropertyType) const |
template<typename DataType > | |
PropertyType< DataType >::Traits::ReturnType | getAbstractPropertyBase (AbstractPropertyType abstractPropertyType) const |
template<typename DataType > | |
optional< typename PropertyType< DataType >::Traits::ReturnType > | getOptionalAbstractProperty (AbstractPropertyType abstractPropertyType) const |
template<typename DataType > | |
optional< typename PropertyType< DataType >::Traits::ReturnType > | getOptionalProperty (const PropertyType< DataType > &propertyType) const |
Evaluates the property value in the same way as the overload above but does not default to the value in property metadata if there are no inputs to the property value. | |
template<typename DataType > | |
optional< typename PropertyType< DataType >::Traits::ReturnType > | getOptionalPropertyBase (const PropertyType< DataType > &propertyType) const |
Returns the current value of a property disregarding modifiers, but does not default to the value in property metadata if there are no inputs to the property value. | |
template<typename DataType > | |
PropertyType< DataType >::Traits::ReturnType | getProperty (const PropertyType< DataType > &propertyType) const |
Returns the current value of a property type. | |
template<typename DataType > | |
PropertyType< DataType >::Traits::ReturnType | getPropertyBase (const PropertyType< DataType > &propertyType) const |
Returns the current value of a property disregarding modifiers. | |
template<typename DataType > | |
size_t | getPropertyNotificationHandlerCount (const PropertyType< DataType > &propertyType) const |
Gets number of current notification handlers for given property type. | |
bool | hasBaseValue (AbstractPropertyType propertyType) const |
Evaluates whether there are any inputs into the property value, disregarding modifiers. | |
bool | hasLocalValue (AbstractPropertyType propertyType) const |
Evaluates whether there is a local value set for the property. | |
bool | hasNonClassValue (AbstractPropertyType propertyType) const |
Evaluates whether there is a value of any precedence higher than class default value set for the property. | |
bool | hasValue (AbstractPropertyType propertyType) const |
Evaluates whether there are any inputs into the property value. | |
bool | isPropertyFlagSet (AbstractPropertyType propertyType, uint32_t flag) const |
virtual void | onPropertyChanged (AbstractPropertyType propertyType, PropertyNotificationReason reason) |
Virtual function to handle property change notifications. | |
PropertyObject () | |
void | removeKzbProperties () |
Remove all KZB properties. | |
void | removeKzbProperties (flat_set< AbstractPropertyType > *keepProperties) |
Remove all KZB properties that are not included in a given set. | |
template<typename DataType > | |
void | removeLocalPropertyValueSource (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::TypedValueSource *valueSource, void *ownerPointer) |
void | removeLocalValue (AbstractPropertyType propertyType) |
Removes the local value associated with the property. | |
template<typename DataType > | |
void | removePropertyModifier (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::ModifierCallback callback, void *owner) |
template<typename DataType > | |
void | removePropertyNotificationHandler (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::NotificationCallback callback, void *owner) |
template<typename DataType > | |
void | removePropertyValueSource (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Descriptor::TypedValueSource *valueSource, void *ownerPointer) |
template<typename DataType > | |
void | setAbstractProperty (AbstractPropertyType abstractPropertyType, typename PropertyType< DataType >::Traits::ParameterType value) |
template<typename DataType > | |
void | setProperty (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::Traits::ParameterType value) |
Sets the local value of a property type. | |
void | setPropertyFlag (AbstractPropertyType propertyType, uint32_t flag) |
KZ_DEPRECATED void | validatePropertyModifiers (AbstractPropertyType propertyType) |
Validates property modifiers and notifies handlers. | |
void | validatePropertyModifiersAndNotifyHandlers (AbstractPropertyType propertyType) |
Validates property modifiers and notifies handlers. | |
virtual | ~PropertyObject () |
Static Public Member Functions | |
static ShaderProgramSharedPtr | create (Domain *domain, const CreateInfo &createInfo, string_view name) |
Create function. | |
static ResourceManager::LoadTaskSharedPtr | createLoadTask (string_view name, KzbFile *kzbFile, ReadOnlyMemoryFilePtr file) |
Static Public Member Functions inherited from kanzi::Object | |
static const Metaclass * | getStaticMetaclass () |
Returns the metaclass of Object class. | |
static PropertyTypeEditorInfoSharedPtr | makeEditorInfo () |
Default implementation that returns empty editor info. | |
Static Public Member Functions inherited from kanzi::MetaObject | |
static const Metaclass * | getStaticMetaclass () |
Returns the metaclass of Object class. | |
static PropertyTypeEditorInfoSharedPtr | makeEditorInfo () |
Default implementation that returns empty editor info. | |
Friends | |
void | swap (ShaderProgram &shader1, ShaderProgram &shader2) |
Additional Inherited Members | |
Protected Types inherited from kanzi::Object | |
typedef vector< AppliedStyleEntrySharedPtr > | AppliedStyleContainer |
Applied style container. | |
Protected Attributes inherited from kanzi::Object | |
AppliedStyleContainer | m_appliedStyles |
Listing of applied styles applied to this object. | |
ShaderProgram defines programmable vertex and fragment operations done by the GPU for a draw call.
For each draw call, graphics device executes a vertex shader for each vertex, rasterizes primitives, and for each rasterized fragment, the fragment shader is executed.
In order to create a ShaderProgram, you must prepare ShaderProgram::CreateInfo structure and make sure it is valid using CreateInfo::validate(), then create the ShaderProgram with ShaderProgram::create(). If ShaderProgram creation parameters are not valid, ShaderProgram::create() will throw an exception, which can stop program execution.
ShaderProgram consist of vertex shader, fragment shader, specification of vertex attributes consumed by the vertex shader, and specification of property types that are used to control uniforms,
Shader programs consume per vertex attribute data, and per draw call values known as uniforms.
Vertex attribute data is typically sourced from Meshes. Kanzi Shader lists a number of shader vertex attributes. Shader vertex attributes have name, semantic and semantic type. When Kanzi prepares a draw call, a mesh is typically used as source for attribute data that is consumed by the shader program. Each mesh has a number of mesh vertex attributes; these are mapped to shader vertex attributes based on attribute semantic and semantic index.
Uniforms are typically sourced from properties, for example Material properties, or from engine. Engine uniforms are for example final transform for the current Model3D node being drawn, camera transformation, or positions and colors of lights in the scene. Engine uniforms are also called "fixed uniforms" in Kanzi.
Values of uniforms can be transformed by Kanzi before they are sent to shader program. Currently only color uniforms have transformations available. With linear to sRGB transform, a linear color is convertex to sRGB when it is sent to uniform. With sRGB to linear transform, a sRGB color value is transformed to linear when it is sent to uniform.
typedef void(* kanzi::ShaderProgram::FixedUniformFunction) (Renderer &renderer, int uniformLocation, const Material &material, RenderPass &renderPass, Node &node) |
Function pointer type for fixed operations that do not require a binding.
renderer | Renderer to use. |
uniform | Shader uniform information. |
renderPass | Local render pass context. |
node | Local node context. |
typedef FixedAttributeArray::iterator kanzi::ShaderProgram::FixedAttributeArrayIterator |
typedef FixedAttributeArray::const_iterator kanzi::ShaderProgram::FixedAttributeArrayConstIterator |
typedef UniformContainer::const_iterator kanzi::ShaderProgram::UniformContainerConstIterator |
Container for bindings in the material.
Binding iterator type.
Fixed uniform locations of the shader program.
Enumerator | |
---|---|
ProjectionCameraWorldMatrix | Projection * camera * world matrix. |
WorldMatrix | World matrix. |
ProjectionMatrix | Projection matrix. |
CameraMatrix | Camera matrix. |
CameraPosition | Camera position. |
ViewPosition | Homogeneous position to use for calculating the view direction to world position. |
Viewport | Viewport area. |
WindowSize | Vec2 containing current window size. |
NormalMatrix | Normal matrix. |
CameraNormalMatrix | Camera * normal matrix (screen space normal). |
CameraWorldMatrix | Camera * world matrix. |
NearFarPlane | Vec2 containing near and far plane. |
Time | Debug timer. |
MorphWeights | Morph weights. |
MorphIndices | Morph indices. \since Kanzi 3.9.7 |
MorphDataTexture | Morph data texture. \since Kanzi 3.9.7 |
MorphDataPositionOffset | Morph position offset. \since Kanzi 3.9.7 |
MorphDataNormalOffset | Morph normal offset. \since Kanzi 3.9.7 |
MorphDataTangentOffset | Morph tangent offset. \since Kanzi 3.9.7 |
MorphDataSize | The combined size, in pixels, of all morph data elements. \since Kanzi 3.9.7 |
MatrixPalette | Bone matrices. |
Count | Number of fixed uniforms. |
Invalid |
How value for uniform should be transformed when setting uniform value.
|
explicit |
Constructor.
domain | Domain to use. |
createInfo | Shader create info. |
name | Shader name. |
|
static |
|
static |
Create function.
domain | Domain to use. |
createInfo | Shader create info. |
name | Shader name. |
|
inline |
Get shader blending control.
AbstractPropertyType kanzi::ShaderProgram::getPropertyTypeByName | ( | string_view | propertyTypeName | ) | const |
Gets property type from shader program by name. Returns 0 if not found.
|
inline |
Gets a const iterator to the beginning of the fixed uniforms.
This is the same as the beginning of the uniform list.
|
inline |
Gets a const iterator to the end of the fixed uniforms.
This is the same as the end of the uniform list if there is only fixed uniforms.
|
inline |
Gets an const iterator to the beginning of the property uniforms.
|
inline |
Gets an const iterator to the end of the property uniforms.
|
inline |
Gets an iterator to the beginning of bindings.
|
inline |
Gets an iterator to the end of bindings.
Get shader program handle.
const ShaderAttributeCollection & kanzi::ShaderProgram::getVertexFormat | ( | ) | const |
void kanzi::ShaderProgram::bind | ( | ) | const |
Binds the shader program for rendering.
bool kanzi::ShaderProgram::hasSamplersWithoutProperties | ( | ) | const |
Return true if shader program has samplers that have no corresponding texture property.
ShaderTextureUniform kanzi::ShaderProgram::getTextureUniformLocation | ( | unsigned int | textureUnit | ) | const |
Returns texture size uniform locations from shader program.
int kanzi::ShaderProgram::getUniformLocation | ( | string_view | name | ) |
Get uniform location from the shader program by name.
name | Name of the uniform. Compared to the property name. |
Get uniform element count from the shader program by name.
name | Name of the uniform. Compared to the property name. |
UniformTransformation kanzi::ShaderProgram::getFixedUniformTransformation | ( | FixedUniform | fixedUniform | ) | const |
Get uniform transformation for a fixed uniform.
fixedUniform | Fixed uniform to query. |
|
inline |
|
inline |
|
overridevirtual |
Resource::reloadFromKzbOverride() implementation.
Reimplemented from kanzi::Resource.
|
overridevirtual |
GpuResoucre::isDeployedOverride() implementation.
Implements kanzi::GPUResource.
|
overrideprotectedvirtual |
Resource::reloadOverride() implementation.
Reimplemented from kanzi::Resource.
|
overrideprotectedvirtual |
GPUResource::invalidateOverride() implementation.
Reimplemented from kanzi::GPUResource.
|
overrideprotectedvirtual |
GPUResource::destroyOverride() implementation.
Reimplemented from kanzi::GPUResource.
|
friend |