From 4e167b53532ec4003c90a8c2471cafdc9ca8ebde Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 16 Mar 2019 15:08:03 +0800 Subject: [PATCH] =?UTF-8?q?VBO,VAO=E7=AD=89=E5=85=A8=E9=83=A8=E5=B0=86?= =?UTF-8?q?=E6=9C=AC=E4=BD=93=E5=92=8C=E6=95=B0=E6=8D=AE=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=99=A8=E5=88=86=E7=A6=BB=EF=BC=8C=E5=BB=BA=E7=AB=8B=E8=B5=B7?= =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E7=9A=84Maker=E7=B1=BB=E3=80=82=20=E4=BB=A5?= =?UTF-8?q?=E6=96=B9=E4=BE=BF=E6=95=B0=E6=8D=AE=E5=AF=B9=E8=B1=A1=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=9C=89=E4=B8=8D=E5=90=8C=E7=9A=84=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E7=B1=BB=EF=BC=8C=E6=88=96=E6=98=AF=E6=9C=89=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E7=9A=84=E6=93=8D=E4=BD=9C=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/graph/VertexArray.h | 25 ++++++++++++--------- inc/hgl/graph/VertexBuffer.h | 38 ++++++++++++++++++++++++-------- inc/hgl/graph/VertexBufferBase.h | 3 +++ 3 files changed, 46 insertions(+), 20 deletions(-) diff --git a/inc/hgl/graph/VertexArray.h b/inc/hgl/graph/VertexArray.h index 61ca58e8..5b6c3c88 100644 --- a/inc/hgl/graph/VertexArray.h +++ b/inc/hgl/graph/VertexArray.h @@ -21,11 +21,13 @@ namespace hgl ObjectList vertex_buffer_list; ///<顶点数据缓冲区 - int vertex_compoment; ///<顶点属性格式 - PixelCompoment color_compoment; ///<颜色属性格式 - VertexBufferBase *element_buffer; - VertexBufferBase *vertex_buffer; + + VertexBufferBase *position_buffer; + int position_compoment; ///<位置属性格式 + + List> color_buffer; + PixelCompoment color_compoment; ///<颜色属性格式 VertexBufferBase *color_buffer; public: @@ -48,11 +50,12 @@ namespace hgl public: //特殊缓冲区独立设置函数 bool SetElementBuffer (VertexBufferBase *eb); ///<设置索引缓冲区数据 - bool SetVertexBuffer (int shader_location,VertexBufferBase *vb); ///<设置顶点缓冲区数据 - bool SetColorBuffer (int shader_location,VertexBufferBase *vb,PixelCompoment cf); ///<设置颜色缓冲区数据 + bool SetPositionBuffer (int shader_location,VertexBufferBase *vb); ///<设置位置缓冲区数据 - int GetVertexCompoment ()const{return vertex_compoment;} ///<取得顶点数据成分数量 - PixelCompoment GetColorCompoment ()const{return color_compoment;} ///<取得顶点颜色格式 + bool AddColorBuffer (int shader_location,VertexBufferBase *vb,PixelCompoment cf); ///<设置颜色缓冲区数据 + + int GetPositionCompoment()const{return position_compoment;} ///<取得位置数据成分数量 + PixelCompoment GetColorCompoment ()const{return color_compoment;} ///<取得颜色数据成份格式 public: @@ -60,9 +63,9 @@ namespace hgl bool Draw(); ///<绘制 };//class VertexArray - 新设计内容,如碰到此处编译失败请在GIT上退回到上一版本 - 1.ColorBuffer可能存在多个,所以上面的SetColorBuffer可能要考虑多个的情况 - 2.将VertexArray类拆分成独立的VAO类和VAOCreater类,所有创建VAO相关的全部放到VAOCreater类中,创建完删除自身并返回VAO对象 + //新设计内容,如碰到此处编译失败请在GIT上退回到上一版本 + //1.ColorBuffer可能存在多个,所以上面的SetColorBuffer可能要考虑多个的情况 + //2.将VertexArray类拆分成独立的VAO类和VAOCreater类,所有创建VAO相关的全部放到VAOCreater类中,创建完删除自身并返回VAO对象 }//namespace graph }//namespace hgl #endif//HGL_GRAPH_VERTEX_ARRAY_INCLUDE diff --git a/inc/hgl/graph/VertexBuffer.h b/inc/hgl/graph/VertexBuffer.h index 1fc342f6..4fd842bc 100644 --- a/inc/hgl/graph/VertexBuffer.h +++ b/inc/hgl/graph/VertexBuffer.h @@ -886,7 +886,23 @@ namespace hgl using EB16=ElementBuffer; using EB32=ElementBuffer; -#define USING_VB1234(type,gl_type,short_name) using VB1##short_name=VertexBuffer1; \ + template + class ColorBufferBase:public BASE + { + protected: + + PixelCompoment color_compoment; + + public: + + const PixelCompoment GetColorCompoment()const{return color_compoment;} + + public: + + ColorBuferBase(const PixelCompoment &pc):color_compoment(pc){} + };// + +#define USING_VB1234(type,gl_type,short_name) using VB1##short_name=VertexBuffer1;using CB1##short_name=ColorBufferBase; \ using VB2##short_name=VertexBuffer2; \ using VB3##short_name=VertexBuffer3; \ using VB4##short_name=VertexBuffer4; @@ -898,15 +914,19 @@ namespace hgl USING_VB1234(int32, GL_INT, i32) USING_VB1234(int32, GL_INT, i) - USING_VB1234(int8, GL_UNSIGNED_BYTE, u8) - USING_VB1234(int8, GL_UNSIGNED_BYTE, ub) - USING_VB1234(int16, GL_UNSIGNED_SHORT, u16) - USING_VB1234(int16, GL_UNSIGNED_SHORT, us) - USING_VB1234(int32, GL_UNSIGNED_INT, u32) - USING_VB1234(int32, GL_UNSIGNED_INT, ui) + USING_VB1234(uint8, GL_UNSIGNED_BYTE, u8) + USING_VB1234(uint8, GL_UNSIGNED_BYTE, ub) + USING_VB1234(uint16,GL_UNSIGNED_SHORT, u16) + USING_VB1234(uint16,GL_UNSIGNED_SHORT, us) + USING_VB1234(uint32,GL_UNSIGNED_INT, u32) + USING_VB1234(uint32,GL_UNSIGNED_INT, ui) - USING_VB1234(float, GL_FLOAT, f) - USING_VB1234(double,GL_DOUBLE, d) + USING_VB1234(uint16,GL_HALF_FLOAT, hf) + USING_VB1234(uint16,GL_HALF_FLOAT, f16) + USING_VB1234(float, GL_FLOAT, f) + USING_VB1234(float, GL_FLOAT, f32) + USING_VB1234(double,GL_DOUBLE, d) + USING_VB1234(double,GL_DOUBLE, f64) #undef USING_VB1234 diff --git a/inc/hgl/graph/VertexBufferBase.h b/inc/hgl/graph/VertexBufferBase.h index 887b7579..c7f4a2f5 100644 --- a/inc/hgl/graph/VertexBufferBase.h +++ b/inc/hgl/graph/VertexBufferBase.h @@ -66,6 +66,9 @@ namespace hgl //void BindVertexBuffer(); int GetBufferIndex()const; ///<取得缓冲区索引 };//class VertexBufferBase + + using VBB=VertexBufferBase; + using VBBPointer=VBB *; }//namespace graph }//namespace hgl #endif//HGL_VERTEX_BUFFER_BASE_INCLUDE