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
28#include "graphics/opengl/system_headers.h"
29#include "graphics/transform_struct.h"
30
31#if defined(USE_OPENGL_SHADERS)
32
33#include "graphics/opengl/shader.h"
34
35namespace Wintermute {
36
37class BaseSurfaceOpenGL3D;
38
39class BaseRenderOpenGL3DShader : public BaseRenderer3D {
40 friend class BaseSurfaceOpenGL3DShader;
41 friend class Mesh3DSOpenGLShader;
42 friend class XMeshOpenGLShader;
43 friend class ShadowVolumeOpenGLShader;
44
45 struct SpriteVertex {
46 float x;
47 float y;
48 float z;
49 float u;
50 float v;
51 float r;
52 float g;
53 float b;
54 float a;
55 };
56
57 struct RectangleVertex {
58 float x;
59 float y;
60 float z;
61 };
62
63 struct SimpleShadowVertex {
64 float x;
65 float y;
66 float z;
67 float nx;
68 float ny;
69 float nz;
70 float u;
71 float v;
72 };
73
74
75public:
76 BaseRenderOpenGL3DShader(BaseGame *inGame = nullptr);
77 ~BaseRenderOpenGL3DShader() override;
78
79 bool invalidateTexture(BaseSurface *texture) override;
80
81 bool invalidateDeviceObjects() override;
82 bool restoreDeviceObjects() override;
83
84 bool resetDevice() override;
85
86 void setSpriteBlendMode(Graphics::TSpriteBlendMode blendMode, bool forceChange = false) override;
87
88 void setAmbientLightRenderState() override;
89
90 int getMaxActiveLights() override;
91 void lightEnable(int index, bool enable) override;
92 void setLightParameters(int index, const DXVector3 &position, const DXVector3 &direction, const DXVector4 &diffuse, bool spotlight) override;
93
94 void enableCulling() override;
95 void disableCulling() override;
96
97 bool enableShadows() override;
98 bool disableShadows() override;
99 bool shadowVolumeSupported() override;
100
101 BaseImage *takeScreenshot(int newWidth = 0, int newHeight = 0) override;
102 bool fadeToColor(byte r, byte g, byte b, byte a) override;
103 bool flip() override;
104 bool clear() override;
105
106 bool setViewport(int left, int top, int right, int bottom) override;
107 bool drawLine(int x1, int y1, int x2, int y2, uint32 color) 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 DXVector2 &pos, const DXVector2 &rot, const DXVector2 &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
164private:
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 GLuint _brightnessVBO{};
185 OpenGL::Shader *_spriteShader{};
186 OpenGL::Shader *_fadeShader{};
187 OpenGL::Shader *_xmodelShader{};
188 OpenGL::Shader *_geometryShader{};
189 OpenGL::Shader *_simpleShadowShader{};
190 OpenGL::Shader *_flatShadowShader{};
191 OpenGL::Shader *_shadowVolumeShader{};
192 OpenGL::Shader *_lineShader{};
193 OpenGL::Shader *_postfilterShader{};
194 OpenGL::Shader *_brightnessShaderOknytt{};
195 OpenGL::Shader *_brightnessShaderJulia{};
196 GLuint _postfilterTexture;
197};
198
199} // namespace Wintermute
200
201#endif // defined(USE_OPENGL_SHADERS)
202
203#endif
Definition: array.h:52
Definition: str.h:59
Definition: shader.h:56
Definition: rect.h:538