mesa: Restore 78-column wrapping of license text in C-style comments.
[mesa.git] / src / mesa / swrast / s_span.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.5
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28 #ifndef S_SPAN_H
29 #define S_SPAN_H
30
31
32 #include "main/config.h"
33 #include "main/glheader.h"
34 #include "main/mtypes.h"
35 #include "swrast/s_chan.h"
36 #include "swrast/swrast.h"
37
38
39 struct gl_context;
40 struct gl_renderbuffer;
41
42
43 /**
44 * \defgroup SpanFlags
45 * Special bitflags to describe span data.
46 *
47 * In general, the point/line/triangle functions interpolate/emit the
48 * attributes specified by swrast->_ActiveAttribs (i.e. FRAT_BIT_* values).
49 * Some things don't fit into that, though, so we have these flags.
50 */
51 /*@{*/
52 #define SPAN_RGBA 0x01 /**< interpMask and arrayMask */
53 #define SPAN_Z 0x02 /**< interpMask and arrayMask */
54 #define SPAN_FLAT 0x04 /**< interpMask: flat shading? */
55 #define SPAN_XY 0x08 /**< array.x[], y[] valid? */
56 #define SPAN_MASK 0x10 /**< was array.mask[] filled in by caller? */
57 #define SPAN_LAMBDA 0x20 /**< array.lambda[] valid? */
58 #define SPAN_COVERAGE 0x40 /**< array.coverage[] valid? */
59 /*@}*/
60
61
62 /**
63 * \sw_span_arrays
64 * \brief Arrays of fragment values.
65 *
66 * These will either be computed from the span x/xStep values or
67 * filled in by glDraw/CopyPixels, etc.
68 * These arrays are separated out of sw_span to conserve memory.
69 */
70 typedef struct sw_span_arrays
71 {
72 /** Per-fragment attributes (indexed by VARYING_SLOT_* tokens) */
73 /* XXX someday look at transposing first two indexes for better memory
74 * access pattern.
75 */
76 GLfloat attribs[VARYING_SLOT_MAX][SWRAST_MAX_WIDTH][4];
77
78 /** This mask indicates which fragments are alive or culled */
79 GLubyte mask[SWRAST_MAX_WIDTH];
80
81 GLenum ChanType; /**< Color channel type, GL_UNSIGNED_BYTE, GL_FLOAT */
82
83 /** Attribute arrays that don't fit into attribs[] array above */
84 /*@{*/
85 GLubyte rgba8[SWRAST_MAX_WIDTH][4];
86 GLushort rgba16[SWRAST_MAX_WIDTH][4];
87 GLchan (*rgba)[4]; /** either == rgba8 or rgba16 */
88 GLint x[SWRAST_MAX_WIDTH]; /**< fragment X coords */
89 GLint y[SWRAST_MAX_WIDTH]; /**< fragment Y coords */
90 GLuint z[SWRAST_MAX_WIDTH]; /**< fragment Z coords */
91 GLuint index[SWRAST_MAX_WIDTH]; /**< Color indexes */
92 GLfloat lambda[MAX_TEXTURE_COORD_UNITS][SWRAST_MAX_WIDTH]; /**< Texture LOD */
93 GLfloat coverage[SWRAST_MAX_WIDTH]; /**< Fragment coverage for AA/smoothing */
94 /*@}*/
95 } SWspanarrays;
96
97
98 /**
99 * The SWspan structure describes the colors, Z, fogcoord, texcoords,
100 * etc for either a horizontal run or an array of independent pixels.
101 * We can either specify a base/step to indicate interpolated values, or
102 * fill in explicit arrays of values. The interpMask and arrayMask bitfields
103 * indicate which attributes are active interpolants or arrays, respectively.
104 *
105 * It would be interesting to experiment with multiprocessor rasterization
106 * with this structure. The triangle rasterizer could simply emit a
107 * stream of these structures which would be consumed by one or more
108 * span-processing threads which could run in parallel.
109 */
110 typedef struct sw_span
111 {
112 /** Coord of first fragment in horizontal span/run */
113 GLint x, y;
114
115 /** Number of fragments in the span */
116 GLuint end;
117
118 /** for clipping left edge of spans */
119 GLuint leftClip;
120
121 /** This flag indicates that mask[] array is effectively filled with ones */
122 GLboolean writeAll;
123
124 /** either GL_POLYGON, GL_LINE, GL_POLYGON, GL_BITMAP */
125 GLenum primitive;
126
127 /** 0 = front-facing span, 1 = back-facing span (for two-sided stencil) */
128 GLuint facing;
129
130 /**
131 * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates
132 * which of the attrStart/StepX/StepY variables are relevant.
133 */
134 GLbitfield interpMask;
135
136 /** Fragment attribute interpolants */
137 GLfloat attrStart[VARYING_SLOT_MAX][4]; /**< initial value */
138 GLfloat attrStepX[VARYING_SLOT_MAX][4]; /**< dvalue/dx */
139 GLfloat attrStepY[VARYING_SLOT_MAX][4]; /**< dvalue/dy */
140
141 /* XXX the rest of these will go away eventually... */
142
143 /* For horizontal spans, step is the partial derivative wrt X.
144 * For lines, step is the delta from one fragment to the next.
145 */
146 GLfixed red, redStep;
147 GLfixed green, greenStep;
148 GLfixed blue, blueStep;
149 GLfixed alpha, alphaStep;
150 GLfixed index, indexStep;
151 GLfixed z, zStep; /**< XXX z should probably be GLuint */
152 GLfixed intTex[2], intTexStep[2]; /**< (s,t) for unit[0] only */
153
154 /**
155 * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates
156 * which of the fragment arrays in the span_arrays struct are relevant.
157 */
158 GLbitfield arrayMask;
159
160 /** Mask of VARYING_BIT_x bits */
161 GLbitfield64 arrayAttribs;
162
163 /**
164 * We store the arrays of fragment values in a separate struct so
165 * that we can allocate sw_span structs on the stack without using
166 * a lot of memory. The span_arrays struct is about 1.4MB while the
167 * sw_span struct is only about 512 bytes.
168 */
169 SWspanarrays *array;
170 } SWspan;
171
172
173
174 #define INIT_SPAN(S, PRIMITIVE) \
175 do { \
176 (S).primitive = (PRIMITIVE); \
177 (S).interpMask = 0x0; \
178 (S).arrayMask = 0x0; \
179 (S).arrayAttribs = 0x0; \
180 (S).end = 0; \
181 (S).leftClip = 0; \
182 (S).facing = 0; \
183 (S).array = SWRAST_CONTEXT(ctx)->SpanArrays; \
184 } while (0)
185
186
187
188 extern void
189 _swrast_span_default_attribs(struct gl_context *ctx, SWspan *span);
190
191 extern void
192 _swrast_span_interpolate_z( const struct gl_context *ctx, SWspan *span );
193
194 extern GLfloat
195 _swrast_compute_lambda(GLfloat dsdx, GLfloat dsdy, GLfloat dtdx, GLfloat dtdy,
196 GLfloat dqdx, GLfloat dqdy, GLfloat texW, GLfloat texH,
197 GLfloat s, GLfloat t, GLfloat q, GLfloat invQ);
198
199
200 extern void
201 _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span);
202
203
204 extern void
205 _swrast_read_rgba_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
206 GLuint n, GLint x, GLint y, GLvoid *rgba);
207
208 extern void
209 _swrast_put_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
210 GLenum datatype,
211 GLuint count, GLint x, GLint y,
212 const void *values, const GLubyte *mask);
213
214 extern void *
215 _swrast_get_dest_rgba(struct gl_context *ctx, struct gl_renderbuffer *rb,
216 SWspan *span);
217
218 #endif