From 9966dcdb05fa93c2578a9b7426ce538330bbc6a2 Mon Sep 17 00:00:00 2001 From: Tim Sylvester Date: Tue, 6 Jun 2023 13:08:05 -0700 Subject: [PATCH] Drawable Renderer (#1570), Better validity check for VAO wrappers. Don't draw if VAO state isn't valid. Reset VAO state to default after draw. --- src/mbgl/gl/drawable_gl.cpp | 5 ++--- src/mbgl/gl/vertex_array.hpp | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/mbgl/gl/drawable_gl.cpp b/src/mbgl/gl/drawable_gl.cpp index e926ae2c1..4a80138c7 100644 --- a/src/mbgl/gl/drawable_gl.cpp +++ b/src/mbgl/gl/drawable_gl.cpp @@ -56,18 +56,17 @@ void DrawableGL::draw(const PaintParameters& parameters) const { bindTextures(); auto& glContext = static_cast(parameters.context); - const auto saveVertexArray = glContext.bindVertexArray.getCurrentValue(); for (const auto& seg : impl->segments) { const auto& glSeg = static_cast(*seg); const auto& mlSeg = glSeg.getSegment(); if (glSeg.getVertexArray().isValid()) { glContext.bindVertexArray = glSeg.getVertexArray().getID(); + glContext.draw(glSeg.getMode(), mlSeg.indexOffset, mlSeg.indexLength); } - glContext.draw(glSeg.getMode(), mlSeg.indexOffset, mlSeg.indexLength); } - glContext.bindVertexArray = saveVertexArray; + glContext.bindVertexArray = value::BindVertexArray::Default; unbindTextures(); unbindUniformBuffers(); diff --git a/src/mbgl/gl/vertex_array.hpp b/src/mbgl/gl/vertex_array.hpp index 6a9ec974e..707172d84 100644 --- a/src/mbgl/gl/vertex_array.hpp +++ b/src/mbgl/gl/vertex_array.hpp @@ -70,7 +70,9 @@ public: return *this; } - bool isValid() const { return state.operator bool(); } + bool isValid() const { + return state && state->vertexArray && state->vertexArray.get(); + } VertexArrayID getID() const { return state->vertexArray; }