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