X-Git-Url: https://git.wh0rd.org/?p=ICEs.git;a=blobdiff_plain;f=394889%2Fs_triangle.i.8;fp=394889%2Fs_triangle.i.8;h=4febcad2f676e7ab365c85eb90394a1a19b4d6b0;hp=0000000000000000000000000000000000000000;hb=bd3239d2bbe0de3a200b266503e3330b1e391489;hpb=dbff64cb4b7530861c2309c794efdd4e0cf47a23 diff --git a/394889/s_triangle.i.8 b/394889/s_triangle.i.8 new file mode 100644 index 0000000..4febcad --- /dev/null +++ b/394889/s_triangle.i.8 @@ -0,0 +1,323 @@ +typedef union { + float f; + int i; +} fi_type; +static __inline__ +int IS_INF_OR_NAN(float x) +{ + fi_type tmp; + tmp.f = x; + return !(int)((unsigned int)((tmp.i & 0x7fffffff) - 0x7f800000) >> 31); +} + +typedef enum { + MESA_FORMAT_RGBA8888, MESA_FORMAT_RGB888, +} gl_format; +typedef enum { + FRAG_ATTRIB_WPOS = 0, FRAG_ATTRIB_COL0 = 1, FRAG_ATTRIB_COL1 = + 2, FRAG_ATTRIB_FOGC = 3, FRAG_ATTRIB_TEX0 = 4, FRAG_ATTRIB_TEX1 = + 5, FRAG_ATTRIB_TEX2 = 6, FRAG_ATTRIB_TEX3 = 7, FRAG_ATTRIB_TEX4 = + 8, FRAG_ATTRIB_TEX5 = 9, FRAG_ATTRIB_TEX6 = 10, FRAG_ATTRIB_TEX7 = + 11, FRAG_ATTRIB_FACE = 12, FRAG_ATTRIB_PNTC = 13, FRAG_ATTRIB_VAR0 = + 14, FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + 16) +} gl_frag_result; +struct gl_config { + int depthBits; +}; +struct gl_lightmodel { + unsigned int ColorControl; +}; +struct gl_depthbuffer_attrib { + unsigned int Func; + unsigned char Mask; +}; +struct gl_hint_attrib { + unsigned int PerspectiveCorrection; +}; +struct gl_light_attrib { + struct gl_lightmodel Model; +}; +struct gl_polygon_attrib { + unsigned char StippleFlag; +}; +typedef enum { + TEXTURE_BUFFER_INDEX, TEXTURE_2D_ARRAY_INDEX, TEXTURE_1D_ARRAY_INDEX, + TEXTURE_CUBE_INDEX, TEXTURE_3D_INDEX, TEXTURE_RECT_INDEX, + TEXTURE_2D_INDEX, TEXTURE_1D_INDEX, NUM_TEXTURE_TARGETS +} gl_texture_index; +struct gl_texture_image { + unsigned int Border; + unsigned int Width; + unsigned int Height; + unsigned int WidthLog2; + unsigned char _IsPowerOfTwo; + unsigned int RowStride; + void *Data; +}; +typedef enum { + MAX_FACES = 6 +} gl_face_index; +struct gl_sampler_object { + unsigned int WrapS; + unsigned int WrapT; +}; +struct gl_texture_object { + struct gl_sampler_object Sampler; + int BaseLevel; + unsigned int _Swizzle; + struct gl_texture_image *Image[MAX_FACES][15]; +}; +struct gl_texture_unit { + unsigned int _ReallyEnabled; + unsigned int EnvMode; + struct gl_texture_object *CurrentTex[NUM_TEXTURE_TARGETS]; +}; +struct gl_texture_attrib { + struct gl_texture_unit Unit[(16 + 16)]; + unsigned int _EnabledUnits; + unsigned int _EnabledCoordUnits; +}; +struct gl_fragment_program_state { + struct gl_fragment_program *_Current; +}; +struct gl_ati_fragment_shader_state { + unsigned char _Enabled; +}; +struct gl_renderbuffer { + void (*PutRowRGB) (struct gl_context * ctx, struct gl_renderbuffer * rb, + unsigned int count, int x, int y, const void *values); +}; +struct gl_framebuffer { + struct gl_config Visual; + struct gl_renderbuffer *_ColorDrawBuffers[8]; +}; +struct gl_context { + struct gl_framebuffer *DrawBuffer; + struct gl_depthbuffer_attrib Depth; + struct gl_hint_attrib Hint; + struct gl_light_attrib Light; + struct gl_polygon_attrib Polygon; + struct gl_texture_attrib Texture; + struct gl_fragment_program_state FragmentProgram; + struct gl_ati_fragment_shader_state ATIFragmentShader; + unsigned int RenderMode; +}; +typedef struct { + float attrib[FRAG_ATTRIB_MAX][4]; +} SWvertex; +typedef struct sw_span { + int x, y; + unsigned int end; + float attrStepX[FRAG_ATTRIB_MAX][4]; + int intTex[2], intTexStep[2]; +} SWspan; +typedef void (*swrast_tri_func) (struct gl_context * ctx, const SWvertex *, + const SWvertex *, const SWvertex *); +typedef struct { + unsigned int _RasterMask; + unsigned char _FogEnabled; + swrast_tri_func Triangle; +} SWcontext; +static void simple_textured_triangle(struct gl_context *ctx, + const SWvertex * v0, const SWvertex * v1, + const SWvertex * v2) +{ + typedef struct { + float dx; + float dy; + int fsx; + int fx0; + int lines; + } EdgeT; + EdgeT eMaj; + EdgeT eTop; + EdgeT eBot; + float oneOverArea; + const SWvertex *vMin; + const SWvertex *vMid; + const SWvertex *vMax; + const int snapMask = ~(((1 << 11) / (1 << 4)) - 1); + int vMin_fx; + int vMin_fy; + int vMid_fx; + int vMid_fy; + int vMax_fx; + int vMax_fy; + SWspan span; + const int fy0 = + (((int) + ((((v0->attrib[FRAG_ATTRIB_WPOS][1] - + 0.5F) * ((float)(1 << 11))) >= + 0.0F) ? (((v0->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) * + ((float)(1 << 11))) + + 0.5F) + : (((v0->attrib[FRAG_ATTRIB_WPOS][1] - + 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask; + const int fy1 = + (((int) + ((((v1->attrib[FRAG_ATTRIB_WPOS][1] - + 0.5F) * ((float)(1 << 11))) >= + 0.0F) ? (((v1->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) * + ((float)(1 << 11))) + + 0.5F) + : (((v1->attrib[FRAG_ATTRIB_WPOS][1] - + 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask; + const int fy2 = + (((int) + ((((v2->attrib[FRAG_ATTRIB_WPOS][1] - + 0.5F) * ((float)(1 << 11))) >= + 0.0F) ? (((v2->attrib[FRAG_ATTRIB_WPOS][1] - 0.5F) * + ((float)(1 << 11))) + + 0.5F) + : (((v2->attrib[FRAG_ATTRIB_WPOS][1] - + 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask; + if (fy0 <= fy1) { + if (fy1 <= fy2) { + vMin = v0; + vMax = v1; + vMin_fy = fy0; + } + } + vMin_fx = + (((int) + ((((vMin->attrib[FRAG_ATTRIB_WPOS][0] + + 0.5F) * ((float)(1 << 11))) >= + 0.0F) ? (((vMin->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) * + ((float)(1 << 11))) + + 0.5F) + : (((vMin->attrib[FRAG_ATTRIB_WPOS][0] + + 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask; + vMid_fx = + (((int) + ((((vMid->attrib[FRAG_ATTRIB_WPOS][0] + + 0.5F) * ((float)(1 << 11))) >= + 0.0F) ? (((vMid->attrib[FRAG_ATTRIB_WPOS][0] + 0.5F) * + ((float)(1 << 11))) + + 0.5F) + : (((vMid->attrib[FRAG_ATTRIB_WPOS][0] + + 0.5F) * ((float)(1 << 11))) - 0.5F)))) & snapMask; + eMaj.dx = ((vMax_fx - vMin_fx) * (1.0F / ((float)(1 << 11)))); + eMaj.dy = ((vMax_fy - vMin_fy) * (1.0F / ((float)(1 << 11)))); + eTop.dx = ((vMax_fx - vMid_fx) * (1.0F / ((float)(1 << 11)))); + eBot.dy = ((vMid_fy - vMin_fy) * (1.0F / ((float)(1 << 11)))); + const float area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy; + if (IS_INF_OR_NAN(area) || area == 0.0F) + return; + oneOverArea = 1.0F / area; + if (eBot.lines > 0) { + eBot.fx0 = vMin_fx; + } + int scan_from_left_to_right; + struct gl_renderbuffer *rb = + ctx->DrawBuffer->_ColorDrawBuffers[0]; + const struct gl_texture_object *obj = + ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; + const struct gl_texture_image *texImg = + obj->Image[0][obj->BaseLevel]; + const float twidth = (float) texImg->Width; + const int twidth_log2 = texImg->WidthLog2; + const unsigned char *texture = (const unsigned char *)texImg->Data; + const int smask = texImg->Width - 1; + const int tmask = texImg->Height - 1; + if (!rb || !texture) { + return; + } + float eMaj_ds = + (vMax->attrib[FRAG_ATTRIB_TEX0][0] - + vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth; + float eBot_ds = + (vMid->attrib[FRAG_ATTRIB_TEX0][0] - + vMin->attrib[FRAG_ATTRIB_TEX0][0]) * twidth; + span.attrStepX[FRAG_ATTRIB_TEX0][0] = + oneOverArea * (eMaj_ds * eBot.dy - + eMaj.dy * eBot_ds); + span.intTexStep[0] = + (((int) + ((((span.attrStepX[FRAG_ATTRIB_TEX0][0]) * + ((float)(1 << 11))) >= + 0.0F) ? (((span.attrStepX[FRAG_ATTRIB_TEX0][0]) + * ((float)(1 << 11))) + + 0.5F) + : (((span.attrStepX[FRAG_ATTRIB_TEX0][0]) * + ((float)(1 << 11))) - 0.5F)))); + int subTriangle; + int fxLeftEdge = 0; + int fxRightEdge = 0; + int sLeft = 0; + for (subTriangle = 0; subTriangle <= 1; subTriangle++) { + EdgeT *eRight; + int lines; + if (subTriangle == 0) { + if (scan_from_left_to_right) { + eRight = &eBot; + lines = eRight->lines; + } else { + eRight = &eMaj; + } + } else { + if (scan_from_left_to_right) { + eRight = &eTop; + } + fxRightEdge = eRight->fsx - 1; + } + while (lines > 0) { + const int right= fxRightEdge >> 11; + span.x = fxLeftEdge >> 11; + if (right <= span.x) + span.end = 0; + else + span.end = right - span.x; + span.intTex[0] = sLeft; + if (span.end > 0 && span.y >= 0) { + unsigned int i; + unsigned char rgb[16384][3]; + for (i = 0; + i < span.end; + i++) { + int s = + ((span. + intTex[0]) + >> 11) & + smask; + int t = + ((span. + intTex[1]) + >> 11) & + tmask; + int pos = + (t << + twidth_log2) + + s; + rgb[i][0] = + texture[pos + + + 2]; + span. + intTex[0] += + span. + intTexStep + [0]; + } + rb->PutRowRGB(ctx, rb, + span.end, + span.x, + span.y, + rgb); + } + } + } +} + +void _swrast_choose_triangle(struct gl_context *ctx) +{ + SWcontext *swrast = SWRAST_CONTEXT(ctx); + const struct gl_texture_object *texObj2D; + const struct gl_texture_image *texImg; + unsigned int minFilter; + unsigned int magFilter; + unsigned int envMode; + gl_format format; + swrast->Triangle = + simple_textured_triangle; + +}