From 4e752f63b94b71d901a1933a1bb121332fffe96b Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 17 Feb 2017 10:09:49 -0800 Subject: [PATCH] [core] Redo approach to unsupported VAO extension --- src/mbgl/gl/context.cpp | 19 ++++++++++--------- src/mbgl/gl/context.hpp | 2 ++ src/mbgl/gl/segment.hpp | 17 +++++++++++------ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 5726eca5d..9c2031ccf 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -122,17 +122,17 @@ UniqueTexture Context::createTexture() { return UniqueTexture{ std::move(id), { this } }; } +bool Context::supportsVertexArrays() const { + return gl::GenVertexArrays && + gl::BindVertexArray && + gl::DeleteVertexArrays && + !disableVAOExtension; +} + UniqueVertexArray Context::createVertexArray() { + assert(supportsVertexArrays()); VertexArrayID id = 0; - if (gl::GenVertexArrays && !disableVAOExtension) { - MBGL_CHECK_ERROR(gl::GenVertexArrays(1, &id)); - } else { - static bool reported = false; - if (!reported) { - Log::Warning(Event::OpenGL, "Not using Vertex Array Objects"); - reported = true; - } - } + MBGL_CHECK_ERROR(gl::GenVertexArrays(1, &id)); return UniqueVertexArray(std::move(id), { this }); } @@ -529,6 +529,7 @@ void Context::performCleanup() { } if (!abandonedVertexArrays.empty()) { + assert(supportsVertexArrays()); for (const auto id : abandonedVertexArrays) { if (vertexArrayObject == id) { vertexArrayObject.setDirty(); diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index d1be79424..9d3ecec66 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -39,6 +39,8 @@ public: UniqueProgram createProgram(ShaderID vertexShader, ShaderID fragmentShader); void linkProgram(ProgramID); UniqueTexture createTexture(); + + bool supportsVertexArrays() const; UniqueVertexArray createVertexArray(); template diff --git a/src/mbgl/gl/segment.hpp b/src/mbgl/gl/segment.hpp index 7ce90e53a..b2761a210 100644 --- a/src/mbgl/gl/segment.hpp +++ b/src/mbgl/gl/segment.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -32,12 +33,11 @@ public: BufferID indexBuffer_, const typename Attributes::Locations& attributeLocations, const typename Attributes::Bindings& attributeBindings_) const { - if (!vao) { - vao = context.createVertexArray(); - context.vertexBuffer.setDirty(); - } - - if (*vao) { + if (context.supportsVertexArrays()) { + if (!vao) { + vao = context.createVertexArray(); + context.vertexBuffer.setDirty(); + } context.vertexArrayObject = *vao; if (indexBuffer != indexBuffer_) { indexBuffer = indexBuffer_; @@ -46,6 +46,11 @@ public: } } else { // No VAO support. Force attributes to be rebound. + static bool reported = false; + if (!reported) { + Log::Warning(Event::OpenGL, "Not using Vertex Array Objects"); + reported = true; + } context.elementBuffer = indexBuffer_; variableBindings = {}; }