From 82ea3fbcbd042e14e8fb83400cee76a386a9cf91 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 20 Mar 2019 21:56:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BB=BA=E7=AB=8B=E7=8B=AC=E7=AB=8B=E7=9A=84Bu?= =?UTF-8?q?fferObject=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=BB=BA=E7=AB=8B?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E7=8B=AC=E7=AB=8B=E7=9A=84=E7=BC=93=E5=86=B2?= =?UTF-8?q?=E5=8C=BA=E7=AE=A1=E7=90=86=E7=B1=BB=EF=BC=8C=E6=89=80=E6=9C=89?= =?UTF-8?q?=E4=B8=8D=E7=AE=A1=E6=98=AFVBO,=E8=BF=98=E6=98=AFUBO,SSBO,TBO?= =?UTF-8?q?=EF=BC=8C=E5=85=A8=E9=83=A8=E5=85=B1=E7=94=A8=E8=BF=99=E4=B8=80?= =?UTF-8?q?=E5=A5=97=E4=BB=A3=E7=A0=81=E3=80=82=E5=8F=A6=E9=9C=80=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E5=B0=86Object=E4=B8=8Ebuffer=20manage=E5=88=86?= =?UTF-8?q?=E7=A6=BB=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/graph/BufferObject.h | 76 ++++++++++++++++++++++++++++++ inc/hgl/graph/VertexBufferObject.h | 18 +------ 2 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 inc/hgl/graph/BufferObject.h diff --git a/inc/hgl/graph/BufferObject.h b/inc/hgl/graph/BufferObject.h new file mode 100644 index 00000000..a4c66da2 --- /dev/null +++ b/inc/hgl/graph/BufferObject.h @@ -0,0 +1,76 @@ +#ifndef HGL_GRAPH_BUFFER_OBJECT_INCLUDE +#define HGL_GRAPH_BUFFER_OBJECT_INCLUDE + +#include +#include +namespace hgl +{ + namespace graph + { + /** + * 显存数据缓冲区对象
+ * 负责对象与API的交接 + */ + class BufferObject + { + GLuint buffer_index; ///<缓冲区索引 + GLenum buffer_type; ///<缓冲区类型(GL_ARRAY_BUFFER,GL_ELEMENT_ARRAY_BUFFER等) + GLenum user_pattern; ///<数据存储区使用模式(GL_STATIC_DRAW,GL_DYNAMIC_DRAW等) + + GLsizeiptr total_bytes; ///<数据总字节数 + void *local_data,*local_data_end; ///<本地数据内存指针 + bool self_alloc; ///<是否自身分配 + + protected: + + BufferObject(GLenum type) + { + buffer_index= + buffer_type=type; + } + + BufferObject(GLenum type,GLenum up) + { + buffer_type=type; + user_pattern=up; + } + + BufferObject(GLuint index,GLenum type,GLenum up) + { + buffer_index=index; + buffer_type=type; + user_pattern=up; + } + + BufferObject(GLenum type,GLenum up,void *data,GLsizeiptr size,bool data_self_alloc) + { + buffer_index=index; + buffer_type=type; + user_pattern=up; + + total_bytes=size; + + local_data=data; + local_data_end=((char *)data)+size; + + self_alloc=data_self_alloc; + } + + virtual ~BufferObject() + { + if(self_alloc) + if(local_data)delete[] local_data; + } + + GLuint GetBuffer ()const {return buffer_index;} ///<取得OpenGL缓冲区 + GLenum GetBufferType ()const {return buffer_type;} ///<取得缓冲区类型 + GLenum GetUserPattern ()const {return user_pattern;} ///<取得缓冲区使用方法 + GLsizeiptr GetTotalBytes ()const {return total_bytes;} ///<取得数据总字节数 + + void * GetData () {return data;} ///<取得数据指针 + void * GetData (const uint pos) {return ((char *)data)+data_bytes*pos;} ///<取得数据指针 + };//class BufferObject + + }//namespace graph +}//namespace hgl +#endif//HGL_GRAPH_BUFFER_OBJECT_INCLUDE diff --git a/inc/hgl/graph/VertexBufferObject.h b/inc/hgl/graph/VertexBufferObject.h index 3e5d9435..b5793884 100644 --- a/inc/hgl/graph/VertexBufferObject.h +++ b/inc/hgl/graph/VertexBufferObject.h @@ -1,8 +1,7 @@ #ifndef HGL_GRAPH_VERTEX_BUFFER_OBJECT_INCLUDE #define HGL_GRAPH_VERTEX_BUFFER_OBJECT_INCLUDE -#include -#include +#include namespace hgl { namespace graph @@ -10,17 +9,10 @@ namespace hgl /** * 顶点缓冲区对象,对应OpenGL的VBO管理 */ - class VertexBufferObject + class VertexBufferObject:public BufferObject { protected: - GLuint buffer_index; - - void * data; - void * data_end; - - GLenum buffer_type; ///<缓冲区类型(GL_ARRAY_BUFFER,GL_ELEMENT_ARRAY_BUFFER等) - GLenum user_pattern; ///<数据存储区使用模式(GL_STATIC_DRAW,GL_DYNAMIC_DRAW等) GLenum data_type; ///<单个数据类型 (GL_BYTE,GL_UNSIGNED_SHORT,GL_FLOAT等) uint data_bytes; ///<单个数据字节数 (GL_BYTE为1,GL_UNSIGNED_SHORT为2GL_FLOAT为4等) @@ -53,9 +45,6 @@ namespace hgl public: - GLuint GetBuffer ()const {return buffer_index;} ///<取得OpenGL缓冲区 - GLenum GetBufferType ()const {return buffer_type;} ///<取得缓冲区类型 - GLenum GetUserPattern ()const {return user_pattern;} ///<取得缓冲区使用方法 GLenum GetDataType ()const {return data_type;} ///<取得数据类型 uint GetComponent ()const {return data_comp;} ///<取数每一组数据中的数据数量 @@ -63,9 +52,6 @@ namespace hgl GLsizeiptr GetCount ()const {return data_count;} ///<取得数据数量 - GLsizeiptr GetTotalBytes ()const {return total_bytes;} ///<取得数据总字节数 - void * GetData () {return data;} ///<取得数据指针 - void * GetData (const uint pos) {return ((char *)data)+data_bytes*pos;} ///<取得数据指针 public: