|
1 #ifndef __RIRASTERIZER_H |
|
2 #define __RIRASTERIZER_H |
|
3 |
|
4 /*------------------------------------------------------------------------ |
|
5 * |
|
6 * OpenVG 1.1 Reference Implementation |
|
7 * ----------------------------------- |
|
8 * |
|
9 * Copyright (c) 2007 The Khronos Group Inc. |
|
10 * |
|
11 * Permission is hereby granted, free of charge, to any person obtaining a |
|
12 * copy of this software and /or associated documentation files |
|
13 * (the "Materials "), to deal in the Materials without restriction, |
|
14 * including without limitation the rights to use, copy, modify, merge, |
|
15 * publish, distribute, sublicense, and/or sell copies of the Materials, |
|
16 * and to permit persons to whom the Materials are furnished to do so, |
|
17 * subject to the following conditions: |
|
18 * |
|
19 * The above copyright notice and this permission notice shall be included |
|
20 * in all copies or substantial portions of the Materials. |
|
21 * |
|
22 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
25 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
|
26 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
|
27 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR |
|
28 * THE USE OR OTHER DEALINGS IN THE MATERIALS. |
|
29 * |
|
30 *//** |
|
31 * \file |
|
32 * \brief Rasterizer class. |
|
33 * \note |
|
34 *//*-------------------------------------------------------------------*/ |
|
35 |
|
36 #ifndef __RIMATH_H |
|
37 #include "riMath.h" |
|
38 #endif |
|
39 |
|
40 #ifndef __RIARRAY_H |
|
41 #include "riArray.h" |
|
42 #endif |
|
43 |
|
44 #ifndef __RIPIXELPIPE_H |
|
45 #include "riPixelPipe.h" |
|
46 #endif |
|
47 |
|
48 //======================================================================= |
|
49 |
|
50 namespace OpenVGRI |
|
51 { |
|
52 |
|
53 /*-------------------------------------------------------------------*//*! |
|
54 * \brief Scalar and vector data types used by the rasterizer. |
|
55 * \param |
|
56 * \return |
|
57 * \note |
|
58 *//*-------------------------------------------------------------------*/ |
|
59 |
|
60 typedef RIfloat RScalar; //change this if you want to have different precision for rasterizer scalars and RIfloat |
|
61 |
|
62 struct RVector2 |
|
63 { |
|
64 RI_INLINE RVector2() { } |
|
65 RI_INLINE RVector2(const Vector2& v) { x = v.x; y = v.y; } |
|
66 RI_INLINE RVector2(RIfloat vx, RIfloat vy) { x = vx; y = vy; } |
|
67 RI_INLINE void set(RIfloat vx, RIfloat vy) { x = vx; y = vy; } |
|
68 RScalar x; |
|
69 RScalar y; |
|
70 }; |
|
71 |
|
72 /*-------------------------------------------------------------------*//*! |
|
73 * \brief Converts a set of edges to coverage values for each pixel and |
|
74 * calls PixelPipe::pixelPipe for painting a pixel. |
|
75 * \param |
|
76 * \return |
|
77 * \note |
|
78 *//*-------------------------------------------------------------------*/ |
|
79 |
|
80 class Rasterizer |
|
81 { |
|
82 public: |
|
83 Rasterizer(); //throws bad_alloc |
|
84 ~Rasterizer(); |
|
85 |
|
86 void setup(int vpx, int vpy, int vpwidth, int vpheight, VGFillRule fillRule, const PixelPipe* pixelPipe, RIuint32* covBuffer); |
|
87 void setScissor(const Array<Rectangle>& scissors); //throws bad_alloc |
|
88 |
|
89 void clear(); |
|
90 void addEdge(const Vector2& v0, const Vector2& v1); //throws bad_alloc |
|
91 |
|
92 int setupSamplingPattern(VGRenderingQuality renderingQuality, int numFSAASamples); |
|
93 void fill(); //throws bad_alloc |
|
94 |
|
95 void getBBox(int& sx, int& sy, int& ex, int& ey) const { sx = m_covMinx; sy = m_covMiny; ex = m_covMaxx; ey = m_covMaxy; } |
|
96 private: |
|
97 Rasterizer(const Rasterizer&); //!< Not allowed. |
|
98 const Rasterizer& operator=(const Rasterizer&); //!< Not allowed. |
|
99 |
|
100 struct ScissorEdge |
|
101 { |
|
102 ScissorEdge() : x(0), miny(0), maxy(0), direction(0) {} |
|
103 bool operator<(const ScissorEdge& e) const { return x < e.x; } |
|
104 int x; |
|
105 int miny; |
|
106 int maxy; |
|
107 int direction; //1 start, -1 end |
|
108 }; |
|
109 |
|
110 struct Edge |
|
111 { |
|
112 Edge() : v0(), v1(), direction(1) {} |
|
113 bool operator<(const Edge& e) const { return v0.y < e.v0.y; } |
|
114 RVector2 v0; |
|
115 RVector2 v1; |
|
116 int direction; |
|
117 }; |
|
118 |
|
119 struct ActiveEdge |
|
120 { |
|
121 ActiveEdge() : v0(), v1(), direction(0), minx(0.0f), maxx(0.0f), n(), cnst(0.0f) {} |
|
122 bool operator<(const ActiveEdge& e) const { return minx < e.minx; } |
|
123 RVector2 v0; |
|
124 RVector2 v1; |
|
125 int direction; //-1 down, 1 up |
|
126 RScalar minx; //for the current scanline |
|
127 RScalar maxx; //for the current scanline |
|
128 RVector2 n; |
|
129 RScalar cnst; |
|
130 }; |
|
131 |
|
132 struct Sample |
|
133 { |
|
134 Sample() : x(0.0f), y(0.0f), weight(0.0f) {} |
|
135 RScalar x; |
|
136 RScalar y; |
|
137 RScalar weight; |
|
138 }; |
|
139 |
|
140 void addBBox(const Vector2& v); |
|
141 |
|
142 Array<Edge> m_edges; |
|
143 Array<ScissorEdge> m_scissorEdges; |
|
144 bool m_scissor; |
|
145 |
|
146 Sample m_samples[RI_MAX_SAMPLES]; |
|
147 int m_numSamples; |
|
148 int m_numFSAASamples; |
|
149 RScalar m_sumWeights; |
|
150 RScalar m_sampleRadius; |
|
151 |
|
152 Vector2 m_edgeMin; |
|
153 Vector2 m_edgeMax; |
|
154 int m_covMinx; |
|
155 int m_covMiny; |
|
156 int m_covMaxx; |
|
157 int m_covMaxy; |
|
158 int m_vpx; |
|
159 int m_vpy; |
|
160 int m_vpwidth; |
|
161 int m_vpheight; |
|
162 VGFillRule m_fillRule; |
|
163 const PixelPipe* m_pixelPipe; |
|
164 RIuint32* m_covBuffer; |
|
165 }; |
|
166 |
|
167 //======================================================================= |
|
168 |
|
169 } //namespace OpenVGRI |
|
170 |
|
171 //======================================================================= |
|
172 |
|
173 #endif /* __RIRASTERIZER_H */ |