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