gles2gsg: fix sRGB texture support

This commit is contained in:
rdb 2020-09-06 09:20:34 +02:00
parent cca84131df
commit 40842ef217
2 changed files with 17 additions and 11 deletions

View File

@ -100,9 +100,7 @@ typedef char GLchar;
#define GL_RGBA16F GL_RGBA16F_EXT
#define GL_RGB32F GL_RGB32F_EXT
#define GL_RGBA32F GL_RGBA32F_EXT
#define GL_SRGB GL_SRGB_EXT
#define GL_SRGB_ALPHA GL_SRGB_ALPHA_EXT
#define GL_SRGB8_ALPHA8 GL_SRGB8_ALPHA8_EXT
#define GL_RGBA8 GL_RGBA8_OES
#define GL_R8 GL_R8_EXT
#define GL_RG8 GL_RG8_EXT
@ -194,6 +192,9 @@ typedef char GLchar;
#define GL_RGB9_E5 0x8C3D
#define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E
#define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B
#define GL_SRGB 0x8C40
#define GL_SRGB8 0x8C41
#define GL_SRGB8_ALPHA8 0x8C43
#define GL_PRIMITIVE_RESTART_FIXED_INDEX 0x8D69
#define GL_RED_INTEGER 0x8D94
#define GL_RGB_INTEGER 0x8D98

View File

@ -10314,11 +10314,9 @@ get_internal_image_format(Texture *tex, bool force_sized) const {
#ifndef OPENGLES_1
case Texture::F_srgb:
#ifndef OPENGLES
return GL_SRGB8;
#endif
return _supports_texture_srgb ? GL_SRGB8 : GL_RGB8;
case Texture::F_srgb_alpha:
return GL_SRGB8_ALPHA8;
return _supports_texture_srgb ? GL_SRGB8_ALPHA8 : GL_RGBA8;
#endif
#ifndef OPENGLES
case Texture::F_sluminance:
@ -12807,11 +12805,20 @@ upload_texture(CLP(TextureContext) *gtc, bool force, bool uses_mipmaps) {
int num_levels = 1;
CPTA_uchar image = tex->get_ram_mipmap_image(mipmap_bias);
bool can_generate = _supports_generate_mipmap;
#if defined(OPENGLES) && !defined(OPENGLES_1)
// OpenGL ES doesn't support generating mipmaps for sRGB textures, so we
// have to do this on the CPU, unless we have a special extension.
if (internal_format == GL_SRGB8 || internal_format == GL_SRGB8_ALPHA8) {
can_generate = has_extension("GL_NV_generate_mipmap_sRGB");
}
#endif
if (image.is_null()) {
// We don't even have a RAM image, so we have no choice but to let
// mipmaps be generated on the GPU.
if (uses_mipmaps) {
if (_supports_generate_mipmap) {
if (can_generate) {
num_levels = tex->get_expected_num_mipmap_levels() - mipmap_bias;
gtc->_generate_mipmaps = true;
} else {
@ -12827,7 +12834,7 @@ upload_texture(CLP(TextureContext) *gtc, bool force, bool uses_mipmaps) {
if (num_levels <= 1) {
// No RAM mipmap levels available. Should we generate some?
if (!_supports_generate_mipmap || !driver_generate_mipmaps ||
if (!can_generate || !driver_generate_mipmaps ||
image_compression != Texture::CM_off) {
// Yes, the GL can't or won't generate them, so we need to. Note
// that some drivers (nVidia) will *corrupt memory* if you ask
@ -12840,7 +12847,7 @@ upload_texture(CLP(TextureContext) *gtc, bool force, bool uses_mipmaps) {
if (num_levels <= 1) {
// We don't have mipmap levels in RAM. Ask the GL to generate them
// if it can.
if (_supports_generate_mipmap) {
if (can_generate) {
num_levels = tex->get_expected_num_mipmap_levels() - mipmap_bias;
gtc->_generate_mipmaps = true;
} else {
@ -14106,9 +14113,7 @@ do_extract_texture_data(CLP(TextureContext) *gtc) {
#ifndef OPENGLES_1
case GL_SRGB:
#ifndef OPENGLES
case GL_SRGB8:
#endif
format = Texture::F_srgb;
break;
case GL_SRGB_ALPHA: