assorted changes for supporting GLfloat color channels (not done)
[mesa.git] / src / mesa / swrast / s_context.h
1 /* $Id: s_context.h,v 1.11 2001/07/13 20:07:37 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 *
26 * Authors:
27 * Keith Whitwell <keithw@valinux.com>
28 */
29
30 #ifndef S_CONTEXT_H
31 #define S_CONTEXT_H
32
33 #include "mtypes.h"
34 #include "swrast.h"
35
36 /*
37 * For texture sampling:
38 */
39 typedef void (*TextureSampleFunc)( GLcontext *ctx, GLuint texUnit,
40 const struct gl_texture_object *tObj,
41 GLuint n,
42 const GLfloat s[], const GLfloat t[],
43 const GLfloat u[], const GLfloat lambda[],
44 GLchan rgba[][4] );
45
46
47
48 /*
49 * Blending function
50 */
51 #ifdef USE_MMX_ASM
52 typedef void (_ASMAPIP blend_func)( GLcontext *ctx, GLuint n,
53 const GLubyte mask[],
54 GLchan src[][4], CONST GLchan dst[][4] );
55 #else
56 typedef void (*blend_func)( GLcontext *ctx, GLuint n, const GLubyte mask[],
57 GLchan src[][4], CONST GLchan dst[][4] );
58 #endif
59
60 typedef void (*swrast_point_func)( GLcontext *ctx, const SWvertex *);
61
62 typedef void (*swrast_line_func)( GLcontext *ctx,
63 const SWvertex *, const SWvertex *);
64
65 typedef void (*swrast_tri_func)( GLcontext *ctx, const SWvertex *,
66 const SWvertex *, const SWvertex *);
67
68
69
70 /*
71 * Bitmasks to indicate which rasterization options are enabled (RasterMask)
72 */
73 #define ALPHATEST_BIT 0x001 /* Alpha-test pixels */
74 #define BLEND_BIT 0x002 /* Blend pixels */
75 #define DEPTH_BIT 0x004 /* Depth-test pixels */
76 #define FOG_BIT 0x008 /* Fog pixels */
77 #define LOGIC_OP_BIT 0x010 /* Apply logic op in software */
78 #define SCISSOR_BIT 0x020 /* Scissor pixels */
79 #define STENCIL_BIT 0x040 /* Stencil pixels */
80 #define MASKING_BIT 0x080 /* Do glColorMask or glIndexMask */
81 #define ALPHABUF_BIT 0x100 /* Using software alpha buffer */
82 #define WINCLIP_BIT 0x200 /* Clip pixels/primitives to window */
83 #define MULTI_DRAW_BIT 0x400 /* Write to more than one color- */
84 /* buffer or no buffers. */
85 #define OCCLUSION_BIT 0x800 /* GL_HP_occlusion_test enabled */
86 #define TEXTURE_BIT 0x1000 /* Texturing really enabled */
87
88
89 #define _SWRAST_NEW_RASTERMASK (_NEW_BUFFERS| \
90 _NEW_SCISSOR| \
91 _NEW_COLOR| \
92 _NEW_DEPTH| \
93 _NEW_FOG| \
94 _NEW_STENCIL| \
95 _NEW_TEXTURE| \
96 _NEW_VIEWPORT| \
97 _NEW_DEPTH)
98
99
100
101 typedef struct
102 {
103 /* Driver interface:
104 */
105 struct swrast_device_driver Driver;
106
107 /* Configuration mechanisms to make software rasterizer match
108 * characteristics of the hardware rasterizer (if present):
109 */
110 GLboolean AllowVertexFog;
111 GLboolean AllowPixelFog;
112
113 /* Derived values, invalidated on statechanges, updated from
114 * _swrast_validate_derived():
115 */
116 GLuint _RasterMask;
117 GLfloat _MinMagThresh[MAX_TEXTURE_UNITS];
118 GLfloat _backface_sign;
119 GLboolean _PreferPixelFog;
120
121 /* Accum buffer temporaries.
122 */
123 GLboolean _IntegerAccumMode; /* Storing unscaled integers? */
124 GLfloat _IntegerAccumScaler; /* Implicit scale factor */
125
126
127 /* Working values:
128 */
129 struct pixel_buffer* PB;
130 GLuint StippleCounter; /* Line stipple counter */
131 GLuint NewState;
132 GLuint StateChanges;
133
134 /* Mechanism to allow driver (like X11) to register further
135 * software rasterization routines.
136 */
137 void (*choose_point)( GLcontext * );
138 void (*choose_line)( GLcontext * );
139 void (*choose_triangle)( GLcontext * );
140
141 GLuint invalidate_point;
142 GLuint invalidate_line;
143 GLuint invalidate_triangle;
144
145
146 /* Function pointers for dispatch behind public entrypoints.
147 */
148 void (*InvalidateState)( GLcontext *ctx, GLuint new_state );
149
150 swrast_point_func Point;
151 swrast_line_func Line;
152 swrast_tri_func Triangle;
153
154 /* Placeholders for when separate specular (or secondary color) is
155 * enabled but texturing is not.
156 */
157 swrast_point_func SpecPoint;
158 swrast_line_func SpecLine;
159 swrast_tri_func SpecTriangle;
160
161
162 /* Internal hooks, kept uptodate by the same mechanism as above.
163 */
164 blend_func BlendFunc;
165 TextureSampleFunc TextureSample[MAX_TEXTURE_UNITS];
166
167 } SWcontext;
168
169
170 extern void
171 _swrast_validate_derived( GLcontext *ctx );
172
173
174 #define SWRAST_CONTEXT(ctx) ((SWcontext *)ctx->swrast_context)
175
176 #define RENDER_START(SWctx, GLctx) \
177 do { \
178 if ((SWctx)->Driver.SpanRenderStart) { \
179 (*(SWctx)->Driver.SpanRenderStart)(GLctx); \
180 } \
181 } while (0)
182
183 #define RENDER_FINISH(SWctx, GLctx) \
184 do { \
185 if ((SWctx)->Driver.SpanRenderFinish) { \
186 (*(SWctx)->Driver.SpanRenderFinish)(GLctx); \
187 } \
188 } while (0)
189
190
191
192 /*
193 * XXX these macros are just bandages for now in order to make
194 * CHAN_BITS==32 compile cleanly.
195 * These should probably go elsewhere at some point.
196 */
197 #if CHAN_TYPE == GL_FLOAT
198 #define ChanToFixed(X) FloatToFixed(X)
199 #define FixedToChan(X) FixedToFloat(X)
200 #else
201 #define ChanToFixed(X) IntToFixed(X)
202 #define FixedToChan(X) FixedToInt(X)
203 #endif
204
205 #endif