ScummVM API documentation
base_renderer3d.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_RENDERER_3D_H
23 #define WINTERMUTE_BASE_RENDERER_3D_H
24 
25 #include "engines/wintermute/base/gfx/base_renderer.h"
26 #include "engines/wintermute/coll_templ.h"
27 #include "engines/wintermute/dctypes.h"
28 #include "engines/wintermute/math/vector2.h"
29 
30 #include "graphics/transform_struct.h"
31 #include "graphics/surface.h"
32 
33 #if defined(USE_OPENGL_SHADERS)
34 
35 #include "graphics/opengl/system_headers.h"
36 
37 #include "engines/wintermute/base/gfx/xmath.h"
38 
39 #endif
40 
41 namespace Wintermute {
42 
43 class AdBlock;
44 class AdGeneric;
45 class AdWalkplane;
46 class BaseSurfaceOpenGL3D;
47 class Light3D;
48 class Mesh3DS;
49 class XMesh;
50 class ShadowVolume;
51 
52 #define DEFAULT_NEAR_PLANE 90.0f
53 #define DEFAULT_FAR_PLANE 10000.0f
54 
55 enum PostFilter {
56  kPostFilterOff,
57  kPostFilterBlackAndWhite,
58  kPostFilterSepia
59 };
60 
61 class BaseRenderer3D : public BaseRenderer {
62 public:
63  BaseRenderer3D(BaseGame *inGame = nullptr);
64  ~BaseRenderer3D() override;
65 
66  bool getProjectionParams(float *resWidth, float *resHeight, float *layerWidth, float *layerHeight,
67  float *modWidth, float *modHeight, bool *customViewport);
68  virtual int getMaxActiveLights() = 0;
69 
70  bool setAmbientLightColor(uint32 color);
71  bool setDefaultAmbientLightColor();
72 
73  uint32 _ambientLightColor;
74  bool _ambientLightOverride;
75 
76  void dumpData(const char *filename) {};
77  bool setup3DCustom(DXMatrix &viewMat, DXMatrix &projMat);
78  virtual bool enableShadows() = 0;
79  virtual bool disableShadows() = 0;
80  virtual bool stencilSupported() = 0;
81  virtual bool invalidateTexture(BaseSurfaceOpenGL3D *texture) = 0;
82 
83  virtual void setSpriteBlendMode(Graphics::TSpriteBlendMode blendMode, bool forceChange = false) = 0;
84 
85  virtual bool invalidateDeviceObjects() = 0;
86  virtual bool restoreDeviceObjects() = 0;
87  BaseSurfaceOpenGL3D *_lastTexture;
88  void fade(uint16 alpha) override;
89  bool drawSprite(BaseSurface *texture, const Common::Rect32 &rect, float zoomX, float zoomY, const Vector2 &pos,
90  uint32 color, bool alphaDisable, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY);
91  virtual bool drawSpriteEx(BaseSurface *texture, const Common::Rect32 &rect, const Vector2 &pos, const Vector2 &rot, const Vector2 &scale,
92  float angle, uint32 color, bool alphaDisable, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) = 0;
93  Camera3D *_camera;
94  virtual bool resetDevice() = 0;
95  void initLoop() override;
96  bool windowedBlt() override;
97 
98  virtual bool startSpriteBatch() override = 0;
99  virtual bool endSpriteBatch() override = 0;
100  virtual bool commitSpriteBatch() = 0;
101 
102 
103  // ScummVM specific methods -->
104 
105  virtual void lightEnable(int index, bool enable) = 0;
106  virtual void setLightParameters(int index, const DXVector3 &position, const DXVector3 &direction,
107  const DXVector4 &diffuse, bool spotlight) = 0;
108 
109  virtual void enableCulling() = 0;
110  virtual void disableCulling() = 0;
111 
112  DXViewport getViewPort();
113 
114  void setWindowed(bool windowed) override;
115  void onWindowChange() override;
116 
117  Graphics::PixelFormat getPixelFormat() const override;
118 
119  virtual bool setWorldTransform(const DXMatrix &transform) = 0;
120  virtual bool setViewTransform(const DXMatrix &transform) = 0;
121  virtual bool setProjectionTransform(const DXMatrix &transform) = 0;
122 
123  void getWorldTransform(DXMatrix *transform) {
124  *transform = _worldMatrix;
125  }
126 
127  void getViewTransform(DXMatrix *transform) {
128  *transform = _viewMatrix;
129  }
130 
131  void getProjectionTransform(DXMatrix *transform) {
132  *transform = _projectionMatrix;
133  }
134 
135  virtual Mesh3DS *createMesh3DS() = 0;
136  virtual XMesh *createXMesh() = 0;
137  virtual ShadowVolume *createShadowVolume() = 0;
138 
139 
140  virtual void renderSceneGeometry(const BaseArray<AdWalkplane *> &planes, const BaseArray<AdBlock *> &blocks,
141  const BaseArray<AdGeneric *> &generics, const BaseArray<Light3D *> &lights, Camera3D *camera) = 0;
142  virtual void renderShadowGeometry(const BaseArray<AdWalkplane *> &planes, const BaseArray<AdBlock *> &blocks, const BaseArray<AdGeneric *> &generics, Camera3D *camera) = 0;
143 
144  virtual void displaySimpleShadow(BaseObject *object) = 0;
145 
146  virtual void postfilter() = 0;
147  virtual void setPostfilter(PostFilter postFilter) = 0;
148  bool flip() override;
149  bool indicatorFlip() override;
150  bool forcedFlip() override;
151  virtual bool setViewport3D(DXViewport *viewport) = 0;
152 
153  // ScummVM specific methods <--
154 
155 protected:
156  DXMatrix _worldMatrix;
157  DXMatrix _viewMatrix;
158  DXMatrix _projectionMatrix;
159  DXViewport _viewport{};
160  float _fov;
161  float _nearClipPlane;
162  float _farClipPlane;
163  TRendererState _state;
164  PostFilter _postFilterMode;
165 
166  virtual void setAmbientLightRenderState() = 0;
167 };
168 
169 } // namespace Wintermute
170 
171 #endif
Definition: base_game.h:75
Definition: rect.h:526
Definition: xmath.h:50
Definition: pixelformat.h:138
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: xmath.h:140
Definition: vector2.h:33
Definition: xmesh.h:48
Definition: base_surface.h:37
void fade(uint16 alpha) override
Definition: 3dmesh.h:55
Definition: 3dshadow_volume.h:49
Definition: base_renderer3d.h:61
Definition: coll_templ.h:347
Definition: base_renderer.h:53
Definition: xmath.h:117
Definition: xmath.h:79
Definition: 3dcamera.h:38
Definition: base_object.h:49
Definition: achievements_tables.h:27
bool indicatorFlip() override