Browse Source

Made the openGL 2D renderer limit the size of its vertex buffers to avoid problems on systems with limited GPUs

tags/2021-05-28
jules 7 years ago
parent
commit
a9bc970ff8
2 changed files with 23 additions and 4 deletions
  1. +4
    -0
      modules/juce_opengl/native/juce_MissingGLDefinitions.h
  2. +19
    -4
      modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp

+ 4
- 0
modules/juce_opengl/native/juce_MissingGLDefinitions.h View File

@@ -92,6 +92,10 @@ enum MissingOpenGLDefinitions
GL_MULTISAMPLE = 0x809D,
#endif
#ifndef GL_MAX_ELEMENTS_INDICES
GL_MAX_ELEMENTS_INDICES = 0x80E9,
#endif
#if JUCE_WINDOWS && ! defined (GL_TEXTURE0)
GL_OPERAND0_RGB = 0x8590,
GL_OPERAND1_RGB = 0x8591,


+ 19
- 4
modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp View File

@@ -1171,6 +1171,15 @@ struct StateHelpers
{
JUCE_CHECK_OPENGL_ERROR
#if JUCE_ANDROID || JUCE_IOS
int numQuads = maxNumQuads;
#else
GLint maxIndices = 0;
glGetIntegerv (GL_MAX_ELEMENTS_INDICES, &maxIndices);
auto numQuads = jmin ((int) maxNumQuads, (int) maxIndices / 6);
maxVertices = numQuads * 4 - 4;
#endif
for (int i = 0, v = 0; i < numQuads * 6; i += 6, v += 4)
{
indexData[i] = (GLushort) v;
@@ -1212,7 +1221,7 @@ struct StateHelpers
numVertices += 4;
if (numVertices > numQuads * 4 - 4)
if (numVertices > maxVertices)
draw();
}
@@ -1264,14 +1273,20 @@ struct StateHelpers
GLuint colour;
};
enum { numQuads = 256 };
enum { maxNumQuads = 256 };
GLuint buffers[2];
VertexInfo vertexData[numQuads * 4];
GLushort indexData[numQuads * 6];
VertexInfo vertexData[maxNumQuads * 4];
GLushort indexData[maxNumQuads * 6];
const OpenGLContext& context;
int numVertices = 0;
#if JUCE_ANDROID || JUCE_IOS
enum { maxVertices = maxNumQuads * 4 - 4 };
#else
int maxVertices = 0;
#endif
void draw() noexcept
{
context.extensions.glBufferSubData (GL_ARRAY_BUFFER, 0, (GLsizeiptr) ((size_t) numVertices * sizeof (VertexInfo)), vertexData);


Loading…
Cancel
Save