Пример #1
0
/*!
*/
void CTRTextureDetailMap2::scanline_bilinear ()
{
	tVideoSample *dst;

#ifdef USE_ZBUFFER
	fp24 *z;
#endif

	s32 xStart;
	s32 xEnd;
	s32 dx;


#ifdef SUBTEXEL
	f32 subPixel;
#endif

#ifdef IPOL_Z
	f32 slopeZ;
#endif
#ifdef IPOL_W
	fp24 slopeW;
#endif
#ifdef IPOL_C0
	sVec4 slopeC;
#endif
#ifdef IPOL_T0
	sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];
#endif

	// apply top-left fill-convention, left
	xStart = core::ceil32( line.x[0] );
	xEnd = core::ceil32( line.x[1] ) - 1;

	dx = xEnd - xStart;

	if ( dx < 0 )
		return;

	// slopes
	const f32 invDeltaX = core::reciprocal_approxim ( line.x[1] - line.x[0] );

#ifdef IPOL_Z
	slopeZ = (line.z[1] - line.z[0]) * invDeltaX;
#endif
#ifdef IPOL_W
	slopeW = (line.w[1] - line.w[0]) * invDeltaX;
#endif
#ifdef IPOL_C0
	slopeC = (line.c[0][1] - line.c[0][0]) * invDeltaX;
#endif
#ifdef IPOL_T0
	slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;
#endif
#ifdef IPOL_T1
	slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;
#endif

#ifdef SUBTEXEL
	subPixel = ( (f32) xStart ) - line.x[0];
#ifdef IPOL_Z
	line.z[0] += slopeZ * subPixel;
#endif
#ifdef IPOL_W
	line.w[0] += slopeW * subPixel;
#endif
#ifdef IPOL_C0
	line.c[0][0] += slopeC * subPixel;
#endif
#ifdef IPOL_T0
	line.t[0][0] += slopeT[0] * subPixel;
#endif
#ifdef IPOL_T1
	line.t[1][0] += slopeT[1] * subPixel;
#endif
#endif

	dst = lockedSurface + ( line.y * RenderTarget->getDimension().Width ) + xStart;

#ifdef USE_ZBUFFER
	z = lockedDepthBuffer + ( line.y * RenderTarget->getDimension().Width ) + xStart;
#endif


#ifdef INVERSE_W
	f32 inversew;
#endif

	tFixPoint tx0, tx1;
	tFixPoint ty0, ty1;

	tFixPoint r0, g0, b0;
	tFixPoint r1, g1, b1;
	tFixPoint r2, g2, b2;


	for ( s32 i = 0; i <= dx; ++i )
	{
#ifdef CMP_Z
		if ( line.z[0] < z[i] )
#endif
#ifdef CMP_W
		if ( line.w[0] >= z[i] )
#endif

		{
#ifdef INVERSE_W
			inversew = fix_inverse32 ( line.w[0] );

			tx0 = f32_to_fixPoint ( line.t[0][0].x,inversew);
			ty0 = f32_to_fixPoint ( line.t[0][0].y,inversew);
			tx1 = f32_to_fixPoint ( line.t[1][0].x,inversew);
			ty1 = f32_to_fixPoint ( line.t[1][0].y,inversew);

#else
			tx0 = f32_to_fixPoint ( line.t[0][0].x );
			ty0 = f32_to_fixPoint ( line.t[0][0].y );
			tx1 = f32_to_fixPoint ( line.t[1][0].x );
			ty1 = f32_to_fixPoint ( line.t[1][0].y );
#endif
			getSample_texture ( r0, g0, b0, &IT[0], tx0,ty0 );
			getSample_texture ( r1, g1, b1, &IT[1], tx1,ty1 );

#define FIX_POINT_HALF_COLOR ( (tFixPoint) ( ((f32) COLOR_MAX / 2.f * FIX_POINT_F32_MUL ) ) )

			// bias half color
			r1 += -FIX_POINT_HALF_COLOR;
			g1 += -FIX_POINT_HALF_COLOR;
			b1 += -FIX_POINT_HALF_COLOR;

			r2 = clampfix_mincolor ( clampfix_maxcolor ( r0 + r1 ) );
			g2 = clampfix_mincolor ( clampfix_maxcolor ( g0 + g1 ) );
			b2 = clampfix_mincolor ( clampfix_maxcolor ( b0 + b1 ) );

			dst[i] = fix_to_color ( r2, g2, b2 );

#ifdef WRITE_Z
			z[i] = line.z[0];
#endif
#ifdef WRITE_W
			z[i] = line.w[0];
#endif

		}

#ifdef IPOL_Z
		line.z[0] += slopeZ;
#endif
#ifdef IPOL_W
		line.w[0] += slopeW;
#endif
#ifdef IPOL_C0
		line.c[0][0] += slopeC;
#endif
#ifdef IPOL_T0
		line.t[0][0] += slopeT[0];
#endif
#ifdef IPOL_T1
		line.t[1][0] += slopeT[1];
#endif
	}

}
/*!
*/
void CTRGTextureLightMap2_M4::scanline_bilinear ()
{
	tVideoSample *dst;

#ifdef USE_ZBUFFER
	fp24 *z;
#endif

	s32 xStart;
	s32 xEnd;
	s32 dx;


#ifdef SUBTEXEL
	f32 subPixel;
#endif

#ifdef IPOL_Z
	f32 slopeZ;
#endif
#ifdef IPOL_W
	fp24 slopeW;
#endif
#ifdef IPOL_C0
	sVec4 slopeC;
#endif
#ifdef IPOL_T0
	sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];
