aboutsummaryrefslogtreecommitdiffstats
path: root/yage/render/shader.h
blob: c958a5009eb62fea8e737190b0e23ff90bd82044 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/** ---------------------------------------------------------------------------
 * @file: shader.h
 *
 * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com>
 * MIT License, see LICENSE file for more details.
 * ----------------------------------------------------------------------------
 */

#pragma once

#include <glad/glad.h>
#include <glm/glm.hpp>

#include <string>

namespace yage
{

class Shader
{
public:
    Shader(const std::string &vertex_path, const std::string &fragment_path);
    Shader(const Shader &) = delete;
    Shader(Shader &&)      = delete;
    ~Shader();

    Shader &operator=(const Shader &) = delete;
    Shader &operator=(Shader &&) = delete;

    /// compiles vertex and fragment shader
    void use() const;

    /// set uniforms of different type
    void setUniform(const std::string &name, int value) const;
    void setUniform(const std::string &name, float value) const;
    void setUniform(const std::string &name, const glm::mat4 &matrix) const;

private:
    /// compiled shader program id
    GLuint program_id_ = 0;

    GLint getUniformLocation(const std::string &uniform_name) const;
    void errorCheck(GLuint shader, const std::string &shader_type) const;
};

} // namespace yage