Files
panopainter/src/renderer_gl/opengl_capabilities.h

284 lines
12 KiB
C++

#pragma once
#include "renderer_api/renderer_api.h"
#include <array>
#include <cstdint>
#include <span>
#include <string_view>
namespace pp::renderer::gl {
struct OpenGlRuntime {
bool desktop_gl = false;
bool gles = false;
bool web = false;
};
struct OpenGlCapabilities {
bool framebuffer_fetch = false;
bool map_buffer_alignment = false;
bool float32_textures = false;
bool float32_linear = false;
bool float16_textures = false;
};
struct OpenGlPixelFormat {
std::uint32_t internal_format = 0;
std::uint32_t pixel_format = 0;
std::uint32_t channel_count = 0;
};
struct OpenGlTextureParameter {
std::uint32_t name = 0;
std::uint32_t value = 0;
};
struct OpenGlSamplerState {
std::uint32_t min_filter = 0;
std::uint32_t mag_filter = 0;
std::uint32_t wrap_s = 0;
std::uint32_t wrap_t = 0;
std::uint32_t wrap_r = 0;
bool supported = false;
};
struct OpenGlViewportRect {
std::int32_t x = 0;
std::int32_t y = 0;
std::int32_t width = 0;
std::int32_t height = 0;
float min_depth = 0.0F;
float max_depth = 1.0F;
};
struct OpenGlScissorRect {
std::uint8_t enabled = 0;
std::int32_t x = 0;
std::int32_t y = 0;
std::int32_t width = 0;
std::int32_t height = 0;
};
struct OpenGlEnumMapping {
std::uint32_t value = 0;
bool supported = false;
};
struct OpenGlColorWriteMask {
std::uint8_t r = 0;
std::uint8_t g = 0;
std::uint8_t b = 0;
std::uint8_t a = 0;
};
struct OpenGlClearValues {
std::array<float, 4> color {};
float depth = 1.0F;
std::uint8_t stencil = 0;
};
struct OpenGlBlendState {
std::uint8_t enabled = 0;
std::uint32_t source_color_factor = 0;
std::uint32_t destination_color_factor = 0;
std::uint32_t color_equation = 0;
std::uint32_t source_alpha_factor = 0;
std::uint32_t destination_alpha_factor = 0;
std::uint32_t alpha_equation = 0;
OpenGlColorWriteMask color_write_mask;
bool supported = false;
};
struct OpenGlDepthState {
std::uint8_t test_enabled = 0;
std::uint8_t write_enabled = 0;
std::uint32_t compare_function = 0;
bool supported = false;
};
struct OpenGlReadbackFormat {
std::uint32_t pixel_format = 0;
std::uint32_t component_type = 0;
std::uint32_t bytes_per_pixel = 0;
};
struct OpenGlRendererTextureFormat {
std::uint32_t internal_format = 0;
std::uint32_t pixel_format = 0;
std::uint32_t component_type = 0;
std::uint32_t bytes_per_pixel = 0;
};
struct OpenGlWindowsWglContextConfig {
std::array<std::int32_t, 9> context_attributes {};
std::array<std::int32_t, 15> pixel_format_attributes {};
};
struct OpenGlInitialState {
bool depth_test_enabled = false;
std::uint32_t depth_test_state = 0;
std::uint32_t source_color_factor = 0;
std::uint32_t destination_color_factor = 0;
std::uint32_t color_equation = 0;
std::uint32_t alpha_equation = 0;
};
using OpenGlCapabilityFn = void (*)(std::uint32_t state) noexcept;
using OpenGlBlendFuncFn = void (*)(std::uint32_t source_factor, std::uint32_t destination_factor) noexcept;
using OpenGlBlendEquationSeparateFn = void (*)(std::uint32_t color_equation, std::uint32_t alpha_equation) noexcept;
struct OpenGlStateDispatch {
OpenGlCapabilityFn enable = nullptr;
OpenGlCapabilityFn disable = nullptr;
OpenGlBlendFuncFn blend_func = nullptr;
OpenGlBlendEquationSeparateFn blend_equation_separate = nullptr;
};
[[nodiscard]] OpenGlCapabilities detect_opengl_capabilities(
std::span<const std::string_view> extensions,
OpenGlRuntime runtime) noexcept;
[[nodiscard]] pp::renderer::RenderDeviceFeatures render_device_features(
OpenGlCapabilities capabilities) noexcept;
[[nodiscard]] OpenGlInitialState panopainter_initial_state() noexcept;
[[nodiscard]] pp::foundation::Status apply_panopainter_initial_state(OpenGlStateDispatch dispatch) noexcept;
[[nodiscard]] std::uint32_t extension_count_query() noexcept;
[[nodiscard]] std::uint32_t extension_string_name() noexcept;
[[nodiscard]] std::uint32_t no_error_code() noexcept;
[[nodiscard]] const char* opengl_error_name(std::uint32_t error_code) noexcept;
[[nodiscard]] std::uint32_t texture_upload_type_for_internal_format(std::uint32_t internal_format) noexcept;
[[nodiscard]] std::uint32_t unsigned_byte_component_type() noexcept;
[[nodiscard]] std::uint32_t rgba_pixel_format() noexcept;
[[nodiscard]] OpenGlPixelFormat texture_format_for_channel_count(std::uint32_t channel_count) noexcept;
[[nodiscard]] OpenGlRendererTextureFormat texture_format_for_renderer_format(
pp::renderer::TextureFormat format) noexcept;
[[nodiscard]] OpenGlReadbackFormat rgba8_readback_format() noexcept;
[[nodiscard]] OpenGlReadbackFormat rgba32f_readback_format() noexcept;
[[nodiscard]] std::uint64_t readback_byte_count(
OpenGlReadbackFormat format,
std::uint32_t width,
std::uint32_t height) noexcept;
[[nodiscard]] std::uint32_t pixel_pack_buffer_target() noexcept;
[[nodiscard]] std::uint32_t pixel_unpack_buffer_target() noexcept;
[[nodiscard]] std::uint32_t pixel_buffer_stream_read_usage() noexcept;
[[nodiscard]] std::uint32_t pixel_buffer_map_read_access() noexcept;
[[nodiscard]] std::uint32_t texture_2d_target() noexcept;
[[nodiscard]] std::uint32_t renderbuffer_target() noexcept;
[[nodiscard]] std::uint32_t depth_component24_format() noexcept;
[[nodiscard]] std::uint32_t framebuffer_target() noexcept;
[[nodiscard]] std::uint32_t draw_framebuffer_target() noexcept;
[[nodiscard]] std::uint32_t read_framebuffer_target() noexcept;
[[nodiscard]] std::uint32_t draw_framebuffer_binding_query() noexcept;
[[nodiscard]] std::uint32_t read_framebuffer_binding_query() noexcept;
[[nodiscard]] std::uint32_t framebuffer_color_attachment() noexcept;
[[nodiscard]] std::uint32_t framebuffer_depth_attachment() noexcept;
[[nodiscard]] std::uint32_t framebuffer_complete_status() noexcept;
[[nodiscard]] std::uint32_t default_framebuffer_id() noexcept;
[[nodiscard]] const char* framebuffer_status_name(std::uint32_t status) noexcept;
[[nodiscard]] std::uint32_t framebuffer_color_buffer_mask() noexcept;
[[nodiscard]] std::uint32_t framebuffer_depth_buffer_mask() noexcept;
[[nodiscard]] std::uint32_t framebuffer_stencil_buffer_mask() noexcept;
[[nodiscard]] std::uint32_t clear_mask_for_render_pass(
pp::renderer::RenderPassDesc desc) noexcept;
[[nodiscard]] OpenGlClearValues clear_values_for_render_pass(
pp::renderer::RenderPassDesc desc) noexcept;
[[nodiscard]] std::uint32_t color_write_mask_query() noexcept;
[[nodiscard]] std::uint32_t framebuffer_blit_filter(bool linear) noexcept;
[[nodiscard]] OpenGlEnumMapping blit_filter_for_renderer_filter(
pp::renderer::BlitFilter filter) noexcept;
[[nodiscard]] std::uint32_t primitive_mode_for_renderer_topology(
pp::renderer::PrimitiveTopology topology) noexcept;
[[nodiscard]] std::uint32_t index_type_for_index_size(std::uint32_t index_size_bytes) noexcept;
[[nodiscard]] std::uint32_t primitive_mode_for_fill_count(std::uint32_t vertex_or_index_count) noexcept;
[[nodiscard]] std::uint32_t primitive_mode_for_stroke_count(std::uint32_t vertex_or_index_count) noexcept;
[[nodiscard]] std::uint32_t array_buffer_target() noexcept;
[[nodiscard]] std::uint32_t element_array_buffer_target() noexcept;
[[nodiscard]] std::uint32_t static_draw_buffer_usage() noexcept;
[[nodiscard]] std::uint32_t vertex_attribute_float_component_type() noexcept;
[[nodiscard]] std::uint32_t vertex_attribute_not_normalized() noexcept;
[[nodiscard]] std::uint32_t vertex_shader_stage() noexcept;
[[nodiscard]] std::uint32_t fragment_shader_stage() noexcept;
[[nodiscard]] std::uint32_t shader_compile_status_query() noexcept;
[[nodiscard]] std::uint32_t program_link_status_query() noexcept;
[[nodiscard]] std::uint32_t active_uniform_count_query() noexcept;
[[nodiscard]] std::uint32_t matrix_uniform_not_transposed() noexcept;
[[nodiscard]] std::uint32_t debug_severity_notification() noexcept;
[[nodiscard]] std::uint32_t debug_severity_low() noexcept;
[[nodiscard]] std::uint32_t debug_severity_medium() noexcept;
[[nodiscard]] std::uint32_t debug_severity_high() noexcept;
[[nodiscard]] std::uint32_t debug_output_state() noexcept;
[[nodiscard]] std::uint32_t debug_output_synchronous_state() noexcept;
[[nodiscard]] std::uint32_t version_string_name() noexcept;
[[nodiscard]] std::uint32_t vendor_string_name() noexcept;
[[nodiscard]] std::uint32_t renderer_string_name() noexcept;
[[nodiscard]] std::uint32_t shading_language_version_string_name() noexcept;
[[nodiscard]] std::uint32_t viewport_query() noexcept;
[[nodiscard]] OpenGlViewportRect viewport_for_renderer_viewport(
pp::renderer::Viewport viewport) noexcept;
[[nodiscard]] std::uint32_t color_clear_value_query() noexcept;
[[nodiscard]] std::uint32_t current_program_query() noexcept;
[[nodiscard]] std::uint32_t active_texture_query() noexcept;
[[nodiscard]] std::uint32_t texture_binding_2d_query() noexcept;
[[nodiscard]] std::uint32_t texture_binding_cube_map_query() noexcept;
[[nodiscard]] std::uint32_t sampler_binding_query() noexcept;
[[nodiscard]] std::uint32_t blend_state() noexcept;
[[nodiscard]] std::uint32_t depth_test_state() noexcept;
[[nodiscard]] OpenGlEnumMapping compare_function_for_renderer_compare_op(
pp::renderer::CompareOp op) noexcept;
[[nodiscard]] OpenGlDepthState depth_state_for_renderer_depth_state(
pp::renderer::DepthState state) noexcept;
[[nodiscard]] std::uint32_t scissor_test_state() noexcept;
[[nodiscard]] OpenGlScissorRect scissor_rect_for_renderer_scissor(
pp::renderer::ScissorRect scissor) noexcept;
[[nodiscard]] std::uint32_t program_point_size_state() noexcept;
[[nodiscard]] std::uint32_t line_smooth_state() noexcept;
[[nodiscard]] std::uint32_t source_alpha_blend_factor() noexcept;
[[nodiscard]] std::uint32_t one_minus_source_alpha_blend_factor() noexcept;
[[nodiscard]] std::uint32_t add_blend_equation() noexcept;
[[nodiscard]] std::uint32_t max_blend_equation() noexcept;
[[nodiscard]] OpenGlEnumMapping blend_factor_for_renderer_factor(
pp::renderer::BlendFactor factor) noexcept;
[[nodiscard]] OpenGlEnumMapping blend_equation_for_renderer_op(
pp::renderer::BlendOp op) noexcept;
[[nodiscard]] OpenGlBlendState blend_state_for_renderer_blend_state(
pp::renderer::BlendState state) noexcept;
[[nodiscard]] std::uint32_t rgba8_internal_format() noexcept;
[[nodiscard]] std::uint32_t rgba16f_internal_format() noexcept;
[[nodiscard]] std::uint32_t rgba32f_internal_format() noexcept;
[[nodiscard]] std::uint8_t color_write_disabled() noexcept;
[[nodiscard]] std::uint8_t color_write_enabled() noexcept;
[[nodiscard]] OpenGlColorWriteMask color_write_mask_for_renderer_blend_state(
pp::renderer::BlendState state) noexcept;
[[nodiscard]] std::uint32_t linear_texture_filter() noexcept;
[[nodiscard]] std::uint32_t linear_mipmap_linear_texture_filter() noexcept;
[[nodiscard]] std::uint32_t nearest_texture_filter() noexcept;
[[nodiscard]] std::uint32_t repeat_texture_wrap() noexcept;
[[nodiscard]] std::uint32_t clamp_to_edge_texture_wrap() noexcept;
[[nodiscard]] std::uint32_t clamp_to_border_texture_wrap() noexcept;
[[nodiscard]] OpenGlEnumMapping sampler_filter_for_renderer_filter(
pp::renderer::SamplerFilter filter) noexcept;
[[nodiscard]] OpenGlEnumMapping sampler_min_filter_for_renderer_filters(
pp::renderer::SamplerFilter min_filter,
pp::renderer::SamplerFilter mip_filter) noexcept;
[[nodiscard]] OpenGlEnumMapping sampler_address_mode_for_renderer_mode(
pp::renderer::SamplerAddressMode mode) noexcept;
[[nodiscard]] OpenGlSamplerState sampler_state_for_renderer_sampler_desc(
pp::renderer::SamplerDesc desc) noexcept;
[[nodiscard]] std::uint32_t active_texture_unit(std::uint32_t unit_index) noexcept;
[[nodiscard]] std::uint32_t texture_cube_map_target() noexcept;
[[nodiscard]] std::uint32_t cube_map_allocation_face_texture_target(std::uint32_t face_index) noexcept;
[[nodiscard]] std::span<const std::uint32_t> panopainter_cube_face_texture_targets() noexcept;
[[nodiscard]] std::uint32_t cube_face_texture_target(std::uint32_t face_index) noexcept;
[[nodiscard]] std::span<const OpenGlTextureParameter> default_render_target_texture_parameters() noexcept;
[[nodiscard]] std::array<OpenGlTextureParameter, 5> sampler_parameters_for_filter_wrap(
std::uint32_t filter,
std::uint32_t wrap) noexcept;
[[nodiscard]] std::array<OpenGlTextureParameter, 2> sampler_filter_parameters(
std::uint32_t filter_min,
std::uint32_t filter_mag) noexcept;
[[nodiscard]] std::uint32_t sampler_border_color_parameter_name() noexcept;
[[nodiscard]] OpenGlWindowsWglContextConfig windows_wgl_core_context_3_3_config() noexcept;
}