s_span.h revision 7117f1b4
1/*
2 * Mesa 3-D graphics library
3 * Version:  6.5
4 *
5 * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26#ifndef S_SPAN_H
27#define S_SPAN_H
28
29
30#include "mtypes.h"
31#include "swrast.h"
32
33
34/**
35 * \defgroup SpanFlags
36 * Bitflags used for interpMask and arrayMask fields below to indicate
37 * which interpolant values and fragment arrays are in use, respectively.
38 *
39 * XXX We should replace these flags with the FRAG_BIT_ values someday...
40 */
41/*@{*/
42#define SPAN_RGBA         0x001
43#define SPAN_SPEC         0x002
44#define SPAN_INDEX        0x004
45#define SPAN_Z            0x008
46#define SPAN_W            0x010
47#define SPAN_FOG          0x020
48#define SPAN_TEXTURE      0x040
49#define SPAN_INT_TEXTURE  0x080
50#define SPAN_LAMBDA       0x100
51#define SPAN_COVERAGE     0x200
52#define SPAN_FLAT         0x400  /**< flat shading? */
53#define SPAN_XY           0x800
54#define SPAN_MASK        0x1000
55#define SPAN_VARYING     0x2000
56/*@}*/
57
58
59#if 0
60/* alternate arrangement for code below */
61struct arrays2 {
62   union {
63      GLubyte  sz1[MAX_WIDTH][4]; /* primary color */
64      GLushort sz2[MAX_WIDTH][4];
65   } rgba;
66   union {
67      GLubyte  sz1[MAX_WIDTH][4]; /* specular color and temp storage */
68      GLushort sz2[MAX_WIDTH][4];
69   } spec;
70};
71#endif
72
73
74
75/**
76 * \sw_span_arrays
77 * \brief Arrays of fragment values.
78 *
79 * These will either be computed from the span x/xStep values or
80 * filled in by glDraw/CopyPixels, etc.
81 * These arrays are separated out of sw_span to conserve memory.
82 */
83typedef struct sw_span_arrays
84{
85   /** Per-fragment attributes (indexed by FRAG_ATTRIB_* tokens) */
86   /* XXX someday look at transposing first two indexes for better memory
87    * access pattern.
88    */
89   GLfloat attribs[FRAG_ATTRIB_MAX][MAX_WIDTH][4];
90
91   /** This mask indicates which fragments are alive or culled */
92   GLubyte mask[MAX_WIDTH];
93
94   GLenum ChanType; /**< Color channel type, GL_UNSIGNED_BYTE, GL_FLOAT */
95   union {
96      struct {
97         GLubyte rgba[MAX_WIDTH][4]; /**< primary color */
98         GLubyte spec[MAX_WIDTH][4]; /**< specular color and temp storage */
99      } sz1;
100      struct {
101         GLushort rgba[MAX_WIDTH][4];
102         GLushort spec[MAX_WIDTH][4];
103      } sz2;
104   } color;
105   /** XXX these are temporary fields, pointing into above color arrays */
106   GLchan (*rgba)[4];
107   GLchan (*spec)[4];
108
109   GLint   x[MAX_WIDTH];  /**< fragment X coords */
110   GLint   y[MAX_WIDTH];  /**< fragment Y coords */
111   GLuint  z[MAX_WIDTH];  /**< fragment Z coords */
112   GLuint  index[MAX_WIDTH];  /**< Color indexes */
113   GLfloat lambda[MAX_TEXTURE_COORD_UNITS][MAX_WIDTH]; /**< Texture LOD */
114   GLfloat coverage[MAX_WIDTH];  /**< Fragment coverage for AA/smoothing */
115} SWspanarrays;
116
117
118/**
119 * The SWspan structure describes the colors, Z, fogcoord, texcoords,
120 * etc for either a horizontal run or an array of independent pixels.
121 * We can either specify a base/step to indicate interpolated values, or
122 * fill in explicit arrays of values.  The interpMask and arrayMask bitfields
123 * indicate which attributes are active interpolants or arrays, respectively.
124 *
125 * It would be interesting to experiment with multiprocessor rasterization
126 * with this structure.  The triangle rasterizer could simply emit a
127 * stream of these structures which would be consumed by one or more
128 * span-processing threads which could run in parallel.
129 */
130typedef struct sw_span
131{
132   /** Coord of first fragment in horizontal span/run */
133   GLint x, y;
134
135   /** Number of fragments in the span */
136   GLuint end;
137
138   /** This flag indicates that mask[] array is effectively filled with ones */
139   GLboolean writeAll;
140
141   /** either GL_POLYGON, GL_LINE, GL_POLYGON, GL_BITMAP */
142   GLenum primitive;
143
144   /** 0 = front-facing span, 1 = back-facing span (for two-sided stencil) */
145   GLuint facing;
146
147   /**
148    * This bitmask (of  \link SpanFlags SPAN_* flags\endlink) indicates
149    * which of the attrStart/StepX/StepY variables are relevant.
150    */
151   GLbitfield interpMask;
152
153   /** Fragment attribute interpolants */
154   GLfloat attrStart[FRAG_ATTRIB_MAX][4];   /**< initial value */
155   GLfloat attrStepX[FRAG_ATTRIB_MAX][4];   /**< dvalue/dx */
156   GLfloat attrStepY[FRAG_ATTRIB_MAX][4];   /**< dvalue/dy */
157
158   /* XXX the rest of these will go away eventually... */
159
160   /* For horizontal spans, step is the partial derivative wrt X.
161    * For lines, step is the delta from one fragment to the next.
162    */
163#if CHAN_TYPE == GL_FLOAT
164   GLfloat red, redStep;
165   GLfloat green, greenStep;
166   GLfloat blue, blueStep;
167   GLfloat alpha, alphaStep;
168   GLfloat specRed, specRedStep;
169   GLfloat specGreen, specGreenStep;
170   GLfloat specBlue, specBlueStep;
171#else /* CHAN_TYPE == GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT */
172   GLfixed red, redStep;
173   GLfixed green, greenStep;
174   GLfixed blue, blueStep;
175   GLfixed alpha, alphaStep;
176   GLfixed specRed, specRedStep;
177   GLfixed specGreen, specGreenStep;
178   GLfixed specBlue, specBlueStep;
179#endif
180   GLfixed index, indexStep;
181   GLfixed z, zStep;    /* XXX z should probably be GLuint */
182   GLfixed intTex[2], intTexStep[2];  /* s, t only */
183
184   /**
185    * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates
186    * which of the fragment arrays in the span_arrays struct are relevant.
187    */
188   GLbitfield arrayMask;
189
190   /**
191    * We store the arrays of fragment values in a separate struct so
192    * that we can allocate sw_span structs on the stack without using
193    * a lot of memory.  The span_arrays struct is about 1.4MB while the
194    * sw_span struct is only about 512 bytes.
195    */
196   SWspanarrays *array;
197} SWspan;
198
199
200
201#define INIT_SPAN(S, PRIMITIVE, END, INTERP_MASK, ARRAY_MASK)	\
202do {								\
203   (S).primitive = (PRIMITIVE);					\
204   (S).interpMask = (INTERP_MASK);				\
205   (S).arrayMask = (ARRAY_MASK);				\
206   (S).end = (END);						\
207   (S).facing = 0;						\
208   (S).array = SWRAST_CONTEXT(ctx)->SpanArrays;			\
209} while (0)
210
211
212
213extern void
214_swrast_span_default_z( GLcontext *ctx, SWspan *span );
215
216extern void
217_swrast_span_interpolate_z( const GLcontext *ctx, SWspan *span );
218
219extern void
220_swrast_span_default_fog( GLcontext *ctx, SWspan *span );
221
222extern void
223_swrast_span_default_color( GLcontext *ctx, SWspan *span );
224
225extern void
226_swrast_span_default_secondary_color(GLcontext *ctx, SWspan *span);
227
228extern void
229_swrast_span_default_texcoords( GLcontext *ctx, SWspan *span );
230
231extern GLfloat
232_swrast_compute_lambda(GLfloat dsdx, GLfloat dsdy, GLfloat dtdx, GLfloat dtdy,
233                       GLfloat dqdx, GLfloat dqdy, GLfloat texW, GLfloat texH,
234                       GLfloat s, GLfloat t, GLfloat q, GLfloat invQ);
235
236extern void
237_swrast_write_index_span( GLcontext *ctx, SWspan *span);
238
239
240extern void
241_swrast_write_rgba_span( GLcontext *ctx, SWspan *span);
242
243
244extern void
245_swrast_read_rgba_span(GLcontext *ctx, struct gl_renderbuffer *rb,
246                       GLuint n, GLint x, GLint y, GLenum type, GLvoid *rgba);
247
248extern void
249_swrast_read_index_span( GLcontext *ctx, struct gl_renderbuffer *rb,
250                         GLuint n, GLint x, GLint y, GLuint indx[] );
251
252extern void
253_swrast_get_values(GLcontext *ctx, struct gl_renderbuffer *rb,
254                   GLuint count, const GLint x[], const GLint y[],
255                   void *values, GLuint valueSize);
256
257extern void
258_swrast_put_row(GLcontext *ctx, struct gl_renderbuffer *rb,
259                GLuint count, GLint x, GLint y,
260                const GLvoid *values, GLuint valueSize);
261
262extern void
263_swrast_get_row(GLcontext *ctx, struct gl_renderbuffer *rb,
264                GLuint count, GLint x, GLint y,
265                GLvoid *values, GLuint valueSize);
266
267
268extern void *
269_swrast_get_dest_rgba(GLcontext *ctx, struct gl_renderbuffer *rb,
270                      SWspan *span);
271
272#endif
273