ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

grim/gfx_opengl_shaders.h

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef GRIM_GFX_OPENGL_SHADERS_H
00024 #define GRIM_GFX_OPENGL_SHADERS_H
00025 
00026 #include "engines/grim/actor.h"
00027 #include "engines/grim/gfx_base.h"
00028 #include "graphics/opengl/shader.h"
00029 #include "common/stack.h"
00030 #include "common/rect.h"
00031 
00032 namespace Grim {
00033 
00034 class GfxOpenGLS : public GfxBase {
00035 public:
00036     GfxOpenGLS();
00037     virtual ~GfxOpenGLS();
00038 
00046     virtual byte *setupScreen(int screenW, int screenH, bool fullscreen) override;
00047 
00053     virtual bool isHardwareAccelerated() override { return true; };
00054     virtual bool supportsShaders() override { return true; }
00055     virtual void setupCameraFrustum(float fov, float nclip, float fclip) override;
00056     virtual void positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest, float roll) override;
00057     virtual void positionCamera(const Math::Vector3d &pos, const Math::Matrix4 &rot) override;
00058 
00059     virtual Math::Matrix4 getModelView() override;
00060     virtual Math::Matrix4 getProjection() override;
00061 
00062     virtual void clearScreen() override;
00063     virtual void clearDepthBuffer() override;
00064 
00068     virtual void flipBuffer() override;
00069 
00070     virtual void getScreenBoundingBox(const Mesh *mesh, int *x1, int *y1, int *x2, int *y2) override;
00071     virtual void getScreenBoundingBox(const EMIModel *model, int *x1, int *y1, int *x2, int *y2) override;
00072     void getActorScreenBBox(const Actor *actor, Common::Point &p1, Common::Point &p2) override;
00073     virtual void startActorDraw(const Actor *actor) override;
00074 
00075     virtual void finishActorDraw() override;
00076     virtual void setShadow(Shadow *shadow) override;
00077     virtual void drawShadowPlanes() override;
00078     virtual void setShadowMode() override;
00079     virtual void clearShadowMode() override;
00080     virtual bool isShadowModeActive() override;
00081     virtual void setShadowColor(byte r, byte g, byte b) override;
00082     virtual void getShadowColor(byte *r, byte *g, byte *b) override;
00083     virtual void destroyShadow(Shadow *shadow) override;
00084 
00085     virtual void set3DMode() override;
00086 
00087     virtual void translateViewpointStart() override;
00088     virtual void translateViewpoint(const Math::Vector3d &vec) override;
00089     virtual void rotateViewpoint(const Math::Angle &angle, const Math::Vector3d &axis) override;
00090     virtual void rotateViewpoint(const Math::Matrix4 &rot) override;
00091     virtual void translateViewpointFinish() override;
00092 
00093     virtual void drawEMIModelFace(const EMIModel* model, const EMIMeshFace* face) override;
00094     virtual void drawModelFace(const Mesh *mesh, const MeshFace *face) override;
00095     virtual void drawSprite(const Sprite *sprite) override;
00096     virtual void drawMesh(const Mesh *mesh) override;
00097     virtual void drawDimPlane() override;
00098 
00099     virtual void enableLights() override;
00100     virtual void disableLights() override;
00101     virtual void setupLight(Light *light, int lightId) override;
00102     virtual void turnOffLight(int lightId) override;
00103 
00104     virtual void createTexture(Texture *texture, const uint8 *data, const CMap *cmap, bool clamp) override;
00105     virtual void selectTexture(const Texture *texture) override;
00106     virtual void destroyTexture(Texture *texture) override;
00107 
00121     virtual void createBitmap(BitmapData *bitmap) override;
00122 
00131     virtual void drawBitmap(const Bitmap *bitmap, int x, int y, uint32 layer = 0) override;
00132 
00142     virtual void destroyBitmap(BitmapData *bitmap) override;
00143 
00144     virtual void createFont(Font *font) override;
00145     virtual void destroyFont(Font *font) override;
00146 
00147     virtual void createTextObject(TextObject *text) override;
00148     virtual void drawTextObject(const TextObject *text) override;
00149     virtual void destroyTextObject(TextObject *text) override;
00150 
00151     virtual Bitmap *getScreenshot(int w, int h, bool useStored) override;
00152     virtual void storeDisplay() override;
00153     virtual void copyStoredToDisplay() override;
00154 
00160     virtual void dimScreen() override;
00161     virtual void dimRegion(int x, int y, int w, int h, float level) override;
00162 
00171     virtual void irisAroundRegion(int x1, int y1, int x2, int y2) override;
00172 
00173     virtual void drawEmergString(int x, int y, const char *text, const Color &fgColor) override;
00174     virtual void loadEmergFont() override;
00175 
00176     virtual void drawRectangle(const PrimitiveObject *primitive) override;
00177     virtual void drawLine(const PrimitiveObject *primitive) override;
00178     virtual void drawPolygon(const PrimitiveObject *primitive) override;
00179 
00190     virtual void prepareMovieFrame(Graphics::Surface* frame) override;
00191     virtual void drawMovieFrame(int offsetX, int offsetY) override;
00192 
00199     virtual void releaseMovieFrame() override;
00200 
00201     virtual const char *getVideoDeviceName() override;
00202 
00203     virtual void renderBitmaps(bool render) override;
00204     virtual void renderZBitmaps(bool render) override;
00205 
00206     virtual void createMesh(Mesh *mesh) override;
00207     virtual void destroyMesh(const Mesh *mesh) override;
00208     virtual void createEMIModel(EMIModel *model) override;
00209     virtual void updateEMIModel(const EMIModel* model) override;
00210     virtual void destroyEMIModel(EMIModel *model) override;
00211 
00212     virtual void setBlendMode(bool additive) override;
00213 
00214 protected:
00215     void setupShaders();
00216     GLuint compileShader(const char *vertex, const char *fragment);
00217     GLuint compileShader(const char *shader) { return compileShader(shader, shader); }
00218     void createSpecialtyTextureFromScreen(uint id, uint8 *data, int x, int y, int width, int height) override;
00219 
00220 private:
00221     const Actor *_currentActor;
00222     float _alpha;
00223     int _maxLights;
00224     GLuint _emergTexture;
00225     OpenGL::Shader* _emergProgram;
00226 
00227     OpenGL::Shader* _backgroundProgram;
00228     OpenGL::Shader* _actorProgram;
00229     OpenGL::Shader* _spriteProgram;
00230     OpenGL::Shader* _dimProgram;
00231     OpenGL::Shader* _dimPlaneProgram;
00232     OpenGL::Shader* _dimRegionProgram;
00233     OpenGL::Shader* _smushProgram;
00234     GLuint _smushVBO, _quadEBO;
00235     OpenGL::Shader* _textProgram;
00236     OpenGL::Shader* _primitiveProgram;
00237     OpenGL::Shader* _irisProgram;
00238     OpenGL::Shader* _shadowPlaneProgram;
00239 
00240     int _smushWidth;
00241     int _smushHeight;
00242     GLuint _smushTexId;
00243     bool _smushSwizzle;
00244     bool _smushSwap;
00245     void setupTexturedQuad();
00246     void setupQuadEBO();
00247 
00248     void setupZBuffer();
00249     void drawDepthBitmap(int x, int y, int w, int h, char *data);
00250 
00251     float _fov;
00252     float _nclip;
00253     float _fclip;
00254     Math::Matrix4 _projMatrix;
00255     Math::Matrix4 _viewMatrix;
00256     Math::Matrix4 _mvpMatrix;
00257     Math::Matrix4 _overworldProjMatrix;
00258 
00259     void setupTexturedCenteredQuad();
00260 
00261     GLuint _spriteVBO;
00262 
00263     Common::Stack<Math::Matrix4> _matrixStack;
00264     Texture *_selectedTexture;
00265 
00266     GLuint _zBufTex;
00267     Math::Vector2d _zBufTexCrop;
00268 
00269     struct Light {
00270         Math::Vector4d _position;
00271         Math::Vector4d _direction;
00272         Math::Vector4d _color;
00273         Math::Vector4d _params;
00274     };
00275 
00276     Light *_lights;
00277     bool _hasAmbientLight;
00278     bool _lightsEnabled;
00279 
00280     void setupPrimitives();
00281     GLuint nextPrimitive();
00282     GLuint _primitiveVBOs[32];
00283     uint32 _currentPrimitive;
00284     void drawGenericPrimitive(const float *vertices, uint32 numVertices, const PrimitiveObject *primitive);
00285     GLuint _irisVBO;
00286     GLuint _dimVBO;
00287     GLuint _dimRegionVBO;
00288     GLuint _blastVBO;
00289     GLuint _storedDisplay;
00290 };
00291 }
00292 #endif


Generated on Sat May 25 2019 05:00:46 for ResidualVM by doxygen 1.7.1
curved edge   curved edge