Esempio n. 1
0
 public SheetBuilder2D(SheetType t, int w, int h)
 {
     channel        = t == SheetType.Indexed ? TextureChannel.Red : TextureChannel.RGBA;
     SheetStoreType = t;
     currentSheet2D = CreateNewSheet(t, w, h);
     sheetsOnCpu.Add(currentSheet2D);
 }
Esempio n. 2
0
 public SheetBuilder2D(SheetType t, Func <Sheet2D> allocateSheetDelegate)
 {
     channel        = t == SheetType.Indexed ? TextureChannel.Red : TextureChannel.RGBA;
     SheetStoreType = t;
     currentSheet2D = allocateSheetDelegate();
     sheetsOnCpu.Add(currentSheet2D);
     this.allocateSheetDelegate = allocateSheetDelegate;
 }
Esempio n. 3
0
        public void AddCommand(int ShaderID, int CurrentFrame, int TotalFrames, int CurrentTime, int TotalTime, int2 iResolutionXY,
                               float3 TopLeftXYrect, float3 SpriteSize, Sprite SpriteUVCoords, PaletteReference PaletteIndex)
        {
            //рисуем в СисКоординат, где начало координат в ЛевомНижнемУглу
            //заполнение локального массива Verts
            //нужно 4 записи сделать, на каждый угол прямоугольника.
            var a = new float3(TopLeftXYrect.X, TopLeftXYrect.Y + SpriteSize.Y, TopLeftXYrect.Z);                //1
            var b = new float3(TopLeftXYrect.X + SpriteSize.X, TopLeftXYrect.Y + SpriteSize.Y, TopLeftXYrect.Z); //2
            var c = new float3(TopLeftXYrect.X, TopLeftXYrect.Y, TopLeftXYrect.Z + 0);                           //3
            var d = new float3(TopLeftXYrect.X + SpriteSize.X, TopLeftXYrect.Y, TopLeftXYrect.Z + 0);            //4

            float TextureStoreChannel = 0;
            int   TextureInputSlot    = 1;        // всегда 1 слот, так как пока поддержка только 1 текстурки будет.
            float palindex            = 0;

            if (SpriteUVCoords != null)
            {
                shtInputSlot1 = SpriteUVCoords.Sheet2D;
                this.SetTexture("Texture2D0", shtInputSlot1.AssignOrGetOrSetDataGLTexture());                 // заполняем текстуру0 для аргумента шейдера

                ni = 0;
                //Vertex mapping xyz,ShaderID,CurrentFrame,TotalFrames, iTime, TotalTime,iResolutionXY, TextureInputSlot , TextureStoreChannel,SpriteUVCoords

                //PaletteIndex.TextureIndex индекс в текстуре палитр


                if (SpriteUVCoords.Channel == TextureChannel.RGBA)
                {
                    TextureStoreChannel = 4f;                     // это потому что, выбор текстуры зависит от 0.0 чисел в шейдере в методе vec4 Sample()
                }
                else
                {
                    TextureStoreChannel = (byte)SpriteUVCoords.Channel;
                }
                TextureStoreChannel = SpriteUVCoords.TextureArrayIndex;
            }

            if (SpriteUVCoords == null)
            {
                SpriteUVCoords = new Sprite(new Sheet(SheetType.Indexed, new Size(0, 0)), new Rectangle(new int2(0, 0), new Size(0, 0)), 0);
            }
            if (PaletteIndex == null)
            {
                PaletteIndex = new PaletteReference("null", 0, null, new HardwarePalette());
                palindex     = PaletteIndex.TextureIndex;
            }



            Verts[nv]     = new Vertex2(a, ShaderID, CurrentFrame, TotalFrames, 0, 0, SpriteUVCoords.Size.X, SpriteUVCoords.Size.Y, TextureInputSlot, TextureStoreChannel, SpriteUVCoords.Left, SpriteUVCoords.Bottom, palindex, 0);
            Verts[nv + 1] = new Vertex2(b, ShaderID, CurrentFrame, TotalFrames, 0, 0, SpriteUVCoords.Size.X, SpriteUVCoords.Size.Y, TextureInputSlot, TextureStoreChannel, SpriteUVCoords.Right, SpriteUVCoords.Bottom, palindex, 0);
            Verts[nv + 2] = new Vertex2(c, ShaderID, CurrentFrame, TotalFrames, 0, 0, SpriteUVCoords.Size.X, SpriteUVCoords.Size.Y, TextureInputSlot, TextureStoreChannel, SpriteUVCoords.Left, SpriteUVCoords.Top, palindex, 0);
            Verts[nv + 3] = new Vertex2(d, ShaderID, CurrentFrame, TotalFrames, 0, 0, SpriteUVCoords.Size.X, SpriteUVCoords.Size.Y, TextureInputSlot, TextureStoreChannel, SpriteUVCoords.Right, SpriteUVCoords.Top, palindex, 0);
            nv           += 4;
        }
