Merge SWvertex texcoord and varying fields into attrib[] array field.
[mesa.git] / src / mesa / swrast / s_context.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.2
4 *
5 * Copyright (C) 1999-2006 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 /**
27 * \file swrast/s_context.h
28 * \brief Software rasterization context and private types.
29 * \author Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32 /**
33 * \mainpage swrast module
34 *
35 * This module, software rasterization, contains the software fallback
36 * routines for drawing points, lines, triangles, bitmaps and images.
37 * All rendering boils down to writing spans (arrays) of pixels with
38 * particular colors. The span-writing routines must be implemented
39 * by the device driver.
40 */
41
42
43 #ifndef S_CONTEXT_H
44 #define S_CONTEXT_H
45
46 #include "mtypes.h"
47 #include "swrast.h"
48 #include "s_span.h"
49
50
51 typedef void (*texture_sample_func)(GLcontext *ctx,
52 const struct gl_texture_object *tObj,
53 GLuint n, const GLfloat texcoords[][4],
54 const GLfloat lambda[], GLchan rgba[][4]);
55
56 typedef void (_ASMAPIP blend_func)( GLcontext *ctx, GLuint n,
57 const GLubyte mask[],
58 GLvoid *src, const GLvoid *dst,
59 GLenum chanType);
60
61 typedef void (*swrast_point_func)( GLcontext *ctx, const SWvertex *);
62
63 typedef void (*swrast_line_func)( GLcontext *ctx,
64 const SWvertex *, const SWvertex *);
65
66 typedef void (*swrast_tri_func)( GLcontext *ctx, const SWvertex *,
67 const SWvertex *, const SWvertex *);
68
69
70 typedef void (*validate_texture_image_func)(GLcontext *ctx,
71 struct gl_texture_object *texObj,
72 GLuint face, GLuint level);
73
74
75 /**
76 * \defgroup Bitmasks
77 * Bitmasks to indicate which rasterization options are enabled
78 * (RasterMask)
79 */
80 /*@{*/
81 #define ALPHATEST_BIT 0x001 /**< Alpha-test pixels */
82 #define BLEND_BIT 0x002 /**< Blend pixels */
83 #define DEPTH_BIT 0x004 /**< Depth-test pixels */
84 #define FOG_BIT 0x008 /**< Fog pixels */
85 #define LOGIC_OP_BIT 0x010 /**< Apply logic op in software */
86 #define CLIP_BIT 0x020 /**< Scissor or window clip pixels */
87 #define STENCIL_BIT 0x040 /**< Stencil pixels */
88 #define MASKING_BIT 0x080 /**< Do glColorMask or glIndexMask */
89 #define MULTI_DRAW_BIT 0x400 /**< Write to more than one color- */
90 /**< buffer or no buffers. */
91 #define OCCLUSION_BIT 0x800 /**< GL_HP_occlusion_test enabled */
92 #define TEXTURE_BIT 0x1000 /**< Texturing really enabled */
93 #define FRAGPROG_BIT 0x2000 /**< Fragment program enabled */
94 #define ATIFRAGSHADER_BIT 0x4000 /**< ATI Fragment shader enabled */
95 #define CLAMPING_BIT 0x8000 /**< Clamp colors to [0,1] */
96 /*@}*/
97
98 #define _SWRAST_NEW_RASTERMASK (_NEW_BUFFERS| \
99 _NEW_SCISSOR| \
100 _NEW_COLOR| \
101 _NEW_DEPTH| \
102 _NEW_FOG| \
103 _NEW_PROGRAM| \
104 _NEW_STENCIL| \
105 _NEW_TEXTURE| \
106 _NEW_VIEWPORT| \
107 _NEW_DEPTH)
108
109
110 /**
111 * \struct SWcontext
112 * \brief Per-context state that's private to the software rasterizer module.
113 */
114 typedef struct
115 {
116 /** Driver interface:
117 */
118 struct swrast_device_driver Driver;
119
120 /** Configuration mechanisms to make software rasterizer match
121 * characteristics of the hardware rasterizer (if present):
122 */
123 GLboolean AllowVertexFog;
124 GLboolean AllowPixelFog;
125
126 /** Derived values, invalidated on statechanges, updated from
127 * _swrast_validate_derived():
128 */
129 GLbitfield _RasterMask;
130 GLfloat _BackfaceSign;
131 GLboolean _PreferPixelFog; /* Compute fog blend factor per fragment? */
132 GLboolean _AnyTextureCombine;
133 GLboolean _FogEnabled;
134 GLenum _FogMode; /* either GL_FOG_MODE or fragment program's fog mode */
135
136 /** Fragment attributes to compute during rasterization.
137 * Mask of FRAG_BIT_* flags.
138 */
139 GLbitfield _FragmentAttribs;
140 GLuint _MinFragmentAttrib; /**< Lowest bit set in _FragmentAttribs */
141 GLuint _MaxFragmentAttrib; /**< Highest bit set in _FragmentAttribs + 1 */
142
143 /* Accum buffer temporaries.
144 */
145 GLboolean _IntegerAccumMode; /**< Storing unscaled integers? */
146 GLfloat _IntegerAccumScaler; /**< Implicit scale factor */
147
148 /* Working values:
149 */
150 GLuint StippleCounter; /**< Line stipple counter */
151 GLbitfield NewState;
152 GLuint StateChanges;
153 GLenum Primitive; /* current primitive being drawn (ala glBegin) */
154
155 void (*InvalidateState)( GLcontext *ctx, GLbitfield new_state );
156
157 /**
158 * When the NewState mask intersects these masks, we invalidate the
159 * Point/Line/Triangle function pointers below.
160 */
161 /*@{*/
162 GLbitfield InvalidatePointMask;
163 GLbitfield InvalidateLineMask;
164 GLbitfield InvalidateTriangleMask;
165 /*@}*/
166
167 /**
168 * Device drivers plug in functions for these callbacks.
169 * Will be called when the GL state change mask intersects the above masks.
170 */
171 /*@{*/
172 void (*choose_point)( GLcontext * );
173 void (*choose_line)( GLcontext * );
174 void (*choose_triangle)( GLcontext * );
175 /*@}*/
176
177 /**
178 * Current point, line and triangle drawing functions.
179 */
180 /*@{*/
181 swrast_point_func Point;
182 swrast_line_func Line;
183 swrast_tri_func Triangle;
184 /*@}*/
185
186 /**
187 * Placeholders for when separate specular (or secondary color) is
188 * enabled but texturing is not.
189 */
190 /*@{*/
191 swrast_point_func SpecPoint;
192 swrast_line_func SpecLine;
193 swrast_tri_func SpecTriangle;
194 /*@}*/
195
196 /**
197 * Typically, we'll allocate a sw_span structure as a local variable
198 * and set its 'array' pointer to point to this object. The reason is
199 * this object is big and causes problems when allocated on the stack
200 * on some systems.
201 */
202 SWspanarrays *SpanArrays;
203
204 /**
205 * Used to buffer N GL_POINTS, instead of rendering one by one.
206 */
207 SWspan PointSpan;
208
209 /** Internal hooks, kept up to date by the same mechanism as above.
210 */
211 blend_func BlendFunc;
212 texture_sample_func TextureSample[MAX_TEXTURE_IMAGE_UNITS];
213
214 /** Buffer for saving the sampled texture colors.
215 * Needed for GL_ARB_texture_env_crossbar implementation.
216 */
217 GLchan *TexelBuffer;
218
219 validate_texture_image_func ValidateTextureImage;
220
221 } SWcontext;
222
223
224 extern void
225 _swrast_validate_derived( GLcontext *ctx );
226
227
228 #define SWRAST_CONTEXT(ctx) ((SWcontext *)ctx->swrast_context)
229
230 #define RENDER_START(SWctx, GLctx) \
231 do { \
232 if ((SWctx)->Driver.SpanRenderStart) { \
233 (*(SWctx)->Driver.SpanRenderStart)(GLctx); \
234 } \
235 } while (0)
236
237 #define RENDER_FINISH(SWctx, GLctx) \
238 do { \
239 if ((SWctx)->Driver.SpanRenderFinish) { \
240 (*(SWctx)->Driver.SpanRenderFinish)(GLctx); \
241 } \
242 } while (0)
243
244
245
246 /**
247 * Size of an RGBA pixel, in bytes, for given datatype.
248 */
249 #define RGBA_PIXEL_SIZE(TYPE) \
250 ((TYPE == GL_UNSIGNED_BYTE) ? 4 * sizeof(GLubyte) : \
251 ((TYPE == GL_UNSIGNED_SHORT) ? 4 * sizeof(GLushort) \
252 : 4 * sizeof(GLfloat)))
253
254
255
256 /*
257 * XXX these macros are just bandages for now in order to make
258 * CHAN_BITS==32 compile cleanly.
259 * These should probably go elsewhere at some point.
260 */
261 #if CHAN_TYPE == GL_FLOAT
262 #define ChanToFixed(X) (X)
263 #define FixedToChan(X) (X)
264 #else
265 #define ChanToFixed(X) IntToFixed(X)
266 #define FixedToChan(X) FixedToInt(X)
267 #endif
268
269 #endif