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