#include "gl_renderer.h"

#include <GL/gl.h>
#include <GL/glad.h> // 或 <glad/glad.h>

GLenum GetOpenGLInternalFormat(texture_format format) {
    switch (format) {
        // 8-bit formats
        case texture_format::R8_UNORM:
            return GL_R8;
        case texture_format::R8_SNORM:
            return GL_R8_SNORM;
        case texture_format::R8_UINT:
            return GL_R8UI;
        case texture_format::R8_SINT:
            return GL_R8I;

        // 16-bit formats
        case texture_format::RG8_UNORM:
            return GL_RG8;
        case texture_format::RG8_SNORM:
            return GL_RG8_SNORM;
        case texture_format::RG8_UINT:
            return GL_RG8UI;
        case texture_format::RG8_SINT:
            return GL_RG8I;

        // 24-bit formats
        case texture_format::RGB8_UNORM:
            return GL_RGB8;
        case texture_format::RGB8_SNORM:
            return GL_RGB8_SNORM;
        case texture_format::RGB8_UINT:
            return GL_RGB8UI;
        case texture_format::RGB8_SINT:
            return GL_RGB8I;

        // 32-bit formats
        case texture_format::RGBA8_UNORM:
            return GL_RGBA8;
        case texture_format::RGBA8_SNORM:
            return GL_RGBA8_SNORM;
        case texture_format::RGBA8_UINT:
            return GL_RGBA8UI;
        case texture_format::RGBA8_SINT:
            return GL_RGBA8I;

        // SRGB formats
        case texture_format::SRGB8:
            return GL_SRGB8;
        case texture_format::SRGB8_ALPHA8:
            return GL_SRGB8_ALPHA8;

        // 16-bit float formats
        case texture_format::R16_FLOAT:
            return GL_R16F;
        case texture_format::RG16_FLOAT:
            return GL_RG16F;
        case texture_format::RGB16_FLOAT:
            return GL_RGB16F;
        case texture_format::RGBA16_FLOAT:
            return GL_RGBA16F;

        // 32-bit float formats
        case texture_format::R32_FLOAT:
            return GL_R32F;
        case texture_format::RG32_FLOAT:
            return GL_RG32F;
        case texture_format::RGB32_FLOAT:
            return GL_RGB32F;
        case texture_format::RGBA32_FLOAT:
            return GL_RGBA32F;

        // Integer formats
        case texture_format::R16_UINT:
            return GL_R16UI;
        case texture_format::R16_SINT:
            return GL_R16I;
        case texture_format::RG16_UINT:
            return GL_RG16UI;
        case texture_format::RG16_SINT:
            return GL_RG16I;
        case texture_format::RGBA16_UINT:
            return GL_RGBA16UI;
        case texture_format::RGBA16_SINT:
            return GL_RGBA16I;
        case texture_format::R32_UINT:
            return GL_R32UI;
        case texture_format::R32_SINT:
            return GL_R32I;
        case texture_format::RG32_UINT:
            return GL_RG32UI;
        case texture_format::RG32_SINT:
            return GL_RG32I;
        case texture_format::RGBA32_UINT:
            return GL_RGBA32UI;
        case texture_format::RGBA32_SINT:
            return GL_RGBA32I;

        // Depth/stencil formats
        case texture_format::D16_UNORM:
            return GL_DEPTH_COMPONENT16;
        case texture_format::D24_UNORM_S8_UINT:
            return GL_DEPTH24_STENCIL8;
        case texture_format::D32_FLOAT:
            return GL_DEPTH_COMPONENT32F;
        case texture_format::D32_FLOAT_S8X24_UINT:
            return GL_DEPTH32F_STENCIL8;

        // Compressed formats
        case texture_format::BC1_UNORM:
            return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
        case texture_format::BC3_UNORM:
            return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
        
        default:
            return 0; // Unsupported format
    }
}
