ScummVM API documentation
zdirtyrect.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 GRAPHICS_TINYGL_ZRECT_H
23 #define GRAPHICS_TINYGL_ZRECT_H
24 
25 #include "common/types.h"
26 #include "common/rect.h"
27 #include "common/array.h"
28 
29 #include "graphics/tinygl/zblit.h"
30 
31 namespace TinyGL {
32 
33 namespace Internal {
34 void *allocateFrame(int size);
35 }
36 
37 struct GLContext;
38 struct GLVertex;
39 struct GLTexture;
40 
41 class DrawCall {
42 public:
43 
44  enum DrawCallType {
45  DrawCall_Rasterization,
46  DrawCall_Blitting,
47  DrawCall_Clear
48  };
49 
50  DrawCall(DrawCallType type) : _type(type) { }
51  virtual ~DrawCall() { }
52  bool operator==(const DrawCall &other) const;
53  bool operator!=(const DrawCall &other) const {
54  return !(*this == other);
55  }
56  virtual void execute(bool restoreState) const = 0;
57  virtual void execute(const Common::Rect &clippingRectangle, bool restoreState) const = 0;
58  DrawCallType getType() const { return _type; }
59  virtual const Common::Rect getDirtyRegion() const { return _dirtyRegion; }
60 protected:
61  Common::Rect _dirtyRegion;
62 private:
63  DrawCallType _type;
64 };
65 
66 class ClearBufferDrawCall : public DrawCall {
67 public:
68  ClearBufferDrawCall(bool clearZBuffer, int zValue, bool clearColorBuffer, int rValue, int gValue, int bValue, bool clearStencilBuffer, int stencilValue);
69  virtual ~ClearBufferDrawCall() { }
70  bool operator==(const ClearBufferDrawCall &other) const;
71  virtual void execute(bool restoreState) const;
72  virtual void execute(const Common::Rect &clippingRectangle, bool restoreState) const;
73 
74  void *operator new(size_t size) {
75  return Internal::allocateFrame(size);
76  }
77 
78  void operator delete(void *p) { }
79 private:
80  bool _clearZBuffer, _clearColorBuffer, _clearStencilBuffer;
81  int _rValue, _gValue, _bValue, _zValue, _stencilValue;
82 };
83 
84 // Encapsulate a rasterization call: it might execute either a triangle or line rasterization.
86 public:
88  virtual ~RasterizationDrawCall() { }
89  bool operator==(const RasterizationDrawCall &other) const;
90  virtual void execute(bool restoreState) const;
91  virtual void execute(const Common::Rect &clippingRectangle, bool restoreState) const;
92 
93  void *operator new(size_t size) {
94  return Internal::allocateFrame(size);
95  }
96 
97  void operator delete(void *p) { }
98 private:
99  void computeDirtyRegion();
100  typedef void (*gl_draw_triangle_func_ptr)(GLContext *c, TinyGL::GLVertex *p0, TinyGL::GLVertex *p1, TinyGL::GLVertex *p2);
101  int _vertexCount;
102  GLVertex *_vertex;
103  gl_draw_triangle_func_ptr _drawTriangleFront, _drawTriangleBack;
104 
105  struct RasterizationState {
106  int beginType;
107  int currentFrontFace;
108  int cullFaceEnabled;
109  bool colorMaskRed;
110  bool colorMaskGreen;
111  bool colorMaskBlue;
112  bool colorMaskAlpha;
113  bool depthTestEnabled;
114  int depthFunction;
115  int depthWriteMask;
116  bool texture2DEnabled;
117  int currentShadeModel;
118  int polygonModeBack;
119  int polygonModeFront;
120  int lightingEnabled;
121  bool enableBlending;
122  int sfactor;
123  int dfactor;
124  int textureVersion;
125  int offsetStates;
126  float offsetFactor;
127  float offsetUnits;
128  float viewportTranslation[3];
129  float viewportScaling[3];
130  bool alphaTestEnabled;
131  int alphaFunc;
132  int alphaRefValue;
133  bool stencilTestEnabled;
134  int stencilTestFunc;
135  int stencilValue;
136  uint stencilMask;
137  uint stencilWriteMask;
138  int stencilSfail;
139  int stencilDpfail;
140  int stencilDppass;
141  bool polygonStippleEnabled;
142  byte polygonStipplePattern[128];
143  GLTexture *texture;
144  uint wrapS, wrapT;
145  bool fogEnabled;
146  float fogColorR;
147  float fogColorG;
148  float fogColorB;
149 
150  bool operator==(const RasterizationState &other) const;
151  };
152 
153  RasterizationState _state;
154 
155  RasterizationState captureState() const;
156  void applyState(const RasterizationState &state) const;
157 };
158 
159 // Encapsulate a blit call: it might execute either a color buffer or z buffer blit.
160 class BlittingDrawCall : public DrawCall {
161 public:
162  enum BlittingMode {
163  BlitMode_Regular,
164  BlitMode_Fast,
165  BlitMode_ZBuffer
166  };
167 
168  BlittingDrawCall(BlitImage *image, const BlitTransform &transform, BlittingMode blittingMode);
169  virtual ~BlittingDrawCall();
170  bool operator==(const BlittingDrawCall &other) const;
171  virtual void execute(bool restoreState) const;
172  virtual void execute(const Common::Rect &clippingRectangle, bool restoreState) const;
173 
174  BlittingMode getBlittingMode() const { return _mode; }
175 
176  void *operator new(size_t size) {
177  return Internal::allocateFrame(size);
178  }
179 
180  void operator delete(void *p) { }
181 private:
182  void computeDirtyRegion();
183  BlitImage *_image;
184  BlitTransform _transform;
185  BlittingMode _mode;
186  int _imageVersion;
187 
188  struct BlittingState {
189  bool enableBlending;
190  int sfactor, dfactor;
191  bool alphaTest;
192  int alphaFunc, alphaRefValue;
193  int depthTestEnabled;
194 
195  bool operator==(const BlittingState &other) const {
196  return
197  enableBlending == other.enableBlending &&
198  sfactor == other.sfactor &&
199  dfactor == other.dfactor &&
200  alphaTest == other.alphaTest &&
201  alphaFunc == other.alphaFunc &&
202  alphaRefValue == other.alphaRefValue &&
203  depthTestEnabled == other.depthTestEnabled;
204  }
205  };
206 
207  BlittingState captureState() const;
208  void applyState(const BlittingState &state) const;
209 
210  BlittingState _blitState;
211 };
212 
213 } // end of namespace TinyGL
214 
215 #endif
Definition: zdirtyrect.h:160
Definition: zblit_public.h:31
Definition: zdirtyrect.h:41
Definition: zdirtyrect.h:85
Definition: rect.h:144
Definition: colormasks.h:27
Definition: zgl.h:206
Definition: zdirtyrect.h:66
Definition: zgl.h:165
Definition: zgl.h:283
Definition: ios7_video.h:39