#include <kanzi/graphics_3d/shader.hpp>
Classes | |
struct | BinaryProgramData |
struct | BinaryShadersCombinedData |
struct | BinaryShadersSeparateData |
class | DeployContext |
struct | ShaderData |
struct | ShaderSourceCodeData |
Public Member Functions | |
Shader (Domain *domain, string_view name="") | |
virtual | ~Shader () KZ_OVERRIDE |
virtual bool | isRenderable () const |
Returns true if the shader is deployed and valid. More... | |
void | addPropertyType (const KzuPropertyType *propertyType) |
Adds property type to shader. More... | |
bool | hasPropertyType (const KzuPropertyType *propertyType) const |
Tell if shader has a property type. More... | |
void | removePropertyType (const KzuPropertyType *propertyType) |
Removes property type from shader. More... | |
const KzuPropertyType * | getPropertyTypeByName (kzString propertyTypeName) const |
Gets property type from shader by name. Returns 0 if not found. More... | |
PropertyTypeContainer::const_iterator | beginPropertyTypes () const |
PropertyTypeContainer::const_iterator | endPropertyTypes () const |
unsigned int | getProgramHandle () const |
Get shader program handle. More... | |
const vector< string > & | getAttributes () const |
int | getAttributeIndex (const string &attributeName) const |
Get location of attribute in Shader from attribute name. More... | |
void | bind () const |
Binds the shader for rendering. More... | |
bool | hasSamplersWithoutProperties () const |
Return true if shader has samplers that have no corresponding texture property. More... | |
void | getTextureUniformLocation (unsigned int textureUnit, int *out_textureWidthUniformLocation, int *out_textureHeightUniformLocation) |
Returns texture size uniform locations from shader. More... | |
void | clearTextureUniformLocations () |
Clear texture uniform location array. More... | |
int | getUniformLocation (unsigned int propertyIndex) |
Get uniform location in Shader with property index. More... | |
void | initializeFromMemory (const char *const vertexShaderSourceSource, const char *const fragmentShaderSourceCode, unsigned int attributeCount, const char *const *attributes) |
Prepare Shader by providing vertex and fragment shader sources. More... | |
void | initializeFromMemory (unsigned int shaderBinaryFormat, unsigned int dataSize, void *data, unsigned int attributeCount, const char *const *attributes) |
Prepare Shader by providing precompiled binary shader data. More... | |
void | initializeFromMemory (unsigned int shaderBinaryFormat, unsigned int vertexDataSize, void *vertexData, unsigned int fragmentDataSize, void *fragmentData, unsigned int attributeCount, const char *const *attributes) |
Prepare Shader by providing precompiled binary shader data. More... | |
void | setStrictWarningLogged () |
bool | getStrictWarningLogged () const |
unsigned int | getLightCount (Light::Type lightType) const |
virtual void | loadFromKZB (const KzuResourceLoaderThreadContext *threadContext, KzcInputStream *inputStream, const KzuBinaryFileInfo *file) KZ_OVERRIDE |
Function for loading the resource from .KZB. More... | |
virtual kzUint | getCPUMemoryUsage () const KZ_OVERRIDE |
Function for getting the memory usage of a resource. More... | |
virtual void | unloadOverride () KZ_OVERRIDE |
Unload function for resource. More... | |
![]() | |
virtual | ~GPUResource () KZ_OVERRIDE |
void | deploy () |
Make graphics API object(s) in the resource usable by preparing GPU objects and data in them. More... | |
void | undeploy () |
Free the GPU objects. After this, the resource is not usable for graphics API until deploy() is called again. More... | |
void | invalidate () |
Notify resource that graphics context was lost and all GPU resources are invalid. More... | |
unsigned int | getGPUMemoryUsage () const |
Renderer * | getRenderer () const |
bool | getDeployOnLoad () const |
Returns true if GPUResource is automatically deployed when loaded. More... | |
void | setDeployOnLoad (bool value) |
Sets GPUResource automatic deployment on loade on or orr. More... | |
bool | isDeployed () const |
void | deployed () |
void | undeployed () |
virtual void | finishLoadingOverride (const KzuResourceLoaderThreadContext *threadContext) KZ_OVERRIDE |
Function for finishing the loading of the resource. More... | |
![]() | |
KzcMemoryManager * | getMemoryManager () const |
Resource (Domain *domain, string_view name) | |
virtual | ~Resource () |
void | setKZB (const KzuBinaryDirectory *binaryDirectory, kzString path) |
void | setLoaded () |
kzString | getName () const |
Accessor. More... | |
void | load () |
void | unload () |
bool | isLoaded () const |
void | kzuResourceLoad_private (const KzuResourceLoaderThreadContext *threadContext) |
Private function for kzuResourceLoad() with specified thread context. More... | |
void | kzuResourceFinishLoading_private (const KzuResourceLoaderThreadContext *threadContext) |
Private function for finishing the loading of the resource. More... | |
KzuResourceLoadingStrategy | getLoadingStrategy () const |
void | setLoadingStrategy (KzuResourceLoadingStrategy loadingStrategy) |
bool | getKeepAlive () const |
Tells if the resource has keep alive flag set. More... | |
void | setKeepAlive (bool keepAlive) |
Sets the keep alive flag. More... | |
![]() | |
Object (Domain *domain) | |
virtual | ~Object () |
Domain * | getDomain () const |
Returns the domain the object belongs to. More... | |
KzuPropertyManager * | getPropertyManager () const |
Returns the property manager of the object. More... | |
KzuTaskScheduler * | getTaskScheduler () const |
Returns the task scheduler of the object. More... | |
KzuMessageDispatcher * | getMessageDispatcher () const |
Returns the message dispatcher of the object. More... | |
ResourceManager * | getResourceManager () const |
Returns the resource manager of the object. More... | |
virtual const Metaclass * | getDynamicMetaclass () const |
Returns the metaclass of the dynamic type of the object. More... | |
bool | isTypeOf (const Metaclass *objectType) const |
Determines if the type of this object is the given type or derived from it. More... | |
template<typename DataType > | |
void | setProperty (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::DataType value) |
Sets the local value of a property. More... | |
void | setProperty (const PropertyType< ResourceID > &propertyType, ResourceSharedPtr value) |
Sets the local value of a resource id property with a resource pointer. More... | |
template<typename DataType > | |
DataType | getProperty (const PropertyType< DataType > &propertyType) const |
Returns the current value of a property. More... | |
template<typename DataType > | |
bool | getProperty (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::DataType &value) 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. More... | |
template<typename DataType > | |
void | setAbstractProperty (AbstractPropertyType abstractPropertyType, typename PropertyType< DataType >::DataType value) |
void | setAbstractProperty (AbstractPropertyType abstractPropertyType, ResourceSharedPtr value) |
template<typename DataType > | |
DataType | getAbstractProperty (AbstractPropertyType abstractPropertyType) const |
template<typename DataType > | |
bool | getAbstractProperty (AbstractPropertyType abstractPropertyType, typename PropertyType< DataType >::DataType &value) const |
bool | hasValue (AbstractPropertyType propertyType) const |
Evaluates whether there are any inputs into the property value. More... | |
bool | hasLocalValue (AbstractPropertyType propertyType) const |
Evaluates whether there is a local value set for the property. More... | |
void | removeLocalValue (AbstractPropertyType propertyType) |
Removes the local value associated with the property. More... | |
void | copyLocalValues (const Object &other) |
Copies all local values from another object. More... | |
virtual void | onPropertyChanged (AbstractPropertyType propertyType, KzuPropertyNotificationReason reason) |
Virtual function to handle property change notifications. More... | |
AppliedStyleEntry * | applyObjectStyle (kanzi::StyleSharedPtr style) |
Applies a style to an object. More... | |
void | unapplyObjectStyle (AppliedStyleEntry *appliedStyleEntry) |
void | applyObjectStyles () |
Apply all styles for an object node. More... | |
void | unapplyObjectStyles () |
Unapplies and removes all applied styles. More... | |
Static Public Member Functions | |
static ShaderSharedPtr | create (Domain *domain, string_view name="") |
![]() | |
static const Metaclass * | getStaticMetaclass () |
Returns the metaclass of Object class. More... | |
static PropertyTypeEditorInfoSharedPtr | makeEditorInfo () |
Default implementation that returns empty editor info. More... | |
Protected Types | |
enum | ProgramType { ProgramTypeNotDeployed, ProgramTypeShaderSources, ProgramTypeBinaryShadersSeparate, ProgramTypeBinaryShadesCombined, ProgramTypeBinaryProgram } |
Describes state of program after tryDeploy() More... | |
typedef array< int, VertexAttribute::SemanticCount > | FixedAttributeArray |
![]() | |
typedef vector < AppliedStyleEntry * > | AppliedStyleContainer |
Applied style container. More... | |
Protected Member Functions | |
virtual void | deployOverride () KZ_OVERRIDE |
Make graphics API object(s) in the resource usable by preparing GPU objects and data in them. Called by deploy() More... | |
virtual void | invalidateOverride () KZ_OVERRIDE |
Notify resource that graphics context was lost and all GPU resources are invalid. Called by invalidate() More... | |
virtual void | undeployOverride () KZ_OVERRIDE |
Free the GPU objects. After this, the resource is not usable for graphics API until deploy() is called again. Called by undeploy() More... | |
virtual void | freeCommonData () KZ_OVERRIDE |
Notify resource that graphics context was lost and all GPU resources are invalid. More... | |
void | setAttributes (unsigned int attributeCount, const char *const *attributes) |
ProgramType | tryDeploy (const GLProgramHandle &programHandle) |
Tries to deploy the program. More... | |
void | findDefaultSamplers () |
Locate samplers in program which are missing property that provides value for them. More... | |
void | locateFixedUniforms () |
Locate uniforms in program which Kanzi engine provides values directly. More... | |
void | locateTextureUniforms () |
Locate texture related uniforms in program. More... | |
void | locatePropertyUniforms () |
Locate uniforms in program for properties. More... | |
![]() | |
GPUResource (Domain *domain, string_view name="") | |
virtual unsigned int | getGPUMemoryUsageOverride () const |
![]() | |
KzuResourceLoadState | getLoadState () |
Access. More... | |
![]() | |
void | initialize () |
void | onCopy (const Object &other) |
Static Protected Member Functions | |
static void | locateFixedAttributes (vector< string > const &attributes, FixedAttributeArray &outFixedAttributes) |
static const char * | toString (Shader::ProgramType type) |
Returns human readable string for ProgramType. More... | |
static unsigned int | getShaderBinaryFormat (string_view format) |
Translate string to GL shader binary format. More... | |
static unsigned int | getProgramBinaryFormat (string_view format) |
Translate string to GL program binary format. More... | |
Additional Inherited Members | |
![]() | |
AppliedStyleContainer | m_appliedStyles |
Listing of applied styles applied to this object. More... | |
Shader GPU resource.
typedef vector<const KzuPropertyType*> kanzi::Shader::PropertyTypeContainer |
typedef vector<int> kanzi::Shader::UniformLocationContainer |
|
protected |
Fixed uniform locations of the shader.
Enumerator | |
---|---|
FixedUniformProjectionCameraWorldMatrix |
Projection * camera * world matrix. |
FixedUniformWorldMatrix |
World matrix. |
FixedUniformProjectionMatrix |
Projection matrix. |
FixedUniformCameraMatrix |
Camera matrix. |
FixedUniformCameraPosition |
Camera position. |
FixedUniformViewport |
Viewport area. |
FixedUniformNormalMatrix |
Normal matrix. |
FixedUniformCameraNormalMatrix |
Camera* normal matrix (screenspace normal). |
FixedUniformCameraWorldMatrix |
Camera * world matrix. |
FixedUniformNearFarPlane |
Vec2 containing near and far plane. |
FixedUniformTime |
Debug timer. |
FixedUniformMorphWeights |
Morph weights. |
FixedUniformMatrixPalette |
Bone matrices. |
FixedUniformDirectionalLightColor | |
FixedUniformPointLightColor | |
FixedUniformSpotLightColor | |
FixedUniformPointLightPosition | |
FixedUniformSpotLightPosition | |
FixedUniformDirectionalLightDirection | |
FixedUniformSpotLightDirection | |
FixedUniformPointLightRadius | |
FixedUniformPointLightAttenuation | |
FixedUniformSpotLightAttenuation | |
FixedUniformSpotLightCutoffAngle | |
FixedUniformSpotLightExponent | |
FixedUniformCount |
Number of fixed uniforms. |
FixedUniformInvalid |
|
protected |
Describes state of program after tryDeploy()
|
explicit |
|
virtual |
|
static |
|
virtual |
Returns true if the shader is deployed and valid.
void kanzi::Shader::addPropertyType | ( | const KzuPropertyType * | propertyType | ) |
Adds property type to shader.
bool kanzi::Shader::hasPropertyType | ( | const KzuPropertyType * | propertyType | ) | const |
Tell if shader has a property type.
propertyType | Property type to check. |
void kanzi::Shader::removePropertyType | ( | const KzuPropertyType * | propertyType | ) |
Removes property type from shader.
const KzuPropertyType* kanzi::Shader::getPropertyTypeByName | ( | kzString | propertyTypeName | ) | const |
Gets property type from shader by name. Returns 0 if not found.
|
inline |
|
inline |
unsigned int kanzi::Shader::getProgramHandle | ( | ) | const |
const vector<string>& kanzi::Shader::getAttributes | ( | ) | const |
int kanzi::Shader::getAttributeIndex | ( | const string & | attributeName | ) | const |
void kanzi::Shader::bind | ( | ) | const |
Binds the shader for rendering.
bool kanzi::Shader::hasSamplersWithoutProperties | ( | ) | const |
Return true if shader has samplers that have no corresponding texture property.
void kanzi::Shader::getTextureUniformLocation | ( | unsigned int | textureUnit, |
int * | out_textureWidthUniformLocation, | ||
int * | out_textureHeightUniformLocation | ||
) |
Returns texture size uniform locations from shader.
void kanzi::Shader::clearTextureUniformLocations | ( | ) |
Clear texture uniform location array.
int kanzi::Shader::getUniformLocation | ( | unsigned int | propertyIndex | ) |
void kanzi::Shader::initializeFromMemory | ( | const char *const | vertexShaderSourceSource, |
const char *const | fragmentShaderSourceCode, | ||
unsigned int | attributeCount, | ||
const char *const * | attributes | ||
) |
Prepare Shader by providing vertex and fragment shader sources.
After Shader has been prepared with initializeFromMemory, the Shader can be deployed.
vertexShader | Source code string for vertex shader. |
fragmentShader | Source code string for fragment shader. |
attributeCount | Number of attributes. |
vertexAttributes | Array of attribute names. Array length must equal to attributeCount. |
void kanzi::Shader::initializeFromMemory | ( | unsigned int | shaderBinaryFormat, |
unsigned int | dataSize, | ||
void * | data, | ||
unsigned int | attributeCount, | ||
const char *const * | attributes | ||
) |
Prepare Shader by providing precompiled binary shader data.
This version takes in a single data blob which specifies has been precompiled from both vertex and fragment shaders.
After Shader has been prepared with initializeFromMemory, the Shader can be deployed.
shaderBinaryFormat | GL shader binary format |
dataSize | Size of shader binary data in bytes |
data | Pointer to shader binary data |
attributeCount | Number of attributes. |
vertexAttributes | Array of attribute names. Array length must equal to attributeCount. |
void kanzi::Shader::initializeFromMemory | ( | unsigned int | shaderBinaryFormat, |
unsigned int | vertexDataSize, | ||
void * | vertexData, | ||
unsigned int | fragmentDataSize, | ||
void * | fragmentData, | ||
unsigned int | attributeCount, | ||
const char *const * | attributes | ||
) |
Prepare Shader by providing precompiled binary shader data.
This version takes in a two data blobs, one for vertex shader and another one for fragment shader.
After Shader has been prepared with initializeFromMemory, the Shader can be deployed.
shaderBinaryFormat | GL shader binary format |
dataSize | Size of shader binary data in bytes |
data | Pointer to shader binary data |
attributeCount | Number of attributes. |
vertexAttributes | Array of attribute names. Array length must equal to attributeCount. |
|
inline |
|
inline |
|
inline |
|
virtual |
Function for loading the resource from .KZB.
This function is called when loading the data from .KZB file. Implementations should call super class loadFromKZB before reading anything else from inputStream. This function is called from arbitrary loading threads. The parameter threadContext contains thread safe memory manager and a thread specific Property manager which can be locked with the threadLock in the threadContext. This function may not access resource manager or the UIDomain due to race conditions.
Reimplemented from kanzi::GPUResource.
|
virtual |
Function for getting the memory usage of a resource.
Reimplemented from kanzi::GPUResource.
|
virtual |
Unload function for resource.
Releases all memory taken by the resource except the resource loader.
Reimplemented from kanzi::GPUResource.
|
protectedvirtual |
Make graphics API object(s) in the resource usable by preparing GPU objects and data in them. Called by deploy()
Reimplemented from kanzi::GPUResource.
|
protectedvirtual |
Notify resource that graphics context was lost and all GPU resources are invalid. Called by invalidate()
Reimplemented from kanzi::GPUResource.
|
protectedvirtual |
Free the GPU objects. After this, the resource is not usable for graphics API until deploy() is called again. Called by undeploy()
Reimplemented from kanzi::GPUResource.
|
protectedvirtual |
Notify resource that graphics context was lost and all GPU resources are invalid.
Reimplemented from kanzi::GPUResource.
|
protected |
|
staticprotected |
|
staticprotected |
Returns human readable string for ProgramType.
|
protected |
Tries to deploy the program.
|
protected |
Locate samplers in program which are missing property that provides value for them.
|
protected |
Locate uniforms in program which Kanzi engine provides values directly.
|
protected |
Locate texture related uniforms in program.
|
protected |
Locate uniforms in program for properties.
|
staticprotected |
Translate string to GL shader binary format.
|
staticprotected |
Translate string to GL program binary format.