cocos2d-x  3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GLProgramState Class Reference

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

#include <CCGLProgramState.h>

Inheritance diagram for GLProgramState:
Ref

Public Member Functions

uint32_t getVertexAttribsFlags () const
 Get the flag of vertex attribs used by OR operation. More...
 
var getVertexAttribsFlags ()
 Get the flag of vertex attribs used by OR operation. More...
 
local getVertexAttribsFlags ()
 Get the flag of vertex attribs used by OR operation. More...
 
ssize_t getVertexAttribCount () const
 Get the number of vertex attributes. More...
 
ssize_t getUniformCount () const
 Get the number of user defined uniform count. More...
 
void apply (const Mat4 &modelView)
void applyGLProgram (const Mat4 &modelView)
void applyAttributes (bool applyAttribFlags=true)
void applyUniforms ()
void setGLProgram (GLProgram *glprogram)
GLProgramgetGLProgram () const
void setVertexAttribCallback (const std::string &name, const std::function< void(VertexAttrib *)> &callback)
void setVertexAttribPointer (const std::string &name, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLvoid *pointer)
var setVertexAttribPointer ( var name, var size, var type, var normalized, var stride, var pointer)
local setVertexAttribPointer ( local name, local size, local type, local normalized, local stride, local pointer)
void setUniformInt (const std::string &uniformName, int value)
void setUniformFloat (const std::string &uniformName, float value)
void setUniformVec2 (const std::string &uniformName, const Vec2 &value)
void setUniformVec3 (const std::string &uniformName, const Vec3 &value)
void setUniformVec4 (const std::string &uniformName, const Vec4 &value)
void setUniformMat4 (const std::string &uniformName, const Mat4 &value)
void setUniformCallback (const std::string &uniformName, const std::function< void(GLProgram *, Uniform *)> &callback)
void setUniformTexture (const std::string &uniformName, Texture2D *texture)
void setUniformTexture (const std::string &uniformName, GLuint textureId)
void setUniformInt (GLint uniformLocation, int value)
void setUniformFloat (GLint uniformLocation, float value)
void setUniformVec2 (GLint uniformLocation, const Vec2 &value)
void setUniformVec3 (GLint uniformLocation, const Vec3 &value)
void setUniformVec4 (GLint uniformLocation, const Vec4 &value)
void setUniformMat4 (GLint uniformLocation, const Mat4 &value)
void setUniformCallback (GLint uniformLocation, const std::function< void(GLProgram *, Uniform *)> &callback)
void setUniformTexture (GLint uniformLocation, Texture2D *texture)
void setUniformTexture (GLint uniformLocation, GLuint textureId)
- Public Member Functions inherited from Ref
void 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...
 
virtual ~Ref ()
 Destructor. More...
 

Static Public Member Functions

static GLProgramStatecreate (GLProgram *glprogram)
 returns a new instance of GLProgramState for a given GLProgram More...
 
local create ( local glprogram)
 returns a new instance of GLProgramState for a given GLProgram More...
 
static GLProgramStategetOrCreateWithGLProgram (GLProgram *glprogram)
 gets-or-creates an instance of GLProgramState for a given GLProgram More...
 
static GLProgramStategetOrCreateWithGLProgramName (const std::string &glProgramName)
 gets-or-creates an instance of GLProgramState for a given GLProgramName More...
 
local getOrCreateWithGLProgramName ( local glProgramName)
 gets-or-creates an instance of GLProgramState for a given GLProgramName More...
 

Protected Member Functions

 GLProgramState ()
 ~GLProgramState ()
bool init (GLProgram *program)
void resetGLProgram ()
void updateUniformsAndAttributes ()
VertexAttribValuegetVertexAttribValue (const std::string &attributeName)
var getVertexAttribValue ( var attributeName)
local getVertexAttribValue ( local attributeName)
UniformValuegetUniformValue (const std::string &uniformName)
UniformValuegetUniformValue (GLint uniformLocation)
- Protected Member Functions inherited from Ref
 Ref ()
 Constructor. More...
 
 Ref ()
 Constructor. More...
 