#endif

	// apply top-left fill-convention, left
	xStart = core::ceil32( line.x[0] );
	xEnd = core::ceil32( line.x[1] ) - 1;

	dx = xEnd - xStart;

	if ( dx < 0 )
		return;

	// slopes
	const f32 invDeltaX = core::reciprocal_approxim ( line.x[1] - line.x[0] );

#ifdef IPOL_Z
	slopeZ = (line.z[1] - line.z[0]) * invDeltaX;
#endif
#ifdef IPOL_W
	slopeW = (line.w[1] - line.w[0]) * invDeltaX;
#endif
#ifdef IPOL_C0
	slopeC = (line.c[0][1] - line.c[0][0]) * invDeltaX;
#endif
#ifdef IPOL_T0
	slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;
#endif
#ifdef IPOL_T1
	slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;
#endif

#ifdef SUBTEXEL
	subPixel = ( (f32) xStart ) - line.x[0];
#ifdef IPOL_Z
	line.z[0] += slopeZ * subPixel;
#endif
#ifdef IPOL_W
	line.w[0] += slopeW * subPixel;
#endif
#ifdef IPOL_C0
	line.c[0][0] += slopeC * subPixel;
#endif
#ifdef IPOL_T0
	line.t[0][0] += slopeT[0] * subPixel;
#endif
#ifdef IPOL_T1
	line.t[1][0] += slopeT[1] * subPixel;
#endif
#endif

	dst = (tVideoSample*)RenderTarget->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;

#ifdef USE_ZBUFFER
	z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
#endif


#ifdef INVERSE_W
	f32 inversew;
#endif

	tFixPoint tx0, tx1;
	tFixPoint ty0, ty1;

	tFixPoint r0, g0, b0;
	tFixPoint r1, g1, b1;
	tFixPoint r2, g2, b2;

#ifdef IPOL_C0
	tFixPoint r3, g3, b3;
