Cocos2d-x  v4
ProgramState Class Reference

A program state object can create or reuse a program. More...

Inherits Ref.

Classes

class  AutoBindingResolver
 An abstract base class that can be extended to support custom material auto bindings. More...
 

Public Member Functions

 ProgramState (Program *program)
 
virtual ~ProgramState ()
 destructor
 
ProgramStateclone () const
 Deep clone ProgramState.
 
backend::Program * getProgram () const
 Get the program object.
 
void setUniform (const backend::UniformLocation &uniformLocation, const void *data, std::size_t size)
 Specify the value of a uniform variable for the current program state object. More...
 
backend::UniformLocation getUniformLocation (const std::string &uniform) const
 Get uniform location in given uniform name. More...
 
backend::UniformLocation getUniformLocation (backend::Uniform name) const
 Get uniform location in a more efficient way by the given built-in uniform name. More...
 
int getAttributeLocation (const std::string &name) const
 Get an attribute location by the actual attribute name. More...
 
int getAttributeLocation (Attribute name) const
 Get an attribute location by the engine built-in attribute name. More...
 
void setCallbackUniform (const backend::UniformLocation &, const UniformCallback &)
 A callback to update unifrom. More...
 
void setTexture (const backend::UniformLocation &uniformLocation, uint32_t slot, backend::TextureBackend *texture)
 Set texture. More...
 
void setTextureArray (const backend::UniformLocation &uniformLocation, const std::vector< uint32_t > &slots, const std::vector< backend::TextureBackend * > textures)
 Set textures in array. More...
 
const std::unordered_map< int, TextureInfo > & getVertexTextureInfos () const
 Get vertex texture informations. More...
 
const std::unordered_map< int, TextureInfo > & getFragmentTextureInfos () const
 Get fragment texture informations. More...
 
const std::unordered_map< UniformLocation, UniformCallback, UniformLocation > & getCallbackUniforms () const
 Get the uniform callback function. More...
 
void getVertexUniformBuffer (char **buffer, std::size_t &size) const
 Get vertex uniform buffer. More...
 
void getFragmentUniformBuffer (char **buffer, std::size_t &size) const
 Get fragment uniform buffer. More...
 
void setParameterAutoBinding (const std::string &uniformName, const std::string &autoBinding)
 Sets a uniform auto-binding. More...
 

Detailed Description

A program state object can create or reuse a program.

Each program state object keep its own unifroms and textures data.

Constructor & Destructor Documentation

◆ ProgramState()

ProgramState ( Program *  program)
Parameters
programSpecifies the program.

Member Function Documentation

◆ setUniform()

void setUniform ( const backend::UniformLocation &  uniformLocation,
const void *  data,
std::size_t  size 
)

Specify the value of a uniform variable for the current program state object.

Parameters
uniformLocationSpecifies the uniform location.
dataSpecifies the new values to be used for the specified uniform variable.
sizeSpecifies the uniform data size.

◆ getUniformLocation() [1/2]

backend::UniformLocation getUniformLocation ( const std::string &  uniform) const

Get uniform location in given uniform name.

Parameters
uniformSpecifies the uniform name.
Returns
Uniform location.
See also
backend::UniformLocation getUniformLocation(backend::Uniform name) const

◆ getUniformLocation() [2/2]

backend::UniformLocation getUniformLocation ( backend::Uniform  name) const

Get uniform location in a more efficient way by the given built-in uniform name.

Parameters
uniformSpecifies the engin built-in uniform name.
Returns
Uniform location.
See also
backend::UniformLocation getUniformLocation(backend::Uniform name) const

◆ getAttributeLocation() [1/2]

int getAttributeLocation ( const std::string &  name) const
inline

Get an attribute location by the actual attribute name.

Parameters
nameSpecifies the attribute name.
Returns
Attribute location.
See also
int getAttributeLocation(const std::string& name) const

◆ getAttributeLocation() [2/2]

int getAttributeLocation ( Attribute  name) const
inline

Get an attribute location by the engine built-in attribute name.

Parameters
nameSpecifies the built-in attribute name.
Returns
Attribute location.
See also
int getAttributeLocation(const std::string& name) const

◆ setCallbackUniform()

void setCallbackUniform ( const backend::UniformLocation &  ,
const UniformCallback &   
)

A callback to update unifrom.

Parameters
uniformLocationSpecifies the uniform location.
unifromCallbackSpecifies a callback function to update the uniform.

◆ setTexture()

void setTexture ( const backend::UniformLocation &  uniformLocation,
uint32_t  slot,
backend::TextureBackend *  texture 
)

Set texture.

Parameters
uniformLocationSpecifies texture location.
slotSpecifies texture slot selector.
textureSpecifies a pointer to backend texture.

◆ setTextureArray()

void setTextureArray ( const backend::UniformLocation &  uniformLocation,
const std::vector< uint32_t > &  slots,
const std::vector< backend::TextureBackend * >  textures 
)

Set textures in array.

Parameters
uniformLocationSpecifies texture location.
slotsSpecifies texture slot selector.
texturesSpecifies a vector of backend texture object.

◆ getVertexTextureInfos()

const std::unordered_map<int, TextureInfo>& getVertexTextureInfos ( ) const
inline

Get vertex texture informations.

Returns
Vertex texture informations. Key is the texture location, Value store the texture informations

◆ getFragmentTextureInfos()

const std::unordered_map<int, TextureInfo>& getFragmentTextureInfos ( ) const
inline

Get fragment texture informations.

Returns
Fragment texture informations. Key is the texture location, Value store the texture informations

◆ getCallbackUniforms()

const std::unordered_map<UniformLocation, UniformCallback, UniformLocation>& getCallbackUniforms ( ) const
inline

Get the uniform callback function.

Returns
Uniform callback funciton.

◆ getVertexUniformBuffer()

void getVertexUniformBuffer ( char **  buffer,
std::size_t &  size 
) const

Get vertex uniform buffer.

The buffer store all the vertex uniform's data.

Parameters
[out]bufferSpecifies the pointer points to a vertex uniform storage.
[out]sizeSpecifies the size of the buffer in bytes.

◆ getFragmentUniformBuffer()

void getFragmentUniformBuffer ( char **  buffer,
std::size_t &  size 
) const

Get fragment uniform buffer.

The buffer store all the fragment uniform's data for metal.

Parameters
[out]bufferSpecifies the pointer points to a fragment uniform storage.
[out]sizeSpecifies the size of the buffer in bytes.

◆ setParameterAutoBinding()

void setParameterAutoBinding ( const std::string &  uniformName,
const std::string &  autoBinding 
)

Sets a uniform auto-binding.

This method parses the passed in autoBinding string and attempts to convert it to an enumeration value. If it matches to one of the predefined strings, it will create a callback to get the correct value at runtime.

Parameters
uniformNameThe name of the material parameter to store an auto-binding for.
autoBindingA string matching one of the built-in AutoBinding enum constants.

The documentation for this class was generated from the following file: