cocos2d::glprogramstate分析

2016-05-01  本文已影响662人  核桃啊

先看看和glprogram的区别,下面是官方的解释:

/**

GLProgramState holds the 'state' (uniforms and attributes) of the GLProgram.

A GLProgram can be used by thousands of Nodes, but if different uniform values

are going to be used, then each node will need its own GLProgramState

*/


可见大多是对于uniform的赋值

glprogram根据一个program创建:

初始化如下:

init中增加了program的引用计数,然后把program中的attribute和uniform的map保存下来

2、glprogramcache

单例用来缓存shader

回到glprogramstate,默认的外部接口:

从cache中拿到缓存的shader

然后看保存的state中是否有,有则返回,无则加入到缓存state中

注意,programstate最后调用的是program的initWithByteArrays,并没有调用createWithByteArrays,但是和createWithByteArrays的流程一样,initWithByteArrays->link->updateuniform

上一篇下一篇

猜你喜欢

热点阅读