Files
Vibe-HD-2D/engine/include/hd2d/Shader.h
Gabrieal Jimmy 2c99305fb0 init
2026-10-02 12:42:00 -05:00

43 lines
1.2 KiB
C++

#pragma once
#include "hd2d/GL.h"
#include <glm/glm.hpp>
#include <string>
#include <unordered_map>
namespace hd2d {
// GLSL program loaded from files. Supports `#include "file.glsl"` (resolved
// relative to the including file) and hot reload: a failed reload keeps the
// previous working program.
class Shader {
public:
Shader() = default;
Shader(const Shader&) = delete;
Shader& operator=(const Shader&) = delete;
~Shader();
bool load(const std::string& vertPath, const std::string& fragPath);
bool reload();
void use() const { glUseProgram(program_); }
GLuint id() const { return program_; }
void set(const char* name, int v);
void set(const char* name, float v);
void set(const char* name, const glm::vec2& v);
void set(const char* name, const glm::vec3& v);
void set(const char* name, const glm::vec4& v);
void set(const char* name, const glm::ivec2& v);
void set(const char* name, const glm::ivec4& v);
void set(const char* name, const glm::mat4& v);
private:
GLint location(const char* name);
GLuint program_ = 0;
std::string vertPath_, fragPath_;
std::unordered_map<std::string, GLint> locations_;
};
} // namespace hd2d