ScummVM API documentation
libretro.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BACKENDS_GRAPHICS_OPENGL_PIPELINES_LIBRETRO_H
23 #define BACKENDS_GRAPHICS_OPENGL_PIPELINES_LIBRETRO_H
24 
25 #include "graphics/opengl/system_headers.h"
26 
27 #if !USE_FORCED_GLES
28 #include "backends/graphics/opengl/pipelines/shader.h"
29 
30 #include "common/array.h"
31 #include "common/fs.h"
32 
33 namespace Graphics {
34 struct Surface;
35 }
36 
37 namespace OpenGL {
38 
39 namespace LibRetro {
40 struct ShaderPreset;
41 struct ShaderPass;
42 } // End of namespace LibRetro
43 
44 class TextureTarget;
45 class LibRetroTextureTarget;
46 
50 class LibRetroPipeline : public Pipeline {
51 public:
53  ~LibRetroPipeline() override;
54 
55  void setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) override;
56  void setProjectionMatrix(const Math::Matrix4 &projectionMatrix) override;
57 
58  bool open(const Common::Path &shaderPath, Common::SearchSet &archSet);
59  void close();
60 
61  /* Called by OpenGLGraphicsManager */
62  void enableLinearFiltering(bool enabled) { _linearFiltering = enabled; }
63  void setRotation(Common::RotationMode rotation) { if (_rotation != rotation) { _rotation = rotation; setPipelineState(); } }
64  /* Called by OpenGLGraphicsManager to setup the internal objects sizes */
65  void setDisplaySizes(uint inputWidth, uint inputHeight, const Common::Rect &outputRect);
66  /* Called by OpenGLGraphicsManager to indicate that next draws need to be scaled. */
67  void beginScaling();
68  /* Called by OpenGLGraphicsManager to indicate that next draws don't need to be scaled.
69  * This must be called to execute scaling. */
70  void finishScaling();
71  bool isAnimated() const { return _isAnimated; }
72 
73  static bool isSupportedByContext() {
74  return OpenGLContext.shadersSupported
75  && OpenGLContext.multitextureSupported
76  && OpenGLContext.framebufferObjectSupported;
77  }
78 private:
79  void activateInternal() override;
80  void deactivateInternal() override;
81  void drawTextureInternal(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) override;
82 
83  bool loadTextures(Common::SearchSet &archSet);
84  bool loadPasses(Common::SearchSet &archSet);
85 
86  void setPipelineState();
87  bool setupFBOs();
88  void setupPassUniforms(const uint id);
89  void setShaderTexUniforms(const Common::String &prefix, Shader *shader, const Texture &texture);
90 
91  /* Pipelines used to draw all layers
92  * First before the scaler then after it to draw on screen
93  */
94  ShaderPipeline _inputPipeline;
95  ShaderPipeline _outputPipeline;
96  bool _needsScaling;
97 
98  const LibRetro::ShaderPreset *_shaderPreset;
99 
100  uint _inputWidth;
101  uint _inputHeight;
102  Common::Rect _outputRect;
103 
104  bool _linearFiltering;
105  Common::RotationMode _rotation;
106 
107  /* Determines if preset depends on frameCount or from previous frames */
108  bool _isAnimated;
109  uint _frameCount;
110 
112  uint _currentTarget;
113 
114  struct LibRetroTexture {
115  LibRetroTexture() : textureData(nullptr), glTexture(nullptr) {}
116  LibRetroTexture(Graphics::Surface *tD, Texture *glTex) : textureData(tD), glTexture(glTex) {}
117 
118  Common::String id;
119  Graphics::Surface *textureData;
120  Texture *glTexture;
121  };
122  LibRetroTexture loadTexture(const Common::Path &fileName, Common::Archive *container, Common::SearchSet &archSet);
123 
125  TextureArray _textures;
126 
127  struct Pass {
128  Pass()
129  : shaderPass(nullptr), shader(nullptr), target(nullptr), texCoords(), texSamplers(),
130  inputTexture(nullptr), vertexCoord(), hasFrameCount(false), prevCount(0) {}
131  Pass(const LibRetro::ShaderPass *sP, Shader *s, TextureTarget *t)
132  : shaderPass(sP), shader(s), target(t), texCoords(), texSamplers(),
133  inputTexture(nullptr), vertexCoord(), hasFrameCount(false), prevCount(0) {}
134 
135  const LibRetro::ShaderPass *shaderPass;
136  Shader *shader;
137  TextureTarget *target;
138 
147 
148  enum Type {
153 
158 
162  kTypePrev
163  };
164 
169 
173  uint index;
174 
175  TexCoordAttribute() : name(), type(), index() {}
176  TexCoordAttribute(const Common::String &n, Type t, uint i) : name(n), type(t), index(i) {}
177  };
178 
180  TexCoordAttributeArray texCoords;
181 
187  void buildTexCoords(const uint id, const Common::StringArray &aliases);
188 
189  void addTexCoord(const Common::String &prefix, const TexCoordAttribute::Type type, const uint index);
190 
194  struct TextureSampler {
198  uint unit;
199 
200  enum Type {
205 
210 
214  kTypePrev
215  };
216 
221 
225  uint index;
226 
227  TextureSampler() : unit(), type(), index() {}
228  TextureSampler(uint u, Type t, uint i) : unit(u), type(t), index(i) {}
229  };
230 
232  TextureSamplerArray texSamplers;
233 
240  void buildTexSamplers(const uint id, const TextureArray &textures, const Common::StringArray &aliases);
241 
242  bool addTexSampler(const Common::String &name, uint *unit, const TextureSampler::Type type, const uint index, const bool prefixIsId = false);
243 
247  const Texture *inputTexture;
248 
252  GLfloat vertexCoord[2*4];
253 
258  bool hasFrameCount;
259 
263  uint prevCount;
264  };
265 
267  PassArray _passes;
268 
269  void renderPass(const Pass &pass);
270  void renderPassSetupCoordinates(const Pass &pass);
271  void renderPassSetupTextures(const Pass &pass);
272 };
273 
274 } // End of namespace OpenGL
275 #endif // !USE_FORCED_GLES
276 
277 #endif
Definition: str.h:59
Definition: surface.h:67
Definition: shader.h:32
Definition: libretro.h:50
Common::String name
Definition: libretro.h:146
Definition: rect.h:524
Definition: path.h:52
Definition: shader.h:56
Definition: archive.h:141
Definition: types.h:85
Definition: framebuffer.h:203
Definition: archive.h:330
uint index
Definition: libretro.h:225
Type type
Definition: libretro.h:220
Definition: formatinfo.h:28
Definition: renderbuffer.h:27
Definition: texture.h:48
uint unit
Definition: libretro.h:198
Definition: types.h:115
RotationMode
Definition: rotationmode.h:44
Definition: pipeline.h:40