Cocos2d-x  v3.10
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups
GLProgramState Class Reference

GLProgramState holds the 'state' (uniforms and attributes) of the GLProgram. More...

Inherits Ref.

Classes

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

Public Member Functions

GLProgramStateclone () const
 Returns a new copy of the GLProgramState. More...
 
void apply (const Mat4 &modelView)
 Apply GLProgram, attributes and uniforms. More...
 
void applyGLProgram (const Mat4 &modelView)
 Apply GLProgram, and built in uniforms. More...
 
void applyAttributes (bool applyAttribFlags=true)
 Apply attributes. More...
 
void applyUniforms ()
 Apply user defined uniforms.
 
void setGLProgram (GLProgram *glprogram)
 Set the binded GLProgram.
 
GLProgramgetGLProgram () const
 Get the binded GLProgram.
 
uint32_t getVertexAttribsFlags () const
 Get the flag of vertex attribs used by OR operation.
 
ssize_t getVertexAttribCount () const
 Get the number of vertex attributes.
 
void setVertexAttribCallback (const std::string &name, const std::function< void(VertexAttrib *)> &callback)
 Set the vertex attribute value by calling callback. More...
 
void setVertexAttribPointer (const std::string &name, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLvoid *pointer)
 Set the vertex attribute value. More...
 
var setVertexAttribPointer ( var name, var size, var type, var normalized, var stride, var pointer)
 Set the vertex attribute value. More...
 
local setVertexAttribPointer ( local name, local size, local type, local normalized, local stride, local pointer)
 Set the vertex attribute value. More...
 
ssize_t getUniformCount () const
 Get the number of user defined uniform count.
 
void setUniformInt (GLint uniformLocation, int value)
 set the value for uniform. More...
 
void setUniformFloat (GLint uniformLocation, float value)
 set the value for uniform. More...
 
void setUniformFloatv (GLint uniformLocation, ssize_t size, const float *pointer)
 set the value for uniform. More...
 
void setUniformVec2 (GLint uniformLocation, const Vec2 &value)
 set the value for uniform. More...
 
void setUniformVec2v (GLint uniformLocation, ssize_t size, const Vec2 *pointer)
 set the value for uniform. More...
 
void setUniformVec3 (GLint uniformLocation, const Vec3 &value)
 set the value for uniform. More...
 
void setUniformVec3v (GLint uniformLocation, ssize_t size, const Vec3 *pointer)
 set the value for uniform. More...
 
void setUniformVec4 (GLint uniformLocation, const Vec4 &value)
 set the value for uniform. More...
 
void setUniformVec4v (GLint uniformLocation, ssize_t size, const Vec4 *pointer)
 set the value for uniform. More...
 
void setUniformMat4 (GLint uniformLocation, const Mat4 &value)
 set the value for uniform. More...
 
void setUniformCallback (GLint uniformLocation, const std::function< void(GLProgram *, Uniform *)> &callback)
 set the value for uniform. More...
 
void setUniformTexture (GLint uniformLocation, Texture2D *texture)
 set the value for uniform. More...
 
void setUniformTexture (GLint uniformLocation, GLuint textureId)
 set the value for uniform. More...
 
NodegetNodeBinding () const
 Get the Node bound to the GLProgramState Node bound to the GLProgramState.
 
void setNodeBinding (Node *node)
 Sets the node that this render state is bound to. More...
 
void applyAutoBinding (const std::string &uniformName, const std::string &autoBinding)
 Applies the specified custom auto-binding. More...
 
void setParameterAutoBinding (const std::string &uniformName, const std::string &autoBinding)
 Sets a uniform auto-binding. More...
 
void setUniformInt (const std::string &uniformName, int value)
 set the value for uniform. More...
 
var setUniformInt ( var uniformName, var value)
 set the value for uniform. More...
 
local setUniformInt ( local uniformName, local value)
 set the value for uniform. More...
 
void setUniformFloat (const std::string &uniformName, float value)
 set the value for uniform. More...
 
local setUniformFloat ( local uniformName, local value)
 set the value for uniform. More...
 
