cocos2d-x节点(CCGLProgram.h)API

本文来自http://blog.csdn.net/runaying ,引用必须注明出处!

cocos2d-x节点(CCGLProgram.h)API

温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记

顶点着色器 相关操作

///cocos2d-x-3.0alpha0/cocos2dx/shaders
//顶点着色器 相关操作


#ifndef __CCGLPROGRAM_H__
#define __CCGLPROGRAM_H__

#include "ccMacros.h"
#include "cocoa/CCObject.h"

#include "CCGL.h"

NS_CC_BEGIN

/**
 * @addtogroup shaders
 * @{
 */

struct _hashUniformEntry;

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

/** GLProgram
 Class that implements a glProgram
 
 
 @since v2.0.0
 */
class CC_DLL GLProgram : public Object
{
public:
    enum
    {
        VERTEX_ATTRIB_POSITION,
        VERTEX_ATTRIB_COLOR,
        VERTEX_ATTRIB_TEX_COORDS,
        
        VERTEX_ATTRIB_MAX,
    };
    
    enum
    {
        UNIFORM_P_MATRIX,
        UNIFORM_MV_MATRIX,
        UNIFORM_MVP_MATRIX,
        UNIFORM_TIME,
        UNIFORM_SIN_TIME,
        UNIFORM_COS_TIME,
        UNIFORM_RANDOM01,
        UNIFORM_SAMPLER,
        
        UNIFORM_MAX,
    };
    
    static const char* SHADER_NAME_POSITION_TEXTURE_COLOR;
    static const char* SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST;
    static const char* SHADER_NAME_POSITION_COLOR;
    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;
    
    // uniform names
    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_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_SAMPLER;
    static const char* UNIFORM_NAME_ALPHA_TEST_VALUE;
    
    // Attribute names
    static const char* ATTRIBUTE_NAME_COLOR;
    static const char* ATTRIBUTE_NAME_POSITION;
    static const char* ATTRIBUTE_NAME_TEX_COORD;
    /**
     * @js ctor
     */
    GLProgram();
    /**
     * @js NA
     * @lua NA
     */
    virtual ~GLProgram();
    /** 使用 a vertex 、 fragment with bytes array(字节数组片段)  初始化一个  GLProgram 
     * @js initWithString
     * @lua initWithString
     */
    bool initWithVertexShaderByteArray(const GLchar* vShaderByteArray, const GLchar* fShaderByteArray);
    /** 使用 vShaderFilename、 fShaderFilename 初始化一个  GLProgram 
     * @js init
     * @lua init
     */
    bool initWithVertexShaderFilename(const char* vShaderFilename, const char* fShaderFilename);
    /** 这将增加一个新的属性到shader */
    void addAttribute(const char* attributeName, GLuint index);
    /** links the glProgram */
    bool link();
    /** it will call glUseProgram() */
    void use();
/** It will create 4 uniforms(标准):
    - kUniformPMatrix
    - kUniformMVMatrix
    - kUniformMVPMatrix
    - GLProgram::UNIFORM_SAMPLER

 And it will bind(绑定) "GLProgram::UNIFORM_SAMPLER" to 0

 */
    void updateUniforms();
    
    /** 检索这个本地的shader程序命名统一时调用. */
    GLint getUniformLocationForName(const char* name) const;
    
    /** 相同的shader程序,只有这次调用和上次调用值是不同的它才调用 glUniform1i
     * @js setUniformLocationI32
     * @lua setUniformLocationI32
     */
    void setUniformLocationWith1i(GLint location, GLint i1);
    
    /** 相同的shader程序,只有这次调用和上次调用值是不同的它才调用 glUniform2i . */
    void setUniformLocationWith2i(GLint location, GLint i1, GLint i2);
    
    /** 相同的shader程序,只有这次调用和上次调用值是不同的它才调用 glUniform3i . */
    void setUniformLocationWith3i(GLint location, GLint i1, GLint i2, GLint i3);
    
    /** 相同的shader程序,只有这次调用和上次调用值是不同的它才调用 glUniform4i . */
    void setUniformLocationWith4i(GLint location, GLint i1, GLint i2, GLint i3, GLint i4);
    
    /** 相同的shader程序,只有这次调用和上次调用值是不同的它才调用 glUniform2iv . */
    void setUniformLocationWith2iv(GLint location, GLint* ints, unsigned int numberOfArrays);
    
