texenvprogram: fix for ARB_draw_buffers.
[mesa.git] / src / gallium / winsys / xlib / xlib.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 *
26 *
27 **************************************************************************/
28
29 /*
30 * Authors:
31 * Keith Whitwell
32 */
33
34 #include "xlib.h"
35 #include "xm_winsys.h"
36
37 #include <stdlib.h>
38 #include <assert.h>
39
40 /* Todo, replace all this with callback-structs provided by the
41 * individual implementations.
42 */
43
44 enum mode {
45 MODE_CELL,
46 MODE_LLVMPIPE,
47 MODE_SOFTPIPE
48 };
49
50 /* advertise OpenGL support */
51 PUBLIC const int st_api_OpenGL = 1;
52
53 static enum mode get_mode()
54 {
55 #ifdef GALLIUM_CELL
56 if (!getenv("GALLIUM_NOCELL"))
57 return MODE_CELL;
58 #endif
59
60 #if defined(GALLIUM_LLVMPIPE)
61 return MODE_LLVMPIPE;
62 #else
63 return MODE_SOFTPIPE;
64 #endif
65 }
66
67 static void _init( void ) __attribute__((constructor));
68
69 static void _init( void )
70 {
71 enum mode xlib_mode = get_mode();
72
73 switch (xlib_mode) {
74 case MODE_CELL:
75 #if defined(GALLIUM_CELL)
76 xmesa_set_driver( &xlib_cell_driver );
77 #endif
78 break;
79 case MODE_LLVMPIPE:
80 #if defined(GALLIUM_LLVMPIPE)
81 xmesa_set_driver( &xlib_llvmpipe_driver );
82 #endif
83 break;
84 case MODE_SOFTPIPE:
85 #if defined(GALLIUM_SOFTPIPE)
86 xmesa_set_driver( &xlib_softpipe_driver );
87 #endif
88 break;
89 default:
90 assert(0);
91 break;
92 }
93 }
94
95
96 /***********************************************************************
97 *
98 * Butt-ugly hack to convince the linker not to throw away public GL
99 * symbols (they are all referenced from getprocaddress, I guess).
100 */
101 extern void (*linker_foo(const unsigned char *procName))();
102 extern void (*glXGetProcAddress(const unsigned char *procName))();
103
104 extern void (*linker_foo(const unsigned char *procName))()
105 {
106 return glXGetProcAddress(procName);
107 }
108
109
110 /**
111 * When GLX_INDIRECT_RENDERING is defined, some symbols are missing in
112 * libglapi.a. We need to define them here.
113 */
114 #ifdef GLX_INDIRECT_RENDERING
115
116 #define GL_GLEXT_PROTOTYPES
117 #include "GL/gl.h"
118 #include "glapi/glapi.h"
119 #include "glapi/glapitable.h"
120 #include "glapi/glapidispatch.h"
121
122 #if defined(USE_MGL_NAMESPACE)
123 #define NAME(func) mgl##func
124 #else
125 #define NAME(func) gl##func
126 #endif
127
128 #define DISPATCH(FUNC, ARGS, MESSAGE) \
129 CALL_ ## FUNC(GET_DISPATCH(), ARGS);
130
131 #define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) \
132 return CALL_ ## FUNC(GET_DISPATCH(), ARGS);
133
134 /* skip normal ones */
135 #define _GLAPI_SKIP_NORMAL_ENTRY_POINTS
136 #include "glapi/glapitemp.h"
137
138 #endif /* GLX_INDIRECT_RENDERING */