예제 #1
0
        /// <summary>
        /// Creates an empty texture.
        /// </summary>
        /// <param name="width">Width of texture in pixel.</param>
        /// <param name="height">Height of texture in pixel.</param>
        /// <param name="mipLevels">Number of mip levels.</param>
        /// <param name="format">Format to use for texture.</param>
        /// <param name="usage">Special texture usage.</param>
        /// <returns>New texture.</returns>
        public ITexture2d Create(int width, int height, int mipLevels, Purple.Graphics.Format format, Purple.Graphics.TextureUsage usage)
        {
            ITexture2d tex = textureLoader.Create(width, height, mipLevels, format, usage);

            textures.Add(new WeakReference(tex));
            return(tex);
        }
예제 #2
0
        /// <summary>
        /// loads a texture from a stream containing raw bitmap data
        /// </summary>
        /// <param name="stream">stream to load from</param>
        /// <param name="width">width of texture</param>
        /// <param name="height">height of texture</param>
        /// <param name="mipLevels">number of MipMap level</param>
        /// <param name="format">format of texture</param>
        /// <returns>texture object</returns>
        private ITexture2d LoadRaw(Stream stream, int width, int height, int mipLevels, Purple.Graphics.Format format)
        {
            int countBytes = width * height * Purple.Graphics.GraphicsEngine.BitsPerPixel(format) / 8;

            byte[] data = new Byte[countBytes];
            stream.Read(data, 0, countBytes);

            System.Drawing.Bitmap bitmap;
            // pin array
            System.Runtime.InteropServices.GCHandle handle = System.Runtime.InteropServices.GCHandle.Alloc(data);
            System.IntPtr ptr = System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(data, 0);
            bitmap = new System.Drawing.Bitmap(width, height, width * 3, System.Drawing.Imaging.PixelFormat.Format24bppRgb, ptr);

            ITexture2d tex = TextureManager.Instance.Create(width, height, 1, Format.A8R8G8B8, TextureUsage.Normal);

            tex.CopyBitmap(bitmap, new System.Drawing.Rectangle(0, 0, width, height), System.Drawing.Point.Empty);
            bitmap.Dispose();
            handle.Free();
            return(tex);
        }