-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.h
54 lines (40 loc) · 1.6 KB
/
context.h
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
#ifndef GL_VALIDATION_LAYER_PRIVATE_CONTEXT_H_
#define GL_VALIDATION_LAYER_PRIVATE_CONTEXT_H_
#include <gl_layer/context.h>
#include <gl_layer/private/types.h>
#include <unordered_map>
#include <cassert>
namespace gl_layer {
class Context {
public:
explicit Context(Version version, const ContextGLFunctions* gl_functions);
void set_output_callback(GLLayerOutputFun callback, void* user_data);
void glCompileShader(unsigned int handle);
void glGetShaderiv(unsigned int handle, GLenum param, int* params);
void glAttachShader(unsigned int program, unsigned int shader);
void glGetProgramiv(unsigned int handle, GLenum param, int* params);
void glLinkProgram(GLuint program);
void glUseProgram(unsigned int handle);
void glDeleteProgram(GLuint program);
void validate_program_bound(std::string_view func_name);
bool validate_program_status(GLuint program);
private:
Version gl_version;
GLLayerOutputFun output_fun = nullptr;
void* output_user_data = nullptr;
ContextGLFunctions gl;
GLuint bound_program = 0;
std::unordered_map<unsigned int, Shader> shaders{};
std::unordered_map<unsigned int, Program> programs{};
template<typename... Args>
void output_fmt(const char* fmt, Args&& ... args) {
std::size_t size = static_cast<std::size_t>(std::snprintf(nullptr, 0, fmt, args...)) + 1; // Extra space for null terminator
assert(size > 0 && "Error during formatting");
char* buf = new char[size];
std::snprintf(buf, size, fmt, args...);
output_fun(buf, output_user_data);
delete[] buf;
}
};
}
#endif