2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
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"
39 struct gl_renderbuffer
;
44 * Special bitflags to describe span data.
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.
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? */
63 * \brief Arrays of fragment values.
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.
69 typedef struct sw_span_arrays
71 /** Per-fragment attributes (indexed by VARYING_SLOT_* tokens) */
72 /* XXX someday look at transposing first two indexes for better memory
75 GLfloat attribs
[VARYING_SLOT_MAX
][SWRAST_MAX_WIDTH
][4];
77 /** This mask indicates which fragments are alive or culled */
78 GLubyte mask
[SWRAST_MAX_WIDTH
];
80 GLenum ChanType
; /**< Color channel type, GL_UNSIGNED_BYTE, GL_FLOAT */
82 /** Attribute arrays that don't fit into attribs[] array above */
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 */
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.
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.
109 typedef struct sw_span
111 /** Coord of first fragment in horizontal span/run */
114 /** Number of fragments in the span */
117 /** for clipping left edge of spans */
120 /** This flag indicates that mask[] array is effectively filled with ones */
123 /** either GL_POLYGON, GL_LINE, GL_POLYGON, GL_BITMAP */
126 /** 0 = front-facing span, 1 = back-facing span (for two-sided stencil) */
130 * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates
131 * which of the attrStart/StepX/StepY variables are relevant.
133 GLbitfield interpMask
;
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 */
140 /* XXX the rest of these will go away eventually... */
142 /* For horizontal spans, step is the partial derivative wrt X.
143 * For lines, step is the delta from one fragment to the next.
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 */
154 * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates
155 * which of the fragment arrays in the span_arrays struct are relevant.
157 GLbitfield arrayMask
;
159 /** Mask of VARYING_BIT_x bits */
160 GLbitfield64 arrayAttribs
;
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.
173 #define INIT_SPAN(S, PRIMITIVE) \
175 (S).primitive = (PRIMITIVE); \
176 (S).interpMask = 0x0; \
177 (S).arrayMask = 0x0; \
178 (S).arrayAttribs = 0x0; \
182 (S).array = SWRAST_CONTEXT(ctx)->SpanArrays; \
188 _swrast_span_default_attribs(struct gl_context
*ctx
, SWspan
*span
);
191 _swrast_span_interpolate_z( const struct gl_context
*ctx
, SWspan
*span
);
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
);
200 _swrast_write_rgba_span( struct gl_context
*ctx
, SWspan
*span
);
204 _swrast_read_rgba_span(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
205 GLuint n
, GLint x
, GLint y
, GLvoid
*rgba
);
208 _swrast_put_row(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
210 GLuint count
, GLint x
, GLint y
,
211 const void *values
, const GLubyte
*mask
);
214 _swrast_get_dest_rgba(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,