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
|
/*
* Copyright (C) 2005-2019 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#pragma once
//==============================================================================
///
/// \defgroup cpp_kodi_gui_gl OpenGL helpers
/// \ingroup cpp_kodi_gui
/// \brief Auxiliary functions for Open GL
///
/// This group includes help for definitions, functions, and classes for
/// OpenGL.
///
/// To use OpenGL for your system, add the \ref GL.h "#include <kodi/gui/gl/GL.h>".
///
///
///-----------------------------------------------------------------------------
///
/// The \ref HAS_GL is declared if Open GL is required and \ref HAS_GLES if Open GL
/// Embedded Systems (ES) is required, with ES the version is additionally given
/// in the definition, this can be "2" or "3".
///
///
///-----------------------------------------------------------------------------
///
/// Following \ref GL_TYPE_STRING define can be used, for example, to manage
/// different folders for GL and GLES and make the selection easier.
/// This are on OpenGL <b>"GL"</b> and on Open GL|ES <b>"GLES"</b>.
///
/// **Example:**
/// ~~~~~~~~~~~~~~~~~{.cpp}
/// kodi::GetAddonPath("resources/shaders/" GL_TYPE_STRING "/frag.glsl");
/// ~~~~~~~~~~~~~~~~~
///
///
///----------------------------------------------------------------------------
///
/// In addition, \ref BUFFER_OFFSET is declared in it which can be used to give an
/// offset on the array to GL.
///
/// **Example:**
/// ~~~~~~~~~~~~~~~~~{.cpp}
/// const struct PackedVertex {
/// float position[3]; // Position x, y, z
/// float color[4]; // Color r, g, b, a
/// } vertices[3] = {
/// { { -0.5f, -0.5f, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } },
/// { { 0.5f, -0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } },
/// { { 0.0f, 0.5f, 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } }
/// };
///
/// glVertexAttribPointer(m_aPosition, 3, GL_FLOAT, GL_FALSE, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, position)));
/// glEnableVertexAttribArray(m_aPosition);
///
/// glVertexAttribPointer(m_aColor, 4, GL_FLOAT, GL_FALSE, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, color)));
/// glEnableVertexAttribArray(m_aColor);
/// ~~~~~~~~~~~~~~~~~
#if HAS_GL
#define GL_TYPE_STRING "GL"
// always define GL_GLEXT_PROTOTYPES before include gl headers
#if !defined(GL_GLEXT_PROTOTYPES)
#define GL_GLEXT_PROTOTYPES
#endif
#if defined(TARGET_LINUX)
#include <GL/gl.h>
#include <GL/glext.h>
#elif defined(TARGET_FREEBSD)
#include <GL/gl.h>
#elif defined(TARGET_DARWIN)
#include <OpenGL/gl3.h>
#include <OpenGL/gl3ext.h>
#elif defined(WIN32)
#error Use of GL under Windows is not possible
#endif
#elif HAS_GLES >= 2
#define GL_TYPE_STRING "GLES"
#if defined(WIN32)
#if defined(HAS_ANGLE)
#include <angle_gl.h>
#else
#error Use of GLES only be available under Windows by the use of angle
#endif
#elif defined(TARGET_DARWIN)
#if HAS_GLES == 3
#include <OpenGLES/ES3/gl.h>
#include <OpenGLES/ES3/glext.h>
#else
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#endif
#else
#if HAS_GLES == 3
#include <GLES3/gl3.h>
#include <GLES3/gl3ext.h>
#else
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#endif
#endif
#endif
#ifndef BUFFER_OFFSET
#define BUFFER_OFFSET(i) ((char *)nullptr + (i))
#endif
|