Apply startup GL state through renderer GL

This commit is contained in:
2026-06-03 05:41:27 +02:00
parent 692fe08d9f
commit b2335b1656
7 changed files with 159 additions and 19 deletions

View File

@@ -7,9 +7,59 @@
#include <cstring>
#include <limits>
#include <string_view>
#include <vector>
namespace {
struct RecordedOpenGlStateCall {
enum class Kind {
enable,
disable,
blend_func,
blend_equation_separate,
};
Kind kind = Kind::enable;
std::uint32_t first = 0;
std::uint32_t second = 0;
};
std::vector<RecordedOpenGlStateCall> recorded_state_calls;
void record_enable(std::uint32_t state) noexcept
{
recorded_state_calls.push_back(RecordedOpenGlStateCall {
.kind = RecordedOpenGlStateCall::Kind::enable,
.first = state,
});
}
void record_disable(std::uint32_t state) noexcept
{
recorded_state_calls.push_back(RecordedOpenGlStateCall {
.kind = RecordedOpenGlStateCall::Kind::disable,
.first = state,
});
}
void record_blend_func(std::uint32_t source_factor, std::uint32_t destination_factor) noexcept
{
recorded_state_calls.push_back(RecordedOpenGlStateCall {
.kind = RecordedOpenGlStateCall::Kind::blend_func,
.first = source_factor,
.second = destination_factor,
});
}
void record_blend_equation_separate(std::uint32_t color_equation, std::uint32_t alpha_equation) noexcept
{
recorded_state_calls.push_back(RecordedOpenGlStateCall {
.kind = RecordedOpenGlStateCall::Kind::blend_equation_separate,
.first = color_equation,
.second = alpha_equation,
});
}
void detects_common_extension_capabilities(pp::tests::Harness& h)
{
constexpr std::array<std::string_view, 2> extensions {
@@ -651,6 +701,43 @@ void maps_app_initialization_parameters(pp::tests::Harness& h)
PP_EXPECT(h, pp::renderer::gl::active_texture_unit(4U) == 0x84C4U);
}
void applies_app_initialization_state(pp::tests::Harness& h)
{
recorded_state_calls.clear();
const auto status = pp::renderer::gl::apply_panopainter_initial_state(
pp::renderer::gl::OpenGlStateDispatch {
.enable = record_enable,
.disable = record_disable,
.blend_func = record_blend_func,
.blend_equation_separate = record_blend_equation_separate,
});
PP_EXPECT(h, status.ok());
PP_EXPECT(h, recorded_state_calls.size() == 3U);
PP_EXPECT(h, recorded_state_calls[0].kind == RecordedOpenGlStateCall::Kind::disable);
PP_EXPECT(h, recorded_state_calls[0].first == 0x0B71U);
PP_EXPECT(h, recorded_state_calls[1].kind == RecordedOpenGlStateCall::Kind::blend_func);
PP_EXPECT(h, recorded_state_calls[1].first == 0x0302U);
PP_EXPECT(h, recorded_state_calls[1].second == 0x0303U);
PP_EXPECT(h, recorded_state_calls[2].kind == RecordedOpenGlStateCall::Kind::blend_equation_separate);
PP_EXPECT(h, recorded_state_calls[2].first == 0x8006U);
PP_EXPECT(h, recorded_state_calls[2].second == 0x8008U);
}
void rejects_incomplete_app_initialization_state_dispatch(pp::tests::Harness& h)
{
const auto status = pp::renderer::gl::apply_panopainter_initial_state(
pp::renderer::gl::OpenGlStateDispatch {
.enable = record_enable,
.disable = record_disable,
.blend_func = record_blend_func,
});
PP_EXPECT(h, !status.ok());
PP_EXPECT(h, status.code == pp::foundation::StatusCode::invalid_argument);
}
void maps_renderer_viewports_and_scissors(pp::tests::Harness& h)
{
const auto viewport = pp::renderer::gl::viewport_for_renderer_viewport(
@@ -1025,6 +1112,8 @@ int main()
harness.run("maps_renderer_sampler_states", maps_renderer_sampler_states);
harness.run("exposes_shader_attribute_binding_catalog", exposes_shader_attribute_binding_catalog);
harness.run("maps_app_initialization_parameters", maps_app_initialization_parameters);
harness.run("applies_app_initialization_state", applies_app_initialization_state);
harness.run("rejects_incomplete_app_initialization_state_dispatch", rejects_incomplete_app_initialization_state_dispatch);
harness.run("maps_renderer_viewports_and_scissors", maps_renderer_viewports_and_scissors);
harness.run("maps_renderer_blend_state_tokens", maps_renderer_blend_state_tokens);
harness.run("maps_renderer_color_write_masks", maps_renderer_color_write_masks);