From 0853cbc29add22413a1216117e04fcf1b53131de Mon Sep 17 00:00:00 2001 From: milek7 Date: Thu, 20 Dec 2018 21:23:48 +0100 Subject: [PATCH] motion blur fixes --- Texture.cpp | 18 +++++++++--------- Texture.h | 4 +++- renderer.cpp | 6 +++--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Texture.cpp b/Texture.cpp index 0bc12910..962e92be 100644 --- a/Texture.cpp +++ b/Texture.cpp @@ -880,14 +880,12 @@ opengl_texture::create() { ::glBindTexture( target, id ); // analyze specified texture traits - bool wraps{ true }; - bool wrapt{ true }; for( auto const &trait : traits ) { switch( trait ) { - case 's': { wraps = false; break; } - case 't': { wrapt = false; break; } + case 's': { wrap_mode_s = GL_CLAMP_TO_EDGE; break; } + case 't': { wrap_mode_t = GL_CLAMP_TO_EDGE; break; } } } @@ -900,8 +898,8 @@ opengl_texture::create() { { glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + glTexParameteri(target, GL_TEXTURE_WRAP_S, wrap_mode_s); + glTexParameteri(target, GL_TEXTURE_WRAP_T, wrap_mode_t); if (data_components == GL_DEPTH_COMPONENT) { glTexParameteri(target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); @@ -926,8 +924,8 @@ opengl_texture::create() { } else { - ::glTexParameteri(target, GL_TEXTURE_WRAP_S, (wraps == true ? GL_REPEAT : GL_CLAMP_TO_EDGE)); - ::glTexParameteri(target, GL_TEXTURE_WRAP_T, (wrapt == true ? GL_REPEAT : GL_CLAMP_TO_EDGE)); + ::glTexParameteri(target, GL_TEXTURE_WRAP_S, wrap_mode_s); + ::glTexParameteri(target, GL_TEXTURE_WRAP_T, wrap_mode_t); set_filtering(); // data_format and data_type specifies how image is laid out in memory @@ -1061,7 +1059,7 @@ opengl_texture::release() { return; } -void opengl_texture::alloc_rendertarget(GLint format, GLint components, int width, int height, int s) +void opengl_texture::alloc_rendertarget(GLint format, GLint components, int width, int height, int s, GLint wrap) { data_width = width; data_height = height; @@ -1069,6 +1067,8 @@ void opengl_texture::alloc_rendertarget(GLint format, GLint components, int widt data_components = components; data_mapcount = 1; is_rendertarget = true; + wrap_mode_s = wrap; + wrap_mode_t = wrap; samples = s; if (samples > 1) target = GL_TEXTURE_2D_MULTISAMPLE; diff --git a/Texture.h b/Texture.h index 42686489..7a8efe7a 100644 --- a/Texture.h +++ b/Texture.h @@ -43,7 +43,7 @@ struct opengl_texture { height() const { return data_height; } - void alloc_rendertarget(GLint format, GLint components, int width, int height, int samples = 1); + void alloc_rendertarget(GLint format, GLint components, int width, int height, int samples = 1, GLint wrap = GL_CLAMP_TO_BORDER); void set_components_hint(GLint hint); static void reset_unit_cache(); @@ -87,6 +87,8 @@ private: data_components{ 0 }; GLint data_type = GL_UNSIGNED_BYTE; + GLint wrap_mode_s = GL_REPEAT; + GLint wrap_mode_t = GL_REPEAT; /* std::atomic is_loaded{ false }; // indicates the texture data was loaded and can be processed std::atomic is_good{ false }; // indicates the texture data was retrieved without errors diff --git a/renderer.cpp b/renderer.cpp index fb191219..3927024e 100644 --- a/renderer.cpp +++ b/renderer.cpp @@ -208,7 +208,7 @@ bool opengl_renderer::Init(GLFWwindow *Window) m_msaa_fb->attach(*m_msaa_rbv, GL_COLOR_ATTACHMENT1); m_main_tex = std::make_unique(); - m_main_tex->alloc_rendertarget(Global.gfx_format_color, GL_RGB, Global.gfx_framebuffer_width, Global.gfx_framebuffer_height); + m_main_tex->alloc_rendertarget(Global.gfx_format_color, GL_RGB, Global.gfx_framebuffer_width, Global.gfx_framebuffer_height, 1, GL_CLAMP_TO_EDGE); m_main_fb = std::make_unique(); m_main_fb->attach(*m_main_tex, GL_COLOR_ATTACHMENT0); @@ -555,9 +555,9 @@ void opengl_renderer::Render_pass(rendermode const Mode) setup_drawing(true); glm::mat4 future; - if (!FreeFlyModeFlag) + if (Global.pCamera.m_owner != nullptr) { - auto const *vehicle = simulation::Train->Dynamic(); + auto const *vehicle = Global.pCamera.m_owner; glm::mat4 mv = OpenGLMatrices.data(GL_MODELVIEW); future = glm::translate(mv, -glm::vec3(vehicle->get_future_movement())) * glm::inverse(mv); }