Migrate shaders to the registry (#964)

Co-authored-by: Bart Louwers <bart.louwers@gmail.com>
This commit is contained in:
mwilsnd
2023-04-04 14:00:12 -05:00
committed by GitHub
parent daeae05181
commit f207aee091
97 changed files with 1924 additions and 3577 deletions

View File

@@ -1,30 +1,44 @@
#include <mbgl/programs/program_parameters.hpp>
#include <mbgl/util/string.hpp>
#include <string_view>
#include <stdexcept>
namespace mbgl {
ProgramParameters::ProgramParameters(const float pixelRatio,
const bool overdraw)
: defines([&] {
std::string result;
result.reserve(32);
result += "#define DEVICE_PIXEL_RATIO ";
result += util::toString(pixelRatio, true);
result += '\n';
if (overdraw) {
result += "#define OVERDRAW_INSPECTOR\n";
}
return result;
std::string result;
result.reserve(32);
result += "#define DEVICE_PIXEL_RATIO ";
result += util::toString(pixelRatio, true);
result += '\n';
if (overdraw) {
result += "#define OVERDRAW_INSPECTOR\n";
}
return result;
}())
{}
ProgramParameters ProgramParameters::withShaderSource(std::string_view vertexSource,
std::string_view fragmentSource) const noexcept
ProgramParameters ProgramParameters::withShaderSource(
const ProgramSource &source) const noexcept
{
assert(gfx::Backend::Type::TYPE_MAX != source.backend);
ProgramParameters params = *this;
params.vertexSource_ = vertexSource;
params.fragmentSource_ = fragmentSource;
params.userSources[static_cast<size_t>(source.backend)]
= source;
return params;
}
ProgramParameters ProgramParameters::withDefaultSource(
const ProgramSource &source) const noexcept
{
assert(gfx::Backend::Type::TYPE_MAX != source.backend);
ProgramParameters params = *this;
params.defaultSources[static_cast<size_t>(source.backend)]
= source;
return params;
}
@@ -32,12 +46,30 @@ const std::string& ProgramParameters::getDefines() const {
return defines;
}
const std::string& ProgramParameters::vertexSource() const noexcept {
return vertexSource_;
const std::string&
ProgramParameters::vertexSource(gfx::Backend::Type backend) const {
assert(gfx::Backend::Type::TYPE_MAX != backend);
if (userSources[static_cast<size_t>(backend)].vertex.length() > 0) {
return userSources[static_cast<size_t>(backend)].vertex;
} else if (defaultSources[static_cast<size_t>(backend)].vertex.length() > 0) {
return defaultSources[static_cast<size_t>(backend)].vertex;
} else {
throw std::runtime_error("No vertex shader source provided for selected backend!");
}
}
const std::string& ProgramParameters::fragmentSource() const noexcept {
return fragmentSource_;
const std::string&
ProgramParameters::fragmentSource(gfx::Backend::Type backend) const {
assert(gfx::Backend::Type::TYPE_MAX != backend);
if (userSources[static_cast<size_t>(backend)].fragment.length() > 0) {
return userSources[static_cast<size_t>(backend)].fragment;
} else if (defaultSources[static_cast<size_t>(backend)].fragment.length() > 0) {
return defaultSources[static_cast<size_t>(backend)].fragment;
} else {
throw std::runtime_error("No fragment shader source provided for selected backend!");
}
}
} // namespace mbgl