VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_getshaders.c@ 74579

Last change on this file since 74579 was 73223, checked in by vboxsync, 6 years ago

3D: texture unpacking reworked, bugref:9192. Merged r123597, r123598, r123600, r123601, r123755.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 11.9 KB
Line 
1/* $Id: server_getshaders.c 73223 2018-07-18 20:07:50Z vboxsync $ */
2/** @file
3 * VBox OpenGL GLSL related get functions
4 */
5
6/*
7 * Copyright (C) 2009-2017 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 crGetActive_t *pLocal = NULL;
40
41 if (bufSize < INT32_MAX / 2)
42 pLocal = (crGetActive_t*)crAlloc(bufSize + sizeof(crGetActive_t));
43
44 if (!pLocal)
45 {
46 crGetActive_t zero;
47 zero.length = 0;
48 crServerReturnValue(&zero, sizeof(zero));
49 return;
50 }
51 /* zero out just the header to ensure it initially contains zero size values */
52 memset(pLocal, 0, sizeof (*pLocal));
53 cr_server.head_spu->dispatch_table.GetActiveAttrib(crStateGetProgramHWID(program), index, bufSize, &pLocal->length, &pLocal->size, &pLocal->type, (char*)&pLocal[1]);
54 crServerReturnValue(pLocal, pLocal->length+1+sizeof(crGetActive_t));
55 crFree(pLocal);
56}
57
58void SERVER_DISPATCH_APIENTRY crServerDispatchGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, char *name)
59{
60 crGetActive_t *pLocal = NULL;
61
62 if (bufSize < INT32_MAX / 2)
63 pLocal = (crGetActive_t*) crAlloc(bufSize + sizeof(crGetActive_t));
64
65 if (!pLocal)
66 {
67 crGetActive_t zero;
68 zero.length = 0;
69 crServerReturnValue(&zero, sizeof(zero));
70 return;
71 }
72 /* zero out just the header to ensure it initially contains zero size values */
73 memset(pLocal, 0, sizeof (*pLocal));
74 cr_server.head_spu->dispatch_table.GetActiveUniform(crStateGetProgramHWID(program), index, bufSize, &pLocal->length, &pLocal->size, &pLocal->type, (char*)&pLocal[1]);
75 crServerReturnValue(pLocal, pLocal->length+1+sizeof(crGetActive_t));
76 crFree(pLocal);
77}
78
79void SERVER_DISPATCH_APIENTRY crServerDispatchGetAttachedShaders(GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders)
80{
81 GLsizei *pLocal = NULL;
82
83 if (maxCount < INT32_MAX / sizeof(GLuint) / 2)
84 pLocal = (GLsizei*) crAlloc(maxCount * sizeof(GLuint) + sizeof(GLsizei));
85
86 if (!pLocal)
87 {
88 GLsizei zero=0;
89 crServerReturnValue(&zero, sizeof(zero));
90 return;
91 }
92 /* initial (fallback )value */
93 *pLocal = 0;
94 cr_server.head_spu->dispatch_table.GetAttachedShaders(crStateGetProgramHWID(program), maxCount, pLocal, (GLuint*)&pLocal[1]);
95
96 {
97 GLsizei i;
98 GLuint *ids=(GLuint*)&pLocal[1];
99
100 for (i=0; i<*pLocal; ++i)
101 ids[i] = crStateGLSLShaderHWIDtoID(ids[i]);
102 }
103
104 crServerReturnValue(pLocal, (*pLocal)*sizeof(GLuint)+sizeof(GLsizei));
105 crFree(pLocal);
106}
107
108void SERVER_DISPATCH_APIENTRY crServerDispatchGetAttachedObjectsARB(VBoxGLhandleARB containerObj, GLsizei maxCount, GLsizei * count, VBoxGLhandleARB * obj)
109{
110 GLsizei *pLocal = NULL;
111
112 if (maxCount < INT32_MAX / sizeof(VBoxGLhandleARB) / 2)
113 pLocal = (GLsizei*) crAlloc(maxCount * sizeof(VBoxGLhandleARB) + sizeof(GLsizei));
114
115 if (!pLocal)
116 {
117 GLsizei zero=0;
118 crServerReturnValue(&zero, sizeof(zero));
119 return;
120 }
121 /* initial (fallback )value */
122 *pLocal = 0;
123 cr_server.head_spu->dispatch_table.GetAttachedObjectsARB(crStateGetProgramHWID(containerObj), maxCount, pLocal, (VBoxGLhandleARB*)&pLocal[1]);
124
125 {
126 GLsizei i;
127 GLuint *ids=(GLuint*)&pLocal[1];
128
129 for (i=0; i<*pLocal; ++i)
130 ids[i] = crStateGLSLShaderHWIDtoID(ids[i]);
131 }
132
133 crServerReturnValue(pLocal, (*pLocal)*sizeof(VBoxGLhandleARB)+sizeof(GLsizei));
134 crFree(pLocal);
135}
136
137AssertCompile(sizeof(GLsizei) == 4);
138
139void SERVER_DISPATCH_APIENTRY crServerDispatchGetInfoLogARB(VBoxGLhandleARB obj, GLsizei maxLength, GLsizei * length, GLcharARB * infoLog)
140{
141 GLsizei *pLocal = NULL;
142 GLuint hwid;
143
144 if (maxLength < INT32_MAX / 2)
145 pLocal = (GLsizei*) crAlloc(maxLength + sizeof(GLsizei));
146
147 if (!pLocal)
148 {
149 GLsizei zero=0;
150 crServerReturnValue(&zero, sizeof(zero));
151 return;
152 }
153 /* initial (fallback )value */
154 *pLocal = 0;
155 /** @todo recheck*/
156 hwid = crStateGetProgramHWID(obj);
157 if (!hwid) hwid = crStateGetShaderHWID(obj);
158 cr_server.head_spu->dispatch_table.GetInfoLogARB(hwid, maxLength, pLocal, (char*)&pLocal[1]);
159 CRASSERT((*pLocal) <= maxLength);
160 crServerReturnValue(pLocal, (*pLocal)+sizeof(GLsizei));
161 crFree(pLocal);
162}
163
164void SERVER_DISPATCH_APIENTRY crServerDispatchGetShaderInfoLog(GLuint shader, GLsizei bufSize, GLsizei *length, char *infoLog)
165{
166 GLsizei *pLocal = NULL;
167
168 if (bufSize < INT32_MAX / 2)
169 pLocal = (GLsizei*) crAlloc(bufSize + sizeof(GLsizei));
170
171 if (!pLocal)
172 {
173 GLsizei zero=0;
174 crServerReturnValue(&zero, sizeof(zero));
175 return;
176 }
177 /* initial (fallback )value */
178 *pLocal = 0;
179 cr_server.head_spu->dispatch_table.GetShaderInfoLog(crStateGetShaderHWID(shader), bufSize, pLocal, (char*)&pLocal[1]);
180 crServerReturnValue(pLocal, pLocal[0]+sizeof(GLsizei));
181 crFree(pLocal);
182}
183
184void SERVER_DISPATCH_APIENTRY crServerDispatchGetProgramInfoLog(GLuint program, GLsizei bufSize, GLsizei *length, char *infoLog)
185{
186 GLsizei *pLocal = NULL;
187
188 if (bufSize < INT32_MAX / 2)
189 pLocal = (GLsizei*) crAlloc(bufSize + sizeof(GLsizei));
190
191 if (!pLocal)
192 {
193 GLsizei zero=0;
194 crServerReturnValue(&zero, sizeof(zero));
195 return;
196 }
197 /* initial (fallback )value */
198 *pLocal = 0;
199 cr_server.head_spu->dispatch_table.GetProgramInfoLog(crStateGetProgramHWID(program), bufSize, pLocal, (char*)&pLocal[1]);
200 CRASSERT(pLocal[0] <= bufSize);
201 crServerReturnValue(pLocal, pLocal[0]+sizeof(GLsizei));
202 crFree(pLocal);
203}
204
205void SERVER_DISPATCH_APIENTRY crServerDispatchGetShaderSource(GLuint shader, GLsizei bufSize, GLsizei *length, char *source)
206{
207 GLsizei *pLocal = NULL;
208
209 if (bufSize < INT32_MAX / 2)
210 pLocal = (GLsizei*) crAlloc(bufSize + sizeof(GLsizei));
211
212 if (!pLocal)
213 {
214 GLsizei zero=0;
215 crServerReturnValue(&zero, sizeof(zero));
216 return;
217 }
218 /* initial (fallback )value */
219 *pLocal = 0;
220 cr_server.head_spu->dispatch_table.GetShaderSource(crStateGetShaderHWID(shader), bufSize, pLocal, (char*)&pLocal[1]);
221 CRASSERT(pLocal[0] <= bufSize);
222 crServerReturnValue(pLocal, pLocal[0]+sizeof(GLsizei));
223 crFree(pLocal);
224}
225
226void SERVER_DISPATCH_APIENTRY
227crServerDispatchGetUniformsLocations(GLuint program, GLsizei maxcbData, GLsizei * cbData, GLvoid * pData)
228{
229 GLsizei *pLocal = NULL;
230
231 (void) cbData;
232 (void) pData;
233
234 if (maxcbData < INT32_MAX / 2)
235 pLocal = (GLsizei*) crAlloc(maxcbData + sizeof(GLsizei));
236
237 if (!pLocal)
238 {
239 GLsizei zero=0;
240 crServerReturnValue(&zero, sizeof(zero));
241 return;
242 }
243
244 /* initial (fallback )value */
245 *pLocal = 0;
246 crStateGLSLProgramCacheUniforms(program, maxcbData, pLocal, (char*)&pLocal[1]);
247
248 crServerReturnValue(pLocal, (*pLocal)+sizeof(GLsizei));
249 crFree(pLocal);
250}
251
252void SERVER_DISPATCH_APIENTRY
253crServerDispatchGetAttribsLocations(GLuint program, GLsizei maxcbData, GLsizei * cbData, GLvoid * pData)
254{
255 GLsizei *pLocal = NULL;
256
257 (void) cbData;
258 (void) pData;
259
260 if (maxcbData < INT32_MAX / 2)
261 pLocal = (GLsizei*) crAlloc(maxcbData + sizeof(GLsizei));
262
263 if (!pLocal)
264 {
265 GLsizei zero=0;
266 crServerReturnValue(&zero, sizeof(zero));
267 return;
268 }
269
270 /* initial (fallback )value */
271 *pLocal = 0;
272 crStateGLSLProgramCacheAttribs(program, maxcbData, pLocal, (char*)&pLocal[1]);
273
274 crServerReturnValue(pLocal, (*pLocal)+sizeof(GLsizei));
275 crFree(pLocal);
276}
277
278static GLint __GetUniformSize(GLuint program, GLint location)
279{
280 GLint size = 0;
281 GLenum type = 0;
282
283 /** @todo check if index and location is the same*/
284 cr_server.head_spu->dispatch_table.GetActiveUniform(crStateGetProgramHWID(program), location, 0, NULL, &size, &type, NULL);
285
286 return crStateGetUniformSize(type);
287}
288
289void SERVER_DISPATCH_APIENTRY crServerDispatchGetUniformfv(GLuint program, GLint location, GLfloat *params)
290{
291 int size = __GetUniformSize(program, location) * sizeof(GLfloat);
292 GLfloat *pLocal;
293
294 pLocal = (GLfloat*) crAlloc(size);
295 if (!pLocal)
296 {
297 GLsizei zero=0;
298 crServerReturnValue(&zero, sizeof(zero));
299 return;
300 }
301
302 cr_server.head_spu->dispatch_table.GetUniformfv(crStateGetProgramHWID(program), location, pLocal);
303
304 crServerReturnValue(pLocal, size);
305 crFree(pLocal);
306}
307
308void SERVER_DISPATCH_APIENTRY crServerDispatchGetUniformiv(GLuint program, GLint location, GLint *params)
309{
310 int size = __GetUniformSize(program, location) * sizeof(GLint);
311 GLint *pLocal;
312
313 pLocal = (GLint*) crAlloc(size);
314 if (!pLocal)
315 {
316 GLsizei zero=0;
317 crServerReturnValue(&zero, sizeof(zero));
318 return;
319 }
320
321 cr_server.head_spu->dispatch_table.GetUniformiv(crStateGetProgramHWID(program), location, pLocal);
322
323 crServerReturnValue(pLocal, size);
324 crFree(pLocal);
325}
326
327GLuint SERVER_DISPATCH_APIENTRY crServerDispatchCreateShader(GLenum type)
328{
329 GLuint retval, hwVal;
330 hwVal = cr_server.head_spu->dispatch_table.CreateShader(type);
331 retval = crStateCreateShader(hwVal, type);
332 crServerReturnValue(&retval, sizeof(retval));
333 return retval; /* ignored */
334}
335
336GLuint SERVER_DISPATCH_APIENTRY crServerDispatchCreateProgram(void)
337{
338 GLuint retval, hwVal;
339 hwVal = cr_server.head_spu->dispatch_table.CreateProgram();
340 retval = crStateCreateProgram(hwVal);
341 crServerReturnValue(&retval, sizeof(retval));
342 return retval; /* ignored */
343}
344
345GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsShader(GLuint shader)
346{
347 GLboolean retval;
348 retval = cr_server.head_spu->dispatch_table.IsShader(crStateGetShaderHWID(shader));
349 crServerReturnValue(&retval, sizeof(retval));
350 return retval; /* ignored */
351}
352
353GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsProgram(GLuint program)
354{
355 GLboolean retval;
356 retval = cr_server.head_spu->dispatch_table.IsProgram(crStateGetProgramHWID(program));
357 crServerReturnValue(&retval, sizeof(retval));
358 return retval; /* ignored */
359}
360
361void SERVER_DISPATCH_APIENTRY crServerDispatchGetObjectParameterfvARB( VBoxGLhandleARB obj, GLenum pname, GLfloat * params )
362{
363 GLfloat local_params[1];
364 GLuint hwid = crStateGetProgramHWID(obj);
365 (void) params;
366
367 if (!hwid)
368 {
369 hwid = crStateGetShaderHWID(obj);
370 if (!hwid)
371 {
372 crWarning("Unknown object %i, in crServerDispatchGetObjectParameterfvARB", obj);
373 }
374 }
375
376 cr_server.head_spu->dispatch_table.GetObjectParameterfvARB( hwid, pname, local_params );
377 crServerReturnValue( &(local_params[0]), 1*sizeof(GLfloat) );
378}
379
380void SERVER_DISPATCH_APIENTRY crServerDispatchGetObjectParameterivARB( VBoxGLhandleARB obj, GLenum pname, GLint * params )
381{
382 GLint local_params[1];
383 GLuint hwid = crStateGetProgramHWID(obj);
384 if (!hwid)
385 {
386 hwid = crStateGetShaderHWID(obj);
387 if (!hwid)
388 {
389 crWarning("Unknown object %i, in crServerDispatchGetObjectParameterivARB", obj);
390 }
391 }
392
393 (void) params;
394 cr_server.head_spu->dispatch_table.GetObjectParameterivARB( hwid, pname, local_params );
395 crServerReturnValue( &(local_params[0]), 1*sizeof(GLint) );
396}
397#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