2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * 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 * If non-zero use GLdouble for walking triangle edges, for better accuracy.
42 #define TRIANGLE_WALK_DOUBLE 0
46 * Bits per depth buffer value (max is 32).
48 #ifndef DEFAULT_SOFTWARE_DEPTH_BITS
49 #define DEFAULT_SOFTWARE_DEPTH_BITS 16
51 /** Depth buffer data type */
52 #if DEFAULT_SOFTWARE_DEPTH_BITS <= 16
53 #define DEFAULT_SOFTWARE_DEPTH_TYPE GLushort
55 #define DEFAULT_SOFTWARE_DEPTH_TYPE GLuint
60 * Max image/surface/texture size.
62 #define SWRAST_MAX_WIDTH 16384
63 #define SWRAST_MAX_HEIGHT 16384
68 * \brief Data-structure to handle vertices in the software rasterizer.
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
77 * wpos = attr[VARYING_SLOT_POS] and MUST BE THE FIRST values in the
78 * vertex because of the tnl clipping code.
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}.
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.
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.
101 GLfloat attrib
[VARYING_SLOT_MAX
][4];
102 GLchan color
[4]; /** integer color */
107 #define VARYING_SLOT_CI VARYING_SLOT_COL0
110 struct swrast_device_driver
;
113 /* These are the public-access functions exported from swrast.
117 _swrast_CreateContext( struct gl_context
*ctx
);
120 _swrast_DestroyContext( struct gl_context
*ctx
);
122 /* Get a (non-const) reference to the device driver struct for swrast.
124 extern struct swrast_device_driver
*
125 _swrast_GetDeviceDriverReference( struct gl_context
*ctx
);
128 _swrast_Bitmap( struct gl_context
*ctx
,
130 GLsizei width
, GLsizei height
,
131 const struct gl_pixelstore_attrib
*unpack
,
132 const GLubyte
*bitmap
);
135 _swrast_CopyPixels( struct gl_context
*ctx
,
136 GLint srcx
, GLint srcy
,
137 GLint destx
, GLint desty
,
138 GLsizei width
, GLsizei height
,
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
);
147 _swrast_DrawPixels( struct gl_context
*ctx
,
149 GLsizei width
, GLsizei height
,
150 GLenum format
, GLenum type
,
151 const struct gl_pixelstore_attrib
*unpack
,
152 const GLvoid
*pixels
);
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
);
161 _swrast_Clear(struct gl_context
*ctx
, GLbitfield buffers
);
165 /* Reset the stipple counter
168 _swrast_ResetLineStipple( struct gl_context
*ctx
);
171 * Indicates front/back facing for subsequent points/lines when drawing
172 * unfilled polygons. Needed for two-side stencil.
175 _swrast_SetFacing(struct gl_context
*ctx
, GLuint facing
);
177 /* These will always render the correct point/line/triangle for the
180 * For flatshaded primitives, the provoking vertex is the final one.
183 _swrast_Point( struct gl_context
*ctx
, const SWvertex
*v
);
186 _swrast_Line( struct gl_context
*ctx
, const SWvertex
*v0
, const SWvertex
*v1
);
189 _swrast_Triangle( struct gl_context
*ctx
, const SWvertex
*v0
,
190 const SWvertex
*v1
, const SWvertex
*v2
);
193 _swrast_Quad( struct gl_context
*ctx
,
194 const SWvertex
*v0
, const SWvertex
*v1
,
195 const SWvertex
*v2
, const SWvertex
*v3
);
198 _swrast_flush( struct gl_context
*ctx
);
201 _swrast_render_primitive( struct gl_context
*ctx
, GLenum mode
);
204 _swrast_render_start( struct gl_context
*ctx
);
207 _swrast_render_finish( struct gl_context
*ctx
);
209 extern struct gl_texture_image
*
210 _swrast_new_texture_image( struct gl_context
*ctx
);
213 _swrast_delete_texture_image(struct gl_context
*ctx
,
214 struct gl_texture_image
*texImage
);
217 _swrast_alloc_texture_image_buffer(struct gl_context
*ctx
,
218 struct gl_texture_image
*texImage
);
221 _swrast_init_texture_image(struct gl_texture_image
*texImage
);
224 _swrast_free_texture_image_buffer(struct gl_context
*ctx
,
225 struct gl_texture_image
*texImage
);
228 _swrast_map_teximage(struct gl_context
*ctx
,
229 struct gl_texture_image
*texImage
,
231 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
234 GLint
*rowStrideOut
);
237 _swrast_unmap_teximage(struct gl_context
*ctx
,
238 struct gl_texture_image
*texImage
,
241 /* Tell the software rasterizer about core state changes.
244 _swrast_InvalidateState( struct gl_context
*ctx
, GLbitfield new_state
);
246 /* Configure software rasterizer to match hardware rasterizer characteristics:
249 _swrast_allow_vertex_fog( struct gl_context
*ctx
, GLboolean value
);
252 _swrast_allow_pixel_fog( struct gl_context
*ctx
, GLboolean value
);
257 _swrast_print_vertex( struct gl_context
*ctx
, const SWvertex
*v
);
262 _swrast_eject_texture_images(struct gl_context
*ctx
);
266 _swrast_render_texture(struct gl_context
*ctx
,
267 struct gl_framebuffer
*fb
,
268 struct gl_renderbuffer_attachment
*att
);
271 _swrast_finish_render_texture(struct gl_context
*ctx
,
272 struct gl_renderbuffer
*rb
);
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.
280 struct swrast_device_driver
{
282 * These are called before and after accessing renderbuffers during
283 * software rasterization.
285 * These are a suitable place for grabbing/releasing hardware locks.
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.
291 void (*SpanRenderStart
)(struct gl_context
*ctx
);
292 void (*SpanRenderFinish
)(struct gl_context
*ctx
);