新的Renderable,接待原先VertexArray中的GetDrawCount/Draw函数,专门用于管理绘制

This commit is contained in:
HuYingzhuo 2019-03-27 14:19:18 +08:00
parent 1327e52a3f
commit 89e58d3d94
3 changed files with 69 additions and 6 deletions

View File

@ -1,7 +1,7 @@
#ifndef HGL_GRAPH_RENDERABLE_INCLUDE
#define HGL_GRAPH_RENDERABLE_INCLUDE
#include<hgl/graph/Shader.h>
#include<hgl/graph/VertexArray.h>
namespace hgl
{
@ -14,8 +14,25 @@ namespace hgl
{
protected:
VertexArray *va;
Material *mtl;
uint primitive; ///<绘制的图元类型
VertexArray *vao;
// Material *mtl;
public:
Renderable(uint prim,VertexArray *va=nullptr)
{
primitive=prim;
vao=va;
}
const uint GetPrimitive()const { return primitive; } ///<取得要绘制的图元类型
public:
uint GetDrawCount(); ///<取得可绘制的数据总数量
bool Draw(); ///<绘制
};//class Renderable
}//namespace graph
}//namespace hgl

View File

@ -5,9 +5,8 @@ SET(GRAPH_SRC_FILES OpenGLDebug.cpp
Shader.cpp
BufferData.cpp
BufferObject.cpp
# VertexArray.cpp
# VertexBuffer.cpp
# VertexBufferObject.cpp
VertexArray.cpp
Renderable.cpp
TextureFormat.cpp
Texture1D.cpp
Texture1DDSA.cpp

View File

@ -0,0 +1,47 @@
#include<hgl/graph/Renderable.h>
namespace hgl
{
namespace graph
{
/**
*
* @return
*/
uint Renderable::GetDrawCount()
{
ElementBufferObject *obj=vao->GetElement();
if(!obj)
obj=vao->GetPosition();
if(!obj)
return 0;
return obj->GetCount();
}
bool Renderable::Draw()
{
glBindVertexArray(vao->GetVAO());
ElementBufferObject *element_buffer=vao->GetElement();
if(!element_buffer)
{
VertexBufferObject *position_buffer=vao->GetPosition();
if(!position_buffer)
return(false);
glDrawArrays(primitive,0,position_buffer->GetCount());
}
else
{
glDrawElements(primitive,element_buffer->GetCount(),element_buffer->GetDataType(),nullptr);
}
return(true);
}
}//namespace graph
}//namespace hgl