Protected Attributes

bool _uniformAttributeValueDirty
std::unordered_map
< std::string, GLint > 
_uniformsByName
var _uniformsByName
local _uniformsByName
std::unordered_map< GLint,
UniformValue
_uniforms
local _uniforms
std::unordered_map
< std::string,
VertexAttribValue
_attributes
var _attributes
local _attributes
std::unordered_map
< std::string, int > 
_boundTextureUnits
var _boundTextureUnits
local _boundTextureUnits
int _textureUnitIndex
uint32_t _vertexAttribsFlags
GLProgram_glprogram
EventListenerCustom_backToForegroundlistener
var _backToForegroundlistener
local _backToForegroundlistener
- Protected Attributes inherited from Ref
unsigned int _referenceCount
 count of references More...
 
local _referenceCount
 count of references More...
 

Friends

class GLProgramStateCache

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

Constructor & Destructor Documentation

GLProgramState ( )
protected
var GLProgramState ( )
protected
local GLProgramState ( )
protected
~GLProgramState ( )
protected
var ~GLProgramState ( )
protected
local ~GLProgramState ( )
protected

Member Function Documentation

void apply ( const Mat4 modelView)

Apply GLProgram, attributes and uniforms. apply function will apply all the states, include GLProgram, attributes and uniforms. applyGLProgram function will apply GLProgram and built in uniform. applyAttributes will apply the vertex attributes. applyUniforms will apply user defined uniforms.

Parameters
Theapplied modelView matrix to shader.
applyAttribFlagsCall GL::enableVertexAttribs(_vertexAttribsFlags) or not.
var apply ( var  modelView)

Apply GLProgram, attributes and uniforms. apply function will apply all the states, include GLProgram, attributes and uniforms. applyGLProgram function will apply GLProgram and built in uniform. applyAttributes will apply the vertex attributes. applyUniforms will apply user defined uniforms.

Parameters
Theapplied modelView matrix to shader.
applyAttribFlagsCall GL::enableVertexAttribs(_vertexAttribsFlags) or not.
local apply ( local  modelView)

Apply GLProgram, attributes and uniforms. apply function will apply all the states, include GLProgram, attributes and uniforms. applyGLProgram function will apply GLProgram and built in uniform. applyAttributes will apply the vertex attributes. applyUniforms will apply user defined uniforms.

Parameters
Theapplied modelView matrix to shader.
applyAttribFlagsCall GL::enableVertexAttribs(_vertexAttribsFlags) or not.
void applyAttributes ( bool  applyAttribFlags = true)
var applyAttributes ( var  applyAttribFlags = true)
local applyAttributes ( local  applyAttribFlags = true)
void applyGLProgram ( const Mat4 modelView)
var applyGLProgram ( var  modelView)
local applyGLProgram ( local  modelView)
void applyUniforms ( )
var applyUniforms ( )
local applyUniforms ( )
static GLProgramState* create ( GLProgram glprogram)
static

returns a new instance of GLProgramState for a given GLProgram

var create ( var  glprogram)
static

returns a new instance of GLProgramState for a given GLProgram

local create ( local  glprogram)
static

returns a new instance of GLProgramState for a given GLProgram

GLProgram* getGLProgram ( ) const
inline
var getGLProgram ( )
inline
local getGLProgram ( )
inline
static GLProgramState*
getOrCreateWithGLProgram
( GLProgram glprogram)
static

gets-or-creates an instance of GLProgramState for a given GLProgram

var getOrCreateWithGLProgram ( var  glprogram)
static

gets-or-creates an instance of GLProgramState for a given GLProgram

local getOrCreateWithGLProgram ( local  glprogram)
static

gets-or-creates an instance of GLProgramState for a given GLProgram

static GLProgramState*
getOrCreateWithGLProgramName
( const std::string &  glProgramName)
static

gets-or-creates an instance of GLProgramState for a given GLProgramName

