diff --git a/inc/hgl/graph/VertexArray.h b/inc/hgl/graph/VertexArray.h index 5b6c3c88..92759553 100644 --- a/inc/hgl/graph/VertexArray.h +++ b/inc/hgl/graph/VertexArray.h @@ -52,7 +52,7 @@ namespace hgl bool SetElementBuffer (VertexBufferBase *eb); ///<设置索引缓冲区数据 bool SetPositionBuffer (int shader_location,VertexBufferBase *vb); ///<设置位置缓冲区数据 - bool AddColorBuffer (int shader_location,VertexBufferBase *vb,PixelCompoment cf); ///<设置颜色缓冲区数据 + bool AddColorBuffer (int shader_location,VertexBufferBase *vb,PixelCompoment cf); ///<添加一个颜色缓冲区数据 int GetPositionCompoment()const{return position_compoment;} ///<取得位置数据成分数量 PixelCompoment GetColorCompoment ()const{return color_compoment;} ///<取得颜色数据成份格式 diff --git a/inc/hgl/graph/VertexBufferObject.h b/inc/hgl/graph/VertexBufferObject.h new file mode 100644 index 00000000..8b350dd5 --- /dev/null +++ b/inc/hgl/graph/VertexBufferObject.h @@ -0,0 +1,66 @@ +#ifndef HGL_GRAPH_VERTEX_BUFFER_OBJECT_INCLUDE +#define HGL_GRAPH_VERTEX_BUFFER_OBJECT_INCLUDE + +#include +#include +namespace hgl +{ + namespace graph + { + /** + * 顶点缓冲区对象,对应OpenGL的VBO管理 + */ + class VertexBufferObject + { + protected: + + GLuint buffer_index; + + GLenum buffer_type; + GLenum data_type; + uint data_bytes; + uint data_comp; + GLsizeiptr data_count; + GLsizeiptr buffer_bytes; + GLenum user_pattern; ///<数据存储区使用模式 + + public: + + VertexBufferObject(const GLuint index, + const GLenum &buf_type, + const uint &dt,const uint &dbytes,const uint &dcm, + const GLsizeiptr &count, + const GLenum &dsup) + { + buffer_index=index; + buffer_type=buf_type; + data_type=dt; + data_bytes=dbytes; + data_comp=dcm; + data_count=count; + buffer_bytes=data_bytes*data_comp*data_count; + user_pattern=dsup; + } + + virtual ~VertexBufferObject()=default; + + GLuint GetBuffer ()const{return buffer_index;} + GLsizeiptr GetBufferBytes ()const{return buffer_bytes;} + };//class VertexBufferObject + + /** + * 创建一个VBO对象 + * @param buf_type 缓冲区类型(GL_ARRAY_BUFFER,GL_ELEMENT_ARRAY_BUFFER等) + * @param data_type 单个数据类型 (GL_BYTE,GL_UNSIGNED_SHORT,GL_FLOAT等) + * @param data_bytes 单个数据字节数 (GL_BYTE为1,GL_UNSIGNED_SHORT为2GL_FLOAT为4等) + * @param data_comp 数据成员数 (1/2/3/4,如2D纹理坐标用2,3D坐标/法线用3) + * @param size 数据数量 + * @param dsup 数据存储区使用模式(GL_STATIC_DRAW,GL_DYNAMIC_DRAW等) + */ + VertexBufferObject *CreateVBO( const GLenum &buf_type, + const uint &data_type,const uint &data_bytes,const uint &data_comp, + const GLsizeiptr &size, + const GLenum &dsup); + }//namespace graph +}//namespace hgl +#endif//HGL_GRAPH_VERTEX_BUFFER_OBJECT_INCLUDE diff --git a/src/RenderDriver/CMakeLists.txt b/src/RenderDriver/CMakeLists.txt index cf4fdb1d..72d9546d 100644 --- a/src/RenderDriver/CMakeLists.txt +++ b/src/RenderDriver/CMakeLists.txt @@ -4,8 +4,7 @@ Shader.cpp VertexArray.cpp VertexBuffer.cpp - VertexBufferControlDSA.cpp - VertexBufferControlBind.cpp + VertexBufferObject.cpp TextureFormat.cpp Texture1D.cpp Texture1DDSA.cpp diff --git a/src/RenderDriver/VertexArray.cpp b/src/RenderDriver/VertexArray.cpp index 5ec194d0..d04700a5 100644 --- a/src/RenderDriver/VertexArray.cpp +++ b/src/RenderDriver/VertexArray.cpp @@ -27,7 +27,7 @@ namespace hgl vertex_buffer_list.PreMalloc(max_vertex_attrib); - vertex_compoment=-1; + position_compoment=-1; color_compoment=HGL_PC_NONE; element_buffer=nullptr; @@ -86,25 +86,25 @@ namespace hgl * @param shader_location 这个缓冲区对应的SHADER地址 * @param vb 数据缓冲区 */ - bool VertexArray::SetVertexBuffer(int shader_location, VertexBufferBase *vb) + bool VertexArray::SetPositionBuffer(int shader_location, VertexBufferBase *vb) { if(!vb)return(false); if(!AddVertexAttribBuffer(shader_location,vb)<0) return(false); - vertex_compoment=vb->GetComponent(); - vertex_buffer=vb; + position_compoment=vb->GetComponent(); + position_buffer=vb; return(true); } /** - * 设置一个颜色缓冲区 + * 添加一个颜色缓冲区 * @param shader_location 这个缓冲区对应的SHADER地址 * @param vb 数据缓冲区 * @param cf 颜色象素格式 */ - bool VertexArray::SetColorBuffer(int shader_location, VertexBufferBase *vb,PixelCompoment cf) + bool VertexArray::AddColorBuffer(int shader_location, VertexBufferBase *vb,PixelCompoment cf) { if(!vb)return(false); if(cf<=HGL_PC_NONE||cf>=HGL_PC_END)return(false); @@ -127,8 +127,8 @@ namespace hgl if(element_buffer) return element_buffer->GetCount(); - if(vertex_buffer) - return vertex_buffer->GetCount(); + if(position_buffer) + return position_buffer->GetCount(); return(-1); } @@ -140,8 +140,8 @@ namespace hgl if (element_buffer) glDrawElements(primitive, element_buffer->GetCount(), element_buffer->GetDataType(), nullptr); else - if(vertex_buffer) - glDrawArrays(primitive,0,vertex_buffer->GetCount()); + if(position_buffer) + glDrawArrays(primitive,0,position_buffer->GetCount()); else return(false); diff --git a/src/RenderDriver/VertexBufferObject.cpp b/src/RenderDriver/VertexBufferObject.cpp new file mode 100644 index 00000000..d16a98ac --- /dev/null +++ b/src/RenderDriver/VertexBufferObject.cpp @@ -0,0 +1,42 @@ +#include + +namespace hgl +{ + namespace graph + { + class VertexBufferObjectDSA:public VertexBufferObject + { + public: + + using VertexBufferObject::VertexBufferObject; + ~VertexBufferObjectDSA() + { + glDeleteBuffers(1,&buffer_index); + } + + void Set(GLsizei size,void *data) + { + glNamedBufferData(buffer_index,size,data,user_pattern); + } + + void Change(GLintptr start,GLsizei size,void *data) + { + glNamedBufferSubData(buffer_index,start,size,data); + } + };//class VertexBufferControlDSA + + VertexBufferObject *CreateVertexBufferObjectDSA(uint type) + { + uint index; + + glCreateBuffers(1,&index); + } + + VertexBufferObject *CreateVBO(const GLenum &buf_type, + const uint &data_type,const uint &data_bytes,const uint &data_comp, + const GLsizeiptr &size, + const GLenum &dsup) + { + } + }//namespace graph +}//namespace hgl