ScummVM API documentation
gfx_opengl_shaders.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 GRIM_GFX_OPENGL_SHADERS_H
23 #define GRIM_GFX_OPENGL_SHADERS_H
24 
25 #include "engines/grim/actor.h"
26 #include "engines/grim/gfx_base.h"
27 
28 #include "graphics/opengl/shader.h"
29 
30 #include "common/stack.h"
31 #include "common/rect.h"
32 
33 namespace Grim {
34 
35 class GfxOpenGLS : public GfxBase {
36 public:
37  GfxOpenGLS();
38  virtual ~GfxOpenGLS();
39 
46  void setupScreen(int screenW, int screenH) override;
47 
53  bool isHardwareAccelerated() override { return true; };
54  bool supportsShaders() override { return true; }
55  void setupCameraFrustum(float fov, float nclip, float fclip) override;
56  void positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest, float roll) override;
57  void positionCamera(const Math::Vector3d &pos, const Math::Matrix4 &rot) override;
58 
59  Math::Matrix4 getModelView() override;
60  Math::Matrix4 getProjection() override;
61 
62  void clearScreen() override;
63  void clearDepthBuffer() override;
64 
68  void flipBuffer(bool opportunistic = false) override;
69 
70  void getScreenBoundingBox(const Mesh *mesh, int *x1, int *y1, int *x2, int *y2) override;
71  void getScreenBoundingBox(const EMIModel *model, int *x1, int *y1, int *x2, int *y2) override;
72  void getActorScreenBBox(const Actor *actor, Common::Point &p1, Common::Point &p2) override;
73  void startActorDraw(const Actor *actor) override;
74 
75  void finishActorDraw() override;
76  void setShadow(Shadow *shadow) override;
77  void drawShadowPlanes() override;
78  void setShadowMode() override;
79  void clearShadowMode() override;
80  bool isShadowModeActive() override;
81  void setShadowColor(byte r, byte g, byte b) override;
82  void getShadowColor(byte *r, byte *g, byte *b) override;
83  void destroyShadow(Shadow *shadow) override;
84 
85  void set3DMode() override;
86 
87  void translateViewpointStart() override;
88  void translateViewpoint(const Math::Vector3d &vec) override;
89  void rotateViewpoint(const Math::Angle &angle, const Math::Vector3d &axis) override;
90  void rotateViewpoint(const Math::Matrix4 &rot) override;
91  void translateViewpointFinish() override;
92 
93  void drawEMIModelFace(const EMIModel* model, const EMIMeshFace* face) override;
94  void drawModelFace(const Mesh *mesh, const MeshFace *face) override;
95  void drawSprite(const Sprite *sprite) override;
96  void drawMesh(const Mesh *mesh) override;
97  void drawDimPlane() override;
98 
99  void enableLights() override;
100  void disableLights() override;
101  void setupLight(Light *light, int lightId) override;
102  void turnOffLight(int lightId) override;
103 
104  void createTexture(Texture *texture, const uint8 *data, const CMap *cmap, bool clamp) override;
105  void selectTexture(const Texture *texture) override;
106  void destroyTexture(Texture *texture) override;
107 
121  void createBitmap(BitmapData *bitmap) override;
122 
131  void drawBitmap(const Bitmap *bitmap, int x, int y, uint32 layer = 0) override;
132 
142  void destroyBitmap(BitmapData *bitmap) override;
143 
144  void createFont(Font *font) override;
145  void destroyFont(Font *font) override;
146 
147  void createTextObject(TextObject *text) override;
148  void drawTextObject(const TextObject *text) override;
149  void destroyTextObject(TextObject *text) override;
150 
151  Bitmap *getScreenshot(int w, int h, bool useStored) override;
152  void storeDisplay() override;
153  void copyStoredToDisplay() override;
154 
160  void dimScreen() override;
161  void dimRegion(int x, int y, int w, int h, float level) override;
162 
171  void irisAroundRegion(int x1, int y1, int x2, int y2) override;
172 
173  void drawEmergString(int x, int y, const char *text, const Color &fgColor) override;
174  void loadEmergFont() override;
175 
176  void drawRectangle(const PrimitiveObject *primitive) override;
177  void drawLine(const PrimitiveObject *primitive) override;
178  void drawPolygon(const PrimitiveObject *primitive) override;
179 
180  const Graphics::PixelFormat getMovieFormat() const override;
181 
192  void prepareMovieFrame(Graphics::Surface* frame) override;
193  void drawMovieFrame(int offsetX, int offsetY) override;
194 
201  void releaseMovieFrame() override;
202 
203  const char *getVideoDeviceName() override;
204 
205  void renderBitmaps(bool render) override;
206  void renderZBitmaps(bool render) override;
207 
208  void createMesh(Mesh *mesh) override;
209  void destroyMesh(const Mesh *mesh) override;
210  void createEMIModel(EMIModel *model) override;
211  void updateEMIModel(const EMIModel* model) override;
212  void destroyEMIModel(EMIModel *model) override;
213 
214  void setBlendMode(bool additive) override;
215 
216 protected:
217  void setupShaders();
218  GLuint compileShader(const char *vertex, const char *fragment);
219  GLuint compileShader(const char *shader) { return compileShader(shader, shader); }
220  void createSpecialtyTextureFromScreen(uint id, uint8 *data, int x, int y, int width, int height) override;
221 
222 private:
223  const Actor *_currentActor;
224  float _alpha;
225  int _maxLights;
226  GLuint _emergTexture;
227  OpenGL::Shader* _emergProgram;
228 
229  OpenGL::Shader* _backgroundProgram;
230  OpenGL::Shader* _actorProgram;
231  OpenGL::Shader* _actorLightsProgram;
232  OpenGL::Shader* _spriteProgram;
233  OpenGL::Shader* _dimProgram;
234  OpenGL::Shader* _dimPlaneProgram;
235  OpenGL::Shader* _dimRegionProgram;
236  OpenGL::Shader* _smushProgram;
237  GLuint _smushVBO, _quadEBO;
238  OpenGL::Shader* _textProgram;
239  OpenGL::Shader* _primitiveProgram;
240  OpenGL::Shader* _irisProgram;
241  OpenGL::Shader* _shadowPlaneProgram;
242 
243  int _smushWidth;
244  int _smushHeight;
245  GLuint _smushTexId;
246  void setupTexturedQuad();
247  void setupQuadEBO();
248 
249  void setupZBuffer();
250  void drawDepthBitmap(int bitmapId, int x, int y, int w, int h, char *data);
251 
252  float _fov;
253  float _nclip;
254  float _fclip;
255  Math::Matrix4 _projMatrix;
256  Math::Matrix4 _viewMatrix;
257  Math::Matrix4 _mvpMatrix;
258  Math::Matrix4 _overworldProjMatrix;
259 
260  void setupTexturedCenteredQuad();
261 
262  GLuint _spriteVBO;
263 
264  Common::Stack<Math::Matrix4> _matrixStack;
265  Texture *_selectedTexture;
266 
267  GLuint _zBufTex;
268  Math::Vector2d _zBufTexCrop;
269 
270  struct GLSLight {
271  Math::Vector4d _position;
272  Math::Vector4d _direction;
273  Math::Vector4d _color;
274  Math::Vector4d _params;
275  };
276 
277  GLSLight *_lights;
278  bool _hasAmbientLight;
279  bool _lightsEnabled;
280 
281  void setupPrimitives();
282  GLuint nextPrimitive();
283  GLuint _primitiveVBOs[32];
284  uint32 _currentPrimitive;
285  void drawGenericPrimitive(const float *vertices, uint32 numVertices, const PrimitiveObject *primitive);
286  GLuint _irisVBO;
287  GLuint _dimVBO;
288  GLuint _dimRegionVBO;
289  GLuint _blastVBO;
290  GLuint _storedDisplay;
291 };
292 
293 }
294 
295 #endif
Definition: set.h:184
void getScreenBoundingBox(const Mesh *mesh, int *x1, int *y1, int *x2, int *y2) override
Definition: surface.h:67
Definition: actor.h:55
void drawBitmap(const Bitmap *bitmap, int x, int y, uint32 layer=0) override
Definition: modelemi.h:82
void setupScreen(int screenW, int screenH) override
Definition: pixelformat.h:138
void createBitmap(BitmapData *bitmap) override
void releaseMovieFrame() override
Definition: gfx_opengl_shaders.h:35
Definition: actor.h:33
Definition: shader.h:56
Definition: model.h:92
Definition: sprite.h:38
Definition: model.h:124
Definition: bitmap.h:125
bool isHardwareAccelerated() override
Definition: gfx_opengl_shaders.h:53
Definition: bitmap.h:50
Definition: textobject.h:84
Definition: gfx_base.h:62
Definition: modelemi.h:55
Definition: colormap.h:35
Definition: rect.h:45
void destroyBitmap(BitmapData *bitmap) override
void dimScreen() override
Definition: primitives.h:34
Definition: font.h:38
Actor represents a 3D character on screen.
Definition: actor.h:72
void irisAroundRegion(int x1, int y1, int x2, int y2) override
void flipBuffer(bool opportunistic=false) override
Definition: material.h:31
Definition: color.h:29
void prepareMovieFrame(Graphics::Surface *frame) override
bool supportsShaders() override
Definition: gfx_opengl_shaders.h:54