From 1a861fb045df72aed28053e388257acee5ff7833 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Sat, 1 Jul 2023 03:58:02 +1000 Subject: [PATCH] Fix GL error --- assets/opensb/rendering/default.vert | 1 - source/application/StarRenderer_opengl20.cpp | 18 +++++++++++------- source/application/StarRenderer_opengl20.hpp | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/assets/opensb/rendering/default.vert b/assets/opensb/rendering/default.vert index a8b2751..612a788 100644 --- a/assets/opensb/rendering/default.vert +++ b/assets/opensb/rendering/default.vert @@ -11,7 +11,6 @@ attribute vec2 vertexPosition; attribute vec2 vertexTextureCoordinate; attribute float vertexTextureIndex; attribute vec4 vertexColor; -attribute float vertexParam1; varying vec2 fragmentTextureCoordinate; varying float fragmentTextureIndex; diff --git a/source/application/StarRenderer_opengl20.cpp b/source/application/StarRenderer_opengl20.cpp index 70185cc..0584b51 100644 --- a/source/application/StarRenderer_opengl20.cpp +++ b/source/application/StarRenderer_opengl20.cpp @@ -692,10 +692,9 @@ void OpenGl20Renderer::GlRenderBuffer::set(List& primitives) { glDeleteBuffers(1, &vb.vertexBuffer); } -void OpenGl20Renderer::logGlErrorSummary(String prefix) { +bool OpenGl20Renderer::logGlErrorSummary(String prefix) { if (GLenum error = glGetError()) { - prefix += ": "; - Logger::error(prefix.utf8Ptr()); + Logger::error("{}: ", prefix); do { if (error == GL_INVALID_ENUM) { Logger::error("GL_INVALID_ENUM"); @@ -714,8 +713,10 @@ void OpenGl20Renderer::logGlErrorSummary(String prefix) { } else { Logger::error(""); } - } while ((error = glGetError())); + } while (error = glGetError()); + return true; } + return false; } void OpenGl20Renderer::uploadTextureImage(PixelFormat pixelFormat, Vec2U size, uint8_t const* data) { @@ -809,14 +810,17 @@ void OpenGl20Renderer::renderGlBuffer(GlRenderBuffer const& renderBuffer, Mat3F glEnableVertexAttribArray(m_texCoordAttribute); glEnableVertexAttribArray(m_texIndexAttribute); glEnableVertexAttribArray(m_colorAttribute); - glEnableVertexAttribArray(m_param1Attribute); glVertexAttribPointer(m_positionAttribute, 2, GL_FLOAT, GL_FALSE, sizeof(GlRenderVertex), (GLvoid*)offsetof(GlRenderVertex, screenCoordinate)); glVertexAttribPointer(m_texCoordAttribute, 2, GL_FLOAT, GL_FALSE, sizeof(GlRenderVertex), (GLvoid*)offsetof(GlRenderVertex, textureCoordinate)); glVertexAttribPointer(m_texIndexAttribute, 1, GL_FLOAT, GL_FALSE, sizeof(GlRenderVertex), (GLvoid*)offsetof(GlRenderVertex, textureIndex)); glVertexAttribPointer(m_colorAttribute, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(GlRenderVertex), (GLvoid*)offsetof(GlRenderVertex, color)); - glVertexAttribPointer(m_param1Attribute, 1, GL_FLOAT, GL_FALSE, sizeof(GlRenderVertex), (GLvoid*)offsetof(GlRenderVertex, param1)); - + + if (m_param1Attribute != -1) { + glEnableVertexAttribArray(m_param1Attribute); + glVertexAttribPointer(m_param1Attribute, 1, GL_FLOAT, GL_FALSE, sizeof(GlRenderVertex), (GLvoid*)offsetof(GlRenderVertex, param1)); + } + glDrawArrays(GL_TRIANGLES, 0, vb.vertexCount); } } diff --git a/source/application/StarRenderer_opengl20.hpp b/source/application/StarRenderer_opengl20.hpp index 5add227..6946073 100644 --- a/source/application/StarRenderer_opengl20.hpp +++ b/source/application/StarRenderer_opengl20.hpp @@ -165,7 +165,7 @@ private: StringMap textures; }; - static void logGlErrorSummary(String prefix); + static bool logGlErrorSummary(String prefix); static void uploadTextureImage(PixelFormat pixelFormat, Vec2U size, uint8_t const* data); static RefPtr createGlTexture(Image const& texture, TextureAddressing addressing, TextureFiltering filtering);