    /** 相同的shader程序,只有这次调用和上次调用值是不同的它才调用 glUniform3iv . */
    void setUniformLocationWith3iv(GLint location, GLint* ints, unsigned int numberOfArrays);
    
    /** 相同的shader程序,只有这次调用和上次调用值是不同的它才调用 glUniform4iv . */
    
    void setUniformLocationWith4iv(GLint location, GLint* ints, unsigned int numberOfArrays);

    /** 相同的shader程序,只有这次调用和上次调用值是不同的它才调用 glUniform1f
     * In js or lua,please use setUniformLocationF32
     * @js NA
     */
    void setUniformLocationWith1f(GLint location, GLfloat f1);

    /** 相同的shader程序,只有这次调用和上次调用值是不同的它才调用 glUniform2f .
     * In js or lua,please use setUniformLocationF32
     * @js NA
     */
    void setUniformLocationWith2f(GLint location, GLfloat f1, GLfloat f2);

    /** 相同的shader程序,只有这次调用和上次调用值是不同的它才调用 glUniform3f .
     * In js or lua,please use setUniformLocationF32
     * @js NA
     */
    void setUniformLocationWith3f(GLint location, GLfloat f1, GLfloat f2, GLfloat f3);

    /** 相同的shader程序,只有这次调用和上次调用值是不同的它才调用 glUniform4f .
     * In js or lua,please use setUniformLocationF32
     * @js NA
     */
    void setUniformLocationWith4f(GLint location, GLfloat f1, GLfloat f2, GLfloat f3, GLfloat f4);

    /** 相同的shader程序,只有这次调用和上次调用值是不同的它才调用 glUniform2fv . */
    void setUniformLocationWith2fv(GLint location, GLfloat* floats, unsigned int numberOfArrays);

    /** 相同的shader程序,只有这次调用和上次调用值是不同的它才调用 glUniform3fv . */
    void setUniformLocationWith3fv(GLint location, GLfloat* floats, unsigned int numberOfArrays);

    /** 相同的shader程序,只有这次调用和上次调用值是不同的它才调用 glUniform4fv . */
    void setUniformLocationWith4fv(GLint location, GLfloat* floats, unsigned int numberOfArrays);

    /** 相同的shader程序,只有这次调用和上次调用值是不同的它才调用 glUniformMatrix4fv . */
    void setUniformLocationWithMatrix4fv(GLint location, GLfloat* matrixArray, unsigned int numberOfMatrices);
    
    /** 相同的shader程序,如果这次调用和上次调用值是不同的,它才调用更新内置的标准. */
    void setUniformsForBuiltins();

    /** returns the vertexShader error log */
    const char* getVertexShaderLog() const;
    /** @过时不再需要建议使用新的 API ,可以使用getVertexShaderLog() 代替
     * @js NA
     * @lua NA
     */
    CC_DEPRECATED_ATTRIBUTE const char* vertexShaderLog() const { return getVertexShaderLog(); }
    /** returns the fragmentShader error log */
    const char* getFragmentShaderLog() const;
    /** @过时不再需要建议使用新的 API ,可以使用 getFragmentShaderLog() 代替
     * @js NA
     * @lua NA
     */
    CC_DEPRECATED_ATTRIBUTE const char* fragmentShaderLog() const{ return getFragmentShaderLog();}
    /** returns the program error log */
    const char* getProgramLog() const;
    /** @过时不再需要建议使用新的 API ,可以使用 getProgramLog() 代替
     * @js NA
     * @lua NA
     */
    CC_DEPRECATED_ATTRIBUTE const char* programLog() const { return getProgramLog(); }
    
    // 这个功能是专为Android,重新加载所有着色器,
    // 当OpenGL上下文丢失时,不调用它.
    void reset();
    
    inline const GLuint getProgram() const { return _program; }

private:
    bool updateUniformLocation(GLint location, GLvoid* data, unsigned int bytes);
    const char* description() const;
    bool compileShader(GLuint * shader, GLenum type, const GLchar* source);
    const char* logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const;

private:
    GLuint            _program;
    GLuint            _vertShader;
    GLuint            _fragShader;
    GLint             _uniforms[UNIFORM_MAX];
    struct _hashUniformEntry* _hashForUniforms;
    bool              _usesTime;
};

// end of shaders group
/// @}

NS_CC_END

#endif /* __CCGLPROGRAM_H__ */


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值