ScummVM API documentation
base_render_opengl3d.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/math/vector2.h"
27 #include "engines/wintermute/dctypes.h"
28 
29 #include "graphics/transform_struct.h"
30 
31 #if defined(USE_OPENGL_GAME)
32 
33 #include "graphics/opengl/system_headers.h"
34 
35 namespace Wintermute {
36 
37 class BaseSurfaceOpenGL3D;
38 
39 class BaseRenderOpenGL3D : public BaseRenderer3D {
40  friend class BaseSurfaceOpenGL3D;
41  friend class Mesh3DSOpenGL;
42  friend class XMeshOpenGL;
43  friend class ShadowVolumeOpenGL;
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 nx;
65  float ny;
66  float nz;
67  float x;
68  float y;
69  float z;
70  float u;
71  float v;
72  };
73 
74 public:
75  BaseRenderOpenGL3D(BaseGame *inGame = nullptr);
76  ~BaseRenderOpenGL3D() override;
77 
78  bool invalidateTexture(BaseSurfaceOpenGL3D *texture) override;
79 
80  bool invalidateDeviceObjects() override;
81  bool restoreDeviceObjects() override;
82 
83  bool resetDevice() override;
84 
85  void setSpriteBlendMode(Graphics::TSpriteBlendMode blendMode, bool forceChange = false) override;
86 
87  void setAmbientLightRenderState() override;
88 
89  int getMaxActiveLights() override;
90  void lightEnable(int index, bool enable) override;
91  void setLightParameters(int index, const DXVector3 &position, const DXVector3 &direction, const DXVector4 &diffuse, bool spotlight) override;
92 
93  void enableCulling() override;
94  void disableCulling() override;
95 
96  bool enableShadows() override;
97  bool disableShadows() override;
98  bool stencilSupported() override;
99 
100  BaseImage *takeScreenshot(int newWidth = 0, int newHeight = 0) override;
101  void fadeToColor(byte r, byte g, byte b, byte a) override;
102 
103  bool flip() override;
104  bool clear() override;
105 
106  bool setViewport(int left, int top, int right, int bottom) override;
107  bool fillRect(int x, int y, int w, int h, uint32 color) override;
108 
109  DXMatrix *buildMatrix(DXMatrix* out, const DXVector2 *centre, const DXVector2 *scaling, float angle);
110  void transformVertices(struct SpriteVertex *vertices, const DXVector2 *centre, const DXVector2 *scaling, float angle);
111 
112  bool setProjection() override;
113  bool setProjection2D();
114  bool setWorldTransform(const DXMatrix &transform) override;
115  bool setViewTransform(const DXMatrix &transform) override;
116  bool setProjectionTransform(const DXMatrix &transform) override;
117 
118  bool initRenderer(int width, int height, bool windowed) override;
119  bool setup2D(bool force = false) override;
120  bool setup3D(Camera3D *camera, bool force = false) override;
121 
122  Common::String getName() const override {
123  return "OpenGL 3D renderer";
124  };
125  bool displayDebugInfo() override {
126  return STATUS_FAILED;
127  };
128  bool drawShaderQuad() override {
129  return STATUS_FAILED;
130  }
131 
132  float getScaleRatioX() const override {
133  return 1.0f;
134  }
135  float getScaleRatioY() const override {
136  return 1.0f;
137  }
138 
139  BaseSurface *createSurface() override;
140 
141  bool startSpriteBatch() override;
142  bool endSpriteBatch() override;
143  bool commitSpriteBatch() override;
144 
145  bool drawSpriteEx(BaseSurface *texture, const Common::Rect32 &rect, const Vector2 &pos, const Vector2 &rot, const Vector2 &scale,
146  float angle, uint32 color, bool alphaDisable, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) override;
147 
148  void renderSceneGeometry(const BaseArray<AdWalkplane *> &planes, const BaseArray<AdBlock *> &blocks,
149  const BaseArray<AdGeneric *> &generics, const BaseArray<Light3D *> &lights, Camera3D *camera) override;
150  void renderShadowGeometry(const BaseArray<AdWalkplane *> &planes, const BaseArray<AdBlock *> &blocks, const BaseArray<AdGeneric *> &generics, Camera3D *camera) override;
151 
152  Mesh3DS *createMesh3DS() override;
153  XMesh *createXMesh() override;
154  ShadowVolume *createShadowVolume() override;
155 
156  bool setViewport3D(DXViewport *viewport) override;
157 
158  void postfilter() override;
159  void setPostfilter(PostFilter postFilter) override { _postFilterMode = postFilter; };
160 
161 private:
162  bool setupLines();
163  void displaySimpleShadow(BaseObject *object) override;
164 
165  Graphics::TSpriteBlendMode _blendMode;
166  SimpleShadowVertex _simpleShadow[4];
167  Common::Array<DXVector4> _lightPositions;
168  Common::Array<DXVector3> _lightDirections;
169  GLuint _postfilterTexture;
170 };
171 
172 } // wintermute namespace
173 
174 #endif // defined(USE_OPENGL_GAME)
175 
176 #endif
Definition: rect.h:526
Definition: str.h:59
Definition: array.h:52
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: achievements_tables.h:27