/// <summary> /// Creates a new TextureCubemap instance with faces compatible to the given bitmap. /// </summary> /// <param name="bitmap">Specifies the bitmap to which the new texture will be compatible.</param> /// <param name="texture">Outputs the newly created texture.</param> /// <param name="levels">Specifies the number of mipmap levels.</param> public static void CreateCompatible(Bitmap bitmap, out TextureCubemap texture, int levels = 0) { if (bitmap.Width != bitmap.Height) { throw new ArgumentException("The faces of cube map textures must be square."); } texture = new TextureCubemap(BitmapFormat.Get(bitmap).InternalFormat, bitmap.Width, levels); }
/// <summary> /// Uploads the contents of the bitmaps to all faces of the given cube map level.<br/> /// Will result in an OpenGL error if any of the given bitmaps is incompatible with the textures storage. /// </summary> public static void LoadBitmap(this TextureCubemap texture, Bitmap[] bitmaps, int level = 0) { if (bitmaps.Length != 6) { throw new ArgumentException("Expected exactly 6 bitmaps for a cube map."); } // load all six faces for (var face = 0; face < 6; face++) { texture.LoadBitmap(bitmaps[face], face, level); } }
/// <summary> /// Uploads the contents of a bitmap to a single face of the given cube map level.<br/> /// Will result in an OpenGL error if the given bitmap is incompatible with the textures storage. /// </summary> public static void LoadBitmap(this TextureCubemap texture, Bitmap bitmap, int face, int level = 0) { const TextureTarget firstFace = TextureTarget.TextureCubeMapPositiveX; texture.Bind(); var data = LockBits(bitmap); try { var map = BitmapFormat.Get(bitmap); GL.TexSubImage2D(firstFace + face, level, 0, 0, data.Width, data.Height, map.PixelFormat, map.PixelType, data.Scan0); } finally { bitmap.UnlockBits(data); } CheckError(); }
/// <summary> /// Attaches a single face of the given cube map texture level to the an attachment point. /// </summary> /// <param name="target">The framebuffer target to bind to.</param> /// <param name="attachment">The attachment point to attach to.</param> /// <param name="texture">The texture to attach.</param> /// <param name="face">The cube map face of the texture to attach.</param> /// <param name="level">The level of the texture to attach.</param> public void Attach(FramebufferTarget target, FramebufferAttachment attachment, TextureCubemap texture, int face, int level = 0) { Attach(target, attachment, (LayeredTexture)texture, face, level); }