s_span.h revision 3464ebd5
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 35struct gl_context; 36struct gl_renderbuffer; 37 38 39/** 40 * \defgroup SpanFlags 41 * Special bitflags to describe span data. 42 * 43 * In general, the point/line/triangle functions interpolate/emit the 44 * attributes specified by swrast->_ActiveAttribs (i.e. FRAT_BIT_* values). 45 * Some things don't fit into that, though, so we have these flags. 46 */ 47/*@{*/ 48#define SPAN_RGBA 0x01 /**< interpMask and arrayMask */ 49#define SPAN_Z 0x02 /**< interpMask and arrayMask */ 50#define SPAN_FLAT 0x04 /**< interpMask: flat shading? */ 51#define SPAN_XY 0x08 /**< array.x[], y[] valid? */ 52#define SPAN_MASK 0x10 /**< was array.mask[] filled in by caller? */ 53#define SPAN_LAMBDA 0x20 /**< array.lambda[] valid? */ 54#define SPAN_COVERAGE 0x40 /**< array.coverage[] valid? */ 55/*@}*/ 56 57 58/** 59 * \sw_span_arrays 60 * \brief Arrays of fragment values. 61 * 62 * These will either be computed from the span x/xStep values or 63 * filled in by glDraw/CopyPixels, etc. 64 * These arrays are separated out of sw_span to conserve memory. 65 */ 66typedef struct sw_span_arrays 67{ 68 /** Per-fragment attributes (indexed by FRAG_ATTRIB_* tokens) */ 69 /* XXX someday look at transposing first two indexes for better memory 70 * access pattern. 71 */ 72 GLfloat attribs[FRAG_ATTRIB_MAX][MAX_WIDTH][4]; 73 74 /** This mask indicates which fragments are alive or culled */ 75 GLubyte mask[MAX_WIDTH]; 76 77 GLenum ChanType; /**< Color channel type, GL_UNSIGNED_BYTE, GL_FLOAT */ 78 79 /** Attribute arrays that don't fit into attribs[] array above */ 80 /*@{*/ 81 GLubyte rgba8[MAX_WIDTH][4]; 82 GLushort rgba16[MAX_WIDTH][4]; 83 GLchan (*rgba)[4]; /** either == rgba8 or rgba16 */ 84 GLint x[MAX_WIDTH]; /**< fragment X coords */ 85 GLint y[MAX_WIDTH]; /**< fragment Y coords */ 86 GLuint z[MAX_WIDTH]; /**< fragment Z coords */ 87 GLuint index[MAX_WIDTH]; /**< Color indexes */ 88 GLfloat lambda[MAX_TEXTURE_COORD_UNITS][MAX_WIDTH]; /**< Texture LOD */ 89 GLfloat coverage[MAX_WIDTH]; /**< Fragment coverage for AA/smoothing */ 90 /*@}*/ 91} SWspanarrays; 92 93 94/** 95 * The SWspan structure describes the colors, Z, fogcoord, texcoords, 96 * etc for either a horizontal run or an array of independent pixels. 97 * We can either specify a base/step to indicate interpolated values, or 98 * fill in explicit arrays of values. The interpMask and arrayMask bitfields 99 * indicate which attributes are active interpolants or arrays, respectively. 100 * 101 * It would be interesting to experiment with multiprocessor rasterization 102 * with this structure. The triangle rasterizer could simply emit a 103 * stream of these structures which would be consumed by one or more 104 * span-processing threads which could run in parallel. 105 */ 106typedef struct sw_span 107{ 108 /** Coord of first fragment in horizontal span/run */ 109 GLint x, y; 110 111 /** Number of fragments in the span */ 112 GLuint end; 113 114 /** for clipping left edge of spans */ 115 GLuint leftClip; 116 117 /** This flag indicates that mask[] array is effectively filled with ones */ 118 GLboolean writeAll; 119 120 /** either GL_POLYGON, GL_LINE, GL_POLYGON, GL_BITMAP */ 121 GLenum primitive; 122 123 /** 0 = front-facing span, 1 = back-facing span (for two-sided stencil) */ 124 GLuint facing; 125 126 /** 127 * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates 128 * which of the attrStart/StepX/StepY variables are relevant. 129 */ 130 GLbitfield interpMask; 131 132 /** Fragment attribute interpolants */ 133 GLfloat attrStart[FRAG_ATTRIB_MAX][4]; /**< initial value */ 134 GLfloat attrStepX[FRAG_ATTRIB_MAX][4]; /**< dvalue/dx */ 135 GLfloat attrStepY[FRAG_ATTRIB_MAX][4]; /**< dvalue/dy */ 136 137 /* XXX the rest of these will go away eventually... */ 138 139 /* For horizontal spans, step is the partial derivative wrt X. 140 * For lines, step is the delta from one fragment to the next. 141 */ 142 GLfixed red, redStep; 143 GLfixed green, greenStep; 144 GLfixed blue, blueStep; 145 GLfixed alpha, alphaStep; 146 GLfixed index, indexStep; 147 GLfixed z, zStep; /**< XXX z should probably be GLuint */ 148 GLfixed intTex[2], intTexStep[2]; /**< (s,t) for unit[0] only */ 149 150 /** 151 * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates 152 * which of the fragment arrays in the span_arrays struct are relevant. 153 */ 154 GLbitfield arrayMask; 155 156 GLbitfield arrayAttribs; 157 158 /** 159 * We store the arrays of fragment values in a separate struct so 160 * that we can allocate sw_span structs on the stack without using 161 * a lot of memory. The span_arrays struct is about 1.4MB while the 162 * sw_span struct is only about 512 bytes. 163 */ 164 SWspanarrays *array; 165} SWspan; 166 167 168 169#define INIT_SPAN(S, PRIMITIVE) \ 170do { \ 171 (S).primitive = (PRIMITIVE); \ 172 (S).interpMask = 0x0; \ 173 (S).arrayMask = 0x0; \ 174 (S).arrayAttribs = 0x0; \ 175 (S).end = 0; \ 176 (S).leftClip = 0; \ 177 (S).facing = 0; \ 178 (S).array = SWRAST_CONTEXT(ctx)->SpanArrays; \ 179} while (0) 180 181 182 183extern void 184_swrast_span_default_attribs(struct gl_context *ctx, SWspan *span); 185 186extern void 187_swrast_span_interpolate_z( const struct gl_context *ctx, SWspan *span ); 188 189extern GLfloat 190_swrast_compute_lambda(GLfloat dsdx, GLfloat dsdy, GLfloat dtdx, GLfloat dtdy, 191 GLfloat dqdx, GLfloat dqdy, GLfloat texW, GLfloat texH, 192 GLfloat s, GLfloat t, GLfloat q, GLfloat invQ); 193 194 195extern void 196_swrast_write_rgba_span( struct gl_context *ctx, SWspan *span); 197 198 199extern void 200_swrast_read_rgba_span(struct gl_context *ctx, struct gl_renderbuffer *rb, 201 GLuint n, GLint x, GLint y, GLenum type, GLvoid *rgba); 202 203extern void 204_swrast_get_values(struct gl_context *ctx, struct gl_renderbuffer *rb, 205 GLuint count, const GLint x[], const GLint y[], 206 void *values, GLuint valueSize); 207 208extern void 209_swrast_put_row(struct gl_context *ctx, struct gl_renderbuffer *rb, 210 GLuint count, GLint x, GLint y, 211 const GLvoid *values, GLuint valueSize); 212 213extern void 214_swrast_get_row(struct gl_context *ctx, struct gl_renderbuffer *rb, 215 GLuint count, GLint x, GLint y, 216 GLvoid *values, GLuint valueSize); 217 218 219extern void * 220_swrast_get_dest_rgba(struct gl_context *ctx, struct gl_renderbuffer *rb, 221 SWspan *span); 222 223#endif 224