1e52adb7bSmrg/* 2e52adb7bSmrg * Copyright © 2014 Intel Corporation 3e52adb7bSmrg * 4e52adb7bSmrg * Permission is hereby granted, free of charge, to any person obtaining a 5e52adb7bSmrg * copy of this software and associated documentation files (the "Software"), 6e52adb7bSmrg * to deal in the Software without restriction, including without limitation 7e52adb7bSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8e52adb7bSmrg * and/or sell copies of the Software, and to permit persons to whom the 9e52adb7bSmrg * Software is furnished to do so, subject to the following conditions: 10e52adb7bSmrg * 11e52adb7bSmrg * The above copyright notice and this permission notice (including the next 12e52adb7bSmrg * paragraph) shall be included in all copies or substantial portions of the 13e52adb7bSmrg * Software. 14e52adb7bSmrg * 15e52adb7bSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16e52adb7bSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17e52adb7bSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18e52adb7bSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19e52adb7bSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20e52adb7bSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21e52adb7bSmrg * IN THE SOFTWARE. 22e52adb7bSmrg */ 23e52adb7bSmrg 24e52adb7bSmrg/** 25e52adb7bSmrg * @file egl_gl.c 26e52adb7bSmrg * 27e52adb7bSmrg * Tests that epoxy works with EGL using desktop OpenGL. 28e52adb7bSmrg */ 29e52adb7bSmrg 30e52adb7bSmrg#define _GNU_SOURCE 31e52adb7bSmrg 32e52adb7bSmrg#include <stdio.h> 33e52adb7bSmrg#include <string.h> 34e52adb7bSmrg#include <stdlib.h> 35e52adb7bSmrg#include <assert.h> 36e52adb7bSmrg#include <err.h> 37e52adb7bSmrg#include <dlfcn.h> 38e52adb7bSmrg#include "epoxy/gl.h" 39e52adb7bSmrg#include "epoxy/egl.h" 40e52adb7bSmrg#include "epoxy/glx.h" 41e52adb7bSmrg 42e52adb7bSmrg#include "egl_common.h" 43e52adb7bSmrg#include "glx_common.h" 44e52adb7bSmrg#include "dlwrap.h" 45e52adb7bSmrg 46e52adb7bSmrgstatic bool 47e52adb7bSmrgmake_egl_current_and_test(EGLDisplay *dpy, EGLContext ctx) 48e52adb7bSmrg{ 49e52adb7bSmrg const char *string; 50e52adb7bSmrg GLuint shader; 51e52adb7bSmrg bool pass = true; 52e52adb7bSmrg 53e52adb7bSmrg eglMakeCurrent(dpy, NULL, NULL, ctx); 54e52adb7bSmrg 55e52adb7bSmrg if (!epoxy_is_desktop_gl()) { 56ca86eba8Smrg fputs("Claimed to be desktop\n", stderr); 57e52adb7bSmrg pass = false; 58e52adb7bSmrg } 59e52adb7bSmrg 60e52adb7bSmrg if (epoxy_gl_version() < 20) { 61e52adb7bSmrg fprintf(stderr, "Claimed to be GL version %d\n", 62e52adb7bSmrg epoxy_gl_version()); 63e52adb7bSmrg pass = false; 64e52adb7bSmrg } 65e52adb7bSmrg 66e52adb7bSmrg string = (const char *)glGetString(GL_VERSION); 67e52adb7bSmrg printf("GL version: %s\n", string); 68e52adb7bSmrg 69e52adb7bSmrg shader = glCreateShader(GL_FRAGMENT_SHADER); 70e52adb7bSmrg pass = glIsShader(shader); 71e52adb7bSmrg 72e52adb7bSmrg return pass; 73e52adb7bSmrg} 74e52adb7bSmrg 75e52adb7bSmrgstatic void 76e52adb7bSmrginit_egl(EGLDisplay **out_dpy, EGLContext *out_ctx) 77e52adb7bSmrg{ 78e52adb7bSmrg EGLDisplay *dpy = get_egl_display_or_skip(); 79e52adb7bSmrg static const EGLint config_attribs[] = { 80e52adb7bSmrg EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 81e52adb7bSmrg EGL_RED_SIZE, 1, 82e52adb7bSmrg EGL_GREEN_SIZE, 1, 83e52adb7bSmrg EGL_BLUE_SIZE, 1, 84e52adb7bSmrg EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, 85e52adb7bSmrg EGL_NONE 86e52adb7bSmrg }; 87e52adb7bSmrg static const EGLint context_attribs[] = { 88e52adb7bSmrg EGL_CONTEXT_CLIENT_VERSION, 2, 89e52adb7bSmrg EGL_NONE 90e52adb7bSmrg }; 91e52adb7bSmrg EGLContext ctx; 92e52adb7bSmrg EGLConfig cfg; 93e52adb7bSmrg EGLint count; 94e52adb7bSmrg 95e52adb7bSmrg if (!epoxy_has_egl_extension(dpy, "EGL_KHR_surfaceless_context")) 96e52adb7bSmrg errx(77, "Test requires EGL_KHR_surfaceless_context"); 97e52adb7bSmrg 98e52adb7bSmrg if (!eglBindAPI(EGL_OPENGL_API)) 99e52adb7bSmrg errx(77, "Couldn't initialize EGL with desktop GL\n"); 100e52adb7bSmrg 101e52adb7bSmrg if (!eglChooseConfig(dpy, config_attribs, &cfg, 1, &count)) 102e52adb7bSmrg errx(77, "Couldn't get an EGLConfig\n"); 103e52adb7bSmrg 104e52adb7bSmrg ctx = eglCreateContext(dpy, cfg, NULL, context_attribs); 105e52adb7bSmrg if (!ctx) 106e52adb7bSmrg errx(77, "Couldn't create a GL context\n"); 107e52adb7bSmrg 108e52adb7bSmrg *out_dpy = dpy; 109e52adb7bSmrg *out_ctx = ctx; 110e52adb7bSmrg} 111e52adb7bSmrg 112e52adb7bSmrgint 113e52adb7bSmrgmain(int argc, char **argv) 114e52adb7bSmrg{ 115e52adb7bSmrg bool pass = true; 116e52adb7bSmrg EGLDisplay *egl_dpy; 117e52adb7bSmrg EGLContext egl_ctx; 118e52adb7bSmrg 119e52adb7bSmrg /* Force epoxy to have loaded both EGL and GLX libs already -- we 120e52adb7bSmrg * can't assume anything about symbol resolution based on having 121e52adb7bSmrg * EGL or GLX loaded. 122e52adb7bSmrg */ 123e52adb7bSmrg (void)glXGetCurrentContext(); 124e52adb7bSmrg (void)eglGetCurrentContext(); 125e52adb7bSmrg 126e52adb7bSmrg init_egl(&egl_dpy, &egl_ctx); 127e52adb7bSmrg pass = make_egl_current_and_test(egl_dpy, egl_ctx) && pass; 128e52adb7bSmrg 129e52adb7bSmrg return pass != true; 130e52adb7bSmrg} 131