#endif

	for ( s32 i = 0; i <= dx; i++ )
	{
#ifdef CMP_Z
		if ( line.z[0] < z[i] )
#endif
#ifdef CMP_W
		if ( line.w[0] >= z[i] )
#endif
		{
#ifdef INVERSE_W
			inversew = fix_inverse32 ( line.w[0] );

			tx0 = tofix ( line.t[0][0].x,inversew);
			ty0 = tofix ( line.t[0][0].y,inversew);
			tx1 = tofix ( line.t[1][0].x,inversew);
			ty1 = tofix ( line.t[1][0].y,inversew);

#ifdef IPOL_C0
			r3 = tofix ( line.c[0][0].y ,inversew );
			g3 = tofix ( line.c[0][0].z ,inversew );
			b3 = tofix ( line.c[0][0].w ,inversew );
#endif

#else
			tx0 = tofix ( line.t[0][0].x );
			ty0 = tofix ( line.t[0][0].y );
			tx1 = tofix ( line.t[1][0].x );
			ty1 = tofix ( line.t[1][0].y );

#ifdef IPOL_C0
			r3 = tofix ( line.c[0][0].y );
			g3 = tofix ( line.c[0][0].z );
			b3 = tofix ( line.c[0][0].w );
#endif

#endif
			getSample_texture ( r0, g0, b0, &IT[0], tx0, ty0 );
			getSample_texture ( r1, g1, b1, &IT[1], tx1, ty1 );

#ifdef IPOL_C0
			r2 = imulFix ( r0, r3 );
			g2 = imulFix ( g0, g3 );
			b2 = imulFix ( b0, b3 );

			r2 = clampfix_maxcolor ( imulFix_tex4 ( r2, r1 ) );
			g2 = clampfix_maxcolor ( imulFix_tex4 ( g2, g1 ) );
			b2 = clampfix_maxcolor ( imulFix_tex4 ( b2, b1 ) );
/*
			r2 = r3 << 8;
			g2 = g3 << 8;
			b2 = b3 << 8;
*/
#else
			r2 = clampfix_maxcolor ( imulFix_tex4 ( r0, r1 ) );
			g2 = clampfix_maxcolor ( imulFix_tex4 ( g0, g1 ) );
			b2 = clampfix_maxcolor ( imulFix_tex4 ( b0, b1 ) );
#endif


			dst[i] = fix_to_color ( r2, g2, b2 );

#ifdef WRITE_Z
			z[i] = line.z[0];
#endif
#ifdef WRITE_W
			z[i] = line.w[0];
#endif
		}

#ifdef IPOL_Z
		line.z[0] += slopeZ;
#endif
#ifdef IPOL_W
		line.w[0] += slopeW;
#endif
#ifdef IPOL_C0
		line.c[0][0] += slopeC;
#endif
#ifdef IPOL_T0
		line.t[0][0] += slopeT[0];
#endif
#ifdef IPOL_T1
		line.t[1][0] += slopeT[1];
#endif
	}

}
/*!
*/
REALINLINE void CTRTextureLightMap2_Add::scanline_bilinear ()
{
	tVideoSample *dst;

#ifdef USE_ZBUFFER
	fp24 *z;
#endif

	s32 xStart;
	s32 xEnd;
	s32 dx;


#ifdef SUBTEXEL
	f32 subPixel;
#endif

#ifdef IPOL_Z
	f32 slopeZ;
#endif
#ifdef IPOL_W
	fp24 slopeW;
#endif
#ifdef IPOL_C0
	sVec4 slopeC;
#endif
#ifdef IPOL_T0
	sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];
#endif

	// apply top-left fill-convention, left
	xStart = core::ceil32( line.x[0] );
	xEnd = core::ceil32( line.x[1] ) - 1;

	dx = xEnd - xStart;

	if ( dx < 0 )
		return;

	// slopes
	const f32 invDeltaX = core::reciprocal_approxim ( line.x[1] - line.x[0] );

#ifdef IPOL_Z
	slopeZ = (line.z[1] - line.z[0]) * invDeltaX;
#endif
#ifdef IPOL_W
	slopeW = (line.w[1] - line.w[0]) * invDeltaX;
#endif
#ifdef IPOL_C0
	slopeC = (line.c[1] - line.c[0]) * invDeltaX;
#endif
#ifdef IPOL_T0
	slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;
#endif
#ifdef IPOL_T1
	slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;
#endif

#ifdef SUBTEXEL
	subPixel = ( (f32) xStart ) - line.x[0];
#ifdef IPOL_Z
	line.z[0] += slopeZ * subPixel;
#endif
#ifdef IPOL_W
	line.w[0] += slopeW * subPixel;
#endif
#ifdef IPOL_C0
	line.c[0] += slopeC * subPixel;
#endif
#ifdef IPOL_T0
	line.t[0][0] += slopeT[0] * subPixel;
#endif
#ifdef IPOL_T1
	line.t[1][0] += slopeT[1] * subPixel;
#endif
#endif

	dst = (tVideoSample*)RenderTarget->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;

#ifdef USE_ZBUFFER
	z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
#endif




#ifdef BURNINGVIDEO_RENDERER_FAST
	u32 dIndex = ( line.y & 3 ) << 2;


#else
	// 
	tFixPoint r0, g0, b0;
	tFixPoint r1, g1, b1;
