mesa: remove gl_renderbuffer::DataType
[mesa.git] / src / mesa / swrast / s_span.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.5
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 #ifndef S_SPAN_H
28 #define S_SPAN_H
29
30
31 #include "main/config.h"
32 #include "main/glheader.h"
33 #include "main/mtypes.h"
34 #include "swrast/s_chan.h"
35
36
37 struct gl_context;
38 struct gl_renderbuffer;
39
40
41 /**
42 * \defgroup SpanFlags
43 * Special bitflags to describe span data.
44 *
45 * In general, the point/line/triangle functions interpolate/emit the
46 * attributes specified by swrast->_ActiveAttribs (i.e. FRAT_BIT_* values).
47 * Some things don't fit into that, though, so we have these flags.
48 */
49 /*@{*/
50 #define SPAN_RGBA 0x01 /**< interpMask and arrayMask */
51 #define SPAN_Z 0x02 /**< interpMask and arrayMask */
52 #define SPAN_FLAT 0x04 /**< interpMask: flat shading? */
53 #define SPAN_XY 0x08 /**< array.x[], y[] valid? */
54 #define SPAN_MASK 0x10 /**< was array.mask[] filled in by caller? */
55 #define SPAN_LAMBDA 0x20 /**< array.lambda[] valid? */
56 #define SPAN_COVERAGE 0x40 /**< array.coverage[] valid? */
57 /*@}*/
58
59
60 /**
61 * \sw_span_arrays
62 * \brief Arrays of fragment values.
63 *
64 * These will either be computed from the span x/xStep values or
65 * filled in by glDraw/CopyPixels, etc.
66 * These arrays are separated out of sw_span to conserve memory.
67 */
68 typedef struct sw_span_arrays
69 {
70 /** Per-fragment attributes (indexed by FRAG_ATTRIB_* tokens) */
71 /* XXX someday look at transposing first two indexes for better memory
72 * access pattern.
73 */
74 GLfloat attribs[FRAG_ATTRIB_MAX][MAX_WIDTH][4];
75
76 /** This mask indicates which fragments are alive or culled */
77 GLubyte mask[MAX_WIDTH];
78
79 GLenum ChanType; /**< Color channel type, GL_UNSIGNED_BYTE, GL_FLOAT */
80
81 /** Attribute arrays that don't fit into attribs[] array above */
82 /*@{*/
83 GLubyte rgba8[MAX_WIDTH][4];
84 GLushort rgba16[MAX_WIDTH][4];
85 GLchan (*rgba)[4]; /** either == rgba8 or rgba16 */
86 GLint x[MAX_WIDTH]; /**< fragment X coords */
87 GLint y[MAX_WIDTH]; /**< fragment Y coords */
88 GLuint z[MAX_WIDTH]; /**< fragment Z coords */
89 GLuint index[MAX_WIDTH]; /**< Color indexes */
90 GLfloat lambda[MAX_TEXTURE_COORD_UNITS][MAX_WIDTH]; /**< Texture LOD */
91 GLfloat coverage[MAX_WIDTH]; /**< Fragment coverage for AA/smoothing */
92 /*@}*/
93 } SWspanarrays;
94
95
96 /**
97 * The SWspan structure describes the colors, Z, fogcoord, texcoords,
98 * etc for either a horizontal run or an array of independent pixels.
99 * We can either specify a base/step to indicate interpolated values, or
100 * fill in explicit arrays of values. The interpMask and arrayMask bitfields
101 * indicate which attributes are active interpolants or arrays, respectively.
102 *
103 * It would be interesting to experiment with multiprocessor rasterization
104 * with this structure. The triangle rasterizer could simply emit a
105 * stream of these structures which would be consumed by one or more
106 * span-processing threads which could run in parallel.
107 */
108 typedef struct sw_span
109 {
110 /** Coord of first fragment in horizontal span/run */
111 GLint x, y;
112
113 /** Number of fragments in the span */
114 GLuint end;
115
116 /** for clipping left edge of spans */
117 GLuint leftClip;
118
119 /** This flag indicates that mask[] array is effectively filled with ones */
120 GLboolean writeAll;
121
122 /** either GL_POLYGON, GL_LINE, GL_POLYGON, GL_BITMAP */
123 GLenum primitive;
124
125 /** 0 = front-facing span, 1 = back-facing span (for two-sided stencil) */
126 GLuint facing;
127
128 /**
129 * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates
130 * which of the attrStart/StepX/StepY variables are relevant.
131 */
132 GLbitfield interpMask;
133
134 /** Fragment attribute interpolants */
135 GLfloat attrStart[FRAG_ATTRIB_MAX][4]; /**< initial value */
136 GLfloat attrStepX[FRAG_ATTRIB_MAX][4]; /**< dvalue/dx */
137 GLfloat attrStepY[FRAG_ATTRIB_MAX][4]; /**< dvalue/dy */
138
139 /* XXX the rest of these will go away eventually... */
140
141 /* For horizontal spans, step is the partial derivative wrt X.
142 * For lines, step is the delta from one fragment to the next.
143 */
144 GLfixed red, redStep;
145 GLfixed green, greenStep;
146 GLfixed blue, blueStep;
147 GLfixed alpha, alphaStep;
148 GLfixed index, indexStep;
149 GLfixed z, zStep; /**< XXX z should probably be GLuint */
150 GLfixed intTex[2], intTexStep[2]; /**< (s,t) for unit[0] only */
151
152 /**
153 * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates
154 * which of the fragment arrays in the span_arrays struct are relevant.
155 */
156 GLbitfield arrayMask;
157
158 /** Mask of FRAG_BIT_x bits */
159 GLbitfield64 arrayAttribs;
160
161 /**
162 * We store the arrays of fragment values in a separate struct so
163 * that we can allocate sw_span structs on the stack without using
164 * a lot of memory. The span_arrays struct is about 1.4MB while the
165 * sw_span struct is only about 512 bytes.
166 */
167 SWspanarrays *array;
168 } SWspan;
169
170
171
172 #define INIT_SPAN(S, PRIMITIVE) \
173 do { \
174 (S).primitive = (PRIMITIVE); \
175 (S).interpMask = 0x0; \
176 (S).arrayMask = 0x0; \
177 (S).arrayAttribs = 0x0; \
178 (S).end = 0; \
179 (S).leftClip = 0; \
180 (S).facing = 0; \
181 (S).array = SWRAST_CONTEXT(ctx)->SpanArrays; \
182 } while (0)
183
184
185
186 extern void
187 _swrast_span_default_attribs(struct gl_context *ctx, SWspan *span);
188
189 extern void
190 _swrast_span_interpolate_z( const struct gl_context *ctx, SWspan *span );
191
192 extern GLfloat
193 _swrast_compute_lambda(GLfloat dsdx, GLfloat dsdy, GLfloat dtdx, GLfloat dtdy,
194 GLfloat dqdx, GLfloat dqdy, GLfloat texW, GLfloat texH,
195 GLfloat s, GLfloat t, GLfloat q, GLfloat invQ);
196
197
198 extern void
199 _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span);
200
201
202 extern void
203 _swrast_read_rgba_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
204 GLuint n, GLint x, GLint y, GLvoid *rgba);
205
206 extern void
207 _swrast_put_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
208 GLenum datatype,
209 GLuint count, GLint x, GLint y,
210 const void *values, const GLubyte *mask);
211
212 extern void *
213 _swrast_get_dest_rgba(struct gl_context *ctx, struct gl_renderbuffer *rb,
214 SWspan *span);
215
216 #endif