Commit e37a5e80 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Use shader_glsl_append_imm_vec4() in shader_glsl_get_register_name().

parent 965ab444
......@@ -420,26 +420,43 @@ static void shader_glsl_add_version_declaration(struct wined3d_string_buffer *bu
shader_addline(buffer, "#version %u\n", shader_glsl_get_version(gl_info));
}
static void shader_glsl_append_imm_vec4(struct wined3d_string_buffer *buffer, const float *values,
const struct wined3d_gl_info *gl_info)
static void shader_glsl_append_imm_vec(struct wined3d_string_buffer *buffer,
const float *values, unsigned int size, const struct wined3d_gl_info *gl_info)
{
char str[4][17];
wined3d_ftoa(values[0], str[0]);
wined3d_ftoa(values[1], str[1]);
wined3d_ftoa(values[2], str[2]);
wined3d_ftoa(values[3], str[3]);
const int *int_values = (const int *)values;
unsigned int i;
char str[17];
if (gl_info->supported[ARB_SHADER_BIT_ENCODING])
if (!gl_info->supported[ARB_SHADER_BIT_ENCODING])
{
const unsigned int *uint_values = (const unsigned int *)values;
if (size > 1)
shader_addline(buffer, "vec%u(", size);
for (i = 0; i < size; ++i)
{
wined3d_ftoa(values[i], str);
shader_addline(buffer, i ? ", %s" : "%s", str);
}
if (size > 1)
shader_addline(buffer, ")");
shader_addline(buffer, "intBitsToFloat(ivec4(%#x, %#x, %#x, %#x))\n"
" /* %s, %s, %s, %s */", uint_values[0], uint_values[1],
uint_values[2], uint_values[3], str[0], str[1], str[2], str[3]);
return;
}
else
shader_addline(buffer, "vec4(%s, %s, %s, %s)", str[0], str[1], str[2], str[3]);
shader_addline(buffer, "intBitsToFloat(");
if (size > 1)
shader_addline(buffer, "ivec%u(", size);
for (i = 0; i < size; ++i)
{
wined3d_ftoa(values[i], str);
shader_addline(buffer, i ? ", %#x /* %s */" : "%#x /* %s */", int_values[i], str);
}
if (size > 1)
shader_addline(buffer, ")");
shader_addline(buffer, ")");
}
static void shader_glsl_append_imm_ivec(struct wined3d_string_buffer *buffer,
......@@ -2796,7 +2813,7 @@ static void shader_generate_glsl_declarations(const struct wined3d_context *cont
LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry)
{
shader_addline(buffer, "const vec4 %s_lc%u = ", prefix, lconst->idx);
shader_glsl_append_imm_vec4(buffer, (const float *)lconst->value, gl_info);
shader_glsl_append_imm_vec(buffer, (const float *)lconst->value, ARRAY_SIZE(lconst->value), gl_info);
shader_addline(buffer, ";\n");
}
}
......@@ -2903,7 +2920,6 @@ static void shader_glsl_get_register_name(const struct wined3d_shader_register *
const struct wined3d_gl_info *gl_info = ctx->gl_info;
const char *prefix = shader_glsl_get_prefix(version->type);
struct glsl_src_param rel_param0, rel_param1;
char imm_str[4][17];
if (reg->idx[0].offset != ~0u && reg->idx[0].rel_addr)
shader_glsl_add_src_param_ext(ctx, reg->idx[0].rel_addr, WINED3DSP_WRITEMASK_0,
......@@ -3139,15 +3155,8 @@ static void shader_glsl_get_register_name(const struct wined3d_shader_register *
case WINED3D_DATA_UNORM:
case WINED3D_DATA_SNORM:
case WINED3D_DATA_FLOAT:
if (gl_info->supported[ARB_SHADER_BIT_ENCODING])
{
string_buffer_sprintf(register_name, "intBitsToFloat(%#x)", reg->u.immconst_data[0]);
}
else
{
wined3d_ftoa(*(const float *)reg->u.immconst_data, imm_str[0]);
string_buffer_sprintf(register_name, "%s", imm_str[0]);
}
string_buffer_clear(register_name);
shader_glsl_append_imm_vec(register_name, (const float *)reg->u.immconst_data, 1, gl_info);
break;
case WINED3D_DATA_INT:
string_buffer_sprintf(register_name, "%#x", reg->u.immconst_data[0]);
......@@ -3169,21 +3178,8 @@ static void shader_glsl_get_register_name(const struct wined3d_shader_register *
case WINED3D_DATA_UNORM:
case WINED3D_DATA_SNORM:
case WINED3D_DATA_FLOAT:
if (gl_info->supported[ARB_SHADER_BIT_ENCODING])
{
string_buffer_sprintf(register_name, "intBitsToFloat(ivec4(%#x, %#x, %#x, %#x))",
reg->u.immconst_data[0], reg->u.immconst_data[1],
reg->u.immconst_data[2], reg->u.immconst_data[3]);
}
else
{
wined3d_ftoa(*(const float *)&reg->u.immconst_data[0], imm_str[0]);
wined3d_ftoa(*(const float *)&reg->u.immconst_data[1], imm_str[1]);
wined3d_ftoa(*(const float *)&reg->u.immconst_data[2], imm_str[2]);
wined3d_ftoa(*(const float *)&reg->u.immconst_data[3], imm_str[3]);
string_buffer_sprintf(register_name, "vec4(%s, %s, %s, %s)",
imm_str[0], imm_str[1], imm_str[2], imm_str[3]);
}
string_buffer_clear(register_name);
shader_glsl_append_imm_vec(register_name, (const float *)reg->u.immconst_data, 4, gl_info);
break;
case WINED3D_DATA_INT:
string_buffer_sprintf(register_name, "ivec4(%#x, %#x, %#x, %#x)",
......@@ -7968,10 +7964,10 @@ static GLuint shader_glsl_generate_pshader(const struct wined3d_context *context
if (args->srgb_correction)
{
shader_addline(buffer, "const vec4 srgb_const0 = ");
shader_glsl_append_imm_vec4(buffer, wined3d_srgb_const0, gl_info);
shader_glsl_append_imm_vec(buffer, wined3d_srgb_const0, 4, gl_info);
shader_addline(buffer, ";\n");
shader_addline(buffer, "const vec4 srgb_const1 = ");
shader_glsl_append_imm_vec4(buffer, wined3d_srgb_const1, gl_info);
shader_glsl_append_imm_vec(buffer, wined3d_srgb_const1, 4, gl_info);
shader_addline(buffer, ";\n");
}
if (reg_maps->vpos || reg_maps->usesdsy)
......@@ -9825,10 +9821,10 @@ static GLuint shader_glsl_generate_ffp_fragment_shader(struct shader_glsl_priv *
if (settings->sRGB_write)
{
shader_addline(buffer, "const vec4 srgb_const0 = ");
shader_glsl_append_imm_vec4(buffer, wined3d_srgb_const0, gl_info);
shader_glsl_append_imm_vec(buffer, wined3d_srgb_const0, 4, gl_info);
shader_addline(buffer, ";\n");
shader_addline(buffer, "const vec4 srgb_const1 = ");
shader_glsl_append_imm_vec4(buffer, wined3d_srgb_const1, gl_info);
shader_glsl_append_imm_vec(buffer, wined3d_srgb_const1, 4, gl_info);
shader_addline(buffer, ";\n");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment