Esempio n. 1
0
        protected override int CreateTexture(int width, int height, IntPtr scan0, bool managedPool, bool mipmaps)
        {
            D3D.Texture texture = null;
            int         levels  = 1 + (mipmaps ? MipmapsLevels(width, height) : 0);

            if (managedPool)
            {
                texture = device.CreateTexture(width, height, levels, Usage.None, Format.A8R8G8B8, Pool.Managed);
                texture.SetData(0, LockFlags.None, scan0, width * height * 4);
                if (mipmaps)
                {
                    DoMipmaps(texture, 0, 0, width, height, scan0, false);
                }
            }
            else
            {
                D3D.Texture sys = device.CreateTexture(width, height, levels, Usage.None, Format.A8R8G8B8, Pool.SystemMemory);
                sys.SetData(0, LockFlags.None, scan0, width * height * 4);
                if (mipmaps)
                {
                    DoMipmaps(sys, 0, 0, width, height, scan0, false);
                }

                texture = device.CreateTexture(width, height, levels, Usage.None, Format.A8R8G8B8, Pool.Default);
                device.UpdateTexture(sys, texture);
                sys.Dispose();
            }
            return(GetOrExpand(ref textures, texture, texBufferSize));
        }
        protected override int CreateTexture(int width, int height, IntPtr scan0, bool managedPool)
        {
            Pool pool = managedPool ? Pool.Managed : Pool.Default;

            D3D.Texture texture = device.CreateTexture(width, height, 0, Usage.None, Format.A8R8G8B8, pool);
            texture.SetData(0, LockFlags.None, scan0, width * height * 4);
            return(GetOrExpand(ref textures, texture, texBufferSize));
        }
Esempio n. 3
0
        unsafe void DoMipmaps(D3D.Texture texture, int x, int y, int width,
                              int height, IntPtr scan0, bool partial)
        {
            IntPtr prev = scan0;
            int    lvls = MipmapsLevels(width, height);

            for (int lvl = 1; lvl <= lvls; lvl++)
            {
                x /= 2; y /= 2;
                if (width > 1)
                {
                    width /= 2;
                }
                if (height > 1)
                {
                    height /= 2;
                }
                int size = width * height * 4;

                IntPtr cur = Marshal.AllocHGlobal(size);
                GenMipmaps(width, height, cur, prev);

                if (partial)
                {
                    texture.SetPartData(lvl, LockFlags.None, cur, x, y, width, height);
                }
                else
                {
                    texture.SetData(lvl, LockFlags.None, cur, size);
                }

                if (prev != scan0)
                {
                    Marshal.FreeHGlobal(prev);
                }
                prev = cur;
            }
            if (prev != scan0)
            {
                Marshal.FreeHGlobal(prev);
            }
        }
Esempio n. 4
0
 public override int CreateTexture(int width, int height, IntPtr scan0)
 {
     D3D.Texture texture = device.CreateTexture(width, height, 0, Usage.None, Format.A8R8G8B8, Pool.Managed);
     texture.SetData(0, LockFlags.None, scan0, width * height * 4);
     return(GetOrExpand(ref textures, texture, texBufferSize));
 }