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

gfx.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 AUTHORS
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 GFX_H_
00024 #define GFX_H_
00025 
00026 #include "common/rect.h"
00027 #include "common/system.h"
00028 
00029 #include "math/frustum.h"
00030 #include "math/matrix4.h"
00031 #include "math/vector3d.h"
00032 
00033 namespace Myst3 {
00034 
00035 class Renderer;
00036 
00037 class Drawable {
00038 public:
00039     Drawable();
00040     virtual ~Drawable() {}
00041 
00042     virtual void draw() {}
00043     virtual void drawOverlay() {}
00044 
00046     bool isConstrainedToWindow() const { return _isConstrainedToWindow; }
00047 
00049     bool is3D() const { return _is3D; }
00050 
00052     bool isScaled() const { return _scaled; }
00053 
00054 protected:
00055     bool _isConstrainedToWindow;
00056     bool _is3D;
00057     bool _scaled;
00058 };
00059 
00066 class Window : public Drawable {
00067 public:
00071     virtual Common::Rect getPosition() const = 0;
00072 
00076     virtual Common::Rect getOriginalPosition() const = 0;
00077 
00081     Common::Point getCenter() const;
00082 
00086     Common::Point screenPosToWindowPos(const Common::Point &screen) const;
00087 
00091     Common::Point scalePoint(const Common::Point &screen) const;
00092 };
00093 
00094 class Texture {
00095 public:
00096     uint width;
00097     uint height;
00098     Graphics::PixelFormat format;
00099 
00100     virtual void update(const Graphics::Surface *surface) = 0;
00101     virtual void updatePartial(const Graphics::Surface *surface, const Common::Rect &rect) = 0;
00102 
00103     static const Graphics::PixelFormat getRGBAPixelFormat();
00104 protected:
00105     Texture() {}
00106     virtual ~Texture() {}
00107 };
00108 
00109 class Renderer {
00110 public:
00111     Renderer(OSystem *system);
00112     virtual ~Renderer();
00113 
00114     virtual void init() = 0;
00115     virtual void clear() = 0;
00116     void toggleFullscreen();
00117 
00121     virtual void flipBuffer() { }
00122 
00123     virtual void initFont(const Graphics::Surface *surface);
00124     virtual void freeFont();
00125 
00126     virtual Texture *createTexture(const Graphics::Surface *surface) = 0;
00127     virtual void freeTexture(Texture *texture) = 0;
00128 
00129     virtual void drawRect2D(const Common::Rect &rect, uint32 color) = 0;
00130     virtual void drawTexturedRect2D(const Common::Rect &screenRect, const Common::Rect &textureRect, Texture *texture,
00131                                     float transparency = -1.0, bool additiveBlending = false) = 0;
00132     virtual void drawTexturedRect3D(const Math::Vector3d &topLeft, const Math::Vector3d &bottomLeft,
00133                                     const Math::Vector3d &topRight, const Math::Vector3d &bottomRight,
00134                                     Texture *texture) = 0;
00135 
00136     virtual void drawCube(Texture **textures) = 0;
00137     virtual void draw2DText(const Common::String &text, const Common::Point &position) = 0;
00138 
00139     virtual Graphics::Surface *getScreenshot() = 0;
00140 
00142     void renderDrawable(Drawable *drawable, Window *window);
00143 
00145     void renderDrawableOverlay(Drawable *drawable, Window *window);
00146 
00148     void renderWindow(Window *window);
00149 
00151     void renderWindowOverlay(Window *window);
00152 
00153     Common::Rect viewport() const;
00154 
00160     virtual void selectTargetWindow(Window *window, bool is3D, bool scaled) = 0;
00161 
00162     void setupCameraPerspective(float pitch, float heading, float fov);
00163 
00164     bool isCubeFaceVisible(uint face);
00165 
00166     Math::Matrix4 getMvpMatrix() const { return _mvpMatrix; }
00167 
00168     void flipVertical(Graphics::Surface *s);
00169 
00170     static const int kOriginalWidth = 640;
00171     static const int kOriginalHeight = 480;
00172     static const int kTopBorderHeight = 30;
00173     static const int kBottomBorderHeight = 90;
00174     static const int kFrameHeight = 360;
00175 
00176     void computeScreenViewport();
00177 
00178 protected:
00179     OSystem *_system;
00180     Texture *_font;
00181 
00182     Common::Rect _screenViewport;
00183 
00184     Math::Matrix4 _projectionMatrix;
00185     Math::Matrix4 _modelViewMatrix;
00186     Math::Matrix4 _mvpMatrix;
00187 
00188     Math::Frustum _frustum;
00189 
00190     static const float cubeVertices[5 * 6 * 4];
00191     Math::AABB _cubeFacesAABB[6];
00192 
00193     Common::Rect getFontCharacterRect(uint8 character);
00194 
00195     Math::Matrix4 makeProjectionMatrix(float fov) const;
00196 };
00197 
00206 class FrameLimiter {
00207 public:
00208     FrameLimiter(OSystem *system, const uint framerate);
00209 
00210     void startFrame();
00211     void delayBeforeSwap();
00212 private:
00213     OSystem *_system;
00214 
00215     bool _enabled;
00216     uint _speedLimitMs;
00217     uint _startFrameTime;
00218 };
00219 
00220 Renderer *CreateGfxOpenGL(OSystem *system);
00221 Renderer *CreateGfxOpenGLShader(OSystem *system);
00222 Renderer *CreateGfxTinyGL(OSystem *system);
00223 Renderer *createRenderer(OSystem *system);
00224 
00225 } // End of namespace Myst3
00226 
00227 #endif // GFX_H_


Generated on Sat Sep 14 2019 05:01:18 for ResidualVM by doxygen 1.7.1
curved edge   curved edge