-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenglUtil.h
67 lines (60 loc) · 2.13 KB
/
OpenglUtil.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
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef __OPENGL_UTIL_H_
#define __OPENGL_UTIL_H_
//https://gitee.com/lamora/SFML/blob/master/src/SFML/Graphics/GLCheck.hpp
//https://gitee.com/pengrui1993/hello-openal001/blob/master/myal.cpp
#include<string>
#include<filesystem>
struct OpenglUtil{
// using Path = std::filesystem::path;
using Path = std::string;
using Line = std::uint_fast32_t;
OpenglUtil() = delete;
~OpenglUtil() = delete;
template <typename GlFunction, typename... Params>
static auto glCall(Path file,Line line,GlFunction function,Params...params)
-> typename std::enable_if<std::is_same<void, decltype(function(params...))>::value, decltype(function(params...))>::type{
function(std::forward<Params>(params)...);
checkError(file,line);
}
template <typename GlFunction, typename... Params>
static auto glCall(Path file,Line line,GlFunction function,Params...params)
->typename std::enable_if<!std::is_same<void, decltype(function(params...))>::value
, decltype(function(params...))>::type{
auto ret = function(std::forward<Params>(params)...);
checkError(file,line);
return ret;
}
template <typename GlFunction>
static auto glCall0(Path file,Line line,GlFunction function)
-> typename std::enable_if<std::is_same<void
, decltype(function())>::value
, decltype(function())>::type{
function();
checkError(file,line);
}
static void clearError();
template <typename GlFunction>
static auto glCall0(Path file,Line line,GlFunction function)
-> typename std::enable_if<!std::is_same<void
, decltype(function())>::value
, decltype(function())>::type{
auto ret = function();
checkError(file,line);
return ret;
}
static const int TRUE{1};
static const int FALSE{0};
static const int exitOnError{TRUE};
static void checkError(const Path& file,Line line);
};
#define DEBUG 1
#ifdef DEBUG
#endif
#if (DEBUG)
#define glCall(function,...) OpenglUtil::glCall(__FILE__,__LINE__,function,__VA_ARGS__)
#define glCall0(function) OpenglUtil::glCall0(__FILE__,__LINE__,function)
#else
#define glCall(function,...) function(__VA_ARGS__)
#define glCall0(function) function()
#endif
#endif