Easy3D 2.5.3
opengl_util.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_RENDERER_OPENGL_UTIL_H
28#define EASY3D_RENDERER_OPENGL_UTIL_H
29
30#include <string>
31#include <iostream>
32#include <unordered_map>
33
34
35namespace easy3d {
36
41 class OpenglUtil {
42 public:
43 static bool init();
44
45 static bool is_initialized();
46
47 // -------------- general information --------------
48
50 static int gl_profile();
51
52 static bool is_supported(const std::string &name); // e.g., "GL_VERSION_3_2", "GL_ARB_vertex_array_object"
53 static bool has_extension(const std::string &name); // e.g., "GL_EXT_framebuffer_object"
54
55 static std::string glew_version();
56
57 static std::string gl_vendor();
58
59 static std::string gl_renderer();
60
61 static std::string gl_version();
62
63 static std::string gl_extensions();
64
65 static std::string glsl_version();
66
67 static int gl_major_version();
68
69 static int gl_minor_version();
70
71 static float glew_version_number();
72
73 static float gl_version_number();
74
75 static float glsl_version_number();
76
77 static int samples();
78
82 static void viewport(int &x, int &y, int &width, int &height);
83
84 // ----------------- GPU memory -------------------
85
90 static int total_gpu_memory();
91
92 static int available_gpu_memory();
93
94 // ----------------- print information -------------------
95
98 static void set_output(std::ostream *out);
99
100 // --------------- buffer information ----------------
101
103 static void get_current_buffer_info();
104
106 static void get_buffer_info(unsigned int target, int bufferName);
107
108 // --------------- GLSL information (GLSL version 4.2 is supported )----------------
109
111 static void get_vao_info(unsigned int buffer);
112
114 static void get_program_info(unsigned int program);
115
117 static void get_attributes_info(unsigned int program);
118
120 static void get_uniforms_info(unsigned int program);
121
123 static void get_uniform_info(unsigned int program, const std::string &uniName);
124
126 static void
127 get_uniform_in_block_info(unsigned int program, const std::string &blockName, const std::string &uniName);
128
129 private:
131 static void _add_message(std::string format, ...);
132
133 static bool _init();
134
135 static int _get_rows(unsigned int type);
136
137 static int _get_columns(unsigned int type);
138
139 static void _display_uniformf(float *f, int rows, int columns);
140
141 static void _display_uniformi(int *f, int rows, int columns);
142
143 static void _display_uniformui(unsigned int *f, int rows, int columns);
144
145 static void _display_uniformd(double *f, int rows, int columns);
146
147 static int _get_uniform_byte_size(int size, int uniType, int arrayStride, int matStride);
148
149 enum Types {
150 DONT_KNOW, INT, UNSIGNED_INT, FLOAT, DOUBLE
151 };
152
153 static Types _get_type(unsigned int type);
154
155 private:
156 static bool _glew_initialized;
157
158 static bool _spInit;
159
160 static std::ostream *_output_stream;
161
162 static std::unordered_map<int, std::string> spBufferAccess;
163 static std::unordered_map<int, std::string> spBufferUsage;
164 static std::unordered_map<int, std::string> spBufferBinding;
165 static std::unordered_map<int, int> spBufferBound;
166 static std::unordered_map<int, int> spBoundBuffer;
167 static std::unordered_map<int, std::string> spDataF;
168 static std::unordered_map<int, std::string> spGLSLType;
169 static std::unordered_map<int, int> spGLSLTypeSize;
170 static std::unordered_map<int, std::string> spShaderType;
171 static std::unordered_map<int, std::string> spTransFeedBufferMode;
172 static std::unordered_map<int, std::string> spGLSLPrimitives;
173 static std::unordered_map<int, std::string> spTessGenSpacing;
174 static std::unordered_map<int, std::string> spVertexOrder;
175 };
176
177
178}
179
180#endif // EASY3D_RENDERER_OPENGL_UTIL_H
181
182
Utilities for OpenGL initialization and states query.
Definition: opengl_util.h:41
static void get_uniform_in_block_info(unsigned int program, const std::string &blockName, const std::string &uniName)
display the values for a uniform in a named block
Definition: opengl_util.cpp:590
static void get_vao_info(unsigned int buffer)
display VAO information, including its attributes
Definition: opengl_util.cpp:351
static void set_output(std::ostream *out)
Definition: opengl_util.cpp:260
static void get_uniform_info(unsigned int program, const std::string &uniName)
display a uniform's value(s)
Definition: opengl_util.cpp:543
static int total_gpu_memory()
Definition: opengl_util.cpp:232
static void get_program_info(unsigned int program)
display detailed info for a program
Definition: opengl_util.cpp:689
static void viewport(int &x, int &y, int &width, int &height)
Definition: opengl_util.cpp:222
static void get_current_buffer_info()
display current bound buffer info
Definition: opengl_util.cpp:288
static int gl_profile()
returns either GL_CONTEXT_CORE_PROFILE_BIT or GL_CONTEXT_COMPATIBILITY_PROFILE_BIT
Definition: opengl_util.cpp:91
static void get_attributes_info(unsigned int program)
display detailed info for attributes in a program
Definition: opengl_util.cpp:660
static void get_uniforms_info(unsigned int program)
display info for all active uniforms in a program
Definition: opengl_util.cpp:414
static void get_buffer_info(unsigned int target, int bufferName)
display the buffer information
Definition: opengl_util.cpp:322
Definition: collider.cpp:182