Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Restore support for GL implementations without VAO extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Feb 11, 2017
1 parent 0b3873c commit 0bbc6b8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/mbgl/gl/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}

Expand Down
4 changes: 4 additions & 0 deletions src/mbgl/gl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ class Context : private util::noncopyable {
std::vector<VertexArrayID> abandonedVertexArrays;
std::vector<FramebufferID> abandonedFramebuffers;
std::vector<RenderbufferID> abandonedRenderbuffers;

public:
// For testing
bool disableVAOExtension = false;
};

} // namespace gl
Expand Down
15 changes: 10 additions & 5 deletions src/mbgl/gl/segment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ class Segment {
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,
Expand Down
Binary file added test/fixtures/map/no_vao/expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/map/map.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <mbgl/map/map.hpp>
#include <mbgl/gl/headless_backend.hpp>
#include <mbgl/gl/offscreen_view.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/sprite/sprite_image.hpp>
#include <mbgl/storage/network_status.hpp>
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 0bbc6b8

Please sign in to comment.