VirtualBox

source: vbox/trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_getstring.c@ 78376

Last change on this file since 78376 was 78375, checked in by vboxsync, 6 years ago

Additions/common/crOpengl,GuestHost/OpenGL,HostServices/SharedOpenGL: Eliminate all global variables from the state tracker library (state_tracker) in preparation of the SPU DLL merging, bugref:9435

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette