示例#1
0
        public static void FastCreateQuad(Vertex[] vertices, float3 o, Sprite r, SamplerPointer samplers, float paletteTextureIndex, int nv, float3 size)
        {
            var b = new float3(o.X + size.X, o.Y, o.Z);
            var c = new float3(o.X + size.X, o.Y + size.Y, o.Z + size.Z);
            var d = new float3(o.X, o.Y + size.Y, o.Z + size.Z);

            FastCreateQuad(vertices, o, b, c, d, r, samplers, paletteTextureIndex, nv);
        }
示例#2
0
        public static void FastCreateQuad(Vertex[] vertices, float3 a, float3 b, float3 c, float3 d, Sprite r, SamplerPointer samplers, float paletteTextureIndex, int nv)
        {
            float sl = 0;
            float st = 0;
            float sr = 0;
            float sb = 0;

            // See shp.vert for documentation on the channel attribute format
            float TextureStoreChannel = 0, TextureSlot = 0, SecTextureStoreChannel = 0, SecTextureSlot = 0;
            float samplerType = 0;

            // тут r трактуется как класс Sprite
            if (r.Channel == TextureChannel.RGBA)
            {
                TextureStoreChannel = 4f;                 // тут нужно указать, в каком канале текстуры R,G,B зашиты данные о цвете. для RGBA текстуры нужно цифру 2, это в шейдере
                // укажет на использование 1.1.1.1 маски
            }
            else
            {
                TextureStoreChannel = (byte)r.Channel;                 // тут нужно понять, в каком канале лежат данные о цвете, так как SheetBiulder распределяет данные картинок
                // по R,G,B группам. Это сделано для картинок с палитрами. Так как их цвет занимает лишь 1 байт, вместо 4 байт.
                // 1 в шейдере это R канал, 2 это RGBA, 3 = G , 5=B, 7=A
                // R=0,G=1,B=2,A=3,RGBA=4 в r.Channel . В шейдере передалана функция связки масок, на точное соотвествие.
            }

            if (samplers.Stype1 == SamplerType.Sampler2d)
            {
                if (r.TextureArrayIndex == 5)
                {
                }
                TextureStoreChannel = r.TextureArrayIndex;
                samplerType         = 1;
            }
            TextureSlot = samplers.num1;              // это потому что, выбор текстуры зависит от 0.0 чисел в шейдере в методе vec4 Sample()

            var ss = r as SpriteWithSecondaryData;

            // тут r трактуется уже как SpriteWithSecondaryData, если преобразование пройдет успешно! а если нет, то ss = null
            // используется для vDepthMask в шейдере и когда поставлен флаг ОтладкиГлубины SpriteRendere.SetDepthPreviewEnabled ставит у шейдера uniform EnableDepthPreview =true
            if (ss != null)
            {
                sl = ss.SecondaryLeft;
                st = ss.SecondaryTop;
                sr = ss.SecondaryRight;
                sb = ss.SecondaryBottom;

                // attribC |= ((byte)ss.SecondaryChannel) << 4 | 0x08;
                if (ss.SecondaryChannel == TextureChannel.RGBA)
                {
                    SecTextureStoreChannel = 4f;
                }
                else
                {
                    SecTextureStoreChannel = (byte)r.Channel;
                }
                if (samplers.StypeSec == SamplerType.Sampler2d)
                {
                    SecTextureStoreChannel = r.TextureArrayIndex;
                }


                // attribC |= samplers.Y << 9;
                SecTextureSlot = samplers.numSec;
            }

            int   drawmode = 0;
            float flipx, flipy;

            flipx = r.FlipX;
            flipy = r.FlipY;
            // Как то передать режим в котором будет рисование.
            if (r.Channel == TextureChannel.RGBA)
            {
                // значит режим рисования RGBA из текстуры
                drawmode = 0;
            }
            else
            {
                drawmode = 1;

                // режим через палитру, в основном из канала R в текстуре идем к цвету в палитре

                // drawmode=2 ставится для рисования прямоугольников и т.п. в RgbaColorRenderer, так как у него свой VBO
            }
            if (r.SpriteType == 1)
            {
                paletteTextureIndex = r.SpriteArrayNum; // положим сюда цифру указывающую на спрайт внутри Texture2dArray в TextureFontMSDF параметра шейдера.
                drawmode            = 3;                // FontMSDF
            }
            if (r.SpriteType == 2)
            {
                drawmode = 6;                 // fill rect with rgba sprite

                int r1, t1;
                r1 = (int)((b.X - a.X) / r.Size.X);
                //b1 = r.Bottom + (b.X - a.X) / r.Size.X;
                t1 = (int)((c.Y - a.Y) / r.Size.Y);
                if (t1 == 0)
                {
                    t1 = 1;
                }
                if (r1 == 0)
                {
                    r1 = 1;
                }

                if (r.Stretched)
                {
                    r1 = 1;
                    t1 = 1;
                }

                vertices[nv]     = new Vertex(a, 0, 0, sl, st, paletteTextureIndex, 0, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, r.Left, r.Top, r.Right, r.Bottom, flipx, flipy);
                vertices[nv + 1] = new Vertex(b, r1, 0, sr, st, paletteTextureIndex, 0, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, r.Left, r.Top, r.Right, r.Bottom, flipx, flipy);
                vertices[nv + 2] = new Vertex(c, r1, t1, sr, sb, paletteTextureIndex, 0, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, r.Left, r.Top, r.Right, r.Bottom, flipx, flipy);
                vertices[nv + 3] = new Vertex(c, r1, t1, sr, sb, paletteTextureIndex, 0, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, r.Left, r.Top, r.Right, r.Bottom, flipx, flipy);
                vertices[nv + 4] = new Vertex(d, 0, t1, sl, sb, paletteTextureIndex, 0, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, r.Left, r.Top, r.Right, r.Bottom, flipx, flipy);
                vertices[nv + 5] = new Vertex(a, 0, 0, sl, st, paletteTextureIndex, 0, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, r.Left, r.Top, r.Right, r.Bottom, flipx, flipy);
                return;
            }

            if (r.SpriteType == 3)
            {
                drawmode = 7;                 // fill rect with one channel sprite

                float hlen, b1, vlen;
                int   wk = (int)((b.X - a.X) / r.Size.X);               //width koof
                int   hk = (int)((c.Y - a.Y) / r.Size.Y);               // height koof

                hlen = wk;
                vlen = hk;

                float top, right, bot, left;
                top   = r.Top;
                right = r.Right;
                bot   = r.Bottom;
                left  = r.Left;

                float d1 = r.Right - r.Left;
                float d2 = r.Bottom - r.Top;

                //   top = r.Bottom;
                //bot = r.Top;
                //right = r.Left;
                //left = r.Right;
                if (r.Rotate > 0)
                {
                    wk = (int)((b.X - a.X) / r.Size.X);                     //width koof
                    hk = (int)((c.Y - a.Y) / r.Size.Y);                     // height koof
                    if (vlen == 0)
                    {
                        vlen = 1;
                    }
                    //left += d1;
                    //right -= d2;
                    //top += d2;
                    //bot -= d2;
                    vertices[nv]     = new Vertex(a, 0, 0, sl, st, paletteTextureIndex, wk, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, left, top, right, bot, flipx, flipy);
                    vertices[nv + 1] = new Vertex(b, hlen, 0, sr, st, paletteTextureIndex, wk, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, left, top, right, bot, flipx, flipy);
                    vertices[nv + 2] = new Vertex(c, hlen, vlen, sr, sb, paletteTextureIndex, wk, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, left, top, right, bot, flipx, flipy);
                    vertices[nv + 3] = new Vertex(c, hlen, vlen, sr, sb, paletteTextureIndex, wk, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, left, top, right, bot, flipx, flipy);
                    vertices[nv + 4] = new Vertex(d, 0, vlen, sl, sb, paletteTextureIndex, wk, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, left, top, right, bot, flipx, flipy);
                    vertices[nv + 5] = new Vertex(a, 0, 0, sl, st, paletteTextureIndex, wk, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, left, top, right, bot, flipx, flipy);
                }
                else

                {
                    if (r.Stretched)
                    {
                        hlen = 1;
                        vlen = 1;
                    }
                    vertices[nv]     = new Vertex(a, 0, 0, sl, st, paletteTextureIndex, wk, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, left, top, right, bot, flipx, flipy);
                    vertices[nv + 1] = new Vertex(b, hlen, 0, sr, st, paletteTextureIndex, wk, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, left, top, right, bot, flipx, flipy);
                    vertices[nv + 2] = new Vertex(c, hlen, vlen, sr, sb, paletteTextureIndex, wk, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, left, top, right, bot, flipx, flipy);
                    vertices[nv + 3] = new Vertex(c, hlen, vlen, sr, sb, paletteTextureIndex, wk, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, left, top, right, bot, flipx, flipy);
                    vertices[nv + 4] = new Vertex(d, 0, vlen, sl, sb, paletteTextureIndex, wk, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, left, top, right, bot, flipx, flipy);
                    vertices[nv + 5] = new Vertex(a, 0, 0, sl, st, paletteTextureIndex, wk, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, left, top, right, bot, flipx, flipy);
                }
                //vertices[nv] = new Vertex(a, r.Left, r.Top, sl, st, paletteTextureIndex, wk, drawmode, hk, ct1, ct2, ct3, ct4, left, top, right, bot);
                //vertices[nv + 1] = new Vertex(b, r.Right, r.Top, sr, st, paletteTextureIndex, wk, drawmode, hk, ct1, ct2, ct3, ct4, left, top, right, bot);
                //vertices[nv + 2] = new Vertex(c, r.Right, r.Bottom, sr, sb, paletteTextureIndex, wk, drawmode, hk, ct1, ct2, ct3, ct4, left, top, right, bot);

                //vertices[nv + 3] = new Vertex(c, r.Right, r.Bottom, sr, sb, paletteTextureIndex, wk, drawmode, hk, ct1, ct2, ct3, ct4, left, top, right, bot);
                //vertices[nv + 4] = new Vertex(d, r.Left, r.Bottom, sl, sb, paletteTextureIndex, wk, drawmode, hk, ct1, ct2, ct3, ct4, left, top, right, bot);
                //vertices[nv + 5] = new Vertex(a, r.Left, r.Top, sl, st, paletteTextureIndex, wk, drawmode, hk, ct1, ct2, ct3, ct4, left, top, right, bot);

                return;
            }

            if (r.SpriteType == 4)
            {
                drawmode = 8;
                //vertices[nv] = new Vertex(a, a.X + 0, a.Y + 0, sl, st, paletteTextureIndex, 0, drawmode, 0, ct1, ct2, ct3, ct4, r.Left, r.Top, r.Right, r.Bottom);
                //vertices[nv + 1] = new Vertex(b, a.X + 1, a.Y + 0, sr, st, paletteTextureIndex, 0, drawmode, 0, ct1, ct2, ct3, ct4, r.Left, r.Top, r.Right, r.Bottom);
                //vertices[nv + 2] = new Vertex(c, a.X + 1, a.Y + 1, sr, sb, paletteTextureIndex, 0, drawmode, 0, ct1, ct2, ct3, ct4, r.Left, r.Top, r.Right, r.Bottom);
                //vertices[nv + 3] = new Vertex(c, a.X + 1, a.Y + 1, sr, sb, paletteTextureIndex, 0, drawmode, 0, ct1, ct2, ct3, ct4, r.Left, r.Top, r.Right, r.Bottom);
                //vertices[nv + 4] = new Vertex(d, a.X + 0, a.Y + 1, sl, sb, paletteTextureIndex, 0, drawmode, 0, ct1, ct2, ct3, ct4, r.Left, r.Top, r.Right, r.Bottom);
                //vertices[nv + 5] = new Vertex(a, a.X + 0, a.Y + 0, sl, st, paletteTextureIndex, 0, drawmode, 0, ct1, ct2, ct3, ct4, r.Left, r.Top, r.Right, r.Bottom);
                //return;
            }

            if (r.SpriteType == 5)             //dump texture to png
            {
                drawmode = 9;
            }

            if (r.SpriteType == 6)             //highlight
            {
                drawmode = 10;
            }
            if (r.SpriteType == 7)             //highlight
            {
                drawmode = 11;
            }
            if (r.SpriteType == 8)             //highlight
            {
                drawmode = 12;
            }
            // var fAttribC = (float)attribC;
            vertices[nv]     = new Vertex(a, r.Left, r.Top, sl, st, paletteTextureIndex, 0, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, flipx, flipy);
            vertices[nv + 1] = new Vertex(b, r.Right, r.Top, sr, st, paletteTextureIndex, 0, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, flipx, flipy);
            vertices[nv + 2] = new Vertex(c, r.Right, r.Bottom, sr, sb, paletteTextureIndex, 0, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, flipx, flipy);

            vertices[nv + 3] = new Vertex(c, r.Right, r.Bottom, sr, sb, paletteTextureIndex, 0, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, flipx, flipy);
            vertices[nv + 4] = new Vertex(d, r.Left, r.Bottom, sl, sb, paletteTextureIndex, 0, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, flipx, flipy);
            vertices[nv + 5] = new Vertex(a, r.Left, r.Top, sl, st, paletteTextureIndex, 0, drawmode, samplerType, TextureStoreChannel, TextureSlot, SecTextureStoreChannel, SecTextureSlot, flipx, flipy);
        }
