Merge branch 'origin' into glsl-compiler-1
[mesa.git] / src / mesa / swrast / swrast.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
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/swrast.h
28 * \brief Public interface to the software rasterization functions.
29 * \author Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32 #ifndef SWRAST_H
33 #define SWRAST_H
34
35 #include "mtypes.h"
36
37 /**
38 * \struct SWvertex
39 * \brief Data-structure to handle vertices in the software rasterizer.
40 *
41 * The software rasterizer now uses this format for vertices. Thus a
42 * 'RasterSetup' stage or other translation is required between the
43 * tnl module and the swrast rasterization functions. This serves to
44 * isolate the swrast module from the internals of the tnl module, and
45 * improve its usefulness as a fallback mechanism for hardware
46 * drivers.
47 *
48 * Full software drivers:
49 * - Register the rastersetup and triangle functions from
50 * utils/software_helper.
51 * - On statechange, update the rasterization pointers in that module.
52 *
53 * Rasterization hardware drivers:
54 * - Keep native rastersetup.
55 * - Implement native twoside,offset and unfilled triangle setup.
56 * - Implement a translator from native vertices to swrast vertices.
57 * - On partial fallback (mix of accelerated and unaccelerated
58 * prims), call a pass-through function which translates native
59 * vertices to SWvertices and calls the appropriate swrast function.
60 * - On total fallback (vertex format insufficient for state or all
61 * primitives unaccelerated), hook in swrast_setup instead.
62 */
63 typedef struct {
64 /** win[0], win[1] are the screen-coords of SWvertex.
65 * win[2] is the z-buffer coord (if 16-bit Z buffer, in range [0,65535]).
66 * win[3] is 1/w where w is the clip-space W coord. This is the value
67 * that clip{XYZ} were multiplied by to get ndc{XYZ}.
68 */
69 GLfloat win[4];
70 GLchan color[4];
71 GLchan specular[4];
72 GLfloat fog;
73 GLfloat index;
74 GLfloat pointSize;
75 GLfloat attrib[FRAG_ATTRIB_MAX][4]; /**< texcoords & varying, more to come */
76 } SWvertex;
77
78
79 struct swrast_device_driver;
80
81
82 /* These are the public-access functions exported from swrast.
83 */
84
85 extern GLboolean
86 _swrast_CreateContext( GLcontext *ctx );
87
88 extern void
89 _swrast_DestroyContext( GLcontext *ctx );
90
91 /* Get a (non-const) reference to the device driver struct for swrast.
92 */
93 extern struct swrast_device_driver *
94 _swrast_GetDeviceDriverReference( GLcontext *ctx );
95
96 extern void
97 _swrast_Bitmap( GLcontext *ctx,
98 GLint px, GLint py,
99 GLsizei width, GLsizei height,
100 const struct gl_pixelstore_attrib *unpack,
101 const GLubyte *bitmap );
102
103 extern void
104 _swrast_CopyPixels( GLcontext *ctx,
105 GLint srcx, GLint srcy,
106 GLint destx, GLint desty,
107 GLsizei width, GLsizei height,
108 GLenum type );
109
110 extern void
111 _swrast_DrawPixels( GLcontext *ctx,
112 GLint x, GLint y,
113 GLsizei width, GLsizei height,
114 GLenum format, GLenum type,
115 const struct gl_pixelstore_attrib *unpack,
116 const GLvoid *pixels );
117
118 extern void
119 _swrast_ReadPixels( GLcontext *ctx,
120 GLint x, GLint y, GLsizei width, GLsizei height,
121 GLenum format, GLenum type,
122 const struct gl_pixelstore_attrib *unpack,
123 GLvoid *pixels );
124
125 extern void
126 _swrast_BlitFramebuffer(GLcontext *ctx,
127 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
128 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
129 GLbitfield mask, GLenum filter);
130
131 extern void
132 _swrast_Clear(GLcontext *ctx, GLbitfield buffers);
133
134 extern void
135 _swrast_Accum(GLcontext *ctx, GLenum op, GLfloat value);
136
137
138
139 /* Reset the stipple counter
140 */
141 extern void
142 _swrast_ResetLineStipple( GLcontext *ctx );
143
144 /* These will always render the correct point/line/triangle for the
145 * current state.
146 *
147 * For flatshaded primitives, the provoking vertex is the final one.
148 */
149 extern void
150 _swrast_Point( GLcontext *ctx, const SWvertex *v );
151
152 extern void
153 _swrast_Line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 );
154
155 extern void
156 _swrast_Triangle( GLcontext *ctx, const SWvertex *v0,
157 const SWvertex *v1, const SWvertex *v2 );
158
159 extern void
160 _swrast_Quad( GLcontext *ctx,
161 const SWvertex *v0, const SWvertex *v1,
162 const SWvertex *v2, const SWvertex *v3);
163
164 extern void
165 _swrast_flush( GLcontext *ctx );
166
167 extern void
168 _swrast_render_primitive( GLcontext *ctx, GLenum mode );
169
170 extern void
171 _swrast_render_start( GLcontext *ctx );
172
173 extern void
174 _swrast_render_finish( GLcontext *ctx );
175
176 /* Tell the software rasterizer about core state changes.
177 */
178 extern void
179 _swrast_InvalidateState( GLcontext *ctx, GLbitfield new_state );
180
181 /* Configure software rasterizer to match hardware rasterizer characteristics:
182 */
183 extern void
184 _swrast_allow_vertex_fog( GLcontext *ctx, GLboolean value );
185
186 extern void
187 _swrast_allow_pixel_fog( GLcontext *ctx, GLboolean value );
188
189 /* Debug:
190 */
191 extern void
192 _swrast_print_vertex( GLcontext *ctx, const SWvertex *v );
193
194
195 /*
196 * Imaging fallbacks (a better solution should be found, perhaps
197 * moving all the imaging fallback code to a new module)
198 */
199 extern void
200 _swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target,
201 GLenum internalFormat,
202 GLint x, GLint y, GLsizei width,
203 GLsizei height);
204 extern void
205 _swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target,
206 GLenum internalFormat,
207 GLint x, GLint y, GLsizei width);
208 extern void
209 _swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start,
210 GLint x, GLint y, GLsizei width);
211 extern void
212 _swrast_CopyColorTable( GLcontext *ctx,
213 GLenum target, GLenum internalformat,
214 GLint x, GLint y, GLsizei width);
215
216
217 /*
218 * Texture fallbacks. Could also live in a new module
219 * with the rest of the texture store fallbacks?
220 */
221 extern void
222 _swrast_copy_teximage1d(GLcontext *ctx, GLenum target, GLint level,
223 GLenum internalFormat,
224 GLint x, GLint y, GLsizei width, GLint border);
225
226 extern void
227 _swrast_copy_teximage2d(GLcontext *ctx, GLenum target, GLint level,
228 GLenum internalFormat,
229 GLint x, GLint y, GLsizei width, GLsizei height,
230 GLint border);
231
232
233 extern void
234 _swrast_copy_texsubimage1d(GLcontext *ctx, GLenum target, GLint level,
235 GLint xoffset, GLint x, GLint y, GLsizei width);
236
237 extern void
238 _swrast_copy_texsubimage2d(GLcontext *ctx,
239 GLenum target, GLint level,
240 GLint xoffset, GLint yoffset,
241 GLint x, GLint y, GLsizei width, GLsizei height);
242
243 extern void
244 _swrast_copy_texsubimage3d(GLcontext *ctx,
245 GLenum target, GLint level,
246 GLint xoffset, GLint yoffset, GLint zoffset,
247 GLint x, GLint y, GLsizei width, GLsizei height);
248
249
250 extern void
251 _swrast_eject_texture_images(GLcontext *ctx);
252
253
254 #if FEATURE_MESA_program_debug
255 extern void
256 _swrast_get_program_register(GLcontext *, enum register_file file,
257 GLuint index, GLfloat val[4]);
258 #endif /* FEATURE_MESA_program_debug */
259
260
261 /**
262 * The driver interface for the software rasterizer.
263 * XXX this may go away.
264 * We may move these functions to ctx->Driver.RenderStart, RenderEnd.
265 */
266 struct swrast_device_driver {
267 /*
268 * These are called before and after accessing renderbuffers during
269 * software rasterization.
270 *
271 * These are a suitable place for grabbing/releasing hardware locks.
272 *
273 * NOTE: The swrast triangle/line/point routines *DO NOT* call
274 * these functions. Locking in that case must be organized by the
275 * driver by other mechanisms.
276 */
277 void (*SpanRenderStart)(GLcontext *ctx);
278 void (*SpanRenderFinish)(GLcontext *ctx);
279 };
280
281
282
283 #endif