新的Renderable,接待原先VertexArray中的GetDrawCount/Draw函数,专门用于管理绘制
This commit is contained in:
parent
1327e52a3f
commit
89e58d3d94
@ -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
|
||||
|
@ -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
|
||||
|
47
src/RenderDriver/Renderable.cpp
Normal file
47
src/RenderDriver/Renderable.cpp
Normal 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
|
Loading…
x
Reference in New Issue
Block a user