Skip to content

Commit ffedc1a

Browse files
committed
Fix OpenGL upload format for "b5g6r5", "b5g5r5a1" and "b4g4r4a4" texture formats
1 parent 13c43fa commit ffedc1a

File tree

3 files changed

+22
-45
lines changed

3 files changed

+22
-45
lines changed

source/opengl/opengl_impl_type_convert.cpp

+19-39
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,8 @@ auto reshade::opengl::convert_format(GLenum format, GLenum type) -> api::format
561561
case GL_RGB_INTEGER:
562562
switch (type)
563563
{
564-
case GL_UNSIGNED_SHORT_5_6_5:
565-
return api::format::b5g6r5_unorm;
566-
case GL_UNSIGNED_SHORT_5_6_5_REV:
567-
assert(false);
568-
return api::format::unknown;
564+
case GL_UNSIGNED_INT_10F_11F_11F_REV:
565+
return api::format::r11g11b10_float;
569566
case GL_FLOAT:
570567
return api::format::r32g32b32_float;
571568
default:
@@ -576,11 +573,10 @@ auto reshade::opengl::convert_format(GLenum format, GLenum type) -> api::format
576573
case GL_BGR_INTEGER:
577574
switch (type)
578575
{
579-
case GL_UNSIGNED_SHORT_5_6_5:
580-
assert(false);
581-
return api::format::unknown;
582576
case GL_UNSIGNED_SHORT_5_6_5_REV:
583577
return api::format::b5g6r5_unorm;
578+
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
579+
return api::format::b5g5r5x1_unorm;
584580
case GL_FLOAT:
585581
default:
586582
assert(false);
@@ -597,30 +593,18 @@ auto reshade::opengl::convert_format(GLenum format, GLenum type) -> api::format
597593
return api::format::r16g16b16a16_snorm;
598594
case GL_UNSIGNED_SHORT:
599595
return api::format::r16g16b16a16_unorm;
600-
case GL_UNSIGNED_SHORT_4_4_4_4:
601-
return api::format::b4g4r4a4_unorm;
602-
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
603-
assert(false);
604-
return api::format::unknown;
605-
case GL_UNSIGNED_SHORT_5_5_5_1:
606-
return api::format::b5g5r5a1_unorm;
607-
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
608-
assert(false);
609-
return api::format::unknown;
610596
case GL_HALF_FLOAT:
611597
return api::format::r16g16b16a16_float;
612598
case GL_INT:
613599
return api::format::r32g32b32a32_sint;
614600
case GL_UNSIGNED_INT:
615601
return api::format::r32g32b32a32_uint;
616-
case GL_UNSIGNED_INT_8_8_8_8:
617-
return api::format::b8g8r8a8_unorm;
618-
case GL_UNSIGNED_INT_8_8_8_8_REV:
602+
case GL_UNSIGNED_INT_8_8_8_8_REV: // On a little endian machine the least-significant byte is stored first
619603
return api::format::r8g8b8a8_unorm;
620-
case GL_UNSIGNED_INT_10_10_10_2:
621-
return api::format::b10g10r10a2_unorm;
622604
case GL_UNSIGNED_INT_2_10_10_10_REV:
623605
return api::format::r10g10b10a2_unorm;
606+
case GL_UNSIGNED_INT_5_9_9_9_REV:
607+
return api::format::r9g9b9e5;
624608
case GL_FLOAT:
625609
return api::format::r32g32b32a32_float;
626610
default:
@@ -637,26 +621,18 @@ auto reshade::opengl::convert_format(GLenum format, GLenum type) -> api::format
637621
return api::format::b8g8r8a8_unorm;
638622
case GL_SHORT:
639623
case GL_UNSIGNED_SHORT:
640-
case GL_UNSIGNED_SHORT_4_4_4_4:
641624
assert(false);
642625
return api::format::unknown;
643626
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
644627
return api::format::b4g4r4a4_unorm;
645-
case GL_UNSIGNED_SHORT_5_5_5_1:
646-
assert(false);
647-
return api::format::unknown;
648628
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
649629
return api::format::b5g5r5a1_unorm;
650630
case GL_INT:
651631
case GL_UNSIGNED_INT:
652632
assert(false);
653633
return api::format::unknown;
654-
case GL_UNSIGNED_INT_8_8_8_8:
655-
return api::format::r8g8b8a8_unorm;
656634
case GL_UNSIGNED_INT_8_8_8_8_REV:
657635
return api::format::b8g8r8a8_unorm;
658-
case GL_UNSIGNED_INT_10_10_10_2:
659-
return api::format::r10g10b10a2_unorm;
660636
case GL_UNSIGNED_INT_2_10_10_10_REV:
661637
return api::format::b10g10r10a2_unorm;
662638
case GL_FLOAT:
@@ -754,6 +730,10 @@ auto reshade::opengl::convert_attrib_format(api::format format, GLint &size, GLb
754730
case api::format::r10g10b10a2_uint:
755731
size = 4;
756732
return GL_UNSIGNED_INT_2_10_10_10_REV;
733+
case api::format::b10g10r10a2_unorm:
734+
normalized = GL_TRUE;
735+
size = GL_BGRA;
736+
return GL_UNSIGNED_INT_2_10_10_10_REV;
757737
case api::format::r16_unorm:
758738
normalized = GL_TRUE;
759739
[[fallthrough]];
@@ -952,17 +932,17 @@ auto reshade::opengl::convert_upload_format(GLenum internal_format, GLenum &type
952932
type = GL_UNSIGNED_INT_10F_11F_11F_REV;
953933
return GL_RGB;
954934
case GL_RGB565:
955-
type = GL_UNSIGNED_SHORT_5_6_5;
956-
return GL_RGB;
935+
type = GL_UNSIGNED_SHORT_5_6_5_REV;
936+
return GL_BGR;
957937
case GL_RGB5_A1:
958-
type = GL_UNSIGNED_SHORT_5_5_5_1;
959-
return GL_RGBA;
938+
type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
939+
return GL_BGRA;
960940
case GL_RGB5:
961-
type = GL_UNSIGNED_SHORT_5_5_5_1;
962-
return GL_RGB;
941+
type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
942+
return GL_BGR;
963943
case GL_RGBA4:
964-
type = GL_UNSIGNED_SHORT_4_4_4_4;
965-
return GL_RGBA;
944+
type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
945+
return GL_BGRA;
966946
case GL_STENCIL_INDEX:
967947
case GL_STENCIL_INDEX8:
968948
type = GL_UNSIGNED_BYTE;

source/runtime.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static inline int format_color_bit_depth(reshade::api::format value)
8787
return 0;
8888
case reshade::api::format::b5g6r5_unorm:
8989
case reshade::api::format::b5g5r5a1_unorm:
90+
case reshade::api::format::b5g5r5x1_unorm:
9091
return 5;
9192
case reshade::api::format::r8g8b8a8_unorm:
9293
case reshade::api::format::r8g8b8a8_unorm_srgb:

source/vulkan/vulkan_impl_type_convert.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,8 @@ auto reshade::vulkan::convert_format(api::format format) -> VkFormat
144144
case api::format::b5g5r5a1_unorm:
145145
case api::format::b5g5r5x1_unorm:
146146
return VK_FORMAT_A1R5G5B5_UNORM_PACK16;
147-
#if 0
148147
case api::format::b4g4r4a4_unorm:
149-
return VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT;
150-
#endif
148+
return VK_FORMAT_A4R4G4B4_UNORM_PACK16;
151149
case api::format::s8_uint:
152150
return VK_FORMAT_S8_UINT;
153151
case api::format::d16_unorm:
@@ -218,10 +216,8 @@ auto reshade::vulkan::convert_format(VkFormat vk_format) -> api::format
218216
default:
219217
case VK_FORMAT_UNDEFINED:
220218
return api::format::unknown;
221-
#if 0
222-
case VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT:
219+
case VK_FORMAT_A4R4G4B4_UNORM_PACK16:
223220
return api::format::b4g4r4a4_unorm;
224-
#endif
225221
case VK_FORMAT_R5G6B5_UNORM_PACK16:
226222
return api::format::b5g6r5_unorm;
227223
case VK_FORMAT_A1R5G5B5_UNORM_PACK16:

0 commit comments

Comments
 (0)