1 /* $Id: s_context.h,v 1.24 2003/02/23 04:10:54 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * \file swrast/s_context.h
30 * \brief Software rasterization context and private types.
31 * \author Keith Whitwell <keith@tungstengraphics.com>
43 * \brief Contains data for either a horizontal line or a set of
44 * pixels that are passed through a pipeline of functions before being
47 * The sw_span structure describes the colors, Z, fogcoord, texcoords,
48 * etc for either a horizontal run or a set of independent pixels. We
49 * can either specify a base/step to indicate interpolated values, or
50 * fill in arrays of values. The interpMask and arrayMask bitfields
51 * indicate which are active.
53 * With this structure it's easy to hand-off span rasterization to
54 * subroutines instead of doing it all inline in the triangle functions
56 * It also cleans up the local variable namespace a great deal.
58 * It would be interesting to experiment with multiprocessor rasterization
59 * with this structure. The triangle rasterizer could simply emit a
60 * stream of these structures which would be consumed by one or more
61 * span-processing threads which could run in parallel.
66 * \defgroup SpanFlags SPAN_XXX-flags
67 * Bitmasks to indicate which span_arrays need to be computed
68 * (sw_span::interpMask) or have already been filled
69 * (sw_span::arrayMask)
72 #define SPAN_RGBA 0x001
73 #define SPAN_SPEC 0x002
74 #define SPAN_INDEX 0x004
76 #define SPAN_FOG 0x010
77 #define SPAN_TEXTURE 0x020
78 #define SPAN_INT_TEXTURE 0x040
79 #define SPAN_LAMBDA 0x080
80 #define SPAN_COVERAGE 0x100
81 #define SPAN_FLAT 0x200 /**< flat shading? */
82 /** sw_span::arrayMask only - for span_arrays::x, span_arrays::y */
84 #define SPAN_MASK 0x800 /**< sw_span::arrayMask only */
90 * \brief Arrays of fragment values.
92 * These will either be computed from the x/xStep values above or
93 * filled in by glDraw/CopyPixels, etc.
94 * These arrays are separated out of sw_span to conserve memory.
97 GLchan rgb
[MAX_WIDTH
][3];
98 GLchan rgba
[MAX_WIDTH
][4];
99 GLuint index
[MAX_WIDTH
];
100 GLchan spec
[MAX_WIDTH
][4]; /* specular color */
101 GLint x
[MAX_WIDTH
]; /**< X/Y used for point/line rendering only */
102 GLint y
[MAX_WIDTH
]; /**< X/Y used for point/line rendering only */
103 GLdepth z
[MAX_WIDTH
];
104 GLfloat fog
[MAX_WIDTH
];
105 GLfloat texcoords
[MAX_TEXTURE_COORD_UNITS
][MAX_WIDTH
][4];
106 GLfloat lambda
[MAX_TEXTURE_COORD_UNITS
][MAX_WIDTH
];
107 GLfloat coverage
[MAX_WIDTH
];
109 /** This mask indicates if fragment is alive or culled */
110 GLubyte mask
[MAX_WIDTH
];
117 /** Only need to process pixels between start <= i < end */
118 /** At this time, start is always zero. */
121 /** This flag indicates that mask[] array is effectively filled with ones */
124 /** either GL_POLYGON, GL_LINE, GL_POLYGON, GL_BITMAP */
127 /** 0 = front-facing span, 1 = back-facing span (for two-sided stencil) */
131 * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates
132 * which of the x/xStep variables are relevant.
136 #if CHAN_TYPE == GL_FLOAT
137 GLfloat red
, redStep
;
138 GLfloat green
, greenStep
;
139 GLfloat blue
, blueStep
;
140 GLfloat alpha
, alphaStep
;
141 GLfloat specRed
, specRedStep
;
142 GLfloat specGreen
, specGreenStep
;
143 GLfloat specBlue
, specBlueStep
;
144 #else /* CHAN_TYPE == GL_UNSIGNED_BYTE or GL_UNSIGNED SHORT */
145 GLfixed red
, redStep
;
146 GLfixed green
, greenStep
;
147 GLfixed blue
, blueStep
;
148 GLfixed alpha
, alphaStep
;
149 GLfixed specRed
, specRedStep
;
150 GLfixed specGreen
, specGreenStep
;
151 GLfixed specBlue
, specBlueStep
;
153 GLfixed index
, indexStep
;
155 GLfloat fog
, fogStep
;
156 GLfloat tex
[MAX_TEXTURE_COORD_UNITS
][4]; /* s, t, r, q */
157 GLfloat texStepX
[MAX_TEXTURE_COORD_UNITS
][4];
158 GLfloat texStepY
[MAX_TEXTURE_COORD_UNITS
][4];
159 GLfixed intTex
[2], intTexStep
[2]; /* s, t only */
162 * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates
163 * which of the fragment arrays in the span_arrays struct are relevant.
168 * We store the arrays of fragment values in a separate struct so
169 * that we can allocate sw_span structs on the stack without using
170 * a lot of memory. The span_arrays struct is about 400KB while the
171 * sw_span struct is only about 512 bytes.
173 struct span_arrays
*array
;
177 #define INIT_SPAN(S, PRIMITIVE, END, INTERP_MASK, ARRAY_MASK) \
179 (S).primitive = (PRIMITIVE); \
180 (S).interpMask = (INTERP_MASK); \
181 (S).arrayMask = (ARRAY_MASK); \
185 (S).array = SWRAST_CONTEXT(ctx)->SpanArrays; \
189 typedef void (*texture_sample_func
)(GLcontext
*ctx
, GLuint texUnit
,
190 const struct gl_texture_object
*tObj
,
191 GLuint n
, const GLfloat texcoords
[][4],
192 const GLfloat lambda
[], GLchan rgba
[][4]);
195 typedef void (_ASMAPIP blend_func
)( GLcontext
*ctx
, GLuint n
,
196 const GLubyte mask
[],
197 GLchan src
[][4], CONST GLchan dst
[][4] );
199 typedef void (*blend_func
)( GLcontext
*ctx
, GLuint n
, const GLubyte mask
[],
200 GLchan src
[][4], CONST GLchan dst
[][4] );
203 typedef void (*swrast_point_func
)( GLcontext
*ctx
, const SWvertex
*);
205 typedef void (*swrast_line_func
)( GLcontext
*ctx
,
206 const SWvertex
*, const SWvertex
*);
208 typedef void (*swrast_tri_func
)( GLcontext
*ctx
, const SWvertex
*,
209 const SWvertex
*, const SWvertex
*);
212 /** \defgroup Bitmasks
213 * Bitmasks to indicate which rasterization options are enabled
217 #define ALPHATEST_BIT 0x001 /**< Alpha-test pixels */
218 #define BLEND_BIT 0x002 /**< Blend pixels */
219 #define DEPTH_BIT 0x004 /**< Depth-test pixels */
220 #define FOG_BIT 0x008 /**< Fog pixels */
221 #define LOGIC_OP_BIT 0x010 /**< Apply logic op in software */
222 #define CLIP_BIT 0x020 /**< Scissor or window clip pixels */
223 #define STENCIL_BIT 0x040 /**< Stencil pixels */
224 #define MASKING_BIT 0x080 /**< Do glColorMask or glIndexMask */
225 #define ALPHABUF_BIT 0x100 /**< Using software alpha buffer */
226 #define MULTI_DRAW_BIT 0x400 /**< Write to more than one color- */
227 /**< buffer or no buffers. */
228 #define OCCLUSION_BIT 0x800 /**< GL_HP_occlusion_test enabled */
229 #define TEXTURE_BIT 0x1000 /**< Texturing really enabled */
232 #define _SWRAST_NEW_RASTERMASK (_NEW_BUFFERS| \
249 /** Driver interface:
251 struct swrast_device_driver Driver
;
253 /** Configuration mechanisms to make software rasterizer match
254 * characteristics of the hardware rasterizer (if present):
256 GLboolean AllowVertexFog
;
257 GLboolean AllowPixelFog
;
259 /** Derived values, invalidated on statechanges, updated from
260 * _swrast_validate_derived():
263 GLfloat _MinMagThresh
[MAX_TEXTURE_IMAGE_UNITS
];
264 GLfloat _backface_sign
;
265 GLboolean _PreferPixelFog
;
266 GLboolean _AnyTextureCombine
;
268 /* Accum buffer temporaries.
270 GLboolean _IntegerAccumMode
; /**< Storing unscaled integers? */
271 GLfloat _IntegerAccumScaler
; /**< Implicit scale factor */
276 GLuint StippleCounter
; /**< Line stipple counter */
279 GLenum Primitive
; /* current primitive being drawn (ala glBegin) */
280 GLuint CurrentBuffer
; /* exactly one of FRONT_LEFT_BIT, BACK_LEFT_BIT, etc*/
282 /** Mechanism to allow driver (like X11) to register further
283 * software rasterization routines.
286 void (*choose_point
)( GLcontext
* );
287 void (*choose_line
)( GLcontext
* );
288 void (*choose_triangle
)( GLcontext
* );
290 GLuint invalidate_point
;
291 GLuint invalidate_line
;
292 GLuint invalidate_triangle
;
295 /** Function pointers for dispatch behind public entrypoints. */
297 void (*InvalidateState
)( GLcontext
*ctx
, GLuint new_state
);
299 swrast_point_func Point
;
300 swrast_line_func Line
;
301 swrast_tri_func Triangle
;
305 * Placeholders for when separate specular (or secondary color) is
306 * enabled but texturing is not.
309 swrast_point_func SpecPoint
;
310 swrast_line_func SpecLine
;
311 swrast_tri_func SpecTriangle
;
315 * Typically, we'll allocate a sw_span structure as a local variable
316 * and set its 'array' pointer to point to this object. The reason is
317 * this object is big and causes problems when allocated on the stack
320 struct span_arrays
*SpanArrays
;
323 * Used to buffer N GL_POINTS, instead of rendering one by one.
325 struct sw_span PointSpan
;
327 /** Internal hooks, kept uptodate by the same mechanism as above.
329 blend_func BlendFunc
;
330 texture_sample_func TextureSample
[MAX_TEXTURE_IMAGE_UNITS
];
332 /** Buffer for saving the sampled texture colors.
333 * Needed for GL_ARB_texture_env_crossbar implementation.
341 _swrast_validate_derived( GLcontext
*ctx
);
344 #define SWRAST_CONTEXT(ctx) ((SWcontext *)ctx->swrast_context)
346 #define RENDER_START(SWctx, GLctx) \
348 if ((SWctx)->Driver.SpanRenderStart) { \
349 (*(SWctx)->Driver.SpanRenderStart)(GLctx); \
353 #define RENDER_FINISH(SWctx, GLctx) \
355 if ((SWctx)->Driver.SpanRenderFinish) { \
356 (*(SWctx)->Driver.SpanRenderFinish)(GLctx); \
363 * XXX these macros are just bandages for now in order to make
364 * CHAN_BITS==32 compile cleanly.
365 * These should probably go elsewhere at some point.
367 #if CHAN_TYPE == GL_FLOAT
368 #define ChanToFixed(X) (X)
369 #define FixedToChan(X) (X)
371 #define ChanToFixed(X) IntToFixed(X)
372 #define FixedToChan(X) FixedToInt(X)