aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics/opengl/opengl-sys.h
blob: 239512bc8a4a7706386673b6e0d7aa134fc53dda (plain)
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
/* 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.
 *
 */

#ifndef BACKENDS_GRAPHICS_OPENGL_OPENGL_SYS_H
#define BACKENDS_GRAPHICS_OPENGL_OPENGL_SYS_H

#include "common/scummsys.h"

#include "backends/graphics/opengl/debug.h"
#ifdef SDL_BACKEND
#include "backends/platform/sdl/sdl-sys.h"
#endif

// We allow to force GL or GLES modes on compile time.
// For this the USE_GLES_MODE define is used. The following values represent
// the given selection choices:
//  0 - Force OpenGL context
//  1 - Force OpenGL ES context
//  2 - Force OpenGL ES 2.0 context
#define USE_FORCED_GL    (defined(USE_GLES_MODE) && USE_GLES_MODE == 0)
#define USE_FORCED_GLES  (defined(USE_GLES_MODE) && USE_GLES_MODE == 1)
#define USE_FORCED_GLES2 (defined(USE_GLES_MODE) && USE_GLES_MODE == 2)

// On Tizen we include the toolchain's OpenGL file. This is something we
// actually want to avoid. However, since Tizen uses eglGetProcAddress which
// is not required to return valid function pointers to non OpenGL extension
// functions, we need the system's definitions to resolve all OpenGL
// functions.
// TODO: See if there is an alternative which allows us to avoid including
// Tizen's OpenGL header here.
#if defined(TIZEN)
	#include <FGraphicsOpengl.h>
	using namespace Tizen::Graphics::Opengl;
	#define USE_BUILTIN_OPENGL
#else
	#include "backends/graphics/opengl/opengl-defs.h"
#endif

#ifdef SDL_BACKEND
	// Win32 needs OpenGL functions declared with APIENTRY.
	// However, SDL does not define APIENTRY in it's SDL.h file on non-Windows
	// targets, thus if it is not available, we just dummy define it.
	#ifndef APIENTRY
		#define APIENTRY
	#endif
	#define GL_CALL_CONV APIENTRY
#else
	#define GL_CALL_CONV
#endif

namespace OpenGL {

enum ContextType {
	kContextGL,
	kContextGLES,
	kContextGLES2
};

/**
 * Description structure of the OpenGL (ES) context.
 */
struct Context {
	/** The type of the active context. */
	ContextType type;

	/**
	 * Reset context.
	 *
	 * This marks all extensions as unavailable and clears all function
	 * pointers.
	 */
	void reset();

	/** Whether GL_ARB_texture_non_power_of_two is available or not. */
	bool NPOTSupported;

#if !USE_FORCED_GLES && !USE_FORCED_GLES2
	/** Whether shader support is available or not. */
	bool shadersSupported;
#endif

#define GL_FUNC_DEF(ret, name, param) ret (GL_CALL_CONV *name)param
#include "backends/graphics/opengl/opengl-func.h"
#undef GL_FUNC_DEF
};

/**
 * The (active) OpenGL context.
 */
extern Context g_context;

} // End of namespace OpenGL

#define GL_CALL(x)                 GL_WRAP_DEBUG(g_context.x, x)
#define GL_CALL_SAFE(func, params) \
	do { \
		if (g_context.func) { \
			GL_CALL(func params); \
		} \
	} while (0)
#define GL_ASSIGN(var, x)          GL_WRAP_DEBUG(var = g_context.x, x)

#endif