void setUniformFloatv (const std::string &uniformName, ssize_t size, const float *pointer)
 set the value for uniform. More...
 
var setUniformFloatv ( var uniformName, var size, var pointer)
 set the value for uniform. More...
 
local setUniformFloatv ( local uniformName, local size, local pointer)
 set the value for uniform. More...
 
void setUniformVec2 (const std::string &uniformName, const Vec2 &value)
 set the value for uniform. More...
 
void setUniformVec2v (const std::string &uniformName, ssize_t size, const Vec2 *pointer)
 set the value for uniform. More...
 
void setUniformVec3 (const std::string &uniformName, const Vec3 &value)
 set the value for uniform. More...
 
void setUniformVec3v (const std::string &uniformName, ssize_t size, const Vec3 *pointer)
 set the value for uniform. More...
 
void setUniformVec4 (const std::string &uniformName, const Vec4 &value)
 set the value for uniform. More...
 
void setUniformVec4v (const std::string &uniformName, ssize_t size, const Vec4 *pointer)
 set the value for uniform. More...
 
void setUniformMat4 (const std::string &uniformName, const Mat4 &value)
 set the value for uniform. More...
 
void setUniformCallback (const std::string &uniformName, const std::function< void(GLProgram *, Uniform *)> &callback)
 set the value for uniform. More...
 
void setUniformTexture (const std::string &uniformName, Texture2D *texture)
 set the value for uniform. More...
 
void setUniformTexture (const std::string &uniformName, GLuint textureId)
 set the value for uniform. More...
 
- Public Member Functions inherited from Ref
void retain ()
 Retains the ownership. More...
 
local retain ()
 Retains the ownership. More...
 
void release ()
 Releases the ownership immediately. More...
 
Refautorelease ()
 Releases the ownership sometime soon automatically. More...
 
unsigned int getReferenceCount () const
 Returns the Ref's current reference count. More...
 
local getReferenceCount ()
 Returns the Ref's current reference count. More...
 
virtual ~Ref ()
 Destructor.
 

Static Public Member Functions

static GLProgramStatecreate (GLProgram *glprogram)
 returns a new instance of GLProgramState for a given GLProgram
 
static GLProgramStategetOrCreateWithGLProgram (GLProgram *glprogram)
 gets-or-creates an instance of GLProgramState for a given GLProgram
 
local getOrCreateWithGLProgram ( local glprogram)
 gets-or-creates an instance of GLProgramState for a given GLProgram
 
static GLProgramStategetOrCreateWithGLProgramName (const std::string &glProgramName)
 gets-or-creates an instance of GLProgramState for a given GLProgramName
 
local getOrCreateWithGLProgramName ( local glProgramName)
 gets-or-creates an instance of GLProgramState for a given GLProgramName
 
static GLProgramStategetOrCreateWithShaders (const std::string &vertexShader, const std::string &fragShader, const std::string &compileTimeDefines)
 gets-or-creates an instance of GLProgramState for given shaders
 
var getOrCreateWithShaders ( var vertexShader, var fragShader, var compileTimeDefines)
 gets-or-creates an instance of GLProgramState for given shaders
 
local getOrCreateWithShaders ( local vertexShader, local fragShader, local compileTimeDefines)
 gets-or-creates an instance of GLProgramState for given shaders
 

Additional Inherited Members

- Public Attributes inherited from Ref
unsigned int _ID
 object id, ScriptSupport need public _ID
 
local _ID
 object id, ScriptSupport need public _ID
 
int _luaID
 Lua reference id.
 
local _luaID
 Lua reference id.
 
void * _scriptObject
 scriptObject, support for swift
 
local _scriptObject
 scriptObject, support for swift
 
bool _rooted
 When true, it means that the object was already rooted.
 
local _rooted
 When true, it means that the object was already rooted.
 
bool _scriptOwned
 The life of the object is scrolled by the scripting engine. More...
 
local _scriptOwned
 The life of the object is scrolled by the scripting engine. More...
 

Detailed Description

GLProgramState holds the 'state' (uniforms and attributes) of the GLProgram.