#endif


	for ( s32 i = 0; i <= dx; i++ )
	{
#ifdef CMP_Z
		if ( line.z[0] < z[i] )
#endif
#ifdef CMP_W
		if ( line.w[0] >= z[i] )
#endif
		{

#ifdef WRITE_Z
			z[i] = line.z[0];
#endif
#ifdef WRITE_W
			z[i] = line.w[0];
#endif

#ifdef BURNINGVIDEO_RENDERER_FAST

#ifdef INVERSE_W

			const f32 inversew = fix_inverse32 ( line.w[0] );

			const tFixPointu d = dithermask [ dIndex | ( i ) & 3 ];

			dst[i] = PixelAdd32 (
					getTexel_plain ( &IT[0],	d + tofix ( line.t[0][0].x,inversew), 
												d + tofix ( line.t[0][0].y,inversew) ),
					getTexel_plain ( &IT[1],	d + tofix ( line.t[1][0].x,inversew), 
												d + tofix ( line.t[1][0].y,inversew) )
							);
#else
			const tFixPointu d = dithermask [ dIndex | ( i ) & 3 ];

			dst[i] = PixelAdd32 (
					getTexel_plain ( &IT[0],	d + tofix ( line.t[0][0].x), 
												d + tofix ( line.t[0][0].y) ),
					getTexel_plain ( &IT[1],	d + tofix ( line.t[1][0].x), 
												d + tofix ( line.t[1][0].y) )
							);

#endif

#else
			const f32 inversew = fix_inverse32 ( line.w[0] );

			getSample_texture ( r0, g0, b0, &IT[0], tofix ( line.t[0][0].x,inversew), tofix ( line.t[0][0].y,inversew) );
			getSample_texture ( r1, g1, b1, &IT[1], tofix ( line.t[0][1].x,inversew), tofix ( line.t[0][1].y,inversew) );

			dst[i] = fix_to_color ( clampfix_maxcolor ( r0 + r1 ),
									clampfix_maxcolor ( g0 + g1 ),
									clampfix_maxcolor ( b0 + b1 )
								);
#endif

		}

#ifdef IPOL_Z
		line.z[0] += slopeZ;
#endif
#ifdef IPOL_W
		line.w[0] += slopeW;
#endif
#ifdef IPOL_C0
		line.c[0] += slopeC;
#endif
#ifdef IPOL_T0
		line.t[0][0] += slopeT[0];
#endif
#ifdef IPOL_T1
		line.t[1][0] += slopeT[1];
#endif
	}

}
Пример #4
0
/*!
*/
void CTRTextureGouraud2::scanline_bilinear ()
{
	tVideoSample *dst;

#ifdef USE_ZBUFFER
	fp24 *z;
#endif

	s32 xStart;
	s32 xEnd;
	s32 dx;


#ifdef SUBTEXEL
	f32 subPixel;
#endif

#ifdef IPOL_Z
	f32 slopeZ;
#endif
#ifdef IPOL_W
	fp24 slopeW;
#endif
#ifdef IPOL_C0
	sVec4 slopeC;
#endif
#ifdef IPOL_T0
	sVec2 slopeT0;
#endif
#ifdef IPOL_T1
	sVec2 slopeT1;
#endif

	// apply top-left fill-convention, left
	xStart = core::ceil32( line.x[0] );
	xEnd = core::ceil32( line.x[1] ) - 1;

	dx = xEnd - xStart;

	if ( dx < 0 )
		return;

	// slopes
	const f32 invDeltaX = core::reciprocal_approxim ( line.x[1] - line.x[0] );

#ifdef IPOL_Z
	slopeZ = (line.z[1] - line.z[0]) * invDeltaX;
#endif
#ifdef IPOL_W
	slopeW = (line.w[1] - line.w[0]) * invDeltaX;
#endif
#ifdef IPOL_C0
	slopeC = (line.c[1] - line.c[0]) * invDeltaX;
#endif
#ifdef IPOL_T0
	slopeT0 = (line.t0[1] - line.t0[0]) * invDeltaX;
#endif
#ifdef IPOL_T1
	slopeT1 = (line.t1[1] - line.t1[0]) * invDeltaX;
#endif

#ifdef SUBTEXEL
	subPixel = ( (f32) xStart ) - line.x[0];
#ifdef IPOL_Z
	line.z[0] += slopeZ * subPixel;
#endif
#ifdef IPOL_W
	line.w[0] += slopeW * subPixel;
#endif
#ifdef IPOL_C0
	line.c[0] += slopeC * subPixel;
#endif
#ifdef IPOL_T0
	line.t0[0] += slopeT0 * subPixel;
#endif
#ifdef IPOL_T1
	line.t1[0] += slopeT1 * subPixel;
#endif
#endif

	dst = lockedSurface + ( line.y * SurfaceWidth ) + xStart;

#ifdef USE_ZBUFFER
	z = lockedZBuffer + ( line.y * SurfaceWidth ) + xStart;
#endif


#ifdef INVERSE_W
	f32 inversew;
#endif

	tFixPoint tx0;
	tFixPoint ty0;

#ifdef IPOL_C0
	tFixPoint r0, g0, b0;
	tFixPoint r1, g1, b1;
#endif

#ifdef BURNINGVIDEO_RENDERER_FAST
	u32 dIndex = ( line.y & 3 ) << 2;
#endif

	for ( s32 i = 0; i <= dx; ++i )
	{
#ifdef CMP_Z
		if ( line.z[0] < z[i] )
#endif
#ifdef CMP_W
		if ( line.w[0] >= z[i] )
#endif
		{
#ifdef WRITE_Z
			z[i] = line.z[0];
#endif
#ifdef WRITE_W
			z[i] = line.w[0];
#endif


#ifdef INVERSE_W
			inversew = fix_inverse32 ( line.w[0] );
			tx0 = f32_to_fixPoint ( line.t0[0].x, inversew);
			ty0 = f32_to_fixPoint ( line.t0[0].y, inversew);

#ifdef IPOL_C0
			r1 = f32_to_fixPoint ( line.c[0].y ,inversew );
			g1 = f32_to_fixPoint ( line.c[0].z ,inversew );
			b1 = f32_to_fixPoint ( line.c[0].w ,inversew );
#endif

#else
			tx0 = f32_to_fixPoint ( line.t0[0].x );
			ty0 = f32_to_fixPoint ( line.t0[0].y );
#ifdef IPOL_C0
			getTexel_plain2 ( r1, g1, b1, line.c[0] );
#endif
#endif

#ifdef IPOL_C0
			getSample_texture ( r0, g0, b0, &IT[0], tx0,ty0 );

			dst[i] = fix_to_color ( imulFix ( r0, r1 ),
									imulFix ( g0, g1 ),
									imulFix ( b0, b1 )
								);
#else

#ifdef BURNINGVIDEO_RENDERER_FAST
			const tFixPointu d = dithermask [ dIndex | ( i ) & 3 ];
			dst[i] = getTexel_plain ( &IT[0], d + tx0, d + ty0 );
#else
			getSample_texture ( r0, g0, b0, &IT[0], tx0,ty0 );
			dst[i] = fix_to_color ( r0, g0, b0 );
#endif

#endif

		}

#ifdef IPOL_Z
		line.z[0] += slopeZ;
#endif
#ifdef IPOL_W
		line.w[0] += slopeW;
#endif
#ifdef IPOL_C0
		line.c[0] += slopeC;
#endif
#ifdef IPOL_T0
		line.t0[0] += slopeT0;
#endif
#ifdef IPOL_T1
		line.t1[0] += slopeT1;
#endif
	}

}
/*!
*/
void CTRTextureVertexAlpha2::scanline_bilinear (  )
{
    tVideoSample *dst;

#ifdef USE_ZBUFFER
    fp24 *z;
#endif

    s32 xStart;
    s32 xEnd;
    s32 dx;


#ifdef SUBTEXEL
    f32 subPixel;
#endif

#ifdef IPOL_Z
    f32 slopeZ;
#endif
#ifdef IPOL_W
    fp24 slopeW;
#endif
#ifdef IPOL_C0
    sVec4 slopeC;
#endif
#ifdef IPOL_T0
    sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];
