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 <keithw@vmware.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 struct gl_framebuffer
*srcFb
,
144 struct gl_framebuffer
*dstFb
,
145 GLint srcX
, GLint srcY
, GLsizei width
, GLsizei height
,
146 GLint dstX
, GLint dstY
, GLenum type
);
149 _swrast_DrawPixels( struct gl_context
*ctx
,
151 GLsizei width
, GLsizei height
,
152 GLenum format
, GLenum type
,
153 const struct gl_pixelstore_attrib
*unpack
,
154 const GLvoid
*pixels
);
157 _swrast_BlitFramebuffer(struct gl_context
*ctx
,
158 struct gl_framebuffer
*readFb
,
159 struct gl_framebuffer
*drawFb
,
160 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
161 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
162 GLbitfield mask
, GLenum filter
);
165 _swrast_Clear(struct gl_context
*ctx
, GLbitfield buffers
);
169 /* Reset the stipple counter
172 _swrast_ResetLineStipple( struct gl_context
*ctx
);
175 * Indicates front/back facing for subsequent points/lines when drawing
176 * unfilled polygons. Needed for two-side stencil.
179 _swrast_SetFacing(struct gl_context
*ctx
, GLuint facing
);
181 /* These will always render the correct point/line/triangle for the
184 * For flatshaded primitives, the provoking vertex is the final one.
187 _swrast_Point( struct gl_context
*ctx
, const SWvertex
*v
);
190 _swrast_Line( struct gl_context
*ctx
, const SWvertex
*v0
, const SWvertex
*v1
);
193 _swrast_Triangle( struct gl_context
*ctx
, const SWvertex
*v0
,
194 const SWvertex
*v1
, const SWvertex
*v2
);
197 _swrast_Quad( struct gl_context
*ctx
,
198 const SWvertex
*v0
, const SWvertex
*v1
,
199 const SWvertex
*v2
, const SWvertex
*v3
);
202 _swrast_flush( struct gl_context
*ctx
);
205 _swrast_render_primitive( struct gl_context
*ctx
, GLenum mode
);
208 _swrast_render_start( struct gl_context
*ctx
);
211 _swrast_render_finish( struct gl_context
*ctx
);
213 extern struct gl_texture_image
*
214 _swrast_new_texture_image( struct gl_context
*ctx
);
217 _swrast_delete_texture_image(struct gl_context
*ctx
,
218 struct gl_texture_image
*texImage
);
221 _swrast_alloc_texture_image_buffer(struct gl_context
*ctx
,
222 struct gl_texture_image
*texImage
);
225 _swrast_init_texture_image(struct gl_texture_image
*texImage
);
228 _swrast_free_texture_image_buffer(struct gl_context
*ctx
,
229 struct gl_texture_image
*texImage
);
232 _swrast_map_teximage(struct gl_context
*ctx
,
233 struct gl_texture_image
*texImage
,
235 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
238 GLint
*rowStrideOut
);
241 _swrast_unmap_teximage(struct gl_context
*ctx
,
242 struct gl_texture_image
*texImage
,
245 /* Tell the software rasterizer about core state changes.
248 _swrast_InvalidateState( struct gl_context
*ctx
, GLbitfield new_state
);
250 /* Configure software rasterizer to match hardware rasterizer characteristics:
253 _swrast_allow_vertex_fog( struct gl_context
*ctx
, GLboolean value
);
256 _swrast_allow_pixel_fog( struct gl_context
*ctx
, GLboolean value
);
261 _swrast_print_vertex( struct gl_context
*ctx
, const SWvertex
*v
);
266 _swrast_eject_texture_images(struct gl_context
*ctx
);
270 _swrast_render_texture(struct gl_context
*ctx
,
271 struct gl_framebuffer
*fb
,
272 struct gl_renderbuffer_attachment
*att
);
275 _swrast_finish_render_texture(struct gl_context
*ctx
,
276 struct gl_renderbuffer
*rb
);
280 * The driver interface for the software rasterizer.
281 * XXX this may go away.
282 * We may move these functions to ctx->Driver.RenderStart, RenderEnd.
284 struct swrast_device_driver
{
286 * These are called before and after accessing renderbuffers during
287 * software rasterization.
289 * These are a suitable place for grabbing/releasing hardware locks.
291 * NOTE: The swrast triangle/line/point routines *DO NOT* call
292 * these functions. Locking in that case must be organized by the
293 * driver by other mechanisms.
295 void (*SpanRenderStart
)(struct gl_context
*ctx
);
296 void (*SpanRenderFinish
)(struct gl_context
*ctx
);