A GLProgram can be used by thousands of Nodes, but if different uniform values are going to be used, then each node will need its own GLProgramState

Member Function Documentation

GLProgramState* clone ( ) const

Returns a new copy of the GLProgramState.

The GLProgram is reused

var clone ( )

Returns a new copy of the GLProgramState.

The GLProgram is reused

local clone ( )

Returns a new copy of the GLProgramState.

The GLProgram is reused

void apply ( const Mat4 modelView)

Apply GLProgram, attributes and uniforms.

The applied modelView matrix to shader.

var apply ( var  modelView)

Apply GLProgram, attributes and uniforms.

The applied modelView matrix to shader.

local apply ( local  modelView)

Apply GLProgram, attributes and uniforms.

The applied modelView matrix to shader.

void applyGLProgram ( const Mat4 modelView)

Apply GLProgram, and built in uniforms.

The applied modelView matrix to shader.

var applyGLProgram ( var  modelView)

Apply GLProgram, and built in uniforms.

The applied modelView matrix to shader.

local applyGLProgram ( local  modelView)

Apply GLProgram, and built in uniforms.

The applied modelView matrix to shader.

void applyAttributes ( bool  applyAttribFlags = true)

Apply attributes.

Call GL::enableVertexAttribs(_vertexAttribsFlags) or not.

var applyAttributes ( var  applyAttribFlags = true)

Apply attributes.

Call GL::enableVertexAttribs(_vertexAttribsFlags) or not.

local applyAttributes ( local  applyAttribFlags = true)

Apply attributes.

Call GL::enableVertexAttribs(_vertexAttribsFlags) or not.

void setVertexAttribCallback ( const std::string &  name,
const std::function< void(VertexAttrib *)> &  callback 
)

Set the vertex attribute value by calling callback.

The name of Vertex attrib. The callback for setting vertex attrib.

var setVertexAttribCallback ( var  name,
var  callback 
)

Set the vertex attribute value by calling callback.

The name of Vertex attrib. The callback for setting vertex attrib.

local setVertexAttribCallback ( local  name,
local  callback 
)

Set the vertex attribute value by calling callback.

The name of Vertex attrib. The callback for setting vertex attrib.

void setVertexAttribPointer ( const std::string &  name,
GLint  size,
GLenum  type,
GLboolean  normalized,
GLsizei  stride,
GLvoid *  pointer 
)

Set the vertex attribute value.

The vertex attrib name. The count of data in the vertex attrib, range from 0-4. The type of data in the vertex attrib Normalize the data or not 0-255 will be mapped to 0-1.0 The stride of the interleaved array. The data pointer

var setVertexAttribPointer ( var  name,
var  size,
var  type,
var  normalized,
var  stride,
var  pointer 
)

Set the vertex attribute value.

The vertex attrib name. The count of data in the vertex attrib, range from 0-4. The type of data in the vertex attrib Normalize the data or not 0-255 will be mapped to 0-1.0 The stride of the interleaved array. The data pointer

local setVertexAttribPointer ( local  name,
local  size,
local  type,
local  normalized,
local  stride,
local  pointer 
)

Set the vertex attribute value.

The vertex attrib name. The count of data in the vertex attrib, range from 0-4. The type of data in the vertex attrib Normalize the data or not 0-255 will be mapped to 0-1.0 The stride of the interleaved array. The data pointer

void setUniformInt ( const std::string &  uniformName,
int  value 
)

set the value for uniform.

Setting user defined uniforms by uniform string name in the shader. The name of uniform. The int value

var setUniformInt ( var  uniformName,
var  value 
)

set the value for uniform.

Setting user defined uniforms by uniform string name in the shader. The name of uniform. The int value

local setUniformInt ( local  uniformName,
local  value 
)

set the value for uniform.

Setting user defined uniforms by uniform string name in the shader. The name of uniform. The int value

void setUniformFloat ( const std::string &  uniformName,
float  value 
)

set the value for uniform.

The name of uniform. The float value

var setUniformFloat ( var  uniformName,
var  value 
)

set the value for uniform.

The name of uniform. The float value