Esempio n. 4
0
        public Sprite(Sheet2D sheet, Rectangle bounds, float zRamp, float3 offset, TextureChannel channel, BlendMode blendMode = BlendMode.Alpha)
        {
            TextureArrayIndex = sheet.textureArrayIndex;
            Sheet2D           = sheet;
            Bounds            = bounds;
            Offset            = offset;
            ZRamp             = zRamp;
            Channel           = channel;
            Size             = new float3(bounds.Size.Width, bounds.Size.Height, bounds.Size.Height * zRamp);
            BlendMode        = blendMode;
            FractionalOffset = Size.Z != 0 ? offset / Size :
                               new float3(offset.X / Size.X, offset.Y / Size.Y, 0);

            Left   = (float)Math.Min(bounds.Left, bounds.Right) / sheet.Size.Width;
            Top    = (float)Math.Min(bounds.Top, bounds.Bottom) / sheet.Size.Height;
            Right  = (float)Math.Max(bounds.Left, bounds.Right) / sheet.Size.Width;
            Bottom = (float)Math.Max(bounds.Top, bounds.Bottom) / sheet.Size.Height;
        }
        public TerrainSpriteLayer(World world, WorldRenderer wr, Sheet2D sheet, BlendMode blendMode, PaletteReference palette, bool restrictToBounds, string ownername)
        {
            // Так как все вертексы хранятся плоским списком, то приходится отправлять в рендер всю ширину карты. Так как нельзя вырезать регион из плоского списка по Ширине
            // Поэтому отрезается только по высоте. А ширина учитывается полностью.
            worldRenderer         = wr;
            this.restrictToBounds = restrictToBounds;

            BlendMode      = blendMode;
            this.palette   = palette;
            this.ownername = ownername;
            map            = world.Map;
            TerrainFullRowLenInVertexRowsNums = 6 * map.MapSize.X;

            vertices     = new Vertex[TerrainFullRowLenInVertexRowsNums * map.MapSize.Y];
            vertexBuffer = Game.Renderer.Context.CreateVertexBuffer(vertices.Length, "TerrainSpriteLayer");
            if (emptySprite == null)
            {
                emptySprite = new Sprite(sheet, Rectangle.Empty, TextureChannel.Alpha);
            }
            vertexBuffer.ownername += "->" + ownername;
            wr.PaletteInvalidated  += UpdatePaletteIndices;
        }
Esempio n. 6
0
 public Sprite GetImage(Sheet2D s)
 {
     rect.X += OffsetLeft;
     rect.Y += OffsetTop;
     return(new Sprite(s, rect, TextureChannel.RGBA));
 }
Esempio n. 7
0
        /// <summary>
        /// Резервирует место под SPrite в текстуре opengl
        /// Определяет в какой канал текстуры будут записаны байты
        /// </summary>
        /// <param name="imageSize"></param>
        /// <param name="zRamp"></param>
        /// <param name="spriteOffset"></param>
        /// <returns></returns>
        public Sprite Allocate(Size imageSize, float zRamp, float3 spriteOffset, TextureChannel overrideChannel = TextureChannel.Red)
        {
            if (overrideChannel == TextureChannel.RGBA)
            {
                channel = TextureChannel.RGBA;                 //сделано, для случаев, когда спрайты в sequences будут 4 байтовые, то есть из PNG идти.
            }
            else
            {
                channel = SheetStoreType == SheetType.Indexed ? TextureChannel.Red : TextureChannel.RGBA;                 // пишем теперь всегда в канал Red
            }
            //используется одномерный массив. Поэтому все разбито по Height(row) и смещение внутри row.
            if (imageSize.Width + p.X > currentSheet2D.Size.Width)             //если дошли до смещения равного ширине картинки, то сбрасываем смещение до 0 и делаем переход на высоту равную предыдущей высоте.
            {
                p         = new int2(0, p.Y + rowHeight);
                rowHeight = imageSize.Height;
            }

            if (imageSize.Height > rowHeight)
            {
                rowHeight = imageSize.Height;
            }

            if (p.Y + imageSize.Height > currentSheet2D.Size.Height)             //если вышли за пределы высоты в одном канале, то переходим в другой канал. и скидываем p=int2.Zero
            {
                //когда дошли по конца массива, то переходи в следующий Sheet , а не в канал.

                //var next = NextChannel(channel);

                //if (next == null)
                //{
                //	NextSheet();
                //}
                //if (next == null) //если закончились каналы внутри текстуры , то создаем новый Sheet.
                //{

                //	NextSheet();
                //	currentSheet2D.ReleaseBuffer();
                //	currentSheet2D = CreateNewSheet(SheetStoreType, Game.Settings.Graphics.SheetSize); //унаследует TextureArrayIndex в новый Sheet2D
                //	sheetsOnCpu.Add(currentSheet2D);
                //	channel = SheetStoreType == SheetType.Indexed ? TextureChannel.Red : TextureChannel.RGBA;
                //}
                //else
                //	channel = next.Value;

                currentSheet2D.ReleaseBuffer();
                textureArray = currentSheet2D.texture;                 // присваиваем текстуру от первого sheet ,так как текстуры имеютс вязь sheet<->texture
                NextSheet();

                currentSheet2D = CreateNewSheet(SheetStoreType, Game.Settings.Graphics.SheetSize);                 //унаследует TextureArrayIndex в новый Sheet2D
                sheetsOnCpu.Add(currentSheet2D);



                rowHeight = imageSize.Height;
                p         = int2.Zero;
            }

            var rect = new Sprite(currentSheet2D, new Rectangle(p.X, p.Y, imageSize.Width, imageSize.Height), zRamp, spriteOffset, channel, BlendMode.Alpha);

            p += new int2(imageSize.Width, 0);             // увеливаем свещение на ширину картинки у p.X параметра

            return(rect);
        }
Esempio n. 8
0
 public Sprite(Sheet2D sheet, Rectangle bounds, TextureChannel channel)
     : this(sheet, bounds, 0, float2.Zero, channel)
 {
 }