示例#3
0
        public static void FastCreateQuadImGui(Vertex[] vertices, float3 a, float3 b, float3 c, float3 d, Sprite r, SamplerPointer samplers, float paletteTextureIndex, int nv)
        {
            float sl = 0;
            float st = 0;
            float sr = 0;
            float sb = 0;

            // See shp.vert for documentation on the channel attribute format
            float ct1 = 0, ct2 = 0, ct3 = 0, ct4 = 0;

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

            // var attribC = r.Channel == TextureChannel.RGBA ? 0x02 : ((byte)r.Channel) << 1 | 0x01;
            // attribC |= samplers.X << 6;
            ct2 = samplers.num1;

            var ss = r as SpriteWithSecondaryData;


            // используется для vDepthMask в шейдере и когда поставлен флаг ОтладкиГлубины SpriteRendere.SetDepthPreviewEnabled ставит у шейдера uniform EnableDepthPreview =true
            if (ss != null)             // тут r трактуется уже как SpriteWithSecondaryData, если преобразование пройдет успешно=> а если нет, то ss = null
            {
                sl = ss.SecondaryLeft;
                st = ss.SecondaryTop;
                sr = ss.SecondaryRight;
                sb = ss.SecondaryBottom;

                // attribC |= ((byte)ss.SecondaryChannel) << 4 | 0x08;
                if (ss.SecondaryChannel == TextureChannel.RGBA)
                {
                    ct3 = 4f;
                }
                else
                {
                    ct3 = (byte)ss.SecondaryChannel;
                }

                // attribC |= samplers.Y << 9;
                ct4 = samplers.numSec;
            }

            int drawmode = 0;

            // Как то передать режим в котором будет рисование.
            if (r.Channel == TextureChannel.RGBA)
            {
                // значит режим рисования RGBA из текстуры
                drawmode = 0;
            }
            else
            {
                drawmode = 1;

                // режим через палитру, в основном из канала R в текстуре идем к цвету в палитре

                // drawmode=2 ставится для рисования прямоугольников и т.п. в RgbaColorRenderer, так как у него свой VBO
            }
            if (r.SpriteType == 1)
            {
                paletteTextureIndex = r.SpriteArrayNum; // положим сюда цифру указывающую на спрайт внутри Texture2dArray в TextureFontMSDF параметра шейдера.
                drawmode            = 3;                // FontMSDF
            }

            drawmode = 5;

            vertices[nv]     = new Vertex(a, r.Left, r.Top, sl, st, paletteTextureIndex, 0, drawmode, 0, ct1, ct2, ct3, ct4, 0, 0);
            vertices[nv + 1] = new Vertex(b, r.Right, r.Top, sr, st, paletteTextureIndex, 0, drawmode, 0, ct1, ct2, ct3, ct4, 0, 0);
            vertices[nv + 2] = new Vertex(c, r.Right, r.Bottom, sr, sb, paletteTextureIndex, 0, drawmode, 0, ct1, ct2, ct3, ct4, 0, 0);
            vertices[nv + 3] = new Vertex(c, r.Right, r.Bottom, sr, sb, paletteTextureIndex, 0, drawmode, 0, ct1, ct2, ct3, ct4, 0, 0);
            vertices[nv + 4] = new Vertex(d, r.Left, r.Bottom, sl, sb, paletteTextureIndex, 0, drawmode, 0, ct1, ct2, ct3, ct4, 0, 0);
            vertices[nv + 5] = new Vertex(a, r.Left, r.Top, sl, st, paletteTextureIndex, 0, drawmode, 0, ct1, ct2, ct3, ct4, 0, 0);
        }