#pragma once
#include "sokol_gfx.h"
#include <d3d11.h>

inline DXGI_FORMAT sg_pixel_format_to_dxgi(sg_pixel_format fmt) {
    switch (fmt) {
        case SG_PIXELFORMAT_R8:
            return DXGI_FORMAT_R8_UNORM;
        case SG_PIXELFORMAT_R8SN:
            return DXGI_FORMAT_R8_SNORM;
        case SG_PIXELFORMAT_R8UI:
            return DXGI_FORMAT_R8_UINT;
        case SG_PIXELFORMAT_R8SI:
            return DXGI_FORMAT_R8_SINT;
        case SG_PIXELFORMAT_R16:
            return DXGI_FORMAT_R16_UNORM;
        case SG_PIXELFORMAT_R16SN:
            return DXGI_FORMAT_R16_SNORM;
        case SG_PIXELFORMAT_R16UI:
            return DXGI_FORMAT_R16_UINT;
        case SG_PIXELFORMAT_R16SI:
            return DXGI_FORMAT_R16_SINT;
        case SG_PIXELFORMAT_R16F:
            return DXGI_FORMAT_R16_FLOAT;
        case SG_PIXELFORMAT_RG8:
            return DXGI_FORMAT_R8G8_UNORM;
        case SG_PIXELFORMAT_RG8SN:
            return DXGI_FORMAT_R8G8_SNORM;
        case SG_PIXELFORMAT_RG8UI:
            return DXGI_FORMAT_R8G8_UINT;
        case SG_PIXELFORMAT_RG8SI:
            return DXGI_FORMAT_R8G8_SINT;
        case SG_PIXELFORMAT_R32UI:
            return DXGI_FORMAT_R32_UINT;
        case SG_PIXELFORMAT_R32SI:
            return DXGI_FORMAT_R32_SINT;
        case SG_PIXELFORMAT_R32F:
            return DXGI_FORMAT_R32_FLOAT;
        case SG_PIXELFORMAT_RG16:
            return DXGI_FORMAT_R16G16_UNORM;
        case SG_PIXELFORMAT_RG16SN:
            return DXGI_FORMAT_R16G16_SNORM;
        case SG_PIXELFORMAT_RG16UI:
            return DXGI_FORMAT_R16G16_UINT;
        case SG_PIXELFORMAT_RG16SI:
            return DXGI_FORMAT_R16G16_SINT;
        case SG_PIXELFORMAT_RG16F:
            return DXGI_FORMAT_R16G16_FLOAT;
        case SG_PIXELFORMAT_RGBA8:
            return DXGI_FORMAT_R8G8B8A8_UNORM;
        case SG_PIXELFORMAT_SRGB8A8:
            return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
        case SG_PIXELFORMAT_RGBA8SN:
            return DXGI_FORMAT_R8G8B8A8_SNORM;
        case SG_PIXELFORMAT_RGBA8UI:
            return DXGI_FORMAT_R8G8B8A8_UINT;
        case SG_PIXELFORMAT_RGBA8SI:
            return DXGI_FORMAT_R8G8B8A8_SINT;
        case SG_PIXELFORMAT_BGRA8:
            return DXGI_FORMAT_B8G8R8A8_UNORM;
        case SG_PIXELFORMAT_RGB10A2:
            return DXGI_FORMAT_R10G10B10A2_UNORM;
        case SG_PIXELFORMAT_RG11B10F:
            return DXGI_FORMAT_R11G11B10_FLOAT;
        case SG_PIXELFORMAT_RGB9E5:
            return DXGI_FORMAT_R9G9B9E5_SHAREDEXP;
        case SG_PIXELFORMAT_RG32UI:
            return DXGI_FORMAT_R32G32_UINT;
        case SG_PIXELFORMAT_RG32SI:
            return DXGI_FORMAT_R32G32_SINT;
        case SG_PIXELFORMAT_RG32F:
            return DXGI_FORMAT_R32G32_FLOAT;
        case SG_PIXELFORMAT_RGBA16:
            return DXGI_FORMAT_R16G16B16A16_UNORM;
        case SG_PIXELFORMAT_RGBA16SN:
            return DXGI_FORMAT_R16G16B16A16_SNORM;
        case SG_PIXELFORMAT_RGBA16UI:
            return DXGI_FORMAT_R16G16B16A16_UINT;
        case SG_PIXELFORMAT_RGBA16SI:
            return DXGI_FORMAT_R16G16B16A16_SINT;
        case SG_PIXELFORMAT_RGBA16F:
            return DXGI_FORMAT_R16G16B16A16_FLOAT;
        case SG_PIXELFORMAT_RGBA32UI:
            return DXGI_FORMAT_R32G32B32A32_UINT;
        case SG_PIXELFORMAT_RGBA32SI:
            return DXGI_FORMAT_R32G32B32A32_SINT;
        case SG_PIXELFORMAT_RGBA32F:
            return DXGI_FORMAT_R32G32B32A32_FLOAT;
        case SG_PIXELFORMAT_DEPTH:
            return DXGI_FORMAT_R32_TYPELESS;
        case SG_PIXELFORMAT_DEPTH_STENCIL:
            return DXGI_FORMAT_R24G8_TYPELESS;
        case SG_PIXELFORMAT_BC1_RGBA:
            return DXGI_FORMAT_BC1_UNORM;
        case SG_PIXELFORMAT_BC2_RGBA:
            return DXGI_FORMAT_BC2_UNORM;
        case SG_PIXELFORMAT_BC3_RGBA:
            return DXGI_FORMAT_BC3_UNORM;
        case SG_PIXELFORMAT_BC3_SRGBA:
            return DXGI_FORMAT_BC3_UNORM_SRGB;
        case SG_PIXELFORMAT_BC4_R:
            return DXGI_FORMAT_BC4_UNORM;
        case SG_PIXELFORMAT_BC4_RSN:
            return DXGI_FORMAT_BC4_SNORM;
        case SG_PIXELFORMAT_BC5_RG:
            return DXGI_FORMAT_BC5_UNORM;
        case SG_PIXELFORMAT_BC5_RGSN:
            return DXGI_FORMAT_BC5_SNORM;
        case SG_PIXELFORMAT_BC6H_RGBF:
            return DXGI_FORMAT_BC6H_SF16;
        case SG_PIXELFORMAT_BC6H_RGBUF:
            return DXGI_FORMAT_BC6H_UF16;
        case SG_PIXELFORMAT_BC7_RGBA:
            return DXGI_FORMAT_BC7_UNORM;
        case SG_PIXELFORMAT_BC7_SRGBA:
            return DXGI_FORMAT_BC7_UNORM_SRGB;
        default:
            return DXGI_FORMAT_UNKNOWN;
    }
}

inline DXGI_FORMAT sg_pixel_format_to_dxgi_srv(sg_pixel_format fmt) {
    if (fmt == SG_PIXELFORMAT_DEPTH) {
        return DXGI_FORMAT_R32_FLOAT;
    }
    if (fmt == SG_PIXELFORMAT_DEPTH_STENCIL) {
	    return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
    }
    return sg_pixel_format_to_dxgi(fmt);
}
