From c960f74204a776e0f4956b60213d9006e44c66d8 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sun, 31 Mar 2019 21:16:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0GLBuffer::Create=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + inc/hgl/graph/BufferObject.h | 6 +++--- src/RenderDriver/BufferObject.cpp | 24 ++++++++++++++++++------ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34680546..91af3163 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 3.0) +SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE) PROJECT(ULRE) diff --git a/inc/hgl/graph/BufferObject.h b/inc/hgl/graph/BufferObject.h index 12c313f1..4d8feb7b 100644 --- a/inc/hgl/graph/BufferObject.h +++ b/inc/hgl/graph/BufferObject.h @@ -37,7 +37,7 @@ namespace hgl public: -// bool Create (GLsizeiptr,GLenum up); ///<创建数据区 + bool Create (GLsizeiptr); ///<创建数据区 bool Submit (void *,GLsizeiptr,GLenum up=GL_STATIC_DRAW); ///<提交数据 bool Submit (const BufferData *,GLenum up=GL_STATIC_DRAW); ///<提交数据 bool Change (void *,GLsizeiptr,GLsizeiptr); ///<修改数据 @@ -71,7 +71,7 @@ namespace hgl * @param user_pattern 数据存储区使用模式(GL_STATIC_DRAW,GL_DYNAMIC_DRAW等) * @param buf 数据缓冲区 */ - template + template inline BO *_CreateBufferObject(BD *buf=nullptr,const GLenum &user_pattern=GL_STATIC_DRAW) { BO *obj=new BO(); @@ -151,7 +151,7 @@ namespace hgl return _CreateBufferObject(data,size,user_pattern); \ } - //ps.在这里用宏了再用模板本是多此一举,但使用模板函数易于调试器中进行逐行调试,同时因为INLINE编译编译器也会自动展开代码,不用担心效率 + //ps.在这里用宏了再用模板本是多此一举,但使用模板函数易于调试器中进行逐行调试,同时因为INLINE编译编译器也会自动展开代码,不用担心效率 VBCLASS_DEF(GL_ARRAY_BUFFER, ArrayBuffer, VertexBufferObject, VertexBufferData, VBO) VBCLASS_DEF(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer, VertexBufferObject, VertexBufferData, EBO) diff --git a/src/RenderDriver/BufferObject.cpp b/src/RenderDriver/BufferObject.cpp index 093ece1c..078dbb7d 100644 --- a/src/RenderDriver/BufferObject.cpp +++ b/src/RenderDriver/BufferObject.cpp @@ -18,7 +18,7 @@ namespace hgl void BufferAlloc(GLenum type,GLuint index,GLsizeiptr size) { - glNamedBufferStorage(type,size,nullptr,GL_MAP_WRITE_BIT); + glNamedBufferStorage(index,size,nullptr,GL_MAP_WRITE_BIT); } void BufferData(GLenum type,GLuint index,void *data,GLsizeiptr size,GLenum user_pattern) @@ -66,6 +66,12 @@ namespace hgl return index; } + void BufferAlloc(GLenum type,GLuint index,GLsizeiptr size) + { + glBindBuffer(type,index); + glBufferStorage(type,size,nullptr,GL_MAP_WRITE_BIT); + } + void BufferData(GLenum type,GLuint index,void *data,GLsizeiptr size,GLenum user_pattern) { glBindBuffer(type,index); @@ -80,6 +86,7 @@ namespace hgl } static GLuint(*CreateBuffer)(); + static void(*BufferAlloc)(GLenum type,GLuint index,GLsizeiptr size); static void(*BufferData)(GLenum type,GLuint index,void *data,GLsizeiptr size,GLenum user_pattern); static void(*BufferSubData)(GLenum type,GLuint index,void *data,GLsizeiptr start,GLsizeiptr size); @@ -90,6 +97,7 @@ namespace hgl ||glNamedBufferSubData) //dsa { hgl::graph::gl::CreateBuffer=dsa::CreateBuffer; + hgl::graph::gl::BufferAlloc=dsa::BufferAlloc; hgl::graph::gl::BufferData=dsa::BufferData; hgl::graph::gl::BufferSubData=dsa::BufferSubData; } @@ -98,12 +106,14 @@ namespace hgl ||glNamedBufferSubDataEXT) { hgl::graph::gl::CreateBuffer=bind::CreateBuffer; + hgl::graph::gl::BufferAlloc=dsa_ext::BufferAlloc; hgl::graph::gl::BufferData=dsa_ext::BufferData; hgl::graph::gl::BufferSubData=dsa_ext::BufferSubData; } else { hgl::graph::gl::CreateBuffer=bind::CreateBuffer; + hgl::graph::gl::BufferAlloc=bind::BufferAlloc; hgl::graph::gl::BufferData=bind::BufferData; hgl::graph::gl::BufferSubData=bind::BufferSubData; } @@ -127,12 +137,14 @@ namespace hgl glDeleteBuffers(1,&buffer_index); } - //bool BufferObject::Create(GLsizeiptr size,GLenum up) - //{ - // if(size<=0)return(false); + bool BufferObject::Create(GLsizeiptr size) + { + if(size<=0)return(false); - // return true; - //} + gl::BufferAlloc(buffer_type,buffer_index,size); + + return true; + } bool BufferObject::Submit(void *data,GLsizeiptr size,GLenum up) {