local setUniformFloat ( local  uniformName,
local  value 
)

set the value for uniform.

The name of uniform. The float value

void setUniformFloatv ( const std::string &  uniformName,
ssize_t  size,
const float *  pointer 
)

set the value for uniform.

The name of uniform. The count of value The pointer of float value

var setUniformFloatv ( var  uniformName,
var  size,
var  pointer 
)

set the value for uniform.

The name of uniform. The count of value The pointer of float value

local setUniformFloatv ( local  uniformName,
local  size,
local  pointer 
)

set the value for uniform.

The name of uniform. The count of value The pointer of float value

void setUniformVec2 ( const std::string &  uniformName,
const Vec2 value 
)

set the value for uniform.

The name of uniform. The Vec2 value

var setUniformVec2 ( var  uniformName,
var  value 
)

set the value for uniform.

The name of uniform. The Vec2 value

local setUniformVec2 ( local  uniformName,
local  value 
)

set the value for uniform.

The name of uniform. The Vec2 value

void setUniformVec2v ( const std::string &  uniformName,
ssize_t  size,
const Vec2 pointer 
)

set the value for uniform.

The name of uniform. The count of value The pointer of Vec2 value

var setUniformVec2v ( var  uniformName,
var  size,
var  pointer 
)

set the value for uniform.

The name of uniform. The count of value The pointer of Vec2 value

local setUniformVec2v ( local  uniformName,
local  size,
local  pointer 
)

set the value for uniform.

The name of uniform. The count of value The pointer of Vec2 value

void setUniformVec3 ( const std::string &  uniformName,
const Vec3 value 
)

set the value for uniform.

The name of uniform. The Vec3 value

var setUniformVec3 ( var  uniformName,
var  value 
)

set the value for uniform.

The name of uniform. The Vec3 value

local setUniformVec3 ( local  uniformName,
local  value 
)

set the value for uniform.

The name of uniform. The Vec3 value

void setUniformVec3v ( const std::string &  uniformName,
ssize_t  size,
const Vec3 pointer 
)

set the value for uniform.

The name of uniform. The count of value The pointer of Vec3 value

var setUniformVec3v ( var  uniformName,
var  size,
var  pointer 
)

set the value for uniform.

The name of uniform. The count of value The pointer of Vec3 value

local setUniformVec3v ( local  uniformName,
local  size,
local  pointer 
)

set the value for uniform.

The name of uniform. The count of value The pointer of Vec3 value

void setUniformVec4 ( const std::string &  uniformName,
const Vec4 value 
)

set the value for uniform.

The name of uniform. The Vec4 value

var setUniformVec4 ( var  uniformName,
var  value 
)

set the value for uniform.

The name of uniform. The Vec4 value

local setUniformVec4 ( local  uniformName,
local  value 
)

set the value for uniform.

The name of uniform. The Vec4 value

void setUniformVec4v ( const std::string &  uniformName,
ssize_t  size,
const Vec4 pointer 
)

set the value for uniform.

The name of uniform. The count of value The pointer of Vec4 value

var setUniformVec4v ( var  uniformName,
var  size,
var  pointer 
)

set the value for uniform.

The name of uniform. The count of value The pointer of Vec4 value

local setUniformVec4v ( local  uniformName,
local  size,
local  pointer 
)

set the value for uniform.

The name of uniform. The count of value The pointer of Vec4 value

void setUniformMat4 ( const std::string &  uniformName,
const Mat4 value 
)

set the value for uniform.

The name of uniform. The Mat4 value

var setUniformMat4 ( var  uniformName,
var  value 
)

set the value for uniform.

The name of uniform. The Mat4 value

local setUniformMat4 ( local  uniformName,
local  value 
)

set the value for uniform.

The name of uniform. The Mat4 value

void setUniformCallback ( const std::string &  uniformName,
const std::function< void(GLProgram *, Uniform *)> &  callback 
)

set the value for uniform.

The name of uniform. callback function for uniform

var setUniformCallback ( var  uniformName,
var  callback 
)

set the value for uniform.

The name of uniform. callback function for uniform

