Topaz 5.0
Topaz Game Engine
Loading...
Searching...
No Matches
shader.hpp
1#ifndef TOPAZ_GPU_SHADER_HPP
2#define TOPAZ_GPU_SHADER_HPP
3#include "tz/core/handle.hpp"
4#include "tz/core/error.hpp"
5#include <string>
6#include <expected>
7#include <string_view>
8#include <span>
9
10
11namespace tz::gpu
12{
13 struct shader_tag_t{};
35 std::expected<shader_handle, tz::error_code> create_graphics_shader(std::string_view vertex_source, std::string_view fragment_source);
45 std::expected<shader_handle, tz::error_code> create_compute_shader(std::string_view compute_source);
57}
58
59#define TZ_MACROHACKERY_JOIN4(X, Y, Z, W) X##Y##Z##W
60#define TZ_MACROHACKERY_STRINGIFY(X) TZ_MACROHACKERY_STRINGIFY2(X)
61#define TZ_MACROHACKERY_STRINGIFY2(X) #X
62#if TOPAZ_VULKAN
63#define TZ_MACROHACKERY_JOIN_SHADER(X, Y, Z) TZ_MACROHACKERY_JOIN4(X, Y, Z, _tzsl_spv)
64//#elif TZ_OGL
65//#define TZ_MACROHACKERY_JOIN_SHADER(X, Y, Z) TZ_MACROHACKERY_JOIN4(X, Y, Z, _tzsl_glsl)
66#endif
67#if TOPAZ_VULKAN
74#define ImportedShaderHeader(shader_name, shader_type) TZ_MACROHACKERY_STRINGIFY2(shader_name.shader_type.tzsl.spv.hpp)
75//#elif TZ_OGL
76//#define ImportedShaderHeader(shader_name, shader_type) TZ_MACROHACKERY_STRINGIFY2(shader_name.shader_type.tzsl.glsl.hpp)
77#else
78#define ImportedShaderHeader
79#endif
80
88#define ImportedShaderSource(shader_name, shader_type) []()->std::string_view{std::span<const std::byte> shader_bin = std::as_bytes(std::span<const std::int8_t>(TZ_MACROHACKERY_JOIN_SHADER(shader_name, _, shader_type))); return std::string_view{reinterpret_cast<const char*>(shader_bin.data()), shader_bin.size_bytes()};}()
89
90#endif // TOPAZ_GPU_SHADER_HPP
std::expected< shader_handle, tz::error_code > create_graphics_shader(std::string_view vertex_source, std::string_view fragment_source)
Create a new shader intended for graphics GPU work, comprised of a vertex and fragment shader.
std::expected< shader_handle, tz::error_code > create_compute_shader(std::string_view compute_source)
Create a new shader intended for compute GPU work, comprised of a single compute shader.
void destroy_shader(shader_handle)
Manually destroy a previously-created shader.