ScummVM API documentation
base_render_opengl3d_shader.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 WINTERMUTE_BASE_RENDER_OPENGL3D_H
23 #define WINTERMUTE_BASE_RENDER_OPENGL3D_H
24 
25 #include "engines/wintermute/base/gfx/base_renderer3d.h"
26 #include "engines/wintermute/dctypes.h"
27 #include "engines/wintermute/math/vector2.h"
28 
29 #include "graphics/opengl/system_headers.h"
30 #include "graphics/transform_struct.h"
31 
32 #if defined(USE_OPENGL_SHADERS)
33 
34 #include "graphics/opengl/shader.h"
35 
36 namespace Wintermute {
37 
38 class BaseSurfaceOpenGL3D;
39 
40 class BaseRenderOpenGL3DShader : public BaseRenderer3D {
41  friend class BaseSurfaceOpenGL3DShader;
42  friend class Mesh3DSOpenGLShader;
43  friend class XMeshOpenGLShader;
44  friend class ShadowVolumeOpenGLShader;
45 
46  struct SpriteVertex {
47  float x;
48  float y;
49  float z;
50  float u;
51  float v;
52  float r;
53  float g;
54  float b;
55  float a;
56  };
57 
58  struct RectangleVertex {
59  float x;
60  float y;
61  float z;
62  };
63 
64  struct SimpleShadowVertex {
65  float x;
66  float y;
67  float z;
68  float nx;
69  float ny;
70  float nz;
71  float u;
72  float v;
73  };
74 
75 
76 public:
77  BaseRenderOpenGL3DShader(BaseGame *inGame = nullptr);
78  ~BaseRenderOpenGL3DShader() override;
79 
80  bool invalidateTexture(BaseSurfaceOpenGL3D *texture) override;
81 
82  bool invalidateDeviceObjects() override;
83  bool restoreDeviceObjects() override;
84 
85  bool resetDevice() override;
86 
87  void setSpriteBlendMode(Graphics::TSpriteBlendMode blendMode, bool forceChange = false) override;
88 
89  void setAmbientLightRenderState() override;
90 
91  int getMaxActiveLights() override;
92  void lightEnable(int index, bool enable) override;
93  void setLightParameters(int index, const DXVector3 &position, const DXVector3 &direction, const DXVector4 &diffuse, bool spotlight) override;
94 
95  void enableCulling() override;
96  void disableCulling() override;
97 
98  bool enableShadows() override;
99  bool disableShadows() override;
100  bool stencilSupported() override;
101 
102  BaseImage *takeScreenshot(int newWidth = 0, int newHeight = 0) override;
103  void fadeToColor(byte r, byte g, byte b, byte a) override;
104  bool flip() override;
105  bool clear() override;
106 
107  bool setViewport(int left, int top, int right, int bottom) override;
108  bool fillRect(int x, int y, int w, int h, uint32 color) override;
109 
110  DXMatrix *buildMatrix(DXMatrix* out, const DXVector2 *centre, const DXVector2 *scaling, float angle);
111  void transformVertices(struct SpriteVertex *vertices, const DXVector2 *centre, const DXVector2 *scaling, float angle);
112 
113  bool setProjection() override;
114  bool setProjection2D(OpenGL::Shader *);
115  bool setWorldTransform(const DXMatrix &transform) override;
116  bool setViewTransform(const DXMatrix &transform) override;
117  bool setProjectionTransform(const DXMatrix &transform) override;
118 
119  bool initRenderer(int width, int height, bool windowed) override;
120  bool setup2D(bool force = false) override;
121  bool setup3D(Camera3D *camera, bool force = false) override;
122 
123  Common::String getName() const override {
124  return "OpenGL 3D renderer";
125  };
126  bool displayDebugInfo() override {
127  return STATUS_FAILED;
128  };
129  bool drawShaderQuad() override {
130  return STATUS_FAILED;
131  }
132 
133  float getScaleRatioX() const override {
134  return 1.0f;
135  }
136  float getScaleRatioY() const override {
137  return 1.0f;
138  }
139 
140  BaseSurface *createSurface() override;
141 
142  bool startSpriteBatch() override;
143  bool endSpriteBatch() override;
144  bool commitSpriteBatch() override;
145 
146  bool drawSpriteEx(BaseSurface *texture, const Common::Rect32 &rect, const Vector2 &pos, const Vector2 &rot, const Vector2 &scale,
147  float angle, uint32 color, bool alphaDisable, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) override;
148 
149  void renderSceneGeometry(const BaseArray<AdWalkplane *> &planes, const BaseArray<AdBlock *> &blocks,
150  const BaseArray<AdGeneric *> &generics, const BaseArray<Light3D *> &lights, Camera3D *camera) override;
151  void renderShadowGeometry(const BaseArray<AdWalkplane *> &planes, const BaseArray<AdBlock *> &blocks, const BaseArray<AdGeneric *> &generics, Camera3D *camera) override;
152 
153  Mesh3DS *createMesh3DS() override;
154  XMesh *createXMesh() override;
155  ShadowVolume *createShadowVolume() override;
156 
157  bool setViewport3D(DXViewport *viewport) override;
158 
159  void postfilter() override;
160  void setPostfilter(PostFilter postFilter) override { _postFilterMode = postFilter; };
161 
162  OpenGL::Shader *_shadowMaskShader;
163 
164 private:
165  bool setupLines();
166  void displaySimpleShadow(BaseObject *object) override;
167 
168  SimpleShadowVertex _simpleShadow[4];
169 
170  Graphics::TSpriteBlendMode _blendMode;
171 
172  DXMatrix _glProjectionMatrix;
173  float _alphaRef;
174 
175  Common::Array<DXMatrix> _transformStack;
176 
177  Math::Vector4d _flatShadowColor;
178 
179  GLuint _spriteVBO{};
180  GLuint _fadeVBO{};
181  GLuint _rectangleVBO{};
182  GLuint _simpleShadowVBO{};
183  GLuint _postfilterVBO{};
184  OpenGL::Shader *_spriteShader{};
185  OpenGL::Shader *_fadeShader{};
186  OpenGL::Shader *_xmodelShader{};
187  OpenGL::Shader *_geometryShader{};
188  OpenGL::Shader *_simpleShadowShader{};
189  OpenGL::Shader *_flatShadowShader{};
190  OpenGL::Shader *_shadowVolumeShader{};
191  OpenGL::Shader *_lineShader{};
192  OpenGL::Shader *_postfilterShader{};
193  GLuint _postfilterTexture;
194 };
195 
196 } // namespace Wintermute
197 
198 #endif // defined(USE_OPENGL_SHADERS)
199 
200 #endif
Definition: rect.h:526
Definition: str.h:59
Definition: array.h:52
Definition: shader.h:56
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: achievements_tables.h:27