00001 00006 #include "sp_context.h" 00007 #include "sp_headers.h" 00008 #include "sp_quad.h" 00009 #include "pipe/p_defines.h" 00010 #include "util/u_memory.h" 00011 00012 00016 static void 00017 stipple_quad(struct quad_stage *qs, struct quad_header *quad) 00018 { 00019 static const uint bit31 = 1 << 31; 00020 static const uint bit30 = 1 << 30; 00021 00022 if (quad->input.prim == PRIM_TRI) { 00023 struct softpipe_context *softpipe = qs->softpipe; 00024 /* need to invert Y to index into OpenGL's stipple pattern */ 00025 int y0, y1; 00026 uint stipple0, stipple1; 00027 if (softpipe->rasterizer->origin_lower_left) { 00028 y0 = softpipe->framebuffer.height - 1 - quad->input.y0; 00029 y1 = y0 - 1; 00030 } 00031 else { 00032 y0 = quad->input.y0; 00033 y1 = y0 + 1; 00034 } 00035 stipple0 = softpipe->poly_stipple.stipple[y0 % 32]; 00036 stipple1 = softpipe->poly_stipple.stipple[y1 % 32]; 00037 00038 #if 1 00039 { 00040 const int col0 = quad->input.x0 % 32; 00041 if ((stipple0 & (bit31 >> col0)) == 0) 00042 quad->inout.mask &= ~MASK_TOP_LEFT; 00043 00044 if ((stipple0 & (bit30 >> col0)) == 0) 00045 quad->inout.mask &= ~MASK_TOP_RIGHT; 00046 00047 if ((stipple1 & (bit31 >> col0)) == 0) 00048 quad->inout.mask &= ~MASK_BOTTOM_LEFT; 00049 00050 if ((stipple1 & (bit30 >> col0)) == 0) 00051 quad->inout.mask &= ~MASK_BOTTOM_RIGHT; 00052 } 00053 #else 00054 /* We'd like to use this code, but we'd need to redefine 00055 * MASK_TOP_LEFT to be (1 << 1) and MASK_TOP_RIGHT to be (1 << 0), 00056 * and similarly for the BOTTOM bits. But that may have undesirable 00057 * side effects elsewhere. 00058 */ 00059 const int col0 = 30 - (quad->input.x0 % 32); 00060 quad->inout.mask &= (((stipple0 >> col0) & 0x3) | 00061 (((stipple1 >> col0) & 0x3) << 2)); 00062 #endif 00063 if (!quad->inout.mask) 00064 return; 00065 } 00066 00067 qs->next->run(qs->next, quad); 00068 } 00069 00070 00071 static void stipple_begin(struct quad_stage *qs) 00072 { 00073 qs->next->begin(qs->next); 00074 } 00075 00076 00077 static void stipple_destroy(struct quad_stage *qs) 00078 { 00079 FREE( qs ); 00080 } 00081 00082 00083 struct quad_stage * 00084 sp_quad_polygon_stipple_stage( struct softpipe_context *softpipe ) 00085 { 00086 struct quad_stage *stage = CALLOC_STRUCT(quad_stage); 00087 00088 stage->softpipe = softpipe; 00089 stage->begin = stipple_begin; 00090 stage->run = stipple_quad; 00091 stage->destroy = stipple_destroy; 00092 00093 return stage; 00094 }