1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include "packspu.h"
|
---|
8 | #include "cr_packfunctions.h"
|
---|
9 | #include "state/cr_statefuncs.h"
|
---|
10 | #include "cr_string.h"
|
---|
11 | #include "packspu_proto.h"
|
---|
12 | #include "cr_mem.h"
|
---|
13 | #include <locale.h>
|
---|
14 |
|
---|
15 | static GLubyte gpszExtensions[10000];
|
---|
16 | #ifdef CR_OPENGL_VERSION_2_0
|
---|
17 | static GLubyte gpszShadingVersion[255]="";
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | static void GetString(GLenum name, GLubyte *pszStr)
|
---|
21 | {
|
---|
22 | GET_THREAD(thread);
|
---|
23 | int writeback = 1;
|
---|
24 |
|
---|
25 | if (pack_spu.swap)
|
---|
26 | crPackGetStringSWAP(name, pszStr, &writeback);
|
---|
27 | else
|
---|
28 | crPackGetString(name, pszStr, &writeback);
|
---|
29 | packspuFlush( (void *) thread );
|
---|
30 |
|
---|
31 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
32 | }
|
---|
33 |
|
---|
34 | static GLfloat
|
---|
35 | GetVersionString(void)
|
---|
36 | {
|
---|
37 | static GLboolean fInitialized = GL_FALSE;
|
---|
38 | static GLfloat version = 0.;
|
---|
39 |
|
---|
40 | if (!fInitialized)
|
---|
41 | {
|
---|
42 | GLubyte return_value[100];
|
---|
43 |
|
---|
44 | GetString(GL_VERSION, return_value);
|
---|
45 | CRASSERT(crStrlen((char *)return_value) < 100);
|
---|
46 |
|
---|
47 | version = crStrToFloat((char *) return_value);
|
---|
48 | version = crStateComputeVersion(version);
|
---|
49 |
|
---|
50 | fInitialized = GL_TRUE;
|
---|
51 | }
|
---|
52 |
|
---|
53 | return version;
|
---|
54 | }
|
---|
55 |
|
---|
56 | static const GLubyte *
|
---|
57 | GetExtensions(void)
|
---|
58 | {
|
---|
59 | static GLboolean fInitialized = GL_FALSE;
|
---|
60 | if (!fInitialized)
|
---|
61 | {
|
---|
62 | GLubyte return_value[10*1000];
|
---|
63 | const GLubyte *extensions, *ext;
|
---|
64 | GET_THREAD(thread);
|
---|
65 | int writeback = 1;
|
---|
66 |
|
---|
67 | if (pack_spu.swap)
|
---|
68 | {
|
---|
69 | crPackGetStringSWAP( GL_EXTENSIONS, return_value, &writeback );
|
---|
70 | }
|
---|
71 | else
|
---|
72 | {
|
---|
73 | crPackGetString( GL_EXTENSIONS, return_value, &writeback );
|
---|
74 | }
|
---|
75 | packspuFlush( (void *) thread );
|
---|
76 |
|
---|
77 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
78 |
|
---|
79 | CRASSERT(crStrlen((char *)return_value) < 10*1000);
|
---|
80 |
|
---|
81 | /* OK, we got the result from the server. Now we have to
|
---|
82 | * intersect is with the set of extensions that Chromium understands
|
---|
83 | * and tack on the Chromium-specific extensions.
|
---|
84 | */
|
---|
85 | extensions = return_value;
|
---|
86 | ext = crStateMergeExtensions(1, &extensions);
|
---|
87 |
|
---|
88 | #ifdef Linux
|
---|
89 | /** @todo
|
---|
90 | *That's a hack to allow running Unity, it uses libnux which is calling extension functions
|
---|
91 | *without checking if it's being supported/exported.
|
---|
92 | *glActiveStencilFaceEXT seems to be actually supported but the extension string isn't exported (for ex. on ATI HD4870),
|
---|
93 | *which leads to libglew setting function pointer to NULL and crashing Unity.
|
---|
94 | */
|
---|
95 | sprintf((char*)gpszExtensions, "%s GL_EXT_stencil_two_side", ext);
|
---|
96 | #else
|
---|
97 | sprintf((char*)gpszExtensions, "%s", ext);
|
---|
98 | #endif
|
---|
99 | fInitialized = GL_TRUE;
|
---|
100 | }
|
---|
101 |
|
---|
102 | return gpszExtensions;
|
---|
103 | }
|
---|
104 |
|
---|
105 | #ifdef WINDOWS
|
---|
106 | static bool packspuRunningUnderWine(void)
|
---|
107 | {
|
---|
108 | return NULL != GetModuleHandle("wined3d.dll") || NULL != GetModuleHandle("wined3dwddm.dll") || NULL != GetModuleHandle("wined3dwddm-x86.dll");
|
---|
109 | }
|
---|
110 | #endif
|
---|
111 |
|
---|
112 | const GLubyte * PACKSPU_APIENTRY packspu_GetString( GLenum name )
|
---|
113 | {
|
---|
114 | GET_CONTEXT(ctx);
|
---|
115 |
|
---|
116 | switch(name)
|
---|
117 | {
|
---|
118 | case GL_EXTENSIONS:
|
---|
119 | return GetExtensions();
|
---|
120 | case GL_VERSION:
|
---|
121 | #if 0 && defined(WINDOWS)
|
---|
122 | if (packspuRunningUnderWine())
|
---|
123 | {
|
---|
124 | GetString(GL_REAL_VERSION, ctx->pszRealVersion);
|
---|
125 | return ctx->pszRealVersion;
|
---|
126 | }
|
---|
127 | else
|
---|
128 | #endif
|
---|
129 | {
|
---|
130 | char *oldlocale;
|
---|
131 | float version;
|
---|
132 |
|
---|
133 | oldlocale = setlocale(LC_NUMERIC, NULL);
|
---|
134 | oldlocale = crStrdup(oldlocale);
|
---|
135 | setlocale(LC_NUMERIC, "C");
|
---|
136 |
|
---|
137 | version = GetVersionString();
|
---|
138 | sprintf((char*)ctx->glVersion, "%.1f Chromium %s", version, CR_VERSION_STRING);
|
---|
139 |
|
---|
140 | if (oldlocale)
|
---|
141 | {
|
---|
142 | setlocale(LC_NUMERIC, oldlocale);
|
---|
143 | crFree(oldlocale);
|
---|
144 | }
|
---|
145 |
|
---|
146 | return ctx->glVersion;
|
---|
147 | }
|
---|
148 | case GL_VENDOR:
|
---|
149 | #ifdef WINDOWS
|
---|
150 | if (packspuRunningUnderWine())
|
---|
151 | {
|
---|
152 | GetString(GL_REAL_VENDOR, ctx->pszRealVendor);
|
---|
153 | return ctx->pszRealVendor;
|
---|
154 | }
|
---|
155 | else
|
---|
156 | #endif
|
---|
157 | {
|
---|
158 | return crStateGetString(name);
|
---|
159 | }
|
---|
160 | case GL_RENDERER:
|
---|
161 | #ifdef WINDOWS
|
---|
162 | if (packspuRunningUnderWine())
|
---|
163 | {
|
---|
164 | GetString(GL_REAL_RENDERER, ctx->pszRealRenderer);
|
---|
165 | return ctx->pszRealRenderer;
|
---|
166 | }
|
---|
167 | else
|
---|
168 | #endif
|
---|
169 | {
|
---|
170 | return crStateGetString(name);
|
---|
171 | }
|
---|
172 |
|
---|
173 | #ifdef CR_OPENGL_VERSION_2_0
|
---|
174 | case GL_SHADING_LANGUAGE_VERSION:
|
---|
175 | {
|
---|
176 | static GLboolean fInitialized = GL_FALSE;
|
---|
177 | if (!fInitialized)
|
---|
178 | {
|
---|
179 | GetString(GL_SHADING_LANGUAGE_VERSION, gpszShadingVersion);
|
---|
180 | fInitialized = GL_TRUE;
|
---|
181 | }
|
---|
182 | return gpszShadingVersion;
|
---|
183 | }
|
---|
184 | #endif
|
---|
185 | #ifdef GL_CR_real_vendor_strings
|
---|
186 | case GL_REAL_VENDOR:
|
---|
187 | GetString(GL_REAL_VENDOR, ctx->pszRealVendor);
|
---|
188 | return ctx->pszRealVendor;
|
---|
189 | case GL_REAL_VERSION:
|
---|
190 | GetString(GL_REAL_VERSION, ctx->pszRealVersion);
|
---|
191 | return ctx->pszRealVersion;
|
---|
192 | case GL_REAL_RENDERER:
|
---|
193 | GetString(GL_REAL_RENDERER, ctx->pszRealRenderer);
|
---|
194 | return ctx->pszRealRenderer;
|
---|
195 | #endif
|
---|
196 | default:
|
---|
197 | return crStateGetString(name);
|
---|
198 | }
|
---|
199 | }
|
---|
200 |
|
---|
201 | void packspuInitStrings()
|
---|
202 | {
|
---|
203 | static GLboolean fInitialized = GL_FALSE;
|
---|
204 |
|
---|
205 | if (!fInitialized)
|
---|
206 | {
|
---|
207 | packspu_GetString(GL_EXTENSIONS);
|
---|
208 | packspu_GetString(GL_VERSION);
|
---|
209 | fInitialized = GL_TRUE;
|
---|
210 | }
|
---|
211 | }
|
---|