Exemple #1
0
 /// <summary>
 /// Retrieves the texture data.
 /// </summary>
 public static T[,] GetContent <T>(this Texture2D texture, PixelFormat pixelFormat, PixelType pixelType, int level = 0)
 where T : struct
 {
     var data = new T[texture.Width, texture.Height];
     texture.Bind();
     GL.GetTexImage(texture.TextureTarget, level, pixelFormat, pixelType, data);
     return(data);
 }
Exemple #2
0
        /// <summary>
        /// Uploads the contents of a bitmap to the given texture level.<br/>
        /// Will result in an OpenGL error if the given bitmap is incompatible with the textures storage.
        /// </summary>
        public static void LoadBitmap(this Texture2D texture, Bitmap bitmap, int level = 0)
        {
            texture.Bind();
            var data = LockBits(bitmap);

            try
            {
                var map = BitmapFormat.Get(bitmap);
                GL.TexSubImage2D(texture.TextureTarget, level, 0, 0, data.Width, data.Height,
                                 map.PixelFormat, map.PixelType, data.Scan0);
            }
            finally
            {
                bitmap.UnlockBits(data);
            }
            CheckError();
        }