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