Extract OpenGL shader attribute bindings
This commit is contained in:
43
src/renderer_gl/shader_bindings.cpp
Normal file
43
src/renderer_gl/shader_bindings.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "renderer_gl/shader_bindings.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
|
||||
namespace pp::renderer::gl {
|
||||
|
||||
std::span<const OpenGlAttributeBinding> panopainter_shader_attribute_bindings() noexcept
|
||||
{
|
||||
static constexpr std::array<OpenGlAttributeBinding, 5> bindings {
|
||||
OpenGlAttributeBinding { .name = "pos", .location = 0 },
|
||||
OpenGlAttributeBinding { .name = "uvs", .location = 1 },
|
||||
OpenGlAttributeBinding { .name = "uvs2", .location = 2 },
|
||||
OpenGlAttributeBinding { .name = "col", .location = 3 },
|
||||
OpenGlAttributeBinding { .name = "nor", .location = 3 },
|
||||
};
|
||||
|
||||
return bindings;
|
||||
}
|
||||
|
||||
pp::foundation::Status validate_shader_attribute_bindings(
|
||||
std::span<const OpenGlAttributeBinding> bindings) noexcept
|
||||
{
|
||||
if (bindings.empty()) {
|
||||
return pp::foundation::Status::invalid_argument("shader attribute binding catalog is empty");
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < bindings.size(); ++i) {
|
||||
if (bindings[i].name == nullptr || bindings[i].name[0] == '\0') {
|
||||
return pp::foundation::Status::invalid_argument("shader attribute binding has no name");
|
||||
}
|
||||
|
||||
for (std::size_t j = i + 1; j < bindings.size(); ++j) {
|
||||
if (bindings[j].name != nullptr && std::strcmp(bindings[i].name, bindings[j].name) == 0) {
|
||||
return pp::foundation::Status::invalid_argument("shader attribute binding name is duplicated");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
}
|
||||
19
src/renderer_gl/shader_bindings.h
Normal file
19
src/renderer_gl/shader_bindings.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "foundation/result.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
|
||||
namespace pp::renderer::gl {
|
||||
|
||||
struct OpenGlAttributeBinding {
|
||||
const char* name = "";
|
||||
std::uint32_t location = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] std::span<const OpenGlAttributeBinding> panopainter_shader_attribute_bindings() noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_shader_attribute_bindings(
|
||||
std::span<const OpenGlAttributeBinding> bindings) noexcept;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user