#endif

    // apply top-left fill-convention, left
    xStart = core::ceil32( line.x[0] );
    xEnd = core::ceil32( line.x[1] ) - 1;

    dx = xEnd - xStart;

    if ( dx < 0 )
        return;

    // slopes
    const f32 invDeltaX = core::reciprocal_approxim ( line.x[1] - line.x[0] );

#ifdef IPOL_Z
    slopeZ = (line.z[1] - line.z[0]) * invDeltaX;
#endif
#ifdef IPOL_W
    slopeW = (line.w[1] - line.w[0]) * invDeltaX;
#endif
#ifdef IPOL_C0
    slopeC = (line.c[0][1] - line.c[0][0]) * invDeltaX;
#endif
#ifdef IPOL_T0
    slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;
#endif
#ifdef IPOL_T1
    slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;
#endif

#ifdef SUBTEXEL
    subPixel = ( (f32) xStart ) - line.x[0];
#ifdef IPOL_Z
    line.z[0] += slopeZ * subPixel;
#endif
#ifdef IPOL_W
    line.w[0] += slopeW * subPixel;
#endif
#ifdef IPOL_C0
    line.c[0][0] += slopeC * subPixel;
#endif
#ifdef IPOL_T0
    line.t[0][0] += slopeT[0] * subPixel;