local setUniformCallback ( local  uniformName,
local  callback 
)

set the value for uniform.

The name of uniform. callback function for uniform

void setUniformTexture ( const std::string &  uniformName,
Texture2D texture 
)

set the value for uniform.

The name of uniform. The texture value,the openGL handle will be used

var setUniformTexture ( var  uniformName,
var  texture 
)

set the value for uniform.

The name of uniform. The texture value,the openGL handle will be used

local setUniformTexture ( local  uniformName,
local  texture 
)

set the value for uniform.

The name of uniform. The texture value,the openGL handle will be used

void setUniformTexture ( const std::string &  uniformName,
GLuint  textureId 
)

set the value for uniform.

The name of uniform. The texture value

var setUniformTexture ( var  uniformName,
var  textureId 
)

set the value for uniform.

The name of uniform. The texture value

local setUniformTexture ( local  uniformName,
local  textureId 
)

set the value for uniform.

The name of uniform. The texture value

void setUniformInt ( GLint  uniformLocation,
int  value 
)

set the value for uniform.

The location of uniform. The int value

var setUniformInt ( var  uniformLocation,
var  value 
)

set the value for uniform.

The location of uniform. The int value

local setUniformInt ( local  uniformLocation,
local  value 
)

set the value for uniform.

The location of uniform. The int value

void setUniformFloat ( GLint  uniformLocation,
float  value 
)

set the value for uniform.

The location of uniform. The float value

var setUniformFloat ( var  uniformLocation,
var  value 
)

set the value for uniform.

The location of uniform. The float value

local setUniformFloat ( local  uniformLocation,
local  value 
)

set the value for uniform.

The location of uniform. The float value

void setUniformFloatv ( GLint  uniformLocation,
ssize_t  size,
const float *  pointer 
)

set the value for uniform.

The location of uniform. The count of value The pointer of float value

var setUniformFloatv ( var  uniformLocation,
var  size,
var  pointer 
)

set the value for uniform.

The location of uniform. The count of value The pointer of float value

local setUniformFloatv ( local  uniformLocation,
local  size,
local  pointer 
)

set the value for uniform.

The location of uniform. The count of value The pointer of float value

void setUniformVec2 ( GLint  uniformLocation,
const Vec2 value 
)

set the value for uniform.

The location of uniform. The Vec2 value

var setUniformVec2 ( var  uniformLocation,
var  value 
)

set the value for uniform.

The location of uniform. The Vec2 value

local setUniformVec2 ( local  uniformLocation,
local  value 
)

set the value for uniform.

The location of uniform. The Vec2 value

void setUniformVec2v ( GLint  uniformLocation,
ssize_t  size,
const Vec2 pointer 
)

set the value for uniform.

The location of uniform. The count of value The pointer of Vec2 value

var setUniformVec2v ( var  uniformLocation,
var  size,
var  pointer 
)

set the value for uniform.

The location of uniform. The count of value The pointer of Vec2 value

local setUniformVec2v ( local  uniformLocation,
local  size,
local  pointer 
)

set the value for uniform.

The location of uniform. The count of value The pointer of Vec2 value

void setUniformVec3 ( GLint  uniformLocation,
const Vec3 value 
)

set the value for uniform.

The location of uniform. The Vec3 value

var setUniformVec3 ( var  uniformLocation,
var  value 
)

set the value for uniform.

The location of uniform. The Vec3 value

local setUniformVec3 ( local  uniformLocation,
local  value 
)

set the value for uniform.

The location of uniform. The Vec3 value

void setUniformVec3v ( GLint  uniformLocation,
ssize_t  size,
const Vec3 pointer 
)

set the value for uniform.

The location of uniform. The count of value The pointer of Vec3 value

var setUniformVec3v ( var  uniformLocation,
var  size,
var  pointer 
)

set the value for uniform.

The location of uniform. The count of value The pointer of Vec3 value

local setUniformVec3v ( local  uniformLocation,
local  size,
local  pointer 
)

set the value for uniform.

The location of uniform. The count of value The pointer of Vec3 value

void setUniformVec4 ( GLint  uniformLocation,
const Vec4 value 
)

