ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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/rect32.h"
28 #include "engines/wintermute/math/vector2.h"
29 
30 #include "graphics/opengl/system_headers.h"
31 #include "graphics/transform_struct.h"
32 
33 #if defined(USE_OPENGL_SHADERS)
34 
35 #include "graphics/opengl/shader.h"
36 
37 namespace Wintermute {
38 
39 class BaseSurfaceOpenGL3D;
40 
41 class BaseRenderOpenGL3DShader : public BaseRenderer3D {
42  friend class BaseSurfaceOpenGL3DShader;
43  friend class Mesh3DSOpenGLShader;
44  friend class XMeshOpenGLShader;
45  friend class ShadowVolumeOpenGLShader;
46 
47  struct SpriteVertex {
48  float x;
49  float y;
50  float z;
51  float u;
52  float v;
53  float r;
54  float g;
55  float b;
56  float a;
57  };
58 
59 public:
60  BaseRenderOpenGL3DShader(BaseGame *inGame = nullptr);
61  ~BaseRenderOpenGL3DShader() override;
62 
63  bool invalidateTexture(BaseSurfaceOpenGL3D *texture) override;
64 
65  void setSpriteBlendMode(Graphics::TSpriteBlendMode blendMode, bool forceChange = false) override;
66 
67  void setAmbientLightRenderState() override;
68 
69  int getMaxActiveLights() override;
70  void lightEnable(int index, bool enable) override;
71  void setLightParameters(int index, const DXVector3 &position, const DXVector3 &direction, const DXVector4 &diffuse, bool spotlight) override;
72 
73  void enableCulling() override;
74  void disableCulling() override;
75 
76  bool enableShadows() override;
77  bool disableShadows() override;
78  void displayShadow(BaseObject *object, const DXVector3 *lightPos, bool lightPosRelative) override;
79  bool stencilSupported() override;
80 
81  void dumpData(const char *filename) override {}
82  BaseImage *takeScreenshot() override;
83  void fadeToColor(byte r, byte g, byte b, byte a) override;
84  bool flip() override;
85  bool fill(byte r, byte g, byte b, Common::Rect *rect = nullptr) override;
86 
87  bool setViewport(int left, int top, int right, int bottom) override;
88  bool drawLine(int x1, int y1, int x2, int y2, uint32 color) override;
89 
90  DXMatrix *buildMatrix(DXMatrix* out, const DXVector2 *centre, const DXVector2 *scaling, float angle);
91  void transformVertices(struct SpriteVertex *vertices, const DXVector2 *centre, const DXVector2 *scaling, float angle);
92 
93  bool setProjection() override;
94  bool setProjection2D(OpenGL::Shader *);
95  bool setWorldTransform(const DXMatrix &transform) override;
96  bool setViewTransform(const DXMatrix &transform) override;
97  bool setProjectionTransform(const DXMatrix &transform) override;
98 
99  bool initRenderer(int width, int height, bool windowed) override;
100  bool setup2D(bool force = false) override;
101  bool setup3D(Camera3D *camera, bool force = false) override;
102  bool setupLines() override;
103 
104  Common::String getName() const override {
105  return "OpenGL 3D renderer";
106  };
107  bool displayDebugInfo() override {
108  return STATUS_FAILED;
109  };
110  bool drawShaderQuad() override {
111  return STATUS_FAILED;
112  }
113 
114  float getScaleRatioX() const override {
115  return 1.0f;
116  }
117  float getScaleRatioY() const override {
118  return 1.0f;
119  }
120 
121  BaseSurface *createSurface() override;
122 
123  bool startSpriteBatch() override;
124  bool endSpriteBatch() override;
125  bool commitSpriteBatch() override;
126 
127  bool drawSpriteEx(BaseSurface *texture, const Rect32 &rect, const Vector2 &pos, const Vector2 &rot, const Vector2 &scale,
128  float angle, uint32 color, bool alphaDisable, Graphics::TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) override;
129 
130  void renderSceneGeometry(const BaseArray<AdWalkplane *> &planes, const BaseArray<AdBlock *> &blocks,
131  const BaseArray<AdGeneric *> &generics, const BaseArray<Light3D *> &lights, Camera3D *camera) override;
132  void renderShadowGeometry(const BaseArray<AdWalkplane *> &planes, const BaseArray<AdBlock *> &blocks, const BaseArray<AdGeneric *> &generics, Camera3D *camera) override;
133 
134  Mesh3DS *createMesh3DS() override;
135  XMesh *createXMesh() override;
136  ShadowVolume *createShadowVolume() override;
137 
138  bool setViewport3D(DXViewport *viewport) override;
139 
140  void postfilter() override;
141  void setPostfilter(PostFilter postFilter) override { _postFilterMode = postFilter; };
142 
143  OpenGL::Shader *_shadowMaskShader;
144 
145 private:
146  void renderSimpleShadow(BaseObject *object);
147 
148  DXMatrix _glProjectionMatrix;
149  float _alphaRef;
150 
151  Common::Array<DXMatrix> _transformStack;
152 
153  Math::Vector4d _flatShadowColor;
154 
155  GLuint _spriteVBO;
156  GLuint _fadeVBO;
157  GLuint _lineVBO;
158  OpenGL::Shader *_spriteShader{};
159  OpenGL::Shader *_fadeShader{};
160  OpenGL::Shader *_xmodelShader{};
161  OpenGL::Shader *_geometryShader{};
162  OpenGL::Shader *_shadowVolumeShader{};
163  OpenGL::Shader *_lineShader{};
164 };
165 
166 } // namespace Wintermute
167 
168 #endif // defined(USE_OPENGL_SHADERS)
169 
170 #endif
Definition: str.h:59
Definition: array.h:52
Definition: rect.h:144
Definition: shader.h:56
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
signed char * fill(signed char *first, signed char *last, Value val)
Definition: algorithm.h:168
Definition: achievements_tables.h:27