174 lines
7.6 KiB
C++
174 lines
7.6 KiB
C++
#include "renderer_gl/opengl_capabilities.h"
|
|
#include "test_harness.h"
|
|
|
|
#include <array>
|
|
#include <cstdint>
|
|
#include <string_view>
|
|
|
|
namespace {
|
|
|
|
void detects_common_extension_capabilities(pp::tests::Harness& h)
|
|
{
|
|
constexpr std::array<std::string_view, 2> extensions {
|
|
"GL_EXT_shader_framebuffer_fetch",
|
|
"GL_ARB_map_buffer_alignment",
|
|
};
|
|
|
|
const auto capabilities = pp::renderer::gl::detect_opengl_capabilities(
|
|
extensions,
|
|
pp::renderer::gl::OpenGlRuntime {});
|
|
|
|
PP_EXPECT(h, capabilities.framebuffer_fetch);
|
|
PP_EXPECT(h, capabilities.map_buffer_alignment);
|
|
PP_EXPECT(h, !capabilities.float32_textures);
|
|
PP_EXPECT(h, !capabilities.float16_textures);
|
|
}
|
|
|
|
void treats_desktop_gl_float_rendering_as_core(pp::tests::Harness& h)
|
|
{
|
|
const auto capabilities = pp::renderer::gl::detect_opengl_capabilities(
|
|
{},
|
|
pp::renderer::gl::OpenGlRuntime { .desktop_gl = true });
|
|
|
|
PP_EXPECT(h, capabilities.float32_textures);
|
|
PP_EXPECT(h, capabilities.float32_linear);
|
|
PP_EXPECT(h, capabilities.float16_textures);
|
|
}
|
|
|
|
void detects_gles_texture_float_extensions(pp::tests::Harness& h)
|
|
{
|
|
constexpr std::array<std::string_view, 3> extensions {
|
|
"GL_OES_texture_float",
|
|
"GL_OES_texture_float_linear",
|
|
"GL_EXT_color_buffer_half_float",
|
|
};
|
|
|
|
const auto capabilities = pp::renderer::gl::detect_opengl_capabilities(
|
|
extensions,
|
|
pp::renderer::gl::OpenGlRuntime { .gles = true });
|
|
|
|
PP_EXPECT(h, capabilities.float32_textures);
|
|
PP_EXPECT(h, capabilities.float32_linear);
|
|
PP_EXPECT(h, capabilities.float16_textures);
|
|
}
|
|
|
|
void ignores_gles_texture_extensions_for_webgl_runtime(pp::tests::Harness& h)
|
|
{
|
|
constexpr std::array<std::string_view, 3> extensions {
|
|
"GL_OES_texture_float",
|
|
"GL_OES_texture_float_linear",
|
|
"GL_EXT_color_buffer_half_float",
|
|
};
|
|
|
|
const auto capabilities = pp::renderer::gl::detect_opengl_capabilities(
|
|
extensions,
|
|
pp::renderer::gl::OpenGlRuntime { .gles = true, .web = true });
|
|
|
|
PP_EXPECT(h, !capabilities.float32_textures);
|
|
PP_EXPECT(h, !capabilities.float32_linear);
|
|
PP_EXPECT(h, !capabilities.float16_textures);
|
|
}
|
|
|
|
void selects_texture_upload_type_from_internal_format(pp::tests::Harness& h)
|
|
{
|
|
constexpr std::uint32_t gl_unsigned_byte = 0x1401U;
|
|
constexpr std::uint32_t gl_float = 0x1406U;
|
|
constexpr std::uint32_t gl_half_float = 0x140BU;
|
|
constexpr std::uint32_t gl_rgba8 = 0x8058U;
|
|
constexpr std::uint32_t gl_rgba32f = 0x8814U;
|
|
constexpr std::uint32_t gl_rgba16f = 0x881AU;
|
|
|
|
PP_EXPECT(h, pp::renderer::gl::texture_upload_type_for_internal_format(gl_rgba8) == gl_unsigned_byte);
|
|
PP_EXPECT(h, pp::renderer::gl::texture_upload_type_for_internal_format(gl_rgba32f) == gl_float);
|
|
PP_EXPECT(h, pp::renderer::gl::texture_upload_type_for_internal_format(gl_rgba16f) == gl_half_float);
|
|
PP_EXPECT(h, pp::renderer::gl::texture_upload_type_for_internal_format(0U) == gl_unsigned_byte);
|
|
}
|
|
|
|
void maps_image_channel_count_to_texture_format(pp::tests::Harness& h)
|
|
{
|
|
constexpr std::uint32_t gl_red = 0x1903U;
|
|
constexpr std::uint32_t gl_rgb = 0x1907U;
|
|
constexpr std::uint32_t gl_rgba = 0x1908U;
|
|
constexpr std::uint32_t gl_rg = 0x8227U;
|
|
constexpr std::uint32_t gl_r8 = 0x8229U;
|
|
constexpr std::uint32_t gl_rg8 = 0x822BU;
|
|
constexpr std::uint32_t gl_rgb8 = 0x8051U;
|
|
constexpr std::uint32_t gl_rgba8 = 0x8058U;
|
|
|
|
const auto r = pp::renderer::gl::texture_format_for_channel_count(1U);
|
|
const auto rg = pp::renderer::gl::texture_format_for_channel_count(2U);
|
|
const auto rgb = pp::renderer::gl::texture_format_for_channel_count(3U);
|
|
const auto rgba = pp::renderer::gl::texture_format_for_channel_count(4U);
|
|
const auto invalid = pp::renderer::gl::texture_format_for_channel_count(5U);
|
|
|
|
PP_EXPECT(h, r.internal_format == gl_r8);
|
|
PP_EXPECT(h, r.pixel_format == gl_red);
|
|
PP_EXPECT(h, rg.internal_format == gl_rg8);
|
|
PP_EXPECT(h, rg.pixel_format == gl_rg);
|
|
PP_EXPECT(h, rgb.internal_format == gl_rgb8);
|
|
PP_EXPECT(h, rgb.pixel_format == gl_rgb);
|
|
PP_EXPECT(h, rgba.internal_format == gl_rgba8);
|
|
PP_EXPECT(h, rgba.pixel_format == gl_rgba);
|
|
PP_EXPECT(h, invalid.channel_count == 0U);
|
|
PP_EXPECT(h, invalid.internal_format == 0U);
|
|
PP_EXPECT(h, invalid.pixel_format == 0U);
|
|
}
|
|
|
|
void names_framebuffer_status_codes(pp::tests::Harness& h)
|
|
{
|
|
PP_EXPECT(h, pp::renderer::gl::framebuffer_status_name(0x8CD5U) == std::string_view("GL_FRAMEBUFFER_COMPLETE"));
|
|
PP_EXPECT(h, pp::renderer::gl::framebuffer_status_name(0x8219U) == std::string_view("GL_FRAMEBUFFER_UNDEFINED"));
|
|
PP_EXPECT(h, pp::renderer::gl::framebuffer_status_name(0x8CD6U)
|
|
== std::string_view("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT"));
|
|
PP_EXPECT(h, pp::renderer::gl::framebuffer_status_name(0x8CD7U)
|
|
== std::string_view("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"));
|
|
PP_EXPECT(h, pp::renderer::gl::framebuffer_status_name(0x8CDBU)
|
|
== std::string_view("GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER"));
|
|
PP_EXPECT(h, pp::renderer::gl::framebuffer_status_name(0x8CDCU)
|
|
== std::string_view("GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER"));
|
|
PP_EXPECT(h, pp::renderer::gl::framebuffer_status_name(0x8CDDU)
|
|
== std::string_view("GL_FRAMEBUFFER_UNSUPPORTED"));
|
|
PP_EXPECT(h, pp::renderer::gl::framebuffer_status_name(0x8D56U)
|
|
== std::string_view("GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE"));
|
|
PP_EXPECT(h, pp::renderer::gl::framebuffer_status_name(0U) == std::string_view("UNKNOWN"));
|
|
}
|
|
|
|
void maps_shape_index_and_primitive_modes(pp::tests::Harness& h)
|
|
{
|
|
constexpr std::uint32_t gl_points = 0x0000U;
|
|
constexpr std::uint32_t gl_lines = 0x0001U;
|
|
constexpr std::uint32_t gl_triangles = 0x0004U;
|
|
constexpr std::uint32_t gl_unsigned_short = 0x1403U;
|
|
constexpr std::uint32_t gl_unsigned_int = 0x1405U;
|
|
|
|
PP_EXPECT(h, pp::renderer::gl::index_type_for_index_size(2U) == gl_unsigned_short);
|
|
PP_EXPECT(h, pp::renderer::gl::index_type_for_index_size(4U) == gl_unsigned_int);
|
|
PP_EXPECT(h, pp::renderer::gl::index_type_for_index_size(1U) == 0U);
|
|
PP_EXPECT(h, pp::renderer::gl::index_type_for_index_size(8U) == 0U);
|
|
|
|
PP_EXPECT(h, pp::renderer::gl::primitive_mode_for_fill_count(1U) == gl_points);
|
|
PP_EXPECT(h, pp::renderer::gl::primitive_mode_for_fill_count(2U) == gl_lines);
|
|
PP_EXPECT(h, pp::renderer::gl::primitive_mode_for_fill_count(3U) == gl_triangles);
|
|
PP_EXPECT(h, pp::renderer::gl::primitive_mode_for_fill_count(99U) == gl_triangles);
|
|
|
|
PP_EXPECT(h, pp::renderer::gl::primitive_mode_for_stroke_count(1U) == gl_points);
|
|
PP_EXPECT(h, pp::renderer::gl::primitive_mode_for_stroke_count(2U) == gl_lines);
|
|
PP_EXPECT(h, pp::renderer::gl::primitive_mode_for_stroke_count(99U) == gl_lines);
|
|
}
|
|
|
|
}
|
|
|
|
int main()
|
|
{
|
|
pp::tests::Harness harness;
|
|
harness.run("detects_common_extension_capabilities", detects_common_extension_capabilities);
|
|
harness.run("treats_desktop_gl_float_rendering_as_core", treats_desktop_gl_float_rendering_as_core);
|
|
harness.run("detects_gles_texture_float_extensions", detects_gles_texture_float_extensions);
|
|
harness.run("ignores_gles_texture_extensions_for_webgl_runtime", ignores_gles_texture_extensions_for_webgl_runtime);
|
|
harness.run("selects_texture_upload_type_from_internal_format", selects_texture_upload_type_from_internal_format);
|
|
harness.run("maps_image_channel_count_to_texture_format", maps_image_channel_count_to_texture_format);
|
|
harness.run("names_framebuffer_status_codes", names_framebuffer_status_codes);
|
|
harness.run("maps_shape_index_and_primitive_modes", maps_shape_index_and_primitive_modes);
|
|
return harness.finish();
|
|
}
|