utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
shader.cpp
1/*
2** ETIB PROJECT, 2026
3** xider
4** File description:
5** shader
6*/
7
8#include <cstring>
9#include <stdexcept>
10#include <string>
11
12#include <utility/graphic/shader.hpp>
13
14namespace utility::graphic
15{
16 namespace
17 {
18 void validateSpirv(const std::string &data, const char *which)
19 {
20 if (data.size() % sizeof(uint32_t) != 0) {
21 throw std::invalid_argument(
22 std::string(which)
23 + " shader bytecode length is not a multiple of 4");
24 }
25 }
26 } // namespace
27
28 Shader::Shader(const std::string &vertString, const std::string &fragString)
29 {
30 validateSpirv(vertString, "Vertex");
31 validateSpirv(fragString, "Fragment");
32
34 std::vector<uint32_t>(vertString.size() / sizeof(uint32_t));
35 std::memcpy(_vertSPIRV.data(), vertString.data(), vertString.size());
36
38 std::vector<uint32_t>(fragString.size() / sizeof(uint32_t));
39 std::memcpy(_fragSPIRV.data(), fragString.data(), fragString.size());
40 }
41
43 // Getters //
45
46 const std::vector<uint32_t> &Shader::getVertexCode() const
47 {
48 return _vertSPIRV;
49 }
50
51 const std::vector<uint32_t> &Shader::getFragmentCode() const
52 {
53 return _fragSPIRV;
54 }
55} // namespace utility::graphic
const std::vector< uint32_t > & getVertexCode() const
Retrieves the SPIR-V bytecode for the vertex shader.
Definition shader.cpp:46
const std::vector< uint32_t > & getFragmentCode() const
Retrieves the SPIR-V bytecode for the fragment shader.
Definition shader.cpp:51
Shader(const std::string &vertString, const std::string &fragString)
Constructs a Shader object by loading vertex and fragment shader bytecode from strings.
Definition shader.cpp:28
std::vector< uint32_t > _fragSPIRV
SPIR-V bytecode for the fragment shader.
Definition shader.hpp:68
std::vector< uint32_t > _vertSPIRV
SPIR-V bytecode for the vertex shader.
Definition shader.hpp:63