VAO中vertex_改名为position_,SetVertexBuffer改名为SetPositionBuffer,以避开名词理解错误
This commit is contained in:
parent
4e167b5353
commit
0663cd8de1
@ -52,7 +52,7 @@ namespace hgl
|
|||||||
bool SetElementBuffer (VertexBufferBase *eb); ///<设置索引缓冲区数据
|
bool SetElementBuffer (VertexBufferBase *eb); ///<设置索引缓冲区数据
|
||||||
bool SetPositionBuffer (int shader_location,VertexBufferBase *vb); ///<设置位置缓冲区数据
|
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;} ///<取得位置数据成分数量
|
int GetPositionCompoment()const{return position_compoment;} ///<取得位置数据成分数量
|
||||||
PixelCompoment GetColorCompoment ()const{return color_compoment;} ///<取得颜色数据成份格式
|
PixelCompoment GetColorCompoment ()const{return color_compoment;} ///<取得颜色数据成份格式
|
||||||
|
66
inc/hgl/graph/VertexBufferObject.h
Normal file
66
inc/hgl/graph/VertexBufferObject.h
Normal 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/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
|
@ -4,8 +4,7 @@
|
|||||||
Shader.cpp
|
Shader.cpp
|
||||||
VertexArray.cpp
|
VertexArray.cpp
|
||||||
VertexBuffer.cpp
|
VertexBuffer.cpp
|
||||||
VertexBufferControlDSA.cpp
|
VertexBufferObject.cpp
|
||||||
VertexBufferControlBind.cpp
|
|
||||||
TextureFormat.cpp
|
TextureFormat.cpp
|
||||||
Texture1D.cpp
|
Texture1D.cpp
|
||||||
Texture1DDSA.cpp
|
Texture1DDSA.cpp
|
||||||
|
@ -27,7 +27,7 @@ namespace hgl
|
|||||||
|
|
||||||
vertex_buffer_list.PreMalloc(max_vertex_attrib);
|
vertex_buffer_list.PreMalloc(max_vertex_attrib);
|
||||||
|
|
||||||
vertex_compoment=-1;
|
position_compoment=-1;
|
||||||
color_compoment=HGL_PC_NONE;
|
color_compoment=HGL_PC_NONE;
|
||||||
|
|
||||||
element_buffer=nullptr;
|
element_buffer=nullptr;
|
||||||
@ -86,25 +86,25 @@ namespace hgl
|
|||||||
* @param shader_location 这个缓冲区对应的SHADER地址
|
* @param shader_location 这个缓冲区对应的SHADER地址
|
||||||
* @param vb 数据缓冲区
|
* @param vb 数据缓冲区
|
||||||
*/
|
*/
|
||||||
bool VertexArray::SetVertexBuffer(int shader_location, VertexBufferBase *vb)
|
bool VertexArray::SetPositionBuffer(int shader_location, VertexBufferBase *vb)
|
||||||
{
|
{
|
||||||
if(!vb)return(false);
|
if(!vb)return(false);
|
||||||
|
|
||||||
if(!AddVertexAttribBuffer(shader_location,vb)<0)
|
if(!AddVertexAttribBuffer(shader_location,vb)<0)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
vertex_compoment=vb->GetComponent();
|
position_compoment=vb->GetComponent();
|
||||||
vertex_buffer=vb;
|
position_buffer=vb;
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置一个颜色缓冲区
|
* 添加一个颜色缓冲区
|
||||||
* @param shader_location 这个缓冲区对应的SHADER地址
|
* @param shader_location 这个缓冲区对应的SHADER地址
|
||||||
* @param vb 数据缓冲区
|
* @param vb 数据缓冲区
|
||||||
* @param cf 颜色象素格式
|
* @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(!vb)return(false);
|
||||||
if(cf<=HGL_PC_NONE||cf>=HGL_PC_END)return(false);
|
if(cf<=HGL_PC_NONE||cf>=HGL_PC_END)return(false);
|
||||||
@ -127,8 +127,8 @@ namespace hgl
|
|||||||
if(element_buffer)
|
if(element_buffer)
|
||||||
return element_buffer->GetCount();
|
return element_buffer->GetCount();
|
||||||
|
|
||||||
if(vertex_buffer)
|
if(position_buffer)
|
||||||
return vertex_buffer->GetCount();
|
return position_buffer->GetCount();
|
||||||
|
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
@ -140,8 +140,8 @@ namespace hgl
|
|||||||
if (element_buffer)
|
if (element_buffer)
|
||||||
glDrawElements(primitive, element_buffer->GetCount(), element_buffer->GetDataType(), nullptr);
|
glDrawElements(primitive, element_buffer->GetCount(), element_buffer->GetDataType(), nullptr);
|
||||||
else
|
else
|
||||||
if(vertex_buffer)
|
if(position_buffer)
|
||||||
glDrawArrays(primitive,0,vertex_buffer->GetCount());
|
glDrawArrays(primitive,0,position_buffer->GetCount());
|
||||||
else
|
else
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
|
42
src/RenderDriver/VertexBufferObject.cpp
Normal file
42
src/RenderDriver/VertexBufferObject.cpp
Normal 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
|
Loading…
x
Reference in New Issue
Block a user