public void Create(long Key, byte[] Data, GalImage Image) { int Handle = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, Handle); const int Level = 0; //TODO: Support mipmap textures. const int Border = 0; TextureCache.AddOrUpdate(Key, new ImageHandler(Handle, Image), (uint)Data.Length); if (ImageUtils.IsCompressed(Image.Format) && !IsAstc(Image.Format)) { InternalFormat InternalFmt = OGLEnumConverter.GetCompressedImageFormat(Image.Format); GL.CompressedTexImage2D( TextureTarget.Texture2D, Level, InternalFmt, Image.Width, Image.Height, Border, Data.Length, Data); } else { //TODO: Use KHR_texture_compression_astc_hdr when available if (IsAstc(Image.Format)) { int TextureBlockWidth = ImageUtils.GetBlockWidth(Image.Format); int TextureBlockHeight = ImageUtils.GetBlockHeight(Image.Format); Data = ASTCDecoder.DecodeToRGBA8888( Data, TextureBlockWidth, TextureBlockHeight, 1, Image.Width, Image.Height, 1); Image.Format = GalImageFormat.RGBA8 | (Image.Format & GalImageFormat.TypeMask); } (PixelInternalFormat InternalFmt, PixelFormat Format, PixelType Type) = OGLEnumConverter.GetImageFormat(Image.Format); GL.TexImage2D( TextureTarget.Texture2D, Level, InternalFmt, Image.Width, Image.Height, Border, Format, Type, Data); } }
public void Create(long Key, int Size, GalImage Image) { int Handle = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, Handle); const int Level = 0; //TODO: Support mipmap textures. const int Border = 0; TextureCache.AddOrUpdate(Key, new ImageHandler(Handle, Image), (uint)Size); GalImageFormat TypeLess = Image.Format & GalImageFormat.FormatMask; bool IsASTC = TypeLess >= GalImageFormat.ASTC_BEGIN && TypeLess <= GalImageFormat.ASTC_END; if (ImageUtils.IsCompressed(Image.Format) && !IsASTC) { InternalFormat InternalFmt = OGLEnumConverter.GetCompressedImageFormat(Image.Format); GL.CompressedTexImage2D( TextureTarget.Texture2D, Level, InternalFmt, Image.Width, Image.Height, Border, Size, IntPtr.Zero); } else { (PixelInternalFormat InternalFmt, PixelFormat Format, PixelType Type) = OGLEnumConverter.GetImageFormat(Image.Format); GL.TexImage2D( TextureTarget.Texture2D, Level, InternalFmt, Image.Width, Image.Height, Border, Format, Type, IntPtr.Zero); } }
public void Create(long Key, byte[] Data, GalImage Image) { int Handle = GL.GenTexture(); TextureCache.AddOrUpdate(Key, new ImageHandler(Handle, Image), (uint)Data.Length); GL.BindTexture(TextureTarget.Texture2D, Handle); const int Level = 0; //TODO: Support mipmap textures. const int Border = 0; if (IsCompressedTextureFormat(Image.Format)) { InternalFormat InternalFmt = OGLEnumConverter.GetCompressedImageFormat(Image.Format); GL.CompressedTexImage2D( TextureTarget.Texture2D, Level, InternalFmt, Image.Width, Image.Height, Border, Data.Length, Data); } else { if (Image.Format >= GalImageFormat.ASTC_BEGIN && Image.Format <= GalImageFormat.ASTC_END) { int TextureBlockWidth = GetAstcBlockWidth(Image.Format); int TextureBlockHeight = GetAstcBlockHeight(Image.Format); Data = ASTCDecoder.DecodeToRGBA8888( Data, TextureBlockWidth, TextureBlockHeight, 1, Image.Width, Image.Height, 1); Image.Format = GalImageFormat.A8B8G8R8_UNORM_PACK32; } (PixelInternalFormat InternalFormat, PixelFormat Format, PixelType Type) = OGLEnumConverter.GetImageFormat(Image.Format); GL.TexImage2D( TextureTarget.Texture2D, Level, InternalFormat, Image.Width, Image.Height, Border, Format, Type, Data); } int SwizzleR = (int)OGLEnumConverter.GetTextureSwizzle(Image.XSource); int SwizzleG = (int)OGLEnumConverter.GetTextureSwizzle(Image.YSource); int SwizzleB = (int)OGLEnumConverter.GetTextureSwizzle(Image.ZSource); int SwizzleA = (int)OGLEnumConverter.GetTextureSwizzle(Image.WSource); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleR, SwizzleR); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleG, SwizzleG); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleB, SwizzleB); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleA, SwizzleA); }