Commit f0b8a7e9 authored by hybrid's avatar hybrid

Add support for vertex_array_bgra extension in OpenGL driver. This will speed...

Add support for vertex_array_bgra extension in OpenGL driver. This will speed up OpenGL rendering quite a lot as it skips the silly color conversion thing we have to do otherwise. Still a little clumsy implementation, but the speed gain is worth this.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3258 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 95680f93
...@@ -930,9 +930,14 @@ bool COpenGLDriver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) ...@@ -930,9 +930,14 @@ bool COpenGLDriver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer)
const E_VERTEX_TYPE vType=mb->getVertexType(); const E_VERTEX_TYPE vType=mb->getVertexType();
const u32 vertexSize = getVertexPitchFromType(vType); const u32 vertexSize = getVertexPitchFromType(vType);
const c8* vbuf = static_cast<const c8*>(vertices);
core::array<c8> buffer;
if (!FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
{
//buffer vertex data, and convert colours... //buffer vertex data, and convert colours...
core::array<c8> buffer(vertexSize * vertexCount); buffer.set_used(vertexSize * vertexCount);
memcpy(buffer.pointer(), vertices, vertexSize * vertexCount); memcpy(buffer.pointer(), vertices, vertexSize * vertexCount);
vbuf = buffer.const_pointer();
// in order to convert the colors into opengl format (RGBA) // in order to convert the colors into opengl format (RGBA)
switch (vType) switch (vType)
...@@ -972,6 +977,7 @@ bool COpenGLDriver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) ...@@ -972,6 +977,7 @@ bool COpenGLDriver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer)
return false; return false;
} }
} }
}
//get or create buffer //get or create buffer
bool newBuffer=false; bool newBuffer=false;
...@@ -992,17 +998,17 @@ bool COpenGLDriver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer) ...@@ -992,17 +998,17 @@ bool COpenGLDriver::updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer)
//copy data to graphics card //copy data to graphics card
glGetError(); // clear error storage glGetError(); // clear error storage
if (!newBuffer) if (!newBuffer)
extGlBufferSubData(GL_ARRAY_BUFFER, 0, vertexCount * vertexSize, buffer.const_pointer()); extGlBufferSubData(GL_ARRAY_BUFFER, 0, vertexCount * vertexSize, vbuf);
else else
{ {
HWBuffer->vbo_verticesSize = vertexCount*vertexSize; HWBuffer->vbo_verticesSize = vertexCount*vertexSize;
if (HWBuffer->Mapped_Vertex==scene::EHM_STATIC) if (HWBuffer->Mapped_Vertex==scene::EHM_STATIC)
extGlBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, buffer.const_pointer(), GL_STATIC_DRAW); extGlBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, vbuf, GL_STATIC_DRAW);
else if (HWBuffer->Mapped_Vertex==scene::EHM_DYNAMIC) else if (HWBuffer->Mapped_Vertex==scene::EHM_DYNAMIC)
extGlBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, buffer.const_pointer(), GL_DYNAMIC_DRAW); extGlBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, vbuf, GL_DYNAMIC_DRAW);
else //scene::EHM_STREAM else //scene::EHM_STREAM
extGlBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, buffer.const_pointer(), GL_STREAM_DRAW); extGlBufferData(GL_ARRAY_BUFFER, vertexCount * vertexSize, vbuf, GL_STREAM_DRAW);
} }
extGlBindBuffer(GL_ARRAY_BUFFER, 0); extGlBindBuffer(GL_ARRAY_BUFFER, 0);
...@@ -1241,7 +1247,7 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun ...@@ -1241,7 +1247,7 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun
CNullDriver::drawVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType); CNullDriver::drawVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType);
if (vertices) if (vertices && !FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
createColorBuffer(vertices, vertexCount, vType); createColorBuffer(vertices, vertexCount, vType);
// draw everything // draw everything
...@@ -1258,7 +1264,27 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun ...@@ -1258,7 +1264,27 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun
glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_NORMAL_ARRAY);
if (vertices) if (vertices)
{
#if defined(GL_ARB_vertex_array_bgra) || defined(GL_EXT_vertex_array_bgra)
if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra])
{
switch (vType)
{
case EVT_STANDARD:
glColorPointer(GL_BGRA, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Color);
break;
case EVT_2TCOORDS:
glColorPointer(GL_BGRA, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].Color);
break;
case EVT_TANGENTS:
glColorPointer(GL_BGRA, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Color);
break;
}
}
else
#endif
glColorPointer(4, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); glColorPointer(4, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]);
}
switch (vType) switch (vType)
{ {
...@@ -1532,7 +1558,7 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo ...@@ -1532,7 +1558,7 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo
CNullDriver::draw2DVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType); CNullDriver::draw2DVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType);
if (vertices) if (vertices && !FeatureAvailable[IRR_ARB_vertex_array_bgra] && !FeatureAvailable[IRR_EXT_vertex_array_bgra])
createColorBuffer(vertices, vertexCount, vType); createColorBuffer(vertices, vertexCount, vType);
// draw everything // draw everything
...@@ -1558,7 +1584,27 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo ...@@ -1558,7 +1584,27 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo
glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (vertices) if (vertices)
{
#if defined(GL_ARB_vertex_array_bgra) || defined(GL_EXT_vertex_array_bgra)
if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra])
{
switch (vType)
{
case EVT_STANDARD:
glColorPointer(GL_BGRA, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Color);
break;
case EVT_2TCOORDS:
glColorPointer(GL_BGRA, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].Color);
break;
case EVT_TANGENTS:
glColorPointer(GL_BGRA, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Color);
break;
}
}
else
#endif
glColorPointer(4, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); glColorPointer(4, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]);
}
switch (vType) switch (vType)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment