diff --git a/libopenage/renderer/opengl/geometry.cpp b/libopenage/renderer/opengl/geometry.cpp index 9b3e9c9101..e0898edbe8 100644 --- a/libopenage/renderer/opengl/geometry.cpp +++ b/libopenage/renderer/opengl/geometry.cpp @@ -54,7 +54,7 @@ void GlGeometry::update_verts_offset(std::vector const &verts, size_t o void GlGeometry::draw() const { switch (this->get_type()) { case geometry_t::bufferless_quad: - // a VAO must be bound before this call. This is handled by GlRenderer. + // any VAO must be bound before this call glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); break; diff --git a/libopenage/renderer/opengl/geometry.h b/libopenage/renderer/opengl/geometry.h index 84a816c4dd..3275c24f13 100644 --- a/libopenage/renderer/opengl/geometry.h +++ b/libopenage/renderer/opengl/geometry.h @@ -1,4 +1,4 @@ -// Copyright 2015-2025 the openage authors. See copying.md for legal info. +// Copyright 2015-2023 the openage authors. See copying.md for legal info. #pragma once diff --git a/libopenage/renderer/opengl/renderer.cpp b/libopenage/renderer/opengl/renderer.cpp index 66932585c6..ff3e611096 100644 --- a/libopenage/renderer/opengl/renderer.cpp +++ b/libopenage/renderer/opengl/renderer.cpp @@ -28,7 +28,7 @@ GlRenderer::GlRenderer(const std::shared_ptr &ctx, display{std::make_shared(ctx, viewport_size[0], viewport_size[1])}, - shared_quad_vao(std::make_shared(ctx)) { + shared_quad_vao{std::make_unique(ctx)} { // color used to clear the color buffers glClearColor(0.0f, 0.0f, 0.0f, 0.0f); @@ -171,7 +171,9 @@ void GlRenderer::render(const std::shared_ptr &pass) { auto gl_target = std::dynamic_pointer_cast(pass->get_target()); gl_target->bind_write(); - // bind the shared quad vao for all bufferless quad geometries + // ensure that an (empty) VAO is bound before rendering geometry + // a bound VAO is required to render bufferless quad geometries by OpenGL + // see https://www.khronos.org/opengl/wiki/Vertex_Rendering#Causes_of_rendering_failure shared_quad_vao->bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); diff --git a/libopenage/renderer/opengl/renderer.h b/libopenage/renderer/opengl/renderer.h index 811d35ac03..b696196dcb 100644 --- a/libopenage/renderer/opengl/renderer.h +++ b/libopenage/renderer/opengl/renderer.h @@ -69,7 +69,13 @@ class GlRenderer final : public Renderer { /// The main screen surface as a render target. std::shared_ptr display; - std::shared_ptr shared_quad_vao; + /// An empty vertex array object (VAO). + /// + /// This VAO has to be bound at the start of a render pass to ensure + /// that bufferless quad geometry can be drawn without errors. Drawing a + /// bufferless quad requires any VAO to be bound + /// see https://www.khronos.org/opengl/wiki/Vertex_Rendering#Causes_of_rendering_failure + std::unique_ptr shared_quad_vao; }; } // namespace opengl