OSDN Git Service

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