MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / main

Function main

test/browser/glframebufferattachmentinfo.c:24–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24int main() {
25 EGLDisplay dpy;
26 EGLint dpy_attrib_list[] = {
27 EGL_CONFORMANT, EGL_OPENGL_ES2_BIT,
28 EGL_DEPTH_SIZE, 16,
29 EGL_NONE
30 };
31 EGLConfig *configs;
32 EGLint num_config;
33 EGLNativeWindowType win;
34 EGLSurface surface;
35 EGLContext ctx;
36 EGLint ctx_attrib_list[] = {
37 EGL_CONTEXT_CLIENT_VERSION, 2,
38 EGL_NONE
39 };
40 dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
41 eglInitialize(dpy, NULL, NULL);
42 eglChooseConfig(dpy, dpy_attrib_list, NULL, 0, &num_config);
43 configs = malloc(sizeof(EGLConfig) * num_config);
44 eglChooseConfig(dpy, dpy_attrib_list, configs, num_config, &num_config);
45 memset(&win, 0, sizeof(EGLNativeWindowType));
46#if defined(__EMSCRIPTEN__)
47 // Simply skip window creation because the handle is ignored by Emscripten.
48#else
49#error not implemented
50#endif
51 surface = eglCreateWindowSurface(dpy, configs[0], win, NULL);
52 ctx = eglCreateContext(dpy, configs[0], EGL_NO_CONTEXT, ctx_attrib_list);
53 eglMakeCurrent(dpy, surface, surface, ctx);
54
55 GLuint fbo;
56 GLuint tex;
57 GLuint rbo;
58 glGenFramebuffers(1, &fbo);
59 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
60 glGenTextures(1, &tex);
61 glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
62 for (int i = 0; i < 6; i++) {
63 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
64 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
65 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
66 }
67 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, tex, 0);
68 glGenRenderbuffers(1, &rbo);
69 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
70 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 256, 256);
71 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo);
72
73 GLint params;
74 int result = 1;
75 printf("check type of GL_COLOR_ATTACHMENT0\n");
76 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &params);
77 result &= check_equal(GL_TEXTURE, params);
78 printf("check type of GL_DEPTH_ATTACHMENT\n");
79 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &params);
80 result &= check_equal(GL_RENDERBUFFER, params);
81 printf("check name of GL_COLOR_ATTACHMENT0\n");

Callers

nothing calls this directly

Calls 7

memsetFunction · 0.85
glGenTexturesFunction · 0.85
glTexImage2DFunction · 0.85
printfFunction · 0.85
check_equalFunction · 0.85
mallocFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected