Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/browser/glgetattachedshaders.c
7085 views
1
/*
2
* Copyright 2013 The Emscripten Authors. All rights reserved.
3
* Emscripten is available under two separate licenses, the MIT license and the
4
* University of Illinois/NCSA Open Source License. Both these licenses can be
5
* found in the LICENSE file.
6
*/
7
8
#include <GLES2/gl2.h>
9
#include <EGL/egl.h>
10
#include <stdio.h>
11
#include <stdlib.h>
12
13
static void die(const char *msg) {
14
printf("%s\n", msg);
15
abort();
16
}
17
18
static void create_context(void) {
19
EGLint num_config;
20
EGLContext g_egl_ctx;
21
EGLDisplay g_egl_dpy;
22
EGLConfig g_config;
23
24
static const EGLint attribute_list[] = {
25
EGL_RED_SIZE, 8,
26
EGL_GREEN_SIZE, 8,
27
EGL_BLUE_SIZE, 8,
28
EGL_ALPHA_SIZE, 8,
29
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
30
EGL_NONE
31
};
32
33
static const EGLint context_attributes[] = {
34
EGL_CONTEXT_CLIENT_VERSION, 2,
35
EGL_NONE
36
};
37
38
g_egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
39
if (!g_egl_dpy)
40
die("failed to create display");
41
42
if (!eglInitialize(g_egl_dpy, NULL, NULL))
43
die("failed to initialize egl");
44
45
if (!eglChooseConfig(g_egl_dpy, attribute_list, &g_config, 1, &num_config))
46
die("failed to choose config");
47
48
g_egl_ctx = eglCreateContext(g_egl_dpy, g_config, EGL_NO_CONTEXT, context_attributes);
49
if (!g_egl_ctx)
50
die("failed to create context");
51
52
EGLNativeWindowType dummyWindow;
53
EGLSurface surface = eglCreateWindowSurface(g_egl_dpy, g_config, dummyWindow, NULL);
54
if (!surface)
55
die("failed to create window surface");
56
57
if (!eglMakeCurrent(g_egl_dpy, surface, surface, g_egl_ctx))
58
die("failed to activate context");
59
}
60
61
int main(int argc, char *argv[]) {
62
unsigned i;
63
64
create_context();
65
66
GLuint prog = glCreateProgram();
67
if (glGetError())
68
die("failed to create program");
69
70
GLuint vertex = glCreateShader(GL_VERTEX_SHADER);
71
if (glGetError())
72
die("failed to create vertex shader");
73
glAttachShader(prog, vertex);
74
75
GLuint fragment = glCreateShader(GL_FRAGMENT_SHADER);
76
if (glGetError())
77
die("failed to create fragment shader");
78
glAttachShader(prog, fragment);
79
80
GLuint shaders[2];
81
GLsizei count;
82
83
glGetAttachedShaders(prog, 2, &count, shaders);
84
if (glGetError())
85
die("failed to get attached shaders");
86
if (count != 2)
87
die("unknown number of shaders returned");
88
if (shaders[0] == shaders[1])
89
die("returned identical shaders");
90
91
for (i = 0; i < count; i++) {
92
if (shaders[i] == 0)
93
die("returned 0");
94
if (shaders[i] != vertex && shaders[i] != fragment)
95
die("unknown shader returned");
96
}
97
98
REPORT_RESULT(1);
99
100
return 0;
101
}
102
103