Metal setup merge (#1616)
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Alex Cristici <alex.cristici@gmail.com> Co-authored-by: mwilsnd <mwilsnd@gmail.com> Co-authored-by: Stefan Karschti <stefan.karschti@gmail.com> Co-authored-by: Bart Louwers <bart@emeel.net> Co-authored-by: Alex Cristici <alex@skoon.energy> Co-authored-by: Bart Louwers <bart.louwers@gmail.com> Co-authored-by: Wei Chen <alanchenboy@gmail.com> Co-authored-by: Siarhei Fedartsou <siarhei.fedartsou@gmail.com> Co-authored-by: tdcosta100 <tdcosta100@gmail.com>
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include <mbgl/shaders/shader_manifest.hpp>
|
||||
#ifdef MBGL_RENDER_BACKEND_OPENGL
|
||||
#if !MLN_RENDER_BACKEND_METAL
|
||||
#include <mbgl/gl/program.hpp>
|
||||
#endif
|
||||
|
||||
@@ -54,7 +54,11 @@ public:
|
||||
|
||||
Program(const ProgramParameters& programParameters) {
|
||||
switch (gfx::Backend::GetType()) {
|
||||
#ifdef MBGL_RENDER_BACKEND_OPENGL
|
||||
#if MLN_RENDER_BACKEND_METAL
|
||||
case gfx::Backend::Type::Metal: {
|
||||
break;
|
||||
}
|
||||
#else // MLN_RENDER_BACKEND_OPENGL
|
||||
case gfx::Backend::Type::OpenGL: {
|
||||
program = std::make_unique<gl::Program<Name>>(programParameters.withDefaultSource(
|
||||
{gfx::Backend::Type::OpenGL,
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
#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;
|
||||
}()) {}
|
||||
: defines(2) {
|
||||
defines["DEVICE_PIXEL_RATIO"] = util::toString(pixelRatio, true);
|
||||
if (overdraw) {
|
||||
defines["OVERDRAW_INSPECTOR"] = std::string();
|
||||
}
|
||||
}
|
||||
|
||||
ProgramParameters ProgramParameters::withShaderSource(const ProgramSource& source) const noexcept {
|
||||
assert(gfx::Backend::Type::TYPE_MAX != source.backend);
|
||||
@@ -34,8 +31,19 @@ ProgramParameters ProgramParameters::withDefaultSource(const ProgramSource& sour
|
||||
return params;
|
||||
}
|
||||
|
||||
const std::string& ProgramParameters::getDefines() const {
|
||||
return defines;
|
||||
const std::string& ProgramParameters::getDefinesString() const {
|
||||
if (definesStr.empty() && !defines.empty()) {
|
||||
definesStr.assign(defines.size() * 32, '\0');
|
||||
definesStr.clear();
|
||||
for (const auto& pair : defines) {
|
||||
definesStr.append("#define ").append(pair.first);
|
||||
if (!pair.second.empty()) {
|
||||
definesStr.append(" ").append(pair.second);
|
||||
}
|
||||
definesStr.append("\n");
|
||||
}
|
||||
}
|
||||
return definesStr;
|
||||
}
|
||||
|
||||
const std::string& ProgramParameters::vertexSource(gfx::Backend::Type backend) const {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -18,8 +19,7 @@ public:
|
||||
ProgramSource() = default;
|
||||
|
||||
/// @brief Construct a new ProgramSource object
|
||||
/// @param forBackend The provided source code is intended for use with the give
|
||||
/// rendering backend.
|
||||
/// @param forBackend The provided source code is intended for use with the given rendering backend.
|
||||
/// @param vertex_ The vertex shader source code, or empty string if not provided.
|
||||
/// @param fragment_ The fragment shader source code, or empty string if not provided.
|
||||
ProgramSource(gfx::Backend::Type forBackend, const std::string& vertex_, const std::string& fragment_)
|
||||
@@ -45,7 +45,11 @@ public:
|
||||
/// @brief Get a list of built-in shader preprocessor defines
|
||||
/// @return Shader source string
|
||||
/// @todo With the addition of future backends, defines should also be backend-aware
|
||||
const std::string& getDefines() const;
|
||||
const std::string& getDefinesString() const;
|
||||
|
||||
/// @brief Get a list of built-in shader preprocessor defines
|
||||
/// @return Map of key-value pairs representing preprocessor definitions
|
||||
const std::unordered_map<std::string, std::string>& getDefines() const { return defines; }
|
||||
|
||||
/// @brief Get source code for the vertex shader compatible with the requested backend
|
||||
/// @param backend Backend type
|
||||
@@ -58,7 +62,10 @@ public:
|
||||
const std::string& fragmentSource(gfx::Backend::Type backend) const;
|
||||
|
||||
private:
|
||||
std::string defines;
|
||||
std::unordered_map<std::string, std::string> defines;
|
||||
|
||||
// cached value of `defines` converted to string format
|
||||
mutable std::string definesStr;
|
||||
|
||||
std::array<ProgramSource, static_cast<size_t>(gfx::Backend::Type::TYPE_MAX)> defaultSources;
|
||||
std::array<ProgramSource, static_cast<size_t>(gfx::Backend::Type::TYPE_MAX)> userSources;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <array>
|
||||
|
||||
#include <mbgl/shaders/shader_manifest.hpp>
|
||||
#ifdef MBGL_RENDER_BACKEND_OPENGL
|
||||
#if !MLN_RENDER_BACKEND_METAL
|
||||
#include <mbgl/gl/program.hpp>
|
||||
#endif
|
||||
|
||||
@@ -263,7 +263,7 @@ public:
|
||||
|
||||
SymbolProgram(const ProgramParameters& programParameters) {
|
||||
switch (gfx::Backend::GetType()) {
|
||||
#ifdef MBGL_RENDER_BACKEND_OPENGL
|
||||
#if !MLN_RENDER_BACKEND_METAL
|
||||
case gfx::Backend::Type::OpenGL: {
|
||||
program = std::make_unique<gl::Program<Name>>(programParameters.withDefaultSource(
|
||||
{gfx::Backend::Type::OpenGL,
|
||||
|
||||
Reference in New Issue
Block a user