aboutsummaryrefslogtreecommitdiffstats
path: root/yage/core/glslprogram.h
blob: 9e49d329f9bcf9518f4479965b9ac0da38e417a6 (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
47
48
49
50
51
52
53
54
55
56
57
58
/** ---------------------------------------------------------------------------
 * @file: glslprogram.h
 *
 * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com>
 * MIT License, see LICENSE file for more details.
 * ----------------------------------------------------------------------------
 */

#ifndef GLSL_PROGRAM_H
#define GLSL_PROGRAM_H

#include <glad/glad.h>

#include <string>

namespace yage
{

class GlslProgram
{
public:
    GlslProgram() = default;
    GlslProgram(const GlslProgram &) = delete;
    GlslProgram(GlslProgram &&) = delete;
    ~GlslProgram();

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

    /// compiles vertex and fragment shader
    void compileShaders(const std::string &vertexShader,
                        const std::string fragmentShader);
    void compileShadersFromFile(const std::string &vertex_shader_path,
                                const std::string &fragment_shader_path);
    void linkShaders();
    void addAttribute(const std::string &attribute_name);
    GLint getUniformLocation(const std::string &uniform_name);
    void use();
    void unuse();

    void defaultSetup();

private:
    /// compiled shader program id
    GLuint program_id_ = 0;
    GLuint vertex_shader_id_ = 0;
    GLuint fragment_shader_id_ = 0;
    int attribute_index_ = 0;

    /// compiles one shader
    void compileShader(GLuint shader, const std::string &shaderContent);
    void compileShaderFromFile(GLuint shader, const std::string &file_path);
    void initShaderId();
};

} // namespace yage

#endif