[core] Redo approach to unsupported VAO extension

This commit is contained in:
John Firebaugh
2017-02-17 10:09:49 -08:00
parent f8ab327874
commit 4e752f63b9
3 changed files with 23 additions and 15 deletions

View File

@@ -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();

View File

@@ -39,6 +39,8 @@ public:
UniqueProgram createProgram(ShaderID vertexShader, ShaderID fragmentShader);
void linkProgram(ProgramID);
UniqueTexture createTexture();
bool supportsVertexArrays() const;
UniqueVertexArray createVertexArray();
template <class Vertex, class DrawMode>

View File

@@ -3,6 +3,7 @@
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/logging.hpp>
#include <cstddef>
#include <vector>
@@ -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 = {};
}