s_span.h revision c1f859d4
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 "swrast.h"
31
32
33/**
34 * \defgroup SpanFlags
35 * Special bitflags to describe span data.
36 *
37 * In general, the point/line/triangle functions interpolate/emit the
38 * attributes specified by swrast->_ActiveAttribs (i.e. FRAT_BIT_* values).
39 * Some things don't fit into that, though, so we have these flags.
40 */
41/*@{*/
42#define SPAN_RGBA       0x01  /**< interpMask and arrayMask */
43#define SPAN_INDEX      0x02  /**< interpMask and arrayMask */
44#define SPAN_Z          0x04  /**< interpMask and arrayMask */
45#define SPAN_FLAT       0x08  /**< interpMask: flat shading? */
46#define SPAN_XY         0x10  /**< array.x[], y[] valid? */
47#define SPAN_MASK       0x20  /**< was array.mask[] filled in by caller? */
48#define SPAN_LAMBDA     0x40  /**< array.lambda[] valid? */
49#define SPAN_COVERAGE   0x80  /**< array.coverage[] valid? */
50/*@}*/
51
52
53/**
54 * \sw_span_arrays
55 * \brief Arrays of fragment values.
56 *
57 * These will either be computed from the span x/xStep values or
58 * filled in by glDraw/CopyPixels, etc.
59 * These arrays are separated out of sw_span to conserve memory.
60 */
61typedef struct sw_span_arrays
62{
63   /** Per-fragment attributes (indexed by FRAG_ATTRIB_* tokens) */
64   /* XXX someday look at transposing first two indexes for better memory
65    * access pattern.
66    */
67   GLfloat attribs[FRAG_ATTRIB_MAX][MAX_WIDTH][4];
68
69   /** This mask indicates which fragments are alive or culled */
70   GLubyte mask[MAX_WIDTH];
71
72   GLenum ChanType; /**< Color channel type, GL_UNSIGNED_BYTE, GL_FLOAT */
73
74   /** Attribute arrays that don't fit into attribs[] array above */
75   /*@{*/
76   GLubyte rgba8[MAX_WIDTH][4];
77   GLushort rgba16[MAX_WIDTH][4];
78   GLchan (*rgba)[4];  /** either == rgba8 or rgba16 */
79   GLint   x[MAX_WIDTH];  /**< fragment X coords */
80   GLint   y[MAX_WIDTH];  /**< fragment Y coords */
81   GLuint  z[MAX_WIDTH];  /**< fragment Z coords */
82   GLuint  index[MAX_WIDTH];  /**< Color indexes */
83   GLfloat lambda[MAX_TEXTURE_COORD_UNITS][MAX_WIDTH]; /**< Texture LOD */
84   GLfloat coverage[MAX_WIDTH];  /**< Fragment coverage for AA/smoothing */
85   /*@}*/
86} SWspanarrays;
87
88
89/**
90 * The SWspan structure describes the colors, Z, fogcoord, texcoords,
91 * etc for either a horizontal run or an array of independent pixels.
92 * We can either specify a base/step to indicate interpolated values, or
93 * fill in explicit arrays of values.  The interpMask and arrayMask bitfields
94 * indicate which attributes are active interpolants or arrays, respectively.
95 *
96 * It would be interesting to experiment with multiprocessor rasterization
97 * with this structure.  The triangle rasterizer could simply emit a
98 * stream of these structures which would be consumed by one or more
99 * span-processing threads which could run in parallel.
100 */
101typedef struct sw_span
102{
103   /** Coord of first fragment in horizontal span/run */
104   GLint x, y;
105
106   /** Number of fragments in the span */
107   GLuint end;
108
109   /** This flag indicates that mask[] array is effectively filled with ones */
110   GLboolean writeAll;
111
112   /** either GL_POLYGON, GL_LINE, GL_POLYGON, GL_BITMAP */
113   GLenum primitive;
114
115   /** 0 = front-facing span, 1 = back-facing span (for two-sided stencil) */
116   GLuint facing;
117
118   /**
119    * This bitmask (of  \link SpanFlags SPAN_* flags\endlink) indicates
120    * which of the attrStart/StepX/StepY variables are relevant.
121    */
122   GLbitfield interpMask;
123
124   /** Fragment attribute interpolants */
125   GLfloat attrStart[FRAG_ATTRIB_MAX][4];   /**< initial value */
126   GLfloat attrStepX[FRAG_ATTRIB_MAX][4];   /**< dvalue/dx */
127   GLfloat attrStepY[FRAG_ATTRIB_MAX][4];   /**< dvalue/dy */
128
129   /* XXX the rest of these will go away eventually... */
130
131   /* For horizontal spans, step is the partial derivative wrt X.
132    * For lines, step is the delta from one fragment to the next.
133    */
134   GLfixed red, redStep;
135   GLfixed green, greenStep;
136   GLfixed blue, blueStep;
137   GLfixed alpha, alphaStep;
138   GLfixed index, indexStep;
139   GLfixed z, zStep;    /**< XXX z should probably be GLuint */
140   GLfixed intTex[2], intTexStep[2];  /**< (s,t) for unit[0] only */
141
142   /**
143    * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates
144    * which of the fragment arrays in the span_arrays struct are relevant.
145    */
146   GLbitfield arrayMask;
147
148   GLbitfield arrayAttribs;
149
150   /**
151    * We store the arrays of fragment values in a separate struct so
152    * that we can allocate sw_span structs on the stack without using
153    * a lot of memory.  The span_arrays struct is about 1.4MB while the
154    * sw_span struct is only about 512 bytes.
155    */
156   SWspanarrays *array;
157} SWspan;
158
159
160
161#define INIT_SPAN(S, PRIMITIVE)			\
162do {						\
163   (S).primitive = (PRIMITIVE);			\
164   (S).interpMask = 0x0;			\
165   (S).arrayMask = 0x0;				\
166   (S).arrayAttribs = 0x0;			\
167   (S).end = 0;					\
168   (S).facing = 0;				\
169   (S).array = SWRAST_CONTEXT(ctx)->SpanArrays;	\
170} while (0)
171
172
173
174extern void
175_swrast_span_default_attribs(GLcontext *ctx, SWspan *span);
176
177extern void
178_swrast_span_interpolate_z( const GLcontext *ctx, SWspan *span );
179
180extern GLfloat
181_swrast_compute_lambda(GLfloat dsdx, GLfloat dsdy, GLfloat dtdx, GLfloat dtdy,
182                       GLfloat dqdx, GLfloat dqdy, GLfloat texW, GLfloat texH,
183                       GLfloat s, GLfloat t, GLfloat q, GLfloat invQ);
184
185extern void
186_swrast_write_index_span( GLcontext *ctx, SWspan *span);
187
188
189extern void
190_swrast_write_rgba_span( GLcontext *ctx, SWspan *span);
191
192
193extern void
194_swrast_read_rgba_span(GLcontext *ctx, struct gl_renderbuffer *rb,
195                       GLuint n, GLint x, GLint y, GLenum type, GLvoid *rgba);
196
197extern void
198_swrast_read_index_span( GLcontext *ctx, struct gl_renderbuffer *rb,
199                         GLuint n, GLint x, GLint y, GLuint indx[] );
200
201extern void
202_swrast_get_values(GLcontext *ctx, struct gl_renderbuffer *rb,
203                   GLuint count, const GLint x[], const GLint y[],
204                   void *values, GLuint valueSize);
205
206extern void
207_swrast_put_row(GLcontext *ctx, struct gl_renderbuffer *rb,
208                GLuint count, GLint x, GLint y,
209                const GLvoid *values, GLuint valueSize);
210
211extern void
212_swrast_get_row(GLcontext *ctx, struct gl_renderbuffer *rb,
213                GLuint count, GLint x, GLint y,
214                GLvoid *values, GLuint valueSize);
215
216
217extern void *
218_swrast_get_dest_rgba(GLcontext *ctx, struct gl_renderbuffer *rb,
219                      SWspan *span);
220
221#endif
222