-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGLRenderer.h
More file actions
57 lines (53 loc) · 1.75 KB
/
GLRenderer.h
File metadata and controls
57 lines (53 loc) · 1.75 KB
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
//
// Created by lesscomplex on 08/03/2020.
//
#ifndef YOURAPPNAME_GLRENDERER_H
#define YOURAPPNAME_GLRENDERER_H
#include "definitions.h"
#include <unordered_map>
class GLShift::GLRenderer {
public:
/**
* Override to provide code for the rendering loop
*/
virtual void render() = 0;
/**
* Override to provide code for the initialization loop
*/
virtual void init() = 0;
/**
* Set the window that the render applies to
* @param context
*/
void setWindow(GLFWwindow * context);
/**
* Create and store an empty program in the renderer
* @param name Name to reference to the program
*/
void createProgram(const std::string& name);
/**
* Link the shaders given to the programs to make it complete
* @param name Name of program to link
*/
void linkProgram(const std::string& name);
/**
* Add a shader to a program
* @param programName Program name to add to
* @param shaderSource Source code of the shader
* @param shader_type Shader type
*/
void addShader(const std::string& programName, const char* shaderSource, GLint shader_type = GL_VERTEX_SHADER);
/**
* A safe function to call programs.
* Newbies might use the command line `glUseProgram(this->glPrograms["name"])`.
* The main problem is that if the program with the key "name" doesn't exists,
* then it will be created, thus you will get en error. This functions checks
* if the key exists before proceeding to use the program to avoid errors
* @param name Name of the program to load
*/
void useProgram(const std::string& name);
protected:
std::unordered_map<std::string, GLuint> glPrograms;
GLFWwindow * window;
};
#endif //YOURAPPNAME_GLRENDERER_H