Exemple #1
0
        protected override void DrawPlayerModel( Player p )
        {
            graphics.Texturing = true;
            graphics.AlphaTest = true;
            block = Byte.Parse( p.ModelName );
            if( block == 0 ) {
                blockHeight = 1;
                return;
            }

            graphics.BindTexture( game.TerrainAtlas.TexId );
            blockHeight = game.BlockInfo.Height[block];
            atlas = game.TerrainAtlas;
            BlockInfo = game.BlockInfo;

            if( BlockInfo.IsSprite[block] ) {
                XQuad( 0f, TileSide.Right, false );
                ZQuad( 0f, TileSide.Back, false );
            } else {
                YQuad( blockHeight, TileSide.Top );
                XQuad( -0.5f, TileSide.Right, false );
                XQuad( 0.5f, TileSide.Left, true );
                ZQuad( -0.5f, TileSide.Front, true );
                ZQuad( 0.5f, TileSide.Back, false );
                YQuad( 0f, TileSide.Bottom );
            }
        }
Exemple #2
0
        public int CalcMaxUsedRow(TerrainAtlas2D atlas2D, BlockInfo info)
        {
            int maxVerSize    = Math.Min(4096, graphics.MaxTextureDimensions);
            int verElements   = maxVerSize / atlas2D.elementSize;
            int totalElements = GetMaxUsedRow(info.textures) * TerrainAtlas2D.ElementsPerRow;

            return(Utils.CeilDiv(totalElements, verElements));
        }
        public int CalcMaxUsedRow( TerrainAtlas2D atlas2D, BlockInfo info )
        {
            int maxVerSize = Math.Min( 4096, graphics.MaxTextureDimensions );
            int verElements = maxVerSize / atlas2D.elementSize;
            int totalElements = GetMaxUsedRow( info.textures ) * TerrainAtlas2D.ElementsPerRow;

            Utils.LogDebug( "Used atlases: " + Utils.CeilDiv( totalElements, verElements ) );
            return Utils.CeilDiv( totalElements, verElements );
        }
Exemple #4
0
        void MakeTexture(ref int id, ref int lastTexLoc, BlockID block)
        {
            int texLoc = BlockInfo.GetTextureLoc(block, Side.Top);

            if (texLoc == lastTexLoc || game.Graphics.LostContext)
            {
                return;
            }
            lastTexLoc = texLoc;

            game.Graphics.DeleteTexture(ref id);
            id = TerrainAtlas2D.LoadTextureElement(texLoc);
        }
        void MakeTexture(ref int id, ref int lastTexLoc, int newTex)
        {
            int texLoc = newTex;

            if (texLoc == lastTexLoc || game.Graphics.LostContext)
            {
                return;
            }
            lastTexLoc = texLoc;

            game.Graphics.DeleteTexture(ref id);
            id = TerrainAtlas2D.LoadTextureElement(texLoc);
        }
Exemple #6
0
        void Convert2DTo1D(TerrainAtlas2D atlas2D, int atlasesCount, int atlas1DHeight)
        {
            TexIds = new int[atlasesCount];
            Utils.LogDebug("Loaded new atlas: {0} bmps, {1} per bmp", atlasesCount, elementsPerAtlas1D);
            int index = 0;

            using (FastBitmap atlas = new FastBitmap(atlas2D.AtlasBitmap, true, true)) {
                for (int i = 0; i < TexIds.Length; i++)
                {
                    Make1DTexture(i, atlas, atlas2D, atlas1DHeight, ref index);
                }
            }
        }
        public void UpdateState( TerrainAtlas2D atlas2D )
        {
            int maxVerticalSize = Math.Min( 4096, graphics.MaxTextureDimensions );
            int elementsPerFullAtlas = maxVerticalSize / atlas2D.elementSize;
            int totalElements = TerrainAtlas2D.RowsCount * TerrainAtlas2D.ElementsPerRow;

            int atlasesCount = Utils.CeilDiv( totalElements, elementsPerFullAtlas );
            elementsPerAtlas1D = Math.Min( elementsPerFullAtlas, totalElements );
            int atlas1DHeight = Utils.NextPowerOf2( elementsPerAtlas1D * atlas2D.elementSize );

            Convert2DTo1D( atlas2D, atlasesCount, atlas1DHeight );
            elementsPerBitmap = atlas1DHeight / atlas2D.elementSize;
            invElementSize = 1f / elementsPerBitmap;
        }
