VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_getshaders.cpp@ 78375

Last change on this file since 78375 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: 12.8 KB
Line 
1/* $Id: server_getshaders.cpp 78375 2019-05-03 21:51:02Z vboxsync $ */
2/** @file
3 * VBox OpenGL GLSL related get functions
4 */
5
6/*
7 * Copyright (C) 2009-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include "cr_spu.h"
19#include "chromium.h"
20#include "cr_error.h"
21#include "cr_mem.h"
22#include "cr_net.h"
23#include "server_dispatch.h"
24#include "server.h"
25
26#include <iprt/assert.h>
27
28#ifdef CR_OPENGL_VERSION_2_0
29
30typedef struct _crGetActive_t
31{
32 GLsizei length;
33 GLint size;
34 GLenum type;
35} crGetActive_t;
36
37void SERVER_DISPATCH_APIENTRY crServerDispatchGetActiveAttrib(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, char *name)
38{
39 RT_NOREF(name, type, size, length);
40
41 crGetActive_t *pLocal = NULL;
42
43 if (bufSize > 0 && bufSize < INT32_MAX / 2)
44 pLocal = (crGetActive_t*)crCalloc(bufSize + sizeof(crGetActive_t));
45
46 if (!pLocal)
47 {
48 crGetActive_t zero;
49 zero.length = 0;
50 crServerReturnValue(&zero, sizeof(zero));
51 return;
52 }
53
54 cr_server.head_spu->dispatch_table.GetActiveAttrib(crStateGetProgramHWID(&cr_server.StateTracker, program), index, bufSize, &pLocal->length, &pLocal->size, &pLocal->type, (char*)&pLocal[1]);
55 crServerReturnValue(pLocal, pLocal->length+1+sizeof(crGetActive_t));
56 crFree(pLocal);
57}
58
59void SERVER_DISPATCH_APIENTRY crServerDispatchGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, char *name)
60{
61 RT_NOREF(name, type, size, length);
62
63 crGetActive_t *pLocal = NULL;
64
65 if (bufSize > 0 && bufSize < INT32_MAX / 2)
66 pLocal = (crGetActive_t*) crCalloc(bufSize + sizeof(crGetActive_t));
67
68 if (!pLocal)
69 {
70 crGetActive_t zero;
71 zero.length = 0;
72 crServerReturnValue(&zero, sizeof(zero));
73 return;
74 }
75
76 cr_server.head_spu->dispatch_table.GetActiveUniform(crStateGetProgramHWID(&cr_server.StateTracker, program), index, bufSize, &pLocal->length, &pLocal->size, &pLocal->type, (char*)&pLocal[1]);
77 crServerReturnValue(pLocal, pLocal->length+1+sizeof(crGetActive_t));
78 crFree(pLocal);
79}
80
81void SERVER_DISPATCH_APIENTRY crServerDispatchGetAttachedShaders(GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders)
82{
83 RT_NOREF(count, shaders);
84
85 GLsizei *pLocal = NULL;
86
87 if (maxCount > 0 && maxCount < INT32_MAX / sizeof(GLuint) / 2)
88 pLocal = (GLsizei*) crCalloc(maxCount * sizeof(GLuint) + sizeof(GLsizei));
89
90 if (!pLocal)
91 {
92 GLsizei zero=0;
93 crServerReturnValue(&zero, sizeof(zero));
94 return;
95 }
96 /* initial (fallback )value */
97 *pLocal = 0;
98 cr_server.head_spu->dispatch_table.GetAttachedShaders(crStateGetProgramHWID(&cr_server.StateTracker, program), maxCount, pLocal, (GLuint*)&pLocal[1]);
99
100 {
101 GLsizei i;
102 GLuint *ids=(GLuint*)&pLocal[1];
103
104 for (i=0; i<*pLocal; ++i)
105 ids[i] = crStateGLSLShaderHWIDtoID(&cr_server.StateTracker, ids[i]);
106 }
107
108 crServerReturnValue(pLocal, (*pLocal)*sizeof(GLuint)+sizeof(GLsizei));
109 crFree(pLocal);
110}
111
112void SERVER_DISPATCH_APIENTRY crServerDispatchGetAttachedObjectsARB(VBoxGLhandleARB containerObj, GLsizei maxCount, GLsizei * count, VBoxGLhandleARB * obj)
113{
114 RT_NOREF(count, obj);
115
116 GLsizei *pLocal = NULL;
117
118 if (maxCount > 0 && maxCount < INT32_MAX / sizeof(VBoxGLhandleARB) / 2)
119 pLocal = (GLsizei*) crCalloc(maxCount * sizeof(VBoxGLhandleARB) + sizeof(GLsizei));
120
121 if (!pLocal)
122 {
123 GLsizei zero=0;
124 crServerReturnValue(&zero, sizeof(zero));
125 return;
126 }
127 /* initial (fallback )value */
128 *pLocal = 0;
129 cr_server.head_spu->dispatch_table.GetAttachedObjectsARB(crStateGetProgramHWID(&cr_server.StateTracker, containerObj), maxCount, pLocal, (VBoxGLhandleARB*)&pLocal[1]);
130
131 {
132 GLsizei i;
133 GLuint *ids=(GLuint*)&pLocal[1];
134
135 for (i=0; i<*pLocal; ++i)
136 ids[i] = crStateGLSLShaderHWIDtoID(&cr_server.StateTracker, ids[i]);
137 }
138
139 crServerReturnValue(pLocal, (*pLocal)*sizeof(VBoxGLhandleARB)+sizeof(GLsizei));
140 crFree(pLocal);
141}
142
143AssertCompile(sizeof(GLsizei) == 4);
144
145void SERVER_DISPATCH_APIENTRY crServerDispatchGetInfoLogARB(VBoxGLhandleARB obj, GLsizei maxLength, GLsizei * length, GLcharARB * infoLog)
146{
147 RT_NOREF(length, infoLog);
148
149 GLsizei *pLocal = NULL;
150 GLuint hwid;
151
152 if (maxLength > 0 && maxLength < INT32_MAX / 2)
153 pLocal = (GLsizei*) crCalloc(maxLength + sizeof(GLsizei));
154
155 if (!pLocal)
156 {
157 GLsizei zero=0;
158 crServerReturnValue(&zero, sizeof(zero));
159 return;
160 }
161 /* initial (fallback )value */
162 *pLocal = 0;
163 /** @todo recheck*/
164 hwid = crStateGetProgramHWID(&cr_server.StateTracker, obj);
165 if (!hwid) hwid = crStateGetShaderHWID(&cr_server.StateTracker, obj);
166 cr_server.head_spu->dispatch_table.GetInfoLogARB(hwid, maxLength, pLocal, (char*)&pLocal[1]);
167 CRASSERT((*pLocal) <= maxLength);
168 crServerReturnValue(pLocal, (*pLocal)+sizeof(GLsizei));
169 crFree(pLocal);
170}
171
172void SERVER_DISPATCH_APIENTRY crServerDispatchGetShaderInfoLog(GLuint shader, GLsizei bufSize, GLsizei *length, char *infoLog)
173{
174 RT_NOREF(length, infoLog);
175
176 GLsizei *pLocal = NULL;
177
178 if (bufSize > 0 && bufSize < INT32_MAX / 2)
179 pLocal = (GLsizei*) crCalloc(bufSize + sizeof(GLsizei));
180
181 if (!pLocal)
182 {
183 GLsizei zero=0;
184 crServerReturnValue(&zero, sizeof(zero));
185 return;
186 }
187 /* initial (fallback )value */
188 *pLocal = 0;
189 cr_server.head_spu->dispatch_table.GetShaderInfoLog(crStateGetShaderHWID(&cr_server.StateTracker, shader), bufSize, pLocal, (char*)&pLocal[1]);
190 crServerReturnValue(pLocal, pLocal[0]+sizeof(GLsizei));
191 crFree(pLocal);
192}
193
194void SERVER_DISPATCH_APIENTRY crServerDispatchGetProgramInfoLog(GLuint program, GLsizei bufSize, GLsizei *length, char *infoLog)
195{
196 RT_NOREF(length, infoLog);
197
198 GLsizei *pLocal = NULL;
199
200 if (bufSize > 0 && bufSize < INT32_MAX / 2)
201 pLocal = (GLsizei*) crCalloc(bufSize + sizeof(GLsizei));
202
203 if (!pLocal)
204 {
205 GLsizei zero=0;
206 crServerReturnValue(&zero, sizeof(zero));
207 return;
208 }
209 /* initial (fallback )value */
210 *pLocal = 0;
211 cr_server.head_spu->dispatch_table.GetProgramInfoLog(crStateGetProgramHWID(&cr_server.StateTracker, program), bufSize, pLocal, (char*)&pLocal[1]);
212 CRASSERT(pLocal[0] <= bufSize);
213 crServerReturnValue(pLocal, pLocal[0]+sizeof(GLsizei));
214 crFree(pLocal);
215}
216
217void SERVER_DISPATCH_APIENTRY crServerDispatchGetShaderSource(GLuint shader, GLsizei bufSize, GLsizei *length, char *source)
218{
219 RT_NOREF(length, source);
220
221 GLsizei *pLocal = NULL;
222
223 if (bufSize > 0 && bufSize < INT32_MAX / 2)
224 pLocal = (GLsizei*) crCalloc(bufSize + sizeof(GLsizei));
225
226 if (!pLocal)
227 {
228 GLsizei zero=0;
229 crServerReturnValue(&zero, sizeof(zero));
230 return;
231 }
232 /* initial (fallback )value */
233 *pLocal = 0;
234 cr_server.head_spu->dispatch_table.GetShaderSource(crStateGetShaderHWID(&cr_server.StateTracker, shader), bufSize, pLocal, (char*)&pLocal[1]);
235 CRASSERT(pLocal[0] <= bufSize);
236 crServerReturnValue(pLocal, pLocal[0]+sizeof(GLsizei));
237 crFree(pLocal);
238}
239
240void SERVER_DISPATCH_APIENTRY
241crServerDispatchGetUniformsLocations(GLuint program, GLsizei maxcbData, GLsizei * cbData, GLvoid * pData)
242{
243 GLsizei *pLocal = NULL;
244
245 (void) cbData;
246 (void) pData;
247
248 if (maxcbData > 0 && maxcbData < INT32_MAX / 2)
249 pLocal = (GLsizei*) crCalloc(maxcbData + sizeof(GLsizei));
250
251 if (!pLocal)
252 {
253 GLsizei zero=0;
254 crServerReturnValue(&zero, sizeof(zero));
255 return;
256 }
257
258 /* initial (fallback )value */
259 *pLocal = 0;
260 crStateGLSLProgramCacheUniforms(&cr_server.StateTracker, program, maxcbData, pLocal, (char*)&pLocal[1]);
261
262 crServerReturnValue(pLocal, (*pLocal)+sizeof(GLsizei));
263 crFree(pLocal);
264}
265
266void SERVER_DISPATCH_APIENTRY
267crServerDispatchGetAttribsLocations(GLuint program, GLsizei maxcbData, GLsizei * cbData, GLvoid * pData)
268{
269 GLsizei *pLocal = NULL;
270
271 (void) cbData;
272 (void) pData;
273
274 if (maxcbData > 0 && maxcbData < INT32_MAX / 2)
275 pLocal = (GLsizei*) crCalloc(maxcbData + sizeof(GLsizei));
276
277 if (!pLocal)
278 {
279 GLsizei zero=0;
280 crServerReturnValue(&zero, sizeof(zero));
281 return;
282 }
283
284 /* initial (fallback )value */
285 *pLocal = 0;
286 crStateGLSLProgramCacheAttribs(&cr_server.StateTracker, program, maxcbData, pLocal, (char*)&pLocal[1]);
287
288 crServerReturnValue(pLocal, (*pLocal)+sizeof(GLsizei));
289 crFree(pLocal);
290}
291
292static GLint __GetUniformSize(GLuint program, GLint location)
293{
294 GLint size = 0;
295 GLenum type = 0;
296
297 /** @todo check if index and location is the same*/
298 cr_server.head_spu->dispatch_table.GetActiveUniform(crStateGetProgramHWID(&cr_server.StateTracker, program), location, 0, NULL, &size, &type, NULL);
299
300 return crStateGetUniformSize(&cr_server.StateTracker, type);
301}
302
303void SERVER_DISPATCH_APIENTRY crServerDispatchGetUniformfv(GLuint program, GLint location, GLfloat *params)
304{
305 RT_NOREF(params);
306
307 int size = __GetUniformSize(program, location) * sizeof(GLfloat);
308 GLfloat *pLocal;
309
310 pLocal = (GLfloat*) crCalloc(size);
311 if (!pLocal)
312 {
313 GLsizei zero=0;
314 crServerReturnValue(&zero, sizeof(zero));
315 return;
316 }
317
318 cr_server.head_spu->dispatch_table.GetUniformfv(crStateGetProgramHWID(&cr_server.StateTracker, program), location, pLocal);
319
320 crServerReturnValue(pLocal, size);
321 crFree(pLocal);
322}
323
324void SERVER_DISPATCH_APIENTRY crServerDispatchGetUniformiv(GLuint program, GLint location, GLint *params)
325{
326 RT_NOREF(params);
327
328 int size = __GetUniformSize(program, location) * sizeof(GLint);
329 GLint *pLocal;
330
331 pLocal = (GLint*) crCalloc(size);
332 if (!pLocal)
333 {
334 GLsizei zero=0;
335 crServerReturnValue(&zero, sizeof(zero));
336 return;
337 }
338
339 cr_server.head_spu->dispatch_table.GetUniformiv(crStateGetProgramHWID(&cr_server.StateTracker, program), location, pLocal);
340
341 crServerReturnValue(pLocal, size);
342 crFree(pLocal);
343}
344
345GLuint SERVER_DISPATCH_APIENTRY crServerDispatchCreateShader(GLenum type)
346{
347 GLuint retval, hwVal;
348 hwVal = cr_server.head_spu->dispatch_table.CreateShader(type);
349 retval = crStateCreateShader(&cr_server.StateTracker, hwVal, type);
350 crServerReturnValue(&retval, sizeof(retval));
351 return retval; /* ignored */
352}
353
354GLuint SERVER_DISPATCH_APIENTRY crServerDispatchCreateProgram(void)
355{
356 GLuint retval, hwVal;
357 hwVal = cr_server.head_spu->dispatch_table.CreateProgram();
358 retval = crStateCreateProgram(&cr_server.StateTracker, hwVal);
359 crServerReturnValue(&retval, sizeof(retval));
360 return retval; /* ignored */
361}
362
363GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsShader(GLuint shader)
364{
365 GLboolean retval;
366 retval = cr_server.head_spu->dispatch_table.IsShader(crStateGetShaderHWID(&cr_server.StateTracker, shader));
367 crServerReturnValue(&retval, sizeof(retval));
368 return retval; /* ignored */
369}
370
371GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsProgram(GLuint program)
372{
373 GLboolean retval;
374 retval = cr_server.head_spu->dispatch_table.IsProgram(crStateGetProgramHWID(&cr_server.StateTracker, program));
375 crServerReturnValue(&retval, sizeof(retval));
376 return retval; /* ignored */
377}
378
379void SERVER_DISPATCH_APIENTRY crServerDispatchGetObjectParameterfvARB( VBoxGLhandleARB obj, GLenum pname, GLfloat * params )
380{
381 GLfloat local_params[1] = {0};
382 GLuint hwid = crStateGetProgramHWID(&cr_server.StateTracker, obj);
383 (void) params;
384
385 if (!hwid)
386 {
387 hwid = crStateGetShaderHWID(&cr_server.StateTracker, obj);
388 if (!hwid)
389 {
390 crWarning("Unknown object %i, in crServerDispatchGetObjectParameterfvARB", obj);
391 }
392 }
393
394 cr_server.head_spu->dispatch_table.GetObjectParameterfvARB( hwid, pname, local_params );
395 crServerReturnValue( &(local_params[0]), 1*sizeof(GLfloat) );
396}
397
398void SERVER_DISPATCH_APIENTRY crServerDispatchGetObjectParameterivARB( VBoxGLhandleARB obj, GLenum pname, GLint * params )
399{
400 GLint local_params[1] = {0};
401 GLuint hwid = crStateGetProgramHWID(&cr_server.StateTracker, obj);
402 if (!hwid)
403 {
404 hwid = crStateGetShaderHWID(&cr_server.StateTracker, obj);
405 if (!hwid)
406 {
407 crWarning("Unknown object %i, in crServerDispatchGetObjectParameterivARB", obj);
408 }
409 }
410
411 (void) params;
412 cr_server.head_spu->dispatch_table.GetObjectParameterivARB( hwid, pname, local_params );
413 crServerReturnValue( &(local_params[0]), 1*sizeof(GLint) );
414}
415#endif /* #ifdef CR_OPENGL_VERSION_2_0 */
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