xbmc
ShaderPresetGL.h
1 /*
2  * Copyright (C) 2019 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "ShaderGL.h"
12 #include "ShaderTextureGL.h"
13 #include "cores/RetroPlayer/shaders/IShaderPreset.h"
14 #include "cores/RetroPlayer/shaders/ShaderTypes.h"
15 #include "games/GameServices.h"
16 #include "utils/Geometry.h"
17 
18 #include <memory>
19 #include <set>
20 #include <string>
21 #include <vector>
22 
23 #include "system_gl.h"
24 
25 namespace ADDON
26 {
27 class CShaderPreset;
28 class CShaderPresetAddon;
29 } // namespace ADDON
30 
31 namespace KODI
32 {
33 namespace RETRO
34 {
35 
36 class CRenderContext;
37 
38 }
39 
40 namespace SHADER
41 {
42 
43 class IShaderTexture;
45 {
46 public:
47  // Instance of CShaderPreset
48  explicit CShaderPresetGL(RETRO::CRenderContext& context,
49  unsigned videoWidth = 0,
50  unsigned videoHeight = 0);
51 
52  ~CShaderPresetGL() override;
53 
54  // implementation of IShaderPreset
55  bool ReadPresetFile(const std::string& presetPath) override;
56  bool RenderUpdate(const CPoint dest[], IShaderTexture* source, IShaderTexture* target) override;
57  void SetSpeed(double speed) override;
58  void SetVideoSize(const unsigned videoWidth, const unsigned videoHeight) override;
59  bool SetShaderPreset(const std::string& shaderPresetPath) override;
60  const std::string& GetShaderPreset() const override;
61  ShaderPassVec& GetPasses() override;
62  bool Update();
63 
64 private:
65  bool CreateShaderTextures();
66  bool CreateShaders();
67  bool CreateBuffers();
68  void UpdateViewPort();
69  void UpdateViewPort(CRect viewPort);
70  void UpdateMVPs();
71  void DisposeShaders();
72  void PrepareParameters(const IShaderTexture* texture, const CPoint dest[]);
73  void RenderShader(IShader* shader, IShaderTexture* source, IShaderTexture* target) const;
74  bool HasPathFailed(const std::string& path) const;
75 
76  // Construction parameters
77  RETRO::CRenderContext& m_context;
78 
79  // Relative path of the currently loaded shader preset
80  // If empty, it means that a preset is not currently loaded
81  std::string m_presetPath;
82 
83  // Video shaders for the shader passes
84  std::vector<std::unique_ptr<IShader>> m_pShaders;
85 
86  // Intermediate textures used for pixel shader passes
87  std::vector<std::unique_ptr<CShaderTextureGL>> m_pShaderTextures;
88 
89  // First texture (this won't be needed when we have RGB rendering
90  //std::unique_ptr<CShaderTextureCD3D> firstTexture;
91 
92  // Was the shader preset changed during the last frame?
93  bool m_bPresetNeedsUpdate = true;
94 
95  // Size of the viewport
96  float2 m_outputSize;
97 
98  // The size of the input texture itself
99  // Power-of-two sized.
100  float2 m_textureSize;
101 
102  // Size of the actual source video data (ie. 160x144 for the Game Boy)
103  float2 m_videoSize;
104 
105  // Number of frames that have passed
106  float m_frameCount = 0.0f;
107 
108  // Point/nearest neighbor sampler
109  //ID3D11SamplerState* m_pSampNearest = nullptr;
110 
111  // Linear sampler
112  //ID3D11SamplerState* m_pSampLinear = nullptr;
113 
114  // Set of paths of presets that are known to not load correctly
115  // Should not contain "" (empty path) because this signifies that a preset is not loaded
116  std::set<std::string> m_failedPaths;
117 
118  // Array of vertices that comprise the full viewport
119  CPoint m_dest[4];
120 
121  // Playback speed
122  double m_speed = 0.0;
123 
124  ShaderParameterMap GetShaderParameters(const std::vector<ShaderParameter>& parameters,
125  const std::string& sourceStr) const;
126 
127  ShaderPassVec m_passes;
128 };
129 
130 } // namespace SHADER
131 } // namespace KODI
Definition: AudioDecoder.h:18
Definition: IShaderPreset.h:23
Definition: ShaderPresetGL.h:44
Definition: RenderContext.h:43
Definition: IShader.h:25
Definition: IShaderTexture.h:15
Definition: ShaderTypes.h:108
Definition: Addon.cpp:39