#1 CCPrimetive 因为CCPrimtiveCommand里有用到这个就先分析下这个吧 按照字面的意思应该是由一系列顶点属性和带有顺序的顶点索引的图元面片类

/**Primitive can support sending points, lines and triangles to glpipeline, which is an abstractionof primitive data.*/
class CC_DLL Primitive : public Ref
{
public:/**Create an instance of primitive.@param verts VertexData used in the primitive.@param indices Optional index data.@param type The type (Points, Lines, Triangles) used.*/static Primitive* create(VertexData* verts, IndexBuffer* indices, int type);/**Get the vertexData.*/const VertexData* getVertexData() const;/**Get the optional index data, will return null if index data is not used.*/const IndexBuffer* getIndexData() const;/**Get the primitive type.*/int getType() const { return _type; }/**called by rendering framework, will send the data to GLPipeline.*/void draw();/**Get the start index of primitive.*/int getStart() const { return _start; }/**Get the number of vertices or indices used for drawing.*/int getCount() const { return _count; }/**Setter for the start index.*/void setStart(int start);/**Setter for the count. */void setCount(int count);protected:Primitive();virtual ~Primitive();bool init(VertexData* verts, IndexBuffer* indices, int type);protected:VertexData* _verts;IndexBuffer* _indices;int _start;int _count;int _type;
};
复制代码

##1.1

void Primitive::draw()
{/*void VertexData::use()
{uint32_t flags(0);for(auto& element : _vertexStreams){flags = flags | (1 << element.second._stream._semantic);}GL::enableVertexAttribs(flags);int lastVBO = -1;for(auto& element : _vertexStreams){//glEnableVertexAttribArray((GLint)element.second._stream._semantic);auto vertexStreamAttrib = element.second._stream;auto vertexBuffer = element.second._buffer;// don't call glBindBuffer() if not needed. Expensive operation.int vbo = vertexBuffer->getVBO();if (vbo != lastVBO) {glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer->getVBO());lastVBO = vbo;}glVertexAttribPointer(GLint(vertexStreamAttrib._semantic),vertexStreamAttrib._size,vertexStreamAttrib._type,vertexStreamAttrib._normalize,vertexBuffer->getSizePerVertex(),(GLvoid*)((long)vertexStreamAttrib._offset));}
}*/if(_verts){_verts->use();if(_indices!= nullptr){GLenum type = (_indices->getType() == IndexBuffer::IndexType::INDEX_TYPE_SHORT_16) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indices->getVBO());size_t offset = _start * _indices->getSizePerIndex();glDrawElements((GLenum)_type, _count, type, (GLvoid*)offset);}else{glDrawArrays((GLenum)_type, _start, _count);}glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);glBindBuffer(GL_ARRAY_BUFFER, 0);}
}
复制代码

#2 CCPrimtiveCommand

class CC_DLL PrimitiveCommand : public RenderCommand
{
public:/**@{Constructor and Destructor.*/PrimitiveCommand();~PrimitiveCommand();/**@}*//** Initializes the command.@param globalOrder GlobalZOrder of the command.@param textureID The openGL handle of the used texture.@param glProgramState The specified glProgram and its uniform.@param blendType Blend function for the command.@param primitive Rendered primitive for the command.@param mv ModelView matrix for the command.@param flags to indicate that the command is using 3D rendering or not.*/void init(float globalOrder, GLuint textureID, GLProgramState* glProgramState, BlendFunc blendType, Primitive* primitive, const Mat4& mv, uint32_t flags);CC_DEPRECATED_ATTRIBUTE void init(float globalOrder, GLuint textureID, GLProgramState* glProgramState, BlendFunc blendType, Primitive* primitive,const Mat4& mv);/**Get the generated material ID.*/inline uint32_t getMaterialID() const { return _materialID; }/**Get the texture ID used for drawing.*/inline GLuint getTextureID() const { return _textureID; }/**Get the glprogramstate used for drawing.*/inline GLProgramState* getGLProgramState() const { return _glProgramState; }/**Get the blend function for drawing.*/inline BlendFunc getBlendType() const { return _blendType; }/**Get the modelview matrix when draw the primitive.*/inline const Mat4& getModelView() const { return _mv; }/**Execute and draw the command, called by renderer.*/void execute() const;
protected:uint32_t _materialID;GLuint _textureID;GLProgramState* _glProgramState;BlendFunc _blendType;Primitive* _primitive;Mat4 _mv;
};
复制代码

##2.1 execute函数 每个非Triangle跟quad 类型的command应该都会执行这个execute这个函数 哟哟哟 用到了 Primtive 的 draw() 函数

void PrimitiveCommand::execute() const
{//Set textureGL::bindTexture2D(_textureID);//set blend modeGL::blendFunc(_blendType.src, _blendType.dst);_glProgramState->apply(_mv);_primitive->draw();CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_primitive->getCount());
}
复制代码