var getOrCreateWithGLProgramName ( var  glProgramName)
static

gets-or-creates an instance of GLProgramState for a given GLProgramName

local getOrCreateWithGLProgramName ( local  glProgramName)
static

gets-or-creates an instance of GLProgramState for a given GLProgramName

ssize_t getUniformCount ( ) const
inline

Get the number of user defined uniform count.

var getUniformCount ( )
inline

Get the number of user defined uniform count.

local getUniformCount ( )
inline

Get the number of user defined uniform count.

UniformValue* getUniformValue ( const std::string &  uniformName)
protected
var getUniformValue ( var  uniformName)
protected
local getUniformValue ( local  uniformName)
protected
UniformValue* getUniformValue ( GLint  uniformLocation)
protected
var getUniformValue ( var  uniformLocation)
protected
local getUniformValue ( local  uniformLocation)
protected
ssize_t getVertexAttribCount ( ) const
inline

Get the number of vertex attributes.

var getVertexAttribCount ( )
inline

Get the number of vertex attributes.

local getVertexAttribCount ( )
inline

Get the number of vertex attributes.

uint32_t getVertexAttribsFlags ( ) const
inline

Get the flag of vertex attribs used by OR operation.

var getVertexAttribsFlags ( )
inline

Get the flag of vertex attribs used by OR operation.

local getVertexAttribsFlags ( )
inline

Get the flag of vertex attribs used by OR operation.

VertexAttribValue*
getVertexAttribValue
( const std::string &  attributeName)
protected
var getVertexAttribValue ( var  attributeName)
protected
local getVertexAttribValue ( local  attributeName)
protected
bool init ( GLProgram program)
protected
var init ( var  program)
protected
local init ( local  program)
protected
void resetGLProgram ( )
protected
var resetGLProgram ( )
protected
local resetGLProgram ( )
protected
void setGLProgram ( GLProgram glprogram)

Setter and Getter of the owner GLProgram binded in this program state.

var setGLProgram ( var  glprogram)

Setter and Getter of the owner GLProgram binded in this program state.

local setGLProgram ( local  glprogram)

Setter and Getter of the owner GLProgram binded in this program state.

void setUniformCallback ( const std::string &  uniformName,
const std::function< void(GLProgram *, Uniform *)> &  callback 
)
var setUniformCallback ( var  uniformName,
var  callback 
)
local setUniformCallback ( local  uniformName,
local  callback 
)
void setUniformCallback ( GLint  uniformLocation,
const std::function< void(GLProgram *, Uniform *)> &  callback 
)
var setUniformCallback ( var  uniformLocation,
var  callback 
)
local setUniformCallback ( local  uniformLocation,
local  callback 
)
void setUniformFloat ( const std::string &  uniformName,
float  value 
)
var setUniformFloat ( var  uniformName,
var  value 
)
local setUniformFloat ( local  uniformName,
local  value 
)
void setUniformFloat ( GLint  uniformLocation,
float  value 
)
var setUniformFloat ( var  uniformLocation,
var  value 
)
local setUniformFloat ( local  uniformLocation,
local  value 
)
void setUniformInt ( const std::string &  uniformName,
int  value 
)

Setting user defined uniforms by uniform string name in the shader.

var setUniformInt ( var  uniformName,
var  value 
)

Setting user defined uniforms by uniform string name in the shader.

local setUniformInt ( local  uniformName,
local  value 
)

Setting user defined uniforms by uniform string name in the shader.

void setUniformInt ( GLint  uniformLocation,
int  value 
)

Setting user defined uniforms by uniform location in the shader.

var setUniformInt ( var  uniformLocation,
var  value 
)

Setting user defined uniforms by uniform location in the shader.

local setUniformInt ( local  uniformLocation,
local  value 
)

Setting user defined uniforms by uniform location in the shader.

