cocos2d-x  3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Shaders

Files

file  ccGLStateCache.h
 

Namespaces

 cocos2d::GL
 

Classes

struct  VertexAttrib
 
struct  Uniform
 
class  GLProgram
 GLProgram Class that implements a glProgram. More...
 
struct  GLProgram::flag_struct
 
class  GLProgramCache
 GLProgramCache Singleton that stores manages GLProgram objects (shaders) More...
 

Typedefs

typedef void(* GLInfoFunction )(GLuint program, GLenum pname, GLint *params)
 
typedef void(* GLLogFunction )(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
 

Enumerations

enum  {
  VERTEX_ATTRIB_POSITION, VERTEX_ATTRIB_COLOR, VERTEX_ATTRIB_TEX_COORD, VERTEX_ATTRIB_TEX_COORD1,
  VERTEX_ATTRIB_TEX_COORD2, VERTEX_ATTRIB_TEX_COORD3, VERTEX_ATTRIB_NORMAL, VERTEX_ATTRIB_BLEND_WEIGHT,
  VERTEX_ATTRIB_BLEND_INDEX, VERTEX_ATTRIB_MAX, VERTEX_ATTRIB_TEX_COORDS = VERTEX_ATTRIB_TEX_COORD
}
 
enum  {
  UNIFORM_AMBIENT_COLOR, UNIFORM_P_MATRIX, UNIFORM_MV_MATRIX, UNIFORM_MVP_MATRIX,
  UNIFORM_NORMAL_MATRIX, UNIFORM_TIME, UNIFORM_SIN_TIME, UNIFORM_COS_TIME,
  UNIFORM_RANDOM01, UNIFORM_SAMPLER0, UNIFORM_SAMPLER1, UNIFORM_SAMPLER2,
  UNIFORM_SAMPLER3, UNIFORM_MAX
}
 
enum  {
  VERTEX_ATTRIB_FLAG_NONE = 0, VERTEX_ATTRIB_FLAG_POSITION = 1 << 0, VERTEX_ATTRIB_FLAG_COLOR = 1 << 1, VERTEX_ATTRIB_FLAG_TEX_COORD = 1 << 2,
  VERTEX_ATTRIB_FLAG_NORMAL = 1 << 3, VERTEX_ATTRIB_FLAG_BLEND_WEIGHT = 1 << 4, VERTEX_ATTRIB_FLAG_BLEND_INDEX = 1 << 5, VERTEX_ATTRIB_FLAG_POS_COLOR_TEX = (VERTEX_ATTRIB_FLAG_POSITION | VERTEX_ATTRIB_FLAG_COLOR | VERTEX_ATTRIB_FLAG_TEX_COORD)
}
 vertex attrib flags More...
 

Functions

 GLProgram ()
 
virtual ~GLProgram ()
 
static GLProgram * createWithPrecompiledProgramByteArray (const GLchar *vShaderByteArray, const GLchar *fShaderByteArray)
 Initializes the GLProgram with a vertex and fragment with bytes array initWithString initWithString. More...
 
bool initWithPrecompiledProgramByteArray (const GLchar *vShaderByteArray, const GLchar *fShaderByteArray)
 
static GLProgram * createWithByteArrays (const GLchar *vShaderByteArray, const GLchar *fShaderByteArray)
 Initializes the GLProgram with a vertex and fragment with bytes array initWithString initWithString. More...
 
bool initWithByteArrays (const GLchar *vShaderByteArray, const GLchar *fShaderByteArray)
 
static GLProgram * createWithFilenames (const std::string &vShaderFilename, const std::string &fShaderFilename)
 Initializes the GLProgram with a vertex and fragment with contents of filenames init init. More...
 
bool initWithFilenames (const std::string &vShaderFilename, const std::string &fShaderFilename)
 
Uniform * getUniform (const std::string &name)
 
VertexAttrib * getVertexAttrib (const std::string &name)
 
void bindAttribLocation (const std::string &attributeName, GLuint index) const
 It will add a new attribute to the shader by calling glBindAttribLocation. More...
 
GLint getAttribLocation (const std::string &attributeName) const
 calls glGetAttribLocation More...
 
GLint getUniformLocation (const std::string &attributeName) const
 calls glGetUniformLocation() More...
 
bool link ()
 links the glProgram More...
 
void use ()
 it will call glUseProgram() More...
 
void updateUniforms ()
 It will create 4 uniforms: More...
 
GLint getUniformLocationForName (const char *name) const
 calls retrieves the named uniform location for this shader program. More...
 
void setUniformLocationWith1i (GLint location, GLint i1)
 calls glUniform1i only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWith2i (GLint location, GLint i1, GLint i2)
 calls glUniform2i only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWith3i (GLint location, GLint i1, GLint i2, GLint i3)
 calls glUniform3i only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWith4i (GLint location, GLint i1, GLint i2, GLint i3, GLint i4)
 calls glUniform4i only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWith2iv (GLint location, GLint *ints, unsigned int numberOfArrays)
 calls glUniform2iv only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWith3iv (GLint location, GLint *ints, unsigned int numberOfArrays)
 calls glUniform3iv only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWith4iv (GLint location, GLint *ints, unsigned int numberOfArrays)
 calls glUniform4iv only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWith1f (GLint location, GLfloat f1)
 calls glUniform1f only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWith2f (GLint location, GLfloat f1, GLfloat f2)
 calls glUniform2f only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWith3f (GLint location, GLfloat f1, GLfloat f2, GLfloat f3)
 calls glUniform3f only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWith4f (GLint location, GLfloat f1, GLfloat f2, GLfloat f3, GLfloat f4)
 calls glUniform4f only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWith1fv (GLint location, const GLfloat *floats, unsigned int numberOfArrays)
 calls glUniformfv only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWith2fv (GLint location, const GLfloat *floats, unsigned int numberOfArrays)
 calls glUniform2fv only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWith3fv (GLint location, const GLfloat *floats, unsigned int numberOfArrays)
 calls glUniform3fv only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWith4fv (GLint location, const GLfloat *floats, unsigned int numberOfArrays)
 calls glUniform4fv only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWithMatrix2fv (GLint location, const GLfloat *matrixArray, unsigned int numberOfMatrices)
 calls glUniformMatrix2fv only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWithMatrix3fv (GLint location, const GLfloat *matrixArray, unsigned int numberOfMatrices)
 calls glUniformMatrix3fv only if the values are different than the previous call for this same shader program. More...
 
void setUniformLocationWithMatrix4fv (GLint location, const GLfloat *matrixArray, unsigned int numberOfMatrices)
 calls glUniformMatrix4fv only if the values are different than the previous call for this same shader program. More...
 
void setUniformsForBuiltins ()
 will update the builtin uniforms if they are different than the previous call for this same shader program. More...
 
void setUniformsForBuiltins (const Mat4 &modelView)
 
std::string getVertexShaderLog () const
 returns the vertexShader error log More...
 
std::string getFragmentShaderLog () const
 returns the fragmentShader error log More...
 
std::string getProgramLog () const
 returns the program error log More...
 
void reset ()
 
const GLuint getProgram () const
 
bool initWithVertexShaderByteArray (const GLchar *vertexByteArray, const GLchar *fragByteArray)
 
bool initWithVertexShaderFilename (const std::string &vertexFilename, const std::string &fragFilename)
 
void addAttribute (const std::string &attributeName, GLuint index) const
 
bool updateUniformLocation (GLint location, const GLvoid *data, unsigned int bytes)
 
virtual std::string getDescription () const
 
void bindPredefinedVertexAttribs ()
 
void parseVertexAttribs ()
 
void parseUniforms ()
 
bool compileShader (GLuint *shader, GLenum type, const GLchar *source)
 
std::string logForOpenGLObject (GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const
 
 flag_struct ()
 
void CC_DLL invalidateStateCache (void)
 Invalidates the GL state cache. More...
 
void CC_DLL useProgram (GLuint program)
 Uses the GL program in case program is different than the current one. More...
 
void CC_DLL deleteProgram (GLuint program)
 Deletes the GL program. More...
 
void CC_DLL blendFunc (GLenum sfactor, GLenum dfactor)
 Uses a blending function in case it not already used. More...
 
void CC_DLL blendResetToCache (void)
 Resets the blending mode back to the cached state in case you used glBlendFuncSeparate() or glBlendEquation(). More...
 
void CC_DLL setProjectionMatrixDirty (void)
 sets the projection matrix as dirty More...
 
void CC_DLL enableVertexAttribs (uint32_t flags)
 Will enable the vertex attribs that are passed as flags. More...
 
void CC_DLL bindTexture2D (GLuint textureId)
 If the texture is not already bound to texture unit 0, it binds it. More...
 
void CC_DLL bindTexture2DN (GLuint textureUnit, GLuint textureId)
 If the texture is not already bound to a given unit, it binds it. More...
 
void CC_DLL deleteTexture (GLuint textureId)
 It will delete a given texture. More...
 
void CC_DLL deleteTextureN (GLuint textureUnit, GLuint textureId)
 It will delete a given texture. More...
 
void CC_DLL activeTexture (GLenum texture)
 Select active texture unit. More...
 
void CC_DLL bindVAO (GLuint vaoId)
 If the vertex array is not already bound, it binds it. More...
 

Variables

GLuint index
 
GLint size
 
GLenum type
 
std::string name
 
GLint location
 
GLint size
 
GLenum type
 
std::string name
 
static const char * SHADER_NAME_POSITION_TEXTURE_COLOR
 
static const char * SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP
 
static const char * SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST
 
static const char * SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV
 
static const char * SHADER_NAME_POSITION_COLOR
 
static const char * SHADER_NAME_POSITION_COLOR_NO_MVP
 
static const char * SHADER_NAME_POSITION_TEXTURE
 
static const char * SHADER_NAME_POSITION_TEXTURE_U_COLOR
 
static const char * SHADER_NAME_POSITION_TEXTURE_A8_COLOR
 
static const char * SHADER_NAME_POSITION_U_COLOR
 
static const char * SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR
 
static const char * SHADER_NAME_LABEL_NORMAL
 
static const char * SHADER_NAME_LABEL_OUTLINE
 
static const char * SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL
 
static const char * SHADER_NAME_LABEL_DISTANCEFIELD_GLOW
 
static const char * SHADER_3D_POSITION
 
static const char * SHADER_3D_POSITION_TEXTURE
 
static const char * SHADER_3D_SKINPOSITION_TEXTURE
 
static const char * SHADER_3D_POSITION_NORMAL
 
static const char * SHADER_3D_POSITION_NORMAL_TEXTURE
 
static const char * SHADER_3D_SKINPOSITION_NORMAL_TEXTURE
 
static const char * UNIFORM_NAME_AMBIENT_COLOR
 
static const char * UNIFORM_NAME_P_MATRIX
 
static const char * UNIFORM_NAME_MV_MATRIX
 
static const char * UNIFORM_NAME_MVP_MATRIX
 
static const char * UNIFORM_NAME_NORMAL_MATRIX
 
static const char * UNIFORM_NAME_TIME
 
static const char * UNIFORM_NAME_SIN_TIME
 
static const char * UNIFORM_NAME_COS_TIME
 
static const char * UNIFORM_NAME_RANDOM01
 
static const char * UNIFORM_NAME_SAMPLER0
 
static const char * UNIFORM_NAME_SAMPLER1
 
static const char * UNIFORM_NAME_SAMPLER2
 
static const char * UNIFORM_NAME_SAMPLER3
 
static const char * UNIFORM_NAME_ALPHA_TEST_VALUE
 
static const char * ATTRIBUTE_NAME_COLOR
 
static const char * ATTRIBUTE_NAME_POSITION
 
static const char * ATTRIBUTE_NAME_TEX_COORD
 
static const char * ATTRIBUTE_NAME_TEX_COORD1
 
static const char * ATTRIBUTE_NAME_TEX_COORD2
 
static const char * ATTRIBUTE_NAME_TEX_COORD3
 
static const char * ATTRIBUTE_NAME_NORMAL
 
static const char * ATTRIBUTE_NAME_BLEND_WEIGHT
 
static const char * ATTRIBUTE_NAME_BLEND_INDEX
 
GLuint _program
 
GLuint _vertShader
 
GLuint _fragShader
 
GLint _builtInUniforms [UNIFORM_MAX]
 
bool _hasShaderCompiler
 
std::string _shaderId
 
unsigned int usesTime:1
 
unsigned int usesNormal:1
 
unsigned int usesMVP:1
 
unsigned int usesMV:1
 
unsigned int usesP:1
 
unsigned int usesRandom:1
 
struct
cocos2d::GLProgram::flag_struct 
_flags
 
std::unordered_map
< std::string, Uniform > 
_userUniforms
 
std::unordered_map
< std::string, VertexAttrib > 
_vertexAttribs
 
std::unordered_map< GLint,
GLvoid * > 
_hashForUniforms
 
Director * _director
 
CC_DLL const GLcharccPosition_uColor_frag
 
CC_DLL const GLcharccPosition_uColor_vert
 
CC_DLL const GLcharccPositionColor_frag
 
CC_DLL const GLcharccPositionColor_vert
 
CC_DLL const GLcharccPositionTexture_frag
 
CC_DLL const GLcharccPositionTexture_vert
 
CC_DLL const GLcharccPositionTextureA8Color_frag
 
CC_DLL const GLcharccPositionTextureA8Color_vert
 
CC_DLL const GLcharccPositionTextureColor_frag
 
CC_DLL const GLcharccPositionTextureColor_vert
 
CC_DLL const GLcharccPositionTextureColor_noMVP_frag
 
CC_DLL const GLcharccPositionTextureColor_noMVP_vert
 
CC_DLL const GLcharccPositionTextureColorAlphaTest_frag
 
CC_DLL const GLcharccPositionTexture_uColor_frag
 
CC_DLL const GLcharccPositionTexture_uColor_vert
 
CC_DLL const GLcharccPositionColorLengthTexture_frag
 
CC_DLL const GLcharccPositionColorLengthTexture_vert
 
CC_DLL const GLcharccLabelDistanceFieldNormal_frag
 
CC_DLL const GLcharccLabelDistanceFieldGlow_frag
 
CC_DLL const GLcharccLabelNormal_frag
 
CC_DLL const GLcharccLabelOutline_frag
 
CC_DLL const GLcharccLabel_vert
 
CC_DLL const GLcharcc3D_PositionTex_vert
 
CC_DLL const GLcharcc3D_SkinPositionTex_vert
 
CC_DLL const GLcharcc3D_ColorTex_frag
 
CC_DLL const GLcharcc3D_Color_frag
 
CC_DLL const GLcharcc3D_PositionNormalTex_vert
 
CC_DLL const GLcharcc3D_SkinPositionNormalTex_vert
 
CC_DLL const GLcharcc3D_ColorNormalTex_frag
 
CC_DLL const GLcharcc3D_ColorNormal_frag
 

Friends

class GLProgramState
 

Detailed Description

Typedef Documentation

typedef void(* GLInfoFunction)(GLuint program, GLenum pname, GLint *params)
typedef void(* GLLogFunction)(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)

Enumeration Type Documentation

anonymous enum
Enumerator
VERTEX_ATTRIB_POSITION 
VERTEX_ATTRIB_COLOR 
VERTEX_ATTRIB_TEX_COORD 
VERTEX_ATTRIB_TEX_COORD1 
VERTEX_ATTRIB_TEX_COORD2 
VERTEX_ATTRIB_TEX_COORD3 
VERTEX_ATTRIB_NORMAL 
VERTEX_ATTRIB_BLEND_WEIGHT 
VERTEX_ATTRIB_BLEND_INDEX 
VERTEX_ATTRIB_MAX 
VERTEX_ATTRIB_TEX_COORDS 
anonymous enum
Enumerator
UNIFORM_AMBIENT_COLOR 
UNIFORM_P_MATRIX 
UNIFORM_MV_MATRIX 
UNIFORM_MVP_MATRIX 
UNIFORM_NORMAL_MATRIX 
UNIFORM_TIME 
UNIFORM_SIN_TIME 
UNIFORM_COS_TIME 
UNIFORM_RANDOM01 
UNIFORM_SAMPLER0 
UNIFORM_SAMPLER1 
UNIFORM_SAMPLER2 
UNIFORM_SAMPLER3 
UNIFORM_MAX 
anonymous enum

vertex attrib flags

Enumerator
VERTEX_ATTRIB_FLAG_NONE 
VERTEX_ATTRIB_FLAG_POSITION 
VERTEX_ATTRIB_FLAG_COLOR 
VERTEX_ATTRIB_FLAG_TEX_COORD 
VERTEX_ATTRIB_FLAG_NORMAL 
VERTEX_ATTRIB_FLAG_BLEND_WEIGHT 
VERTEX_ATTRIB_FLAG_BLEND_INDEX 
VERTEX_ATTRIB_FLAG_POS_COLOR_TEX 

Function Documentation

flag_struct ( )
inline
GLProgram ( )
virtual ~GLProgram ( )
virtual
void CC_DLL cocos2d::GL::activeTexture ( GLenum  texture)

Select active texture unit.

If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glActiveTexture() directly.

Since
v3.0
void addAttribute ( const std::string &  attributeName,
GLuint  index 
) const
inline
void bindAttribLocation ( const std::string &  attributeName,
GLuint  index 
) const

It will add a new attribute to the shader by calling glBindAttribLocation.

void bindPredefinedVertexAttribs ( )
protected
void CC_DLL cocos2d::GL::bindTexture2D ( GLuint  textureId)

If the texture is not already bound to texture unit 0, it binds it.

If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.

Since
v2.0.0
void CC_DLL cocos2d::GL::bindTexture2DN ( GLuint  textureUnit,
GLuint  textureId 
)

If the texture is not already bound to a given unit, it binds it.

If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.

Since
v2.1.0
void CC_DLL cocos2d::GL::bindVAO ( GLuint  vaoId)

If the vertex array is not already bound, it binds it.

If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindVertexArray() directly.

Since
v2.0.0
void CC_DLL cocos2d::GL::blendFunc ( GLenum  sfactor,
GLenum  dfactor 
)

Uses a blending function in case it not already used.

If CC_ENABLE_GL_STATE_CACHE is disabled, it will the glBlendFunc() directly.

Since
v2.0.0
void CC_DLL cocos2d::GL::blendResetToCache ( void  )

Resets the blending mode back to the cached state in case you used glBlendFuncSeparate() or glBlendEquation().

If CC_ENABLE_GL_STATE_CACHE is disabled, it will just set the default blending mode using GL_FUNC_ADD.

Since
v2.0.0
bool compileShader ( GLuint *  shader,
GLenum  type,
const GLchar source 
)
protected
static GLProgram* createWithByteArrays ( const GLchar vShaderByteArray,
const GLchar fShaderByteArray 
)
static

Initializes the GLProgram with a vertex and fragment with bytes array initWithString initWithString.

static GLProgram* createWithFilenames ( const std::string &  vShaderFilename,
const std::string &  fShaderFilename 
)
static

Initializes the GLProgram with a vertex and fragment with contents of filenames init init.

static GLProgram* createWithPrecompiledProgramByteArray ( const GLchar vShaderByteArray,
const GLchar fShaderByteArray 
)
static

Initializes the GLProgram with a vertex and fragment with bytes array initWithString initWithString.

Initializes the CCGLProgram with precompiled shader program

void CC_DLL cocos2d::GL::deleteProgram ( GLuint  program)

Deletes the GL program.

If it is the one that is being used, it invalidates it. If CC_ENABLE_GL_STATE_CACHE is disabled, it will the glDeleteProgram() directly.

Since
v2.0.0
void CC_DLL cocos2d::GL::deleteTexture ( GLuint  textureId)

It will delete a given texture.

If the texture was bound, it will invalidate the cached. If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly.

Since
v2.0.0
void CC_DLL cocos2d::GL::deleteTextureN ( GLuint  textureUnit,
GLuint  textureId 
)

It will delete a given texture.

If the texture was bound, it will invalidate the cached for the given texture unit. If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly.

Since
v2.1.0
void CC_DLL cocos2d::GL::enableVertexAttribs ( uint32_t  flags)

Will enable the vertex attribs that are passed as flags.

Possible flags:

 VERTEX_ATTRIB_FLAG_POSITION
 VERTEX_ATTRIB_FLAG_COLOR
 VERTEX_ATTRIB_FLAG_TEX_COORDS

These flags can be ORed. The flags that are not present, will be disabled.

Since
v2.0.0
GLint getAttribLocation ( const std::string &  attributeName) const

calls glGetAttribLocation

virtual std::string getDescription ( ) const
protectedvirtual
std::string getFragmentShaderLog ( ) const

returns the fragmentShader error log

const GLuint getProgram ( ) const
inline
std::string getProgramLog ( ) const

returns the program error log

Uniform* getUniform ( const std::string &  name)
GLint getUniformLocation ( const std::string &  attributeName) const

calls glGetUniformLocation()

GLint getUniformLocationForName ( const char *  name) const

calls retrieves the named uniform location for this shader program.

VertexAttrib* getVertexAttrib ( const std::string &  name)
std::string getVertexShaderLog ( ) const

returns the vertexShader error log

bool initWithByteArrays ( const GLchar vShaderByteArray,
const GLchar fShaderByteArray 
)
bool initWithFilenames ( const std::string &  vShaderFilename,
const std::string &  fShaderFilename 
)
bool initWithPrecompiledProgramByteArray ( const GLchar vShaderByteArray,
const GLchar fShaderByteArray 
)
bool initWithVertexShaderByteArray ( const GLchar vertexByteArray,
const GLchar fragByteArray 
)
inline
bool initWithVertexShaderFilename ( const std::string &  vertexFilename,
const std::string &  fragFilename 
)
inline
void CC_DLL cocos2d::GL::invalidateStateCache ( void  )

Invalidates the GL state cache.

If CC_ENABLE_GL_STATE_CACHE it will reset the GL state cache.

Since
v2.0.0
bool link ( )

links the glProgram

std::string logForOpenGLObject ( GLuint  object,
GLInfoFunction  infoFunc,
GLLogFunction  logFunc 
) const
protected
void parseUniforms ( )
protected
void parseVertexAttribs ( )
protected
void reset ( )
void CC_DLL cocos2d::GL::setProjectionMatrixDirty ( void  )

sets the projection matrix as dirty

Since
v2.0.0
void setUniformLocationWith1f ( GLint  location,
GLfloat  f1 
)

calls glUniform1f only if the values are different than the previous call for this same shader program.

In js or lua,please use setUniformLocationF32 NA

void setUniformLocationWith1fv ( GLint  location,
const GLfloat *  floats,
unsigned int  numberOfArrays 
)

calls glUniformfv only if the values are different than the previous call for this same shader program.

void setUniformLocationWith1i ( GLint  location,
GLint  i1 
)

calls glUniform1i only if the values are different than the previous call for this same shader program.

setUniformLocationI32 setUniformLocationI32

void setUniformLocationWith2f ( GLint  location,
GLfloat  f1,
GLfloat  f2 
)

calls glUniform2f only if the values are different than the previous call for this same shader program.

In js or lua,please use setUniformLocationF32 NA

void setUniformLocationWith2fv ( GLint  location,
const GLfloat *  floats,
unsigned int  numberOfArrays 
)

calls glUniform2fv only if the values are different than the previous call for this same shader program.

void setUniformLocationWith2i ( GLint  location,
GLint  i1,
GLint  i2 
)

calls glUniform2i only if the values are different than the previous call for this same shader program.

void setUniformLocationWith2iv ( GLint  location,
GLint *  ints,
unsigned int  numberOfArrays 
)

calls glUniform2iv only if the values are different than the previous call for this same shader program.

void setUniformLocationWith3f ( GLint  location,
GLfloat  f1,
GLfloat  f2,
GLfloat  f3 
)

calls glUniform3f only if the values are different than the previous call for this same shader program.

In js or lua,please use setUniformLocationF32 NA

void setUniformLocationWith3fv ( GLint  location,
const GLfloat *  floats,
unsigned int  numberOfArrays 
)

calls glUniform3fv only if the values are different than the previous call for this same shader program.

void setUniformLocationWith3i ( GLint  location,
GLint  i1,
GLint  i2,
GLint  i3 
)

calls glUniform3i only if the values are different than the previous call for this same shader program.

void setUniformLocationWith3iv ( GLint  location,
GLint *  ints,
unsigned int  numberOfArrays 
)

calls glUniform3iv only if the values are different than the previous call for this same shader program.

void setUniformLocationWith4f ( GLint  location,
GLfloat  f1,
GLfloat  f2,
GLfloat  f3,
GLfloat  f4 
)

calls glUniform4f only if the values are different than the previous call for this same shader program.

In js or lua,please use setUniformLocationF32 NA

void setUniformLocationWith4fv ( GLint  location,
const GLfloat *  floats,
unsigned int  numberOfArrays 
)

calls glUniform4fv only if the values are different than the previous call for this same shader program.

void setUniformLocationWith4i ( GLint  location,
GLint  i1,
GLint  i2,
GLint  i3,
GLint  i4 
)

calls glUniform4i only if the values are different than the previous call for this same shader program.

void setUniformLocationWith4iv ( GLint  location,
GLint *  ints,
unsigned int  numberOfArrays 
)

calls glUniform4iv only if the values are different than the previous call for this same shader program.

void setUniformLocationWithMatrix2fv ( GLint  location,
const GLfloat *  matrixArray,
unsigned int  numberOfMatrices 
)

calls glUniformMatrix2fv only if the values are different than the previous call for this same shader program.

void setUniformLocationWithMatrix3fv ( GLint  location,
const GLfloat *  matrixArray,
unsigned int  numberOfMatrices 
)

calls glUniformMatrix3fv only if the values are different than the previous call for this same shader program.

void setUniformLocationWithMatrix4fv ( GLint  location,
const GLfloat *  matrixArray,
unsigned int  numberOfMatrices 
)

calls glUniformMatrix4fv only if the values are different than the previous call for this same shader program.

void setUniformsForBuiltins ( )

will update the builtin uniforms if they are different than the previous call for this same shader program.

void setUniformsForBuiltins ( const Mat4 modelView)
bool updateUniformLocation ( GLint  location,
const GLvoid *  data,
unsigned int  bytes 
)
protected
void updateUniforms ( )

It will create 4 uniforms:

  • kUniformPMatrix
  • kUniformMVMatrix
  • kUniformMVPMatrix
  • GLProgram::UNIFORM_SAMPLER

And it will bind "GLProgram::UNIFORM_SAMPLER" to 0

void use ( )

it will call glUseProgram()

void CC_DLL cocos2d::GL::useProgram ( GLuint  program)

Uses the GL program in case program is different than the current one.

If CC_ENABLE_GL_STATE_CACHE is disabled, it will the glUseProgram() directly.

Since
v2.0.0

Variable Documentation

GLint _builtInUniforms[UNIFORM_MAX]
protected
Director* _director
protected
struct cocos2d::GLProgram::flag_struct _flags
protected
GLuint _fragShader
protected
std::unordered_map<GLint, GLvoid*> _hashForUniforms
protected
bool _hasShaderCompiler
protected
GLuint _program
protected
std::string _shaderId
protected
std::unordered_map<std::string, Uniform> _userUniforms
protected
std::unordered_map<std::string, VertexAttrib> _vertexAttribs
protected
GLuint _vertShader
protected
const char* ATTRIBUTE_NAME_BLEND_INDEX
static
const char* ATTRIBUTE_NAME_BLEND_WEIGHT
static
const char* ATTRIBUTE_NAME_COLOR
static
const char* ATTRIBUTE_NAME_NORMAL
static
const char* ATTRIBUTE_NAME_POSITION
static
const char* ATTRIBUTE_NAME_TEX_COORD
static
const char* ATTRIBUTE_NAME_TEX_COORD1
static
const char* ATTRIBUTE_NAME_TEX_COORD2
static
const char* ATTRIBUTE_NAME_TEX_COORD3
static
CC_DLL const GLchar* cc3D_Color_frag
CC_DLL const GLchar* cc3D_ColorNormal_frag
CC_DLL const GLchar* cc3D_ColorNormalTex_frag
CC_DLL const GLchar* cc3D_ColorTex_frag
CC_DLL const GLchar* cc3D_PositionNormalTex_vert
CC_DLL const GLchar* cc3D_PositionTex_vert
CC_DLL const GLchar* cc3D_SkinPositionNormalTex_vert
CC_DLL const GLchar* cc3D_SkinPositionTex_vert
CC_DLL const GLchar* ccLabel_vert
CC_DLL const GLchar* ccLabelDistanceFieldGlow_frag
CC_DLL const GLchar* ccLabelDistanceFieldNormal_frag
CC_DLL const GLchar* ccLabelNormal_frag
CC_DLL const GLchar* ccLabelOutline_frag
CC_DLL const GLchar* ccPosition_uColor_frag
CC_DLL const GLchar* ccPosition_uColor_vert
CC_DLL const GLchar* ccPositionColor_frag
CC_DLL const GLchar* ccPositionColor_vert
CC_DLL const GLchar* ccPositionColorLengthTexture_frag
CC_DLL const GLchar* ccPositionColorLengthTexture_vert
CC_DLL const GLchar* ccPositionTexture_frag
CC_DLL const GLchar* ccPositionTexture_uColor_frag
CC_DLL const GLchar* ccPositionTexture_uColor_vert
CC_DLL const GLchar* ccPositionTexture_vert
CC_DLL const GLchar* ccPositionTextureA8Color_frag
CC_DLL const GLchar* ccPositionTextureA8Color_vert
CC_DLL const GLchar* ccPositionTextureColor_frag
CC_DLL const GLchar* ccPositionTextureColor_noMVP_frag
CC_DLL const GLchar* ccPositionTextureColor_noMVP_vert
CC_DLL const GLchar* ccPositionTextureColor_vert
CC_DLL const GLchar* ccPositionTextureColorAlphaTest_frag
GLuint index
GLint location
std::string name
std::string name
const char* SHADER_3D_POSITION
static
const char* SHADER_3D_POSITION_NORMAL
static
const char* SHADER_3D_POSITION_NORMAL_TEXTURE
static
const char* SHADER_3D_POSITION_TEXTURE
static
const char* SHADER_3D_SKINPOSITION_NORMAL_TEXTURE
static
const char* SHADER_3D_SKINPOSITION_TEXTURE
static
const char* SHADER_NAME_LABEL_DISTANCEFIELD_GLOW
static
const char* SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL
static
const char* SHADER_NAME_LABEL_NORMAL
static
const char* SHADER_NAME_LABEL_OUTLINE
static
const char* SHADER_NAME_POSITION_COLOR
static
const char* SHADER_NAME_POSITION_COLOR_NO_MVP
static
const char* SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR
static
const char* SHADER_NAME_POSITION_TEXTURE
static
const char* SHADER_NAME_POSITION_TEXTURE_A8_COLOR
static
const char* SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST
static
const char* SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV
static
const char* SHADER_NAME_POSITION_TEXTURE_COLOR
static
const char* SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP
static
const char* SHADER_NAME_POSITION_TEXTURE_U_COLOR
static
const char* SHADER_NAME_POSITION_U_COLOR
static
GLint size
GLint size
GLenum type
GLenum type
const char* UNIFORM_NAME_ALPHA_TEST_VALUE
static
const char* UNIFORM_NAME_AMBIENT_COLOR
static
const char* UNIFORM_NAME_COS_TIME
static
const char* UNIFORM_NAME_MV_MATRIX
static
const char* UNIFORM_NAME_MVP_MATRIX
static
const char* UNIFORM_NAME_NORMAL_MATRIX
static
const char* UNIFORM_NAME_P_MATRIX
static
const char* UNIFORM_NAME_RANDOM01
static
const char* UNIFORM_NAME_SAMPLER0
static
const char* UNIFORM_NAME_SAMPLER1
static
const char* UNIFORM_NAME_SAMPLER2
static
const char* UNIFORM_NAME_SAMPLER3
static
const char* UNIFORM_NAME_SIN_TIME
static
const char* UNIFORM_NAME_TIME
static
unsigned int usesMV
unsigned int usesMVP
unsigned int usesNormal
unsigned int usesP
unsigned int usesRandom
unsigned int usesTime

Friends

friend class GLProgramState
friend