swrast.h revision c9a7dfcf92e6adb4b85338c2c8dbbfbaf39fbfe7
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 "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[FRAG_ATTRIB_WPOS] 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 */
100typedef struct {
101   GLfloat attrib[FRAG_ATTRIB_MAX][4];
102   GLchan color[4];   /** integer color */
103   GLfloat pointSize;
104} SWvertex;
105
106
107#define FRAG_ATTRIB_CI FRAG_ATTRIB_COL0
108
109
110struct swrast_device_driver;
111
112
113/* These are the public-access functions exported from swrast.
114 */
115
116extern GLboolean
117_swrast_CreateContext( struct gl_context *ctx );
118
119extern void
120_swrast_DestroyContext( struct gl_context *ctx );
121
122/* Get a (non-const) reference to the device driver struct for swrast.
123 */
124extern struct swrast_device_driver *
125_swrast_GetDeviceDriverReference( struct gl_context *ctx );
126
127extern 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
134extern 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
141extern GLboolean
142swrast_fast_copy_pixels(struct gl_context *ctx,
143			GLint srcX, GLint srcY, GLsizei width, GLsizei height,
144			GLint dstX, GLint dstY, GLenum type);
145
146extern 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
154extern 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
160extern void
161_swrast_Clear(struct gl_context *ctx, GLbitfield buffers);
162
163
164
165/* Reset the stipple counter
166 */
167extern 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 */
174extern 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 */
182extern void
183_swrast_Point( struct gl_context *ctx, const SWvertex *v );
184
185extern void
186_swrast_Line( struct gl_context *ctx, const SWvertex *v0, const SWvertex *v1 );
187
188extern void
189_swrast_Triangle( struct gl_context *ctx, const SWvertex *v0,
190                  const SWvertex *v1, const SWvertex *v2 );
191
192extern void
193_swrast_Quad( struct gl_context *ctx,
194              const SWvertex *v0, const SWvertex *v1,
195	      const SWvertex *v2,  const SWvertex *v3);
196
197extern void
198_swrast_flush( struct gl_context *ctx );
199
200extern void
201_swrast_render_primitive( struct gl_context *ctx, GLenum mode );
202
203extern void
204_swrast_render_start( struct gl_context *ctx );
205
206extern void
207_swrast_render_finish( struct gl_context *ctx );
208
209extern struct gl_texture_image *
210_swrast_new_texture_image( struct gl_context *ctx );
211
212extern void
213_swrast_delete_texture_image(struct gl_context *ctx,
214                             struct gl_texture_image *texImage);
215
216extern GLboolean
217_swrast_alloc_texture_image_buffer(struct gl_context *ctx,
218                                   struct gl_texture_image *texImage);
219
220extern void
221_swrast_init_texture_image(struct gl_texture_image *texImage);
222
223extern void
224_swrast_free_texture_image_buffer(struct gl_context *ctx,
225                                  struct gl_texture_image *texImage);
226
227extern 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
236extern 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 */
243extern void
244_swrast_InvalidateState( struct gl_context *ctx, GLbitfield new_state );
245
246/* Configure software rasterizer to match hardware rasterizer characteristics:
247 */
248extern void
249_swrast_allow_vertex_fog( struct gl_context *ctx, GLboolean value );
250
251extern void
252_swrast_allow_pixel_fog( struct gl_context *ctx, GLboolean value );
253
254/* Debug:
255 */
256extern void
257_swrast_print_vertex( struct gl_context *ctx, const SWvertex *v );
258
259
260
261extern void
262_swrast_eject_texture_images(struct gl_context *ctx);
263
264
265extern void
266_swrast_render_texture(struct gl_context *ctx,
267                       struct gl_framebuffer *fb,
268                       struct gl_renderbuffer_attachment *att);
269
270extern void
271_swrast_finish_render_texture(struct gl_context *ctx,
272                              struct gl_renderbuffer_attachment *att);
273
274
275
276extern GLboolean
277_swrast_AllocTextureStorage(struct gl_context *ctx,
278                            struct gl_texture_object *texObj,
279                            GLsizei levels, GLsizei width,
280                            GLsizei height, GLsizei depth);
281
282
283/**
284 * The driver interface for the software rasterizer.
285 * XXX this may go away.
286 * We may move these functions to ctx->Driver.RenderStart, RenderEnd.
287 */
288struct swrast_device_driver {
289   /*
290    * These are called before and after accessing renderbuffers during
291    * software rasterization.
292    *
293    * These are a suitable place for grabbing/releasing hardware locks.
294    *
295    * NOTE: The swrast triangle/line/point routines *DO NOT* call
296    * these functions.  Locking in that case must be organized by the
297    * driver by other mechanisms.
298    */
299   void (*SpanRenderStart)(struct gl_context *ctx);
300   void (*SpanRenderFinish)(struct gl_context *ctx);
301};
302
303
304
305#endif
306