set the value for uniform.

The location of uniform. The Vec4 value

var setUniformVec4 ( var  uniformLocation,
var  value 
)

set the value for uniform.

The location of uniform. The Vec4 value

local setUniformVec4 ( local  uniformLocation,
local  value 
)

set the value for uniform.

The location of uniform. The Vec4 value

void setUniformVec4v ( GLint  uniformLocation,
ssize_t  size,
const Vec4 pointer 
)

set the value for uniform.

The location of uniform. The count of value The pointer of Vec4 value

var setUniformVec4v ( var  uniformLocation,
var  size,
var  pointer 
)

set the value for uniform.

The location of uniform. The count of value The pointer of Vec4 value

local setUniformVec4v ( local  uniformLocation,
local  size,
local  pointer 
)

set the value for uniform.

The location of uniform. The count of value The pointer of Vec4 value

void setUniformMat4 ( GLint  uniformLocation,
const Mat4 value 
)

set the value for uniform.

The location of uniform. The Mat4 value

var setUniformMat4 ( var  uniformLocation,
var  value 
)

set the value for uniform.

The location of uniform. The Mat4 value

local setUniformMat4 ( local  uniformLocation,
local  value 
)

set the value for uniform.

The location of uniform. The Mat4 value

void setUniformCallback ( GLint  uniformLocation,
const std::function< void(GLProgram *, Uniform *)> &  callback 
)

set the value for uniform.

The location of uniform. callback function for uniform

var setUniformCallback ( var  uniformLocation,
var  callback 
)

set the value for uniform.

The location of uniform. callback function for uniform

local setUniformCallback ( local  uniformLocation,
local  callback 
)

set the value for uniform.

The location of uniform. callback function for uniform

void setUniformTexture ( GLint  uniformLocation,
Texture2D texture 
)

set the value for uniform.

The location of uniform. The texture value,the openGL handle will be used

var setUniformTexture ( var  uniformLocation,
var  texture 
)

set the value for uniform.

The location of uniform. The texture value,the openGL handle will be used

local setUniformTexture ( local  uniformLocation,
local  texture 
)

set the value for uniform.

The location of uniform. The texture value,the openGL handle will be used

void setUniformTexture ( GLint  uniformLocation,
GLuint  textureId 
)

set the value for uniform.

The location of uniform. The texture value

var setUniformTexture ( var  uniformLocation,
var  textureId 
)

set the value for uniform.

The location of uniform. The texture value

local setUniformTexture ( local  uniformLocation,
local  textureId 
)

set the value for uniform.

The location of uniform. The texture value

void setNodeBinding ( Node node)

Sets the node that this render state is bound to.

The specified node is used to apply auto-bindings for the render state. This is typically set to the node of the model that a material is applied to. The node to use for applying auto-bindings.

var setNodeBinding ( var  node)

Sets the node that this render state is bound to.

The specified node is used to apply auto-bindings for the render state. This is typically set to the node of the model that a material is applied to. The node to use for applying auto-bindings.

local setNodeBinding ( local  node)

Sets the node that this render state is bound to.

The specified node is used to apply auto-bindings for the render state. This is typically set to the node of the model that a material is applied to. The node to use for applying auto-bindings.

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

Applies the specified custom auto-binding.

Name of the shader uniform. Name of the auto binding.

var applyAutoBinding ( var  uniformName,
var  autoBinding 
)

Applies the specified custom auto-binding.

Name of the shader uniform. Name of the auto binding.

local applyAutoBinding ( local  uniformName,
local  autoBinding 
)

Applies the specified custom auto-binding.

Name of the shader uniform. Name of the auto binding.

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. The name of the material parameter to store an auto-binding for. A string matching one of the built-in AutoBinding enum constants.

var setParameterAutoBinding ( var  uniformName,
var  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. The name of the material parameter to store an auto-binding for. A string matching one of the built-in AutoBinding enum constants.

local setParameterAutoBinding ( local  uniformName,
local  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. The name of the material parameter to store an auto-binding for. A string matching one of the built-in AutoBinding enum constants.


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