issue #1056: Rename ccGLState to ccGLStateCache, add some ccShader_***_.h, update CCGLProgram class.

This commit is contained in:
James Chen 2012-03-15 10:42:22 +08:00
parent 8aa3f7f9ae
commit 9e89171557
35 changed files with 546 additions and 135 deletions

View File

@ -49,7 +49,7 @@ THE SOFTWARE.
#include "CCTouch.h"
#include "CCUserDefault.h"
#include "extensions/CCNotificationCenter.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "CCShaderCache.h"
#include "kazmath/kazmath.h"
#include "kazmath/GL/matrix.h"

View File

@ -29,7 +29,7 @@ THE SOFTWARE.
#include "ccMacros.h"
#include "CCGL.h"
#include "CCDirector.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "CCShaderCache.h"
#include "CCGLProgram.h"
#include <string.h>

View File

@ -29,7 +29,7 @@ THE SOFTWARE.
#include "CCDirector.h"
#include "CCGLProgram.h"
#include "CCShaderCache.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "CCDirector.h"
#include "support/TransformUtils.h"

View File

@ -29,7 +29,7 @@ THE SOFTWARE.
#include "support/ccUtils.h"
#include "CCGLProgram.h"
#include "CCShaderCache.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "CCGL.h"
#include "CCPointExtension.h"
#include "support/TransformUtils.h"

View File

