Add OpenGL renderer capability target
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "pch.h"
|
||||
#include "app.h"
|
||||
#include "renderer_api/shader_catalog.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include "shader.h"
|
||||
|
||||
void App::initShaders()
|
||||
@@ -13,27 +14,33 @@ void App::initShaders()
|
||||
render_task([] {
|
||||
GLint n_exts;
|
||||
glGetIntegerv(GL_NUM_EXTENSIONS, &n_exts);
|
||||
std::vector<std::string> extension_storage;
|
||||
std::vector<std::string_view> extension_views;
|
||||
extension_storage.reserve(n_exts);
|
||||
extension_views.reserve(n_exts);
|
||||
for (int i = 0; i < n_exts; i++)
|
||||
{
|
||||
std::string ext = (const char*)glGetStringi(GL_EXTENSIONS, i);
|
||||
if (ext.find("shader_framebuffer_fetch") != std::string::npos)
|
||||
ShaderManager::ext_framebuffer_fetch = true;
|
||||
if (ext.find("map_buffer_alignment") != std::string::npos)
|
||||
ShaderManager::ext_map_aligned = true;
|
||||
#if __GLES__ && !__WEB__
|
||||
if (ext.find("texture_float") != std::string::npos)
|
||||
ShaderManager::ext_float32 = true;
|
||||
if (ext.find("texture_float_linear") != std::string::npos)
|
||||
ShaderManager::ext_float32_linear = true;
|
||||
if (ext.find("color_buffer_float") != std::string::npos)
|
||||
ShaderManager::ext_float32 = true;
|
||||
if (ext.find("texture_half_float") != std::string::npos)
|
||||
ShaderManager::ext_float16 = true;
|
||||
if (ext.find("color_buffer_half_float") != std::string::npos)
|
||||
ShaderManager::ext_float16 = true;
|
||||
#endif
|
||||
LOG("EXT: %s", ext.c_str());
|
||||
extension_storage.emplace_back((const char*)glGetStringi(GL_EXTENSIONS, i));
|
||||
extension_views.push_back(extension_storage.back());
|
||||
LOG("EXT: %s", extension_storage.back().c_str());
|
||||
}
|
||||
|
||||
pp::renderer::gl::OpenGlRuntime runtime;
|
||||
#if __GL__
|
||||
runtime.desktop_gl = true;
|
||||
#endif
|
||||
#if __GLES__
|
||||
runtime.gles = true;
|
||||
#endif
|
||||
#if __WEB__
|
||||
runtime.web = true;
|
||||
#endif
|
||||
const auto capabilities = pp::renderer::gl::detect_opengl_capabilities(extension_views, runtime);
|
||||
ShaderManager::ext_framebuffer_fetch = capabilities.framebuffer_fetch;
|
||||
ShaderManager::ext_map_aligned = capabilities.map_buffer_alignment;
|
||||
ShaderManager::ext_float32 = capabilities.float32_textures;
|
||||
ShaderManager::ext_float32_linear = capabilities.float32_linear;
|
||||
ShaderManager::ext_float16 = capabilities.float16_textures;
|
||||
});
|
||||
|
||||
#if __GL__
|
||||
|
||||
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