OSDN Git Service

359a985fdead76a21a2f316c62e711b531252657
[android-x86/external-mesa.git] / src / mesa / swrast / swrast.h
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  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  * OTHER DEALINGS IN THE SOFTWARE.
24  *
25  */
26
27 /**
28  * \file swrast/swrast.h
29  * \brief Public interface to the software rasterization functions.
30  * \author Keith Whitwell <keith@tungstengraphics.com>
31  */
32
33 #ifndef SWRAST_H
34 #define SWRAST_H
35
36 #include "main/mtypes.h"
37 #include "swrast/s_chan.h"
38
39
40 /**
41  * If non-zero use GLdouble for walking triangle edges, for better accuracy.
42  */
43 #define TRIANGLE_WALK_DOUBLE 0
44
45
46 /**
47  * Bits per depth buffer value (max is 32).
48  */
49 #ifndef DEFAULT_SOFTWARE_DEPTH_BITS
50 #define DEFAULT_SOFTWARE_DEPTH_BITS 16
51 #endif
52 /** Depth buffer data type */
53 #if DEFAULT_SOFTWARE_DEPTH_BITS <= 16
54 #define DEFAULT_SOFTWARE_DEPTH_TYPE GLushort
55 #else
56 #define DEFAULT_SOFTWARE_DEPTH_TYPE GLuint
57 #endif
58
59
60 /**
61  * Max image/surface/texture size.
62  */
63 #define SWRAST_MAX_WIDTH 16384
64 #define SWRAST_MAX_HEIGHT 16384
65
66
67 /**
68  * \struct SWvertex
69  * \brief Data-structure to handle vertices in the software rasterizer.
70  * 
71  * The software rasterizer now uses this format for vertices.  Thus a
72  * 'RasterSetup' stage or other translation is required between the
73  * tnl module and the swrast rasterization functions.  This serves to
74  * isolate the swrast module from the internals of the tnl module, and
75  * improve its usefulness as a fallback mechanism for hardware
76  * drivers.
77  *
78  * wpos = attr[VARYING_SLOT_POS] and MUST BE THE FIRST values in the
79  * vertex because of the tnl clipping code.
80
81  * wpos[0] and [1] are the screen-coords of SWvertex.
82  * wpos[2] is the z-buffer coord (if 16-bit Z buffer, in range [0,65535]).
83  * wpos[3] is 1/w where w is the clip-space W coord.  This is the value
84  * that clip{XYZ} were multiplied by to get ndc{XYZ}.
85  *
86  * Full software drivers:
87  *   - Register the rastersetup and triangle functions from
88  *     utils/software_helper.
89  *   - On statechange, update the rasterization pointers in that module.
90  *
91  * Rasterization hardware drivers:
92  *   - Keep native rastersetup.
93  *   - Implement native twoside,offset and unfilled triangle setup.
94  *   - Implement a translator from native vertices to swrast vertices.
95  *   - On partial fallback (mix of accelerated and unaccelerated
96  *   prims), call a pass-through function which translates native
97  *   vertices to SWvertices and calls the appropriate swrast function.
98  *   - On total fallback (vertex format insufficient for state or all
99  *     primitives unaccelerated), hook in swrast_setup instead.
100  */
101 typedef struct {
102    GLfloat attrib[VARYING_SLOT_MAX][4];
103    GLchan color[4];   /** integer color */
104    GLfloat pointSize;
105 } SWvertex;
106
107
108 #define VARYING_SLOT_CI VARYING_SLOT_COL0
109
110
111 struct swrast_device_driver;
112
113
114 /* These are the public-access functions exported from swrast.
115  */
116
117 extern GLboolean
118 _swrast_CreateContext( struct gl_context *ctx );
119
120 extern void
121 _swrast_DestroyContext( struct gl_context *ctx );
122
123 /* Get a (non-const) reference to the device driver struct for swrast.
124  */
125 extern struct swrast_device_driver *
126 _swrast_GetDeviceDriverReference( struct gl_context *ctx );
127
128 extern void
129 _swrast_Bitmap( struct gl_context *ctx,
130                 GLint px, GLint py,
131                 GLsizei width, GLsizei height,
132                 const struct gl_pixelstore_attrib *unpack,
133                 const GLubyte *bitmap );
134
135 extern void
136 _swrast_CopyPixels( struct gl_context *ctx,
137                     GLint srcx, GLint srcy,
138                     GLint destx, GLint desty,
139                     GLsizei width, GLsizei height,
140                     GLenum type );
141
142 extern GLboolean
143 swrast_fast_copy_pixels(struct gl_context *ctx,
144                         GLint srcX, GLint srcY, GLsizei width, GLsizei height,
145                         GLint dstX, GLint dstY, GLenum type);
146
147 extern void
148 _swrast_DrawPixels( struct gl_context *ctx,
149                     GLint x, GLint y,
150                     GLsizei width, GLsizei height,
151                     GLenum format, GLenum type,
152                     const struct gl_pixelstore_attrib *unpack,
153                     const GLvoid *pixels );
154
155 extern void
156 _swrast_BlitFramebuffer(struct gl_context *ctx,
157                         GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
158                         GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
159                         GLbitfield mask, GLenum filter);
160
161 extern void
162 _swrast_Clear(struct gl_context *ctx, GLbitfield buffers);
163
164
165
166 /* Reset the stipple counter
167  */
168 extern void
169 _swrast_ResetLineStipple( struct gl_context *ctx );
170
171 /**
172  * Indicates front/back facing for subsequent points/lines when drawing
173  * unfilled polygons.  Needed for two-side stencil.
174  */
175 extern void
176 _swrast_SetFacing(struct gl_context *ctx, GLuint facing);
177
178 /* These will always render the correct point/line/triangle for the
179  * current state.
180  *
181  * For flatshaded primitives, the provoking vertex is the final one.
182  */
183 extern void
184 _swrast_Point( struct gl_context *ctx, const SWvertex *v );
185
186 extern void
187 _swrast_Line( struct gl_context *ctx, const SWvertex *v0, const SWvertex *v1 );
188
189 extern void
190 _swrast_Triangle( struct gl_context *ctx, const SWvertex *v0,
191                   const SWvertex *v1, const SWvertex *v2 );
192
193 extern void
194 _swrast_Quad( struct gl_context *ctx,
195               const SWvertex *v0, const SWvertex *v1,
196               const SWvertex *v2,  const SWvertex *v3);
197
198 extern void
199 _swrast_flush( struct gl_context *ctx );
200
201 extern void
202 _swrast_render_primitive( struct gl_context *ctx, GLenum mode );
203
204 extern void
205 _swrast_render_start( struct gl_context *ctx );
206
207 extern void
208 _swrast_render_finish( struct gl_context *ctx );
209
210 extern struct gl_texture_image *
211 _swrast_new_texture_image( struct gl_context *ctx );
212
213 extern void
214 _swrast_delete_texture_image(struct gl_context *ctx,
215                              struct gl_texture_image *texImage);
216
217 extern GLboolean
218 _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
219                                    struct gl_texture_image *texImage);
220
221 extern GLboolean
222 _swrast_init_texture_image(struct gl_texture_image *texImage);
223
224 extern void
225 _swrast_free_texture_image_buffer(struct gl_context *ctx,
226                                   struct gl_texture_image *texImage);
227
228 extern void
229 _swrast_map_teximage(struct gl_context *ctx,
230                      struct gl_texture_image *texImage,
231                      GLuint slice,
232                      GLuint x, GLuint y, GLuint w, GLuint h,
233                      GLbitfield mode,
234                      GLubyte **mapOut,
235                      GLint *rowStrideOut);
236
237 extern void
238 _swrast_unmap_teximage(struct gl_context *ctx,
239                        struct gl_texture_image *texImage,
240                        GLuint slice);
241
242 /* Tell the software rasterizer about core state changes.
243  */
244 extern void
245 _swrast_InvalidateState( struct gl_context *ctx, GLbitfield new_state );
246
247 /* Configure software rasterizer to match hardware rasterizer characteristics:
248  */
249 extern void
250 _swrast_allow_vertex_fog( struct gl_context *ctx, GLboolean value );
251
252 extern void
253 _swrast_allow_pixel_fog( struct gl_context *ctx, GLboolean value );
254
255 /* Debug:
256  */
257 extern void
258 _swrast_print_vertex( struct gl_context *ctx, const SWvertex *v );
259
260
261
262 extern void
263 _swrast_eject_texture_images(struct gl_context *ctx);
264
265
266 extern void
267 _swrast_render_texture(struct gl_context *ctx,
268                        struct gl_framebuffer *fb,
269                        struct gl_renderbuffer_attachment *att);
270
271 extern void
272 _swrast_finish_render_texture(struct gl_context *ctx,
273                               struct gl_renderbuffer *rb);
274
275
276 /**
277  * The driver interface for the software rasterizer.
278  * XXX this may go away.
279  * We may move these functions to ctx->Driver.RenderStart, RenderEnd.
280  */
281 struct swrast_device_driver {
282    /*
283     * These are called before and after accessing renderbuffers during
284     * software rasterization.
285     *
286     * These are a suitable place for grabbing/releasing hardware locks.
287     *
288     * NOTE: The swrast triangle/line/point routines *DO NOT* call
289     * these functions.  Locking in that case must be organized by the
290     * driver by other mechanisms.
291     */
292    void (*SpanRenderStart)(struct gl_context *ctx);
293    void (*SpanRenderFinish)(struct gl_context *ctx);
294 };
295
296
297
298 #endif