From 6511c6615bcc458b229626f7e08743269bda37fc Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 6 Dec 2018 21:17:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A1=AC=E4=BB=B6=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E9=A1=B6=E7=82=B9=E5=B1=9E=E6=80=A7=E5=8F=96=E5=80=BC?= =?UTF-8?q?=E5=92=8C=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/graph/VertexArray.h | 5 ++++- src/RenderDriver/VertexArray.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/inc/hgl/graph/VertexArray.h b/inc/hgl/graph/VertexArray.h index 3d30d427..dd70d6b4 100644 --- a/inc/hgl/graph/VertexArray.h +++ b/inc/hgl/graph/VertexArray.h @@ -15,7 +15,7 @@ namespace hgl { protected: - int vao; + GLuint vao; uint primitive; ///<绘制的图元类型 @@ -40,6 +40,8 @@ namespace hgl VertexArray(uint prim,uint max_vertex_attrib); ~VertexArray(); + static int GetMaxVertexAttrib(); + uint GetPrimitive ()const{return primitive;} ///<取得要绘制的图元类型 public: //通用顶点缓冲区设置 @@ -61,6 +63,7 @@ namespace hgl public: int GetDrawCount (); ///<取得可绘制的数据总数量 + bool Draw(); ///<绘制 };//class VertexArray }//namespace graph }//namespace hgl diff --git a/src/RenderDriver/VertexArray.cpp b/src/RenderDriver/VertexArray.cpp index 4f17615a..8e8b23d5 100644 --- a/src/RenderDriver/VertexArray.cpp +++ b/src/RenderDriver/VertexArray.cpp @@ -5,8 +5,24 @@ namespace hgl { namespace graph { + namespace + { + static int HGL_MAX_VERTEX_ATTRIBS=0; + } + + int VertexArray::GetMaxVertexAttrib() + { + if(HGL_MAX_VERTEX_ATTRIBS<=0) + glGetIntegerv(GL_MAX_VERTEX_ATTRIBS,&HGL_MAX_VERTEX_ATTRIBS); + + return HGL_MAX_VERTEX_ATTRIBS; + } + VertexArray::VertexArray(uint prim,uint max_vertex_attrib) { + if(max_vertex_attrib>GetMaxVertexAttrib()) + max_vertex_attrib=HGL_MAX_VERTEX_ATTRIBS; + primitive=prim; vertex_buffer_list.PreMalloc(max_vertex_attrib); @@ -90,5 +106,18 @@ namespace hgl return(-1); } + + bool VertexArray::Draw() + { + if(element_buffer) + glDrawElements(primitive,0,element_buffer->GetCount(),element_buffer->GetDataType(),nullptr); + else + if(vertex_buffer) + glDrawArrays(primitive,0,vertex_buffer->GetCount()); + else + return(false); + + return(true); + } }//namespace graph }//namespace hgl