From 0bbc6b814cbec44be7026a0bac83d56e4d71a287 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 8 Feb 2017 15:57:58 -0800 Subject: [core] Restore support for GL implementations without VAO extension --- src/mbgl/gl/context.cpp | 14 +++++++++----- src/mbgl/gl/context.hpp | 4 ++++ src/mbgl/gl/segment.hpp | 15 ++++++++++----- test/fixtures/map/no_vao/expected.png | Bin 0 -> 9832 bytes test/map/map.test.cpp | 19 +++++++++++++++++++ 5 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 test/fixtures/map/no_vao/expected.png diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index a74e941bc6..5726eca5dc 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -123,12 +123,16 @@ UniqueTexture Context::createTexture() { } UniqueVertexArray Context::createVertexArray() { - if (!gl::GenVertexArrays) { - throw std::runtime_error("GL_ARB_vertex_array_object extension is required"); - } - VertexArrayID id = 0; - MBGL_CHECK_ERROR(gl::GenVertexArrays(1, &id)); + 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; + } + } return UniqueVertexArray(std::move(id), { this }); } diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index 636dfc9eac..d1be794240 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -222,6 +222,10 @@ private: std::vector abandonedVertexArrays; std::vector abandonedFramebuffers; std::vector abandonedRenderbuffers; + +public: + // For testing + bool disableVAOExtension = false; }; } // namespace gl diff --git a/src/mbgl/gl/segment.hpp b/src/mbgl/gl/segment.hpp index bb9f2f1ee8..7ce90e53a6 100644 --- a/src/mbgl/gl/segment.hpp +++ b/src/mbgl/gl/segment.hpp @@ -37,12 +37,17 @@ public: context.vertexBuffer.setDirty(); } - context.vertexArrayObject = *vao; - - if (indexBuffer != indexBuffer_) { - indexBuffer = indexBuffer_; - context.elementBuffer.setDirty(); + if (*vao) { + context.vertexArrayObject = *vao; + if (indexBuffer != indexBuffer_) { + indexBuffer = indexBuffer_; + context.elementBuffer.setDirty(); + context.elementBuffer = indexBuffer_; + } + } else { + // No VAO support. Force attributes to be rebound. context.elementBuffer = indexBuffer_; + variableBindings = {}; } Attributes::bind(context, diff --git a/test/fixtures/map/no_vao/expected.png b/test/fixtures/map/no_vao/expected.png new file mode 100644 index 0000000000..d5b7c42762 Binary files /dev/null and b/test/fixtures/map/no_vao/expected.png differ diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index fd3bfe58d7..aec181e058 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -305,6 +306,24 @@ TEST(Map, AddLayer) { test::checkImage("test/fixtures/map/add_layer", test::render(map, test.view)); } +TEST(Map, WithoutVAOExtension) { + MapTest test; + + test.backend.getContext().disableVAOExtension = true; + +#ifdef MBGL_ASSET_ZIP + // Regenerate with `cd test/fixtures/api/ && zip -r assets.zip assets/` + DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets.zip"); +#else + DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets"); +#endif + + Map map(test.backend, test.view.size, 1, fileSource, test.threadPool, MapMode::Still); + map.setStyleJSON(util::read_file("test/fixtures/api/water.json")); + + test::checkImage("test/fixtures/map/no_vao", test::render(map, test.view), 0.002); +} + TEST(Map, RemoveLayer) { MapTest test; -- cgit v1.2.1