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     virtual Texture *copyScreenshotToTexture();
00141 
00143     void renderDrawable(Drawable *drawable, Window *window);
00144 
00146     void renderDrawableOverlay(Drawable *drawable, Window *window);
00147 
00149     void renderWindow(Window *window);
00150 
00152     void renderWindowOverlay(Window *window);
00153 
00154     Common::Rect viewport() const;
00155 
00161     virtual void selectTargetWindow(Window *window, bool is3D, bool scaled) = 0;
00162 
00163     void setupCameraPerspective(float pitch, float heading, float fov);
00164 
00165     bool isCubeFaceVisible(uint face);
00166 
00167     Math::Matrix4 getMvpMatrix() const { return _mvpMatrix; }
00168 
00169     void flipVertical(Graphics::Surface *s);
00170 
00171     static const int kOriginalWidth = 640;
00172     static const int kOriginalHeight = 480;
00173     static const int kTopBorderHeight = 30;
00174     static const int kBottomBorderHeight = 90;
00175     static const int kFrameHeight = 360;
00176 
00177     void computeScreenViewport();
00178 
00179 protected:
00180     OSystem *_system;
00181     Texture *_font;
00182 
00183     Common::Rect _screenViewport;
00184 
00185     Math::Matrix4 _projectionMatrix;
00186     Math::Matrix4 _modelViewMatrix;
00187     Math::Matrix4 _mvpMatrix;
00188 
00189     Math::Frustum _frustum;
00190 
00191     static const float cubeVertices[5 * 6 * 4];
00192     Math::AABB _cubeFacesAABB[6];
00193 
00194     Common::Rect getFontCharacterRect(uint8 character);
00195 
00196     Math::Matrix4 makeProjectionMatrix(float fov) const;
00197 };
00198 
00207 class FrameLimiter {
00208 public:
00209     FrameLimiter(OSystem *system, const uint framerate);
00210 
00211     void startFrame();
00212     void delayBeforeSwap();
00213 private:
00214     OSystem *_system;
00215 
00216     bool _enabled;
00217     uint _speedLimitMs;
00218     uint _startFrameTime;
00219 };
00220 
00221 Renderer *CreateGfxOpenGL(OSystem *system);
00222 Renderer *CreateGfxOpenGLShader(OSystem *system);
00223 Renderer *CreateGfxTinyGL(OSystem *system);
00224 Renderer *createRenderer(OSystem *system);
00225 
00226 } // End of namespace Myst3
00227 
00228 #endif // GFX_H_


Generated on Sat Nov 16 2019 05:00:41 for ResidualVM by doxygen 1.7.1
curved edge   curved edge