From babb43849e9be1bec4fd34b94b5a437cf19eda98 Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Thu, 14 Nov 2019 15:49:12 +0100 Subject: [PATCH] opengl error fixes --- Globals.cpp | 14 +++++++--- Globals.h | 1 + Texture.cpp | 14 +++++----- Texture.h | 2 +- gl/buffer.cpp | 2 ++ gl/query.cpp | 3 ++- opengl33renderer.cpp | 62 ++++++++++++++++++++++++++++++-------------- stdafx.h | 4 +-- uilayer.cpp | 2 +- 9 files changed, 70 insertions(+), 34 deletions(-) diff --git a/Globals.cpp b/Globals.cpp index 5ff04bf6..17441c7a 100644 --- a/Globals.cpp +++ b/Globals.cpp @@ -371,6 +371,7 @@ global_settings::ConfigParse(cParser &Parser) { GfxRenderer = "default"; } BasicRenderer = ( GfxRenderer == "simple" ); + LegacyRenderer = ( GfxRenderer != "default" ); } else if( token == "shadows" ) { // shadow render toggle @@ -728,7 +729,10 @@ global_settings::ConfigParse(cParser &Parser) { #endif else if (token == "compresstex") { Parser.getTokens( 1 ); - Parser >> compress_tex; + if( false == gfx_usegles ) { + // ogl es use requires compression to be disabled + Parser >> compress_tex; + } } else if (token == "gfx.framebuffer.width") { @@ -813,18 +817,22 @@ global_settings::ConfigParse(cParser &Parser) { Parser.getTokens(1); Parser >> gfx_extraeffects; } -/* + /* else if (token == "gfx.usegles") { Parser.getTokens(1); Parser >> gfx_usegles; + if( true == gfx_usegles ) { + compress_tex = false; + gfx_shadergamma = true; + } } -*/ else if (token == "gfx.shadergamma") { Parser.getTokens(1); Parser >> gfx_shadergamma; } + */ else if (token == "python.mipmaps") { Parser.getTokens(1); diff --git a/Globals.h b/Globals.h index db249098..f48eed03 100644 --- a/Globals.h +++ b/Globals.h @@ -113,6 +113,7 @@ struct global_settings { int DynamicLightCount{ 3 }; bool ScaleSpecularValues{ true }; std::string GfxRenderer{ "default" }; + bool LegacyRenderer{ false }; bool BasicRenderer{ false }; bool RenderShadows{ true }; int RenderCabShadowsRange{ 0 }; diff --git a/Texture.cpp b/Texture.cpp index 416e1baa..23138417 100644 --- a/Texture.cpp +++ b/Texture.cpp @@ -823,11 +823,13 @@ opengl_texture::create() { glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(target, GL_TEXTURE_WRAP_S, wrap_mode_s); glTexParameteri(target, GL_TEXTURE_WRAP_T, wrap_mode_t); - if (data_components == GL_DEPTH_COMPONENT) + if (data_components == GL_DEPTH_COMPONENT) { glTexParameteri(target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); - float borderColor[] = { 0.0f, 0.0f, 0.0f, 0.0f }; - glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, borderColor); + if( false == Global.gfx_usegles ) { + float borderColor[] = { 0.0f, 0.0f, 0.0f, 0.0f }; + glTexParameterfv( target, GL_TEXTURE_BORDER_COLOR, borderColor ); + } } if (Global.gfx_usegles) @@ -1026,7 +1028,7 @@ opengl_texture::set_filtering() const { ::glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, Global.AnisotropicFiltering ); } - if( false == Global.gfx_usegles ) { + if( Global.LegacyRenderer ) { bool sharpen{ false }; for( auto const &trait : traits ) { @@ -1040,11 +1042,11 @@ opengl_texture::set_filtering() const { if( true == sharpen ) { // #: sharpen more - ::glTexEnvf( GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -2.0 ); + ::glTexEnvf( GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -2.0f ); } else { // regular texture sharpening - ::glTexEnvf( GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -1.0 ); + ::glTexEnvf( GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -1.0f ); } } } diff --git a/Texture.h b/Texture.h index 599b4eb0..6c2eb282 100644 --- a/Texture.h +++ b/Texture.h @@ -36,7 +36,7 @@ struct opengl_texture { void release(); void - alloc_rendertarget( GLint format, GLint components, int width, int height, int samples = 1, GLint wrap = GL_CLAMP_TO_BORDER ); + alloc_rendertarget( GLint format, GLint components, int width, int height, int samples = 1, GLint wrap = GL_CLAMP_TO_EDGE ); void set_components_hint( GLint hint ); static void diff --git a/gl/buffer.cpp b/gl/buffer.cpp index 2aa4b5e3..0321a70b 100644 --- a/gl/buffer.cpp +++ b/gl/buffer.cpp @@ -39,6 +39,8 @@ void gl::buffer::bind_base(targets target, GLuint index) void gl::buffer::unbind(targets target) { + if( binding_points[ target ] == 0 ) { return; } + glBindBuffer(glenum_target(target), 0); binding_points[target] = 0; } diff --git a/gl/query.cpp b/gl/query.cpp index d98451b8..600164a4 100644 --- a/gl/query.cpp +++ b/gl/query.cpp @@ -34,7 +34,8 @@ void gl::query::end() std::optional gl::query::result() { - GLuint ready; + end(); // intercept potential error if the result check is called for still active object + GLuint ready; glGetQueryObjectuiv(*this, GL_QUERY_RESULT_AVAILABLE, &ready); int64_t value = 0; if (ready) { diff --git a/opengl33renderer.cpp b/opengl33renderer.cpp index 2a4f9b87..86c86370 100644 --- a/opengl33renderer.cpp +++ b/opengl33renderer.cpp @@ -26,8 +26,25 @@ int const EU07_PICKBUFFERSIZE{1024}; // size of (square) textures bound with the auto const gammacorrection { glm::vec3( 2.2f ) }; +void GLAPIENTRY +ErrorCallback( GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam ) { + + ErrorLog( + "bad gfx code: " + std::string( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ) + + " type = " + to_hex_str( id ) + + ", severity = " + to_hex_str( severity ) + + ", message = " + message ); +} + bool opengl33_renderer::Init(GLFWwindow *Window) { +/* + if( false == Global.gfx_usegles ) { + // enable for gles after move to 3.2+ + glEnable( GL_DEBUG_OUTPUT ); + glDebugMessageCallback( ErrorCallback, 0 ); + } +*/ if (!Init_caps()) return false; @@ -172,7 +189,7 @@ bool opengl33_renderer::Init(GLFWwindow *Window) WriteLog("cabshadows enabled"); } - if (Global.gfx_envmap_enabled) + if (Global.gfx_envmap_enabled) { m_env_rb = std::make_unique(); m_env_rb->alloc(Global.gfx_format_depth, gl::ENVMAP_SIZE, gl::ENVMAP_SIZE); @@ -274,7 +291,7 @@ bool opengl33_renderer::Init(GLFWwindow *Window) WriteLog("gfx renderer setup complete"); - return true; + return true; } /* bool opengl33_renderer::AddViewport(const global_settings::extraviewport_config &conf) @@ -740,12 +757,12 @@ void opengl33_renderer::Render_pass(viewport_config &vp, rendermode const Mode) glDebug("uilayer render"); Timer::subsystem.gfx_gui.start(); - if (vp.main) { + if (vp.main) { draw_debug_ui(); Application.render_ui(); } - Timer::subsystem.gfx_gui.stop(); + Timer::subsystem.gfx_gui.stop(); // restore binding scene_ubo->bind_uniform(); @@ -1691,11 +1708,13 @@ void opengl33_renderer::Bind_Material_Shadow(material_handle const Material) m_textures.bind(0, material.textures[0]); m_alpha_shadow_shader->bind(); } - else - m_shadow_shader->bind(); + else { + m_shadow_shader->bind(); + } } - else - m_shadow_shader->bind(); + else { + m_shadow_shader->bind(); + } } opengl_material const &opengl33_renderer::Material(material_handle const Material) const @@ -2400,7 +2419,7 @@ bool opengl33_renderer::Render_cab(TDynamicObject const *Dynamic, float const Li ::glTranslated(originoffset.x, originoffset.y, originoffset.z); ::glMultMatrixd(Dynamic->mMatrix.readArray()); - switch (m_renderpass.draw_mode) + switch (m_renderpass.draw_mode) { case rendermode::color: { @@ -2440,14 +2459,17 @@ bool opengl33_renderer::Render_cab(TDynamicObject const *Dynamic, float const Li break; } - case rendermode::cabshadows: - if (true == Alpha) - // translucent parts - Render_Alpha(Dynamic->mdKabina, Dynamic->Material(), 0.0); - else - // opaque parts - Render(Dynamic->mdKabina, Dynamic->Material(), 0.0); - break; + case rendermode::cabshadows: { + if( true == Alpha ) { + // translucent parts + Render_Alpha( Dynamic->mdKabina, Dynamic->Material(), 0.0 ); + } + else { + // opaque parts + Render( Dynamic->mdKabina, Dynamic->Material(), 0.0 ); + } + break; + } case rendermode::pickcontrols: { Render(Dynamic->mdKabina, Dynamic->Material(), 0.0); @@ -2585,7 +2607,7 @@ void opengl33_renderer::Render(TSubModel *Submodel) case rendermode::shadows: case rendermode::cabshadows: { - if (Submodel->m_material < 0) + if (Submodel->m_material < 0) { // zmienialne skóry Bind_Material_Shadow(Submodel->ReplacableSkinId[-Submodel->m_material]); } @@ -2594,8 +2616,8 @@ void opengl33_renderer::Render(TSubModel *Submodel) // również 0 Bind_Material_Shadow(Submodel->m_material); } - draw(Submodel->m_geometry); - break; + draw(Submodel->m_geometry); + break; } case rendermode::pickscenery: { diff --git a/stdafx.h b/stdafx.h index e2b3607b..c2a35ead 100644 --- a/stdafx.h +++ b/stdafx.h @@ -77,9 +77,9 @@ #include "glad/glad.h" -#include "GL/glu.h" +//#include "GL/glu.h" -#define GLFW_INCLUDE_NONE +#define GLFW_INCLUDE_GLU #include #ifndef GLFW_TRUE diff --git a/uilayer.cpp b/uilayer.cpp index bb47e4a8..098e43cc 100644 --- a/uilayer.cpp +++ b/uilayer.cpp @@ -92,7 +92,7 @@ ui_layer::init( GLFWwindow *Window ) { if( Global.GfxRenderer == "default" ) { // opengl 3.3 render path if( Global.gfx_usegles ) { - ImGui_ImplOpenGL3_Init( "#version 300 es\nprecision highp float;" ); + ImGui_ImplOpenGL3_Init( "#version 300 es" ); } else { ImGui_ImplOpenGL3_Init( "#version 330 core" );