1 #ifdef BCMHOST
2 #include "bcm_host.h"
3 #endif
4 
5 #include <EGL/egl.h>
6 #include <stdbool.h>
7 #include <stdlib.h>
8 #include <X11/Xlib.h>
9 #include <X11/Xutil.h>
10 #include <stdio.h>
11 #include <string.h>
12 
13 #include "../gl/gl.h"
14 
15 // defines yoinked from Mesa glx.h
16 #define GLX_VERSION_1_1     1
17 #define GLX_VERSION_1_2     1
18 #define GLX_VERSION_1_3     1
19 #define GLX_VERSION_1_4     1
20 
21 #define GLX_EXTENSION_NAME   "GLX"
22 
23 /*
24  * Tokens for glXChooseVisual and glXGetConfig:
25  */
26 #define GLX_USE_GL      1
27 #define GLX_BUFFER_SIZE     2
28 #define GLX_LEVEL       3
29 #define GLX_RGBA        4
30 #define GLX_DOUBLEBUFFER    5
31 #define GLX_STEREO      6
32 #define GLX_AUX_BUFFERS     7
33 #define GLX_RED_SIZE        8
34 #define GLX_GREEN_SIZE      9
35 #define GLX_BLUE_SIZE       10
36 #define GLX_ALPHA_SIZE      11
37 #define GLX_DEPTH_SIZE      12
38 #define GLX_STENCIL_SIZE    13
39 #define GLX_ACCUM_RED_SIZE  14
40 #define GLX_ACCUM_GREEN_SIZE    15
41 #define GLX_ACCUM_BLUE_SIZE 16
42 #define GLX_ACCUM_ALPHA_SIZE    17
43 
44 /*
45  * Error codes returned by glXGetConfig:
46  */
47 #define GLX_BAD_SCREEN      1
48 #define GLX_BAD_ATTRIBUTE   2
49 #define GLX_NO_EXTENSION    3
50 #define GLX_BAD_VISUAL      4
51 #define GLX_BAD_CONTEXT     5
52 #define GLX_BAD_VALUE           6
53 #define GLX_BAD_ENUM        7
54 
55 /*
56  * GLX 1.1 and later:
57  */
58 #define GLX_VENDOR      1
59 #define GLX_VERSION     2
60 #define GLX_EXTENSIONS      3
61 
62 /*
63  * GLX 1.3 and later:
64  */
65 #define GLX_CONFIG_CAVEAT       0x20
66 #define GLX_DONT_CARE           0xFFFFFFFF
67 #define GLX_X_VISUAL_TYPE       0x22
68 #define GLX_TRANSPARENT_TYPE        0x23
69 #define GLX_TRANSPARENT_INDEX_VALUE 0x24
70 #define GLX_TRANSPARENT_RED_VALUE   0x25
71 #define GLX_TRANSPARENT_GREEN_VALUE 0x26
72 #define GLX_TRANSPARENT_BLUE_VALUE  0x27
73 #define GLX_TRANSPARENT_ALPHA_VALUE 0x28
74 #define GLX_WINDOW_BIT          0x00000001
75 #define GLX_PIXMAP_BIT          0x00000002
76 #define GLX_PBUFFER_BIT         0x00000004
77 #define GLX_AUX_BUFFERS_BIT     0x00000010
78 #define GLX_FRONT_LEFT_BUFFER_BIT   0x00000001
79 #define GLX_FRONT_RIGHT_BUFFER_BIT  0x00000002
80 #define GLX_BACK_LEFT_BUFFER_BIT    0x00000004
81 #define GLX_BACK_RIGHT_BUFFER_BIT   0x00000008
82 #define GLX_DEPTH_BUFFER_BIT        0x00000020
83 #define GLX_STENCIL_BUFFER_BIT      0x00000040
84 #define GLX_ACCUM_BUFFER_BIT        0x00000080
85 #define GLX_NONE            0x8000
86 #define GLX_SLOW_CONFIG         0x8001
87 #define GLX_TRUE_COLOR          0x8002
88 #define GLX_DIRECT_COLOR        0x8003
89 #define GLX_PSEUDO_COLOR        0x8004
90 #define GLX_STATIC_COLOR        0x8005
91 #define GLX_GRAY_SCALE          0x8006
92 #define GLX_STATIC_GRAY         0x8007
93 #define GLX_TRANSPARENT_RGB     0x8008
94 #define GLX_TRANSPARENT_INDEX       0x8009
95 #define GLX_VISUAL_ID           0x800B
96 #define GLX_SCREEN          0x800C
97 #define GLX_NON_CONFORMANT_CONFIG   0x800D
98 #define GLX_DRAWABLE_TYPE       0x8010
99 #define GLX_RENDER_TYPE         0x8011
100 #define GLX_X_RENDERABLE        0x8012
101 #define GLX_FBCONFIG_ID         0x8013
102 #define GLX_RGBA_TYPE           0x8014
103 #define GLX_COLOR_INDEX_TYPE        0x8015
104 #define GLX_MAX_PBUFFER_WIDTH       0x8016
105 #define GLX_MAX_PBUFFER_HEIGHT      0x8017
106 #define GLX_MAX_PBUFFER_PIXELS      0x8018
107 #define GLX_PRESERVED_CONTENTS      0x801B
108 #define GLX_LARGEST_PBUFFER     0x801C
109 #define GLX_WIDTH           0x801D
110 #define GLX_HEIGHT          0x801E
111 #define GLX_EVENT_MASK          0x801F
112 #define GLX_DAMAGED         0x8020
113 #define GLX_SAVED           0x8021
114 #define GLX_WINDOW          0x8022
115 #define GLX_PBUFFER         0x8023
116 #define GLX_PBUFFER_HEIGHT              0x8040
117 #define GLX_PBUFFER_WIDTH               0x8041
118 #define GLX_RGBA_BIT            0x00000001
119 #define GLX_COLOR_INDEX_BIT     0x00000002
120 #define GLX_PBUFFER_CLOBBER_MASK    0x08000000
121 
122 /*
123  * GLX 1.4 and later:
124  */
125 #define GLX_SAMPLE_BUFFERS              0x186a0 /*100000*/
126 #define GLX_SAMPLES                     0x186a1 /*100001*/
127 
128 struct __GLXContextRec {
129     Display *display;
130     unsigned char direct;
131     int currentWritable;
132     int currentReadable;
133     XID xid;
134 };
135 typedef struct __GLXContextRec *GLXContext;
136 
137 struct __GLXFBConfigRec {
138     int visualType;
139     int transparentType;
140                                 /*    colors are floats scaled to ints */
141     int transparentRed, transparentGreen, transparentBlue, transparentAlpha;
142     int transparentIndex;
143 
144     int visualCaveat;
145 
146     int associatedVisualId;
147     int screen;
148 
149     int drawableType;
150     int renderType;
151 
152     int maxPbufferWidth, maxPbufferHeight, maxPbufferPixels;
153     int optimalPbufferWidth, optimalPbufferHeight;  /* for SGIX_pbuffer */
154 
155     int visualSelectGroup;  /* visuals grouped by select priority */
156 
157     unsigned int id;
158 
159     unsigned char rgbMode;
160     unsigned char colorIndexMode;
161     unsigned char doubleBufferMode;
162     unsigned char stereoMode;
163     unsigned char haveAccumBuffer;
164     unsigned char haveDepthBuffer;
165     unsigned char haveStencilBuffer;
166 
167     /* The number of bits present in various buffers */
168     int accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits;
169     int depthBits;
170     int stencilBits;
171     int indexBits;
172     int redBits, greenBits, blueBits, alphaBits;
173     unsigned int redMask, greenMask, blueMask, alphaMask;
174 
175     unsigned int multiSampleSize; /* Number of samples per pixel (0 if no ms) */
176 
177     unsigned int nMultiSampleBuffers; /* Number of availble ms buffers */
178     int maxAuxBuffers;
179 
180     /* frame buffer level */
181     int level;
182 
183     /* color ranges (for SGI_color_range) */
184     unsigned char extendedRange;
185     double minRed, maxRed;
186     double minGreen, maxGreen;
187     double minBlue, maxBlue;
188     double minAlpha, maxAlpha;
189 };
190 typedef struct __GLXFBConfigRec *GLXFBConfig;
191 
192 GLXContext glXCreateContext(Display *dpy,
193                             XVisualInfo *visual,
194                             GLXContext shareList,
195                             Bool direct);
196 
197 GLXContext glXCreateContextAttribsARB(Display *display, void *config,
198                                       GLXContext share_context, Bool direct,
199                                       const int *attrib_list);
200 
201 void glXSwapIntervalEXT(Display *display, int drawable, int interval);
202 void glXSwapIntervalMESA(int interval);
203 void glXSwapIntervalSGI(int interval);
204 
205 // GLX 1.1?
206 Bool glXIsDirect(Display * display, GLXContext ctx);
207 Bool glXMakeCurrent(Display *display, int drawable, GLXContext context);
208 Bool glXQueryExtension(Display *display, int *errorBase, int *eventBase);
209 Bool glXQueryVersion(Display *display, int *major, int *minor);
210 const char *glXGetClientString(Display *display, int name);
211 const char *glXQueryExtensionsString(Display *display, int screen);
212 const char *glXQueryServerString(Display *display, int screen, int name);
213 void glXGetCurrentDrawable();
214 void glXCreateGLXPixmap(Display *display, XVisualInfo * visual, Pixmap pixmap);
215 int glXGetConfig(Display *display, XVisualInfo *visual, int attribute, int *value);
216 void glXCopyContext(Display *display, GLXContext src, GLXContext dst, GLuint mask);
217 void glXDestroyContext(Display *display, GLXContext ctx);
218 void glXDestroyGLXPixmap(Display *display, void *pixmap);
219 void glXSwapBuffers(Display *display, int drawable);
220 void glXUseXFont(Font font, int first, int count, int listBase);
221 void glXWaitGL();
222 void glXWaitX();
223 XVisualInfo *glXChooseVisual(Display *display, int screen, int *attributes);
224 
225 // GLX 1.2
226 Display *glXGetCurrentDisplay();
227 
228 // GLX 1.3
229 GLXContext glXGetCurrentContext();
230 XVisualInfo *glXGetVisualFromFBConfig(Display *display, GLXFBConfig config);
231 GLXFBConfig *glXChooseFBConfig(Display *display, int screen, const int *attrib_list, int *count);
232 GLXFBConfig *glXGetFBConfigs(Display *display, int screen, int *count);
233 int glXGetFBConfigAttrib(Display *display, GLXFBConfig config, int attribute, int *value);
234 
235 void glXCreateWindow(Display *display, GLXFBConfig config, Window win, int *attrib_list);
236 void glXDestroyWindow(Display *display, void *win);
237 
238