7 #include <gtest/gtest.h>
10 #include "util/macros.h"
11 #include "util/u_endian.h"
12 #include "util/u_math.h"
21 class OSMesaRenderTestFixture
: public testing::TestWithParam
<Params
> {};
24 name_params(const testing::TestParamInfo
<Params
> params
) {
25 auto p
= params
.param
;
26 std::string first
, second
;
46 case GL_UNSIGNED_SHORT
:
47 second
= "unsigned_short";
49 case GL_UNSIGNED_BYTE
:
50 second
= "unsigned_byte";
55 case GL_UNSIGNED_SHORT_5_6_5
:
56 second
= "unsigned_short_565";
60 return first
+ "_" + second
;
63 TEST_P(OSMesaRenderTestFixture
, Render
)
66 const int w
= 2, h
= 2;
67 uint8_t pixels
[w
* h
* 8] = { 0 };
69 std::unique_ptr
<osmesa_context
, decltype(&OSMesaDestroyContext
)> ctx
{
70 OSMesaCreateContext(p
.format
, NULL
), &OSMesaDestroyContext
};
73 auto ret
= OSMesaMakeCurrent(ctx
.get(), &pixels
, p
.type
, w
, h
);
74 ASSERT_EQ(ret
, GL_TRUE
);
76 glClearColor(0.25, 1.0, 0.5, 0.75);
78 uint64_t expected
= p
.expected
;
80 /* All the formats other than 565 and RGB/byte are array formats, but our
81 * expected values are packed, so byte swap appropriately.
83 if (UTIL_ARCH_BIG_ENDIAN
) {
86 expected
= util_bswap64(expected
);
90 expected
= util_bswap32(expected
);
99 glClear(GL_COLOR_BUFFER_BIT
);
103 for (unsigned i
= 0; i
< ARRAY_SIZE(pixels
); i
+= 4) {
104 fprintf(stderr
, "pixel %d: %02x %02x %02x %02x\n",
113 for (unsigned i
= 0; i
< w
* h
; i
++) {
117 memcpy(&color
, &pixels
[i
* p
.bpp
], p
.bpp
);
118 ASSERT_EQ(expected
, color
);
123 uint32_t color
= ((pixels
[i
* p
.bpp
+ 0] << 0) |
124 (pixels
[i
* p
.bpp
+ 1] << 8) |
125 (pixels
[i
* p
.bpp
+ 2] << 16));
126 ASSERT_EQ(expected
, color
);
132 memcpy(&color
, &pixels
[i
* p
.bpp
], p
.bpp
);
133 ASSERT_EQ(expected
, color
);
139 memcpy(&color
, &pixels
[i
* p
.bpp
], p
.bpp
);
140 ASSERT_EQ(expected
, color
);
145 unreachable("bad bpp");
150 INSTANTIATE_TEST_CASE_P(
152 OSMesaRenderTestFixture
,
154 Params
{ OSMESA_RGBA
, GL_UNSIGNED_BYTE
, 4, 0xbf80ff40 },
155 Params
{ OSMESA_BGRA
, GL_UNSIGNED_BYTE
, 4, 0xbf40ff80 },
156 Params
{ OSMESA_ARGB
, GL_UNSIGNED_BYTE
, 4, 0x80ff40bf},
157 Params
{ OSMESA_RGB
, GL_UNSIGNED_BYTE
, 3, 0x80ff40 },
158 Params
{ OSMESA_RGBA
, GL_UNSIGNED_SHORT
, 8, 0xbfff8000ffff4000ull
},
159 Params
{ OSMESA_RGB_565
, GL_UNSIGNED_SHORT_5_6_5
, 2, ((0x10 << 0) |