#endif
#ifdef IPOL_T1
    line.t[1][0] += slopeT[1] * subPixel;
#endif
#endif

    dst = (tVideoSample*)RenderTarget->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;

#ifdef USE_ZBUFFER
    z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
#endif


#ifdef INVERSE_W
    f32 inversew;
#endif

//#define __TEST_THIS

#ifdef __TEST_THIS

#else
    tFixPoint tx0;
    tFixPoint ty0;

    tFixPoint r0, g0, b0;
    tFixPoint r1, g1, b1;
    tFixPoint r2, g2, b2;
#endif


#ifdef IPOL_C0
    tFixPoint a3;
#endif


    for ( s32 i = 0; i <= dx; ++i )
    {
#ifdef CMP_Z
        if ( line.z[0] < z[i] )
#endif
#ifdef CMP_W
            if ( line.w[0] >= z[i] )
#endif

            {
#ifdef __TEST_THIS

                inversew = fix_inverse32 ( line.w[0] );

                dst[i] = PixelAdd32 (
                             dst[i],
                             getTexel_plain ( &IT[0],	tofix ( line.t[0][0].x,inversew),
                                              tofix ( line.t[0][0].y,inversew) )
                         );

#else

#ifdef INVERSE_W
                inversew = fix_inverse32 ( line.w[0] );

                tx0 = tofix ( line.t[0][0].x,inversew);
                ty0 = tofix ( line.t[0][0].y,inversew);

#ifdef IPOL_C0
                a3 = tofix ( line.c[0][0].y,inversew );
#endif

#else
                tx0 = tofix ( line.t[0][0].x );
                ty0 = tofix ( line.t[0][0].y );

#ifdef IPOL_C0
                a3 = tofix ( line.c[0][0].y );
#endif


#endif

                getSample_texture ( r0, g0, b0, &IT[0], tx0, ty0 );
                color_to_fix ( r1, g1, b1, dst[i] );

#ifdef IPOL_C0
                r2 = clampfix_maxcolor ( r1 + imulFix ( r0, a3 ) );
                g2 = clampfix_maxcolor ( g1 + imulFix ( g0, a3 ) );
                b2 = clampfix_maxcolor ( b1 + imulFix ( b0, a3 ) );
#else
                r2 = clampfix_maxcolor ( r1 + r0 );
                g2 = clampfix_maxcolor ( g1 + g0 );
                b2 = clampfix_maxcolor ( b1 + b0 );
#endif

                dst[i] = fix_to_color ( r2, g2, b2 );

#ifdef WRITE_Z
                z[i] = line.z[0];
#endif
#ifdef WRITE_W
                z[i] = line.w[0];
#endif
#endif
            }

#ifdef IPOL_Z
        line.z[0] += slopeZ;
#endif
#ifdef IPOL_W
        line.w[0] += slopeW;
#endif
#ifdef IPOL_C0
        line.c[0][0] += slopeC;
#endif
#ifdef IPOL_T0
        line.t[0][0] += slopeT[0];
#endif
#ifdef IPOL_T1
        line.t[1][0] += slopeT[1];
#endif
    }

}
/*!
*/
void CTRTextureLightMap2_M2::scanline_bilinear ( sScanLineData * data ) const
{
	tVideoSample *dst;

#ifdef USE_Z
	TZBufferType2 *z;
#endif

	s32 xStart;
	s32 xEnd;
	s32 dx;

	f32 invDeltaX;

#ifdef SUBTEXEL
	f32 subPixel;
#endif

#ifdef IPOL_Z
	f32 slopeZ;
#endif
#ifdef IPOL_W
	f32 slopeW;
#endif
#ifdef IPOL_C
	sVec4 slopeC;
#endif
#ifdef IPOL_T0
	sVec2 slopeT0;
#endif
#ifdef IPOL_T1
	sVec2 slopeT1;
#endif

	// apply top-left fill-convention, left
	xStart = irr::core::ceil32( data->x[0] );
	xEnd = irr::core::ceil32( data->x[1] ) - 1;

	dx = xEnd - xStart;

	if ( dx < 0 )
		return;

	// slopes
	invDeltaX = data->x[1] - data->x[0];
	invDeltaX = inverse32 ( invDeltaX );

#ifdef IPOL_Z
	slopeZ = (data->z[1] - data->z[0]) * invDeltaX;
#endif
#ifdef IPOL_W
	slopeW = (data->w[1] - data->w[0]) * invDeltaX;
#endif
#ifdef IPOL_C
	slopeC = (data->c[1] - data->c[0]) * invDeltaX;
#endif
#ifdef IPOL_T0
	slopeT0 = (data->t0[1] - data->t0[0]) * invDeltaX;
#endif
#ifdef IPOL_T1
	slopeT1 = (data->t1[1] - data->t1[0]) * invDeltaX;
#endif

#ifdef SUBTEXEL
	subPixel = ( (f32) xStart ) - data->x[0];
#ifdef IPOL_Z
	data->z[0] += slopeZ * subPixel;
#endif
#ifdef IPOL_W
	data->w[0] += slopeW * subPixel;
#endif
#ifdef IPOL_C
	data->c[0] += slopeC * subPixel;
#endif
#ifdef IPOL_T0
	data->t0[0] += slopeT0 * subPixel;
#endif
#ifdef IPOL_T1
	data->t1[0] += slopeT1 * subPixel;
#endif
#endif

	dst = lockedSurface + ( data->y * SurfaceWidth ) + xStart;

#ifdef USE_Z
	z = lockedZBuffer + ( data->y * SurfaceWidth ) + xStart;
#endif


#ifdef INVERSE_W
	f32 inversew;
#endif

	tFixPoint tx0, tx1;
	tFixPoint ty0, ty1;

	tFixPoint r0, g0, b0;
	tFixPoint r1, g1, b1;
	tFixPoint r2, g2, b2;


	for ( s32 i = 0; i <= dx; ++i )
	{
#ifdef CMP_Z
		if ( data->z[0] < z[i] )
#endif
#ifdef CMP_W
		if ( data->w[0] > z[i] )
#endif

		{
#ifdef INVERSE_W
			inversew = fix_inverse32 ( data->w[0] );

			tx0 = f32_to_fixPoint ( data->t0[0].x,inversew);
			ty0 = f32_to_fixPoint ( data->t0[0].y,inversew);
			tx1 = f32_to_fixPoint ( data->t1[0].x,inversew);
			ty1 = f32_to_fixPoint ( data->t1[0].y,inversew);
#else
			tx0 = f32_to_fixPoint ( data->t0[0].x );
			ty0 = f32_to_fixPoint ( data->t0[0].y );
			tx1 = f32_to_fixPoint ( data->t1[0].x );
			ty1 = f32_to_fixPoint ( data->t1[0].y );
#endif
			getSample_texture ( r0, g0, b0, &IT[0], tx0, ty0 );
			getSample_texture ( r1, g1, b1, &IT[1], tx1, ty1 );

			r2 = clampfix_maxcolor ( imulFix2 ( r0, r1 ) );
			g2 = clampfix_maxcolor ( imulFix2 ( g0, g1 ) );
			b2 = clampfix_maxcolor ( imulFix2 ( b0, b1 ) );

			dst[i] = fix_to_color ( r2, g2, b2 );

#ifdef WRITE_Z
			z[i] = data->z[0];
#endif
#ifdef WRITE_W
			z[i] = data->w[0];
#endif

		}

#ifdef IPOL_Z
		data->z[0] += slopeZ;
#endif
#ifdef IPOL_W
		data->w[0] += slopeW;
#endif
#ifdef IPOL_C
		data->c[0] += slopeC;
#endif
#ifdef IPOL_T0
		data->t0[0] += slopeT0;
#endif
#ifdef IPOL_T1
		data->t1[0] += slopeT1;
#endif
	}

}
/*!
*/
void CTRTextureBlend::fragment_src_alpha_one ()
{
	tVideoSample *dst;

#ifdef USE_ZBUFFER
	fp24 *z;
#endif

	s32 xStart;
	s32 xEnd;
	s32 dx;


#ifdef SUBTEXEL
	f32 subPixel;
#endif

#ifdef IPOL_Z
	f32 slopeZ;
#endif
#ifdef IPOL_W
	fp24 slopeW;
#endif
#ifdef IPOL_C0
	sVec4 slopeC[MATERIAL_MAX_COLORS];
#endif
#ifdef IPOL_T0
	sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];
