Skip to content

Commit

Permalink
update according to reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzzhHe committed Jan 2, 2025
1 parent ec8707d commit 727c338
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libopenage/renderer/opengl/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void GlGeometry::update_verts_offset(std::vector<uint8_t> 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;

Expand Down
2 changes: 1 addition & 1 deletion libopenage/renderer/opengl/geometry.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 4 additions & 2 deletions libopenage/renderer/opengl/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ GlRenderer::GlRenderer(const std::shared_ptr<GlContext> &ctx,
display{std::make_shared<GlRenderTarget>(ctx,
viewport_size[0],
viewport_size[1])},
shared_quad_vao(std::make_shared<GlVertexArray>(ctx)) {
shared_quad_vao{std::make_unique<GlVertexArray>(ctx)} {
// color used to clear the color buffers
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

Expand Down Expand Up @@ -171,7 +171,9 @@ void GlRenderer::render(const std::shared_ptr<RenderPass> &pass) {
auto gl_target = std::dynamic_pointer_cast<GlRenderTarget>(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);
Expand Down
8 changes: 7 additions & 1 deletion libopenage/renderer/opengl/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ class GlRenderer final : public Renderer {
/// The main screen surface as a render target.
std::shared_ptr<GlRenderTarget> display;

std::shared_ptr<GlVertexArray> 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<GlVertexArray> shared_quad_vao;
};

} // namespace opengl
Expand Down

0 comments on commit 727c338

Please sign in to comment.