1*706d0b42SXin Li /*
2*706d0b42SXin Li * Copyright © 2013 Intel Corporation
3*706d0b42SXin Li *
4*706d0b42SXin Li * Permission is hereby granted, free of charge, to any person obtaining a
5*706d0b42SXin Li * copy of this software and associated documentation files (the "Software"),
6*706d0b42SXin Li * to deal in the Software without restriction, including without limitation
7*706d0b42SXin Li * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*706d0b42SXin Li * and/or sell copies of the Software, and to permit persons to whom the
9*706d0b42SXin Li * Software is furnished to do so, subject to the following conditions:
10*706d0b42SXin Li *
11*706d0b42SXin Li * The above copyright notice and this permission notice (including the next
12*706d0b42SXin Li * paragraph) shall be included in all copies or substantial portions of the
13*706d0b42SXin Li * Software.
14*706d0b42SXin Li *
15*706d0b42SXin Li * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*706d0b42SXin Li * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*706d0b42SXin Li * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18*706d0b42SXin Li * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*706d0b42SXin Li * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*706d0b42SXin Li * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21*706d0b42SXin Li * IN THE SOFTWARE.
22*706d0b42SXin Li */
23*706d0b42SXin Li
24*706d0b42SXin Li #include <stdio.h>
25*706d0b42SXin Li #include <assert.h>
26*706d0b42SXin Li #include "epoxy/gl.h"
27*706d0b42SXin Li #include "epoxy/glx.h"
28*706d0b42SXin Li #include <X11/Xlib.h>
29*706d0b42SXin Li
30*706d0b42SXin Li #include "glx_common.h"
31*706d0b42SXin Li
32*706d0b42SXin Li static Display *dpy;
33*706d0b42SXin Li static bool has_argb2101010;
34*706d0b42SXin Li
35*706d0b42SXin Li static bool
test_with_epoxy(void)36*706d0b42SXin Li test_with_epoxy(void)
37*706d0b42SXin Li {
38*706d0b42SXin Li glBegin(GL_TRIANGLES);
39*706d0b42SXin Li {
40*706d0b42SXin Li /* Hit a base entrypoint that won't call gl_version() */
41*706d0b42SXin Li glVertex2f(0, 0);
42*706d0b42SXin Li
43*706d0b42SXin Li /* Hit an entrypoint that will call probably call gl_version() */
44*706d0b42SXin Li glMultiTexCoord4f(GL_TEXTURE0, 0.0, 0.0, 0.0, 0.0);
45*706d0b42SXin Li
46*706d0b42SXin Li /* Hit an entrypoint that will probably call
47*706d0b42SXin Li * epoxy_conservative_has_extension();
48*706d0b42SXin Li */
49*706d0b42SXin Li if (has_argb2101010) {
50*706d0b42SXin Li glTexCoordP4ui(GL_UNSIGNED_INT_2_10_10_10_REV, 0);
51*706d0b42SXin Li }
52*706d0b42SXin Li }
53*706d0b42SXin Li glEnd();
54*706d0b42SXin Li
55*706d0b42SXin Li /* No error should have been generated in the process. */
56*706d0b42SXin Li return glGetError() == 0;
57*706d0b42SXin Li }
58*706d0b42SXin Li
59*706d0b42SXin Li
60*706d0b42SXin Li
61*706d0b42SXin Li #undef glBegin
62*706d0b42SXin Li #undef glEnd
63*706d0b42SXin Li extern void glBegin(GLenum primtype);
64*706d0b42SXin Li extern void glEnd(void);
65*706d0b42SXin Li
66*706d0b42SXin Li static bool
test_without_epoxy(void)67*706d0b42SXin Li test_without_epoxy(void)
68*706d0b42SXin Li {
69*706d0b42SXin Li glBegin(GL_TRIANGLES);
70*706d0b42SXin Li {
71*706d0b42SXin Li /* Hit a base entrypoint that won't call gl_version() */
72*706d0b42SXin Li glVertex4f(0, 0, 0, 0);
73*706d0b42SXin Li
74*706d0b42SXin Li /* Hit an entrypoint that will call probably call gl_version() */
75*706d0b42SXin Li glMultiTexCoord3f(GL_TEXTURE0, 0.0, 0.0, 0.0);
76*706d0b42SXin Li
77*706d0b42SXin Li /* Hit an entrypoint that will probably call
78*706d0b42SXin Li * epoxy_conservative_has_extension();
79*706d0b42SXin Li */
80*706d0b42SXin Li if (has_argb2101010) {
81*706d0b42SXin Li glTexCoordP3ui(GL_UNSIGNED_INT_2_10_10_10_REV, 0);
82*706d0b42SXin Li }
83*706d0b42SXin Li }
84*706d0b42SXin Li glEnd();
85*706d0b42SXin Li
86*706d0b42SXin Li /* We can't make any assertions about error presence this time
87*706d0b42SXin Li * around. This test is just trying to catch segfaults.
88*706d0b42SXin Li */
89*706d0b42SXin Li return true;
90*706d0b42SXin Li }
91*706d0b42SXin Li
92*706d0b42SXin Li int
main(int argc,char ** argv)93*706d0b42SXin Li main(int argc, char **argv)
94*706d0b42SXin Li {
95*706d0b42SXin Li bool pass = true;
96*706d0b42SXin Li
97*706d0b42SXin Li dpy = get_display_or_skip();
98*706d0b42SXin Li make_glx_context_current_or_skip(dpy);
99*706d0b42SXin Li
100*706d0b42SXin Li has_argb2101010 =
101*706d0b42SXin Li epoxy_has_gl_extension("GL_ARB_vertex_type_2_10_10_10_rev");
102*706d0b42SXin Li
103*706d0b42SXin Li pass = pass && test_with_epoxy();
104*706d0b42SXin Li pass = pass && test_without_epoxy();
105*706d0b42SXin Li
106*706d0b42SXin Li return pass != true;
107*706d0b42SXin Li }
108