删除旧的VertexBuffer

This commit is contained in:
HuYingzhuo 2019-03-27 14:08:16 +08:00
parent 07c7de17c0
commit 5860a911ec
7 changed files with 1167 additions and 1167 deletions

View File

@ -1,95 +1,95 @@
#include<hgl/graph/VertexBuffer.h>
#include<hgl/graph/VertexArray.h>
#include<GLEWCore/glew.h>
#include"VertexBufferControl.h"
#include<hgl/graph/RenderDriver.h>
namespace hgl
{
namespace graph
{
VertexBufferControl *CreateVertexBufferControlDSA(uint);
VertexBufferControl *CreateVertexBufferControlBind(uint);
namespace
{
static VertexBufferControl *(*CreateVertexBufferControl)(uint)=nullptr;
void InitVertexBufferAPI()
{
if(IsSupportDSA())
CreateVertexBufferControl=CreateVertexBufferControlDSA;
else
CreateVertexBufferControl=CreateVertexBufferControlBind;
}
}//namespace
void VertexBufferBase::SetDataSize(int size)
{
if (total_bytes == size)return;
total_bytes = size;
if (mem_data)
mem_data = hgl_realloc(mem_data, size);
else
mem_data = hgl_malloc(size);
mem_end = ((char *)mem_data) + size;
}
VertexBufferBase::VertexBufferBase(uint type,uint dt,uint dbyte,uint dcm,uint size,uint usage)
{
vb_type =type;
data_type =dt;
data_bytes =dbyte;
dc_num =dcm;
count =size;
total_bytes =dcm*size*dbyte;
mem_data =hgl_malloc(total_bytes); //在很多情况下hgl_malloc分配的内存是对齐的这样有效率上的提升
mem_end =((char *)mem_data)+total_bytes;
data_usage =usage;
if(!CreateVertexBufferControl)
InitVertexBufferAPI();
vbc=CreateVertexBufferControl(type);
}
VertexBufferBase::~VertexBufferBase()
{
hgl_free(mem_data);
SAFE_CLEAR(vbc);
}
void VertexBufferBase::Update()
{
if(!vbc)return;
vbc->Set(total_bytes,mem_data,data_usage);
}
void VertexBufferBase::Change(int start, int size, void *data)
{
if (!vbc)return;
vbc->Change(start,size,data);
}
// void VertexBufferBase::BindVertexBuffer()
// {
// if(!video_buffer_type)return;
//
// glBindBuffer(video_buffer_type,video_buffer_index);
// }
int VertexBufferBase::GetBufferIndex()const
{
return vbc?vbc->GetIndex():-1;
}
}//namespace graph
}//namespace hgl
#include<hgl/graph/VertexBuffer.h>
#include<hgl/graph/VertexArray.h>
#include<GLEWCore/glew.h>
#include"VertexBufferControl.h"
#include<hgl/graph/RenderDriver.h>
namespace hgl
{
namespace graph
{
VertexBufferControl *CreateVertexBufferControlDSA(uint);
VertexBufferControl *CreateVertexBufferControlBind(uint);
namespace
{
static VertexBufferControl *(*CreateVertexBufferControl)(uint)=nullptr;
void InitVertexBufferAPI()
{
if(IsSupportDSA())
CreateVertexBufferControl=CreateVertexBufferControlDSA;
else
CreateVertexBufferControl=CreateVertexBufferControlBind;
}
}//namespace
void VertexBufferBase::SetDataSize(int size)
{
if (total_bytes == size)return;
total_bytes = size;
if (mem_data)
mem_data = hgl_realloc(mem_data, size);
else
mem_data = hgl_malloc(size);
mem_end = ((char *)mem_data) + size;
}
VertexBufferBase::VertexBufferBase(uint type,uint dt,uint dbyte,uint dcm,uint size,uint usage)
{
vb_type =type;
data_type =dt;
data_bytes =dbyte;
dc_num =dcm;
count =size;
total_bytes =dcm*size*dbyte;
mem_data =hgl_malloc(total_bytes); //在很多情况下hgl_malloc分配的内存是对齐的这样有效率上的提升
mem_end =((char *)mem_data)+total_bytes;
data_usage =usage;
if(!CreateVertexBufferControl)
InitVertexBufferAPI();
vbc=CreateVertexBufferControl(type);
}
VertexBufferBase::~VertexBufferBase()
{
hgl_free(mem_data);
SAFE_CLEAR(vbc);
}
void VertexBufferBase::Update()
{
if(!vbc)return;
vbc->Set(total_bytes,mem_data,data_usage);
}
void VertexBufferBase::Change(int start, int size, void *data)
{
if (!vbc)return;
vbc->Change(start,size,data);
}
// void VertexBufferBase::BindVertexBuffer()
// {
// if(!video_buffer_type)return;
//
// glBindBuffer(video_buffer_type,video_buffer_index);
// }
int VertexBufferBase::GetBufferIndex()const
{
return vbc?vbc->GetIndex():-1;
}
}//namespace graph
}//namespace hgl

File diff suppressed because it is too large Load Diff

View File

