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