From f9c20571ab3b0be276e17593abbbd7fe6795daa9 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 21 May 2018 11:54:53 -0400 Subject: [PATCH 1/4] PostProcessing: Default constructor and destructor of PostProcessingShaderConfiguration Also ensure that all members of the class are initialized on construction as well. Previously the bool indicating if options are dirty wouldn't be initialized, which could be read uninitialized if an instance was constructed and then IsDirty() is called. --- Source/Core/VideoCommon/PostProcessing.cpp | 4 ++++ Source/Core/VideoCommon/PostProcessing.h | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Source/Core/VideoCommon/PostProcessing.cpp b/Source/Core/VideoCommon/PostProcessing.cpp index 027ad85ab5..756bcea5e0 100644 --- a/Source/Core/VideoCommon/PostProcessing.cpp +++ b/Source/Core/VideoCommon/PostProcessing.cpp @@ -63,6 +63,10 @@ std::vector PostProcessingShaderImplementation::GetAnaglyphShaderLi return {}; } +PostProcessingShaderConfiguration::PostProcessingShaderConfiguration() = default; + +PostProcessingShaderConfiguration::~PostProcessingShaderConfiguration() = default; + std::string PostProcessingShaderConfiguration::LoadShader(std::string shader) { // Load the shader from the configuration if there isn't one sent to us. diff --git a/Source/Core/VideoCommon/PostProcessing.h b/Source/Core/VideoCommon/PostProcessing.h index f453fff587..d114b26523 100644 --- a/Source/Core/VideoCommon/PostProcessing.h +++ b/Source/Core/VideoCommon/PostProcessing.h @@ -48,8 +48,9 @@ public: typedef std::map ConfigMap; - PostProcessingShaderConfiguration() : m_current_shader("") {} - virtual ~PostProcessingShaderConfiguration() {} + PostProcessingShaderConfiguration(); + virtual ~PostProcessingShaderConfiguration(); + // Loads the configuration with a shader // If the argument is "" the class will load the shader from the g_activeConfig option. // Returns the loaded shader source from file @@ -69,7 +70,7 @@ public: void SetOptionb(const std::string& option, bool value); private: - bool m_any_options_dirty; + bool m_any_options_dirty = false; std::string m_current_shader; ConfigMap m_options; From 8ce6f9bae581283f49898cdd0ed5114393a37db1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 21 May 2018 11:57:15 -0400 Subject: [PATCH 2/4] PostProcessing: Replace typedef with a using alias --- Source/Core/VideoCommon/PostProcessing.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/PostProcessing.h b/Source/Core/VideoCommon/PostProcessing.h index d114b26523..30f3bf966f 100644 --- a/Source/Core/VideoCommon/PostProcessing.h +++ b/Source/Core/VideoCommon/PostProcessing.h @@ -46,7 +46,7 @@ public: bool m_dirty; }; - typedef std::map ConfigMap; + using ConfigMap = std::map; PostProcessingShaderConfiguration(); virtual ~PostProcessingShaderConfiguration(); From 9d1b6cdea401b4afadda95e38b8e6e8c337a39f7 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 21 May 2018 11:59:04 -0400 Subject: [PATCH 3/4] PostProcessing: Make member functions const qualified where applicable These functions don't modify internal class state --- Source/Core/VideoCommon/PostProcessing.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Core/VideoCommon/PostProcessing.h b/Source/Core/VideoCommon/PostProcessing.h index 30f3bf966f..fc60fb4676 100644 --- a/Source/Core/VideoCommon/PostProcessing.h +++ b/Source/Core/VideoCommon/PostProcessing.h @@ -57,10 +57,10 @@ public: std::string LoadShader(std::string shader = ""); void SaveOptionsConfiguration(); void ReloadShader(); - std::string GetShader() { return m_current_shader; } - bool IsDirty() { return m_any_options_dirty; } + std::string GetShader() const { return m_current_shader; } + bool IsDirty() const { return m_any_options_dirty; } void SetDirty(bool dirty) { m_any_options_dirty = dirty; } - bool HasOptions() { return m_options.size() > 0; } + bool HasOptions() const { return m_options.size() > 0; } const ConfigMap& GetOptions() const { return m_options; } ConfigMap& GetOptions() { return m_options; } const ConfigurationOption& GetOption(const std::string& option) { return m_options[option]; } From c4d27cc8ec2222ec7ad650b212a2c3b005f51f0f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 21 May 2018 12:07:46 -0400 Subject: [PATCH 4/4] PostProcessing: Make GetShader() return by constant reference We don't need to create copies of the shader string when they can be avoided. --- Source/Core/VideoCommon/PostProcessing.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/PostProcessing.h b/Source/Core/VideoCommon/PostProcessing.h index fc60fb4676..e610b7fc38 100644 --- a/Source/Core/VideoCommon/PostProcessing.h +++ b/Source/Core/VideoCommon/PostProcessing.h @@ -57,7 +57,7 @@ public: std::string LoadShader(std::string shader = ""); void SaveOptionsConfiguration(); void ReloadShader(); - std::string GetShader() const { return m_current_shader; } + const std::string& GetShader() const { return m_current_shader; } bool IsDirty() const { return m_any_options_dirty; } void SetDirty(bool dirty) { m_any_options_dirty = dirty; } bool HasOptions() const { return m_options.size() > 0; }