From 4c3c08b965489dd2211252bb62f217b48d4c6117 Mon Sep 17 00:00:00 2001 From: Daid Date: Thu, 26 Mar 2020 20:25:04 +0100 Subject: [PATCH 1/3] Fixed https://github.com/daid/EmptyEpsilon/issues/823 --- src/input.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/input.cpp b/src/input.cpp index 6750119e..8002a5a6 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -153,6 +153,9 @@ void InputHandler::handleEvent(sf::Event& event) void InputHandler::postEventsUpdate() { + input_event_handlers.update(); + joystick_event_handlers.update(); + if (last_key_press.code != sf::Keyboard::Unknown) { InputHandler::fireKeyEvent(last_key_press, -1); From 7a17c0813970b84816134cd33b809882145a0822 Mon Sep 17 00:00:00 2001 From: Oznogon Date: Fri, 27 Mar 2020 00:53:11 -0700 Subject: [PATCH 2/3] dos2unix to convert line endings in postProcessManager --- src/postProcessManager.cpp | 90 +++++++++++++++++++------------------- src/postProcessManager.h | 36 +++++++-------- 2 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/postProcessManager.cpp b/src/postProcessManager.cpp index 2cc0da51..318191e5 100644 --- a/src/postProcessManager.cpp +++ b/src/postProcessManager.cpp @@ -1,75 +1,75 @@ -#include "logging.h" -#include "postProcessManager.h" +#include "logging.h" +#include "postProcessManager.h" bool PostProcessor::global_post_processor_enabled = true; - -static int powerOfTwo(int v) -{ - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - v++; - return v; -} + +static int powerOfTwo(int v) +{ + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v++; + return v; +} PostProcessor::PostProcessor(string name, RenderChain* chain) -: chain(chain) +: chain(chain) { if (sf::Shader::isAvailable()) - { - if (shader.loadFromFile("resources/" + name + ".frag", sf::Shader::Fragment)) - { - LOG(INFO) << "Loaded shader: " << name; - enabled = true; - }else{ - LOG(WARNING) << "Failed to load shader:" << name; - enabled = false; + { + if (shader.loadFromFile("resources/" + name + ".frag", sf::Shader::Fragment)) + { + LOG(INFO) << "Loaded shader: " << name; + enabled = true; + }else{ + LOG(WARNING) << "Failed to load shader:" << name; + enabled = false; } }else{ LOG(WARNING) << "Did not load load shader: " << name; LOG(WARNING) << "Because of no shader support in video card driver."; enabled = false; } -} - -void PostProcessor::render(sf::RenderTarget& window) +} + +void PostProcessor::render(sf::RenderTarget& window) { if (!enabled || !sf::Shader::isAvailable() || !global_post_processor_enabled) { chain->render(window); return; } - if (renderTexture.getSize().x < 1) + if (renderTexture.getSize().x < 1) { - //Setup a backBuffer to render the game on. Then we can render the backbuffer back to the main screen with full-screen shader effects - int w = window.getView().getViewport().width * window.getSize().x; - int h = window.getView().getViewport().height * window.getSize().y; - int tw = powerOfTwo(w); - int th = powerOfTwo(h); - sf::View view(window.getView()); - view.setViewport(sf::FloatRect(0, 1.0 - float(h) / float(th), float(w) / float(tw), float(h) / float(th))); - - renderTexture.create(tw, th, true); - renderTexture.setRepeated(true); - renderTexture.setSmooth(true); - renderTexture.setView(view); + //Setup a backBuffer to render the game on. Then we can render the backbuffer back to the main screen with full-screen shader effects + int w = window.getView().getViewport().width * window.getSize().x; + int h = window.getView().getViewport().height * window.getSize().y; + int tw = powerOfTwo(w); + int th = powerOfTwo(h); + sf::View view(window.getView()); + view.setViewport(sf::FloatRect(0, 1.0 - float(h) / float(th), float(w) / float(tw), float(h) / float(th))); + + renderTexture.create(tw, th, true); + renderTexture.setRepeated(true); + renderTexture.setSmooth(true); + renderTexture.setView(view); - shader.setUniform("inputSize", sf::Vector2f(window.getSize().x, window.getSize().y)); + shader.setUniform("inputSize", sf::Vector2f(window.getSize().x, window.getSize().y)); shader.setUniform("textureSize", sf::Vector2f(renderTexture.getSize().x, renderTexture.getSize().y)); } renderTexture.clear(sf::Color(20, 20, 20)); chain->render(renderTexture); - renderTexture.display(); - sf::Sprite backBufferSprite(renderTexture.getTexture(), sf::IntRect(0, renderTexture.getSize().y - window.getView().getViewport().height * window.getSize().y, window.getView().getViewport().width * window.getSize().x, window.getView().getViewport().height * window.getSize().y)); + renderTexture.display(); + sf::Sprite backBufferSprite(renderTexture.getTexture(), sf::IntRect(0, renderTexture.getSize().y - window.getView().getViewport().height * window.getSize().y, window.getView().getViewport().width * window.getSize().x, window.getView().getViewport().height * window.getSize().y)); backBufferSprite.setScale(window.getView().getSize().x/float(renderTexture.getSize().x)/renderTexture.getView().getViewport().width, window.getView().getSize().y/float(renderTexture.getSize().y)/renderTexture.getView().getViewport().height); - - window.draw(backBufferSprite, &shader); -} + + window.draw(backBufferSprite, &shader); +} void PostProcessor::setUniform(string name, float value) { diff --git a/src/postProcessManager.h b/src/postProcessManager.h index 178a3fa9..b2adbb43 100644 --- a/src/postProcessManager.h +++ b/src/postProcessManager.h @@ -1,33 +1,33 @@ -#ifndef POST_PROCESS_MANAGER_H -#define POST_PROCESS_MANAGER_H - -#include - -#include "stringImproved.h" +#ifndef POST_PROCESS_MANAGER_H +#define POST_PROCESS_MANAGER_H + +#include + +#include "stringImproved.h" #include "Updatable.h" -#include "Renderable.h" - -class PostProcessor : public RenderChain -{ -private: +#include "Renderable.h" + +class PostProcessor : public RenderChain +{ +private: sf::Shader shader; sf::RenderTexture renderTexture; RenderChain* chain; static bool global_post_processor_enabled; -public: +public: bool enabled; - PostProcessor(string name, RenderChain* chain); + PostProcessor(string name, RenderChain* chain); virtual ~PostProcessor() {} virtual void render(sf::RenderTarget& window); void setUniform(string name, float value); - static void setEnable(bool enable) { global_post_processor_enabled = enable; } - static bool isEnabled() { return global_post_processor_enabled; } -}; - -#endif//POST_PROCESS_MANAGER_H + static void setEnable(bool enable) { global_post_processor_enabled = enable; } + static bool isEnabled() { return global_post_processor_enabled; } +}; + +#endif//POST_PROCESS_MANAGER_H From 48992dab9703f21f369d3e927e697f965e458409 Mon Sep 17 00:00:00 2001 From: Oznogon Date: Fri, 27 Mar 2020 01:58:31 -0700 Subject: [PATCH 3/3] Check for window resize on postProcessing render --- src/postProcessManager.cpp | 21 ++++++++++++++------- src/postProcessManager.h | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/postProcessManager.cpp b/src/postProcessManager.cpp index 318191e5..e6c4f181 100644 --- a/src/postProcessManager.cpp +++ b/src/postProcessManager.cpp @@ -42,14 +42,20 @@ void PostProcessor::render(sf::RenderTarget& window) chain->render(window); return; } - if (renderTexture.getSize().x < 1) + + sf::View view(window.getView()); + + // If the window or texture size is 0/impossible, or if the window size has + // changed, resize the viewport, render texture, and input/textureSizes. + if (size.x < 1 || renderTexture.getSize().x < 1 || size != window.getSize()) { + size = window.getSize(); + //Setup a backBuffer to render the game on. Then we can render the backbuffer back to the main screen with full-screen shader effects - int w = window.getView().getViewport().width * window.getSize().x; - int h = window.getView().getViewport().height * window.getSize().y; + int w = view.getViewport().width * size.x; + int h = view.getViewport().height * size.y; int tw = powerOfTwo(w); int th = powerOfTwo(h); - sf::View view(window.getView()); view.setViewport(sf::FloatRect(0, 1.0 - float(h) / float(th), float(w) / float(tw), float(h) / float(th))); renderTexture.create(tw, th, true); @@ -57,7 +63,7 @@ void PostProcessor::render(sf::RenderTarget& window) renderTexture.setSmooth(true); renderTexture.setView(view); - shader.setUniform("inputSize", sf::Vector2f(window.getSize().x, window.getSize().y)); + shader.setUniform("inputSize", sf::Vector2f(size.x, size.y)); shader.setUniform("textureSize", sf::Vector2f(renderTexture.getSize().x, renderTexture.getSize().y)); } @@ -65,8 +71,9 @@ void PostProcessor::render(sf::RenderTarget& window) chain->render(renderTexture); renderTexture.display(); - sf::Sprite backBufferSprite(renderTexture.getTexture(), sf::IntRect(0, renderTexture.getSize().y - window.getView().getViewport().height * window.getSize().y, window.getView().getViewport().width * window.getSize().x, window.getView().getViewport().height * window.getSize().y)); - backBufferSprite.setScale(window.getView().getSize().x/float(renderTexture.getSize().x)/renderTexture.getView().getViewport().width, window.getView().getSize().y/float(renderTexture.getSize().y)/renderTexture.getView().getViewport().height); + + sf::Sprite backBufferSprite(renderTexture.getTexture(), sf::IntRect(0, renderTexture.getSize().y - view.getViewport().height * size.y, view.getViewport().width * size.x, view.getViewport().height * size.y)); + backBufferSprite.setScale(view.getSize().x / float(renderTexture.getSize().x) / renderTexture.getView().getViewport().width, view.getSize().y / float(renderTexture.getSize().y) / renderTexture.getView().getViewport().height); window.draw(backBufferSprite, &shader); } diff --git a/src/postProcessManager.h b/src/postProcessManager.h index b2adbb43..4e5d0a72 100644 --- a/src/postProcessManager.h +++ b/src/postProcessManager.h @@ -12,6 +12,7 @@ class PostProcessor : public RenderChain private: sf::Shader shader; sf::RenderTexture renderTexture; + sf::Vector2u size; RenderChain* chain;