删除旧的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/VertexBuffer.h>
#include<hgl/graph/VertexArray.h> #include<hgl/graph/VertexArray.h>
#include<GLEWCore/glew.h> #include<GLEWCore/glew.h>
#include"VertexBufferControl.h" #include"VertexBufferControl.h"
#include<hgl/graph/RenderDriver.h> #include<hgl/graph/RenderDriver.h>
namespace hgl namespace hgl
{ {
namespace graph namespace graph
{ {
VertexBufferControl *CreateVertexBufferControlDSA(uint); VertexBufferControl *CreateVertexBufferControlDSA(uint);
VertexBufferControl *CreateVertexBufferControlBind(uint); VertexBufferControl *CreateVertexBufferControlBind(uint);
namespace namespace
{ {
static VertexBufferControl *(*CreateVertexBufferControl)(uint)=nullptr; static VertexBufferControl *(*CreateVertexBufferControl)(uint)=nullptr;
void InitVertexBufferAPI() void InitVertexBufferAPI()
{ {
if(IsSupportDSA()) if(IsSupportDSA())
CreateVertexBufferControl=CreateVertexBufferControlDSA; CreateVertexBufferControl=CreateVertexBufferControlDSA;
else else
CreateVertexBufferControl=CreateVertexBufferControlBind; CreateVertexBufferControl=CreateVertexBufferControlBind;
} }
}//namespace }//namespace
void VertexBufferBase::SetDataSize(int size) void VertexBufferBase::SetDataSize(int size)
{ {
if (total_bytes == size)return; if (total_bytes == size)return;
total_bytes = size; total_bytes = size;
if (mem_data) if (mem_data)
mem_data = hgl_realloc(mem_data, size); mem_data = hgl_realloc(mem_data, size);
else else
mem_data = hgl_malloc(size); mem_data = hgl_malloc(size);
mem_end = ((char *)mem_data) + size; mem_end = ((char *)mem_data) + size;
} }
VertexBufferBase::VertexBufferBase(uint type,uint dt,uint dbyte,uint dcm,uint size,uint usage) VertexBufferBase::VertexBufferBase(uint type,uint dt,uint dbyte,uint dcm,uint size,uint usage)
{ {
vb_type =type; vb_type =type;
data_type =dt; data_type =dt;
data_bytes =dbyte; data_bytes =dbyte;
dc_num =dcm; dc_num =dcm;
count =size; count =size;
total_bytes =dcm*size*dbyte; total_bytes =dcm*size*dbyte;
mem_data =hgl_malloc(total_bytes); //在很多情况下hgl_malloc分配的内存是对齐的这样有效率上的提升 mem_data =hgl_malloc(total_bytes); //在很多情况下hgl_malloc分配的内存是对齐的这样有效率上的提升
mem_end =((char *)mem_data)+total_bytes; mem_end =((char *)mem_data)+total_bytes;
data_usage =usage; data_usage =usage;
if(!CreateVertexBufferControl) if(!CreateVertexBufferControl)
InitVertexBufferAPI(); InitVertexBufferAPI();
vbc=CreateVertexBufferControl(type); vbc=CreateVertexBufferControl(type);
} }
VertexBufferBase::~VertexBufferBase() VertexBufferBase::~VertexBufferBase()
{ {
hgl_free(mem_data); hgl_free(mem_data);
SAFE_CLEAR(vbc); SAFE_CLEAR(vbc);
} }
void VertexBufferBase::Update() void VertexBufferBase::Update()
{ {
if(!vbc)return; if(!vbc)return;
vbc->Set(total_bytes,mem_data,data_usage); vbc->Set(total_bytes,mem_data,data_usage);
} }
void VertexBufferBase::Change(int start, int size, void *data) void VertexBufferBase::Change(int start, int size, void *data)
{ {
if (!vbc)return; if (!vbc)return;
vbc->Change(start,size,data); vbc->Change(start,size,data);
} }
// void VertexBufferBase::BindVertexBuffer() // void VertexBufferBase::BindVertexBuffer()
// { // {
// if(!video_buffer_type)return; // if(!video_buffer_type)return;
// //
// glBindBuffer(video_buffer_type,video_buffer_index); // glBindBuffer(video_buffer_type,video_buffer_index);
// } // }
int VertexBufferBase::GetBufferIndex()const int VertexBufferBase::GetBufferIndex()const
{ {
return vbc?vbc->GetIndex():-1; return vbc?vbc->GetIndex():-1;
} }
}//namespace graph }//namespace graph
}//namespace hgl }//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 #ifndef HGL_GRAPH_VERTEX_BUFFER_OBJECT_CONTROL_INCLUDE
#define HGL_GRAPH_VERTEX_BUFFER_OBJECT_CONTROL_INCLUDE #define HGL_GRAPH_VERTEX_BUFFER_OBJECT_CONTROL_INCLUDE
#include<hgl/type/DataType.h> #include<hgl/type/DataType.h>
#include<GLEWCore/glew.h> #include<GLEWCore/glew.h>
namespace hgl namespace hgl
{ {
namespace graph namespace graph
{ {
class VertexBufferControl class VertexBufferControl
{ {
protected: protected:
uint type; uint type;
uint index; uint index;
public: public:
uint GetIndex()const { return index; } uint GetIndex()const { return index; }
public: public:
VertexBufferControl(uint t, uint i) { type = t; index = i; } VertexBufferControl(uint t, uint i) { type = t; index = i; }
virtual ~VertexBufferControl() virtual ~VertexBufferControl()
{ {
Clear(); Clear();
} }
virtual void Set(GLsizei, void *,GLenum)=0; virtual void Set(GLsizei, void *,GLenum)=0;
virtual void Change(GLintptr,GLsizei, void *)=0; virtual void Change(GLintptr,GLsizei, void *)=0;
void Clear() void Clear()
{ {
if(!type||!index)return; if(!type||!index)return;
glDeleteBuffers(1, &index); glDeleteBuffers(1, &index);
type = index = 0; type = index = 0;
} }
};//class VertexBufferControl };//class VertexBufferControl
}//namespace graph }//namespace graph
}//namespace hgl }//namespace hgl
#endif//HGL_GRAPH_VERTEX_BUFFER_OBJECT_CONTROL_INCLUDE #endif//HGL_GRAPH_VERTEX_BUFFER_OBJECT_CONTROL_INCLUDE

View File

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

View File

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