Пример #1
0
        public virtual BaseTexture Add(ByteArraySegment buffer, BasePicture picture)
        {
            var textureNumber = this.Allocate(picture.Width, picture.Height, out var x, out var y);

            var source = new RectangleF( );

            source.X      = ( float )((x + 0.01) / ( float )this.Height);
            source.Width  = picture.Width / ( float )this.Width;
            source.Y      = ( float )((y + 0.01) / ( float  )this.Height);
            source.Height = picture.Height / ( float )this.Height;

            picture.Source = source;

            this.IsDirty = true;

            var k = 0;

            for (var i = 0; i < picture.Height; i++)
            {
                for (var j = 0; j < picture.Width; j++, k++)
                {
                    this.Texels[textureNumber][(y + i) * this.Width + x + j] = buffer.Data[buffer.StartIndex + k];  // p->data[k];
                }
            }

            this.Upload(true);

            return(this.Textures[textureNumber]);
        }
Пример #2
0
        public virtual BaseTexture Add(ByteArraySegment buffer, BasePicture picture)
        {
            var textureNumber = Allocate(picture.Width, picture.Height, out var x, out var y);

            var source = new System.Drawing.RectangleF( );

            source.X      = ( Single )((x + 0.01) / ( Single )Height);
            source.Width  = (picture.Width) / ( Single )Width;
            source.Y      = ( Single )((y + 0.01) / ( Single  )Height);
            source.Height = (picture.Height) / ( Single )Height;

            picture.Source = source;

            IsDirty = true;

            var k = 0;

            for (var i = 0; i < picture.Height; i++)
            {
                for (var j = 0; j < picture.Width; j++, k++)
                {
                    Texels[textureNumber][(y + i) * Width + x + j] = buffer.Data[buffer.StartIndex + k];  // p->data[k];
                }
            }

            Upload(true);

            return(Textures[textureNumber]);
        }
Пример #3
0
        public static BaseTexture FromBuffer(BaseDevice device, BasePicture picture, UInt32[] buffer, String filter = "GL_LINEAR_MIPMAP_NEAREST", Boolean isLightMap = false)
        {
            if (picture.Source.Width <= 0)
            {
                picture.Source = new RectangleF(0, 0, 1, 1);
            }

            if (String.IsNullOrEmpty(picture.Identifier))
            {
                picture.Identifier = Guid.NewGuid( ).ToString( );
            }

            return(FromBuffer(device, picture.Identifier, buffer, picture.Width, picture.Height, false, true, filter: filter, isLightMap: isLightMap));
        }
Пример #4
0
        /// <summary>
        /// GL_LoadPicTexture
        /// </summary>
        public static BaseTexture FromBuffer(BaseDevice device, BasePicture picture, ByteArraySegment buffer, string filter = "GL_LINEAR_MIPMAP_NEAREST", bool isLightMap = false)
        {
            if (picture.Source.Width <= 0)
            {
                picture.Source = new(0, 0, 1, 1);
            }

            if (string.IsNullOrEmpty(picture.Identifier))
            {
                picture.Identifier = Guid.NewGuid( ).ToString( );
            }

            return(BaseTexture.FromBuffer(device, picture.Identifier, buffer, picture.Width, picture.Height, false, true, filter, isLightMap: isLightMap));
        }
Пример #5
0
        //qpic_t *Draw_PicFromWad (char *name);
        public static BasePicture FromWad(BaseDevice device, Wad wad, string name, string filter = "GL_LINEAR_MIPMAP_NEAREST")
        {
            if (BasePicture.PicturePool.ContainsKey(name))
            {
                return(BasePicture.PicturePool[name]);
            }

            var offset = wad.GetLumpNameOffset(name);
            var ptr    = new IntPtr(wad.DataPointer.ToInt64( ) + offset);
            var header = ( WadPicHeader )Marshal.PtrToStructure(ptr, typeof(WadPicHeader));

            offset += Marshal.SizeOf(typeof(WadPicHeader));

            return(BasePicture.FromBuffer(device, new(wad.Data, offset), header.width, header.height, name, filter));
        }
Пример #6
0
        public static BasePicture FromFile(BaseDevice device, string path, string filter = "GL_LINEAR_MIPMAP_NEAREST", bool ignoreAtlas = false)
        {
            if (BasePicture.PicturePool.ContainsKey(path))
            {
                return(BasePicture.PicturePool[path]);
            }

            var data = FileSystem.LoadFile(path);

            if (data == null)
            {
                Utilities.Error($"BaseTexture_FromFile: failed to load {path}");
            }

            var ext = Path.GetExtension(path).ToLower( ).Substring(1);

            switch (ext)
            {
            case "lmp":
                var header = Utilities.BytesToStructure <WadPicHeader>(data, 0);

                EndianHelper.SwapPic(header);

                var headerSize = Marshal.SizeOf(typeof(WadPicHeader));

                return(BasePicture.FromBuffer(device, new(data, headerSize), ( int )header.width, ( int )header.height, path, filter, ignoreAtlas));

            case "jpg":
            case "bmp":
            case "png":
                break;

            case "tga":
                break;
            }

            return(null);
        }
Пример #7
0
        public static BasePicture FromBuffer(BaseDevice device, ByteArraySegment buffer, int width, int height, string identifier = null, string filter = "GL_LINEAR_MIPMAP_NEAREST", bool ignoreAtlas = false)
        {
            if (BasePicture.PicturePool.ContainsKey(identifier))
            {
                return(BasePicture.PicturePool[identifier]);
            }

            var picture = new BasePicture( );

            picture.Width      = width;
            picture.Height     = height;
            picture.Identifier = identifier;

            if (!ignoreAtlas && picture.Width < 64 && picture.Height < 64)
            {
                picture.Texture = device.TextureAtlas.Add(buffer, picture);
            }
            else
            {
                picture.Texture = BaseTexture.FromBuffer(device, picture, buffer, filter);
            }

            return(picture);
        }