#endif

	// apply top-left fill-convention, left
	xStart = core::ceil32( line.x[0] );
	xEnd = core::ceil32( line.x[1] ) - 1;

	dx = xEnd - xStart;

	if ( dx < 0 )
		return;

	// slopes
	const f32 invDeltaX = core::reciprocal_approxim ( line.x[1] - line.x[0] );

#ifdef IPOL_Z
	slopeZ = (line.z[1] - line.z[0]) * invDeltaX;
#endif
#ifdef IPOL_W
	slopeW = (line.w[1] - line.w[0]) * invDeltaX;
#endif
#ifdef IPOL_C0
	slopeC[0] = (line.c[0][1] - line.c[0][0]) * invDeltaX;
#endif
#ifdef IPOL_T0
	slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;
#endif
#ifdef IPOL_T1
	slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;
#endif

#ifdef SUBTEXEL
	subPixel = ( (f32) xStart ) - line.x[0];
#ifdef IPOL_Z
	line.z[0] += slopeZ * subPixel;
#endif
#ifdef IPOL_W
	line.w[0] += slopeW * subPixel;
#endif
#ifdef IPOL_C0
	line.c[0][0] += slopeC[0] * subPixel;
#endif
#ifdef IPOL_T0
	line.t[0][0] += slopeT[0] * subPixel;
