Enigma
3.2.2
A Simple, Reliable and Efficient Encryption Tool
Loading...
Searching...
No Matches
OpenGLUtils.hpp
Go to the documentation of this file.
1
#pragma once
2
#ifndef ENIGMA_OPENGL_UTILS_H
3
#define ENIGMA_OPENGL_UTILS_H
4
#include <glad/glad.h>
5
#include <
Core/Core.hpp
>
6
#include <cstring>
7
8
// NVX_gpu_memory_info extension defines from https://www.khronos.org/registry/OpenGL/extensions/NVX/NVX_gpu_memory_info.tx
9
#define GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047
10
#define GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048
11
#define GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049
12
#define GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX 0x904A
13
#define GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX 0x904B
14
15
16
NS_ENIGMA_BEGIN
17
18
class
OpenGLUtils
final {
19
ENIGMA_STATIC_CLASS
(
OpenGLUtils
);
20
21
public
:
22
/*
23
* Checks wether an extension available for example: GL_NVX_gpu_memory_info
24
* returns extension index of glGetStringi() if found, -1 otherwise
25
*/
26
static
const
GLint
IsExtensionSupported
(
const
char
*extension_name)
noexcept
{
27
GLint ext_count{};
28
glGetIntegerv(GL_NUM_EXTENSIONS, &ext_count);
29
if
(ext_count < 1)
30
return
-1;
31
32
for
(GLint i = 0; i < ext_count; ++i) {
33
const
char
*extension =
reinterpret_cast<
const
char
*
>
(glGetStringi(GL_EXTENSIONS, i));
34
if
(std::strcmp(extension, extension_name) == 0) {
35
// Found
36
return
i;
37
}
38
}
39
// Not found
40
return
-1;
41
}
42
43
/*
44
* Convert GL Error Enum macro name to a std::string, returns "Unknown GLenum" on non detected macros
45
*/
46
static
constexpr
const
char
*
GetGLErrorEnumString
(
const
GLenum& _enum)
noexcept
{
47
#define CASE_ENUM(e) \
48
case e: \
49
return #e
50
switch
(_enum) {
51
// errors
52
CASE_ENUM
(GL_NONE);
53
CASE_ENUM
(GL_INVALID_ENUM);
54
CASE_ENUM
(GL_INVALID_VALUE);
55
CASE_ENUM
(GL_INVALID_OPERATION);
56
CASE_ENUM
(GL_INVALID_FRAMEBUFFER_OPERATION);
57
CASE_ENUM
(GL_OUT_OF_MEMORY);
58
default
:
59
return
"Unknown GLenum"
;
60
};
61
#undef CASE_ENUM
62
}
63
};
64
65
67
#define glAssert(call) \
68
do { \
69
(call); \
70
const GLenum err = glGetError(); \
71
if (err != GL_NO_ERROR) { \
72
ENIGMA_ASSERT(false, OpenGLUtils::GetGLErrorEnumString(err)); \
73
} \
74
} while (false)
76
77
NS_ENIGMA_END
78
79
#endif
// !ENIGMA_OPENGL_UTILS_H
Core.hpp
NS_ENIGMA_BEGIN
#define NS_ENIGMA_BEGIN
Enable/Disable Assertions.
Definition
Macros.hpp:13
NS_ENIGMA_END
#define NS_ENIGMA_END
Definition
Macros.hpp:14
ENIGMA_STATIC_CLASS
#define ENIGMA_STATIC_CLASS(Class)
Makes a class static, which will prevent creating instances from it and only use it as Class::Func()....
Definition
Macros.hpp:120
CASE_ENUM
#define CASE_ENUM(e)
OpenGLUtils
Definition
OpenGLUtils.hpp:18
OpenGLUtils::GetGLErrorEnumString
static constexpr const char * GetGLErrorEnumString(const GLenum &_enum) noexcept
Definition
OpenGLUtils.hpp:46
OpenGLUtils::IsExtensionSupported
static const GLint IsExtensionSupported(const char *extension_name) noexcept
Definition
OpenGLUtils.hpp:26
src
Utility
OpenGLUtils.hpp
Generated on Sat Apr 12 2025 16:55:01 for Enigma by
1.9.8