Add OpenGL renderer capability target
This commit is contained in:
53
src/renderer_gl/opengl_capabilities.cpp
Normal file
53
src/renderer_gl/opengl_capabilities.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
|
||||
namespace pp::renderer::gl {
|
||||
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] bool contains(std::string_view text, std::string_view needle) noexcept
|
||||
{
|
||||
return text.find(needle) != std::string_view::npos;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
OpenGlCapabilities detect_opengl_capabilities(
|
||||
std::span<const std::string_view> extensions,
|
||||
OpenGlRuntime runtime) noexcept
|
||||
{
|
||||
OpenGlCapabilities capabilities;
|
||||
|
||||
if (runtime.desktop_gl) {
|
||||
capabilities.float32_textures = true;
|
||||
capabilities.float32_linear = true;
|
||||
capabilities.float16_textures = true;
|
||||
}
|
||||
|
||||
for (const auto extension : extensions) {
|
||||
if (contains(extension, "shader_framebuffer_fetch")) {
|
||||
capabilities.framebuffer_fetch = true;
|
||||
}
|
||||
|
||||
if (contains(extension, "map_buffer_alignment")) {
|
||||
capabilities.map_buffer_alignment = true;
|
||||
}
|
||||
|
||||
if (runtime.gles && !runtime.web) {
|
||||
if (contains(extension, "texture_float") || contains(extension, "color_buffer_float")) {
|
||||
capabilities.float32_textures = true;
|
||||
}
|
||||
|
||||
if (contains(extension, "texture_float_linear")) {
|
||||
capabilities.float32_linear = true;
|
||||
}
|
||||
|
||||
if (contains(extension, "texture_half_float") || contains(extension, "color_buffer_half_float")) {
|
||||
capabilities.float16_textures = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
}
|
||||
26
src/renderer_gl/opengl_capabilities.h
Normal file
26
src/renderer_gl/opengl_capabilities.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#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;
|
||||
};
|
||||
|
||||
[[nodiscard]] OpenGlCapabilities detect_opengl_capabilities(
|
||||
std::span<const std::string_view> extensions,
|
||||
OpenGlRuntime runtime) noexcept;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user