Commit 76794587 authored by hybrid's avatar hybrid

Fix vertex color array when used together with VBOs and the vertex_array_bgra...

Fix vertex color array when used together with VBOs and the vertex_array_bgra extension. Thanks to Auria for pointing out this issue.
Also fixed two warnings mentioned by him.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3627 dfc29bdd-3216-0410-991c-e03cc46cb475
parent edf7c82e
...@@ -1257,7 +1257,7 @@ void COpenGLDriver::createOcclusionQuery(scene::ISceneNode* node, ...@@ -1257,7 +1257,7 @@ void COpenGLDriver::createOcclusionQuery(scene::ISceneNode* node,
CNullDriver::createOcclusionQuery(node, mesh); CNullDriver::createOcclusionQuery(node, mesh);
const s32 index = OcclusionQueries.linear_search(SOccQuery(node)); const s32 index = OcclusionQueries.linear_search(SOccQuery(node));
if ((index != -1) && (OcclusionQueries[index].UID == 0)) if ((index != -1) && (OcclusionQueries[index].UID == 0))
extGlGenQueries(1, &OcclusionQueries[index].UID); extGlGenQueries(1, reinterpret_cast<GLuint*>(&OcclusionQueries[index].UID));
} }
...@@ -1268,7 +1268,7 @@ void COpenGLDriver::removeOcclusionQuery(scene::ISceneNode* node) ...@@ -1268,7 +1268,7 @@ void COpenGLDriver::removeOcclusionQuery(scene::ISceneNode* node)
if (index != -1) if (index != -1)
{ {
if (OcclusionQueries[index].UID != 0) if (OcclusionQueries[index].UID != 0)
extGlDeleteQueries(1, &OcclusionQueries[index].UID); extGlDeleteQueries(1, reinterpret_cast<GLuint*>(&OcclusionQueries[index].UID));
CNullDriver::removeOcclusionQuery(node); CNullDriver::removeOcclusionQuery(node);
} }
} }
...@@ -1398,32 +1398,35 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun ...@@ -1398,32 +1398,35 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun
if ((pType!=scene::EPT_POINTS) && (pType!=scene::EPT_POINT_SPRITES)) if ((pType!=scene::EPT_POINTS) && (pType!=scene::EPT_POINT_SPRITES))
glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_NORMAL_ARRAY);
if (vertices)
{
//due to missing defines in OSX headers, we have to be more specific with this check //due to missing defines in OSX headers, we have to be more specific with this check
//#if defined(GL_ARB_vertex_array_bgra) || defined(GL_EXT_vertex_array_bgra) //#if defined(GL_ARB_vertex_array_bgra) || defined(GL_EXT_vertex_array_bgra)
#ifdef GL_BGRA #ifdef GL_BGRA
const GLint colorSize=(FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra])?GL_BGRA:4;
#else
const GLint colorSize=4;
#endif
if (vertices)
{
if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra])
{ {
switch (vType) switch (vType)
{ {
case EVT_STANDARD: case EVT_STANDARD:
glColorPointer(GL_BGRA, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Color); glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Color);
break; break;
case EVT_2TCOORDS: case EVT_2TCOORDS:
glColorPointer(GL_BGRA, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].Color); glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].Color);
break; break;
case EVT_TANGENTS: case EVT_TANGENTS:
glColorPointer(GL_BGRA, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Color); glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Color);
break; break;
} }
} }
else else
#endif
{ {
// avoid passing broken pointer to OpenGL // avoid passing broken pointer to OpenGL
_IRR_DEBUG_BREAK_IF(ColorBuffer.size()==0); _IRR_DEBUG_BREAK_IF(ColorBuffer.size()==0);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]);
} }
} }
...@@ -1439,7 +1442,7 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun ...@@ -1439,7 +1442,7 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun
else else
{ {
glNormalPointer(GL_FLOAT, sizeof(S3DVertex), buffer_offset(12)); glNormalPointer(GL_FLOAT, sizeof(S3DVertex), buffer_offset(12));
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertex), buffer_offset(24)); glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), buffer_offset(24));
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28)); glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28));
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), 0); glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex), 0);
} }
...@@ -1464,7 +1467,7 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun ...@@ -1464,7 +1467,7 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun
else else
{ {
glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(12)); glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(12));
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), buffer_offset(24)); glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), buffer_offset(24));
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(28)); glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(28));
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(0)); glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(0));
} }
...@@ -1490,7 +1493,7 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun ...@@ -1490,7 +1493,7 @@ void COpenGLDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCoun
else else
{ {
glNormalPointer(GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(12)); glNormalPointer(GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(12));
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), buffer_offset(24)); glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), buffer_offset(24));
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(28)); glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(28));
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(0)); glVertexPointer(3, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(0));
} }
...@@ -1724,32 +1727,35 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo ...@@ -1724,32 +1727,35 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo
if ((pType!=scene::EPT_POINTS) && (pType!=scene::EPT_POINT_SPRITES)) if ((pType!=scene::EPT_POINTS) && (pType!=scene::EPT_POINT_SPRITES))
glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (vertices)
{
//due to missing defines in OSX headers, we have to be more specific with this check //due to missing defines in OSX headers, we have to be more specific with this check
//#if defined(GL_ARB_vertex_array_bgra) || defined(GL_EXT_vertex_array_bgra) //#if defined(GL_ARB_vertex_array_bgra) || defined(GL_EXT_vertex_array_bgra)
#ifdef GL_BGRA #ifdef GL_BGRA
const GLint colorSize=(FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra])?GL_BGRA:4;
#else
const GLint colorSize=4;
#endif
if (vertices)
{
if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra]) if (FeatureAvailable[IRR_ARB_vertex_array_bgra] || FeatureAvailable[IRR_EXT_vertex_array_bgra])
{ {
switch (vType) switch (vType)
{ {
case EVT_STANDARD: case EVT_STANDARD:
glColorPointer(GL_BGRA, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Color); glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Color);
break; break;
case EVT_2TCOORDS: case EVT_2TCOORDS:
glColorPointer(GL_BGRA, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].Color); glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), &(static_cast<const S3DVertex2TCoords*>(vertices))[0].Color);
break; break;
case EVT_TANGENTS: case EVT_TANGENTS:
glColorPointer(GL_BGRA, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Color); glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), &(static_cast<const S3DVertexTangents*>(vertices))[0].Color);
break; break;
} }
} }
else else
#endif
{ {
// avoid passing broken pointer to OpenGL // avoid passing broken pointer to OpenGL
_IRR_DEBUG_BREAK_IF(ColorBuffer.size()==0); _IRR_DEBUG_BREAK_IF(ColorBuffer.size()==0);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]); glColorPointer(colorSize, GL_UNSIGNED_BYTE, 0, &ColorBuffer[0]);
} }
} }
...@@ -1763,7 +1769,7 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo ...@@ -1763,7 +1769,7 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo
} }
else else
{ {
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertex), buffer_offset(24)); glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex), buffer_offset(24));
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28)); glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex), buffer_offset(28));
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), 0); glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex), 0);
} }
...@@ -1786,7 +1792,7 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo ...@@ -1786,7 +1792,7 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo
} }
else else
{ {
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), buffer_offset(24)); glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), buffer_offset(24));
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(28)); glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(28));
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(0)); glVertexPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(0));
} }
...@@ -1809,7 +1815,7 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo ...@@ -1809,7 +1815,7 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo
} }
else else
{ {
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), buffer_offset(24)); glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertexTangents), buffer_offset(24));
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(28)); glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(28));
glVertexPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(0)); glVertexPointer(2, GL_FLOAT, sizeof(S3DVertexTangents), buffer_offset(0));
} }
......
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