46 lines
1.4 KiB
C++
46 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "GLFunctions.hpp"
|
|
|
|
#include <glm/glm.hpp>
|
|
#include <string>
|
|
|
|
namespace engine {
|
|
|
|
// -----------------------------------------------------------------------
|
|
// Shader
|
|
//
|
|
// Thin RAII wrapper around a linked OpenGL program object, compiled from
|
|
// a vertex + fragment shader pair loaded from disk.
|
|
// -----------------------------------------------------------------------
|
|
class Shader {
|
|
public:
|
|
Shader() = default;
|
|
~Shader();
|
|
|
|
Shader(const Shader&) = delete;
|
|
Shader& operator=(const Shader&) = delete;
|
|
Shader(Shader&& other) noexcept;
|
|
Shader& operator=(Shader&& other) noexcept;
|
|
|
|
// Compiles and links the program. Returns false (and logs to stderr)
|
|
// on failure; the shader remains unusable but the caller can continue
|
|
// running with a null program.
|
|
bool loadFromFiles(const std::string& vertexPath, const std::string& fragmentPath);
|
|
|
|
void use() const;
|
|
GLuint id() const { return program_; }
|
|
|
|
void setMat4(const std::string& name, const glm::mat4& m) const;
|
|
void setVec3(const std::string& name, const glm::vec3& v) const;
|
|
void setVec4(const std::string& name, const glm::vec4& v) const;
|
|
void setFloat(const std::string& name, float f) const;
|
|
void setInt(const std::string& name, int i) const;
|
|
|
|
private:
|
|
GLuint program_ = 0;
|
|
GLint locationOf(const std::string& name) const;
|
|
};
|
|
|
|
} // namespace engine
|