diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl.h b/code/nel/src/3d/driver/opengl3/driver_opengl.h index 8a188ff17..e7fc173db 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl.h +++ b/code/nel/src/3d/driver/opengl3/driver_opengl.h @@ -1132,6 +1132,7 @@ private: // The VertexBufferHardGL activated. IVertexBufferGL *_CurrentVertexBufferGL; bool _SlowUnlockVBHard; + GLenum vertexBufferUsageGL3(CVertexBuffer::TPreferredMemory usage); // Handle lost buffers void updateLostBuffers(); diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_vertex.cpp b/code/nel/src/3d/driver/opengl3/driver_opengl_vertex.cpp index 6295d2f15..a30e42682 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_vertex.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_vertex.cpp @@ -121,12 +121,24 @@ bool CDriverGL3::setupVertexBuffer(CVertexBuffer& VB) CVBDrvInfosGL3 *info = new CVBDrvInfosGL3(this, it, &VB); *it= VB.DrvInfos = info; - // Preferred memory - CVertexBuffer::TPreferredMemory preferred = VB.getPreferredMemory (); - if ((preferred == CVertexBuffer::RAMVolatile) || - (preferred == CVertexBuffer::AGPVolatile) || - (preferred == CVertexBuffer::RAMPreferred)) - preferred = CVertexBuffer::AGPPreferred; + // Preferred memory, reduce choices + CVertexBuffer::TPreferredMemory preferred = VB.getPreferredMemory(); + CVertexBuffer::TLocation location; + switch (preferred) + { + case CVertexBuffer::StaticPreferred: + if (getStaticMemoryToVRAM()) + location = CVertexBuffer::VRAMResident; + else + location = CVertexBuffer::AGPResident; + case CVertexBuffer::RAMVolatile: + case CVertexBuffer::RAMPreferred: + location = CVertexBuffer::RAMResident; + case CVertexBuffer::AGPPreferred: + case CVertexBuffer::AGPVolatile: + default: + location = CVertexBuffer::AGPResident; + } const uint size = VB.capacity()*VB.getVertexSize(); @@ -134,7 +146,7 @@ bool CDriverGL3::setupVertexBuffer(CVertexBuffer& VB) info->_VBHard = createVertexBufferGL(size, VB.capacity(), preferred, &VB); // Upload the data - VB.setLocation ((CVertexBuffer::TLocation)preferred); + VB.setLocation(location); } } @@ -209,7 +221,7 @@ bool CDriverGL3::activeIndexBuffer(CIndexBuffer& IB) bool CDriverGL3::supportVolatileVertexBuffer() const { H_AUTO_OGL(CDriverGL3_supportVolatileVertexBuffer) - return false; // TODO VERTEXBUFFER PINNED + return true; // TODO VERTEXBUFFER PINNED } @@ -229,6 +241,23 @@ uint CDriverGL3::getMaxVerticesByVertexBufferHard() const return std::numeric_limits::max(); } +GLenum CDriverGL3::vertexBufferUsageGL3(CVertexBuffer::TPreferredMemory usage) +{ + switch (usage) + { + case CVertexBuffer::RAMPreferred: + case CVertexBuffer::AGPPreferred: + return GL_DYNAMIC_DRAW; + case CVertexBuffer::StaticPreferred: + return getStaticMemoryToVRAM() ? GL_STATIC_DRAW : GL_DYNAMIC_DRAW; + case CVertexBuffer::RAMVolatile: + case CVertexBuffer::AGPVolatile: + return GL_STREAM_DRAW; + default: + nlerror("Invalid preferred memory"); + return GL_DYNAMIC_DRAW; + } +} // *************************************************************************** IVertexBufferGL *CDriverGL3::createVertexBufferGL(uint size, uint numVertices, CVertexBuffer::TPreferredMemory vbType, CVertexBuffer *vb) @@ -239,21 +268,7 @@ IVertexBufferGL *CDriverGL3::createVertexBufferGL(uint size, uint numVertices, C GLuint vertexBufferID; nglGenBuffers(1, &vertexBufferID); _DriverGLStates.forceBindARBVertexBuffer(vertexBufferID); - switch (vbType) - { - case CVertexBuffer::AGPPreferred: - nglBufferData(GL_ARRAY_BUFFER, size, NULL, GL_DYNAMIC_DRAW); - break; - case CVertexBuffer::StaticPreferred: - if (getStaticMemoryToVRAM()) - nglBufferData(GL_ARRAY_BUFFER, size, NULL, GL_STATIC_DRAW); - else - nglBufferData(GL_ARRAY_BUFFER, size, NULL, GL_DYNAMIC_DRAW); - break; - default: - nlassert(0); - break; - } + nglBufferData(GL_ARRAY_BUFFER, size, NULL, vertexBufferUsageGL3(vbType)); CVertexBufferGL *newVbHard = new CVertexBufferGL(this, vb); newVbHard->initGL(vertexBufferID, vbType); _DriverGLStates.forceBindARBVertexBuffer(0); diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_buffer.cpp b/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_buffer.cpp index f3ccf0a38..eac2459e5 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_buffer.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_buffer.cpp @@ -108,21 +108,7 @@ void *CVertexBufferGL::lock() } const uint size = VB->getNumVertices() * VB->getVertexSize(); m_Driver->_DriverGLStates.forceBindARBVertexBuffer(vertexBufferID); - switch(m_MemType) - { - case CVertexBuffer::AGPPreferred: - nglBufferData(GL_ARRAY_BUFFER, size, NULL, GL_DYNAMIC_DRAW); - break; - case CVertexBuffer::StaticPreferred: - if (m_Driver->getStaticMemoryToVRAM()) - nglBufferData(GL_ARRAY_BUFFER, size, NULL, GL_STATIC_DRAW); - else - nglBufferData(GL_ARRAY_BUFFER, size, NULL, GL_DYNAMIC_DRAW); - break; - default: - nlassert(0); - break; - } + nglBufferData(GL_ARRAY_BUFFER, size, NULL, m_Driver->vertexBufferUsageGL3(m_MemType)); if (glGetError() != GL_NO_ERROR) { m_Driver->incrementResetCounter();