Path: blob/main/test/browser/glgetattachedshaders.c
7085 views
/*1* Copyright 2013 The Emscripten Authors. All rights reserved.2* Emscripten is available under two separate licenses, the MIT license and the3* University of Illinois/NCSA Open Source License. Both these licenses can be4* found in the LICENSE file.5*/67#include <GLES2/gl2.h>8#include <EGL/egl.h>9#include <stdio.h>10#include <stdlib.h>1112static void die(const char *msg) {13printf("%s\n", msg);14abort();15}1617static void create_context(void) {18EGLint num_config;19EGLContext g_egl_ctx;20EGLDisplay g_egl_dpy;21EGLConfig g_config;2223static const EGLint attribute_list[] = {24EGL_RED_SIZE, 8,25EGL_GREEN_SIZE, 8,26EGL_BLUE_SIZE, 8,27EGL_ALPHA_SIZE, 8,28EGL_SURFACE_TYPE, EGL_WINDOW_BIT,29EGL_NONE30};3132static const EGLint context_attributes[] = {33EGL_CONTEXT_CLIENT_VERSION, 2,34EGL_NONE35};3637g_egl_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);38if (!g_egl_dpy)39die("failed to create display");4041if (!eglInitialize(g_egl_dpy, NULL, NULL))42die("failed to initialize egl");4344if (!eglChooseConfig(g_egl_dpy, attribute_list, &g_config, 1, &num_config))45die("failed to choose config");4647g_egl_ctx = eglCreateContext(g_egl_dpy, g_config, EGL_NO_CONTEXT, context_attributes);48if (!g_egl_ctx)49die("failed to create context");5051EGLNativeWindowType dummyWindow;52EGLSurface surface = eglCreateWindowSurface(g_egl_dpy, g_config, dummyWindow, NULL);53if (!surface)54die("failed to create window surface");5556if (!eglMakeCurrent(g_egl_dpy, surface, surface, g_egl_ctx))57die("failed to activate context");58}5960int main(int argc, char *argv[]) {61unsigned i;6263create_context();6465GLuint prog = glCreateProgram();66if (glGetError())67die("failed to create program");6869GLuint vertex = glCreateShader(GL_VERTEX_SHADER);70if (glGetError())71die("failed to create vertex shader");72glAttachShader(prog, vertex);7374GLuint fragment = glCreateShader(GL_FRAGMENT_SHADER);75if (glGetError())76die("failed to create fragment shader");77glAttachShader(prog, fragment);7879GLuint shaders[2];80GLsizei count;8182glGetAttachedShaders(prog, 2, &count, shaders);83if (glGetError())84die("failed to get attached shaders");85if (count != 2)86die("unknown number of shaders returned");87if (shaders[0] == shaders[1])88die("returned identical shaders");8990for (i = 0; i < count; i++) {91if (shaders[i] == 0)92die("returned 0");93if (shaders[i] != vertex && shaders[i] != fragment)94die("unknown shader returned");95}9697REPORT_RESULT(1);9899return 0;100}101102103