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

zdirtyrect.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 /*
00024  * This file is based on, or a modified version of code from TinyGL (C) 1997-1998 Fabrice Bellard,
00025  * which is licensed under the zlib-license (see LICENSE).
00026  * It also has modifications by the ResidualVM-team, which are covered under the GPLv2 (or later).
00027  */
00028 
00029 #ifndef GRAPHICS_TINYGL_ZRECT_H_
00030 #define GRAPHICS_TINYGL_ZRECT_H_
00031 
00032 #include "common/rect.h"
00033 #include "graphics/tinygl/zblit.h"
00034 #include "common/array.h"
00035 
00036 namespace TinyGL {
00037     struct GLContext;
00038     struct GLVertex;
00039     struct GLTexture;
00040 }
00041 
00042 namespace Internal {
00043     void *allocateFrame(int size);
00044 }
00045 
00046 namespace Graphics {
00047 
00048 class DrawCall {
00049 public:
00050 
00051     enum DrawCallType {
00052         DrawCall_Rasterization,
00053         DrawCall_Blitting,
00054         DrawCall_Clear
00055     };
00056 
00057     DrawCall(DrawCallType type) : _type(type) { }
00058     virtual ~DrawCall() { }
00059     bool operator==(const DrawCall &other) const;
00060     bool operator!=(const DrawCall &other) const {
00061         return !(*this == other);
00062     }
00063     virtual void execute(bool restoreState) const = 0;
00064     virtual void execute(const Common::Rect &clippingRectangle, bool restoreState) const = 0;
00065     DrawCallType getType() const { return _type; }
00066     virtual const Common::Rect getDirtyRegion() const { return _dirtyRegion; }
00067 protected:
00068     Common::Rect _dirtyRegion;
00069 private:
00070     DrawCallType _type;
00071 };
00072 
00073 class ClearBufferDrawCall : public DrawCall {
00074 public:
00075     ClearBufferDrawCall(bool clearZBuffer, int zValue, bool clearColorBuffer, int rValue, int gValue, int bValue);
00076     virtual ~ClearBufferDrawCall() { }
00077     bool operator==(const ClearBufferDrawCall &other) const;
00078     virtual void execute(bool restoreState) const;
00079     virtual void execute(const Common::Rect &clippingRectangle, bool restoreState) const;
00080 
00081     void *operator new(size_t size) {
00082         return ::Internal::allocateFrame(size);
00083     }
00084 
00085     void operator delete(void *p) { }
00086 private:
00087     bool _clearZBuffer, _clearColorBuffer;
00088     int _rValue, _gValue, _bValue, _zValue;
00089 };
00090 
00091 // Encapsulate a rasterization call: it might execute either a triangle or line rasterization.
00092 class RasterizationDrawCall : public DrawCall {
00093 public:
00094     RasterizationDrawCall();
00095     virtual ~RasterizationDrawCall() { }
00096     bool operator==(const RasterizationDrawCall &other) const;
00097     virtual void execute(bool restoreState) const;
00098     virtual void execute(const Common::Rect &clippingRectangle, bool restoreState) const;
00099 
00100     void *operator new(size_t size) {
00101         return ::Internal::allocateFrame(size);
00102     }
00103 
00104     void operator delete(void *p) { }
00105 private:
00106     void computeDirtyRegion();
00107     typedef void (*gl_draw_triangle_func_ptr)(TinyGL::GLContext *c, TinyGL::GLVertex *p0, TinyGL::GLVertex *p1, TinyGL::GLVertex *p2);
00108     int _vertexCount;
00109     TinyGL::GLVertex *_vertex;
00110     gl_draw_triangle_func_ptr _drawTriangleFront, _drawTriangleBack; 
00111 
00112     struct RasterizationState {
00113         int beginType;
00114         int currentFrontFace;
00115         int cullFaceEnabled;
00116         int colorMask;
00117         int depthTest;
00118         int depthFunction;
00119         int depthWrite;
00120         int shadowMode;
00121         int texture2DEnabled;
00122         int currentShadeModel;
00123         int polygonModeBack;
00124         int polygonModeFront;
00125         int lightingEnabled;
00126         bool enableBlending;
00127         int sfactor, dfactor;
00128         int textureVersion;
00129         int depthTestEnabled;
00130         float viewportTranslation[3];
00131         float viewportScaling[3];
00132         bool alphaTest;
00133         int alphaFunc, alphaRefValue;
00134         TinyGL::GLTexture *texture;
00135         unsigned char *shadowMaskBuf;
00136 
00137         bool operator==(const RasterizationState &other) const;
00138     };
00139 
00140     RasterizationState _state;
00141 
00142     RasterizationState captureState() const;
00143     void applyState(const RasterizationState &state) const;
00144 };
00145 
00146 // Encapsulate a blit call: it might execute either a color buffer or z buffer blit.
00147 class BlittingDrawCall : public DrawCall {
00148 public:
00149     enum BlittingMode {
00150         BlitMode_Regular,
00151         BlitMode_NoBlend,
00152         BlitMode_Fast,
00153         BlitMode_ZBuffer
00154     };
00155 
00156     BlittingDrawCall(BlitImage *image, const BlitTransform &transform, BlittingMode blittingMode);
00157     virtual ~BlittingDrawCall();
00158     bool operator==(const BlittingDrawCall &other) const;
00159     virtual void execute(bool restoreState) const;
00160     virtual void execute(const Common::Rect &clippingRectangle, bool restoreState) const;
00161 
00162     BlittingMode getBlittingMode() const { return _mode; }
00163     
00164     void *operator new(size_t size) {
00165         return ::Internal::allocateFrame(size);
00166     }
00167 
00168     void operator delete(void *p) { }
00169 private:
00170     void computeDirtyRegion();
00171     BlitImage *_image;
00172     BlitTransform _transform;
00173     BlittingMode _mode;
00174     int _imageVersion;
00175 
00176     struct BlittingState {
00177         bool enableBlending;
00178         int sfactor, dfactor;
00179         bool alphaTest;
00180         int alphaFunc, alphaRefValue;
00181         int depthTestEnabled;
00182 
00183         bool operator==(const BlittingState &other) const {
00184             return  enableBlending == other.enableBlending &&
00185                     sfactor == other.sfactor &&
00186                     dfactor == other.dfactor &&
00187                     alphaTest == other.alphaTest &&
00188                     alphaFunc == other.alphaFunc && 
00189                     alphaRefValue == other.alphaRefValue &&
00190                     depthTestEnabled == other.depthTestEnabled;
00191         }
00192     };
00193 
00194     BlittingState captureState() const;
00195     void applyState(const BlittingState &state) const;
00196 
00197     BlittingState _blitState;
00198 };
00199 
00200 } // end of namespace Graphics
00201 
00202 #endif


Generated on Sat Jul 13 2019 05:01:16 for ResidualVM by doxygen 1.7.1
curved edge   curved edge