void setUniformMat4 ( const std::string &  uniformName,
const Mat4 value 
)
var setUniformMat4 ( var  uniformName,
var  value 
)
local setUniformMat4 ( local  uniformName,
local  value 
)
void setUniformMat4 ( GLint  uniformLocation,
const Mat4 value 
)
var setUniformMat4 ( var  uniformLocation,
var  value 
)
local setUniformMat4 ( local  uniformLocation,
local  value 
)
void setUniformTexture ( const std::string &  uniformName,
Texture2D texture 
)
var setUniformTexture ( var  uniformName,
var  texture 
)
local setUniformTexture ( local  uniformName,
local  texture 
)
void setUniformTexture ( const std::string &  uniformName,
GLuint  textureId 
)
var setUniformTexture ( var  uniformName,
var  textureId 
)
local setUniformTexture ( local  uniformName,
local  textureId 
)
void setUniformTexture ( GLint  uniformLocation,
Texture2D texture 
)
var setUniformTexture ( var  uniformLocation,
var  texture 
)
local setUniformTexture ( local  uniformLocation,
local  texture 
)
void setUniformTexture ( GLint  uniformLocation,
GLuint  textureId 
)
var setUniformTexture ( var  uniformLocation,
var  textureId 
)
local setUniformTexture ( local  uniformLocation,
local  textureId 
)
void setUniformVec2 ( const std::string &  uniformName,
const Vec2 value 
)
var setUniformVec2 ( var  uniformName,
var  value 
)
local setUniformVec2 ( local  uniformName,
local  value 
)
void setUniformVec2 ( GLint  uniformLocation,
const Vec2 value 
)
var setUniformVec2 ( var  uniformLocation,
var  value 
)
local setUniformVec2 ( local  uniformLocation,
local  value 
)
void setUniformVec3 ( const std::string &  uniformName,
const Vec3 value 
)
var setUniformVec3 ( var  uniformName,
var  value 
)
local setUniformVec3 ( local  uniformName,
local  value 
)
void setUniformVec3 ( GLint  uniformLocation,
const Vec3 value 
)
var setUniformVec3 ( var  uniformLocation,
var  value 
)
local setUniformVec3 ( local  uniformLocation,
local  value 
)
void setUniformVec4 ( const std::string &  uniformName,
const Vec4 value 
)
var setUniformVec4 ( var  uniformName,
var  value 
)
local setUniformVec4 ( local  uniformName,
local  value 
)
void setUniformVec4 ( GLint  uniformLocation,
const Vec4 value 
)
var setUniformVec4 ( var  uniformLocation,
var  value 
)
local setUniformVec4 ( local  uniformLocation,
local  value 
)
void setVertexAttribCallback ( const std::string &  name,
const std::function< void(VertexAttrib *)> &  callback 
)

Set the vertex attribute value.

var setVertexAttribCallback ( var  name,
var  callback 
)

Set the vertex attribute value.

local setVertexAttribCallback ( local  name,
local  callback 
)

Set the vertex attribute value.

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

Friends And Related Function Documentation

friend class GLProgramStateCache
friend
var GLProgramStateCache
friend
local GLProgramStateCache
friend

Member Data Documentation

std::unordered_map<std::string,
VertexAttribValue> _attributes
protected
var _attributes
protected
local _attributes
protected
EventListenerCustom*
_backToForegroundlistener
protected
var _backToForegroundlistener
protected
local _backToForegroundlistener
protected
std::unordered_map<std::string,
int> _boundTextureUnits
protected
var _boundTextureUnits
protected
local _boundTextureUnits
protected
GLProgram* _glprogram
protected
var _glprogram
protected
local _glprogram
protected
int _textureUnitIndex
protected
var _textureUnitIndex
protected
local _textureUnitIndex
protected
bool _uniformAttributeValueDirty
protected
std::unordered_map<GLint,
UniformValue> _uniforms
protected
var _uniforms
protected
local _uniforms
protected
std::unordered_map<std::string,
GLint> _uniformsByName
protected
var _uniformsByName
protected
local _uniformsByName
protected
uint32_t _vertexAttribsFlags
protected
var _vertexAttribsFlags
protected
local _vertexAttribsFlags
protected

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