2019-03-23 02:06:06 +08:00
|
|
|
|
#ifndef HGL_GRAPH_BUFFER_DATA_INCLUDE
|
|
|
|
|
#define HGL_GRAPH_BUFFER_DATA_INCLUDE
|
|
|
|
|
|
|
|
|
|
#include<GLEWCore/glew.h>
|
|
|
|
|
#include<hgl/type/DataType.h>
|
|
|
|
|
namespace hgl
|
|
|
|
|
{
|
|
|
|
|
namespace graph
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* 缓冲区数据管理类
|
|
|
|
|
*/
|
|
|
|
|
class BufferData
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
|
2019-03-27 14:09:01 +08:00
|
|
|
|
GLsizeiptr total_bytes; ///<数据总字节数
|
|
|
|
|
|
|
|
|
|
char * buffer_data;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
friend BufferData *CreateBufferData(void *data,const GLsizeiptr &length);
|
|
|
|
|
|
|
|
|
|
BufferData(char *data,const GLsizeiptr &length)
|
|
|
|
|
{
|
|
|
|
|
total_bytes =length;
|
|
|
|
|
buffer_data =data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
virtual ~BufferData()=default;
|
|
|
|
|
|
|
|
|
|
GLsizeiptr GetTotalBytes ()const {return total_bytes;} ///<取得数据总字节数
|
|
|
|
|
void * GetData ()const {return buffer_data;} ///<取得数据指针
|
|
|
|
|
};//class BufferData
|
|
|
|
|
|
|
|
|
|
BufferData *CreateBufferData(const GLsizeiptr &length);
|
|
|
|
|
BufferData *CreateBufferData(void *data,const GLsizeiptr &length);
|
|
|
|
|
|
|
|
|
|
class VertexBufferData:public BufferData
|
|
|
|
|
{
|
2019-03-23 02:06:06 +08:00
|
|
|
|
GLenum data_type; ///<单个数据类型 (GL_BYTE,GL_UNSIGNED_SHORT,GL_FLOAT等)
|
|
|
|
|
uint data_bytes; ///<单个数据字节数 (GL_BYTE为1,GL_UNSIGNED_SHORT为2,GL_FLOAT为4等)
|
|
|
|
|
uint data_comp; ///<数据成员数 (1/2/3/4,如2D纹理坐标用2,3D坐标/法线用3)
|
|
|
|
|
|
|
|
|
|
uint data_stride; ///<每组数据字节数
|
|
|
|
|
|
|
|
|
|
GLsizeiptr data_count; ///<数据数量
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
2019-03-27 14:09:01 +08:00
|
|
|
|
friend VertexBufferData *CreateVertexBufferData(void *data,const GLenum &dt,const uint &dbytes,const uint &dcm,const GLsizeiptr &count);
|
2019-03-23 02:06:06 +08:00
|
|
|
|
|
2019-03-27 14:09:01 +08:00
|
|
|
|
VertexBufferData(const GLenum &dt,const uint &dbytes,const uint &dcm,const GLsizeiptr &count,char *data):BufferData(data,dbytes*dcm*count)
|
2019-03-23 02:06:06 +08:00
|
|
|
|
{
|
2019-03-27 14:09:01 +08:00
|
|
|
|
data_type=dt;
|
|
|
|
|
data_bytes=dbytes;
|
|
|
|
|
data_comp=dcm;
|
2019-03-23 02:06:06 +08:00
|
|
|
|
|
2019-03-27 14:09:01 +08:00
|
|
|
|
data_stride=data_comp*data_bytes;
|
2019-03-23 02:06:06 +08:00
|
|
|
|
|
2019-03-27 14:09:01 +08:00
|
|
|
|
data_count=count;
|
2019-03-23 02:06:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2019-03-27 14:09:01 +08:00
|
|
|
|
virtual ~VertexBufferData()=default;
|
2019-03-23 02:06:06 +08:00
|
|
|
|
|
2019-03-27 14:09:01 +08:00
|
|
|
|
GLenum GetDataType()const { return data_type; } ///<取得数据类型
|
|
|
|
|
uint GetComponent()const { return data_comp; } ///<取数每一组数据中的数据数量
|
|
|
|
|
uint GetStride()const { return data_stride; } ///<取得每一组数据字节数
|
2019-03-23 02:06:06 +08:00
|
|
|
|
|
2019-03-27 14:09:01 +08:00
|
|
|
|
GLsizeiptr GetCount()const { return data_count; } ///<取得数据数量
|
|
|
|
|
GLsizeiptr GetTotalBytes()const { return total_bytes; } ///<取得数据总字节数
|
|
|
|
|
};
|
2019-03-23 02:06:06 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-03-27 14:09:01 +08:00
|
|
|
|
* 创建一个顶点数据缓冲区<br>
|
2019-03-23 02:06:06 +08:00
|
|
|
|
* 这种方式创建的缓冲区,它会自行分配内存,最终释放
|
|
|
|
|
* @param dt 单个数据类型 (GL_BYTE,GL_UNSIGNED_SHORT,GL_FLOAT等)
|
|
|
|
|
* @param dbytes 单个数据字节数 (GL_BYTE为1,GL_UNSIGNED_SHORT为2,GL_FLOAT为4等)
|
|
|
|
|
* @param dcm 数据成员数 (1/2/3/4,如2D纹理坐标用2,3D坐标/法线用3)
|
|
|
|
|
* @param count 数据数量
|
|
|
|
|
*/
|
2019-03-27 14:09:01 +08:00
|
|
|
|
VertexBufferData *CreateVertexBufferData(const GLenum &dt,const uint &dbytes,const uint &dcm,const GLsizeiptr &count);
|
2019-03-23 02:06:06 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-03-27 14:09:01 +08:00
|
|
|
|
* 创建一个顶点数据缓冲区
|
2019-03-23 02:06:06 +08:00
|
|
|
|
* @param data 数据指针
|
|
|
|
|
* @param dt 单个数据类型 (GL_BYTE,GL_UNSIGNED_SHORT,GL_FLOAT等)
|
|
|
|
|
* @param dbytes 单个数据字节数 (GL_BYTE为1,GL_UNSIGNED_SHORT为2,GL_FLOAT为4等)
|
|
|
|
|
* @param dcm 数据成员数 (1/2/3/4,如2D纹理坐标用2,3D坐标/法线用3)
|
|
|
|
|
* @param count 数据数量
|
|
|
|
|
*/
|
2019-03-27 14:09:01 +08:00
|
|
|
|
VertexBufferData *CreateVertexBufferData(void *data,const GLenum &dt,const uint &dbytes,const uint &dcm,const GLsizeiptr &count);
|
2019-03-23 02:06:06 +08:00
|
|
|
|
}//namespace graph
|
|
|
|
|
}//namespace hgl
|
|
|
|
|
#endif//HGL_GRAPH_BUFFER_DATA_INCLUDE
|