ACloudViewer
3.9.4
A Modern Library for 3D Data Processing
opengl_utils.h
Go to the documentation of this file.
1
// ----------------------------------------------------------------------------
2
// - CloudViewer: www.cloudViewer.org -
3
// ----------------------------------------------------------------------------
4
// Copyright (c) 2018-2024 www.cloudViewer.org
5
// SPDX-License-Identifier: MIT
6
// ----------------------------------------------------------------------------
7
8
#pragma once
9
10
#ifdef GUI_ENABLED
11
#include <QAction>
12
#include <QApplication>
13
#include <QOffscreenSurface>
14
#include <QOpenGLContext>
15
#include <QThread>
16
#include <QWaitCondition>
17
#endif
18
19
#include "
util/threading.h
"
20
21
namespace
colmap
{
22
23
#ifdef DEBUG
24
#define glDebugLog() glError(__FILE__, __LINE__)
25
#else
26
#define glDebugLog()
27
#endif
28
29
#ifdef GUI_ENABLED
30
31
// This class manages a thread-safe OpenGL context. Note that this class must be
32
// instantiated in the main Qt thread, since an OpenGL context must be created
33
// in it. The context can then be made current in any other thread.
34
class
OpenGLContextManager :
public
QObject {
35
public
:
36
OpenGLContextManager
(
int
opengl_major_version = 2,
37
int
opengl_minor_version = 1);
38
39
// Make the OpenGL context available by moving it from the thread where it
40
// was created to the current thread and making it current.
41
void
MakeCurrent
();
42
43
// Check whether the machine has OpenGL and we can create the context.
44
static
bool
HasOpenGL
();
45
46
private
:
47
QOffscreenSurface surface_;
48
QOpenGLContext context_;
49
QThread* parent_thread_;
50
QThread* current_thread_;
51
QAction* make_current_action_;
52
};
53
54
// Run and wait for the thread, that uses the OpenGLContextManager, e.g.:
55
//
56
// class TestThread : public Thread {
57
// private:
58
// void Run() { opengl_context_.MakeCurrent(); }
59
// OpenGLContextManager opengl_context_;
60
// };
61
// QApplication app(argc, argv);
62
// TestThread thread;
63
// RunThreadWithOpenGLContext(&thread);
64
//
65
void
RunThreadWithOpenGLContext
(Thread* thread);
66
67
// Get the OpenGL errors and print them to stderr.
68
void
GLError
(
const
char
* file,
const
int
line);
69
70
#else
71
72
// Dummy implementation when GUI support is disabled
73
class
OpenGLContextManager
{
74
public
:
75
OpenGLContextManager
(
int
opengl_major_version = 2,
76
int
opengl_minor_version = 1) {}
77
inline
void
MakeCurrent
() {}
78
inline
static
bool
HasOpenGL
() {
return
false
; }
79
};
80
81
inline
void
RunThreadWithOpenGLContext
(
Thread
* thread) {}
82
83
inline
void
GLError
(
const
char
* file,
const
int
line) {}
84
85
#endif
86
87
}
// namespace colmap
colmap::OpenGLContextManager
Definition:
opengl_utils.h:73
colmap::OpenGLContextManager::MakeCurrent
void MakeCurrent()
Definition:
opengl_utils.h:77
colmap::OpenGLContextManager::HasOpenGL
static bool HasOpenGL()
Definition:
opengl_utils.h:78
colmap::OpenGLContextManager::OpenGLContextManager
OpenGLContextManager(int opengl_major_version=2, int opengl_minor_version=1)
Definition:
opengl_utils.h:75
colmap::Thread
Definition:
threading.h:74
colmap
Definition:
AutomaticReconstructionController.h:17
colmap::GLError
void GLError(const char *file, const int line)
Definition:
opengl_utils.h:83
colmap::RunThreadWithOpenGLContext
void RunThreadWithOpenGLContext(Thread *thread)
Definition:
opengl_utils.h:81
threading.h
libs
Reconstruction
src
util
opengl_utils.h
Generated on Tue Feb 3 2026 07:12:30 for ACloudViewer by
1.9.1