-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathds_egl.cpp
139 lines (99 loc) · 3.46 KB
/
ds_egl.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
136
137
138
// Copyright 2019 David Butler <[email protected]>
#include <stdio.h>
#define EGL_EGLEXT_PROTOTYPES
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include "util_types.hpp"
EGLDisplay egl_display;
EGLSurface egl_surface;
static void egl_debug_proc(
EGLenum error,
const char *command,
EGLint messageType,
EGLLabelKHR threadLabel,
EGLLabelKHR objectLabel,
const char* message) {
printf("EGL_DEBUG_PROC: %d %s %d %p %p %s\n",
error, command, messageType, threadLabel, objectLabel, message
);
assert(0);
}
void egl_init1() {
auto eglDebugMessageControl = (typeof(&eglDebugMessageControlKHR))
eglGetProcAddress("eglDebugMessageControlKHR");
assert(eglDebugMessageControl);
auto r7 = eglDebugMessageControl(egl_debug_proc, 0);
assert(r7 == EGL_SUCCESS);
}
void egl_init2() {
int egl_major = -1;
int egl_minor = -1;
eglInitialize(egl_display, &egl_major, &egl_minor);
assert(egl_major* 1000 + egl_minor >= 1004);
printf("EGL_CLIENT_APIS:%s EGL_VENDOR:%s EGL_VERSION:%s EGL_EXTENSIONS:%s \n",
eglQueryString(egl_display, EGL_CLIENT_APIS),
eglQueryString(egl_display, EGL_VENDOR),
eglQueryString(egl_display, EGL_VERSION),
eglQueryString(egl_display, EGL_EXTENSIONS)
);
//eglBindAPI(EGL_OPENGL_API); // OPENGGL
eglBindAPI(EGL_OPENGL_ES_API); // OPENGLES
assert(eglGetError() == EGL_SUCCESS);
}
void egl_init3(void* native_window) {
EGLConfig config;
EGLint num_config;
EGLint config_attributes[] = {
#if 1
EGL_CONFORMANT , EGL_OPENGL_BIT, // OPENGL 2.1
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, // OPENGL 2.1
#endif
#if 0
EGL_CONFORMANT , EGL_OPENGL_ES_BIT, // OPENGLES 2.0
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, // OPENGLES 2.0
#endif
EGL_RED_SIZE, 1,
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
EGL_ALPHA_SIZE, 0,
EGL_NONE
};
eglChooseConfig(egl_display, config_attributes, &config, 1, &num_config);
EGLint context_attributes[] = {
#if 0
EGL_CONTEXT_MAJOR_VERSION_KHR, 2, // OPENGL 2.1
EGL_CONTEXT_MINOR_VERSION_KHR, 1,
EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR,
#endif
#if 0
EGL_CONTEXT_MAJOR_VERSION_KHR, 3, // OPENGL 3.3
EGL_CONTEXT_MINOR_VERSION_KHR, 3,
EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR,
#endif
#if 1
EGL_CONTEXT_MAJOR_VERSION_KHR, 2, // OPENGLES 2.0
EGL_CONTEXT_MINOR_VERSION_KHR, 0, // OPENGLES 2.0
#endif
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR,
EGL_NONE,
};
auto egl_context = eglCreateContext(
egl_display, config,
EGL_NO_CONTEXT, context_attributes);
auto r5 = eglGetError();
assert(r5 == EGL_SUCCESS);
assert(eglGetError() == EGL_SUCCESS);
assert(egl_context != EGL_NO_CONTEXT);
egl_surface = eglCreateWindowSurface(egl_display, config,
(EGLNativeWindowType)native_window, NULL);
eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context);
glClear(GL_COLOR_BUFFER_BIT);
eglSwapBuffers(egl_display, egl_surface);
}
void egl_frame() {
glFlush();
eglSwapBuffers(egl_display, egl_surface);
assert(eglGetError() == EGL_SUCCESS);
}