mesa: Change "BRIAN PAUL" to "THE AUTHORS" in license text.
[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 * THE AUTHORS 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 "main/mtypes.h"
36 #include "swrast/s_chan.h"
37
38
39 /**
40 * If non-zero use GLdouble for walking triangle edges, for better accuracy.
41 */
42 #define TRIANGLE_WALK_DOUBLE 0
43
44
45 /**
46 * Bits per depth buffer value (max is 32).
47 */
48 #ifndef DEFAULT_SOFTWARE_DEPTH_BITS
49 #define DEFAULT_SOFTWARE_DEPTH_BITS 16
50 #endif
51 /** Depth buffer data type */
52 #if DEFAULT_SOFTWARE_DEPTH_BITS <= 16
53 #define DEFAULT_SOFTWARE_DEPTH_TYPE GLushort
54 #else
55 #define DEFAULT_SOFTWARE_DEPTH_TYPE GLuint
56 #endif
57
58
59 /**
60 * Max image/surface/texture size.
61 */
62 #define SWRAST_MAX_WIDTH 16384
63 #define SWRAST_MAX_HEIGHT 16384
64
65
66 /**
67 * \struct SWvertex
68 * \brief Data-structure to handle vertices in the software rasterizer.
69 *
70 * The software rasterizer now uses this format for vertices. Thus a
71 * 'RasterSetup' stage or other translation is required between the
72 * tnl module and the swrast rasterization functions. This serves to
73 * isolate the swrast module from the internals of the tnl module, and
74 * improve its usefulness as a fallback mechanism for hardware
75 * drivers.
76 *
77 * wpos = attr[VARYING_SLOT_POS] and MUST BE THE FIRST values in the
78 * vertex because of the tnl clipping code.
79
80 * wpos[0] and [1] are the screen-coords of SWvertex.
81 * wpos[2] is the z-buffer coord (if 16-bit Z buffer, in range [0,65535]).
82 * wpos[3] is 1/w where w is the clip-space W coord. This is the value
83 * that clip{XYZ} were multiplied by to get ndc{XYZ}.
84 *
85 * Full software drivers:
86 * - Register the rastersetup and triangle functions from
87 * utils/software_helper.
88 * - On statechange, update the rasterization pointers in that module.
89 *
90 * Rasterization hardware drivers:
91 * - Keep native rastersetup.
92 * - Implement native twoside,offset and unfilled triangle setup.
93 * - Implement a translator from native vertices to swrast vertices.
94 * - On partial fallback (mix of accelerated and unaccelerated
95 * prims), call a pass-through function which translates native
96 * vertices to SWvertices and calls the appropriate swrast function.
97 * - On total fallback (vertex format insufficient for state or all
98 * primitives unaccelerated), hook in swrast_setup instead.
99 */
100 typedef struct {
101 GLfloat attrib[VARYING_SLOT_MAX][4];
102 GLchan color[4]; /** integer color */
103 GLfloat pointSize;
104 } SWvertex;
105
106
107 #define VARYING_SLOT_CI VARYING_SLOT_COL0
108
109
110 struct swrast_device_driver;
111
112
113 /* These are the public-access functions exported from swrast.
114 */
115
116 extern GLboolean
117 _swrast_CreateContext( struct gl_context *ctx );
118
119 extern void
120 _swrast_DestroyContext( struct gl_context *ctx );
121
122 /* Get a (non-const) reference to the device driver struct for swrast.
123 */
124 extern struct swrast_device_driver *
125 _swrast_GetDeviceDriverReference( struct gl_context *ctx );
126
127 extern void
128 _swrast_Bitmap( struct gl_context *ctx,
129 GLint px, GLint py,
130 GLsizei width, GLsizei height,
131 const struct gl_pixelstore_attrib *unpack,
132 const GLubyte *bitmap );
133
134 extern void
135 _swrast_CopyPixels( struct gl_context *ctx,
136 GLint srcx, GLint srcy,
137 GLint destx, GLint desty,
138 GLsizei width, GLsizei height,
139 GLenum type );
140
141 extern GLboolean
142 swrast_fast_copy_pixels(struct gl_context *ctx,
143 GLint srcX, GLint srcY, GLsizei width, GLsizei height,
144 GLint dstX, GLint dstY, GLenum type);
145
146 extern void
147 _swrast_DrawPixels( struct gl_context *ctx,
148 GLint x, GLint y,
149 GLsizei width, GLsizei height,
150 GLenum format, GLenum type,
151 const struct gl_pixelstore_attrib *unpack,
152 const GLvoid *pixels );
153
154 extern void
155 _swrast_BlitFramebuffer(struct gl_context *ctx,
156 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
157 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
158 GLbitfield mask, GLenum filter);
159
160 extern void
161 _swrast_Clear(struct gl_context *ctx, GLbitfield buffers);
162
163
164
165 /* Reset the stipple counter
166 */
167 extern void
168 _swrast_ResetLineStipple( struct gl_context *ctx );
169
170 /**
171 * Indicates front/back facing for subsequent points/lines when drawing
172 * unfilled polygons. Needed for two-side stencil.
173 */
174 extern void
175 _swrast_SetFacing(struct gl_context *ctx, GLuint facing);
176
177 /* These will always render the correct point/line/triangle for the
178 * current state.
179 *
180 * For flatshaded primitives, the provoking vertex is the final one.
181 */
182 extern void
183 _swrast_Point( struct gl_context *ctx, const SWvertex *v );
184
185 extern void
186 _swrast_Line( struct gl_context *ctx, const SWvertex *v0, const SWvertex *v1 );
187
188 extern void
189 _swrast_Triangle( struct gl_context *ctx, const SWvertex *v0,
190 const SWvertex *v1, const SWvertex *v2 );
191
192 extern void
193 _swrast_Quad( struct gl_context *ctx,
194 const SWvertex *v0, const SWvertex *v1,
195 const SWvertex *v2, const SWvertex *v3);
196
197 extern void
198 _swrast_flush( struct gl_context *ctx );
199
200 extern void
201 _swrast_render_primitive( struct gl_context *ctx, GLenum mode );
202
203 extern void
204 _swrast_render_start( struct gl_context *ctx );
205
206 extern void
207 _swrast_render_finish( struct gl_context *ctx );
208
209 extern struct gl_texture_image *
210 _swrast_new_texture_image( struct gl_context *ctx );
211
212 extern void
213 _swrast_delete_texture_image(struct gl_context *ctx,
214 struct gl_texture_image *texImage);
215
216 extern GLboolean
217 _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
218 struct gl_texture_image *texImage);
219
220 extern void
221 _swrast_init_texture_image(struct gl_texture_image *texImage);
222
223 extern void
224 _swrast_free_texture_image_buffer(struct gl_context *ctx,
225 struct gl_texture_image *texImage);
226
227 extern void
228 _swrast_map_teximage(struct gl_context *ctx,
229 struct gl_texture_image *texImage,
230 GLuint slice,
231 GLuint x, GLuint y, GLuint w, GLuint h,
232 GLbitfield mode,
233 GLubyte **mapOut,
234 GLint *rowStrideOut);
235
236 extern void
237 _swrast_unmap_teximage(struct gl_context *ctx,
238 struct gl_texture_image *texImage,
239 GLuint slice);
240
241 /* Tell the software rasterizer about core state changes.
242 */
243 extern void
244 _swrast_InvalidateState( struct gl_context *ctx, GLbitfield new_state );
245
246 /* Configure software rasterizer to match hardware rasterizer characteristics:
247 */
248 extern void
249 _swrast_allow_vertex_fog( struct gl_context *ctx, GLboolean value );
250
251 extern void
252 _swrast_allow_pixel_fog( struct gl_context *ctx, GLboolean value );
253
254 /* Debug:
255 */
256 extern void
257 _swrast_print_vertex( struct gl_context *ctx, const SWvertex *v );
258
259
260
261 extern void
262 _swrast_eject_texture_images(struct gl_context *ctx);
263
264
265 extern void
266 _swrast_render_texture(struct gl_context *ctx,
267 struct gl_framebuffer *fb,
268 struct gl_renderbuffer_attachment *att);
269
270 extern void
271 _swrast_finish_render_texture(struct gl_context *ctx,
272 struct gl_renderbuffer_attachment *att);
273
274
275 /**
276 * The driver interface for the software rasterizer.
277 * XXX this may go away.
278 * We may move these functions to ctx->Driver.RenderStart, RenderEnd.
279 */
280 struct swrast_device_driver {
281 /*
282 * These are called before and after accessing renderbuffers during
283 * software rasterization.
284 *
285 * These are a suitable place for grabbing/releasing hardware locks.
286 *
287 * NOTE: The swrast triangle/line/point routines *DO NOT* call
288 * these functions. Locking in that case must be organized by the
289 * driver by other mechanisms.
290 */
291 void (*SpanRenderStart)(struct gl_context *ctx);
292 void (*SpanRenderFinish)(struct gl_context *ctx);
293 };
294
295
296
297 #endif