From 693257fffedcd9b4ffa0b6497f0c6d00f10510fb Mon Sep 17 00:00:00 2001 From: bmanGH Date: Mon, 28 Oct 2013 00:58:57 +0800 Subject: [PATCH] add setUniformLocationWithMatrix2fv, setUniformLocationWithMatrix3fv mothed in GLProgram class. --- cocos/2d/CCGLProgram.cpp | 18 ++++++++++++++++++ cocos/2d/CCGLProgram.h | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/cocos/2d/CCGLProgram.cpp b/cocos/2d/CCGLProgram.cpp index 83da8f9bdc..ccc908d646 100644 --- a/cocos/2d/CCGLProgram.cpp +++ b/cocos/2d/CCGLProgram.cpp @@ -512,6 +512,24 @@ void GLProgram::setUniformLocationWith4fv(GLint location, GLfloat* floats, unsig } } +void GLProgram::setUniformLocationWithMatrix2fv(GLint location, GLfloat* matrixArray, unsigned int numberOfMatrices) { + bool updated = updateUniformLocation(location, matrixArray, sizeof(float)*4*numberOfMatrices); + + if( updated ) + { + glUniformMatrix2fv( (GLint)location, (GLsizei)numberOfMatrices, GL_FALSE, matrixArray); + } +} + +void GLProgram::setUniformLocationWithMatrix3fv(GLint location, GLfloat* matrixArray, unsigned int numberOfMatrices) { + bool updated = updateUniformLocation(location, matrixArray, sizeof(float)*9*numberOfMatrices); + + if( updated ) + { + glUniformMatrix3fv( (GLint)location, (GLsizei)numberOfMatrices, GL_FALSE, matrixArray); + } +} + void GLProgram::setUniformLocationWithMatrix4fv(GLint location, GLfloat* matrixArray, unsigned int numberOfMatrices) { diff --git a/cocos/2d/CCGLProgram.h b/cocos/2d/CCGLProgram.h index cea1add0b2..44b5676dea 100644 --- a/cocos/2d/CCGLProgram.h +++ b/cocos/2d/CCGLProgram.h @@ -198,6 +198,12 @@ public: /** calls glUniform4fv only if the values are different than the previous call for this same shader program. */ void setUniformLocationWith4fv(GLint location, GLfloat* floats, unsigned int numberOfArrays); + /** calls glUniformMatrix2fv only if the values are different than the previous call for this same shader program. */ + void setUniformLocationWithMatrix2fv(GLint location, GLfloat* matrixArray, unsigned int numberOfMatrices); + + /** calls glUniformMatrix3fv only if the values are different than the previous call for this same shader program. */ + void setUniformLocationWithMatrix3fv(GLint location, GLfloat* matrixArray, unsigned int numberOfMatrices); + /** calls glUniformMatrix4fv only if the values are different than the previous call for this same shader program. */ void setUniformLocationWithMatrix4fv(GLint location, GLfloat* matrixArray, unsigned int numberOfMatrices);