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  /* Called by OpenGLGraphicsManager to setup the internal objects sizes */
64  void setDisplaySizes(uint inputWidth, uint inputHeight, const Common::Rect &outputRect);
65  /* Called by OpenGLGraphicsManager to indicate that next draws need to be scaled. */
66  void beginScaling();
67  /* Called by OpenGLGraphicsManager to indicate that next draws don't need to be scaled.
68  * This must be called to execute scaling. */
69  void finishScaling();
70  bool isAnimated() const { return _isAnimated; }
71 
72  static bool isSupportedByContext() {
73  return OpenGLContext.shadersSupported
74  && OpenGLContext.multitextureSupported
75  && OpenGLContext.framebufferObjectSupported;
76  }
77 private:
78  void activateInternal() override;
79  void deactivateInternal() override;
80  void drawTextureInternal(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) override;
81 
82  bool loadTextures(Common::SearchSet &archSet);
83  bool loadPasses(Common::SearchSet &archSet);
84 
85  void setPipelineState();
86  bool setupFBOs();
87  void setupPassUniforms(const uint id);
88  void setShaderTexUniforms(const Common::String &prefix, Shader *shader, const Texture &texture);
89 
90  /* Pipelines used to draw all layers
91  * First before the scaler then after it to draw on screen
92  */
93  ShaderPipeline _inputPipeline;
94  ShaderPipeline _outputPipeline;
95  bool _needsScaling;
96 
97  const LibRetro::ShaderPreset *_shaderPreset;
98 
99  uint _inputWidth;
100  uint _inputHeight;
101  Common::Rect _outputRect;
102 
103  bool _linearFiltering;
104 
105  /* Determines if preset depends on frameCount or from previous frames */
106  bool _isAnimated;
107  uint _frameCount;
108 
110  uint _currentTarget;
111 
112  struct LibRetroTexture {
113  LibRetroTexture() : textureData(nullptr), glTexture(nullptr) {}
114  LibRetroTexture(Graphics::Surface *tD, Texture *glTex) : textureData(tD), glTexture(glTex) {}
115 
116  Common::String id;
117  Graphics::Surface *textureData;
118  Texture *glTexture;
119  };
120  LibRetroTexture loadTexture(const Common::Path &fileName, Common::Archive *container, Common::SearchSet &archSet);
121 
123  TextureArray _textures;
124 
125  struct Pass {
126  Pass()
127  : shaderPass(nullptr), shader(nullptr), target(nullptr), texCoords(), texSamplers(),
128  inputTexture(nullptr), vertexCoord(), hasFrameCount(false), prevCount(0) {}
129  Pass(const LibRetro::ShaderPass *sP, Shader *s, TextureTarget *t)
130  : shaderPass(sP), shader(s), target(t), texCoords(), texSamplers(),
131  inputTexture(nullptr), vertexCoord(), hasFrameCount(false), prevCount(0) {}
132 
133  const LibRetro::ShaderPass *shaderPass;
134  Shader *shader;
135  TextureTarget *target;
136 
145 
146  enum Type {
151 
156 
160  kTypePrev
161  };
162 
167 
171  uint index;
172 
173  TexCoordAttribute() : name(), type(), index() {}
174  TexCoordAttribute(const Common::String &n, Type t, uint i) : name(n), type(t), index(i) {}
175  };
176 
178  TexCoordAttributeArray texCoords;
179 
185  void buildTexCoords(const uint id, const Common::StringArray &aliases);
186 
187  void addTexCoord(const Common::String &prefix, const TexCoordAttribute::Type type, const uint index);
188 
192  struct TextureSampler {
196  uint unit;
197 
198  enum Type {
203 
208 
212  kTypePrev
213  };
214 
219 
223  uint index;
224 
225  TextureSampler() : unit(), type(), index() {}
226  TextureSampler(uint u, Type t, uint i) : unit(u), type(t), index(i) {}
227  };
228 
230  TextureSamplerArray texSamplers;
231 
238  void buildTexSamplers(const uint id, const TextureArray &textures, const Common::StringArray &aliases);
239 
240  bool addTexSampler(const Common::String &name, uint *unit, const TextureSampler::Type type, const uint index, const bool prefixIsId = false);
241 
245  const Texture *inputTexture;
246 
250  GLfloat vertexCoord[2*4];
251 
256  bool hasFrameCount;
257 
261  uint prevCount;
262  };
263 
265  PassArray _passes;
266 
267  void renderPass(const Pass &pass);
268  void renderPassSetupCoordinates(const Pass &pass);
269  void renderPassSetupTextures(const Pass &pass);
270 };
271 
272 } // End of namespace OpenGL
273 #endif // !USE_FORCED_GLES
274 
275 #endif
Definition: str.h:59
Definition: surface.h:67
Definition: shader.h:32
Definition: libretro.h:50
Common::String name
Definition: libretro.h:144
Definition: rect.h:144
Definition: path.h:52
Definition: shader.h:56
Definition: archive.h:141
Definition: types.h:85
Definition: framebuffer.h:203
Definition: archive.h:312
uint index
Definition: libretro.h:223
Type type
Definition: libretro.h:218
Definition: formatinfo.h:28
Definition: renderbuffer.h:27
Definition: texture.h:47
uint unit
Definition: libretro.h:196
Definition: types.h:115
Definition: pipeline.h:42