5ec8cfc735
Add cbt/gfx layer (pipeline + render_target) inspired by Sokol but C++-friendly with RAII and pipeline_desc. Supports building full graphics pipelines (VS/IA/raster/PS/OM), render-to-texture (FBO), and post-processing steps (scene -> RT -> fullscreen quad with sampler + vignette). - Depth/state/viewport/texture cleanup for reliable scene switching. - Updated cube/sphere to demonstrate (sphere uses RT+post). - Vulkan backend easy via PIMPL in impl (same public API). - Fixed depth test, viewport restore, and state leakage on switch. Followed coding conventions (snake_case, trailing returns, east const, include order, no ; after ns/class, etc.).
82 lines
2.1 KiB
C++
82 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <span>
|
|
#include <vector>
|
|
|
|
#include "glm/glm.hpp"
|
|
|
|
namespace cbt::gfx {
|
|
|
|
enum class primitive_type {
|
|
triangles
|
|
};
|
|
|
|
enum class index_type {
|
|
uint16,
|
|
uint32
|
|
};
|
|
|
|
struct attribute_desc {
|
|
std::uint32_t location = 0;
|
|
std::uint32_t num_components = 3;
|
|
std::uint32_t offset = 0;
|
|
};
|
|
|
|
struct pipeline_desc {
|
|
std::span<std::byte const> vertex_data{};
|
|
std::span<std::byte const> index_data{};
|
|
std::vector<attribute_desc> attributes{};
|
|
std::uint32_t vertex_stride = 0;
|
|
char const* vertex_shader_src = nullptr;
|
|
char const* fragment_shader_src = nullptr;
|
|
bool depth_test = true;
|
|
primitive_type primitive = primitive_type::triangles;
|
|
index_type index_type_ = index_type::uint32;
|
|
};
|
|
|
|
class pipeline {
|
|
public:
|
|
pipeline();
|
|
explicit pipeline(pipeline_desc const& desc);
|
|
pipeline(pipeline const&) = delete;
|
|
pipeline(pipeline&& other) noexcept;
|
|
auto operator=(pipeline const&) -> pipeline& = delete;
|
|
auto operator=(pipeline&& other) noexcept -> pipeline&;
|
|
~pipeline();
|
|
|
|
auto valid() const -> bool;
|
|
auto draw(glm::mat4 const& model, glm::mat4 const& view, glm::mat4 const& proj) const -> void;
|
|
auto bind_texture(char const* sampler_name, std::uint32_t texture_id, std::uint32_t unit = 0) const -> void;
|
|
|
|
private:
|
|
struct impl;
|
|
std::unique_ptr<impl> m_impl;
|
|
};
|
|
|
|
class render_target {
|
|
public:
|
|
explicit render_target(int width, int height);
|
|
render_target(render_target const&) = delete;
|
|
render_target(render_target&& other) noexcept;
|
|
auto operator=(render_target const&) -> render_target& = delete;
|
|
auto operator=(render_target&& other) noexcept -> render_target&;
|
|
~render_target();
|
|
|
|
auto bind() const -> void;
|
|
auto unbind() const -> void;
|
|
auto color_id() const -> std::uint32_t;
|
|
auto width() const -> int;
|
|
auto height() const -> int;
|
|
auto valid() const -> bool;
|
|
auto resize(int width, int height) -> void;
|
|
|
|
private:
|
|
struct impl;
|
|
std::unique_ptr<impl> m_impl;
|
|
};
|
|
|
|
} // namespace cbt::gfx
|