@ -1,39 +1,56 @@
//
// Copyright 2011 Jeff Lamarche
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided
// that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
// the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
// and the following disclaimer in the documentation and/or other materials provided with the
// distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT
// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Adapted for cocos2d http://www.cocos2d-iphone.org
/****************************************************************************
Copyright 2012 cocos2d-x.org
Copyright 2011 Jeff Lamarche
Copyright 2012 Goffredo Marocchi
Copyright 2012 Ricardo Quesada
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN false EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCGLProgram.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "ccMacros.h"
#include "CCFileUtils.h"
#include "support/data_support/uthash.h"
#include "CCString.h"
// extern
#include "kazmath/GL/matrix.h"
#include "kazmath/kazmath.h"
NS_CC_BEGIN
typedef struct _hashUniformEntry
{
GLvoid* value; // value
unsigned int location; // Key
UT_hash_handle hh; // hash entry
} tHashUniformEntry;
CCGLProgram::CCGLProgram()
: program_(0)
, vertShader_(0)
, fragShader_(0)
, hashForUniforms_(NULL)
{
memset(uniforms_, 0, sizeof(uniforms_));
}
CCGLProgram::~CCGLProgram()
@ -45,43 +62,62 @@ CCGLProgram::~CCGLProgram()
CCAssert( fragShader_ == 0, "Vertex Shaders should have been already deleted");
if (program_)
{
ccGLDeleteProgram(program_);
}
tHashUniformEntry *current_element, *tmp;
// Purge uniform hash
HASH_ITER(hh, hashForUniforms_, current_element, tmp) {
HASH_DEL(hashForUniforms_, current_element);
free(current_element->value);
free(current_element);
}
}
bool CCGLProgram::initWithVertexShaderFilename(const char* vShaderFilename, const char* fShaderFilename)
bool CCGLProgram::initWithVertexShaderByteArray(const GLchar* vShaderByteArray, const GLchar* fShaderByteArray)
{
program_ = glCreateProgram();
vertShader_ = fragShader_ = 0;
if( vShaderFilename ) {
const char *fullname = CCFileUtils::fullPathFromRelativePath(vShaderFilename);
if( vShaderByteArray ) {
if (!compileShader(&vertShader_, GL_VERTEX_SHADER, fullname)) {
CCLOG("cocos2d: ERROR: Failed to compile vertex shader: %s", vShaderFilename);
if (!compileShader(&vertShader_, GL_VERTEX_SHADER, vShaderByteArray)) {
CCLOG("cocos2d: ERROR: Failed to compile vertex shader");
}
}
// Create and compile fragment shader
if( fShaderFilename ) {
const char *fullname = CCFileUtils::fullPathFromRelativePath(fShaderFilename);
if( fShaderByteArray ) {
if (!compileShader(&fragShader_, GL_FRAGMENT_SHADER, fullname)) {
CCLOG("cocos2d: ERROR: Failed to compile fragment shader: %s", fShaderFilename);
if (!compileShader(&fragShader_, GL_FRAGMENT_SHADER, fShaderByteArray)) {
CCLOG("cocos2d: ERROR: Failed to compile fragment shader");
}
}
if( vertShader_ )
if( vertShader_ ) {
glAttachShader(program_, vertShader_);
}
if( fragShader_ )
if( fragShader_ ) {
glAttachShader(program_, fragShader_);
}
hashForUniforms_ = NULL;
return true;
}
bool CCGLProgram::initWithVertexShaderFilename(const char* vShaderFilename, const char* fShaderFilename)
{
const GLchar * vertexSource = (GLchar*) CCString::stringWithContentsOfFile(CCFileUtils::fullPathFromRelativePath(vShaderFilename));
const GLchar * fragmentSource = (GLchar*) CCString::stringWithContentsOfFile(CCFileUtils::fullPathFromRelativePath(fShaderFilename));
return initWithVertexShaderByteArray(vertexSource, fragmentSource);
}
const char* CCGLProgram::description()
{
static char strDescription[100] = {0};
@ -89,12 +125,10 @@ const char* CCGLProgram::description()
return strDescription;
}
bool CCGLProgram::compileShader(GLuint * shader, GLenum type, const char* file)
bool CCGLProgram::compileShader(GLuint * shader, GLenum type, const GLchar* source)
{
GLint status;
const GLchar *source;
source = (GLchar *)CCString::stringWithContentsOfFile(file);
if (!source)
return false;
@ -106,12 +140,12 @@ bool CCGLProgram::compileShader(GLuint * shader, GLenum type, const char* file)
if( ! status ) {
if( type == GL_VERTEX_SHADER )
CCLOG("cocos2d: %s: %s", file, vertexShaderLog() );
CCLOG("cocos2d: %s", vertexShaderLog() );
else
CCLOG("cocos2d: %s: %s", file, fragmentShaderLog() );
CCLOG("cocos2d: %s", fragmentShaderLog() );
}
return status == GL_TRUE;
return ( status == GL_TRUE );
}
void CCGLProgram::addAttribute(const char* attributeName, GLuint index)
@ -129,8 +163,8 @@ void CCGLProgram::updateUniforms()
uniforms_[kCCUniformSampler] = glGetUniformLocation(program_, kCCUniformSampler_s);
ccGLUseProgram( program_ );
glUniform1i( uniforms_[kCCUniformSampler], 0 );
this->use();
this->setUniformLocationWith1i( uniforms_[kCCUniformSampler], 0 );
}
bool CCGLProgram::link()
@ -189,7 +223,7 @@ const char* CCGLProgram::logForOpenGLObject(GLuint object, GLInfoFunction infoFu
const char* CCGLProgram::vertexShaderLog()
{
return this->logForOpenGLObject(vertShader_, (GLInfoFunction)&glGetProgramiv, (GLLogFunction)&glGetProgramInfoLog);
return this->logForOpenGLObject(vertShader_, (GLInfoFunction)&glGetShaderiv, (GLLogFunction)&glGetShaderInfoLog);
}
const char* CCGLProgram::fragmentShaderLog()
@ -202,5 +236,126 @@ const char* CCGLProgram::programLog()
return this->logForOpenGLObject(program_, (GLInfoFunction)&glGetProgramiv, (GLLogFunction)&glGetProgramInfoLog);
}
// Uniform cache
bool CCGLProgram::updateUniformLocation(unsigned int location, GLvoid* data, unsigned int bytes)
{
bool updated = true;
tHashUniformEntry *element = NULL;
HASH_FIND_INT(hashForUniforms_, &location, element);
if( ! element ) {
element = (tHashUniformEntry*)malloc( sizeof(*element) );
// key
element->location = location;
// value
element->value = malloc( bytes );
memcpy(element->value, data, bytes );
HASH_ADD_INT(hashForUniforms_, location, element);
}
else
{
if( memcmp( element->value, data, bytes) == 0 )
updated = false;
else
memcpy( element->value, data, bytes );
}
return updated;
}
void CCGLProgram::setUniformLocationWith1i(unsigned int location, GLint i1)
{
bool updated = updateUniformLocation(location, &i1, sizeof(i1)*1);
if( updated )
glUniform1i( (GLint)location, i1);
}
void CCGLProgram::setUniformLocationWith1f(unsigned int location, GLfloat f1)
{
bool updated = updateUniformLocation(location, &f1, sizeof(f1)*1);
if( updated )
glUniform1f( (GLint)location, f1);
}
void CCGLProgram::setUniformLocationWith2f(unsigned int location, GLfloat f1, GLfloat f2)
{
GLfloat floats[2] = {f1,f2};
bool updated = updateUniformLocation(location, floats, sizeof(floats));
if( updated )
glUniform2f( (GLint)location, f1, f2);
}
void CCGLProgram::setUniformLocationWith3f(unsigned int location, GLfloat f1, GLfloat f2, GLfloat f3)
{
GLfloat floats[3] = {f1,f2,f3};
bool updated = updateUniformLocation(location, floats, sizeof(floats));
if( updated )
glUniform3f( (GLint)location, f1, f2, f3);
}
void CCGLProgram::setUniformLocationWith4f(unsigned int location, GLfloat f1, GLfloat f2, GLfloat f3, GLfloat f4)
{
GLfloat floats[4] = {f1,f2,f3,f4};
bool updated = updateUniformLocation(location, floats, sizeof(floats));
if( updated )
glUniform4f( (GLint)location, f1, f2, f3,f4);
}
void CCGLProgram::setUniformLocationWith2fv(unsigned int location, GLfloat* floats, unsigned int numberOfArrays)
{
bool updated = updateUniformLocation(location, floats, sizeof(float)*2*numberOfArrays);
if( updated )
glUniform2fv( (GLint)location, (GLsizei)numberOfArrays, floats );
}
void CCGLProgram::setUniformLocationWith3fv(unsigned int location, GLfloat* floats, unsigned int numberOfArrays)
{
bool updated = updateUniformLocation(location, floats, sizeof(float)*3*numberOfArrays);
if( updated )
glUniform3fv( (GLint)location, (GLsizei)numberOfArrays, floats );
}
void CCGLProgram::setUniformLocationWith4fv(unsigned int location, GLfloat* floats, unsigned int numberOfArrays)
{
bool updated = updateUniformLocation(location, floats, sizeof(float)*4*numberOfArrays);
if( updated )
glUniform4fv( (GLint)location, (GLsizei)numberOfArrays, floats );
}
void CCGLProgram::setUniformLocationwithMatrix4fv(unsigned int location, GLfloat* matrixArray, unsigned int numberOfMatrices)
{
bool updated = updateUniformLocation(location, matrixArray, sizeof(float)*16*numberOfMatrices);
if( updated )
glUniformMatrix4fv( (GLint)location, (GLsizei)numberOfMatrices, GL_FALSE, matrixArray);
}
void CCGLProgram::setUniformForModelViewProjectionMatrix()
{
kmMat4 matrixP;
kmMat4 matrixMV;
kmMat4 matrixMVP;
kmGLGetMatrix(KM_GL_PROJECTION, &matrixP );
kmGLGetMatrix(KM_GL_MODELVIEW, &matrixMV );
kmMat4Multiply(&matrixMVP, &matrixP, &matrixMV);
setUniformLocationwithMatrix4fv(uniforms_[kCCUniformMVPMatrix], matrixMVP.mat, 1);
}
NS_CC_END

View File

@ -23,7 +23,7 @@
* THE SOFTWARE.
*/
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "CCGLProgram.h"
#include "CCDirector.h"
#include "ccConfig.h"
@ -54,7 +54,10 @@ static int _ccGLServerState = 0;
void ccGLInvalidateStateCache( void )
{
kmGLFreeAll();
_ccCurrentProjectionMatrix = -1;
_vertexAttribPosition = false;
_vertexAttribColor = false;
_vertexAttribTexCoords = false;
#if CC_ENABLE_GL_STATE_CACHE
_ccCurrentShaderProgram = -1;
for( int i=0; i < kCCMaxActiveTexture; i++ )
@ -217,20 +220,6 @@ void ccGLEnableVertexAttribs( unsigned int flags )
//#pragma mark - GL Uniforms functions
void ccGLUniformModelViewProjectionMatrix( CCGLProgram *shaderProgram )
{
kmMat4 matrixP;
kmMat4 matrixMV;
kmMat4 matrixMVP;
kmGLGetMatrix(KM_GL_PROJECTION, &matrixP );
kmGLGetMatrix(KM_GL_MODELVIEW, &matrixMV );
kmMat4Multiply(&matrixMVP, &matrixP, &matrixMV);
glUniformMatrix4fv( shaderProgram->uniforms_[kCCUniformMVPMatrix], 1, GL_FALSE, matrixMVP.mat);
}
void ccSetProjectionMatrixDirty( void )
{
_ccCurrentProjectionMatrix = -1;

View File

@ -1,27 +1,29 @@
//
// Copyright 2011 Jeff Lamarche
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided
// that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
// the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
// and the following disclaimer in the documentation and/or other materials provided with the
// distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT
// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//
// Adapted for cocos2d http://www.cocos2d-iphone.org
/****************************************************************************
Copyright 2012 cocos2d-x.org
Copyright 2011 Jeff Lamarche
Copyright 2012 Goffredo Marocchi
Copyright 2012 Ricardo Quesada
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCGLPROGRAM_H__
#define __CCGLPROGRAM_H__
@ -52,6 +54,7 @@ enum {
#define kCCShader_PositionTexture "ShaderPositionTexture"
#define kCCShader_PositionTexture_uColor "ShaderPositionTexture_uColor"
#define kCCShader_PositionTextureA8Color "ShaderPositionTextureA8Color"
#define kCCShader_Position_uColor "ShaderPosition_uColor"
// uniform names
#define kCCUniformMVPMatrix_s "u_MVPMatrix"
@ -63,6 +66,8 @@ enum {
#define kCCAttributeNamePosition "a_position"
#define kCCAttributeNameTexCoord "a_texCoord"
struct _hashUniformEntry;
typedef void (*GLInfoFunction)(GLuint program,
GLenum pname,
GLint* params);
@ -73,34 +78,75 @@ typedef void (*GLLogFunction) (GLuint program,
/** CCGLProgram
Class that implements a glProgram
@since v2.0.0
*/
class CC_DLL CCGLProgram : public CCObject
{
public:
CCGLProgram();
virtual ~CCGLProgram();
/** Initializes the CCGLProgram with a vertex and fragment with bytes array */
bool initWithVertexShaderByteArray(const GLchar* vShaderByteArray, const GLchar* fShaderByteArray);
/** Initializes the CCGLProgram with a vertex and fragment with contents of filenames */
bool initWithVertexShaderFilename(const char* vShaderFilename, const char* fShaderFilename);
/** It will add a new attribute to the shader */
void addAttribute(const char* attributeName, GLuint index);
/** links the glProgram */
bool link();
/** it will call glUseProgram() */
void use();
/* It will create 3 uniforms:
/** It will create 3 uniforms:
- kCCUniformPMatrix
- kCCUniformMVMatrix
- kCCUniformSampler
And it will bind "kCCUniformSampler" to 0
@since v2.0.0
*/
void updateUniforms();
/** calls glUniform1i only if the values are different than the previous call for this same shader program. */
void setUniformLocationWith1i(unsigned int location, GLint i1);
/** calls glUniform1f only if the values are different than the previous call for this same shader program. */
void setUniformLocationWith1f(unsigned int location, GLfloat f1);
/** calls glUniform2f only if the values are different than the previous call for this same shader program. */
void setUniformLocationWith2f(unsigned int location, GLfloat f1, GLfloat f2);
/** calls glUniform3f only if the values are different than the previous call for this same shader program. */
void setUniformLocationWith3f(unsigned int location, GLfloat f1, GLfloat f2, GLfloat f3);
/** calls glUniform4f only if the values are different than the previous call for this same shader program. */
void setUniformLocationWith4f(unsigned int location, GLfloat f1, GLfloat f2, GLfloat f3, GLfloat f4);
/** calls glUniform2fv only if the values are different than the previous call for this same shader program. */
void setUniformLocationWith2fv(unsigned int location, GLfloat* floats, unsigned int numberOfArrays);
/** calls glUniform3fv only if the values are different than the previous call for this same shader program. */
void setUniformLocationWith3fv(unsigned int location, GLfloat* floats, unsigned int numberOfArrays);
/** calls glUniform4fv only if the values are different than the previous call for this same shader program. */
void setUniformLocationWith4fv(unsigned int location, GLfloat* floats, unsigned int numberOfArrays);
/** calls glUniformMatrix4fv only if the values are different than the previous call for this same shader program. */
void setUniformLocationwithMatrix4fv(unsigned int location, GLfloat* matrixArray, unsigned int numberOfMatrices);
/** will update the MVP matrix on the MVP uniform if it is different than the previous call for this same shader program. */
void setUniformForModelViewProjectionMatrix();
/** returns the vertexShader error log */
const char* vertexShaderLog();
/** returns the fragmentShader error log */
const char* fragmentShaderLog();
/** returns the program error log */
const char* programLog();
private:
bool updateUniformLocation(unsigned int location, GLvoid* data, unsigned int bytes);
const char* description();
bool compileShader(GLuint * shader, GLenum type, const char* file);
bool compileShader(GLuint * shader, GLenum type, const GLchar* source);
const char* logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc);
public:
@ -108,6 +154,8 @@ public:
GLuint vertShader_;
GLuint fragShader_;
GLint uniforms_[kCCUniform_MAX];
private:
struct _hashUniformEntry* hashForUniforms_;
};
NS_CC_END

View File

@ -32,7 +32,7 @@
#include "CCAffineTransform.h"
#include "CCArray.h"
#include "CCGL.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "kazmath/kazmath.h"
namespace cocos2d {

View File

@ -56,7 +56,7 @@ typedef enum {
} ccGLServerState;
/** @file ccGLState.h
/** @file ccGLStateCache.h
*/
/** Invalidates the GL state cache.
@ -83,11 +83,6 @@ void CC_DLL ccGLDeleteProgram( GLuint program );
*/
void CC_DLL ccGLBlendFunc(GLenum sfactor, GLenum dfactor);
/** sets the ModelViewProjection Matrix in the GL program
@since v2.0.0
*/
void CC_DLL ccGLUniformModelViewProjectionMatrix( CCGLProgram *shaderProgram );
/** sets the projection matrix as dirty
@since v2.0.0
*/

View File

@ -118,7 +118,7 @@ THE SOFTWARE.
#include "extensions/CCNotificationCenter.h"
// Shaders
#include "CCGLProgram.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "CCShaderCache.h"
//
// cocos2d macros

View File

@ -30,7 +30,7 @@ THE SOFTWARE.
#include "ccConfig.h"
#include "CCShaderCache.h"
#include "CCGLProgram.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "CCDirector.h"
#include "support/TransformUtils.h"
// external

View File

@ -34,7 +34,7 @@ THE SOFTWARE.
#include "CCScriptSupport.h"
#include "CCShaderCache.h"
#include "CCGLProgram.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "support/TransformUtils.h"
// extern
#include "kazmath/GL/matrix.h"

View File

@ -24,7 +24,7 @@ THE SOFTWARE.
****************************************************************************/
#include "CCMotionStreak.h"
#include "CCTextureCache.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "CCGLProgram.h"
#include "CCShaderCache.h"
#include "ccMacros.h"

View File

@ -29,7 +29,7 @@ THE SOFTWARE.
#include "CCPointExtension.h"
#include "CCGLProgram.h"
#include "CCShaderCache.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "CCDirector.h"
#include "support/TransformUtils.h"
#include "CCDrawingPrimitives.h"

View File

@ -29,7 +29,7 @@ THE SOFTWARE.
#include "platform/platform.h"
#include "CCImage.h"
#include "CCGLProgram.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "CCConfiguration.h"
#include "support/ccUtils.h"
#include "CCTextureCache.h"

View File

@ -38,7 +38,7 @@
#include "CCParticleSystem.h"
#include "CCShaderCache.h"
#include "CCGLProgram.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "support/base64.h"
#include "support/zip_support/ZipUtils.h"

View File

@ -35,7 +35,7 @@ THE SOFTWARE.
#include "CCTextureAtlas.h"
#include "CCDirector.h"
#include "CCShaderCache.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "CCGLProgram.h"
#include "support/TransformUtils.h"

View File

@ -424,7 +424,7 @@
>
</File>
<File
RelativePath="..\include\ccGLState.h"
RelativePath="..\include\ccGLStateCache.h"
>
</File>
<File
@ -1108,7 +1108,7 @@
>
</File>
<File
RelativePath="..\gles2\ccGLState.cpp"
RelativePath="..\gles2\ccGLStateCache.cpp"
>
</File>
<File

View File

@ -0,0 +1,12 @@
" \n\
#ifdef GL_ES \n\
precision lowp float; \n\
#endif \n\
\n\
varying vec4 v_fragmentColor; \n\
\n\
void main() \n\
{ \n\
gl_FragColor = v_fragmentColor; \n\
} \n\
";

View File

@ -0,0 +1,17 @@
" \n\
attribute vec4 a_position; \n\
attribute vec4 a_color; \n\
uniform mat4 u_MVPMatrix; \n\
\n\
#ifdef GL_ES \n\
varying lowp vec4 v_fragmentColor; \n\
#else \n\
varying vec4 v_fragmentColor; \n\
#endif \n\
\n\
void main() \n\
{ \n\
gl_Position = u_MVPMatrix * a_position; \n\
v_fragmentColor = a_color; \n\
} \n\
";

View File

@ -0,0 +1,16 @@
" \n\
#ifdef GL_ES \n\
precision lowp float; \n\
#endif \n\
\n\
varying vec4 v_fragmentColor; \n\
varying vec2 v_texCoord; \n\
uniform sampler2D u_texture; \n\
\n\
void main() \n\
{ \n\
gl_FragColor = vec4( v_fragmentColor.rgb, // RGB from uniform \n\
v_fragmentColor.a * texture2D(u_texture, v_texCoord).a // A from texture & uniform \n\
); \n\
} \n\
";

View File

@ -0,0 +1,21 @@
" \n\
attribute vec4 a_position; \n\
attribute vec2 a_texCoord; \n\
attribute vec4 a_color; \n\
uniform mat4 u_MVPMatrix; \n\
\n\
#ifdef GL_ES \n\
varying lowp vec4 v_fragmentColor; \n\
varying mediump vec2 v_texCoord; \n\
#else \n\
varying vec4 v_fragmentColor; \n\
varying vec2 v_texCoord; \n\
#endif \n\
\n\
void main() \n\
{ \n\
gl_Position = u_MVPMatrix * a_position; \n\
v_fragmentColor = a_color; \n\
v_texCoord = a_texCoord; \n\
} \n\
";

View File

@ -0,0 +1,23 @@
" \n\
#ifdef GL_ES \n\
precision lowp float; \n\
#endif \n\
\n\
varying vec4 v_fragmentColor; \n\
varying vec2 v_texCoord; \n\
uniform sampler2D u_texture; \n\
uniform float u_alpha_value; \n\
\n\
void main() \n\
{ \n\
vec4 texColor = texture2D(u_texture, v_texCoord); \n\
\n\
// mimic: glAlphaFunc(GL_GREATER) \n\
// pass if ( incoming_pixel >= u_alpha_value ) => fail if incoming_pixel < u_alpha_value \n\
\n\
if ( texColor.a <= u_alpha_value ) \n\
discard; \n\
\n\
gl_FragColor = texColor * v_fragmentColor; \n\
} \n\
";

View File

@ -0,0 +1,14 @@
" \n\
#ifdef GL_ES \n\
precision lowp float; \n\
#endif \n\
\n\
varying vec4 v_fragmentColor; \n\
varying vec2 v_texCoord; \n\
uniform sampler2D u_texture; \n\
\n\
void main() \n\
{ \n\
gl_FragColor = v_fragmentColor * texture2D(u_texture, v_texCoord); \n\
} \n\
";

View File

@ -0,0 +1,22 @@
" \n\
attribute vec4 a_position; \n\
attribute vec2 a_texCoord; \n\
attribute vec4 a_color; \n\
\n\
uniform mat4 u_MVPMatrix; \n\
\n\
#ifdef GL_ES \n\
varying lowp vec4 v_fragmentColor; \n\
varying mediump vec2 v_texCoord; \n\
#else \n\
varying vec4 v_fragmentColor; \n\
varying vec2 v_texCoord; \n\
#endif \n\
\n\
void main() \n\
{ \n\
gl_Position = u_MVPMatrix * a_position; \n\
v_fragmentColor = a_color; \n\
v_texCoord = a_texCoord; \n\
} \n\
";

View File

@ -0,0 +1,13 @@
" \n\
#ifdef GL_ES \n\
precision lowp float; \n\
#endif \n\
\n\
varying vec2 v_texCoord; \n\
uniform sampler2D u_texture; \n\
\n\
void main() \n\
{ \n\
gl_FragColor = texture2D(u_texture, v_texCoord); \n\
} \n\
";

View File

@ -0,0 +1,16 @@
" \n\
#ifdef GL_ES \n\
precision lowp float; \n\
#endif \n\
\n\
uniform vec4 u_color; \n\
\n\
varying vec2 v_texCoord; \n\
\n\
uniform sampler2D u_texture; \n\
\n\
void main() \n\
{ \n\
gl_FragColor = texture2D(u_texture, v_texCoord) * u_color; \n\
} \n\
";

View File

@ -0,0 +1,18 @@
" \n\
attribute vec4 a_position; \n\
attribute vec2 a_texCoord; \n\
\n\
uniform mat4 u_MVPMatrix; \n\
\n\
#ifdef GL_ES \n\
varying mediump vec2 v_texCoord; \n\
#else \n\
varying vec2 v_texCoord; \n\
#endif \n\
\n\
void main() \n\
{ \n\
gl_Position = u_MVPMatrix * a_position; \n\
v_texCoord = a_texCoord; \n\
} \n\
";

View File

@ -0,0 +1,17 @@
" \n\
attribute vec4 a_position; \n\
attribute vec2 a_texCoord; \n\
uniform mat4 u_MVPMatrix; \n\
\n\
#ifdef GL_ES \n\
varying mediump vec2 v_texCoord; \n\
#else \n\
varying vec2 v_texCoord; \n\
#endif \n\
\n\
void main() \n\
{ \n\
gl_Position = u_MVPMatrix * a_position; \n\
v_texCoord = a_texCoord; \n\
} \n\
";

View File

@ -0,0 +1,12 @@
" \n\
#ifdef GL_ES \n\
precision lowp float; \n\
#endif \n\
\n\
varying vec4 v_fragmentColor; \n\
\n\
void main() \n\
{ \n\
gl_FragColor = v_fragmentColor; \n\
} \n\
";

View File

@ -0,0 +1,19 @@
" \n\
attribute vec4 a_position; \n\
uniform mat4 u_MVPMatrix; \n\
uniform vec4 u_color; \n\
uniform float u_pointSize; \n\
\n\
#ifdef GL_ES \n\
varying lowp vec4 v_fragmentColor; \n\
#else \n\
varying vec4 v_fragmentColor; \n\
#endif \n\
\n\
void main() \n\
{ \n\
gl_Position = u_MVPMatrix * a_position; \n\
gl_PointSize = u_pointSize; \n\
v_fragmentColor = u_color; \n\
} \n\
";

View File

@ -34,7 +34,7 @@ THE SOFTWARE.
#include "CCTextureCache.h"
#include "CCDrawingPrimitives.h"
#include "CCShaderCache.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "CCGLProgram.h"
#include "CCDirector.h"
#include "CCPointExtension.h"
@ -561,6 +561,10 @@ void CCSprite::draw(void)
{
ccGLBindTexture2D( m_pobTexture->getName() );
}
else
{
ccGLBindTexture2D(0);
}
//
// Attributes

View File

@ -33,7 +33,7 @@ THE SOFTWARE.
#include "CCPointExtension.h"
#include "CCShaderCache.h"
#include "CCGLProgram.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "CCDirector.h"
#include "support/TransformUtils.h"
#include "support/CCProfiling.h"

View File

@ -43,7 +43,7 @@ THE SOFTWARE.
#include "CCTexturePVR.h"
#include "CCDirector.h"
#include "CCGLProgram.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
#include "CCShaderCache.h"
#if CC_ENABLE_CACHE_TEXTTURE_DATA

View File

@ -29,7 +29,7 @@ THE SOFTWARE.
#include "CCTextureCache.h"
#include "ccMacros.h"
#include "CCGLProgram.h"
#include "ccGLState.h"
#include "ccGLStateCache.h"
// support
#include "CCTexture2D.h"