建立独立的BufferObject,用于建立统一独立的缓冲区管理类,所有不管是VBO,还是UBO,SSBO,TBO,全部共用这一套代码。另需设计将Object与buffer manage分离。

This commit is contained in:
hyzboy 2019-03-20 21:56:48 +08:00
parent 8d2a4b33f0
commit 82ea3fbcbd
2 changed files with 78 additions and 16 deletions

View File

@ -0,0 +1,76 @@
#ifndef HGL_GRAPH_BUFFER_OBJECT_INCLUDE
#define HGL_GRAPH_BUFFER_OBJECT_INCLUDE
#include<GLEWCore/glew.h>
#include<hgl/type/DataType.h>
namespace hgl
{
namespace graph
{
/**
* <br>
* 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

View File

@ -1,8 +1,7 @@
#ifndef HGL_GRAPH_VERTEX_BUFFER_OBJECT_INCLUDE #ifndef HGL_GRAPH_VERTEX_BUFFER_OBJECT_INCLUDE
#define HGL_GRAPH_VERTEX_BUFFER_OBJECT_INCLUDE #define HGL_GRAPH_VERTEX_BUFFER_OBJECT_INCLUDE
#include<GLEWCore/glew.h> #include<graph/BufferObject.h>
#include<hgl/type/DataType.h>
namespace hgl namespace hgl
{ {
namespace graph namespace graph
@ -10,17 +9,10 @@ namespace hgl
/** /**
* OpenGL的VBO管理 * OpenGL的VBO管理
*/ */
class VertexBufferObject class VertexBufferObject:public BufferObject
{ {
protected: 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等) GLenum data_type; ///<单个数据类型 (GL_BYTE,GL_UNSIGNED_SHORT,GL_FLOAT等)
uint data_bytes; ///<单个数据字节数 (GL_BYTE为1,GL_UNSIGNED_SHORT为2GL_FLOAT为4等) uint data_bytes; ///<单个数据字节数 (GL_BYTE为1,GL_UNSIGNED_SHORT为2GL_FLOAT为4等)
@ -53,9 +45,6 @@ namespace hgl
public: 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;} ///<取得数据类型 GLenum GetDataType ()const {return data_type;} ///<取得数据类型
uint GetComponent ()const {return data_comp;} ///<取数每一组数据中的数据数量 uint GetComponent ()const {return data_comp;} ///<取数每一组数据中的数据数量
@ -63,9 +52,6 @@ namespace hgl
GLsizeiptr GetCount ()const {return data_count;} ///<取得数据数量 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: public: