This ends up being slightly more code, but I think the table is much more
readable.
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
---
dlls/wined3d/utils.c | 200 ++++++++++++++++++++++-------------------
dlls/wined3d/wined3d_private.h | 14 ---
2 files changed, 109 insertions(+), 105 deletions(-)
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index 3a74fc8f281..17aa8c07732 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -3403,85 +3403,129 @@ static void init_format_filter_info(struct wined3d_adapter *adapter,
}
}
-static void apply_format_fixups(struct wined3d_adapter *adapter, struct wined3d_gl_info *gl_info)
+static enum fixup_channel_source fixup_source_from_char(char c)
{
- struct wined3d_format *format;
- unsigned int i;
+ switch (c)
+ {
+ default:
+ case '0':
+ return CHANNEL_SOURCE_ZERO;
+ case '1':
+ return CHANNEL_SOURCE_ONE;
+ case 'x':
+ case 'X':
+ return CHANNEL_SOURCE_X;
+ case 'y':
+ case 'Y':
+ return CHANNEL_SOURCE_Y;
+ case 'z':
+ case 'Z':
+ return CHANNEL_SOURCE_Z;
+ case 'w':
+ case 'W':
+ return CHANNEL_SOURCE_W;
+ }
+}
+
+static unsigned int fixup_sign_from_char(char c)
+{
+ if (c == 'x' || c == 'y' || c == 'z' || c == 'w')
+ return 1;
+ return 0;
+}
- format = get_format_internal(adapter, WINED3DFMT_R16_FLOAT);
- format->color_fixup = create_color_fixup_desc(
- 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_W);
+static struct color_fixup_desc create_color_fixup_desc_from_string(const char *s)
+{
+ struct color_fixup_desc fixup;
- format = get_format_internal(adapter, WINED3DFMT_R32_FLOAT);
- format->color_fixup = create_color_fixup_desc(
- 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_W);
+ if (strlen(s) != 4)
+ {
+ ERR("Invalid fixup string %s.\n", wine_dbgstr_a(s));
+ return COLOR_FIXUP_IDENTITY;
+ }
- format = get_format_internal(adapter, WINED3DFMT_R16G16_UNORM);
- format->color_fixup = create_color_fixup_desc(
- 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_W);
+ fixup.x_sign_fixup = fixup_sign_from_char(s[0]);
+ fixup.x_source = fixup_source_from_char(s[0]);
+ fixup.y_sign_fixup = fixup_sign_from_char(s[1]);
+ fixup.y_source = fixup_source_from_char(s[1]);
+ fixup.z_sign_fixup = fixup_sign_from_char(s[2]);
+ fixup.z_source = fixup_source_from_char(s[2]);
+ fixup.w_sign_fixup = fixup_sign_from_char(s[3]);
+ fixup.w_source = fixup_source_from_char(s[3]);
- format = get_format_internal(adapter, WINED3DFMT_R16G16_FLOAT);
- format->color_fixup = create_color_fixup_desc(
- 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_W);
+ return fixup;
+}
- format = get_format_internal(adapter, WINED3DFMT_R32G32_FLOAT);
- format->color_fixup = create_color_fixup_desc(
- 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_W);
+static void apply_format_fixups(struct wined3d_adapter *adapter, struct wined3d_gl_info *gl_info)
+{
+ struct wined3d_format *format;
+ unsigned int i;
- /* GL_ATI_envmap_bumpmap in theory supports R8G8_SNORM but is no longer supported by
- * any driver. */
- if (gl_info->supported[NV_TEXTURE_SHADER] || gl_info->supported[EXT_TEXTURE_SNORM])
+ static const struct
{
- /* R8G8_SNORM and R16G16_SNORM need a fixup of the undefined blue channel. OpenGL
- * returns 0.0 when sampling from it, DirectX 1.0. So we always have in-shader
- * conversion for this format. */
- format = get_format_internal(adapter, WINED3DFMT_R8G8_SNORM);
- format->color_fixup = create_color_fixup_desc(
- 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
- format = get_format_internal(adapter, WINED3DFMT_R16G16_SNORM);
- format->color_fixup = create_color_fixup_desc(
- 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
+ enum wined3d_format_id id;
+ const char *fixup;
+ enum wined3d_gl_extension extension;
}
- else
+ fixups[] =
{
- /* Emulate using unsigned formats. This requires load-time conversion in addition to the
- * fixups here. */
- format = get_format_internal(adapter, WINED3DFMT_R8G8_SNORM);
- format->color_fixup = create_color_fixup_desc(
- 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
- format = get_format_internal(adapter, WINED3DFMT_R16G16_SNORM);
- format->color_fixup = create_color_fixup_desc(
- 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
- format = get_format_internal(adapter, WINED3DFMT_R8G8B8A8_SNORM);
- format->color_fixup = create_color_fixup_desc(
- 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Y, 1, CHANNEL_SOURCE_Z, 1, CHANNEL_SOURCE_W);
- format = get_format_internal(adapter, WINED3DFMT_R5G5_SNORM_L6_UNORM);
- format->color_fixup = create_color_fixup_desc(
- 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Z, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE);
- }
+ {WINED3DFMT_R16_FLOAT, "X11W", WINED3D_GL_EXT_NONE},
+ {WINED3DFMT_R32_FLOAT, "X11W", WINED3D_GL_EXT_NONE},
+ {WINED3DFMT_R16G16_UNORM, "XY1W", WINED3D_GL_EXT_NONE},
+ {WINED3DFMT_R16G16_FLOAT, "XY1W", WINED3D_GL_EXT_NONE},
+ {WINED3DFMT_R32G32_FLOAT, "XY1W", WINED3D_GL_EXT_NONE},
- if (!gl_info->supported[NV_TEXTURE_SHADER])
- {
- format = get_format_internal(adapter, WINED3DFMT_R8G8_SNORM_L8X8_UNORM);
- format->color_fixup = create_color_fixup_desc(
- 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_Z, 0, CHANNEL_SOURCE_W);
- }
+ {WINED3DFMT_R8G8_SNORM, "xy11", WINED3D_GL_EXT_NONE},
+ {WINED3DFMT_R8G8_SNORM, "XY11", NV_TEXTURE_SHADER},
+ {WINED3DFMT_R8G8_SNORM, "XY11", EXT_TEXTURE_SNORM},
- if (gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC] || gl_info->supported[EXT_TEXTURE_COMPRESSION_RGTC])
- {
- format = get_format_internal(adapter, WINED3DFMT_ATI1N);
- format->color_fixup = create_color_fixup_desc(
- 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X);
+ {WINED3DFMT_R16G16_SNORM, "xy11", WINED3D_GL_EXT_NONE},
+ {WINED3DFMT_R16G16_SNORM, "XY11", NV_TEXTURE_SHADER},
+ {WINED3DFMT_R16G16_SNORM, "XY11", EXT_TEXTURE_SNORM},
- format = get_format_internal(adapter, WINED3DFMT_ATI2N);
- format->color_fixup = create_color_fixup_desc(
- 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
- }
- else if (gl_info->supported[ATI_TEXTURE_COMPRESSION_3DC])
+ {WINED3DFMT_R8G8B8A8_SNORM, "xyzw", WINED3D_GL_EXT_NONE},
+ {WINED3DFMT_R8G8B8A8_SNORM, "XYZW", NV_TEXTURE_SHADER},
+ {WINED3DFMT_R8G8B8A8_SNORM, "XYZW", EXT_TEXTURE_SNORM},
+
+ {WINED3DFMT_R5G5_SNORM_L6_UNORM, "xzY1", WINED3D_GL_EXT_NONE},
+ {WINED3DFMT_R5G5_SNORM_L6_UNORM, "XYZW", NV_TEXTURE_SHADER},
+ {WINED3DFMT_R5G5_SNORM_L6_UNORM, "XYZW", EXT_TEXTURE_SNORM},
+
+ {WINED3DFMT_R8G8_SNORM_L8X8_UNORM, "xyZW", WINED3D_GL_EXT_NONE},
+ {WINED3DFMT_R8G8_SNORM_L8X8_UNORM, "XYZW", NV_TEXTURE_SHADER},
+
+ {WINED3DFMT_ATI1N, "XXXX", EXT_TEXTURE_COMPRESSION_RGTC},
+ {WINED3DFMT_ATI1N, "XXXX", ARB_TEXTURE_COMPRESSION_RGTC},
+
+ {WINED3DFMT_ATI2N, "XW11", ATI_TEXTURE_COMPRESSION_3DC},
+ {WINED3DFMT_ATI2N, "YX11", EXT_TEXTURE_COMPRESSION_RGTC},
+ {WINED3DFMT_ATI2N, "YX11", ARB_TEXTURE_COMPRESSION_RGTC},
+
+ {WINED3DFMT_A8_UNORM, "000X", WINED3D_GL_EXT_NONE},
+ {WINED3DFMT_A8_UNORM, "XYZW", WINED3D_GL_LEGACY_CONTEXT},
+
+ {WINED3DFMT_L8A8_UNORM, "XXXY", WINED3D_GL_EXT_NONE},
+ {WINED3DFMT_L8A8_UNORM, "XYZW", WINED3D_GL_LEGACY_CONTEXT},
+
+ {WINED3DFMT_L4A4_UNORM, "XXXY", WINED3D_GL_EXT_NONE},
+ {WINED3DFMT_L4A4_UNORM, "XYZW", WINED3D_GL_LEGACY_CONTEXT},
+
+ {WINED3DFMT_L16_UNORM, "XXX1", WINED3D_GL_EXT_NONE},
+ {WINED3DFMT_L16_UNORM, "XYZW", WINED3D_GL_LEGACY_CONTEXT},
+
+ {WINED3DFMT_INTZ, "XXXX", WINED3D_GL_EXT_NONE},
+ {WINED3DFMT_INTZ, "XYZW", WINED3D_GL_LEGACY_CONTEXT},
+
+ {WINED3DFMT_L8_UNORM, "XXX1", ARB_TEXTURE_RG},
+ };
+
+ for (i = 0; i < ARRAY_SIZE(fixups); ++i)
{
- format = get_format_internal(adapter, WINED3DFMT_ATI2N);
- format->color_fixup = create_color_fixup_desc(
- 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_W, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
+ if (!gl_info->supported[fixups[i].extension])
+ continue;
+
+ format = get_format_internal(adapter, fixups[i].id);
+ format->color_fixup = create_color_fixup_desc_from_string(fixups[i].fixup);
}
if (!gl_info->supported[APPLE_YCBCR_422] && (gl_info->supported[ARB_FRAGMENT_PROGRAM]
@@ -3527,32 +3571,6 @@ static void apply_format_fixups(struct wined3d_adapter *adapter, struct wined3d_
format->glInternal = 0;
}
- if (!gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
- {
- format = get_format_internal(adapter, WINED3DFMT_A8_UNORM);
- format->color_fixup = create_color_fixup_desc(
- 0, CHANNEL_SOURCE_ZERO, 0, CHANNEL_SOURCE_ZERO, 0, CHANNEL_SOURCE_ZERO, 0, CHANNEL_SOURCE_X);
- format = get_format_internal(adapter, WINED3DFMT_L8A8_UNORM);
- format->color_fixup = create_color_fixup_desc(
- 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y);
- format = get_format_internal(adapter, WINED3DFMT_L4A4_UNORM);
- format->color_fixup = create_color_fixup_desc(
- 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y);
- format = get_format_internal(adapter, WINED3DFMT_L16_UNORM);
- format->color_fixup = create_color_fixup_desc(
- 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_ONE);
- format = get_format_internal(adapter, WINED3DFMT_INTZ);
- format->color_fixup = create_color_fixup_desc(
- 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X);
- }
-
- if (gl_info->supported[ARB_TEXTURE_RG])
- {
- format = get_format_internal(adapter, WINED3DFMT_L8_UNORM);
- format->color_fixup = create_color_fixup_desc(
- 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_ONE);
- }
-
if (gl_info->supported[ARB_FRAGMENT_PROGRAM] || gl_info->supported[ARB_FRAGMENT_SHADER])
{
format = get_format_internal(adapter, WINED3DFMT_P8_UINT);
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 7c8beb87535..2673de0c4eb 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -201,20 +201,6 @@ struct wined3d_d3d_info
static const struct color_fixup_desc COLOR_FIXUP_IDENTITY =
{0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_Z, 0, CHANNEL_SOURCE_W};
-static inline struct color_fixup_desc create_color_fixup_desc(
- int sign0, enum fixup_channel_source src0, int sign1, enum fixup_channel_source src1,
- int sign2, enum fixup_channel_source src2, int sign3, enum fixup_channel_source src3)
-{
- struct color_fixup_desc fixup =
- {
- sign0, src0,
- sign1, src1,
- sign2, src2,
- sign3, src3,
- };
- return fixup;
-}
-
static inline struct color_fixup_desc create_complex_fixup_desc(enum complex_fixup complex_fixup)
{
struct color_fixup_desc fixup =
--
2.11.0