diff options
author | Brian <[email protected]> | 2007-05-25 15:45:21 -0600 |
---|---|---|
committer | Brian <[email protected]> | 2007-05-25 15:45:21 -0600 |
commit | 00d5334899010b0e7c0ba53fdc9b112d20f6c34b (patch) | |
tree | 54fa9dbdc0f2c0800d25add27ffb7885236d9280 /src | |
parent | cbe4dbef8e8e9ff29d64ca588e81c2bb079d99f1 (diff) |
Add some comments to explain things, code clarifications.
Also, add quad.facing field for front/back facing. See comments for details.
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/softpipe/generic/g_headers.h | 1 | ||||
-rw-r--r-- | src/mesa/softpipe/generic/g_prim_setup.c | 78 | ||||
-rw-r--r-- | src/mesa/softpipe/generic/g_tile_fs.c | 29 |
3 files changed, 72 insertions, 36 deletions
diff --git a/src/mesa/softpipe/generic/g_headers.h b/src/mesa/softpipe/generic/g_headers.h index 1db325a4ab6..96ff52a453b 100644 --- a/src/mesa/softpipe/generic/g_headers.h +++ b/src/mesa/softpipe/generic/g_headers.h @@ -93,6 +93,7 @@ struct quad_header { GLint x0; GLint y0; GLuint mask; + GLuint facing; /**< Front or back facing? */ struct { GLfloat color[4][QUAD_SIZE]; /* rrrr, gggg, bbbb, aaaa */ diff --git a/src/mesa/softpipe/generic/g_prim_setup.c b/src/mesa/softpipe/generic/g_prim_setup.c index 3e9639f7bc1..ce93c0a6f96 100644 --- a/src/mesa/softpipe/generic/g_prim_setup.c +++ b/src/mesa/softpipe/generic/g_prim_setup.c @@ -68,35 +68,30 @@ struct setup_stage { struct quad_header quad; struct { - GLint left[2]; + GLint left[2]; /**< [0] = row0, [1] = row1 */ GLint right[2]; GLint y; GLuint y_flags; - GLuint mask; + GLuint mask; /**< mask of MASK_BOTTOM/TOP_LEFT/RIGHT bits */ } span; }; - +/** + * Basically a cast wrapper. + */ static inline struct setup_stage *setup_stage( struct prim_stage *stage ) { return (struct setup_stage *)stage; } - -static inline GLint _min(GLint x, GLint y) -{ - return x < y ? x : y; -} - -static inline GLint _max(GLint x, GLint y) -{ - return x > y ? x : y; -} - +/** + * Given an X or Y coordinate, return the block/quad coordinate that it + * belongs to. + */ static inline GLint block( GLint x ) { return x & ~1; @@ -110,7 +105,9 @@ static void setup_begin( struct prim_stage *stage ) } - +/** + * Run shader on a quad/block. + */ static void run_shader_block( struct setup_stage *setup, GLint x, GLint y, GLuint mask ) { @@ -122,7 +119,11 @@ static void run_shader_block( struct setup_stage *setup, } -/* this is pretty nasty... may need to rework flush_spans again to +/** + * Compute mask which indicates which pixels in the 2x2 quad are actually inside + * the triangle's bounds. + * + * this is pretty nasty... may need to rework flush_spans again to * fix it, if possible. */ static GLuint calculate_mask( struct setup_stage *setup, @@ -146,6 +147,9 @@ static GLuint calculate_mask( struct setup_stage *setup, } +/** + * Render a horizontal span of quads + */ static void flush_spans( struct setup_stage *setup ) { GLint minleft, maxright; @@ -153,10 +157,8 @@ static void flush_spans( struct setup_stage *setup ) switch (setup->span.y_flags) { case 3: - minleft = _min(setup->span.left[0], - setup->span.left[1]); - maxright = _max(setup->span.right[0], - setup->span.right[1]); + minleft = MIN2(setup->span.left[0], setup->span.left[1]); + maxright = MAX2(setup->span.right[0], setup->span.right[1]); break; case 1: @@ -188,8 +190,10 @@ static void flush_spans( struct setup_stage *setup ) setup->span.right[1] = 0; } - +/** + * Do setup for point rasterization, then render the point. + */ static void setup_point( struct prim_stage *stage, struct prim_header *header ) @@ -197,6 +201,9 @@ setup_point( struct prim_stage *stage, } +/** + * Do setup for line rasterization, then render the line. + */ static void setup_line( struct prim_stage *stage, struct prim_header *header ) @@ -204,10 +211,6 @@ setup_line( struct prim_stage *stage, } - - - - static GLboolean setup_sort_vertices( struct setup_stage *setup, const struct prim_header *prim ) { @@ -288,6 +291,11 @@ static GLboolean setup_sort_vertices( struct setup_stage *setup, setup->oneoverarea = 1.0 / area; } + /* XXX need to know if this is a front or back-facing triangle: + * - the GLSL gl_FrontFacing fragment attribute (bool) + * - two-sided stencil test + */ + setup->quad.facing = 0; _mesa_printf("%s one-over-area %f\n", __FUNCTION__, setup->oneoverarea ); @@ -296,6 +304,9 @@ static GLboolean setup_sort_vertices( struct setup_stage *setup, } +/** + * Compute a0 for a constant-valued coefficient (GL_FLAT shading). + */ static void const_coeff( struct setup_stage *setup, GLuint slot, GLuint i ) @@ -309,6 +320,9 @@ static void const_coeff( struct setup_stage *setup, } +/** + * Compute a0, dadx and dady for a linearly interpolated coefficient. + */ static void linear_coeff( struct setup_stage *setup, GLuint slot, GLuint i) @@ -345,6 +359,9 @@ static void linear_coeff( struct setup_stage *setup, } +/** + * Compute a0, dadx and dady for a perspective-corrected interpolant. + */ static void persp_coeff( struct setup_stage *setup, GLuint slot, GLuint i ) @@ -430,10 +447,10 @@ static void setup_edges( struct setup_stage *setup ) } - - - - +/** + * Render the upper or lower half of a triangle. + * Scissoring is applied here too. + */ static void subtriangle( struct setup_stage *setup, struct edge *eleft, struct edge *eright, @@ -511,6 +528,9 @@ static void subtriangle( struct setup_stage *setup, } +/** + * Do setup for triangle rasterization, then render the triangle. + */ static void setup_tri( struct prim_stage *stage, struct prim_header *prim ) { diff --git a/src/mesa/softpipe/generic/g_tile_fs.c b/src/mesa/softpipe/generic/g_tile_fs.c index 35e1ab63dea..8473a9b5f19 100644 --- a/src/mesa/softpipe/generic/g_tile_fs.c +++ b/src/mesa/softpipe/generic/g_tile_fs.c @@ -44,6 +44,9 @@ struct exec_machine { }; +/** + * Compute quad's attributes values, as constants (GL_FLAT shading). + */ static void INLINE cinterp( struct exec_machine *exec, GLuint attrib, GLuint i ) @@ -56,7 +59,10 @@ static void INLINE cinterp( struct exec_machine *exec, } -/* Push into the fp: +/** + * Compute quad's attribute values by linear interpolation. + * + * Push into the fp: * * INPUT[attr] = MAD COEF_A0[attr], COEF_DADX[attr], INPUT_WPOS.xxxx * INPUT[attr] = MAD INPUT[attr], COEF_DADY[attr], INPUT_WPOS.yyyy @@ -68,14 +74,20 @@ static INLINE void linterp( struct exec_machine *exec, GLuint j; for (j = 0; j < QUAD_SIZE; j++) { + const GLfloat x = exec->attr[FRAG_ATTRIB_WPOS][0][j]; + const GLfloat y = exec->attr[FRAG_ATTRIB_WPOS][1][j]; exec->attr[attrib][i][j] = (exec->coef[attrib].a0[i] + - exec->coef[attrib].dadx[i] * exec->attr[0][0][j] + - exec->coef[attrib].dady[i] * exec->attr[0][1][j]); + exec->coef[attrib].dadx[i] * x + + exec->coef[attrib].dady[i] * y); } } -/* Push into the fp: +/** + * Compute quad's attribute values by linear interpolation with + * perspective correction. + * + * Push into the fp: * * INPUT[attr] = MAD COEF_A0[attr], COEF_DADX[attr], INPUT_WPOS.xxxx * INPUT[attr] = MAD INPUT[attr], COEF_DADY[attr], INPUT_WPOS.yyyy @@ -90,10 +102,12 @@ static INLINE void pinterp( struct exec_machine *exec, GLuint j; for (j = 0; j < QUAD_SIZE; j++) { + const GLfloat x = exec->attr[FRAG_ATTRIB_WPOS][0][j]; + const GLfloat y = exec->attr[FRAG_ATTRIB_WPOS][1][j]; + const GLfloat invW = exec->attr[FRAG_ATTRIB_WPOS][3][j]; exec->attr[attrib][i][j] = ((exec->coef[attrib].a0[i] + - exec->coef[attrib].dadx[i] * exec->attr[0][0][j] + - exec->coef[attrib].dady[i] * exec->attr[0][1][j]) * - exec->attr[0][3][j]); + exec->coef[attrib].dadx[i] * x + + exec->coef[attrib].dady[i] * y) * invW); } } @@ -125,6 +139,7 @@ void quad_shade( struct generic_context *generic, exec.attr[FRAG_ATTRIB_WPOS][1][3] = fy + 1.0; /* Z and W are done by linear interpolation: + * XXX we'll probably have to use integers for Z */ if (generic->need_z) { linterp(&exec, 0, 2); |