#include <iostream>

#include "wrapper/TextureFormat.h"

TextureFormat::TextureFormat(GLint internalformat, GLenum format, GLenum type, bool linear, bool depth)
    : internalformat(internalformat), format(format), type(type), linear(linear), depth(depth) {
}

TextureFormat TextureFormat::color8(int channels, bool linear) {
    switch(channels) {
        case 1: return TextureFormat(GL_RED, GL_RED, GL_UNSIGNED_BYTE, linear);
        case 2: return TextureFormat(GL_RG, GL_RG, GL_UNSIGNED_BYTE, linear);
        case 3: return TextureFormat(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, linear);
        case 4: return TextureFormat(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, linear);
    }
    std::cout << channels << " is not a valid amount of channels\n";
    return TextureFormat(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, linear);
}

TextureFormat TextureFormat::float16(int channels, bool linear) {
    switch(channels) {
        case 1: return TextureFormat(GL_R16F, GL_RED, GL_FLOAT, linear);
        case 2: return TextureFormat(GL_RG16F, GL_RG, GL_FLOAT, linear);
        case 3: return TextureFormat(GL_RGB16F, GL_RGB, GL_FLOAT, linear);
        case 4: return TextureFormat(GL_RGBA16F, GL_RGBA, GL_FLOAT, linear);
    }
    std::cout << channels << " is not a valid amount of channels\n";
    return TextureFormat(GL_RGBA16F, GL_RGBA, GL_FLOAT, linear);
}

TextureFormat TextureFormat::float32(int channels, bool linear) {
    switch(channels) {
        case 1: return TextureFormat(GL_R32F, GL_RED, GL_FLOAT, linear);
        case 2: return TextureFormat(GL_RG32F, GL_RG, GL_FLOAT, linear);
        case 3: return TextureFormat(GL_RGB32F, GL_RGB, GL_FLOAT, linear);
        case 4: return TextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, linear);
    }
    std::cout << channels << " is not a valid amount of channels\n";
    return TextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, linear);
}

TextureFormat TextureFormat::depth16(bool linear) {
    return TextureFormat(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_FLOAT, linear, true);
}

TextureFormat TextureFormat::depth32(bool linear) {
    return TextureFormat(GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_FLOAT, linear, true);
}

TextureFormat TextureFormat::unknown() {
    return TextureFormat(-1, -1, -1, false, false);
}