PostProcessing.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright 2014 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <map>
  6. #include <string>
  7. #include <vector>
  8. #include "Common/StringUtil.h"
  9. #include "Common/Timer.h"
  10. #include "VideoCommon/VideoCommon.h"
  11. class PostProcessingShaderConfiguration
  12. {
  13. public:
  14. struct ConfigurationOption
  15. {
  16. enum OptionType
  17. {
  18. OPTION_BOOL = 0,
  19. OPTION_FLOAT,
  20. OPTION_INTEGER,
  21. };
  22. bool m_bool_value;
  23. std::vector<float> m_float_values;
  24. std::vector<s32> m_integer_values;
  25. std::vector<float> m_float_min_values;
  26. std::vector<s32> m_integer_min_values;
  27. std::vector<float> m_float_max_values;
  28. std::vector<s32> m_integer_max_values;
  29. std::vector<float> m_float_step_values;
  30. std::vector<s32> m_integer_step_values;
  31. OptionType m_type;
  32. std::string m_gui_name;
  33. std::string m_option_name;
  34. std::string m_dependent_option;
  35. bool m_dirty;
  36. };
  37. typedef std::map<std::string, ConfigurationOption> ConfigMap;
  38. PostProcessingShaderConfiguration() : m_current_shader("") {}
  39. virtual ~PostProcessingShaderConfiguration() {}
  40. // Loads the configuration with a shader
  41. // If the argument is "" the class will load the shader from the g_activeConfig option.
  42. // Returns the loaded shader source from file
  43. std::string LoadShader(std::string shader = "");
  44. void SaveOptionsConfiguration();
  45. void ReloadShader();
  46. std::string GetShader() { return m_current_shader; }
  47. bool IsDirty() { return m_any_options_dirty; }
  48. void SetDirty(bool dirty) { m_any_options_dirty = dirty; }
  49. bool HasOptions() { return m_options.size() > 0; }
  50. ConfigMap& GetOptions() { return m_options; }
  51. const ConfigurationOption& GetOption(const std::string& option) { return m_options[option]; }
  52. // For updating option's values
  53. void SetOptionf(const std::string& option, int index, float value);
  54. void SetOptioni(const std::string& option, int index, s32 value);
  55. void SetOptionb(const std::string& option, bool value);
  56. private:
  57. bool m_any_options_dirty;
  58. std::string m_current_shader;
  59. ConfigMap m_options;
  60. void LoadOptions(const std::string& code);
  61. void LoadOptionsConfiguration();
  62. };
  63. class PostProcessingShaderImplementation
  64. {
  65. public:
  66. PostProcessingShaderImplementation();
  67. virtual ~PostProcessingShaderImplementation();
  68. PostProcessingShaderConfiguration* GetConfig() { return &m_config; }
  69. // Should be implemented by the backends for backend specific code
  70. virtual void BlitFromTexture(TargetRectangle src, TargetRectangle dst,
  71. int src_texture, int src_width, int src_height, int layer = 0) = 0;
  72. virtual void ApplyShader() = 0;
  73. protected:
  74. // Timer for determining our time value
  75. Common::Timer m_timer;
  76. PostProcessingShaderConfiguration m_config;
  77. };