VAO中vertex_改名为position_,SetVertexBuffer改名为SetPositionBuffer,以避开名词理解错误

This commit is contained in:
hyzboy 2019-03-18 14:28:34 +08:00
parent 4e167b5353
commit 0663cd8de1
5 changed files with 120 additions and 13 deletions

View File

@ -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;} ///<取得颜色数据成份格式

View File

@ -0,0 +1,66 @@
#ifndef HGL_GRAPH_VERTEX_BUFFER_OBJECT_INCLUDE
#define HGL_GRAPH_VERTEX_BUFFER_OBJECT_INCLUDE
#include<GLEWCore/glew.h>
#include<hgl/type/DataType.h>
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/42D纹理坐标用23D坐标/线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

View File

@ -4,8 +4,7 @@
Shader.cpp
VertexArray.cpp
VertexBuffer.cpp
VertexBufferControlDSA.cpp
VertexBufferControlBind.cpp
VertexBufferObject.cpp
TextureFormat.cpp
Texture1D.cpp
Texture1DDSA.cpp

View File

@ -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);

View File

@ -0,0 +1,42 @@
#include<hgl/graph/VertexBufferObject.h>
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