• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Mesa 3-D graphics library
3  *
4  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
5  *
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:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
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.
23  *
24  */
25 
26 /**
27  * \file swrast/swrast.h
28  * \brief Public interface to the software rasterization functions.
29  * \author Keith Whitwell <keithw@vmware.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                         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);
147 
148 extern void
149 _swrast_DrawPixels( struct gl_context *ctx,
150 		    GLint x, GLint y,
151 		    GLsizei width, GLsizei height,
152 		    GLenum format, GLenum type,
153 		    const struct gl_pixelstore_attrib *unpack,
154 		    const GLvoid *pixels );
155 
156 extern void
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);
163 
164 extern void
165 _swrast_Clear(struct gl_context *ctx, GLbitfield buffers);
166 
167 
168 
169 /* Reset the stipple counter
170  */
171 extern void
172 _swrast_ResetLineStipple( struct gl_context *ctx );
173 
174 /**
175  * Indicates front/back facing for subsequent points/lines when drawing
176  * unfilled polygons.  Needed for two-side stencil.
177  */
178 extern void
179 _swrast_SetFacing(struct gl_context *ctx, GLuint facing);
180 
181 /* These will always render the correct point/line/triangle for the
182  * current state.
183  *
184  * For flatshaded primitives, the provoking vertex is the final one.
185  */
186 extern void
187 _swrast_Point( struct gl_context *ctx, const SWvertex *v );
188 
189 extern void
190 _swrast_Line( struct gl_context *ctx, const SWvertex *v0, const SWvertex *v1 );
191 
192 extern void
193 _swrast_Triangle( struct gl_context *ctx, const SWvertex *v0,
194                   const SWvertex *v1, const SWvertex *v2 );
195 
196 extern void
197 _swrast_Quad( struct gl_context *ctx,
198               const SWvertex *v0, const SWvertex *v1,
199 	      const SWvertex *v2,  const SWvertex *v3);
200 
201 extern void
202 _swrast_flush( struct gl_context *ctx );
203 
204 extern void
205 _swrast_render_primitive( struct gl_context *ctx, GLenum mode );
206 
207 extern void
208 _swrast_render_start( struct gl_context *ctx );
209 
210 extern void
211 _swrast_render_finish( struct gl_context *ctx );
212 
213 extern struct gl_texture_image *
214 _swrast_new_texture_image( struct gl_context *ctx );
215 
216 extern void
217 _swrast_delete_texture_image(struct gl_context *ctx,
218                              struct gl_texture_image *texImage);
219 
220 extern GLboolean
221 _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
222                                    struct gl_texture_image *texImage);
223 
224 extern GLboolean
225 _swrast_init_texture_image(struct gl_texture_image *texImage);
226 
227 extern void
228 _swrast_free_texture_image_buffer(struct gl_context *ctx,
229                                   struct gl_texture_image *texImage);
230 
231 extern void
232 _swrast_map_teximage(struct gl_context *ctx,
233 		     struct gl_texture_image *texImage,
234 		     GLuint slice,
235 		     GLuint x, GLuint y, GLuint w, GLuint h,
236 		     GLbitfield mode,
237 		     GLubyte **mapOut,
238 		     GLint *rowStrideOut);
239 
240 extern void
241 _swrast_unmap_teximage(struct gl_context *ctx,
242 		       struct gl_texture_image *texImage,
243 		       GLuint slice);
244 
245 /* Tell the software rasterizer about core state changes.
246  */
247 extern void
248 _swrast_InvalidateState( struct gl_context *ctx, GLbitfield new_state );
249 
250 /* Configure software rasterizer to match hardware rasterizer characteristics:
251  */
252 extern void
253 _swrast_allow_vertex_fog( struct gl_context *ctx, GLboolean value );
254 
255 extern void
256 _swrast_allow_pixel_fog( struct gl_context *ctx, GLboolean value );
257 
258 /* Debug:
259  */
260 extern void
261 _swrast_print_vertex( struct gl_context *ctx, const SWvertex *v );
262 
263 
264 
265 extern void
266 _swrast_eject_texture_images(struct gl_context *ctx);
267 
268 
269 extern void
270 _swrast_render_texture(struct gl_context *ctx,
271                        struct gl_framebuffer *fb,
272                        struct gl_renderbuffer_attachment *att);
273 
274 extern void
275 _swrast_finish_render_texture(struct gl_context *ctx,
276                               struct gl_renderbuffer *rb);
277 
278 
279 /**
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.
283  */
284 struct swrast_device_driver {
285    /*
286     * These are called before and after accessing renderbuffers during
287     * software rasterization.
288     *
289     * These are a suitable place for grabbing/releasing hardware locks.
290     *
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.
294     */
295    void (*SpanRenderStart)(struct gl_context *ctx);
296    void (*SpanRenderFinish)(struct gl_context *ctx);
297 };
298 
299 
300 
301 #endif
302