diff --git a/sources/ewol/renderer/ResourceManager.cpp b/sources/ewol/renderer/ResourceManager.cpp index 4f3b55e0..64977c9f 100644 --- a/sources/ewol/renderer/ResourceManager.cpp +++ b/sources/ewol/renderer/ResourceManager.cpp @@ -336,7 +336,7 @@ bool ewol::resource::Keep(etk::UString& filename, ewol::MeshObj*& object) } -bool ewol::resource::Keep(etk::UString& accesMode, ewol::VirtualBufferObject*& object) +bool ewol::resource::Keep(const etk::UString& accesMode, ewol::VirtualBufferObject*& object) { // this element create a new one every time .... object = new ewol::VirtualBufferObject(accesMode); @@ -458,3 +458,10 @@ void ewol::resource::Release(ewol::Colored3DObject*& object) Release(object2); object = NULL; } + +void ewol::resource::Release(ewol::VirtualBufferObject*& object) +{ + ewol::Resource* object2 = static_cast(object); + Release(object2); + object = NULL; +} diff --git a/sources/ewol/renderer/ResourceManager.h b/sources/ewol/renderer/ResourceManager.h index 520116f0..f68b0ba2 100644 --- a/sources/ewol/renderer/ResourceManager.h +++ b/sources/ewol/renderer/ResourceManager.h @@ -72,7 +72,7 @@ namespace ewol bool Keep(etk::UString& filename, ewol::Shader*& object); bool Keep(ewol::Texture*& object); // no name needed here ... bool Keep(etk::UString& filename, ewol::TextureFile*& object, ivec2 size); - bool Keep(etk::UString& accesMode, ewol::VirtualBufferObject*& object); + bool Keep(const etk::UString& accesMode, ewol::VirtualBufferObject*& object); bool Keep(etk::UString& filename, ewol::MeshObj*& object); bool Keep(etk::UString& filename, ewol::ConfigFile*& object); bool Keep(ewol::Colored3DObject*& object); diff --git a/sources/ewol/renderer/resources/Mesh.cpp b/sources/ewol/renderer/resources/Mesh.cpp index 4d8ec169..a97dd4f0 100644 --- a/sources/ewol/renderer/resources/Mesh.cpp +++ b/sources/ewol/renderer/resources/Mesh.cpp @@ -25,6 +25,7 @@ ewol::Mesh::Mesh(etk::UString genName) : m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation"); m_GLtexID = m_GLprogram->GetUniform("EW_texID"); } + //ewol::resource::Keep("w", m_verticesVBO); } ewol::Mesh::~Mesh(void) @@ -34,6 +35,7 @@ ewol::Mesh::~Mesh(void) ewol::resource::Release(m_texture1); } ewol::resource::Release(m_GLprogram); + //ewol::resource::Release(m_verticesVBO); } diff --git a/sources/ewol/renderer/resources/Mesh.h b/sources/ewol/renderer/resources/Mesh.h index d2e2c21e..1c35c05c 100644 --- a/sources/ewol/renderer/resources/Mesh.h +++ b/sources/ewol/renderer/resources/Mesh.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace ewol { @@ -28,6 +29,7 @@ namespace ewol int32_t m_GLtexID; public: etk::Vector m_indices; + ewol::VirtualBufferObject* m_verticesVBO; etk::Vector m_vertices; etk::Vector m_uvTextures; etk::Vector m_normals; diff --git a/sources/ewol/renderer/resources/MeshObj.cpp b/sources/ewol/renderer/resources/MeshObj.cpp index 73a76822..20ee2422 100644 --- a/sources/ewol/renderer/resources/MeshObj.cpp +++ b/sources/ewol/renderer/resources/MeshObj.cpp @@ -181,6 +181,9 @@ ewol::MeshObj::MeshObj(etk::UString _fileName) : // Put the attributes in buffers m_vertices.PushBack(vertices[vertexIndex-1]); + m_verticesVBO->GetRefBuffer().PushBack(vertices[vertexIndex-1].x); + m_verticesVBO->GetRefBuffer().PushBack(vertices[vertexIndex-1].y); + m_verticesVBO->GetRefBuffer().PushBack(vertices[vertexIndex-1].z); m_uvTextures.PushBack(uvTextures[uvIndex-1]); draw::Color tmpppp(0xFFFFFFFF); draw::Colorf tmppppp(tmpppp); @@ -191,6 +194,7 @@ ewol::MeshObj::MeshObj(etk::UString _fileName) : m_normals.PushBack(normals[normalIndex-1]); } } + m_verticesVBO->Flush(); } diff --git a/sources/ewol/renderer/resources/VirtualBufferObject.cpp b/sources/ewol/renderer/resources/VirtualBufferObject.cpp index 274c288f..6c4e1658 100644 --- a/sources/ewol/renderer/resources/VirtualBufferObject.cpp +++ b/sources/ewol/renderer/resources/VirtualBufferObject.cpp @@ -12,20 +12,13 @@ -ewol::VirtualBufferObject::VirtualBufferObject(etk::UString& accesMode): +ewol::VirtualBufferObject::VirtualBufferObject(const etk::UString& accesMode): ewol::Resource(), m_exist(false), m_vbo(0) { m_resourceLevel = 3; - EWOL_DEBUG("OGL : load VBO mode\"" << accesMode << "\""); - // load data from file "all the time ..." - - /* - glGenBuffers(1, &m_vbo); - glBindBuffer(GL_ARRAY_BUFFER, m_vbo); - glBufferData(GL_ARRAY_BUFFER, sizeof(cube_vertices), cube_vertices, GL_STATIC_DRAW); - */ + EWOL_DEBUG("OGL : load VBO mode=\"" << accesMode << "\""); } @@ -48,16 +41,24 @@ void ewol::VirtualBufferObject::UpdateContext(void) if (m_buffer.Size()<=0) { RemoveContext(); } else { + EWOL_INFO("VBO: Update [" << m_uniqueId << "]=" << m_buffer.Size() << "*sizeof(float) OGl_Id=" << m_vbo); glBindBuffer(GL_ARRAY_BUFFER, m_vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(float)*m_buffer.Size(), &m_buffer[0], GL_STATIC_DRAW); + // } } else { // create the Buffer if (m_buffer.Size()>0) { + // Allocate and assign a Vertex Array Object to our handle + glGenVertexArrays(1, &m_vao); glGenBuffers(1, &m_vbo); + EWOL_INFO("VBO: Add [" << m_uniqueId << "]=" << m_buffer.Size() << "*sizeof(float) OGl_Id=" << m_vbo); m_exist = true; glBindBuffer(GL_ARRAY_BUFFER, m_vbo); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glBufferData(GL_ARRAY_BUFFER, sizeof(float)*m_buffer.Size(), &m_buffer[0], GL_STATIC_DRAW); + //glEnableVertexAttribArray(0); + //glDisableVertexAttribArray(0); } // Note we did not create the buffer when no data is needed } @@ -66,6 +67,7 @@ void ewol::VirtualBufferObject::UpdateContext(void) void ewol::VirtualBufferObject::RemoveContext(void) { if (true==m_exist) { + EWOL_INFO("VBO: Remove [" << m_uniqueId << "]=" << m_buffer.Size() << "*sizeof(float) OGl_Id=" << m_vbo); glDeleteBuffers(1, &m_vbo); m_exist = false; m_vbo = 0; diff --git a/sources/ewol/renderer/resources/VirtualBufferObject.h b/sources/ewol/renderer/resources/VirtualBufferObject.h index b5c3cab1..be83db5a 100644 --- a/sources/ewol/renderer/resources/VirtualBufferObject.h +++ b/sources/ewol/renderer/resources/VirtualBufferObject.h @@ -25,13 +25,14 @@ namespace ewol private : bool m_exist; //!< This data is availlable in the Graphic card GLuint m_vbo; //!< OpenGl ID of this VBO + GLuint m_vao; etk::Vector m_buffer; //!< data that is availlable in the VBO system ... public: /** * @brief Constructor of this VBO. * @param[in] accesMode Acces mode : ??? */ - VirtualBufferObject(etk::UString& accesMode); + VirtualBufferObject(const etk::UString& accesMode); /** * @brief Destructor of this VBO. */ @@ -58,7 +59,7 @@ namespace ewol /** * @brief Send the data to the graphic card. */ - void Flush(void) {}; + void Flush(void) { UpdateContext(); }; /** * @brief This load/reload the data in the opengl context, needed when removed previously. */