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