Skip to content

Commit

Permalink
UPBGE: Use ARB OpenGL for functions higher than 3.0.
Browse files Browse the repository at this point in the history
Functions like glVertexAttribDivisor and glDraw[Arrays/Elements]Instanced
are requiering OpenGL 3.0/3, but some GPU could not offer it and so they
must use the ARB extension instead.
  • Loading branch information
panzergame committed Jan 1, 2018
1 parent 0414529 commit ae062f8
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ inline static void attribVector(unsigned short loc, unsigned short stride, intpt
{
glEnableVertexAttribArray(loc);
glVertexAttribPointer(loc, size, GL_FLOAT, false, stride, (const void *)offset);
glVertexAttribDivisor(loc, divisor);
glVertexAttribDivisorARB(loc, divisor);
}

inline static void attribMatrix(unsigned short loc, unsigned short stride, intptr_t offset, unsigned short size, unsigned short divisor)
{
for (unsigned short i = 0; i < size; ++i) {
glEnableVertexAttribArray(loc + i);
glVertexAttribPointer(loc + i, size, GL_FLOAT, false, stride, (const void *)(offset + size * i * sizeof(float)));
glVertexAttribDivisor(loc + i, divisor);
glVertexAttribDivisorARB(loc + i, divisor);
}
}

Expand Down Expand Up @@ -112,13 +112,12 @@ RAS_OpenGLDebugDraw::RAS_OpenGLDebugDraw()
static const unsigned short stride = sizeof(RAS_DebugDraw::Line) / 2;
const unsigned int pos = GPU_shader_get_attribute(m_colorShader, "pos");
const unsigned int color = GPU_shader_get_attribute(m_colorShader, "color");

glBindBuffer(GL_ARRAY_BUFFER, m_vbos[LINES_VBO]);
attribVector(pos, stride, offsetof(RAS_DebugDraw::Line, m_from), 3, 0);
attribVector(color, stride, offsetof(RAS_DebugDraw::Line, m_color), 4, 0);
}


static const unsigned short frustumStride = sizeof(RAS_DebugDraw::Frustum);

glBindVertexArray(m_vaos[FRUSTUMS_LINE_VAO]);
Expand Down Expand Up @@ -222,11 +221,11 @@ void RAS_OpenGLDebugDraw::Flush(RAS_Rasterizer *rasty, RAS_ICanvas *canvas, RAS_

glBindVertexArray(m_vaos[FRUSTUMS_LINE_VAO]);
GPU_shader_bind(m_frustumLineShader);
glDrawElementsInstanced(GL_LINES, 24, GL_UNSIGNED_BYTE, nullptr, numfrustums);
glDrawElementsInstancedARB(GL_LINES, 24, GL_UNSIGNED_BYTE, nullptr, numfrustums);

glBindVertexArray(m_vaos[FRUSTUMS_SOLID_VAO]);
GPU_shader_bind(m_frustumSolidShader);
glDrawElementsInstanced(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, (const void *)(sizeof(GLubyte) * 24), numfrustums);
glDrawElementsInstancedARB(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, (const void *)(sizeof(GLubyte) * 24), numfrustums);
}

const std::vector<RAS_DebugDraw::Aabb>& aabbs = debugDraw->m_aabbs;
Expand All @@ -236,7 +235,7 @@ void RAS_OpenGLDebugDraw::Flush(RAS_Rasterizer *rasty, RAS_ICanvas *canvas, RAS_

glBindVertexArray(m_vaos[AABB_VAO]);
GPU_shader_bind(m_frustumLineShader);
glDrawElementsInstanced(GL_LINES, 24, GL_UNSIGNED_BYTE, nullptr, numaabbs);
glDrawElementsInstancedARB(GL_LINES, 24, GL_UNSIGNED_BYTE, nullptr, numaabbs);
}

const unsigned int width = canvas->GetWidth();
Expand All @@ -261,7 +260,7 @@ void RAS_OpenGLDebugDraw::Flush(RAS_Rasterizer *rasty, RAS_ICanvas *canvas, RAS_

glBindVertexArray(m_vaos[BOX_2D_VAO]);
GPU_shader_bind(m_box2dShader);
glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, numboxes);
glDrawArraysInstancedARB(GL_TRIANGLE_FAN, 0, 4, numboxes);
}

glBindVertexArray(0);
Expand Down

0 comments on commit ae062f8

Please sign in to comment.