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/rect32.h"
29 #include "engines/wintermute/math/vector2.h"
30 
31 #include "graphics/transform_struct.h"
32 #include "graphics/surface.h"
33 
34 #if defined(USE_OPENGL_SHADERS)
35 
36 #include "graphics/opengl/system_headers.h"
37 
38 #include "engines/wintermute/base/gfx/xmath.h"
39 
40 #endif
41 
42 namespace Wintermute {
43 
44 class AdBlock;
45 class AdGeneric;
46 class AdWalkplane;
47 class BaseSurfaceOpenGL3D;
48 class Light3D;
49 class Mesh3DS;
50 class XMesh;
51 class ShadowVolume;
52 
53 #define DEFAULT_NEAR_PLANE 90.0f
54 #define DEFAULT_FAR_PLANE 10000.0f
55 
56 enum PostFilter {
57  kPostFilterOff,
58  kPostFilterBlackAndWhite,
59  kPostFilterSepia
60 };
61 
62 class BaseRenderer3D : public BaseRenderer {
63 public:
64  BaseRenderer3D(BaseGame *inGame = nullptr);
65  ~BaseRenderer3D() override;
66 
67  bool getProjectionParams(float *resWidth, float *resHeight, float *layerWidth, float *layerHeight,
68  float *modWidth, float *modHeight, bool *customViewport);
69  virtual int getMaxActiveLights() = 0;
70 
71  bool setAmbientLightColor(uint32 color);
72  bool setDefaultAmbientLightColor();
73 
74  uint32 _ambientLightColor;
75  bool _ambientLightOverride;
76 
77  //virtual void DumpData(char* Filename);
78  virtual bool enableShadows() = 0;
79  virtual bool disableShadows() = 0;
80  virtual bool stencilSupported() = 0;
81  virtual void displayShadow(BaseObject *object, const DXVector3 *light, bool lightPosRelative) = 0;
82  virtual bool invalidateTexture(BaseSurfaceOpenGL3D *texture) = 0;
83 
84  Graphics::TSpriteBlendMode _blendMode;
85  virtual void setSpriteBlendMode(Graphics::TSpriteBlendMode blendMode, bool forceChange = false) = 0;
86  // declared in sub class: virtual const char* GetName();
87  // declared in sub class: virtual HRESULT DisplayDebugInfo();
88 
89  // declared in sub class: virtual CBImage* TakeScreenshot();
90  // declared in sub class: virtual HRESULT SetViewport(int left, int top, int right, int bottom);
91  bool invalidateDeviceObjects();
92  // NOT declared in sub class: HRESULT RestoreDeviceObjects();
93  BaseSurfaceOpenGL3D *_lastTexture;
94  void fade(uint16 alpha) override;
95  // declared in sub class: virtual HRESULT FadeToColor(DWORD Color, RECT* rect=NULL);
96  // declared in sub class: virtual HRESULT DrawLine(int X1, int Y1, int X2, int Y2, DWORD Color);
97  // declared in sub class: virtual HRESULT SetProjection();
98  bool drawSprite(BaseSurface *texture, const Rect32 &rect, float zoomX, float zoomY, const Vector2 &pos,
99  uint32 color, bool alphaDisable, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY);
100  virtual bool drawSpriteEx(BaseSurface *texture, const Rect32 &rect, const Vector2 &pos, const Vector2 &rot, const Vector2 &scale,
101  float angle, uint32 color, bool alphaDisable, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) = 0;
102  // declared in sub class: virtual HRESULT Setup3D(C3DCamera* Camera=NULL, bool Force=false);
103  // NOT declared in sub class: virtual HRESULT Setup3DCustom(D3DXMATRIX* ViewMat, D3DXMATRIX* ProjMat);
104  // declared in sub class: virtual HRESULT Setup2D(bool Force=false);
105  // declared in sub class: virtual HRESULT SetupLines();
106  Camera3D *_camera;
107  // declared in sub class: HRESULT ResetDevice();
108  void initLoop() override;
109  // declared in sub class: virtual HRESULT Fill(BYTE r, BYTE g, BYTE b, RECT* rect=NULL);
110  // declared in sub class: virtual HRESULT Flip();
111  // declared in sub class: virtual HRESULT InitRenderer(CHWManager* hwManager);
112  // NOT declared in sub class: virtual HRESULT SwitchFullscreen();
113  // declared in sub class: virtual HRESULT WindowedBlt();
114 
115  // declared in sub class: virtual bool UsingStencilBuffer();
116 
117  virtual bool startSpriteBatch() override = 0;
118  virtual bool endSpriteBatch() override = 0;
119  virtual bool commitSpriteBatch() = 0;
120 
121  // declared in sub class: virtual HRESULT DrawShaderQuad();
122 
123 
124  // ScummVM specific methods -->
125 
126  virtual void lightEnable(int index, bool enable) = 0;
127  virtual void setLightParameters(int index, const DXVector3 &position, const DXVector3 &direction,
128  const DXVector4 &diffuse, bool spotlight) = 0;
129 
130  virtual void enableCulling() = 0;
131  virtual void disableCulling() = 0;
132 
133  DXViewport getViewPort();
134 
135  void setWindowed(bool windowed) override;
136  void onWindowChange() override;
137  bool windowedBlt() override;
138 
139  Graphics::PixelFormat getPixelFormat() const override;
140 
141  virtual bool setWorldTransform(const DXMatrix &transform) = 0;
142  virtual bool setViewTransform(const DXMatrix &transform) = 0;
143  virtual bool setProjectionTransform(const DXMatrix &transform) = 0;
144 
145  void getWorldTransform(DXMatrix *transform) {
146  *transform = _worldMatrix;
147  }
148 
149  void getViewTransform(DXMatrix *transform) {
150  *transform = _viewMatrix;
151  }
152 
153  void getProjectionTransform(DXMatrix *transform) {
154  *transform = _projectionMatrix;
155  }
156 
157  virtual Mesh3DS *createMesh3DS() = 0;
158  virtual XMesh *createXMesh() = 0;
159  virtual ShadowVolume *createShadowVolume() = 0;
160 
161 
162  virtual void renderSceneGeometry(const BaseArray<AdWalkplane *> &planes, const BaseArray<AdBlock *> &blocks,
163  const BaseArray<AdGeneric *> &generics, const BaseArray<Light3D *> &lights, Camera3D *camera) = 0;
164  virtual void renderShadowGeometry(const BaseArray<AdWalkplane *> &planes, const BaseArray<AdBlock *> &blocks, const BaseArray<AdGeneric *> &generics, Camera3D *camera) = 0;
165 
166  virtual void postfilter() = 0;
167  virtual void setPostfilter(PostFilter postFilter) = 0;
168  bool flip() override;
169  bool indicatorFlip() override;
170  bool forcedFlip() override;
171  virtual bool setViewport3D(DXViewport *viewport) = 0;
172 
173  // ScummVM specific methods <--
174 
175 protected:
176  DXMatrix _worldMatrix;
177  DXMatrix _viewMatrix;
178  DXMatrix _projectionMatrix;
179  DXViewport _viewport{};
180  float _fov;
181  float _nearClipPlane;
182  float _farClipPlane;
183  TRendererState _state;
184  bool _spriteBatchMode;
185  Graphics::TSpriteBlendMode _batchBlendMode;
186  bool _batchAlphaDisable;
187  BaseSurfaceOpenGL3D *_batchTexture;
188  PostFilter _postFilterMode;
189 
190  // NOT declared in sub class: HRESULT CreateShaderQuad();
191  virtual void setAmbientLightRenderState() = 0;
192  // NOT declared in sub class: D3DMATRIX* BuildMatrix(D3DMATRIX* pOut, const D3DXVECTOR2* centre, const D3DXVECTOR2* scaling, float angle);
193  // NOT declared in sub class: void TransformVertices(struct SPRITEVERTEX* vertices, const D3DXVECTOR2* pCentre, const D3DXVECTOR2* pScaling, float angle);
194 
195  // ScummVM specific methods:
196  void flipVertical(Graphics::Surface *s);
197 };
198 
199 } // namespace Wintermute
200 
201 #endif
Definition: base_game.h:76
Definition: surface.h:67
Definition: xmath.h:50
Definition: pixelformat.h:138
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: xmath.h:139
Definition: vector2.h:33
Definition: xmesh.h:48
Definition: rect32.h:60
Definition: base_surface.h:38
void fade(uint16 alpha) override
Definition: 3dmesh.h:55
Definition: 3dshadow_volume.h:49
Definition: base_renderer3d.h:62
Definition: coll_templ.h:63
Definition: base_renderer.h:53
Definition: xmath.h:116
Definition: xmath.h:79
Definition: 3dcamera.h:38
Definition: base_object.h:49
Definition: achievements_tables.h:27
bool indicatorFlip() override