/
OpenGLModule.cpp
135 lines (108 loc) · 3.15 KB
/
OpenGLModule.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "OpenGLModule.h"
#include "irender.h"
#include "itextstream.h"
#include "imainframe.h"
#include "debugging/debugging.h"
#include "module/StaticModule.h"
#include <string/convert.h>
#include "wxutil/GLWidget.h"
#include "wxutil/dialog/MessageBox.h"
#include <stdexcept>
#include <FTGL/ftgl.h>
OpenGLModule::OpenGLModule() :
_unknownError("Unknown error."),
_shaderProgramsAvailable(false)
{}
void OpenGLModule::assertNoErrors()
{
#ifdef _DEBUG
// Return if no error
GLenum error = glGetError();
if (error == GL_NO_ERROR)
{
return;
}
// Build list of all GL errors
std::string allErrString = "GL errors encountered: ";
int maxErrors = 100;
for ( ; error != GL_NO_ERROR; error = glGetError())
{
const char* strErr = reinterpret_cast<const char*>(
gluErrorString(error)
);
allErrString += string::to_string(error);
allErrString += " (" + std::string(strErr) + ") ";
if (--maxErrors <= 0)
{
allErrString += "---> Maximum number of GL errors reached, maybe there is a problem with the GL context?";
break;
}
}
// Show the error message and terminate
wxutil::Messagebox::ShowFatalError(allErrString);
#endif
}
void OpenGLModule::sharedContextCreated()
{
// Initialise the font before firing the extension initialised signal
_font.reset(new wxutil::GLFont(wxutil::GLFont::FONT_SANS, 12));
// This call will automatically realise the render system
GlobalRenderSystem().extensionsInitialised();
}
void OpenGLModule::sharedContextDestroyed()
{
_font.reset();
GlobalRenderSystem().unrealise();
}
bool OpenGLModule::shaderProgramsAvailable() const
{
return _shaderProgramsAvailable;
}
// Sets the flag whether shader programs are available.
// This is set by the RenderSystem once the extensions are initialised
void OpenGLModule::setShaderProgramsAvailable(bool available)
{
_shaderProgramsAvailable = available;
}
void OpenGLModule::drawString(const std::string& string) const
{
ftglRenderFont(_font->getFtglFont(),string.c_str(),0xFFFF);//FTGL_RENDER_ALL);
}
void OpenGLModule::drawChar(char character) const
{
std::string str(1,character);
drawString(str);
}
int OpenGLModule::getFontHeight()
{
return _font->getPixelHeight();
}
const std::string& OpenGLModule::getName() const
{
static std::string _name(MODULE_OPENGL);
return _name;
}
const StringSet& OpenGLModule::getDependencies() const
{
static StringSet _dependencies;
if (_dependencies.empty())
{
_dependencies.insert(MODULE_SHARED_GL_CONTEXT);
}
return _dependencies;
}
void OpenGLModule::initialiseModule(const IApplicationContext& ctx)
{
rMessage() << getName() << "::initialiseModule called." << std::endl;
_contextCreated = GlobalOpenGLContext().signal_sharedContextCreated().connect(
sigc::mem_fun(this, &OpenGLModule::sharedContextCreated));
_contextDestroyed = GlobalOpenGLContext().signal_sharedContextDestroyed().connect(
sigc::mem_fun(this, &OpenGLModule::sharedContextDestroyed));
}
void OpenGLModule::shutdownModule()
{
_contextCreated.disconnect();
_contextDestroyed.disconnect();
}
// Define the static OpenGLModule module
module::StaticModule<OpenGLModule> openGLModule;