bool GetSupportedDepthFormat(out MgFormat depthFormat) { // Since all depth formats may be optional, we need to find a suitable depth format to use // Start with the highest precision packed format MgFormat[] depthFormats = { MgFormat.D32_SFLOAT_S8_UINT, MgFormat.D32_SFLOAT, MgFormat.D24_UNORM_S8_UINT, MgFormat.D16_UNORM_S8_UINT, MgFormat.D16_UNORM }; Debug.Assert(mGraphicsConfiguration.Partition != null); foreach (var format in depthFormats) { MgFormatProperties formatProps; mGraphicsConfiguration.Partition.PhysicalDevice.GetPhysicalDeviceFormatProperties(format, out formatProps); // Format must support depth stencil attachment for optimal tiling if ((formatProps.OptimalTilingFeatures & MgFormatFeatureFlagBits.DEPTH_STENCIL_ATTACHMENT_BIT) == MgFormatFeatureFlagBits.DEPTH_STENCIL_ATTACHMENT_BIT) { depthFormat = format; return(true); } } depthFormat = MgFormat.UNDEFINED; return(false); }
public int CreateTextureStorage3D(int levels, MgFormat format, int width, int height, int depth) { var internalFormat = GetInternalFormat(format); int[] textureId = new int[1]; GL.CreateTextures(TextureTarget.Texture3D, 1, textureId); GL.Ext.TextureStorage3D(textureId [0], (ExtDirectStateAccess)All.Texture3D, levels, internalFormat, width, height, depth); return(textureId [0]); }
static GLClearAttachmentType GetAttachmentType(MgFormat format) { switch (format) { case MgFormat.D16_UNORM: case MgFormat.D16_UNORM_S8_UINT: case MgFormat.D24_UNORM_S8_UINT: case MgFormat.D32_SFLOAT: case MgFormat.D32_SFLOAT_S8_UINT: return(GLClearAttachmentType.DEPTH_STENCIL); case MgFormat.R8_SINT: case MgFormat.R8G8_SINT: case MgFormat.R8G8B8_SINT: case MgFormat.R8G8B8A8_SINT: case MgFormat.R16_SINT: case MgFormat.R16G16_SINT: case MgFormat.R16G16B16_SINT: case MgFormat.R16G16B16A16_SINT: case MgFormat.R32_SINT: case MgFormat.R32G32_SINT: case MgFormat.R32G32B32_SINT: case MgFormat.R32G32B32A32_SINT: case MgFormat.R64_SINT: case MgFormat.R64G64_SINT: case MgFormat.R64G64B64_SINT: case MgFormat.R64G64B64A64_SINT: return(GLClearAttachmentType.COLOR_INT); case MgFormat.R8_UINT: case MgFormat.R8G8_UINT: case MgFormat.R8G8B8_UINT: case MgFormat.R8G8B8A8_UINT: case MgFormat.R16_UINT: case MgFormat.R16G16_UINT: case MgFormat.R16G16B16_UINT: case MgFormat.R16G16B16A16_UINT: case MgFormat.R32_UINT: case MgFormat.R64_UINT: return(GLClearAttachmentType.COLOR_UINT); case MgFormat.R32_SFLOAT: case MgFormat.R32G32_SFLOAT: case MgFormat.R32G32B32_SFLOAT: case MgFormat.R32G32B32A32_SFLOAT: return(GLClearAttachmentType.COLOR_FLOAT); default: throw new NotSupportedException(); } }
public GLImage(IGLDeviceImageEntrypoint entrypoint, int textureId, MgImageType imageType, MgFormat format, int width, int height, int depth, int levels, int arrayLayers) { mEntrypoint = entrypoint; mTextureId = textureId; mFormat = format; mImageType = imageType; //mInternalFormat = internalFormat; mWidth = width; mHeight = height; mDepth = depth; mLevels = levels; mLayers = arrayLayers; GenerateMipmapLevels(); }
public static bool IsStencilFormat(MgFormat format) { switch (format) { default: return(false); case MgFormat.S8_UINT: //return MTLPixelFormat.Stencil8; case MgFormat.D24_UNORM_S8_UINT: //return MTLPixelFormat.Depth24Unorm_Stencil8; case MgFormat.D32_SFLOAT_S8_UINT: //return MTLPixelFormat.Depth32Float_Stencil8; return(true); } }
int GetStencilBit(MgFormat format) { switch (format) { case MgFormat.D16_UNORM: case MgFormat.D32_SFLOAT: return(0); case MgFormat.D16_UNORM_S8_UINT: case MgFormat.D24_UNORM_S8_UINT: case MgFormat.D32_SFLOAT_S8_UINT: return(8); default: throw new NotSupportedException(); } }
int GetDepthBit(MgFormat format) { switch (format) { case MgFormat.D16_UNORM: case MgFormat.D16_UNORM_S8_UINT: return(16); case MgFormat.D24_UNORM_S8_UINT: return(24); case MgFormat.D32_SFLOAT: case MgFormat.D32_SFLOAT_S8_UINT: return(32); default: throw new NotSupportedException(); } }
public static MTLVertexFormat GetVertexFormat(MgFormat format) { switch (format) { default: throw new NotSupportedException(); case MgFormat.UNDEFINED: return(MTLVertexFormat.Invalid); case MgFormat.R8G8_UINT: return(MTLVertexFormat.UChar2); case MgFormat.R8G8B8_UINT: case MgFormat.B8G8R8_UINT: return(MTLVertexFormat.UChar3); case MgFormat.R8G8B8A8_UINT: case MgFormat.B8G8R8A8_UINT: return(MTLVertexFormat.UChar4); case MgFormat.R8G8_SINT: return(MTLVertexFormat.Char2); case MgFormat.R8G8B8_SINT: case MgFormat.B8G8R8_SINT: return(MTLVertexFormat.Char3); case MgFormat.R8G8B8A8_SINT: case MgFormat.B8G8R8A8_SINT: return(MTLVertexFormat.Char4); case MgFormat.R8G8_UNORM: return(MTLVertexFormat.UChar2Normalized); case MgFormat.R8G8B8_UNORM: case MgFormat.B8G8R8_UNORM: return(MTLVertexFormat.UChar3Normalized); case MgFormat.R8G8B8A8_UNORM: case MgFormat.B8G8R8A8_UNORM: return(MTLVertexFormat.UChar4Normalized); case MgFormat.R8G8_SNORM: return(MTLVertexFormat.Char2Normalized); case MgFormat.R8G8B8_SNORM: case MgFormat.B8G8R8_SNORM: return(MTLVertexFormat.Char3Normalized); case MgFormat.R8G8B8A8_SNORM: case MgFormat.B8G8R8A8_SNORM: return(MTLVertexFormat.Char4Normalized); case MgFormat.R16G16_UINT: return(MTLVertexFormat.UShort2); case MgFormat.R16G16B16_UINT: return(MTLVertexFormat.UShort3); case MgFormat.R16G16B16A16_UINT: return(MTLVertexFormat.UShort4); case MgFormat.R16G16_SINT: return(MTLVertexFormat.Short2); case MgFormat.R16G16B16_SINT: return(MTLVertexFormat.Short3); case MgFormat.R16G16B16A16_SINT: return(MTLVertexFormat.Short4); case MgFormat.R16G16_UNORM: return(MTLVertexFormat.UShort2Normalized); case MgFormat.R16G16B16_UNORM: return(MTLVertexFormat.UShort3Normalized); case MgFormat.R16G16B16A16_UNORM: return(MTLVertexFormat.UShort4Normalized); case MgFormat.R16G16_SNORM: return(MTLVertexFormat.Short2Normalized); case MgFormat.R16G16B16_SNORM: return(MTLVertexFormat.Short3Normalized); case MgFormat.R16G16B16A16_SNORM: return(MTLVertexFormat.Short4Normalized); case MgFormat.R16G16_SFLOAT: return(MTLVertexFormat.Half2); case MgFormat.R16G16B16_SFLOAT: return(MTLVertexFormat.Half3); case MgFormat.R16G16B16A16_SFLOAT: return(MTLVertexFormat.Half4); case MgFormat.R32_SFLOAT: return(MTLVertexFormat.Float); case MgFormat.R32G32_SFLOAT: return(MTLVertexFormat.Float2); case MgFormat.R32G32B32_SFLOAT: return(MTLVertexFormat.Float3); case MgFormat.R32G32B32A32_SFLOAT: return(MTLVertexFormat.Float4); case MgFormat.R32_SINT: return(MTLVertexFormat.Int); case MgFormat.R32G32_SINT: return(MTLVertexFormat.Int2); case MgFormat.R32G32B32_SINT: return(MTLVertexFormat.Int3); case MgFormat.R32G32B32A32_SINT: return(MTLVertexFormat.Int4); case MgFormat.R32_UINT: return(MTLVertexFormat.UInt); case MgFormat.R32G32_UINT: return(MTLVertexFormat.UInt2); case MgFormat.R32G32B32_UINT: return(MTLVertexFormat.UInt3); case MgFormat.R32G32B32A32_UINT: return(MTLVertexFormat.UInt4); case MgFormat.A2R10G10B10_SNORM_PACK32: case MgFormat.A2B10G10R10_SNORM_PACK32: return(MTLVertexFormat.Int1010102Normalized); case MgFormat.A2R10G10B10_UNORM_PACK32: case MgFormat.A2B10G10R10_UNORM_PACK32: return(MTLVertexFormat.UInt1010102Normalized); } }
public static MgClearValue FromColorAndFormat(MgFormat format, MgColor4f color) { float factor = 0; MgClearColorCategory category; switch (format) { case MgFormat.R8_SINT: case MgFormat.R8G8_SINT: case MgFormat.R8G8B8_SINT: case MgFormat.R8G8B8A8_SINT: case MgFormat.B8G8R8_SINT: case MgFormat.B8G8R8A8_SINT: factor = sbyte.MaxValue; category = MgClearColorCategory.INT; break; case MgFormat.R16_SINT: case MgFormat.R16G16_SINT: case MgFormat.R16G16B16_SINT: case MgFormat.R16G16B16A16_SINT: factor = short.MaxValue; category = MgClearColorCategory.INT; break; case MgFormat.R32_SINT: case MgFormat.R32G32_SINT: case MgFormat.R32G32B32_SINT: case MgFormat.R32G32B32A32_SINT: factor = int.MaxValue; category = MgClearColorCategory.INT; break; case MgFormat.R64_SINT: case MgFormat.R64G64_SINT: case MgFormat.R64G64B64_SINT: case MgFormat.R64G64B64A64_SINT: factor = long.MaxValue; category = MgClearColorCategory.INT; break; case MgFormat.R8_UINT: case MgFormat.R8G8_UINT: case MgFormat.R8G8B8_UINT: case MgFormat.R8G8B8A8_UINT: case MgFormat.B8G8R8_UINT: case MgFormat.B8G8R8A8_UINT: factor = byte.MaxValue; category = MgClearColorCategory.UINT; break; case MgFormat.R16_UINT: case MgFormat.R16G16_UINT: case MgFormat.R16G16B16_UINT: case MgFormat.R16G16B16A16_UINT: factor = ushort.MaxValue; category = MgClearColorCategory.UINT; break; case MgFormat.R32_UINT: case MgFormat.R32G32_UINT: case MgFormat.R32G32B32_UINT: case MgFormat.R32G32B32A32_UINT: factor = uint.MaxValue; category = MgClearColorCategory.UINT; break; case MgFormat.R64_UINT: case MgFormat.R64G64_UINT: case MgFormat.R64G64B64_UINT: case MgFormat.R64G64B64A64_UINT: factor = long.MaxValue; category = MgClearColorCategory.UINT; break; case MgFormat.R8_SNORM: case MgFormat.R8G8_SNORM: case MgFormat.R8G8B8_SNORM: case MgFormat.R8G8B8A8_SNORM: case MgFormat.R16_SNORM: case MgFormat.R16G16_SNORM: case MgFormat.R16G16B16_SNORM: case MgFormat.R16G16B16A16_SNORM: case MgFormat.R8_UNORM: case MgFormat.R8G8_UNORM: case MgFormat.R8G8B8_UNORM: case MgFormat.R8G8B8A8_UNORM: case MgFormat.R16_UNORM: case MgFormat.R16G16_UNORM: case MgFormat.R16G16B16_UNORM: case MgFormat.R16G16B16A16_UNORM: case MgFormat.B8G8R8_UNORM: case MgFormat.B8G8R8A8_UNORM: case MgFormat.R32_SFLOAT: case MgFormat.R32G32_SFLOAT: case MgFormat.R32G32B32_SFLOAT: case MgFormat.R32G32B32A32_SFLOAT: case MgFormat.R64_SFLOAT: case MgFormat.R64G64_SFLOAT: case MgFormat.R64G64B64_SFLOAT: case MgFormat.R64G64B64A64_SFLOAT: factor = 1f; category = MgClearColorCategory.FLOAT; break; default: throw new NotSupportedException(); } switch (category) { case MgClearColorCategory.INT: return(new MgClearValue { Color = new MgClearColorValue(new MgVec4i((int)(color.R * factor), (int)(color.G * factor), (int)(color.B * factor), (int)(color.A * factor))) }); case MgClearColorCategory.UINT: return(new MgClearValue { Color = new MgClearColorValue(new MgVec4Ui((uint)(color.R * factor), (uint)(color.G * factor), (uint)(color.B * factor), (uint)(color.A * factor))) }); case MgClearColorCategory.FLOAT: return(new MgClearValue { Color = new MgClearColorValue(new MgColor4f(color.R * factor, color.G * factor, color.B * factor, color.A * factor)) }); default: throw new NotSupportedException(); } }
public GLInternalImageFormat GetGLFormat(MgFormat format, bool supportsSRgb) { // InternalFormat = (int) PixelInternalFormat.Rgba; // GLFormat = (int) PixelFormat.Rgba; // GLType = (int) PixelType.UnsignedByte; switch (format) { case MgFormat.R8G8B8_UINT: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.Rgb8ui, GLFormat = (int)PixelFormat.RgbInteger, GLType = (int)PixelType.UnsignedByte, }); case MgFormat.R8G8B8A8_UINT: //case SurfaceFormat.Color: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.Rgba8ui, GLFormat = (int)PixelFormat.RgbaInteger, GLType = (int)PixelType.UnsignedByte, }); case MgFormat.R8G8B8A8_SRGB: //case SurfaceFormat.ColorSRgb: if (!supportsSRgb) { //goto case SurfaceFormat.Color; goto case MgFormat.R8G8B8A8_UINT; } return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.Srgb, //(PixelInternalFormat) 0x8C40; // (int) PixelInternalFormat.Srgb; GLFormat = (int)PixelFormat.Rgba, GLType = (int)PixelType.UnsignedByte, }); case MgFormat.B5G6R5_UNORM_PACK16: //case SurfaceFormat.Bgr565: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.Rgb, GLFormat = (int)PixelFormat.Rgb, GLType = (int)PixelType.UnsignedShort565, }); case MgFormat.B4G4R4A4_UNORM_PACK16: //case SurfaceFormat.Bgra4444: return(new GLInternalImageFormat { #if IOS || ANDROID InternalFormat = (int)PixelInternalFormat.Rgba, #else InternalFormat = (int)PixelInternalFormat.Rgba4, #endif GLFormat = (int)PixelFormat.Rgba, GLType = (int)PixelType.UnsignedShort4444, }); case MgFormat.B5G5R5A1_UNORM_PACK16: return(new GLInternalImageFormat { //case SurfaceFormat.Bgra5551: InternalFormat = (int)PixelInternalFormat.Rgba, GLFormat = (int)PixelFormat.Rgba, GLType = (int)PixelType.UnsignedShort5551, }); case MgFormat.R8_UINT: return(new GLInternalImageFormat { //case SurfaceFormat.Alpha8: InternalFormat = (int)PixelInternalFormat.Luminance, GLFormat = (int)PixelFormat.Luminance, GLType = (int)PixelType.UnsignedByte, }); #if !IOS && !ANDROID && !ANGLE case MgFormat.BC1_RGB_UNORM_BLOCK: return(new GLInternalImageFormat { //case SurfaceFormat.Dxt1: InternalFormat = (int)PixelInternalFormat.CompressedRgbS3tcDxt1Ext, GLFormat = (int)All.CompressedTextureFormats, GLType = (int)PixelType.UnsignedByte, // DEFAULT }); case MgFormat.BC1_RGB_SRGB_BLOCK: // case SurfaceFormat.Dxt1SRgb: if (!supportsSRgb) { //goto case SurfaceFormat.Dxt1; goto case MgFormat.BC1_RGB_SRGB_BLOCK; } return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.CompressedSrgbS3tcDxt1Ext, GLFormat = (int)All.CompressedTextureFormats, GLType = (int)PixelType.UnsignedByte, // DEFAULT }); case MgFormat.BC1_RGBA_UNORM_BLOCK: //case SurfaceFormat.Dxt1a: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.CompressedRgbaS3tcDxt1Ext, GLFormat = (int)All.CompressedTextureFormats, GLType = (int)PixelType.UnsignedByte, // DEFAULT }); case MgFormat.BC2_UNORM_BLOCK: //case SurfaceFormat.Dxt3: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.CompressedRgbaS3tcDxt3Ext, GLFormat = (int)All.CompressedTextureFormats, GLType = (int)PixelType.UnsignedByte, // DEFAULT }); case MgFormat.BC2_SRGB_BLOCK: //case SurfaceFormat.Dxt3SRgb: if (!supportsSRgb) { goto case MgFormat.BC2_UNORM_BLOCK; } // goto case SurfaceFormat.Dxt3; return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.CompressedSrgbAlphaS3tcDxt3Ext, GLFormat = (int)All.CompressedTextureFormats, GLType = (int)PixelType.UnsignedByte, // DEFAULT }); case MgFormat.BC3_UNORM_BLOCK: //case SurfaceFormat.Dxt5: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.CompressedRgbaS3tcDxt5Ext, GLFormat = (int)All.CompressedTextureFormats, GLType = (int)PixelType.UnsignedByte, // DEFAULT }); case MgFormat.BC3_SRGB_BLOCK: //case SurfaceFormat.Dxt5SRgb: if (!supportsSRgb) { goto case MgFormat.BC3_UNORM_BLOCK; } //goto case SurfaceFormat.Dxt5; return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.CompressedSrgbAlphaS3tcDxt5Ext, GLFormat = (int)All.CompressedTextureFormats, GLType = (int)PixelType.UnsignedByte, // DEFAULT }); case MgFormat.R32_SFLOAT: // case SurfaceFormat.Single: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.R32f, GLFormat = (int)PixelFormat.Red, GLType = (int)PixelType.Float, }); case MgFormat.R16G16_SFLOAT: // case SurfaceFormat.HalfVector2: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.Rg16f, GLFormat = (int)PixelFormat.Rg, GLType = (int)PixelType.HalfFloat, }); // HdrBlendable implemented as HalfVector4 (see http://blogs.msdn.com/b/shawnhar/archive/2010/07/09/surfaceformat-hdrblendable.aspx) case MgFormat.R16G16B16A16_SFLOAT: //case SurfaceFormat.HdrBlendable: //case SurfaceFormat.HalfVector4: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.Rgba16f, GLFormat = (int)PixelFormat.Rgba, GLType = (int)PixelType.HalfFloat, }); case MgFormat.R16_SFLOAT: //case SurfaceFormat.HalfSingle: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.R16f, GLFormat = (int)PixelFormat.Red, GLType = (int)PixelType.HalfFloat, }); case MgFormat.R32G32_SFLOAT: //case SurfaceFormat.Vector2: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.Rg32f, GLFormat = (int)PixelFormat.Rg, GLType = (int)PixelType.Float, }); case MgFormat.R32G32B32A32_SFLOAT: //case SurfaceFormat.Vector4: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.Rgba32f, GLFormat = (int)PixelFormat.Rgba, GLType = (int)PixelType.Float, }); case MgFormat.R8G8_SNORM: //case SurfaceFormat.NormalizedByte2: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.Rg8i, GLFormat = (int)PixelFormat.Rg, GLType = (int)PixelType.Byte, }); case MgFormat.R8G8B8A8_SNORM: //case SurfaceFormat.NormalizedByte4: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.Rgba8i, GLFormat = (int)PixelFormat.Rgba, GLType = (int)PixelType.Byte, }); case MgFormat.R16G16_UINT: //case SurfaceFormat.Rg32: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.Rg16ui, GLFormat = (int)PixelFormat.RgInteger, GLType = (int)PixelType.UnsignedShort, }); case MgFormat.R16G16B16A16_UINT: //case SurfaceFormat.Rgba64: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.Rgba16ui, GLFormat = (int)PixelFormat.RgbaInteger, GLType = (int)PixelType.UnsignedShort, }); case MgFormat.A2B10G10R10_UINT_PACK32: //case SurfaceFormat.Rgba1010102: return(new GLInternalImageFormat { InternalFormat = (int)PixelInternalFormat.Rgb10A2ui, GLFormat = (int)PixelFormat.Rgba, GLType = (int)PixelType.UnsignedInt1010102, }); #endif // #if !(IOS || ANDROID) // // TODO : find compatible VKFormat // case SurfaceFormat.RgbPvrtc2Bpp: // return new GLImageFormat // { // InternalFormat = (PixelInternalFormat)All.CompressedRgbPvrtc2Bppv1Img, // GLFormat = (int) All.CompressedTextureFormats, //// GLType = PixelType.UnsignedByte, // DEFAULT // }; // case SurfaceFormat.RgbPvrtc4Bpp: // return new GLImageFormat // { // InternalFormat = (PixelInternalFormat)All.CompressedRgbPvrtc4Bppv1Img, // GLFormat = (int) All.CompressedTextureFormats, //// GLType = PixelType.UnsignedByte, // DEFAULT // }; // break; // case SurfaceFormat.RgbaPvrtc2Bpp: // return new GLImageFormat // { // InternalFormat = (PixelInternalFormat)All.CompressedRgbaPvrtc2Bppv1Img, // GLFormat = (int) All.CompressedTextureFormats, //// GLType = PixelType.UnsignedByte, // DEFAULT // }; // case SurfaceFormat.RgbaPvrtc4Bpp: // return new GLImageFormat // { // InternalFormat = (PixelInternalFormat)All.CompressedRgbaPvrtc4Bppv1Img, // GLFormat = (int) All.CompressedTextureFormats, //// GLType = PixelType.UnsignedByte, // DEFAULT // }; // #endif default: throw new NotSupportedException(); } }
void loadTexture(string fileName, MgFormat format) { IMgImageTools imageTools = new Magnesium.MgImageTools(); IMgTextureGenerator optimizer = new Magnesium.MgStagingBufferOptimizer(mManager.Configuration, imageTools); IKTXTextureLoader loader = new KTXTextureManager(optimizer, mManager.Configuration); using (var fs = System.IO.File.OpenRead(fileName)) { var result = loader.Load(fs); // Create sampler // In Vulkan textures are accessed by samplers // This separates all the sampling information from the // texture data // This means you could have multiple sampler objects // for the same texture with different settings // Similar to the samplers available with OpenGL 3.3 var samplerCreateInfo = new MgSamplerCreateInfo { MagFilter = MgFilter.LINEAR, MinFilter = MgFilter.LINEAR, MipmapMode = MgSamplerMipmapMode.LINEAR, AddressModeU = MgSamplerAddressMode.REPEAT, AddressModeV = MgSamplerAddressMode.REPEAT, AddressModeW = MgSamplerAddressMode.REPEAT, MipLodBias = 0.0f, CompareOp = MgCompareOp.NEVER, MinLod = 0.0f, BorderColor = MgBorderColor.FLOAT_OPAQUE_WHITE, }; // Set max level-of-detail to mip level count of the texture var mipLevels = (uint)result.Source.Mipmaps.Length; samplerCreateInfo.MaxLod = (float)mipLevels; // Enable anisotropic filtering // This feature is optional, so we must check if it's supported on the device //mManager.Configuration.Partition. if (mFeatures.SamplerAnisotropy) { // Use max. level of anisotropy for this example samplerCreateInfo.MaxAnisotropy = mPhysicalDeviceProperties.Limits.MaxSamplerAnisotropy; samplerCreateInfo.AnisotropyEnable = true; } else { // The device does not support anisotropic filtering samplerCreateInfo.MaxAnisotropy = 1.0f; samplerCreateInfo.AnisotropyEnable = false; } IMgSampler sampler; var err = mManager.Configuration.Device.CreateSampler(samplerCreateInfo, null, out sampler); Debug.Assert(err == Result.SUCCESS); // Create image view // Textures are not directly accessed by the shaders and // are abstracted by image views containing additional // information and sub resource ranges var viewCreateInfo = new MgImageViewCreateInfo { Image = result.TextureInfo.Image, // TODO : FETCH VIEW TYPE FROM KTX ViewType = MgImageViewType.TYPE_2D, Format = result.Source.Format, Components = new MgComponentMapping { R = MgComponentSwizzle.R, G = MgComponentSwizzle.G, B = MgComponentSwizzle.B, A = MgComponentSwizzle.A, }, // The subresource range describes the set of mip levels (and array layers) that can be accessed through this image view // It's possible to create multiple image views for a single image referring to different (and/or overlapping) ranges of the image SubresourceRange = new MgImageSubresourceRange { AspectMask = MgImageAspectFlagBits.COLOR_BIT, BaseMipLevel = 0, BaseArrayLayer = 0, LayerCount = 1, LevelCount = mipLevels, } }; IMgImageView view; err = mManager.Configuration.Device.CreateImageView(viewCreateInfo, null, out view); Debug.Assert(err == Result.SUCCESS); texture = new Texture { image = result.TextureInfo.Image, imageLayout = result.TextureInfo.ImageLayout, deviceMemory = result.TextureInfo.DeviceMemory, sampler = sampler, width = result.Source.Width, height = result.Source.Height, mipLevels = mipLevels, view = view, descriptor = new MgDescriptorImageInfo { ImageLayout = MgImageLayout.GENERAL, ImageView = view, Sampler = sampler, } }; } }
static GLVertexAttributeInfo GetAttributeFormat(MgFormat format) { switch (format) { case MgFormat.R8_SINT: return(new GLVertexAttributeInfo { Size = 1, IsNormalized = false, PointerType = GLVertexAttributeType.Byte, Function = GLVertexAttribFunction.INT, }); case MgFormat.R8G8_SINT: return(new GLVertexAttributeInfo { Size = 2, IsNormalized = false, PointerType = GLVertexAttributeType.Byte, Function = GLVertexAttribFunction.INT, }); case MgFormat.R8G8B8_SINT: case MgFormat.B8G8R8_SINT: // TODO : swizzle return(new GLVertexAttributeInfo { Size = 3, IsNormalized = false, PointerType = GLVertexAttributeType.Byte, Function = GLVertexAttribFunction.INT, }); case MgFormat.R8G8B8A8_SINT: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = false, PointerType = GLVertexAttributeType.Byte, Function = GLVertexAttribFunction.INT, }); case MgFormat.R16_SINT: return(new GLVertexAttributeInfo { Size = 1, IsNormalized = false, PointerType = GLVertexAttributeType.Short, Function = GLVertexAttribFunction.INT, }); case MgFormat.R16G16_SINT: return(new GLVertexAttributeInfo { Size = 2, IsNormalized = false, PointerType = GLVertexAttributeType.Short, Function = GLVertexAttribFunction.INT, }); case MgFormat.R16G16B16_SINT: return(new GLVertexAttributeInfo { Size = 3, IsNormalized = false, PointerType = GLVertexAttributeType.Short, Function = GLVertexAttribFunction.INT, }); case MgFormat.R16G16B16A16_SINT: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = false, PointerType = GLVertexAttributeType.Short, Function = GLVertexAttribFunction.INT, }); case MgFormat.R32_SINT: return(new GLVertexAttributeInfo { Size = 1, IsNormalized = false, PointerType = GLVertexAttributeType.Int, Function = GLVertexAttribFunction.INT, }); case MgFormat.R32G32_SINT: return(new GLVertexAttributeInfo { Size = 2, IsNormalized = false, PointerType = GLVertexAttributeType.Int, Function = GLVertexAttribFunction.INT, }); case MgFormat.R32G32B32_SINT: return(new GLVertexAttributeInfo { Size = 3, IsNormalized = false, PointerType = GLVertexAttributeType.Int, Function = GLVertexAttribFunction.INT, }); case MgFormat.R32G32B32A32_SINT: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = false, PointerType = GLVertexAttributeType.Int, Function = GLVertexAttribFunction.INT, }); case MgFormat.R8_UINT: return(new GLVertexAttributeInfo { Size = 1, IsNormalized = false, PointerType = GLVertexAttributeType.UnsignedByte, Function = GLVertexAttribFunction.INT, }); case MgFormat.R8G8_UINT: return(new GLVertexAttributeInfo { Size = 2, IsNormalized = false, PointerType = GLVertexAttributeType.UnsignedByte, Function = GLVertexAttribFunction.INT, }); case MgFormat.R8G8B8_UINT: case MgFormat.B8G8R8_UINT: // TODO : swizzle return(new GLVertexAttributeInfo { Size = 3, IsNormalized = false, PointerType = GLVertexAttributeType.UnsignedByte, Function = GLVertexAttribFunction.INT, }); case MgFormat.R8G8B8A8_UINT: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = false, PointerType = GLVertexAttributeType.UnsignedByte, Function = GLVertexAttribFunction.INT, }); case MgFormat.R16_UINT: return(new GLVertexAttributeInfo { Size = 1, IsNormalized = false, PointerType = GLVertexAttributeType.UnsignedShort, Function = GLVertexAttribFunction.INT, }); case MgFormat.R16G16_UINT: return(new GLVertexAttributeInfo { Size = 2, IsNormalized = false, PointerType = GLVertexAttributeType.UnsignedShort, Function = GLVertexAttribFunction.INT, }); case MgFormat.R16G16B16_UINT: return(new GLVertexAttributeInfo { Size = 3, IsNormalized = false, PointerType = GLVertexAttributeType.UnsignedShort, Function = GLVertexAttribFunction.INT, }); case MgFormat.R16G16B16A16_UINT: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = false, PointerType = GLVertexAttributeType.UnsignedShort, Function = GLVertexAttribFunction.INT, }); case MgFormat.R32_UINT: return(new GLVertexAttributeInfo { Size = 1, IsNormalized = false, PointerType = GLVertexAttributeType.UnsignedInt, Function = GLVertexAttribFunction.INT, }); case MgFormat.R32G32_UINT: return(new GLVertexAttributeInfo { Size = 2, IsNormalized = false, PointerType = GLVertexAttributeType.UnsignedInt, Function = GLVertexAttribFunction.INT, }); case MgFormat.R32G32B32_UINT: return(new GLVertexAttributeInfo { Size = 3, IsNormalized = false, PointerType = GLVertexAttributeType.UnsignedInt, Function = GLVertexAttribFunction.INT, }); case MgFormat.R32G32B32A32_UINT: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = false, PointerType = GLVertexAttributeType.UnsignedInt, Function = GLVertexAttribFunction.INT, }); case MgFormat.R32_SFLOAT: return(new GLVertexAttributeInfo { Size = 1, IsNormalized = false, PointerType = GLVertexAttributeType.Float, Function = GLVertexAttribFunction.FLOAT, }); case MgFormat.R32G32_SFLOAT: return(new GLVertexAttributeInfo { Size = 2, IsNormalized = false, PointerType = GLVertexAttributeType.Float, Function = GLVertexAttribFunction.FLOAT, }); case MgFormat.R32G32B32_SFLOAT: return(new GLVertexAttributeInfo { Size = 3, IsNormalized = false, PointerType = GLVertexAttributeType.Float, Function = GLVertexAttribFunction.FLOAT, }); case MgFormat.R32G32B32A32_SFLOAT: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = false, PointerType = GLVertexAttributeType.Float, Function = GLVertexAttribFunction.FLOAT, }); case MgFormat.R16_SFLOAT: return(new GLVertexAttributeInfo { Size = 1, IsNormalized = false, PointerType = GLVertexAttributeType.HalfFloat, Function = GLVertexAttribFunction.FLOAT, }); case MgFormat.R16G16_SFLOAT: return(new GLVertexAttributeInfo { Size = 2, IsNormalized = false, PointerType = GLVertexAttributeType.HalfFloat, Function = GLVertexAttribFunction.FLOAT, }); case MgFormat.R16G16B16_SFLOAT: return(new GLVertexAttributeInfo { Size = 3, IsNormalized = false, PointerType = GLVertexAttributeType.HalfFloat, Function = GLVertexAttribFunction.FLOAT, }); case MgFormat.R16G16B16A16_SFLOAT: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = false, PointerType = GLVertexAttributeType.HalfFloat, Function = GLVertexAttribFunction.FLOAT, }); case MgFormat.R64_SFLOAT: return(new GLVertexAttributeInfo { Size = 1, IsNormalized = false, PointerType = GLVertexAttributeType.Double, Function = GLVertexAttribFunction.DOUBLE, }); case MgFormat.R64G64_SFLOAT: return(new GLVertexAttributeInfo { Size = 2, IsNormalized = false, PointerType = GLVertexAttributeType.Double, Function = GLVertexAttribFunction.DOUBLE, }); case MgFormat.R64G64B64_SFLOAT: return(new GLVertexAttributeInfo { Size = 3, IsNormalized = false, PointerType = GLVertexAttributeType.Double, Function = GLVertexAttribFunction.DOUBLE, }); case MgFormat.R64G64B64A64_SFLOAT: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = false, PointerType = GLVertexAttributeType.Double, Function = GLVertexAttribFunction.DOUBLE, }); // NORMALIZED case MgFormat.R8_SNORM: return(new GLVertexAttributeInfo { Size = 1, IsNormalized = false, PointerType = GLVertexAttributeType.Byte, Function = GLVertexAttribFunction.INT, }); case MgFormat.R8G8_SNORM: return(new GLVertexAttributeInfo { Size = 2, IsNormalized = false, PointerType = GLVertexAttributeType.Byte, Function = GLVertexAttribFunction.INT, }); case MgFormat.R8G8B8_SNORM: case MgFormat.B8G8R8_SNORM: // TODO : swizzle return(new GLVertexAttributeInfo { Size = 3, IsNormalized = false, PointerType = GLVertexAttributeType.Byte, Function = GLVertexAttribFunction.INT, }); case MgFormat.R8G8B8A8_SNORM: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = false, PointerType = GLVertexAttributeType.Byte, Function = GLVertexAttribFunction.INT, }); case MgFormat.R16_UNORM: return(new GLVertexAttributeInfo { Size = 1, IsNormalized = true, PointerType = GLVertexAttributeType.UnsignedShort, Function = GLVertexAttribFunction.INT, }); case MgFormat.R16G16_UNORM: return(new GLVertexAttributeInfo { Size = 2, IsNormalized = true, PointerType = GLVertexAttributeType.UnsignedShort, Function = GLVertexAttribFunction.INT, }); case MgFormat.R16G16B16_UNORM: return(new GLVertexAttributeInfo { Size = 3, IsNormalized = true, PointerType = GLVertexAttributeType.UnsignedShort, Function = GLVertexAttribFunction.INT, }); case MgFormat.R16G16B16A16_UNORM: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = true, PointerType = GLVertexAttributeType.UnsignedShort, Function = GLVertexAttribFunction.INT, }); // A2B10G10R10 case MgFormat.A2B10G10R10_SINT_PACK32: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = false, PointerType = GLVertexAttributeType.Int2101010Rev, Function = GLVertexAttribFunction.INT, }); case MgFormat.A2B10G10R10_SNORM_PACK32: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = true, PointerType = GLVertexAttributeType.Int2101010Rev, Function = GLVertexAttribFunction.FLOAT, }); case MgFormat.A2B10G10R10_SSCALED_PACK32: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = false, PointerType = GLVertexAttributeType.Int2101010Rev, Function = GLVertexAttribFunction.FLOAT, }); case MgFormat.A2B10G10R10_UINT_PACK32: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = false, PointerType = GLVertexAttributeType.UnsignedInt2101010Rev, Function = GLVertexAttribFunction.FLOAT, }); case MgFormat.A2B10G10R10_UNORM_PACK32: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = true, PointerType = GLVertexAttributeType.UnsignedInt2101010Rev, Function = GLVertexAttribFunction.FLOAT, }); case MgFormat.A2B10G10R10_USCALED_PACK32: return(new GLVertexAttributeInfo { Size = 4, IsNormalized = false, PointerType = GLVertexAttributeType.UnsignedInt2101010Rev, Function = GLVertexAttribFunction.FLOAT, }); default: throw new NotSupportedException(); } }
public void GetPhysicalDeviceSparseImageFormatProperties(MgFormat format, MgImageType type, MgSampleCountFlagBits samples, MgImageUsageFlagBits usage, MgImageTiling tiling, out MgSparseImageFormatProperties[] pProperties) { throw new NotImplementedException(); }
private static uint GetSize(MgFormat surfaceFormat) { switch (surfaceFormat) { case MgFormat.BC1_RGB_UNORM_BLOCK: //case SurfaceFormat.Dxt1: case MgFormat.BC1_RGB_SRGB_BLOCK: //case SurfaceFormat.Dxt1SRgb: case MgFormat.BC1_RGBA_UNORM_BLOCK: //case SurfaceFormat.Dxt1a: //case SurfaceFormat.RgbPvrtc2Bpp: //case SurfaceFormat.RgbaPvrtc2Bpp: //case SurfaceFormat.RgbEtc1: // One texel in DXT1, PVRTC 2bpp and ETC1 is a minimum 4x4 block, which is 8 bytes return(8); case MgFormat.BC2_UNORM_BLOCK: //case SurfaceFormat.Dxt3: case MgFormat.BC2_SRGB_BLOCK: //case SurfaceFormat.Dxt3SRgb: case MgFormat.BC3_UNORM_BLOCK: //case SurfaceFormat.Dxt5: case MgFormat.BC3_SRGB_BLOCK: //case SurfaceFormat.Dxt5SRgb: //case SurfaceFormat.RgbPvrtc4Bpp: //case SurfaceFormat.RgbaPvrtc4Bpp: //case SurfaceFormat.RgbaAtcExplicitAlpha: //case SurfaceFormat.RgbaAtcInterpolatedAlpha: // One texel in DXT3, DXT5 and PVRTC 4bpp is a minimum 4x4 block, which is 16 bytes return(16); case MgFormat.R8_UNORM: //case SurfaceFormat.Alpha8: return(1); case MgFormat.B5G6R5_UNORM_PACK16: //case SurfaceFormat.Bgr565: case MgFormat.B4G4R4A4_UNORM_PACK16: //case SurfaceFormat.Bgra4444: case MgFormat.B5G5R5A1_UNORM_PACK16: //case SurfaceFormat.Bgra5551: case MgFormat.R16_SFLOAT: //case SurfaceFormat.HalfSingle: case MgFormat.R16_UNORM: //case SurfaceFormat.NormalizedByte2: return(2); case MgFormat.R8G8B8A8_UINT: //case SurfaceFormat.Color: case MgFormat.R8G8B8A8_SRGB: //case SurfaceFormat.ColorSRgb: case MgFormat.R32_SFLOAT: //case SurfaceFormat.Single: case MgFormat.R16G16_UINT: //case SurfaceFormat.Rg32: case MgFormat.R16G16_SFLOAT: //case SurfaceFormat.HalfVector2: case MgFormat.R8G8B8A8_SNORM: //case SurfaceFormat.NormalizedByte4: case MgFormat.A2B10G10R10_UINT_PACK32: //case SurfaceFormat.Rgba1010102: //case SurfaceFormat.Bgra32: //case SurfaceFormat.Bgra32SRgb: //case SurfaceFormat.Bgr32: //case SurfaceFormat.Bgr32SRgb: return(4); case MgFormat.R16G16B16A16_SFLOAT: //case SurfaceFormat.HalfVector4: //case SurfaceFormat.Rgba64: case MgFormat.R32G32_SFLOAT: //case SurfaceFormat.Vector2: return(8); case MgFormat.R32G32B32A32_SFLOAT: //case SurfaceFormat.Vector4: return(16); case MgFormat.R8G8B8_SRGB: case MgFormat.R8G8B8_SSCALED: case MgFormat.R8G8B8_UINT: case MgFormat.R8G8B8_UNORM: case MgFormat.R8G8B8_USCALED: case MgFormat.R8G8B8_SINT: case MgFormat.R8G8B8_SNORM: return(3); default: throw new ArgumentException(); } }
static AmtRenderPassClearValueType GetClearValueType(MgFormat format) { switch (format) { case MgFormat.D16_UNORM: case MgFormat.D16_UNORM_S8_UINT: case MgFormat.D24_UNORM_S8_UINT: case MgFormat.D32_SFLOAT: case MgFormat.D32_SFLOAT_S8_UINT: return(AmtRenderPassClearValueType.DEPTH_STENCIL); case MgFormat.R8_SINT: case MgFormat.R8G8_SINT: case MgFormat.R8G8B8_SINT: case MgFormat.R8G8B8A8_SINT: case MgFormat.R16_SINT: case MgFormat.R16G16_SINT: case MgFormat.R16G16B16_SINT: case MgFormat.R16G16B16A16_SINT: case MgFormat.R32_SINT: case MgFormat.R32G32_SINT: case MgFormat.R32G32B32_SINT: case MgFormat.R32G32B32A32_SINT: case MgFormat.R64_SINT: case MgFormat.R64G64_SINT: case MgFormat.R64G64B64_SINT: case MgFormat.R64G64B64A64_SINT: case MgFormat.B8G8R8_SINT: case MgFormat.B8G8R8A8_SINT: return(AmtRenderPassClearValueType.COLOR_INT); case MgFormat.R8_UINT: case MgFormat.R8G8_UINT: case MgFormat.R8G8B8_UINT: case MgFormat.R8G8B8A8_UINT: case MgFormat.R16_UINT: case MgFormat.R16G16_UINT: case MgFormat.R16G16B16_UINT: case MgFormat.R16G16B16A16_UINT: case MgFormat.R32_UINT: case MgFormat.R64_UINT: case MgFormat.B8G8R8_UINT: case MgFormat.B8G8R8A8_UINT: return(AmtRenderPassClearValueType.COLOR_UINT); case MgFormat.R32_SFLOAT: case MgFormat.R32G32_SFLOAT: case MgFormat.R32G32B32_SFLOAT: case MgFormat.R32G32B32A32_SFLOAT: case MgFormat.R8G8B8_UNORM: case MgFormat.R8G8B8A8_UNORM: case MgFormat.R8G8B8_SNORM: case MgFormat.R8G8B8A8_SNORM: case MgFormat.B8G8R8_UNORM: case MgFormat.B8G8R8A8_UNORM: case MgFormat.B8G8R8_SNORM: case MgFormat.B8G8R8A8_SNORM: case MgFormat.R16G16B16_UNORM: case MgFormat.R16G16B16_SNORM: case MgFormat.R16G16B16A16_UNORM: case MgFormat.R16G16B16A16_SNORM: return(AmtRenderPassClearValueType.COLOR_FLOAT); default: throw new NotSupportedException(); } }
static float GetAttachmentDivisor(MgFormat format) { switch (format) { case MgFormat.D16_UNORM: case MgFormat.D16_UNORM_S8_UINT: case MgFormat.D24_UNORM_S8_UINT: case MgFormat.D32_SFLOAT: case MgFormat.D32_SFLOAT_S8_UINT: return(1f); case MgFormat.R8_SINT: case MgFormat.R8G8_SINT: case MgFormat.R8G8B8_SINT: case MgFormat.R8G8B8A8_SINT: return(sbyte.MaxValue); case MgFormat.R8_UINT: case MgFormat.R8G8_UINT: case MgFormat.R8G8B8_UINT: case MgFormat.R8G8B8A8_UINT: return(byte.MaxValue); case MgFormat.R16_UINT: case MgFormat.R16G16_UINT: case MgFormat.R16G16B16_UINT: case MgFormat.R16G16B16A16_UINT: return(ushort.MaxValue); case MgFormat.R16_SINT: case MgFormat.R16G16_SINT: case MgFormat.R16G16B16_SINT: case MgFormat.R16G16B16A16_SINT: return(short.MaxValue); case MgFormat.R32_SINT: case MgFormat.R32G32_SINT: case MgFormat.R32G32B32_SINT: case MgFormat.R32G32B32A32_SINT: return(int.MaxValue); // return smaller of the two case MgFormat.R64_SINT: case MgFormat.R64G64_SINT: case MgFormat.R64G64B64_SINT: case MgFormat.R64G64B64A64_SINT: return(uint.MaxValue); case MgFormat.R32_UINT: case MgFormat.R64_UINT: return(uint.MaxValue); case MgFormat.R32_SFLOAT: case MgFormat.R32G32_SFLOAT: case MgFormat.R32G32B32_SFLOAT: case MgFormat.R32G32B32A32_SFLOAT: return(1f); default: throw new NotSupportedException(); } }
public GLInternalImageFormat GetGLFormat(MgFormat format, bool supportsSRgb) { // InternalFormat = PixelInternalFormat.Rgba; // GLFormat = PixelFormat.Rgba; // GLType = PixelType.UnsignedByte; switch (format) { case MgFormat.R8G8B8_UINT: return(new GLInternalImageFormat { InternalFormat = (int)All.Rgb8Oes, GLFormat = (int)PixelFormat.Rgb, // TODO: double check GLType = (int)All.UnsignedByte, }); case MgFormat.R8G8B8A8_UINT: //case SurfaceFormat.Color: return(new GLInternalImageFormat { InternalFormat = (int)All.Rgba8Oes, GLFormat = (int)PixelFormat.Rgba, GLType = (int)All.UnsignedByte, }); case MgFormat.R8G8B8A8_SRGB: //case SurfaceFormat.ColorSRgb: if (!supportsSRgb) { //goto case SurfaceFormat.Color; goto case MgFormat.R8G8B8A8_UINT; } return(new GLInternalImageFormat { InternalFormat = (int)0x8C40, // PixelInternalFormat.Srgb; GLFormat = (int)All.Rgba, GLType = (int)All.UnsignedByte, }); case MgFormat.B5G6R5_UNORM_PACK16: //case SurfaceFormat.Bgr565: return(new GLInternalImageFormat { InternalFormat = (int)All.Rgb, GLFormat = (int)All.Rgb, GLType = (int)All.UnsignedShort565, }); case MgFormat.B4G4R4A4_UNORM_PACK16: //case SurfaceFormat.Bgra4444: return(new GLInternalImageFormat { InternalFormat = (int)All.Rgba, GLFormat = (int)All.Rgba, GLType = (int)All.UnsignedShort4444, }); case MgFormat.B5G5R5A1_UNORM_PACK16: return(new GLInternalImageFormat { //case SurfaceFormat.Bgra5551: InternalFormat = (int)All.Rgba, GLFormat = (int)All.Rgba, GLType = (int)All.UnsignedShort5551, }); case MgFormat.R8_UINT: return(new GLInternalImageFormat { //case SurfaceFormat.Alpha8: InternalFormat = (int)All.Luminance, GLFormat = (int)All.Luminance, GLType = (int)All.UnsignedByte, }); case MgFormat.BC1_RGB_UNORM_BLOCK: //case SurfaceFormat.Dxt1: // 0x83F0 is the RGB version, 0x83F1 is the RGBA version (1-bit alpha) // XNA uses the RGB version. return(new GLInternalImageFormat { InternalFormat = 0x83F0, GLFormat = (int)All.CompressedTextureFormats, GLType = (int)All.UnsignedByte, // DEFAULT }); case MgFormat.BC1_RGB_SRGB_BLOCK: //case SurfaceFormat.Dxt1SRgb: if (!supportsSRgb) { goto case MgFormat.BC1_RGB_UNORM_BLOCK; } //goto case SurfaceFormat.Dxt1; return(new GLInternalImageFormat { InternalFormat = 0x8C4C, GLFormat = (int)All.CompressedTextureFormats, GLType = (int)All.UnsignedByte, // DEFAULT }); case MgFormat.BC1_RGBA_UNORM_BLOCK: //case SurfaceFormat.Dxt1a: // 0x83F0 is the RGB version, 0x83F1 is the RGBA version (1-bit alpha) return(new GLInternalImageFormat { InternalFormat = 0x83F1, GLFormat = (int)All.CompressedTextureFormats, GLType = (int)All.UnsignedByte, // DEFAULT }); case MgFormat.BC2_UNORM_BLOCK: // case SurfaceFormat.Dxt3: return(new GLInternalImageFormat { InternalFormat = 0x83F2, GLFormat = (int)All.CompressedTextureFormats, GLType = (int)All.UnsignedByte, // DEFAULT }); case MgFormat.BC2_SRGB_BLOCK: //case SurfaceFormat.Dxt3SRgb: if (!supportsSRgb) { //goto case SurfaceFormat.Dxt3; goto case MgFormat.BC2_UNORM_BLOCK; } return(new GLInternalImageFormat { InternalFormat = 0x8C4E, GLFormat = (int)All.CompressedTextureFormats, GLType = (int)All.UnsignedByte, // DEFAULT }); case MgFormat.BC3_UNORM_BLOCK: //case SurfaceFormat.Dxt5: return(new GLInternalImageFormat { InternalFormat = 0x83F3, GLFormat = (int)All.CompressedTextureFormats, GLType = (int)All.UnsignedByte, // DEFAULT }); case MgFormat.BC3_SRGB_BLOCK: //case SurfaceFormat.Dxt5SRgb: if (!supportsSRgb) { //goto case SurfaceFormat.Dxt5; goto case MgFormat.BC3_UNORM_BLOCK; } return(new GLInternalImageFormat { InternalFormat = 0x8C4F, GLFormat = (int)All.CompressedTextureFormats, GLType = (int)All.UnsignedByte, // DEFAULT }); // TODO : find compatible VKFormat // case SurfaceFormat.RgbaAtcExplicitAlpha: // return new GLImageFormat // { // InternalFormat = (PixelInternalFormat)(int) All.AtcRgbaExplicitAlphaAmd, // GLFormat = (PixelFormat)(int) All.CompressedTextureFormats, // GLType = PixelType.UnsignedByte, // DEFAUL // }; // case SurfaceFormat.RgbaAtcInterpolatedAlpha: // return new GLImageFormat // { // InternalFormat = (PixelInternalFormat)(int) All.AtcRgbaInterpolatedAlphaAmd, // GLFormat = (PixelFormat)(int) All.CompressedTextureFormats, // GLType = PixelType.UnsignedByte, // DEFAULT // }; // // case SurfaceFormat.RgbEtc1: // return new GLImageFormat // { // InternalFormat = (PixelInternalFormat)0x8D64, // GL_ETC1_RGB8_OES // GLFormat = (PixelFormat)(int) All.CompressedTextureFormats, // GLType = PixelType.UnsignedByte, // DEFAULT // }; // #if IOS || ANDROID // // TODO : find compatible VKFormat // case SurfaceFormat.RgbPvrtc2Bpp: // return new GLImageFormat // { // InternalFormat = (PixelInternalFormat)(int) All.CompressedRgbPvrtc2Bppv1Img, // GLFormat = (PixelFormat)(int) All.CompressedTextureFormats, // // GLType = PixelType.UnsignedByte, // DEFAULT // }; // case SurfaceFormat.RgbPvrtc4Bpp: // return new GLImageFormat // { // InternalFormat = (PixelInternalFormat)(int) All.CompressedRgbPvrtc4Bppv1Img, // GLFormat = (PixelFormat)(int) All.CompressedTextureFormats, // // GLType = PixelType.UnsignedByte, // DEFAULT // }; // break; // case SurfaceFormat.RgbaPvrtc2Bpp: // return new GLImageFormat // { // InternalFormat = (PixelInternalFormat)(int) All.CompressedRgbaPvrtc2Bppv1Img, // GLFormat = (PixelFormat)(int) All.CompressedTextureFormats, // // GLType = PixelType.UnsignedByte, // DEFAULT // }; // case SurfaceFormat.RgbaPvrtc4Bpp: // return new GLImageFormat // { // InternalFormat = (PixelInternalFormat)(int) All.CompressedRgbaPvrtc4Bppv1Img, // GLFormat = (PixelFormat)(int) All.CompressedTextureFormats, // // GLType = PixelType.UnsignedByte, // DEFAULT // }; // #endif default: throw new NotSupportedException(); } }
public Result GetPhysicalDeviceImageFormatProperties(MgFormat format, MgImageType type, MgImageTiling tiling, MgImageUsageFlagBits usage, MgImageCreateFlagBits flags, out MgImageFormatProperties pImageFormatProperties) { throw new NotImplementedException(); }
public void GetPhysicalDeviceFormatProperties(MgFormat format, out MgFormatProperties pFormatProperties) { throw new NotImplementedException(); }
static SizedInternalFormat GetInternalFormat(MgFormat format) { // FROM https://www.opengl.org/wiki/Image_Format // "": No type suffix means unsigned normalized integer format. // "_SNORM": Signed normalized integer format. // "F": Floating-point. Thus, GL_RGBA32F is a floating-point format where // each component is a 32-bit IEEE floating-point value. // "I": Signed integral format. Thus GL_RGBA8I gives a signed integer // format where each of the four components is an integer on the range [-128, 127]. // "UI": Unsigned integral format. The values go from [0, MAX_INT] for the integer size. switch (format) { // 8bit MATCHING : GL_R8UI, GL_R8I, GL_R8_SNORM, GL_R8 case MgFormat.R8_UINT: return(SizedInternalFormat.R8ui); case MgFormat.R8_SINT: return(SizedInternalFormat.R8i); case MgFormat.R8_SNORM: return((SizedInternalFormat)All.R8Snorm); case MgFormat.R8_UNORM: return((SizedInternalFormat)All.R8); // 16 bit MATCHING : GL_R16F, GL_RG8UI, GL_R16UI, GL_RG8I, GL_R16I, // GL_RG8_SNORM, GL_R16_SNORM, GL_RG8, GL_R16 case MgFormat.R16_SFLOAT: return(SizedInternalFormat.R16f); case MgFormat.R8G8_UINT: return(SizedInternalFormat.Rg8ui); case MgFormat.R16_UINT: return(SizedInternalFormat.R16ui); case MgFormat.R8G8_SINT: return(SizedInternalFormat.Rg8i); case MgFormat.R16_SINT: return(SizedInternalFormat.R16i); case MgFormat.R8G8_SNORM: return((SizedInternalFormat)All.Rg8Snorm); case MgFormat.R16_SNORM: return((SizedInternalFormat)All.R16Snorm); case MgFormat.R8G8_UNORM: return((SizedInternalFormat)All.Rg8); case MgFormat.R16_UNORM: return((SizedInternalFormat)All.R16); // 24bit MATCHING : GL_RGB8, GL_RGB8_SNORM, GL_SRGB8, GL_RGB8UI, GL_RGB8I case MgFormat.R8G8B8_UNORM: return((SizedInternalFormat)All.Rgb8); case MgFormat.R8G8B8_SNORM: return((SizedInternalFormat)All.Rgb8Snorm); case MgFormat.R8G8B8_SRGB: return((SizedInternalFormat)All.Srgb8); case MgFormat.R8G8B8_UINT: return((SizedInternalFormat)All.Rgb8ui); case MgFormat.R8G8B8_SINT: return((SizedInternalFormat)All.Rgb8i); // 32bit MATCHING : GL_RG16F, GL_R11F_G11F_B10F, GL_R32F, GL_RGB10_A2UI, // GL_RGBA8UI, GL_RG16UI, GL_R32UI, GL_RGBA8I // GL_RG16I, GL_R32I, GL_RGBA8, GL_RG16, GL_RGBA8_SNORM, // GL_RG16_SNORM, GL_SRGB8_ALPHA8, GL_RGB9_E5 case MgFormat.R16G16_SFLOAT: return(SizedInternalFormat.Rg16f); case MgFormat.B10G11R11_UFLOAT_PACK32: return((SizedInternalFormat)All.R11fG11fB10f); case MgFormat.R32_SFLOAT: return(SizedInternalFormat.R32f); case MgFormat.A2B10G10R10_UINT_PACK32: return((SizedInternalFormat)All.Rgb10A2ui); case MgFormat.R8G8B8A8_UINT: return(SizedInternalFormat.Rgba8ui); case MgFormat.R16G16_UINT: return(SizedInternalFormat.Rg16ui); case MgFormat.R32_UINT: return(SizedInternalFormat.R32ui); case MgFormat.R8G8B8A8_SINT: return(SizedInternalFormat.Rgba8i); case MgFormat.R16G16_SINT: return((SizedInternalFormat)All.Rg16i); case MgFormat.R32_SINT: return((SizedInternalFormat)All.R32i); case MgFormat.A2B10G10R10_UNORM_PACK32: return((SizedInternalFormat)All.Rgb10A2); case MgFormat.R8G8B8A8_UNORM: return((SizedInternalFormat)All.Rgba8); case MgFormat.R16G16_UNORM: return((SizedInternalFormat)All.Rg16); case MgFormat.R8G8B8A8_SNORM: return((SizedInternalFormat)All.Rgba8Snorm); case MgFormat.R16G16_SNORM: return((SizedInternalFormat)All.Rg16Snorm); case MgFormat.R8G8B8A8_SRGB: return((SizedInternalFormat)All.Srgb8Alpha8); case MgFormat.E5B9G9R9_UFLOAT_PACK32: return((SizedInternalFormat)All.Rgb9E5); // 48-bit // MATCHING : GL_RGB16, GL_RGB16_SNORM, GL_RGB16F, GL_RGB16UI, GL_RGB16I case MgFormat.R16G16B16_UNORM: return((SizedInternalFormat)All.Rgb16); case MgFormat.R16G16B16_SNORM: return((SizedInternalFormat)All.Rgb16Snorm); case MgFormat.R16G16B16_SFLOAT: return((SizedInternalFormat)All.Rgb16f); case MgFormat.R16G16B16_UINT: return((SizedInternalFormat)All.Rgb16ui); case MgFormat.R16G16B16_SINT: return((SizedInternalFormat)All.Rgb16i); // 64-bit // MATCHING : GL_RGBA16F, GL_RG32F, GL_RGBA16UI, GL_RG32UI, GL_RGBA16I, GL_RG32I // GL_RGBA16, GL_RGBA16_SNORM case MgFormat.R16G16B16A16_SFLOAT: return(SizedInternalFormat.Rgba32f); case MgFormat.R32G32_SFLOAT: return(SizedInternalFormat.Rg32f); case MgFormat.R16G16B16A16_UINT: return(SizedInternalFormat.Rgba16ui); case MgFormat.R32G32_UINT: return(SizedInternalFormat.Rg32ui); case MgFormat.R16G16B16A16_SINT: return(SizedInternalFormat.Rgba16i); case MgFormat.R32G32_SINT: return(SizedInternalFormat.Rg32i); case MgFormat.R16G16B16A16_UNORM: return(SizedInternalFormat.Rgba16); case MgFormat.R16G16B16A16_SNORM: return((SizedInternalFormat)All.Rgba16Snorm); // 96-bit // MATCHING : GL_RGB32F, GL_RGB32UI, GL_RGB32I case MgFormat.R32G32B32_SFLOAT: return((SizedInternalFormat)All.Rgb32f); case MgFormat.R32G32B32_UINT: return((SizedInternalFormat)All.Rgb32ui); case MgFormat.R32G32B32_SINT: return((SizedInternalFormat)All.Rgb32i); // 128-bit // MATCHING : GL_RGBA32F, GL_RGBA32UI // NOT MATCHING : , , GL_RGBA32I case MgFormat.R32G32B32A32_SFLOAT: return(SizedInternalFormat.Rgba32f); case MgFormat.R32G32B32A32_UINT: return(SizedInternalFormat.Rgba32ui); case MgFormat.R32G32B32A32_SINT: return(SizedInternalFormat.Rgba32i); // GL_S3TC_DXT1_RGB GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT case MgFormat.BC1_RGB_UNORM_BLOCK: return((SizedInternalFormat)All.CompressedRgbS3tcDxt1Ext); case MgFormat.BC1_RGB_SRGB_BLOCK: return((SizedInternalFormat)All.CompressedSrgbS3tcDxt1Ext); // GL_S3TC_DXT1_RGBA GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT case MgFormat.BC1_RGBA_UNORM_BLOCK: return((SizedInternalFormat)All.CompressedRgbaS3tcDxt1Ext); case MgFormat.BC1_RGBA_SRGB_BLOCK: return((SizedInternalFormat)All.CompressedSrgbAlphaS3tcDxt1Ext); // GL_S3TC_DXT3_RGBA GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT case MgFormat.BC2_UNORM_BLOCK: return((SizedInternalFormat)All.CompressedRgbaS3tcDxt3Ext); case MgFormat.BC2_SRGB_BLOCK: return((SizedInternalFormat)All.CompressedSrgbAlphaS3tcDxt3Ext); // GL_S3TC_DXT5_RGBA GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT case MgFormat.BC3_UNORM_BLOCK: return((SizedInternalFormat)All.CompressedRgbaS3tcDxt5Ext); case MgFormat.BC3_SRGB_BLOCK: return((SizedInternalFormat)All.CompressedSrgbAlphaS3tcDxt5Ext); default: throw new NotSupportedException(); } }
public static MTLPixelFormat GetPixelFormat(MgFormat format) { switch (format) { default: throw new NotSupportedException(); case MgFormat.UNDEFINED: return(MTLPixelFormat.Invalid); //A8Unorm, case MgFormat.R8_SRGB: return(MTLPixelFormat.R8Unorm_sRGB); case MgFormat.R8_UNORM: return(MTLPixelFormat.R8Unorm); case MgFormat.R8_SNORM: return(MTLPixelFormat.R8Snorm); case MgFormat.R8_UINT: return(MTLPixelFormat.R8Uint); case MgFormat.R8_SINT: return(MTLPixelFormat.R8Sint); case MgFormat.R16_UNORM: return(MTLPixelFormat.R16Unorm); case MgFormat.R16_SNORM: return(MTLPixelFormat.R16Snorm); case MgFormat.R16_UINT: return(MTLPixelFormat.R16Uint); case MgFormat.R16_SINT: return(MTLPixelFormat.R16Sint); case MgFormat.R16_SFLOAT: return(MTLPixelFormat.R16Float); case MgFormat.R8G8_UNORM: return(MTLPixelFormat.RG8Unorm); case MgFormat.R8G8_SNORM: return(MTLPixelFormat.RG8Snorm); case MgFormat.R8G8_UINT: return(MTLPixelFormat.RG8Uint); case MgFormat.R8G8_SINT: return(MTLPixelFormat.RG8Sint); case MgFormat.R32_UINT: return(MTLPixelFormat.R32Uint); case MgFormat.R32_SINT: return(MTLPixelFormat.R32Sint); case MgFormat.R32_SFLOAT: return(MTLPixelFormat.R32Float); case MgFormat.R16G16_UNORM: return(MTLPixelFormat.RG16Unorm); case MgFormat.R16G16_SNORM: return(MTLPixelFormat.RG16Snorm); case MgFormat.R16G16_UINT: return(MTLPixelFormat.RG16Uint); case MgFormat.R16G16_SINT: return(MTLPixelFormat.RG16Sint); case MgFormat.R16G16_SFLOAT: return(MTLPixelFormat.RG16Float); case MgFormat.R8G8B8A8_UNORM: return(MTLPixelFormat.RGBA8Unorm); case MgFormat.R8G8B8A8_SRGB: return(MTLPixelFormat.RGBA8Unorm_sRGB); case MgFormat.R8G8B8A8_SNORM: return(MTLPixelFormat.RGBA8Snorm); case MgFormat.R8G8B8A8_UINT: return(MTLPixelFormat.RGBA8Uint); case MgFormat.R8G8B8A8_SINT: return(MTLPixelFormat.RGBA8Sint); case MgFormat.B8G8R8A8_UNORM: return(MTLPixelFormat.BGRA8Unorm); case MgFormat.B8G8R8A8_SRGB: return(MTLPixelFormat.BGRA8Unorm_sRGB); case MgFormat.A2R10G10B10_UNORM_PACK32: return(MTLPixelFormat.RGB10A2Unorm); case MgFormat.A2R10G10B10_UINT_PACK32: return(MTLPixelFormat.RGB10A2Uint); case MgFormat.B10G11R11_UFLOAT_PACK32: return(MTLPixelFormat.RG11B10Float); case MgFormat.E5B9G9R9_UFLOAT_PACK32: return(MTLPixelFormat.RGB9E5Float); case MgFormat.R32G32_UINT: return(MTLPixelFormat.RG32Uint); case MgFormat.R32G32_SINT: return(MTLPixelFormat.RG32Sint); case MgFormat.R32G32_SFLOAT: return(MTLPixelFormat.RG32Float); case MgFormat.R16G16B16A16_UNORM: return(MTLPixelFormat.RGBA16Unorm); case MgFormat.R16G16B16A16_SNORM: return(MTLPixelFormat.RGBA16Snorm); case MgFormat.R16G16B16A16_UINT: return(MTLPixelFormat.RGBA16Uint); case MgFormat.R16G16B16A16_SINT: return(MTLPixelFormat.RGBA16Sint); case MgFormat.R16G16B16A16_SFLOAT: return(MTLPixelFormat.RGBA16Float); case MgFormat.R32G32B32A32_UINT: return(MTLPixelFormat.RGBA32Uint); case MgFormat.R32G32B32A32_SINT: return(MTLPixelFormat.RGBA32Sint); case MgFormat.R32G32B32A32_SFLOAT: return(MTLPixelFormat.RGBA32Float); case MgFormat.BC1_RGBA_UNORM_BLOCK: return(MTLPixelFormat.BC1RGBA); case MgFormat.BC1_RGBA_SRGB_BLOCK: return(MTLPixelFormat.BC1_RGBA_sRGB); case MgFormat.BC2_UNORM_BLOCK: return(MTLPixelFormat.BC2RGBA); case MgFormat.BC2_SRGB_BLOCK: return(MTLPixelFormat.BC2_RGBA_sRGB); case MgFormat.BC3_UNORM_BLOCK: return(MTLPixelFormat.BC3RGBA); case MgFormat.BC3_SRGB_BLOCK: return(MTLPixelFormat.BC3_RGBA_sRGB); case MgFormat.BC4_UNORM_BLOCK: return(MTLPixelFormat.BC4_RUnorm); case MgFormat.BC4_SNORM_BLOCK: return(MTLPixelFormat.BC4_RSnorm); case MgFormat.BC5_UNORM_BLOCK: return(MTLPixelFormat.BC5_RGUnorm); case MgFormat.BC5_SNORM_BLOCK: return(MTLPixelFormat.BC5_RGSnorm); case MgFormat.BC6H_SFLOAT_BLOCK: return(MTLPixelFormat.BC6H_RGBFloat); case MgFormat.BC6H_UFLOAT_BLOCK: return(MTLPixelFormat.BC6H_RGBUFloat); case MgFormat.BC7_UNORM_BLOCK: return(MTLPixelFormat.BC7_RGBAUnorm); case MgFormat.BC7_SRGB_BLOCK: return(MTLPixelFormat.BC7_RGBAUnorm_sRGB); //GBGR422 = 240uL, //BGRG422, case MgFormat.D32_SFLOAT: return(MTLPixelFormat.Depth32Float); case MgFormat.S8_UINT: return(MTLPixelFormat.Stencil8); case MgFormat.D24_UNORM_S8_UINT: return(MTLPixelFormat.Depth24Unorm_Stencil8); case MgFormat.D32_SFLOAT_S8_UINT: return(MTLPixelFormat.Depth32Float_Stencil8); } }
public void Test_GL001() { uint width = 600; uint height = 400; MgFormat format = MgFormat.R8G8B8A8_UINT; var beginInfo = new MgCommandBufferBeginInfo { Flags = 0, }; cmdBuf.BeginCommandBuffer(beginInfo); var passBeginInfo = new MgRenderPassBeginInfo { Framebuffer = framebuffer, RenderPass = renderpass, RenderArea = new MgRect2D { Extent = new MgExtent2D { Width = width, Height = height, }, Offset = new MgOffset2D { X = 0, Y = 0, } }, ClearValues = new[] { MgClearValue.FromColorAndFormat(format, new MgColor4f(1f, 0, 1f, 1f)), new MgClearValue { DepthStencil = new MgClearDepthStencilValue(1f, 0), } }, }; cmdBuf.CmdBeginRenderPass(passBeginInfo, MgSubpassContents.INLINE); cmdBuf.CmdBindPipeline(MgPipelineBindPoint.GRAPHICS, pipeline); cmdBuf.CmdBindVertexBuffers(0, new[] { vertexBuffer }, new ulong[] { 0 }); cmdBuf.CmdBindIndexBuffer(indexBuffer, 0, MgIndexType.UINT32); cmdBuf.CmdDrawIndexed(6, 1, 0, 0, 0); cmdBuf.CmdEndRenderPass(); var err = cmdBuf.EndCommandBuffer(); var submitInfo = new[] { new MgSubmitInfo { CommandBuffers = new [] { cmdBuf, } } }; queue.QueueSubmit(submitInfo, null); queue.QueueWaitIdle(); // MAKE SURE DOUBLE SUBMISSION WORKS queue.QueueSubmit(submitInfo, null); queue.QueueWaitIdle(); }