日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Cocos2dx源码记录(11) CCPrimtiveCommand,CCPrimetive

發布時間:2023/12/20 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Cocos2dx源码记录(11) CCPrimtiveCommand,CCPrimetive 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。