xref: /aosp_15_r20/external/libepoxy/test/cgl_epoxy_api.c (revision 706d0b42ae4182339789e08d473a0b312ecdc60f)
1 /*
2  * Copyright 2018  Emmanuele Bassi
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 /**
25  * @file cgl_epoxy_api.c
26  *
27  * Tests the Epoxy API using the CoreGraphics OpenGL framework.
28  */
29 
30 #include <epoxy/gl.h>
31 #include <Carbon/Carbon.h>
32 #include <OpenGL/OpenGL.h>
33 #include <OpenGL/CGLTypes.h>
34 #include <OpenGL/CGLCurrent.h>
35 #include <OpenGL/CGLContext.h>
36 
37 int
main(void)38 main (void)
39 {
40     CGLPixelFormatAttribute attribs[] = {0};
41     CGLPixelFormatObj pix;
42     CGLContextObj ctx;
43     const char *string;
44     bool pass = true;
45     int npix;
46     GLint shader;
47 
48     CGLChoosePixelFormat(attribs, &pix, &npix);
49     CGLCreateContext(pix, (void *) 0, &ctx);
50     CGLSetCurrentContext(ctx);
51 
52     if (!epoxy_is_desktop_gl()) {
53         fputs("Claimed not to be desktop\n", stderr);
54         pass = false;
55     }
56 
57     if (epoxy_gl_version() < 20) {
58         fprintf(stderr, "Claimed to be GL version %d\n",
59                 epoxy_gl_version());
60         pass = false;
61     }
62 
63     if (epoxy_glsl_version() < 100) {
64         fprintf(stderr, "Claimed to have GLSL version %d\n",
65                 epoxy_glsl_version());
66         pass = false;
67     }
68 
69     string = (const char *)glGetString(GL_VERSION);
70     printf("GL version: %s - Epoxy: %d\n", string, epoxy_gl_version());
71 
72     string = (const char *)glGetString(GL_SHADING_LANGUAGE_VERSION);
73     printf("GLSL version: %s - Epoxy: %d\n", string, epoxy_glsl_version());
74 
75     shader = glCreateShader(GL_FRAGMENT_SHADER);
76     pass = glIsShader(shader);
77 
78     CGLSetCurrentContext(NULL);
79     CGLReleaseContext(ctx);
80     CGLReleasePixelFormat(pix);
81 
82     return pass != true;
83 }
84