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 
43 
44  uint
45  sourceRGB,
46  operandRGB,
47  sourceAlpha,
48  operandAlpha;
49 };
50 
51 struct GLTextureEnv {
52  GLTextureEnv();
53  bool isDefault() const;
54 
55  uint envMode, combineRGB, combineAlpha;
56  byte constA, constR, constG, constB;
57  GLTextureEnvArgument arg0, arg1;
58 };
59 
60 class DrawCall {
61 public:
62 
63  enum DrawCallType {
64  DrawCall_Rasterization,
65  DrawCall_Blitting,
66  DrawCall_Clear
67  };
68 
69  DrawCall(DrawCallType type) : _type(type) { }
70  virtual ~DrawCall() { }
71  bool operator==(const DrawCall &other) const;
72  bool operator!=(const DrawCall &other) const {
73  return !(*this == other);
74  }
75  virtual void execute(bool restoreState, const Common::Rect *clippingRectangle = nullptr) const = 0;
76  DrawCallType getType() const { return _type; }
77  virtual const Common::Rect getDirtyRegion() const { return _dirtyRegion; }
78 protected:
79  Common::Rect _dirtyRegion;
80 private:
81  DrawCallType _type;
82 };
83 
84 class ClearBufferDrawCall : public DrawCall {
85 public:
86  ClearBufferDrawCall(bool clearZBuffer, int zValue, bool clearColorBuffer, int rValue, int gValue, int bValue, bool clearStencilBuffer, int stencilValue);
87  virtual ~ClearBufferDrawCall() { }
88  bool operator==(const ClearBufferDrawCall &other) const;
89  virtual void execute(bool restoreState, const Common::Rect *clippingRectangle = nullptr) const;
90 
91  void *operator new(size_t size) {
92  return Internal::allocateFrame(size);
93  }
94 
95  void operator delete(void *p) { }
96 private:
97  bool _clearZBuffer, _clearColorBuffer, _clearStencilBuffer;
98  int _rValue, _gValue, _bValue, _zValue, _stencilValue;
99  struct ClearBufferState {
100  bool enableScissor;
101  int scissor[4];
102 
103  bool operator==(const ClearBufferState &other) const {
104  return
105  enableScissor == other.enableScissor &&
106  scissor[0] == other.scissor[0] &&
107  scissor[1] == other.scissor[1] &&
108  scissor[2] == other.scissor[2] &&
109  scissor[3] == other.scissor[3];
110  }
111  };
112 
113  ClearBufferState captureState() const;
114  void applyState(const ClearBufferState &state, const Common::Rect *clippingRectangle) const;
115 
116  ClearBufferState _clearState;
117 };
118 
119 // Encapsulate a rasterization call: it might execute either a triangle or line rasterization.
121 public:
123  virtual ~RasterizationDrawCall() { }
124  bool operator==(const RasterizationDrawCall &other) const;
125  virtual void execute(bool restoreState, const Common::Rect *clippingRectangle = nullptr) const;
126 
127  void *operator new(size_t size) {
128  return Internal::allocateFrame(size);
129  }
130 
131  void operator delete(void *p) { }
132 private:
133  void computeDirtyRegion();
134  typedef void (*gl_draw_triangle_func_ptr)(GLContext *c, TinyGL::GLVertex *p0, TinyGL::GLVertex *p1, TinyGL::GLVertex *p2);
135  int _vertexCount;
136  GLVertex *_vertex;
137  gl_draw_triangle_func_ptr _drawTriangleFront, _drawTriangleBack;
138 
139  struct RasterizationState {
140  bool enableScissor;
141  int scissor[4];
142  int beginType;
143  int currentFrontFace;
144  int cullFaceEnabled;
145  bool colorMaskRed;
146  bool colorMaskGreen;
147  bool colorMaskBlue;
148  bool colorMaskAlpha;
149  bool depthTestEnabled;
150  int depthFunction;
151  int depthWriteMask;
152  bool texture2DEnabled;
153  int currentShadeModel;
154  int polygonModeBack;
155  int polygonModeFront;
156  int lightingEnabled;
157  bool enableBlending;
158  int sfactor;
159  int dfactor;
160  int textureVersion;
161  int offsetStates;
162  float offsetFactor;
163  float offsetUnits;
164  float viewportTranslation[3];
165  float viewportScaling[3];
166  bool alphaTestEnabled;
167  int alphaFunc;
168  int alphaRefValue;
169  bool stencilTestEnabled;
170  int stencilTestFunc;
171  byte stencilValue;
172  byte stencilMask;
173  byte stencilWriteMask;
174  int stencilSfail;
175  int stencilDpfail;
176  int stencilDppass;
177  bool polygonStippleEnabled;
178  byte polygonStipplePattern[128];
179  uint32 stippleColor;
180  bool two_color_stipple_enabled;
181  GLTexture *texture;
182  uint wrapS, wrapT;
183  GLTextureEnv textureEnv;
184  bool fogEnabled;
185  float fogColorR;
186  float fogColorG;
187  float fogColorB;
188 
189  bool operator==(const RasterizationState &other) const;
190  };
191 
192  RasterizationState _state;
193 
194  RasterizationState captureState() const;
195  void applyState(const RasterizationState &state, const Common::Rect *clippingRectangle) const;
196 };
197 
198 // Encapsulate a blit call: it might execute either a color buffer or z buffer blit.
199 class BlittingDrawCall : public DrawCall {
200 public:
201  enum BlittingMode {
202  BlitMode_Regular,
203  BlitMode_Fast,
204  BlitMode_ZBuffer
205  };
206 
207  BlittingDrawCall(BlitImage *image, const BlitTransform &transform, BlittingMode blittingMode);
208  virtual ~BlittingDrawCall();
209  bool operator==(const BlittingDrawCall &other) const;
210  virtual void execute(bool restoreState, const Common::Rect *clippingRectangle = nullptr) const;
211 
212  BlittingMode getBlittingMode() const { return _mode; }
213 
214  void *operator new(size_t size) {
215  return Internal::allocateFrame(size);
216  }
217 
218  void operator delete(void *p) { }
219 private:
220  void computeDirtyRegion();
221  BlitImage *_image;
222  BlitTransform _transform;
223  BlittingMode _mode;
224  int _imageVersion;
225 
226  struct BlittingState {
227  bool enableScissor;
228  int scissor[4];
229  bool enableBlending;
230  int sfactor, dfactor;
231  bool alphaTest;
232  int alphaFunc, alphaRefValue;
233  int depthTestEnabled;
234 
235  bool operator==(const BlittingState &other) const {
236  return
237  enableScissor == other.enableScissor &&
238  scissor[0] == other.scissor[0] &&
239  scissor[1] == other.scissor[1] &&
240  scissor[2] == other.scissor[2] &&
241  scissor[3] == other.scissor[3] &&
242  enableBlending == other.enableBlending &&
243  sfactor == other.sfactor &&
244  dfactor == other.dfactor &&
245  alphaTest == other.alphaTest &&
246  alphaFunc == other.alphaFunc &&
247  alphaRefValue == other.alphaRefValue &&
248  depthTestEnabled == other.depthTestEnabled;
249  }
250  };
251 
252  BlittingState captureState() const;
253  void applyState(const BlittingState &state, const Common::Rect *clippingRectangle) const;
254 
255  BlittingState _blitState;
256 };
257 
258 } // end of namespace TinyGL
259 
260 #endif
Definition: zdirtyrect.h:199
Definition: zblit_public.h:31
Definition: zdirtyrect.h:60
Definition: zdirtyrect.h:120
Definition: rect.h:524
Definition: colormasks.h:27
Definition: zgl.h:206
Definition: zdirtyrect.h:84
Definition: zgl.h:165
Definition: zdirtyrect.h:41
Definition: zgl.h:283
Definition: ios7_video.h:39
Definition: zdirtyrect.h:51