2020-10-04 23:24:14 +02:00
|
|
|
#include "Common/GPU/OpenGL/DataFormatGL.h"
|
2022-10-08 16:06:39 -07:00
|
|
|
#include "Common/GPU/OpenGL/GLFeatures.h"
|
2017-12-19 14:35:24 +01:00
|
|
|
#include "Common/Log.h"
|
|
|
|
|
|
|
|
|
|
namespace Draw {
|
|
|
|
|
|
|
|
|
|
// TODO: Also output storage format (GL_RGBA8 etc) for modern GL usage.
|
2022-09-12 15:34:32 +02:00
|
|
|
bool Thin3DFormatToGLFormatAndType(DataFormat fmt, GLuint &internalFormat, GLuint &format, GLuint &type, int &alignment) {
|
2017-12-19 14:35:24 +01:00
|
|
|
alignment = 4;
|
|
|
|
|
switch (fmt) {
|
2022-09-12 15:34:32 +02:00
|
|
|
case DataFormat::R16_UNORM:
|
2022-09-12 23:32:38 +02:00
|
|
|
internalFormat = GL_RGBA;
|
|
|
|
|
format = GL_RED;
|
2022-09-12 15:34:32 +02:00
|
|
|
type = GL_UNSIGNED_SHORT;
|
2022-09-14 23:35:15 +02:00
|
|
|
alignment = 2;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DataFormat::R8_UNORM:
|
2022-10-08 16:06:39 -07:00
|
|
|
if (gl_extensions.IsGLES) {
|
|
|
|
|
internalFormat = GL_LUMINANCE;
|
|
|
|
|
format = GL_LUMINANCE;
|
|
|
|
|
} else if (gl_extensions.VersionGEThan(3, 0)) {
|
|
|
|
|
internalFormat = GL_RED;
|
|
|
|
|
format = GL_RED;
|
|
|
|
|
} else {
|
|
|
|
|
internalFormat = GL_RGBA;
|
|
|
|
|
format = GL_RED;
|
|
|
|
|
}
|
2022-09-14 23:35:15 +02:00
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
|
alignment = 1;
|
2022-09-12 15:34:32 +02:00
|
|
|
break;
|
|
|
|
|
|
2017-12-19 14:35:24 +01:00
|
|
|
case DataFormat::R8G8B8A8_UNORM:
|
|
|
|
|
internalFormat = GL_RGBA;
|
|
|
|
|
format = GL_RGBA;
|
|
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DataFormat::D32F:
|
|
|
|
|
internalFormat = GL_DEPTH_COMPONENT;
|
|
|
|
|
format = GL_DEPTH_COMPONENT;
|
|
|
|
|
type = GL_FLOAT;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
#ifndef USING_GLES2
|
|
|
|
|
case DataFormat::S8:
|
|
|
|
|
internalFormat = GL_STENCIL_INDEX;
|
|
|
|
|
format = GL_STENCIL_INDEX;
|
|
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
|
alignment = 1;
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
case DataFormat::R8G8B8_UNORM:
|
|
|
|
|
internalFormat = GL_RGB;
|
|
|
|
|
format = GL_RGB;
|
|
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
|
alignment = 1;
|
|
|
|
|
break;
|
|
|
|
|
|
2019-10-24 23:01:45 +02:00
|
|
|
case DataFormat::R4G4B4A4_UNORM_PACK16:
|
2017-12-19 14:35:24 +01:00
|
|
|
internalFormat = GL_RGBA;
|
|
|
|
|
format = GL_RGBA;
|
|
|
|
|
type = GL_UNSIGNED_SHORT_4_4_4_4;
|
|
|
|
|
alignment = 2;
|
|
|
|
|
break;
|
|
|
|
|
|
2019-10-24 23:01:45 +02:00
|
|
|
case DataFormat::R5G6B5_UNORM_PACK16:
|
2017-12-19 14:35:24 +01:00
|
|
|
internalFormat = GL_RGB;
|
|
|
|
|
format = GL_RGB;
|
|
|
|
|
type = GL_UNSIGNED_SHORT_5_6_5;
|
|
|
|
|
alignment = 2;
|
|
|
|
|
break;
|
|
|
|
|
|
2019-10-24 23:01:45 +02:00
|
|
|
case DataFormat::R5G5B5A1_UNORM_PACK16:
|
2017-12-19 14:35:24 +01:00
|
|
|
internalFormat = GL_RGBA;
|
|
|
|
|
format = GL_RGBA;
|
|
|
|
|
type = GL_UNSIGNED_SHORT_5_5_5_1;
|
|
|
|
|
alignment = 2;
|
|
|
|
|
break;
|
|
|
|
|
|
2019-10-24 22:40:26 +02:00
|
|
|
case DataFormat::R32G32B32A32_FLOAT:
|
|
|
|
|
internalFormat = GL_RGBA32F;
|
|
|
|
|
format = GL_RGBA;
|
|
|
|
|
type = GL_FLOAT;
|
|
|
|
|
alignment = 16;
|
|
|
|
|
break;
|
|
|
|
|
|
2017-12-19 14:35:24 +01:00
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-28 17:27:23 +01:00
|
|
|
}
|