0
点赞
收藏
分享

微信扫一扫

cocos设置自定义渲染

1kesou 2022-03-14 阅读 51

1.使用CustomCommand
对node子类(需有_customCommand成员)重写visit或draw,在其中使用CustomCommand绘制命令。

_customCommand.func = CC_CALLBACK_0(HelloWorld::onDraw, this);
renderer->addCommand(&_customCommand);

CustomCommand执行execute时会直接调用func函数,func设置为每帧执行的onDraw函数,onDraw函数里实现OpenGL相关代码

对整个类的渲染方式都发送了改变

2.setGLProgramState
init函数中设置使用自定义shader

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

创建自定义shader的GLPragram

GLProgramState* GLProgramState::getOrCreateWithGLProgram(GLProgram *glprogram)

通过cache缓存创建一个GLProgramState

void Node::setGLProgramState(cocos2d::GLProgramState* glProgramState)

在onDraw函数中获取GLProgramState传入shader所需参数

GLProgramState *getGLProgramState() const;
举报

相关推荐

0 条评论