2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
27 * \file swrast/swrast.h
28 * \brief Public interface to the software rasterization functions.
29 * \author Keith Whitwell <keith@tungstengraphics.com>
35 #include "main/mtypes.h"
36 #include "swrast/s_chan.h"
40 * \brief Data-structure to handle vertices in the software rasterizer.
42 * The software rasterizer now uses this format for vertices. Thus a
43 * 'RasterSetup' stage or other translation is required between the
44 * tnl module and the swrast rasterization functions. This serves to
45 * isolate the swrast module from the internals of the tnl module, and
46 * improve its usefulness as a fallback mechanism for hardware
49 * wpos = attr[FRAG_ATTRIB_WPOS] and MUST BE THE FIRST values in the
50 * vertex because of the tnl clipping code.
52 * wpos[0] and [1] are the screen-coords of SWvertex.
53 * wpos[2] is the z-buffer coord (if 16-bit Z buffer, in range [0,65535]).
54 * wpos[3] is 1/w where w is the clip-space W coord. This is the value
55 * that clip{XYZ} were multiplied by to get ndc{XYZ}.
57 * Full software drivers:
58 * - Register the rastersetup and triangle functions from
59 * utils/software_helper.
60 * - On statechange, update the rasterization pointers in that module.
62 * Rasterization hardware drivers:
63 * - Keep native rastersetup.
64 * - Implement native twoside,offset and unfilled triangle setup.
65 * - Implement a translator from native vertices to swrast vertices.
66 * - On partial fallback (mix of accelerated and unaccelerated
67 * prims), call a pass-through function which translates native
68 * vertices to SWvertices and calls the appropriate swrast function.
69 * - On total fallback (vertex format insufficient for state or all
70 * primitives unaccelerated), hook in swrast_setup instead.
73 GLfloat attrib
[FRAG_ATTRIB_MAX
][4];
74 GLchan color
[4]; /** integer color */
79 #define FRAG_ATTRIB_CI FRAG_ATTRIB_COL0
82 struct swrast_device_driver
;
85 /* These are the public-access functions exported from swrast.
89 _swrast_CreateContext( struct gl_context
*ctx
);
92 _swrast_DestroyContext( struct gl_context
*ctx
);
94 /* Get a (non-const) reference to the device driver struct for swrast.
96 extern struct swrast_device_driver
*
97 _swrast_GetDeviceDriverReference( struct gl_context
*ctx
);
100 _swrast_Bitmap( struct gl_context
*ctx
,
102 GLsizei width
, GLsizei height
,
103 const struct gl_pixelstore_attrib
*unpack
,
104 const GLubyte
*bitmap
);
107 _swrast_CopyPixels( struct gl_context
*ctx
,
108 GLint srcx
, GLint srcy
,
109 GLint destx
, GLint desty
,
110 GLsizei width
, GLsizei height
,
114 _swrast_DrawPixels( struct gl_context
*ctx
,
116 GLsizei width
, GLsizei height
,
117 GLenum format
, GLenum type
,
118 const struct gl_pixelstore_attrib
*unpack
,
119 const GLvoid
*pixels
);
122 _swrast_ReadPixels( struct gl_context
*ctx
,
123 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
124 GLenum format
, GLenum type
,
125 const struct gl_pixelstore_attrib
*unpack
,
129 _swrast_BlitFramebuffer(struct gl_context
*ctx
,
130 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
131 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
132 GLbitfield mask
, GLenum filter
);
135 _swrast_Clear(struct gl_context
*ctx
, GLbitfield buffers
);
138 _swrast_Accum(struct gl_context
*ctx
, GLenum op
, GLfloat value
);
142 /* Reset the stipple counter
145 _swrast_ResetLineStipple( struct gl_context
*ctx
);
148 * Indicates front/back facing for subsequent points/lines when drawing
149 * unfilled polygons. Needed for two-side stencil.
152 _swrast_SetFacing(struct gl_context
*ctx
, GLuint facing
);
154 /* These will always render the correct point/line/triangle for the
157 * For flatshaded primitives, the provoking vertex is the final one.
160 _swrast_Point( struct gl_context
*ctx
, const SWvertex
*v
);
163 _swrast_Line( struct gl_context
*ctx
, const SWvertex
*v0
, const SWvertex
*v1
);
166 _swrast_Triangle( struct gl_context
*ctx
, const SWvertex
*v0
,
167 const SWvertex
*v1
, const SWvertex
*v2
);
170 _swrast_Quad( struct gl_context
*ctx
,
171 const SWvertex
*v0
, const SWvertex
*v1
,
172 const SWvertex
*v2
, const SWvertex
*v3
);
175 _swrast_flush( struct gl_context
*ctx
);
178 _swrast_render_primitive( struct gl_context
*ctx
, GLenum mode
);
181 _swrast_render_start( struct gl_context
*ctx
);
184 _swrast_render_finish( struct gl_context
*ctx
);
186 extern struct gl_texture_image
*
187 _swrast_new_texture_image( struct gl_context
*ctx
);
190 _swrast_delete_texture_image(struct gl_context
*ctx
,
191 struct gl_texture_image
*texImage
);
194 _swrast_alloc_texture_image_buffer(struct gl_context
*ctx
,
195 struct gl_texture_image
*texImage
,
196 gl_format format
, GLsizei width
,
197 GLsizei height
, GLsizei depth
);
200 _swrast_free_texture_image_buffer(struct gl_context
*ctx
,
201 struct gl_texture_image
*texImage
);
204 _swrast_map_teximage(struct gl_context
*ctx
,
205 struct gl_texture_image
*texImage
,
207 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
210 GLint
*rowStrideOut
);
213 _swrast_unmap_teximage(struct gl_context
*ctx
,
214 struct gl_texture_image
*texImage
,
217 /* Tell the software rasterizer about core state changes.
220 _swrast_InvalidateState( struct gl_context
*ctx
, GLbitfield new_state
);
222 /* Configure software rasterizer to match hardware rasterizer characteristics:
225 _swrast_allow_vertex_fog( struct gl_context
*ctx
, GLboolean value
);
228 _swrast_allow_pixel_fog( struct gl_context
*ctx
, GLboolean value
);
233 _swrast_print_vertex( struct gl_context
*ctx
, const SWvertex
*v
);
238 _swrast_eject_texture_images(struct gl_context
*ctx
);
242 _swrast_render_texture(struct gl_context
*ctx
,
243 struct gl_framebuffer
*fb
,
244 struct gl_renderbuffer_attachment
*att
);
247 _swrast_finish_render_texture(struct gl_context
*ctx
,
248 struct gl_renderbuffer_attachment
*att
);
253 * The driver interface for the software rasterizer.
254 * XXX this may go away.
255 * We may move these functions to ctx->Driver.RenderStart, RenderEnd.
257 struct swrast_device_driver
{
259 * These are called before and after accessing renderbuffers during
260 * software rasterization.
262 * These are a suitable place for grabbing/releasing hardware locks.
264 * NOTE: The swrast triangle/line/point routines *DO NOT* call
265 * these functions. Locking in that case must be organized by the
266 * driver by other mechanisms.
268 void (*SpanRenderStart
)(struct gl_context
*ctx
);
269 void (*SpanRenderFinish
)(struct gl_context
*ctx
);