首先分析:CCGLProgram /**************************************************************************** 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__ #include "ccMacros.h" #include "cocoa/CCObject.h" #include "CCGL.h" NS_CC_BEGIN /** * @addtogroup shaders * @{ */ enum { kCCVertexAttrib_Position, //顶点流的位置属性 kCCVertexAttrib_Color, //顶点流颜色属性 kCCVertexAttrib_TexCoords, //顶点流纹理坐标属性 kCCVertexAttrib_MAX, }; //以下是cocos2d自带的shaderprogram 中的 uniform 变量 enum { kCCUniformPMatrix, //projection transform Matrix kCCUniformMVMatrix, //model view transform Matrix kCCUniformMVPMatrix, //model view pro transform matrix kCCUniformTime, kCCUniformSinTime, kCCUniformCosTime, kCCUniformRandom01, kCCUniformSampler, kCCUniform_MAX, }; //cocos2dx 自带的shader #define kCCShader_PositionTextureColor "ShaderPositionTextureColor" #define kCCShader_PositionTextureColorAlphaTest "ShaderPositionTextureColorAlphaTest" #define kCCShader_PositionColor "ShaderPositionColor" #define kCCShader_PositionTexture "ShaderPositionTexture" #define kCCShader_PositionTexture_uColor "ShaderPositionTexture_uColor" #define kCCShader_PositionTextureA8Color "ShaderPositionTextureA8Color" #define kCCShader_Position_uColor "ShaderPosition_uColor" #define kCCShader_PositionLengthTexureColor "ShaderPositionLengthTextureColor" // uniform names shader中用到的变量 #define kCCUniformPMatrix_s "CC_PMatrix" #define kCCUniformMVMatrix_s "CC_MVMatrix" #define kCCUniformMVPMatrix_s "CC_MVPMatrix" #define kCCUniform