VirtualBox

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

Last change on this file since 48521 was 47075, checked in by vboxsync, 11 years ago

crOpenGL: fix shader info getters

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