From 5860a911ecc6ae9018d1fc9192c8261b70e2cadf Mon Sep 17 00:00:00 2001 From: HuYingzhuo Date: Wed, 27 Mar 2019 14:08:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A7=E7=9A=84VertexBuffe?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VertexBuffer.cpp | 190 +- {inc/hgl/graph => discarded}/VertexBuffer.h | 1870 ++++++++--------- .../graph => discarded}/VertexBufferBase.h | 0 .../VertexBufferControl.h | 82 +- .../VertexBufferControlBind.cpp | 116 +- .../VertexBufferControlDSA.cpp | 76 +- .../graph => discarded}/VertexBufferObject.h | 0 7 files changed, 1167 insertions(+), 1167 deletions(-) rename {src/RenderDriver => discarded}/VertexBuffer.cpp (96%) rename {inc/hgl/graph => discarded}/VertexBuffer.h (97%) rename {inc/hgl/graph => discarded}/VertexBufferBase.h (100%) rename {src/RenderDriver => discarded}/VertexBufferControl.h (96%) rename {src/RenderDriver => discarded}/VertexBufferControlBind.cpp (96%) rename {src/RenderDriver => discarded}/VertexBufferControlDSA.cpp (96%) rename {inc/hgl/graph => discarded}/VertexBufferObject.h (100%) diff --git a/src/RenderDriver/VertexBuffer.cpp b/discarded/VertexBuffer.cpp similarity index 96% rename from src/RenderDriver/VertexBuffer.cpp rename to discarded/VertexBuffer.cpp index be993b20..a770c596 100644 --- a/src/RenderDriver/VertexBuffer.cpp +++ b/discarded/VertexBuffer.cpp @@ -1,95 +1,95 @@ -#include -#include -#include -#include"VertexBufferControl.h" -#include - -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 +#include +#include +#include"VertexBufferControl.h" +#include + +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 diff --git a/inc/hgl/graph/VertexBuffer.h b/discarded/VertexBuffer.h similarity index 97% rename from inc/hgl/graph/VertexBuffer.h rename to discarded/VertexBuffer.h index 4fd842bc..2fb19a45 100644 --- a/inc/hgl/graph/VertexBuffer.h +++ b/discarded/VertexBuffer.h @@ -1,935 +1,935 @@ -#ifndef HGL_VERTEX_BUFFER_OBJECT_INCLUDE -#define HGL_VERTEX_BUFFER_OBJECT_INCLUDE - -#include -#include -#include -// #include -#include -//#include -#include -namespace hgl -{ - namespace graph - { - class VertexBufferControl; - - /** - * 顶点属性数据实际模板 - */ - template class VertexBuffer:public VertexBufferBase - { - protected: - - T *mem_type; ///<符合当前类型的地址 - T *access; ///<当前访问地址 - - T *start; ///<访问起始地址 - - public: - - VertexBuffer(const uint type,const uint dt,const int _size,const T *_data=nullptr,uint level=GL_STATIC_DRAW):VertexBufferBase(type,dt,sizeof(T),C,_size,level) - { - count=_size; - - mem_type=(T *)GetData(); - access=0; - start=0; - - if(_data) - { - memcpy(mem_type,_data,this->total_bytes); - this->Update(); - } - } - - virtual ~VertexBuffer()=default; - - void SetCount(int _count) - { - count=_count; - - SetDataSize(_count*C*sizeof(T)); - - mem_type=(T *)GetData(); - access=0; - start=0; - } - - /** - * 取得数据区地址 - * @param offset 从第几个数据开始访问 - * @return 访问地址 - */ - T *Get(int offset=0) - { - if(!mem_type||offset>=count) - { - // LOG_HINT(OS_TEXT("VertexBuffer::Get() out,offset:")+OSString(offset)); - return(nullptr); - } - - return mem_type+offset*C; - } - - /** - * 开始访问数据区 - * @param offset 从第几个数据开始访问 - * @return 访问地址 - */ - void *Begin(int offset=0) - { - if(access) - { - // LOG_HINT(OS_TEXT("VertexBuffer::Begin() access!=0,offset:")+OSString(offset)); - return(nullptr); - } - - access=Get(offset); - - if(access) - start=access; - - return access; - } - - /** - * 结束访问 - */ - void End() - { - this->Change(((char *)start )-((char *)mem_type), - ((char *)access)-((char *)start), - start); - - access=nullptr; - start=nullptr; - } - - /** - * 写入指定数量的数据 - * @param vp 数据指针 - * @param number 数据数量 - */ - bool WriteData(const T *vp,const int number) - { - if(!this->access||this->access+C*number>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer::Write(const T *,number) out,number:")+OSString(number)); - return(false); - } - - memcpy(access,vp,C*number*sizeof(T)); - - access+=C*number; - - return(true); - } - };//class VertexBuffer - - /** - * 一元数据缓冲区 - */ - template class VertexBuffer1:public VertexBuffer - { - public: - - VertexBuffer1(const uint type,const int _size,const T *_data=nullptr,uint level=GL_STATIC_DRAW):VertexBuffer(type,DT,_size,_data,level){} - VertexBuffer1(const int _size,const T *_data=nullptr,uint level=GL_STATIC_DRAW):VertexBuffer(GL_ARRAY_BUFFER,DT,_size,_data,level){} - virtual ~VertexBuffer1()=default; - - bool Write(const T v1) - { - if(!this->access||this->access+1>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer1::Write(const T) out")); - return(false); - } - - *this->access++=v1; - return(true); - } - - /** - * 将一个值重复多次写入缓冲区 - * @param v 值 - * @param count 写入数量 - */ - bool WriteRepeat(const T v,const int count) - { - if(!this->access||this->access+count>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer1::Write(const T,")+OSString(count)+OS_TEXT(") out")); - return(false); - } - - hgl_set(this->access,v,count); - this->access+=count; - return(true); - } - };//class VertexBuffer1 - - /** - * 索引数据缓冲区 - */ - template class ElementBuffer:public VertexBuffer1 - { - public: - ElementBuffer(const int _size,const T *_data=nullptr,uint level=GL_STATIC_DRAW):VertexBuffer1(GL_ELEMENT_ARRAY_BUFFER,DT,_size,_data,level){} - virtual ~ElementBuffer()=default; - };// - - /** - * 二元数据缓冲区 - */ - template class VertexBuffer2:public VertexBuffer - { - public: - - VertexBuffer2(const int _size,const T *_data=nullptr,uint level=GL_STATIC_DRAW):VertexBuffer(GL_ARRAY_BUFFER,DT,_size,_data,level){} - virtual ~VertexBuffer2()=default; - - bool Write(const T v1,const T v2) - { - if(!this->access||this->access+2>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer2::Write(const T ,const T) out")); - return(false); - } - - *this->access++=v1; - *this->access++=v2; - - return(true); - } - - bool Write(const T *v) - { - if(!this->access||this->access+2>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer2::Write(T *) out")); - return(false); - } - - *this->access++=*v++; - *this->access++=*v; - - return(true); - } - - bool Write(const Vector2f &v) - { - if(!this->access||this->access+2>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer2::Write(vec2 &) out")); - return(false); - } - - *this->access++=v.x; - *this->access++=v.y; - - return(true); - } - - /** - * 将一个值重复多次写入缓冲区 - * @param v 值 - * @param count 写入数量 - */ - bool Write(const Vector2f &v,const int count) - { - if(!this->access||this->access+(count<<1)>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer1::Write(const Vector2f &,")+OSString(count)+OS_TEXT(") out")); - return(false); - } - - for(int i=0;iaccess++=v.x; - *this->access++=v.y; - } - - return(true); - } - - bool WriteLine(const T start_x,const T start_y,const T end_x,const T end_y) - { - if(!this->access||this->access+4>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer2::WriteLine(T,T,T,T) out")); - return(false); - } - - *this->access++=start_x; - *this->access++=start_y; - *this->access++=end_x; - *this->access++=end_y; - - return(true); - } - - bool WriteLine(const Vector2f &start,const Vector2f &end) - { - if(!this->access||this->access+4>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer2::WriteLine(vec2,vec2) out")); - return(false); - } - - *this->access++=start.x; - *this->access++=start.y; - *this->access++=end.x; - *this->access++=end.y; - - return(true); - } - - /** - * 写入2D三角形 - */ - bool WriteTriangle(const Vector2f &v1,const Vector2f &v2,const Vector2f &v3) - { - if(!this->access||this->access+6>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer2::WriteTriangle(vec2,vec2,vec2) out")); - return(false); - } - - *this->access++=v1.x; - *this->access++=v1.y; - - *this->access++=v2.x; - *this->access++=v2.y; - - *this->access++=v3.x; - *this->access++=v3.y; - - return(true); - } - - /** - * 写入2D三角形 - */ - bool WriteTriangle(const Vector2f *v) - { - if(!this->access||this->access+6>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer2::WriteTriangle(vec2 *) out")); - return(false); - } - - *this->access++=v->x; - *this->access++=v->y; - ++v; - - *this->access++=v->x; - *this->access++=v->y; - ++v; - - *this->access++=v->x; - *this->access++=v->y; - - return(true); - } - - /** - * 写入2D四边形坐标数据 - */ - bool WriteQuad(const Vector2f <,const Vector2f &rt,const Vector2f &rb,const Vector2f &lb) - { - if(WriteTriangle(lt,lb,rb)) - if(WriteTriangle(lt,rb,rt)) - return(true); - - // LOG_HINT(OS_TEXT("VertexBuffer2::WriteQuad(vec2 &,vec2 &,vec2 &,vec2 &) error")); - return(false); - } - - /** - * 写入2D矩形(两个三角形)坐标数据 - */ - bool WriteRect(const T left,const T top,const T width,const T height) - { - const Vector2f lt(left ,top); - const Vector2f rt(left+width,top); - const Vector2f rb(left+width,top+height); - const Vector2f lb(left ,top+height); - - return WriteQuad(lt,rt,rb,lb); - } - };//class VertexBuffer2 - - /** - * 三元数据缓冲区 - */ - template class VertexBuffer3:public VertexBuffer - { - public: - - VertexBuffer3(const int _size,const T *_data=nullptr,uint level=GL_STATIC_DRAW):VertexBuffer(GL_ARRAY_BUFFER,DT,_size,_data,level){} - virtual ~VertexBuffer3()=default; - - /** - * 计算绑定盒 - * @param min_vertex 最小值坐标 - * @param max_vertex 最大值坐标 - */ - template - void GetBoundingBox(V &min_vertex,V &max_vertex) - { - T *p=this->mem_type; - - //先以corner为最小值,length为最大值,求取最小最大值 - min_vertex.x=*p++; - min_vertex.y=*p++; - min_vertex.z=*p++; - - max_vertex=min_vertex; - - for(int i=1;icount;i++) - { - if(*pmax_vertex.x)max_vertex.x=*p; - ++p; - - if(*pmax_vertex.y)max_vertex.y=*p; - ++p; - - if(*pmax_vertex.z)max_vertex.z=*p; - ++p; - } - } - - bool Write(const T v1,const T v2,const T v3) - { - if(!this->access||this->access+3>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer3::Write(T,T,T) out")); - return(false); - } - - *this->access++=v1; - *this->access++=v2; - *this->access++=v3; - - return(true); - } - - bool Write(const T *v) - { - if(!this->access||this->access+3>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer3::Write(T *) out")); - return(false); - } - - *this->access++=*v++; - *this->access++=*v++; - *this->access++=*v; - - return(true); - } - - bool Write(const Vector3f &v) - { - if(!this->access||this->access+3>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer3::Write(vec3 &) out")); - return(false); - } - - *this->access++=v.x; - *this->access++=v.y; - *this->access++=v.z; - - return(true); - } - - bool Write(const Vector4f &v) - { - if(!this->access||this->access+3>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer3::Write(vec4 &) out")); - return(false); - } - - *this->access++=v.x; - *this->access++=v.y; - *this->access++=v.z; - - return(true); - } - - /** - * 将一个值重复多次写入缓冲区 - * @param v 值 - * @param count 写入数量 - */ - bool Write(const Vector3f &v,const int count) - { - if(!this->access||this->access+(count*3)>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer3::Write(const Vector3f,")+OSString(count)+OS_TEXT(") out")); - return(false); - } - - for(int i=0;iaccess++=v.x; - *this->access++=v.y; - *this->access++=v.z; - } - - return(true); - } - - bool Write(const Color3f &v) - { - if(!this->access||this->access+3>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer3::Write(color3f &) out")); - return(false); - } - - *this->access++=v.r; - *this->access++=v.g; - *this->access++=v.b; - - return(true); - } - - bool WriteLine(const T start_x,const T start_y,const T start_z,const T end_x,const T end_y,const T end_z) - { - if(!this->access||this->access+6>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer3::WriteLine(T,T,T,T,T,T) out")); - return(false); - } - - *this->access++=start_x; - *this->access++=start_y; - *this->access++=start_z; - *this->access++=end_x; - *this->access++=end_y; - *this->access++=end_z; - - return(true); - } - - bool WriteLine(const Vector3f &start,const Vector3f &end) - { - if(!this->access||this->access+6>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer3::WriteLine(vec3,vec3) out")); - return(false); - } - - *this->access++=start.x; - *this->access++=start.y; - *this->access++=start.z; - *this->access++=end.x; - *this->access++=end.y; - *this->access++=end.z; - - return(true); - } - - /** - * 写入3D三角形 - */ - bool WriteTriangle(const Vector3f &v1,const Vector3f &v2,const Vector3f &v3) - { - if(!this->access||this->access+9>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer3::WriteTriangle(vec3,vec3,vec3) out")); - return(false); - } - - *this->access++=v1.x; - *this->access++=v1.y; - *this->access++=v1.z; - - *this->access++=v2.x; - *this->access++=v2.y; - *this->access++=v2.z; - - *this->access++=v3.x; - *this->access++=v3.y; - *this->access++=v3.z; - - return(true); - } - - /** - * 写入3D三角形 - */ - bool WriteTriangle(const Vector3f *v) - { - if(!this->access||this->access+9>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer3::WriteTriangle(vec3 *) out")); - return(false); - } - - *this->access++=v->x; - *this->access++=v->y; - *this->access++=v->z; - ++v; - - *this->access++=v->x; - *this->access++=v->y; - *this->access++=v->z; - ++v; - - *this->access++=v->x; - *this->access++=v->y; - *this->access++=v->z; - - return(true); - } - - /** - * 写入3D四边形坐标数据 - */ - bool WriteQuad(const Vector3f <,const Vector3f &rt,const Vector3f &rb,const Vector3f &lb) - { - if(WriteTriangle(lt,lb,rb)) - if(WriteTriangle(lt,rb,rt)) - return(true); - - // LOG_HINT(OS_TEXT("VertexBuffer3::WriteQuad(vec3 &,vec3 &,vec3 &,vec3 &) error")); - return(false); - } - };//class VertexBuffer3 - - /** - * 四元数据缓冲区 - */ - template class VertexBuffer4:public VertexBuffer - { - public: - - VertexBuffer4(const int _size,const T *_data=nullptr,uint level=GL_STATIC_DRAW):VertexBuffer(GL_ARRAY_BUFFER,DT,_size,_data,level){} - virtual ~VertexBuffer4()=default; - - /** - * 计算绑定盒 - * @param min_vertex 最小值坐标 - * @param max_vertex 最大值坐标 - */ - template - void GetBoundingBox(V &min_vertex,V &max_vertex) - { - T *p=this->mem_type; - - //先以corner为最小值,length为最大值,求取最小最大值 - min_vertex.x=*p++; - min_vertex.y=*p++; - min_vertex.z=*p++; - - max_vertex=min_vertex; - - for(int i=1;icount;i++) - { - if(*pmax_vertex.x)max_vertex.x=*p; - ++p; - - if(*pmax_vertex.y)max_vertex.y=*p; - ++p; - - if(*pmax_vertex.z)max_vertex.z=*p; - ++p; - } - } - - bool Write(const T v1,const T v2,const T v3,const T v4) - { - if(!this->access||this->access+4>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer4::Write(T,T,T,T) out")); - return(false); - } - - *this->access++=v1; - *this->access++=v2; - *this->access++=v3; - *this->access++=v4; - - return(true); - } - - bool Write(const T *v) - { - if(!this->access||this->access+4>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer4::Write(T *) out")); - return(false); - } - - *this->access++=*v++; - *this->access++=*v++; - *this->access++=*v++; - *this->access++=*v; - - return(true); - } - - bool Write(const Vector4f &v) - { - if(!this->access||this->access+4>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer4::Write(color4 &) out")); - return(false); - } - - *this->access++=v.x; - *this->access++=v.y; - *this->access++=v.z; - *this->access++=v.w; - - return(true); - } - - bool Write(const Color4f &v) - { - if(!this->access||this->access+4>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer4::Write(color4 &) out")); - return(false); - } - - *this->access++=v.r; - *this->access++=v.g; - *this->access++=v.b; - *this->access++=v.a; - - return(true); - } - - /** - * 将一个值重复多次写入缓冲区 - * @param v 值 - * @param count 写入数量 - */ - bool Write(const Vector4f &v,const int count) - { - if(!this->access||this->access+(count<<2)>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer4::Write(const Vector4f,")+OSString(count)+OS_TEXT(") out")); - return(false); - } - - for(int i=0;iaccess++=v.x; - *this->access++=v.y; - *this->access++=v.z; - *this->access++=v.w; - } - - return(true); - } - - bool WriteLine(const T start_x,const T start_y,const T start_z,const T end_x,const T end_y,const T end_z) - { - if(!this->access||this->access+8>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer4::WriteLine(T,T,T,T,T,T) out")); - return(false); - } - - *this->access++=start_x; - *this->access++=start_y; - *this->access++=start_z; - *this->access++=1.0f; - *this->access++=end_x; - *this->access++=end_y; - *this->access++=end_z; - *this->access++=1.0f; - - return(true); - } - - bool WriteLine(const Vector3f &start,const Vector3f &end) - { - if(!this->access||this->access+8>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer4::WriteLine(vec3,vec3) out")); - return(false); - } - - *this->access++=start.x; - *this->access++=start.y; - *this->access++=start.z; - *this->access++=1.0f; - *this->access++=end.x; - *this->access++=end.y; - *this->access++=end.z; - *this->access++=1.0f; - - return(true); - } - - /** - * 写入3D三角形 - */ - bool WriteTriangle(const Vector3f &v1,const Vector3f &v2,const Vector3f &v3) - { - if(!this->access||this->access+12>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer4::WriteTriangle(vec3,vec3,vec3) out")); - return(false); - } - - *this->access++=v1.x; - *this->access++=v1.y; - *this->access++=v1.z; - *this->access++=1.0f; - - *this->access++=v2.x; - *this->access++=v2.y; - *this->access++=v2.z; - *this->access++=1.0f; - - *this->access++=v3.x; - *this->access++=v3.y; - *this->access++=v3.z; - *this->access++=1.0f; - - return(true); - } - - /** - * 写入3D三角形 - */ - bool WriteTriangle(const Vector3f *v) - { - if(!this->access||this->access+12>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer4::WriteTriangle(vec3 *) out")); - return(false); - } - - *this->access++=v->x; - *this->access++=v->y; - *this->access++=v->z; - *this->access++=1.0f; - ++v; - - *this->access++=v->x; - *this->access++=v->y; - *this->access++=v->z; - *this->access++=1.0f; - ++v; - - *this->access++=v->x; - *this->access++=v->y; - *this->access++=v->z; - *this->access++=1.0f; - - return(true); - } - - /** - * 写入2D矩形,注:这个函数会依次写入Left,Top,Width,Height四个值 - */ - template - bool WriteRectangle2D(const RectScope2 &rect) - { - if(!this->access||this->access+4>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer4::WriteRectangle2D(RectScope2 ) out")); - return(false); - } - - *this->access++=rect.Left; - *this->access++=rect.Top; - *this->access++=rect.Width; - *this->access++=rect.Height; - - return(true); - } - - /** - * 写入2D矩形,注:这个函数会依次写入Left,Top,Width,Height四个值 - */ - template - bool WriteRectangle2D(const RectScope2 *rect,const int count) - { - if(!this->access||this->access+(4*count)>this->mem_end) - { - // LOG_HINT(OS_TEXT("VertexBuffer4::WriteRectangle2D(RectScope2 *,count) out")); - return(false); - } - - for(int i=0;iaccess++=rect->Left; - *this->access++=rect->Top; - *this->access++=rect->Width; - *this->access++=rect->Height; - - ++rect; - } - - return(true); - } - };//class VertexBuffer4 - - //缓冲区具体数据类型定义 - using EB16=ElementBuffer; - using EB32=ElementBuffer; - - template - class ColorBufferBase:public BASE - { - protected: - - PixelCompoment color_compoment; - - public: - - const PixelCompoment GetColorCompoment()const{return color_compoment;} - - public: - - ColorBuferBase(const PixelCompoment &pc):color_compoment(pc){} - };// - -#define USING_VB1234(type,gl_type,short_name) using VB1##short_name=VertexBuffer1;using CB1##short_name=ColorBufferBase; \ - using VB2##short_name=VertexBuffer2; \ - using VB3##short_name=VertexBuffer3; \ - using VB4##short_name=VertexBuffer4; - - USING_VB1234(int8, GL_BYTE, i8) - USING_VB1234(int8, GL_BYTE, b) - USING_VB1234(int16, GL_SHORT, i16) - USING_VB1234(int16, GL_SHORT, s) - USING_VB1234(int32, GL_INT, i32) - USING_VB1234(int32, GL_INT, i) - - USING_VB1234(uint8, GL_UNSIGNED_BYTE, u8) - USING_VB1234(uint8, GL_UNSIGNED_BYTE, ub) - USING_VB1234(uint16,GL_UNSIGNED_SHORT, u16) - USING_VB1234(uint16,GL_UNSIGNED_SHORT, us) - USING_VB1234(uint32,GL_UNSIGNED_INT, u32) - USING_VB1234(uint32,GL_UNSIGNED_INT, ui) - - USING_VB1234(uint16,GL_HALF_FLOAT, hf) - USING_VB1234(uint16,GL_HALF_FLOAT, f16) - USING_VB1234(float, GL_FLOAT, f) - USING_VB1234(float, GL_FLOAT, f32) - USING_VB1234(double,GL_DOUBLE, d) - USING_VB1234(double,GL_DOUBLE, f64) - -#undef USING_VB1234 - - }//namespace graph -}//namespace hgl -#endif//HGL_VERTEX_BUFFER_OBJECT_INCLUDE +#ifndef HGL_VERTEX_BUFFER_OBJECT_INCLUDE +#define HGL_VERTEX_BUFFER_OBJECT_INCLUDE + +#include +#include +#include +// #include +#include +//#include +#include +namespace hgl +{ + namespace graph + { + class VertexBufferControl; + + /** + * 顶点属性数据实际模板 + */ + template class VertexBuffer:public VertexBufferBase + { + protected: + + T *mem_type; ///<符合当前类型的地址 + T *access; ///<当前访问地址 + + T *start; ///<访问起始地址 + + public: + + VertexBuffer(const uint type,const uint dt,const int _size,const T *_data=nullptr,uint level=GL_STATIC_DRAW):VertexBufferBase(type,dt,sizeof(T),C,_size,level) + { + count=_size; + + mem_type=(T *)GetData(); + access=0; + start=0; + + if(_data) + { + memcpy(mem_type,_data,this->total_bytes); + this->Update(); + } + } + + virtual ~VertexBuffer()=default; + + void SetCount(int _count) + { + count=_count; + + SetDataSize(_count*C*sizeof(T)); + + mem_type=(T *)GetData(); + access=0; + start=0; + } + + /** + * 取得数据区地址 + * @param offset 从第几个数据开始访问 + * @return 访问地址 + */ + T *Get(int offset=0) + { + if(!mem_type||offset>=count) + { + // LOG_HINT(OS_TEXT("VertexBuffer::Get() out,offset:")+OSString(offset)); + return(nullptr); + } + + return mem_type+offset*C; + } + + /** + * 开始访问数据区 + * @param offset 从第几个数据开始访问 + * @return 访问地址 + */ + void *Begin(int offset=0) + { + if(access) + { + // LOG_HINT(OS_TEXT("VertexBuffer::Begin() access!=0,offset:")+OSString(offset)); + return(nullptr); + } + + access=Get(offset); + + if(access) + start=access; + + return access; + } + + /** + * 结束访问 + */ + void End() + { + this->Change(((char *)start )-((char *)mem_type), + ((char *)access)-((char *)start), + start); + + access=nullptr; + start=nullptr; + } + + /** + * 写入指定数量的数据 + * @param vp 数据指针 + * @param number 数据数量 + */ + bool WriteData(const T *vp,const int number) + { + if(!this->access||this->access+C*number>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer::Write(const T *,number) out,number:")+OSString(number)); + return(false); + } + + memcpy(access,vp,C*number*sizeof(T)); + + access+=C*number; + + return(true); + } + };//class VertexBuffer + + /** + * 一元数据缓冲区 + */ + template class VertexBuffer1:public VertexBuffer + { + public: + + VertexBuffer1(const uint type,const int _size,const T *_data=nullptr,uint level=GL_STATIC_DRAW):VertexBuffer(type,DT,_size,_data,level){} + VertexBuffer1(const int _size,const T *_data=nullptr,uint level=GL_STATIC_DRAW):VertexBuffer(GL_ARRAY_BUFFER,DT,_size,_data,level){} + virtual ~VertexBuffer1()=default; + + bool Write(const T v1) + { + if(!this->access||this->access+1>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer1::Write(const T) out")); + return(false); + } + + *this->access++=v1; + return(true); + } + + /** + * 将一个值重复多次写入缓冲区 + * @param v 值 + * @param count 写入数量 + */ + bool WriteRepeat(const T v,const int count) + { + if(!this->access||this->access+count>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer1::Write(const T,")+OSString(count)+OS_TEXT(") out")); + return(false); + } + + hgl_set(this->access,v,count); + this->access+=count; + return(true); + } + };//class VertexBuffer1 + + /** + * 索引数据缓冲区 + */ + template class ElementBuffer:public VertexBuffer1 + { + public: + ElementBuffer(const int _size,const T *_data=nullptr,uint level=GL_STATIC_DRAW):VertexBuffer1(GL_ELEMENT_ARRAY_BUFFER,DT,_size,_data,level){} + virtual ~ElementBuffer()=default; + };// + + /** + * 二元数据缓冲区 + */ + template class VertexBuffer2:public VertexBuffer + { + public: + + VertexBuffer2(const int _size,const T *_data=nullptr,uint level=GL_STATIC_DRAW):VertexBuffer(GL_ARRAY_BUFFER,DT,_size,_data,level){} + virtual ~VertexBuffer2()=default; + + bool Write(const T v1,const T v2) + { + if(!this->access||this->access+2>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer2::Write(const T ,const T) out")); + return(false); + } + + *this->access++=v1; + *this->access++=v2; + + return(true); + } + + bool Write(const T *v) + { + if(!this->access||this->access+2>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer2::Write(T *) out")); + return(false); + } + + *this->access++=*v++; + *this->access++=*v; + + return(true); + } + + bool Write(const Vector2f &v) + { + if(!this->access||this->access+2>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer2::Write(vec2 &) out")); + return(false); + } + + *this->access++=v.x; + *this->access++=v.y; + + return(true); + } + + /** + * 将一个值重复多次写入缓冲区 + * @param v 值 + * @param count 写入数量 + */ + bool Write(const Vector2f &v,const int count) + { + if(!this->access||this->access+(count<<1)>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer1::Write(const Vector2f &,")+OSString(count)+OS_TEXT(") out")); + return(false); + } + + for(int i=0;iaccess++=v.x; + *this->access++=v.y; + } + + return(true); + } + + bool WriteLine(const T start_x,const T start_y,const T end_x,const T end_y) + { + if(!this->access||this->access+4>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer2::WriteLine(T,T,T,T) out")); + return(false); + } + + *this->access++=start_x; + *this->access++=start_y; + *this->access++=end_x; + *this->access++=end_y; + + return(true); + } + + bool WriteLine(const Vector2f &start,const Vector2f &end) + { + if(!this->access||this->access+4>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer2::WriteLine(vec2,vec2) out")); + return(false); + } + + *this->access++=start.x; + *this->access++=start.y; + *this->access++=end.x; + *this->access++=end.y; + + return(true); + } + + /** + * 写入2D三角形 + */ + bool WriteTriangle(const Vector2f &v1,const Vector2f &v2,const Vector2f &v3) + { + if(!this->access||this->access+6>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer2::WriteTriangle(vec2,vec2,vec2) out")); + return(false); + } + + *this->access++=v1.x; + *this->access++=v1.y; + + *this->access++=v2.x; + *this->access++=v2.y; + + *this->access++=v3.x; + *this->access++=v3.y; + + return(true); + } + + /** + * 写入2D三角形 + */ + bool WriteTriangle(const Vector2f *v) + { + if(!this->access||this->access+6>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer2::WriteTriangle(vec2 *) out")); + return(false); + } + + *this->access++=v->x; + *this->access++=v->y; + ++v; + + *this->access++=v->x; + *this->access++=v->y; + ++v; + + *this->access++=v->x; + *this->access++=v->y; + + return(true); + } + + /** + * 写入2D四边形坐标数据 + */ + bool WriteQuad(const Vector2f <,const Vector2f &rt,const Vector2f &rb,const Vector2f &lb) + { + if(WriteTriangle(lt,lb,rb)) + if(WriteTriangle(lt,rb,rt)) + return(true); + + // LOG_HINT(OS_TEXT("VertexBuffer2::WriteQuad(vec2 &,vec2 &,vec2 &,vec2 &) error")); + return(false); + } + + /** + * 写入2D矩形(两个三角形)坐标数据 + */ + bool WriteRect(const T left,const T top,const T width,const T height) + { + const Vector2f lt(left ,top); + const Vector2f rt(left+width,top); + const Vector2f rb(left+width,top+height); + const Vector2f lb(left ,top+height); + + return WriteQuad(lt,rt,rb,lb); + } + };//class VertexBuffer2 + + /** + * 三元数据缓冲区 + */ + template class VertexBuffer3:public VertexBuffer + { + public: + + VertexBuffer3(const int _size,const T *_data=nullptr,uint level=GL_STATIC_DRAW):VertexBuffer(GL_ARRAY_BUFFER,DT,_size,_data,level){} + virtual ~VertexBuffer3()=default; + + /** + * 计算绑定盒 + * @param min_vertex 最小值坐标 + * @param max_vertex 最大值坐标 + */ + template + void GetBoundingBox(V &min_vertex,V &max_vertex) + { + T *p=this->mem_type; + + //先以corner为最小值,length为最大值,求取最小最大值 + min_vertex.x=*p++; + min_vertex.y=*p++; + min_vertex.z=*p++; + + max_vertex=min_vertex; + + for(int i=1;icount;i++) + { + if(*pmax_vertex.x)max_vertex.x=*p; + ++p; + + if(*pmax_vertex.y)max_vertex.y=*p; + ++p; + + if(*pmax_vertex.z)max_vertex.z=*p; + ++p; + } + } + + bool Write(const T v1,const T v2,const T v3) + { + if(!this->access||this->access+3>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer3::Write(T,T,T) out")); + return(false); + } + + *this->access++=v1; + *this->access++=v2; + *this->access++=v3; + + return(true); + } + + bool Write(const T *v) + { + if(!this->access||this->access+3>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer3::Write(T *) out")); + return(false); + } + + *this->access++=*v++; + *this->access++=*v++; + *this->access++=*v; + + return(true); + } + + bool Write(const Vector3f &v) + { + if(!this->access||this->access+3>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer3::Write(vec3 &) out")); + return(false); + } + + *this->access++=v.x; + *this->access++=v.y; + *this->access++=v.z; + + return(true); + } + + bool Write(const Vector4f &v) + { + if(!this->access||this->access+3>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer3::Write(vec4 &) out")); + return(false); + } + + *this->access++=v.x; + *this->access++=v.y; + *this->access++=v.z; + + return(true); + } + + /** + * 将一个值重复多次写入缓冲区 + * @param v 值 + * @param count 写入数量 + */ + bool Write(const Vector3f &v,const int count) + { + if(!this->access||this->access+(count*3)>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer3::Write(const Vector3f,")+OSString(count)+OS_TEXT(") out")); + return(false); + } + + for(int i=0;iaccess++=v.x; + *this->access++=v.y; + *this->access++=v.z; + } + + return(true); + } + + bool Write(const Color3f &v) + { + if(!this->access||this->access+3>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer3::Write(color3f &) out")); + return(false); + } + + *this->access++=v.r; + *this->access++=v.g; + *this->access++=v.b; + + return(true); + } + + bool WriteLine(const T start_x,const T start_y,const T start_z,const T end_x,const T end_y,const T end_z) + { + if(!this->access||this->access+6>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer3::WriteLine(T,T,T,T,T,T) out")); + return(false); + } + + *this->access++=start_x; + *this->access++=start_y; + *this->access++=start_z; + *this->access++=end_x; + *this->access++=end_y; + *this->access++=end_z; + + return(true); + } + + bool WriteLine(const Vector3f &start,const Vector3f &end) + { + if(!this->access||this->access+6>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer3::WriteLine(vec3,vec3) out")); + return(false); + } + + *this->access++=start.x; + *this->access++=start.y; + *this->access++=start.z; + *this->access++=end.x; + *this->access++=end.y; + *this->access++=end.z; + + return(true); + } + + /** + * 写入3D三角形 + */ + bool WriteTriangle(const Vector3f &v1,const Vector3f &v2,const Vector3f &v3) + { + if(!this->access||this->access+9>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer3::WriteTriangle(vec3,vec3,vec3) out")); + return(false); + } + + *this->access++=v1.x; + *this->access++=v1.y; + *this->access++=v1.z; + + *this->access++=v2.x; + *this->access++=v2.y; + *this->access++=v2.z; + + *this->access++=v3.x; + *this->access++=v3.y; + *this->access++=v3.z; + + return(true); + } + + /** + * 写入3D三角形 + */ + bool WriteTriangle(const Vector3f *v) + { + if(!this->access||this->access+9>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer3::WriteTriangle(vec3 *) out")); + return(false); + } + + *this->access++=v->x; + *this->access++=v->y; + *this->access++=v->z; + ++v; + + *this->access++=v->x; + *this->access++=v->y; + *this->access++=v->z; + ++v; + + *this->access++=v->x; + *this->access++=v->y; + *this->access++=v->z; + + return(true); + } + + /** + * 写入3D四边形坐标数据 + */ + bool WriteQuad(const Vector3f <,const Vector3f &rt,const Vector3f &rb,const Vector3f &lb) + { + if(WriteTriangle(lt,lb,rb)) + if(WriteTriangle(lt,rb,rt)) + return(true); + + // LOG_HINT(OS_TEXT("VertexBuffer3::WriteQuad(vec3 &,vec3 &,vec3 &,vec3 &) error")); + return(false); + } + };//class VertexBuffer3 + + /** + * 四元数据缓冲区 + */ + template class VertexBuffer4:public VertexBuffer + { + public: + + VertexBuffer4(const int _size,const T *_data=nullptr,uint level=GL_STATIC_DRAW):VertexBuffer(GL_ARRAY_BUFFER,DT,_size,_data,level){} + virtual ~VertexBuffer4()=default; + + /** + * 计算绑定盒 + * @param min_vertex 最小值坐标 + * @param max_vertex 最大值坐标 + */ + template + void GetBoundingBox(V &min_vertex,V &max_vertex) + { + T *p=this->mem_type; + + //先以corner为最小值,length为最大值,求取最小最大值 + min_vertex.x=*p++; + min_vertex.y=*p++; + min_vertex.z=*p++; + + max_vertex=min_vertex; + + for(int i=1;icount;i++) + { + if(*pmax_vertex.x)max_vertex.x=*p; + ++p; + + if(*pmax_vertex.y)max_vertex.y=*p; + ++p; + + if(*pmax_vertex.z)max_vertex.z=*p; + ++p; + } + } + + bool Write(const T v1,const T v2,const T v3,const T v4) + { + if(!this->access||this->access+4>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer4::Write(T,T,T,T) out")); + return(false); + } + + *this->access++=v1; + *this->access++=v2; + *this->access++=v3; + *this->access++=v4; + + return(true); + } + + bool Write(const T *v) + { + if(!this->access||this->access+4>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer4::Write(T *) out")); + return(false); + } + + *this->access++=*v++; + *this->access++=*v++; + *this->access++=*v++; + *this->access++=*v; + + return(true); + } + + bool Write(const Vector4f &v) + { + if(!this->access||this->access+4>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer4::Write(color4 &) out")); + return(false); + } + + *this->access++=v.x; + *this->access++=v.y; + *this->access++=v.z; + *this->access++=v.w; + + return(true); + } + + bool Write(const Color4f &v) + { + if(!this->access||this->access+4>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer4::Write(color4 &) out")); + return(false); + } + + *this->access++=v.r; + *this->access++=v.g; + *this->access++=v.b; + *this->access++=v.a; + + return(true); + } + + /** + * 将一个值重复多次写入缓冲区 + * @param v 值 + * @param count 写入数量 + */ + bool Write(const Vector4f &v,const int count) + { + if(!this->access||this->access+(count<<2)>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer4::Write(const Vector4f,")+OSString(count)+OS_TEXT(") out")); + return(false); + } + + for(int i=0;iaccess++=v.x; + *this->access++=v.y; + *this->access++=v.z; + *this->access++=v.w; + } + + return(true); + } + + bool WriteLine(const T start_x,const T start_y,const T start_z,const T end_x,const T end_y,const T end_z) + { + if(!this->access||this->access+8>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer4::WriteLine(T,T,T,T,T,T) out")); + return(false); + } + + *this->access++=start_x; + *this->access++=start_y; + *this->access++=start_z; + *this->access++=1.0f; + *this->access++=end_x; + *this->access++=end_y; + *this->access++=end_z; + *this->access++=1.0f; + + return(true); + } + + bool WriteLine(const Vector3f &start,const Vector3f &end) + { + if(!this->access||this->access+8>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer4::WriteLine(vec3,vec3) out")); + return(false); + } + + *this->access++=start.x; + *this->access++=start.y; + *this->access++=start.z; + *this->access++=1.0f; + *this->access++=end.x; + *this->access++=end.y; + *this->access++=end.z; + *this->access++=1.0f; + + return(true); + } + + /** + * 写入3D三角形 + */ + bool WriteTriangle(const Vector3f &v1,const Vector3f &v2,const Vector3f &v3) + { + if(!this->access||this->access+12>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer4::WriteTriangle(vec3,vec3,vec3) out")); + return(false); + } + + *this->access++=v1.x; + *this->access++=v1.y; + *this->access++=v1.z; + *this->access++=1.0f; + + *this->access++=v2.x; + *this->access++=v2.y; + *this->access++=v2.z; + *this->access++=1.0f; + + *this->access++=v3.x; + *this->access++=v3.y; + *this->access++=v3.z; + *this->access++=1.0f; + + return(true); + } + + /** + * 写入3D三角形 + */ + bool WriteTriangle(const Vector3f *v) + { + if(!this->access||this->access+12>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer4::WriteTriangle(vec3 *) out")); + return(false); + } + + *this->access++=v->x; + *this->access++=v->y; + *this->access++=v->z; + *this->access++=1.0f; + ++v; + + *this->access++=v->x; + *this->access++=v->y; + *this->access++=v->z; + *this->access++=1.0f; + ++v; + + *this->access++=v->x; + *this->access++=v->y; + *this->access++=v->z; + *this->access++=1.0f; + + return(true); + } + + /** + * 写入2D矩形,注:这个函数会依次写入Left,Top,Width,Height四个值 + */ + template + bool WriteRectangle2D(const RectScope2 &rect) + { + if(!this->access||this->access+4>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer4::WriteRectangle2D(RectScope2 ) out")); + return(false); + } + + *this->access++=rect.Left; + *this->access++=rect.Top; + *this->access++=rect.Width; + *this->access++=rect.Height; + + return(true); + } + + /** + * 写入2D矩形,注:这个函数会依次写入Left,Top,Width,Height四个值 + */ + template + bool WriteRectangle2D(const RectScope2 *rect,const int count) + { + if(!this->access||this->access+(4*count)>this->mem_end) + { + // LOG_HINT(OS_TEXT("VertexBuffer4::WriteRectangle2D(RectScope2 *,count) out")); + return(false); + } + + for(int i=0;iaccess++=rect->Left; + *this->access++=rect->Top; + *this->access++=rect->Width; + *this->access++=rect->Height; + + ++rect; + } + + return(true); + } + };//class VertexBuffer4 + + //缓冲区具体数据类型定义 + using EB16=ElementBuffer; + using EB32=ElementBuffer; + + template + class ColorBufferBase:public BASE + { + protected: + + PixelCompoment color_compoment; + + public: + + const PixelCompoment GetColorCompoment()const{return color_compoment;} + + public: + + ColorBuferBase(const PixelCompoment &pc):color_compoment(pc){} + };// + +#define USING_VB1234(type,gl_type,short_name) using VB1##short_name=VertexBuffer1;using CB1##short_name=ColorBufferBase; \ + using VB2##short_name=VertexBuffer2; \ + using VB3##short_name=VertexBuffer3; \ + using VB4##short_name=VertexBuffer4; + + USING_VB1234(int8, GL_BYTE, i8) + USING_VB1234(int8, GL_BYTE, b) + USING_VB1234(int16, GL_SHORT, i16) + USING_VB1234(int16, GL_SHORT, s) + USING_VB1234(int32, GL_INT, i32) + USING_VB1234(int32, GL_INT, i) + + USING_VB1234(uint8, GL_UNSIGNED_BYTE, u8) + USING_VB1234(uint8, GL_UNSIGNED_BYTE, ub) + USING_VB1234(uint16,GL_UNSIGNED_SHORT, u16) + USING_VB1234(uint16,GL_UNSIGNED_SHORT, us) + USING_VB1234(uint32,GL_UNSIGNED_INT, u32) + USING_VB1234(uint32,GL_UNSIGNED_INT, ui) + + USING_VB1234(uint16,GL_HALF_FLOAT, hf) + USING_VB1234(uint16,GL_HALF_FLOAT, f16) + USING_VB1234(float, GL_FLOAT, f) + USING_VB1234(float, GL_FLOAT, f32) + USING_VB1234(double,GL_DOUBLE, d) + USING_VB1234(double,GL_DOUBLE, f64) + +#undef USING_VB1234 + + }//namespace graph +}//namespace hgl +#endif//HGL_VERTEX_BUFFER_OBJECT_INCLUDE diff --git a/inc/hgl/graph/VertexBufferBase.h b/discarded/VertexBufferBase.h similarity index 100% rename from inc/hgl/graph/VertexBufferBase.h rename to discarded/VertexBufferBase.h diff --git a/src/RenderDriver/VertexBufferControl.h b/discarded/VertexBufferControl.h similarity index 96% rename from src/RenderDriver/VertexBufferControl.h rename to discarded/VertexBufferControl.h index 775b8c6c..02bde812 100644 --- a/src/RenderDriver/VertexBufferControl.h +++ b/discarded/VertexBufferControl.h @@ -1,41 +1,41 @@ -#ifndef HGL_GRAPH_VERTEX_BUFFER_OBJECT_CONTROL_INCLUDE -#define HGL_GRAPH_VERTEX_BUFFER_OBJECT_CONTROL_INCLUDE - -#include -#include -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 +#include +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 diff --git a/src/RenderDriver/VertexBufferControlBind.cpp b/discarded/VertexBufferControlBind.cpp similarity index 96% rename from src/RenderDriver/VertexBufferControlBind.cpp rename to discarded/VertexBufferControlBind.cpp index f345fdbc..bd609fff 100644 --- a/src/RenderDriver/VertexBufferControlBind.cpp +++ b/discarded/VertexBufferControlBind.cpp @@ -1,58 +1,58 @@ -#include"VertexBufferControl.h" -#include - -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 + +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 diff --git a/src/RenderDriver/VertexBufferControlDSA.cpp b/discarded/VertexBufferControlDSA.cpp similarity index 96% rename from src/RenderDriver/VertexBufferControlDSA.cpp rename to discarded/VertexBufferControlDSA.cpp index 80e43494..6d26f633 100644 --- a/src/RenderDriver/VertexBufferControlDSA.cpp +++ b/discarded/VertexBufferControlDSA.cpp @@ -1,38 +1,38 @@ -#include"VertexBufferControl.h" -#include - -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 + +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 diff --git a/inc/hgl/graph/VertexBufferObject.h b/discarded/VertexBufferObject.h similarity index 100% rename from inc/hgl/graph/VertexBufferObject.h rename to discarded/VertexBufferObject.h