cogl/tests: Avoid converting 16bpc -> float -> 16bpc
Instead just assign 16bpc -> 16bpc
This avoids variations in CPU and GL driver behaviour when using
floats as intermediate values.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3582
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3903>
(cherry picked from commit 5360c58fe5
)
This commit is contained in:
parent
c2c694464c
commit
d6a4ffc843
1 changed files with 17 additions and 16 deletions
|
@ -61,35 +61,36 @@ test_offscreen_texture_formats_store_rgba16161616 (void)
|
|||
const uint16_t rgba16_green = 61133;
|
||||
const uint16_t rgba16_blue = 2;
|
||||
const uint16_t rgba16_alpha = 1111;
|
||||
float red;
|
||||
float green;
|
||||
float blue;
|
||||
float alpha;
|
||||
int i;
|
||||
|
||||
red = (rgba16_red / (float) ((1 << 16) - 1));
|
||||
green = (rgba16_green / (float) ((1 << 16) - 1));
|
||||
blue = (rgba16_blue / (float) ((1 << 16) - 1));
|
||||
alpha = (rgba16_alpha / (float) ((1 << 16) - 1));
|
||||
uint16_t tex_data[16];
|
||||
|
||||
g_assert_cmpint (rgb8_to_rgb16 (rgb16_to_rgb8 (rgba16_red)), !=, rgba16_red);
|
||||
g_assert_cmpint (rgb8_to_rgb16 (rgb16_to_rgb8 (rgba16_green)), !=, rgba16_green);
|
||||
g_assert_cmpint (rgb8_to_rgb16 (rgb16_to_rgb8 (rgba16_blue)), !=, rgba16_blue);
|
||||
g_assert_cmpint (rgb8_to_rgb16 (rgb16_to_rgb8 (rgba16_alpha)), !=, rgba16_alpha);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
uint16_t *pixel_data = (uint16_t *) &tex_data [i * 4];
|
||||
|
||||
pixel_data[0] = rgba16_red;
|
||||
pixel_data[1] = rgba16_green;
|
||||
pixel_data[2] = rgba16_blue;
|
||||
pixel_data[3] = rgba16_alpha;
|
||||
}
|
||||
|
||||
/* Allocate 2x2 to ensure we avoid any fast paths. */
|
||||
tex = cogl_texture_2d_new_with_format (test_ctx,
|
||||
2, 2,
|
||||
COGL_PIXEL_FORMAT_RGBA_16161616_PRE);
|
||||
tex = cogl_texture_2d_new_from_data (test_ctx,
|
||||
2, 2,
|
||||
COGL_PIXEL_FORMAT_RGBA_16161616_PRE,
|
||||
16,
|
||||
(const uint8_t *) tex_data,
|
||||
NULL);
|
||||
|
||||
offscreen = cogl_offscreen_new_with_texture (tex);
|
||||
cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen), &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
cogl_framebuffer_clear4f (COGL_FRAMEBUFFER (offscreen),
|
||||
COGL_BUFFER_BIT_COLOR,
|
||||
red, green, blue, alpha);
|
||||
|
||||
cogl_framebuffer_read_pixels (COGL_FRAMEBUFFER (offscreen), 0, 0, 2, 2,
|
||||
COGL_PIXEL_FORMAT_RG_1616,
|
||||
(uint8_t *) &readback);
|
||||
|
|
Loading…
Reference in a new issue