#endif
#ifdef IPOL_T1
	line.t[1][0] += slopeT[1] * subPixel;
#endif
#endif

	dst = (tVideoSample*)RenderTarget->getData() + ( line.y * RenderTarget->getDimension().Width ) + xStart;

#ifdef USE_ZBUFFER
	z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
#endif


	f32 iw = FIX_POINT_F32_MUL;

	tFixPoint a0, r0, g0, b0;
	tFixPoint r1, g1, b1;
	tFixPoint r2, g2, b2;

	s32 i;

	switch ( ZCompare )
	{
	case 1:
	for ( i = 0; i <= dx; ++i )
	{
#ifdef CMP_W
		if ( line.w[0] >= z[i] )
#endif

		{


#ifdef INVERSE_W
		iw = fix_inverse32 ( line.w[0] );
#endif

		getSample_texture ( a0, r0, g0, b0, IT + 0, tofix ( line.t[0][0].x,iw),tofix ( line.t[0][0].y,iw) );
		if ( a0 > 0 )
		{
		a0 >>= 8;

		color_to_fix ( r1, g1, b1, dst[i] );

#ifdef IPOL_C0
		getSample_color ( r2, g2, b2, line.c[0][0],iw );

		dst[i] = fix4_to_color ( a0,
								 clampfix_maxcolor ( imulFix (r0,a0 ) + r1),
								 clampfix_maxcolor ( imulFix (g0,a0 ) + g1),
								 clampfix_maxcolor ( imulFix (b0,a0 ) + b1)
								);

/*
		a0 >>= 8;
		dst[i] = fix4_to_color ( a0,
								imulFix ( imulFix ( r0, a0 ) + r1, r2 ),
								imulFix ( imulFix ( g0, a0 ) + g1, g2 ),
								imulFix ( imulFix ( b0, a0 ) + b1, b2 )
							);
*/
#else
		dst[i] = fix4_to_color ( a0,
								 clampfix_maxcolor ( imulFix (r0,a0 ) + r1 ),
								 clampfix_maxcolor ( imulFix (g0,a0 ) + g1 ),
								 clampfix_maxcolor ( imulFix (b0,a0 ) + b1 )
								);

#endif

#ifdef WRITE_W
			//z[i] = line.w[0];
#endif
		}

		}

#ifdef IPOL_W
		line.w[0] += slopeW;
#endif
#ifdef IPOL_T0
		line.t[0][0] += slopeT[0];
#endif
#ifdef IPOL_C0
		line.c[0][0] += slopeC[0];
#endif
	}