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
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "backends/graphics/opengl/opengl-sys.h"
#include "backends/graphics/opengl/opengl-graphics.h"
#include "common/tokenizer.h"
namespace OpenGL {
void Context::reset(bool full) {
// GLES supports least features, thus we initialize the context type
// to this on full reset.
const ContextType savedType = full ? kContextGLES : type;
memset(this, 0, sizeof(Context));
type = savedType;
}
Context g_context;
void OpenGLGraphicsManager::setContextType(ContextType type) {
#if USE_FORCED_GL
type = kContextGL;
#elif USE_FORCED_GLES
type = kContextGLES;
#elif USE_FORCED_GLES2
type = kContextGLES2;
#endif
g_context.type = type;
}
void OpenGLGraphicsManager::initializeGLContext() {
// Initialize default state.
g_context.reset();
// Load all functions.
// We use horrible trickery to silence C++ compilers.
// See backends/plugins/sdl/sdl-provider.cpp for more information.
assert(sizeof(void (*)()) == sizeof(void *));
void *fn = nullptr;
#define GL_EXT_FUNC_DEF(ret, name, param) \
fn = getProcAddress(#name); \
memcpy(&g_context.name, &fn, sizeof(fn))
#ifdef USE_BUILTIN_OPENGL
#define GL_FUNC_DEF(ret, name, param) g_context.name = &name
#else
#define GL_FUNC_DEF GL_EXT_FUNC_DEF
#endif
#include "backends/graphics/opengl/opengl-func.h"
#undef GL_EXT_FUNC_DEF
#undef GL_FUNC_DEF
const char *extString = (const char *)g_context.glGetString(GL_EXTENSIONS);
#if !USE_FORCED_GLES && !USE_FORCED_GLES2
bool ARBShaderObjects = false;
bool ARBShadingLanguage100 = false;
bool ARBVertexShader = false;
bool ARBFragmentShader = false;
#endif
Common::StringTokenizer tokenizer(extString, " ");
while (!tokenizer.empty()) {
Common::String token = tokenizer.nextToken();
if (token == "GL_ARB_texture_non_power_of_two") {
g_context.NPOTSupported = true;
#if !USE_FORCED_GLES && !USE_FORCED_GLES2
} else if (token == "GL_ARB_shader_objects") {
ARBShaderObjects = true;
} else if (token == "GL_ARB_shading_language_100") {
ARBShadingLanguage100 = true;
} else if (token == "GL_ARB_vertex_shader") {
ARBVertexShader = true;
} else if (token == "GL_ARB_fragment_shader") {
ARBFragmentShader = true;
#endif
}
}
#if !USE_FORCED_GLES && !USE_FORCED_GLES2
g_context.shadersSupported = ARBShaderObjects & ARBShadingLanguage100 & ARBVertexShader & ARBFragmentShader;
#endif
}
} // End of namespace OpenGL
|