Exemple #8
0
        public void UpdateState(TerrainAtlas2D atlas2D)
        {
            int maxVerticalSize      = Math.Min(4096, game.Graphics.MaxTextureDimensions);
            int elementsPerFullAtlas = maxVerticalSize / atlas2D.TileSize;
            int totalElements        = TerrainAtlas2D.RowsCount * TerrainAtlas2D.TilesPerRow;

            int atlasesCount = Utils.CeilDiv(totalElements, elementsPerFullAtlas);

            elementsPerAtlas1D = Math.Min(elementsPerFullAtlas, totalElements);
            int atlas1DHeight = Utils.NextPowerOf2(elementsPerAtlas1D * atlas2D.TileSize);

            Convert2DTo1D(atlas2D, atlasesCount, atlas1DHeight);
            elementsPerBitmap = atlas1DHeight / atlas2D.TileSize;
            invElementSize    = 1f / elementsPerBitmap;
        }
Exemple #9
0
        void Make1DTexture(int i, FastBitmap atlas, TerrainAtlas2D atlas2D, int atlas1DHeight, ref int index)
        {
            int elemSize = atlas2D.TileSize;

            using (Bitmap atlas1d = Platform.CreateBmp(atlas2D.TileSize, atlas1DHeight))
                using (FastBitmap dst = new FastBitmap(atlas1d, true, false))
                {
                    for (int index1D = 0; index1D < elementsPerAtlas1D; index1D++)
                    {
                        FastBitmap.MovePortion((index & 0x0F) * elemSize, (index >> 4) * elemSize,
                                               0, index1D * elemSize, atlas, dst, elemSize);
                        index++;
                    }
                    TexIds[i] = game.Graphics.CreateTexture(dst, true, game.Graphics.Mipmaps);
                }
        }
        protected override void DrawPlayerModel( Player p )
        {
            // TODO: using 'is' is ugly, but means we can avoid creating
            // a string every single time held block changes.
            if( p is FakePlayer ) {
                Vector3I eyePos = Vector3I.Floor( game.LocalPlayer.EyePosition );
                FastColour baseCol = game.Map.IsLit( eyePos ) ? game.Map.Sunlight : game.Map.Shadowlight;
                col = FastColour.Scale( baseCol, 0.8f );
                block = ((FakePlayer)p).Block;
            } else {
                block = Byte.Parse( p.ModelName );
            }
            if( block == 0 ) {
                blockHeight = 1;
                return;
            }

            graphics.BindTexture( game.TerrainAtlas.TexId );
            blockHeight = game.BlockInfo.Height[block];
            atlas = game.TerrainAtlas;
            BlockInfo = game.BlockInfo;

            if( BlockInfo.IsSprite[block] ) {
                float offset = TerrainAtlas2D.invElementSize / 2;
                XQuad( 0f, TileSide.Right, -scale, 0, 0, -offset, false );
                ZQuad( 0f, TileSide.Back, 0, scale, offset, 0, false );

                XQuad( 0f, TileSide.Right, 0, scale, offset, 0, false );
                ZQuad( 0f, TileSide.Back, -scale, 0, 0, -offset, false );
            } else {
                YQuad( 0f, TileSide.Bottom );
                XQuad( scale, TileSide.Left, -scale, scale, 0, 0, true );
                ZQuad( -scale, TileSide.Front, -scale, scale, 0, 0, true );

                ZQuad( scale, TileSide.Back, -scale, scale, 0, 0, true );
                YQuad( blockHeight, TileSide.Top );
                XQuad( -scale, TileSide.Right, -scale, scale, 0, 0, true );

            }
            graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, cache.vb, cache.vertices, index, index * 6 / 4 );
        }
        void Convert2DTo1D( TerrainAtlas2D atlas2D, int atlasesCount, int atlas1DHeight )
        {
            TexIds = new int[atlasesCount];
            Utils.LogDebug( "Loaded new atlas: {0} bmps, {1} per bmp", atlasesCount, elementsPerAtlas1D );
            int index = 0;

            using( FastBitmap atlas = new FastBitmap( atlas2D.AtlasBitmap, true, true ) ) {
                for( int i = 0; i < TexIds.Length; i++ )
                    Make1DTexture( i, atlas, atlas2D, atlas1DHeight, ref index );
            }
        }
 void Make1DTexture( int i, FastBitmap atlas, TerrainAtlas2D atlas2D, int atlas1DHeight, ref int index )
 {
     int elemSize = atlas2D.elementSize;
     using( Bitmap atlas1d = new Bitmap( atlas2D.elementSize, atlas1DHeight ) )
         using( FastBitmap dst = new FastBitmap( atlas1d, true, false ) )
     {
         for( int index1D = 0; index1D < elementsPerAtlas1D; index1D++ ) {
             FastBitmap.MovePortion( (index & 0x0F) * elemSize, (index >> 4) * elemSize,
                                    0, index1D * elemSize, atlas, dst, elemSize );
             index++;
         }
         TexIds[i] = graphics.CreateTexture( dst );
     }
 }