实际上相当于还是用的Primitive的draw函数

转载于:https://juejin.im/post/5a30dd405188254dd93663ff

Cocos2dx源码记录(11) CCPrimtiveCommand,CCPrimetive相关推荐

  1. Cocos2dx源码记录(1) CCGLProgram

    前言: 这个系列是我自己在看cocos2dx源码时记录的一些比较重要的数据结构跟方法中间可能穿插些opengl的知识. 每个介绍的类之间没有固定引用顺序,仅作为个人的记录,可能会有点乱(其实主要是为了 ...

  2. Cocos2dx源码记录(6) CCTrianglesCommand

    CCQuadCommand类继承自CCTrianglesCommand类, 因为一个4个点的封闭图形由两个三角形组成.下面先介绍父类CCTrianglesCommand 然后再简单地介绍下CCQuad ...

  3. Gem5模拟器,popnet模拟器源码记录(十五)

    在使用王小航老师课题组开源的Gem5代码进行大规模的Chiplet并行仿真时,有个关键问题是:为什么原来的gem5不可以进行大规模仿真?为什么精度不够?也是论文提出的背景: (20条消息) 傻白探索C ...

  4. Eclipse导入Zookeeper源码Version2017.11.3

    将Zookeeper源码导入Eclipse, Zookeeper源码需要使用ant构建后才能导入Eclipse, 和Solr的源码一样也是使用ant构建的, 大部分可以参考Eclipse导入Solr源 ...

  5. 学习vue-router源码记录-1

    因为本人开发中使用的是VUE技术栈,最近也是开始源码的学习,以此记录个人理解,若行文有误,请多多指教. 1.new Router和install 在vue中我们使用vue-router时需要先进行ne ...

  6. Ubuntu16.04编译android6.0.1源码记录

    目录 目录 一.安装环境 二.下载源码 1.下载repo 2.初始化repo 3.同步源代码 关于驱动 三.编译源码 四.导入源码到AS 五.刷入真机 六.修改源码 总结: 3.同步源代码 关于驱动 ...

  7. 【GAT】图注意力网络 - 简单的源码记录

    由于和GCN代码比较相似,所以部分内容从GCN那篇博客中截取. 1 - cora数据集 GNN常用数据集之Cora数据集 2 - 源码含义记录 首先我们来整体看一下代码的组成 截图中的这一大坨为命令行 ...

  8. 安卓贴图源码---记录旋转后位置..类似in/百度魔图

    效果如图: 类似in,百度魔图,的贴图功能  核心的地方:单/多点 旋转缩放后记录各个顶点小图标位置 引用这里 http://blog.csdn.net/xiaanming/article/detai ...

  9. repo下载安卓源码记录

    文章目录 前言和repo简介 源码下载 准备repo 初始化 代码同步 问题总结 网络错误 找不到版本 个人小结 前言和repo简介 众所周知,当前世界上最大的同性交友网站GitHub,里面几乎收藏了 ...

最新文章

  1. 修改value_Java 反射修改String引发的思考?
  2. 成绩查看_托福网考免费寄送成绩单,掌握这些知识能帮你省不少钱!
  3. cmd输入net start mysql提示:服务名无效(解决方案笔记)
  4. 面试必备TCP三次握手
  5. Mysql更新数据库数据sql_一条更新SQL在MySQL数据库中是如何执行的
  6. python第6天作业
  7. Analysis-ik 中文分词安装
  8. JMeter java.net.SocketException:Operationnotsupported:connect解决方案
  9. 例4.2 又一版A+B - 九度教程第43题(进制转换)
  10. 前端开源项目周报0221
  11. 科学研究设计一:什么是科学
  12. 如何把多个文件夹里的文件提取出来?
  13. 坚果pro2刷MIUI10
  14. 资源、角色、用户、岗位的关系(工作中用到的)
  15. 阿里云安全ACP认证试验之阿里云Web应用防火墙接入体验
  16. 计算机网线怎么连接另一台电脑,求解一台电脑怎么连接另一台电脑上网
  17. 达芬奇密码 第五十九章
  18. 计算机应用月什么,计算机应用月考试卷
  19. html 3d坐标,3d transform的坐标空间及位置_html/css_WEB-ITnose
  20. 数据嗨客 | 第1期

热门文章

  1. java as uuid_java UUID 源码学习
  2. js动态添加meta标签
  3. flutter项目内配置代理
  4. CNN结构:序列预测复合DNN结构-AcGANs、 ENN误差编码网络
  5. C++11:using 的各种作用
  6. [动态代理三部曲:上] - 动态代理是如何坑掉了我4500块钱
  7. 通过js 判断当前应用是什么浏览器【借鉴转载】
  8. ASP.NET Web实时消息后台服务器推送技术---GoEasy
  9. 思维题 UVA 10881 Piotr's Ants
  10. linux 下创建并动态加载.so 文件