Exemple #1
0
        /*
        ===============
        R_DrawSurface
        ===============
        */
        public static void R_DrawSurface()
        {
            helper.ByteBuffer   basetptr;
            int				    smax, tmax, twidth;
            int				    u;
            int				    soffset, basetoffset, texwidth;
            int				    horzblockstep;
            helper.ByteBuffer   pcolumndest;
            blockdrawer         pblockdrawer;
            model.texture_t	    mt;

            // calculate the lightings
            R_BuildLightMap ();

            surfrowbytes = r_drawsurf.rowbytes;

            mt = r_drawsurf.texture;

            r_source = new helper.ByteBuffer(mt.pixels, (int)mt.offsets[r_drawsurf.surfmip]);

            // the fractional light values should range from 0 to (VID_GRADES - 1) << 16
            // from a source range of 0 - 255

            texwidth = (int)(mt.width >> r_drawsurf.surfmip);

            blocksize = 16 >> r_drawsurf.surfmip;
            blockdivshift = 4 - r_drawsurf.surfmip;
            blockdivmask = (uint)((1 << blockdivshift) - 1);

            r_lightwidth = (r_drawsurf.surf.extents[0]>>4)+1;

            r_numhblocks = r_drawsurf.surfwidth >> blockdivshift;
            r_numvblocks = r_drawsurf.surfheight >> blockdivshift;

            //==============================

            if (r_pixbytes == 1)
            {
                pblockdrawer = surfmiptable[r_drawsurf.surfmip];
            // TODO: only needs to be set when there is a display settings change
                horzblockstep = blocksize;
            }
            else
            {
                pblockdrawer = R_DrawSurfaceBlock16;
            // TODO: only needs to be set when there is a display settings change
                horzblockstep = blocksize << 1;
            }

            smax = (int)(mt.width >> r_drawsurf.surfmip);
            twidth = texwidth;
            tmax = (int)(mt.height >> r_drawsurf.surfmip);
            sourcetstep = texwidth;
            r_stepback = tmax * twidth;

            r_sourcemax = r_source + (tmax * smax);

            soffset = r_drawsurf.surf.texturemins[0];
            basetoffset = r_drawsurf.surf.texturemins[1];

            // << 16 components are to guarantee positive values for %
            soffset = ((soffset >> r_drawsurf.surfmip) + (smax << 16)) % smax;
            basetptr = new helper.ByteBuffer(r_source, ((((basetoffset >> r_drawsurf.surfmip)
                + (tmax << 16)) % tmax) * twidth));

            pcolumndest = new helper.ByteBuffer(r_drawsurf.surfdat);

            for (u=0 ; u<r_numhblocks; u++)
            {
                r_lightptr = new helper.UIntBuffer(blocklights, u);

                prowdestbase = new helper.ByteBuffer(pcolumndest);

                pbasesource = new helper.ByteBuffer(basetptr, soffset);

                pblockdrawer();

                soffset = soffset + blocksize;
                if (soffset >= smax)
                    soffset = 0;

                pcolumndest.Add(horzblockstep);
            }
        }
Exemple #2
0
        /*
        ================
        R_DrawSurfaceBlock8_mip3
        ================
        */
        static void R_DrawSurfaceBlock8_mip3()
        {
            int v, i, b, lightstep, lighttemp, light;
            byte pix;
            helper.ByteBuffer psource, prowdest;

            psource = new helper.ByteBuffer(pbasesource);
            prowdest = new helper.ByteBuffer(prowdestbase);

            for (v = 0; v < r_numvblocks; v++)
            {
                // FIXME: make these locals?
                // FIXME: use delta rather than both right and left, like ASM?
                lightleft = (int)r_lightptr[0];
                lightright = (int)r_lightptr[1];
                r_lightptr += r_lightwidth;
                lightleftstep = (int)(r_lightptr[0] - lightleft) >> 1;
                lightrightstep = (int)(r_lightptr[1] - lightright) >> 1;

                for (i = 0; i < 2; i++)
                {
                    lighttemp = lightleft - lightright;
                    lightstep = lighttemp >> 1;

                    light = lightright;

                    for (b = 1; b >= 0; b--)
                    {
                        pix = psource[b];
                        prowdest[b] = screen.vid.colormap
                                [(light & 0xFF00) + pix];
                        light += lightstep;
                    }

                    psource.Add(sourcetstep);
                    lightright += lightrightstep;
                    lightleft += lightleftstep;
                    prowdest.Add(surfrowbytes);
                }

                if (psource >= r_sourcemax)
                    psource.Sub(r_stepback);
            }
        }