@ -1,41 +1,41 @@
#ifndef HGL_GRAPH_VERTEX_BUFFER_OBJECT_CONTROL_INCLUDE
#define HGL_GRAPH_VERTEX_BUFFER_OBJECT_CONTROL_INCLUDE
#include<hgl/type/DataType.h>
#include<GLEWCore/glew.h>
namespace hgl
{
namespace graph
{
class VertexBufferControl
{
protected:
uint type;
uint index;
public:
uint GetIndex()const { return index; }
public:
VertexBufferControl(uint t, uint i) { type = t; index = i; }
virtual ~VertexBufferControl()
{
Clear();
}
virtual void Set(GLsizei, void *,GLenum)=0;
virtual void Change(GLintptr,GLsizei, void *)=0;
void Clear()
{
if(!type||!index)return;
glDeleteBuffers(1, &index);
type = index = 0;
}
};//class VertexBufferControl
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_VERTEX_BUFFER_OBJECT_CONTROL_INCLUDE
#ifndef HGL_GRAPH_VERTEX_BUFFER_OBJECT_CONTROL_INCLUDE
#define HGL_GRAPH_VERTEX_BUFFER_OBJECT_CONTROL_INCLUDE
#include<hgl/type/DataType.h>
#include<GLEWCore/glew.h>
namespace hgl
{
namespace graph
{
class VertexBufferControl
{
protected:
uint type;
uint index;
public:
uint GetIndex()const { return index; }
public:
VertexBufferControl(uint t, uint i) { type = t; index = i; }
virtual ~VertexBufferControl()
{
Clear();
}
virtual void Set(GLsizei, void *,GLenum)=0;
virtual void Change(GLintptr,GLsizei, void *)=0;
void Clear()
{
if(!type||!index)return;
glDeleteBuffers(1, &index);
type = index = 0;
}
};//class VertexBufferControl
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_VERTEX_BUFFER_OBJECT_CONTROL_INCLUDE

View File

@ -1,58 +1,58 @@
#include"VertexBufferControl.h"
#include<GLEWCore/glew.h>
namespace hgl
{
namespace graph
{
//class VertexBufferBind
//{
// uint type;
// int old_id;
//public:
// VertexBufferBind(uint t, uint binding_type, int id) :type(t)
// {
// glGetIntegerv(binding_type, &old_id);
// glBindBuffer(type, id);
// }
// ~VertexBufferBind()
// {
// glBindBuffer(type, old_id);
// }
//};//class VertexBufferBind
class VertexBufferControlBind:public VertexBufferControl
{
public:
using VertexBufferControl::VertexBufferControl;
~VertexBufferControlBind()
{
glDeleteBuffers(1,&(this->index));
}
void Set(GLsizei size, void *data, GLenum data_usage)
{
glBindBuffer(this->type,this->index);
glBufferData(this->type, size, data, data_usage);
}
void Change(GLintptr start, GLsizei size, void *data)
{
glBindBuffer(this->type, this->index);
glBufferSubData(this->type, start, size, data);
}
};//class VertexBufferControlBind
VertexBufferControl *CreateVertexBufferControlBind(uint type)
{
uint index;
glGenBuffers(1, &index);
return(new VertexBufferControlBind(type, index));
}
}//namespace graph
}//namespace hgl
#include"VertexBufferControl.h"
#include<GLEWCore/glew.h>
namespace hgl
{
namespace graph
{
//class VertexBufferBind
//{
// uint type;
// int old_id;
//public:
// VertexBufferBind(uint t, uint binding_type, int id) :type(t)
// {
// glGetIntegerv(binding_type, &old_id);
// glBindBuffer(type, id);
// }
// ~VertexBufferBind()
// {
// glBindBuffer(type, old_id);
// }
//};//class VertexBufferBind
class VertexBufferControlBind:public VertexBufferControl
{
public:
using VertexBufferControl::VertexBufferControl;
~VertexBufferControlBind()
{
glDeleteBuffers(1,&(this->index));
}
void Set(GLsizei size, void *data, GLenum data_usage)
{
glBindBuffer(this->type,this->index);
glBufferData(this->type, size, data, data_usage);
}
void Change(GLintptr start, GLsizei size, void *data)
{
glBindBuffer(this->type, this->index);
glBufferSubData(this->type, start, size, data);
}
};//class VertexBufferControlBind
VertexBufferControl *CreateVertexBufferControlBind(uint type)
{
uint index;
glGenBuffers(1, &index);
return(new VertexBufferControlBind(type, index));
}
}//namespace graph
}//namespace hgl

View File

@ -1,38 +1,38 @@
#include"VertexBufferControl.h"
#include<GLEWCore/glew.h>
namespace hgl
{
namespace graph
{
class VertexBufferControlDSA:public VertexBufferControl
{
public:
using VertexBufferControl::VertexBufferControl;
void Set(GLsizei size, void *data,GLenum data_usage)
{
glNamedBufferData(this->index, size, data, data_usage);
}
void Change(GLintptr start, GLsizei size, void *data)
{
glNamedBufferSubData(this->index, start, size, data);
}
};//class VertexBufferControlDSA
VertexBufferControl *CreateVertexBufferControlDSA(uint type)
{
uint index;
glCreateBuffers(1,&index);
return(new VertexBufferControlDSA(type,index));
}
void DeleteVertexBufferControlDSA(VertexBufferControl *vbc)
{
SAFE_CLEAR(vbc);
}
}//namespace graph
}//namespace hgl
#include"VertexBufferControl.h"
#include<GLEWCore/glew.h>
namespace hgl
{
namespace graph
{
class VertexBufferControlDSA:public VertexBufferControl
{
public:
using VertexBufferControl::VertexBufferControl;
void Set(GLsizei size, void *data,GLenum data_usage)
{
glNamedBufferData(this->index, size, data, data_usage);
}
void Change(GLintptr start, GLsizei size, void *data)
{
glNamedBufferSubData(this->index, start, size, data);
}
};//class VertexBufferControlDSA
VertexBufferControl *CreateVertexBufferControlDSA(uint type)
{
uint index;
glCreateBuffers(1,&index);
return(new VertexBufferControlDSA(type,index));
}
void DeleteVertexBufferControlDSA(VertexBufferControl *vbc)
{
SAFE_CLEAR(vbc);
}
}//namespace graph
}//namespace hgl