1 | /* $Id: server_getshaders.c 43051 2012-08-28 15:35:26Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox OpenGL GLSL related get functions
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2009 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 |
|
---|
31 | typedef struct _crGetActive_t
|
---|
32 | {
|
---|
33 | GLsizei length;
|
---|
34 | GLint size;
|
---|
35 | GLenum type;
|
---|
36 | } crGetActive_t;
|
---|
37 |
|
---|
38 | void 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 | cr_server.head_spu->dispatch_table.GetActiveAttrib(crStateGetProgramHWID(program), index, bufSize, &pLocal->length, &pLocal->size, &pLocal->type, (char*)&pLocal[1]);
|
---|
50 | crServerReturnValue(pLocal, pLocal->length+1+sizeof(crGetActive_t));
|
---|
51 | crFree(pLocal);
|
---|
52 | }
|
---|
53 |
|
---|
54 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, char *name)
|
---|
55 | {
|
---|
56 | crGetActive_t *pLocal;
|
---|
57 |
|
---|
58 | pLocal = (crGetActive_t*) crAlloc(bufSize+sizeof(crGetActive_t));
|
---|
59 | if (!pLocal)
|
---|
60 | {
|
---|
61 | crGetActive_t zero;
|
---|
62 | zero.length = 0;
|
---|
63 | crServerReturnValue(&zero, sizeof(zero));
|
---|
64 | }
|
---|
65 | cr_server.head_spu->dispatch_table.GetActiveUniform(crStateGetProgramHWID(program), index, bufSize, &pLocal->length, &pLocal->size, &pLocal->type, (char*)&pLocal[1]);
|
---|
66 | crServerReturnValue(pLocal, pLocal->length+1+sizeof(crGetActive_t));
|
---|
67 | crFree(pLocal);
|
---|
68 | }
|
---|
69 |
|
---|
70 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetAttachedShaders(GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders)
|
---|
71 | {
|
---|
72 | GLsizei *pLocal;
|
---|
73 |
|
---|
74 | pLocal = (GLsizei*) crAlloc(maxCount*sizeof(GLuint)+sizeof(GLsizei));
|
---|
75 | if (!pLocal)
|
---|
76 | {
|
---|
77 | GLsizei zero=0;
|
---|
78 | crServerReturnValue(&zero, sizeof(zero));
|
---|
79 | }
|
---|
80 | cr_server.head_spu->dispatch_table.GetAttachedShaders(crStateGetProgramHWID(program), maxCount, pLocal, (GLuint*)&pLocal[1]);
|
---|
81 |
|
---|
82 | {
|
---|
83 | GLsizei i;
|
---|
84 | GLuint *ids=(GLuint*)&pLocal[1];
|
---|
85 |
|
---|
86 | for (i=0; i<*pLocal; ++i);
|
---|
87 | ids[i] = crStateGLSLShaderHWIDtoID(ids[i]);
|
---|
88 | }
|
---|
89 |
|
---|
90 | crServerReturnValue(pLocal, (*pLocal)*sizeof(GLuint)+sizeof(GLsizei));
|
---|
91 | crFree(pLocal);
|
---|
92 | }
|
---|
93 |
|
---|
94 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetAttachedObjectsARB(GLhandleARB containerObj, GLsizei maxCount, GLsizei * count, GLhandleARB * obj)
|
---|
95 | {
|
---|
96 | GLsizei *pLocal;
|
---|
97 |
|
---|
98 | pLocal = (GLsizei*) crAlloc(maxCount*sizeof(GLhandleARB)+sizeof(GLsizei));
|
---|
99 | if (!pLocal)
|
---|
100 | {
|
---|
101 | GLsizei zero=0;
|
---|
102 | crServerReturnValue(&zero, sizeof(zero));
|
---|
103 | }
|
---|
104 | cr_server.head_spu->dispatch_table.GetAttachedObjectsARB(crStateGetProgramHWID(containerObj), maxCount, pLocal, (GLhandleARB*)&pLocal[1]);
|
---|
105 |
|
---|
106 | {
|
---|
107 | GLsizei i;
|
---|
108 | GLuint *ids=(GLuint*)&pLocal[1];
|
---|
109 |
|
---|
110 | for (i=0; i<*pLocal; ++i)
|
---|
111 | ids[i] = crStateGLSLShaderHWIDtoID(ids[i]);
|
---|
112 | }
|
---|
113 |
|
---|
114 | crServerReturnValue(pLocal, (*pLocal)*sizeof(GLhandleARB)+sizeof(GLsizei));
|
---|
115 | crFree(pLocal);
|
---|
116 | }
|
---|
117 |
|
---|
118 | AssertCompile(sizeof(GLsizei) == 4);
|
---|
119 |
|
---|
120 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetInfoLogARB(GLhandleARB obj, GLsizei maxLength, GLsizei * length, GLcharARB * infoLog)
|
---|
121 | {
|
---|
122 | GLsizei *pLocal;
|
---|
123 | GLuint hwid;
|
---|
124 |
|
---|
125 | pLocal = (GLsizei*) crAlloc(maxLength+sizeof(GLsizei));
|
---|
126 | if (!pLocal)
|
---|
127 | {
|
---|
128 | GLsizei zero=0;
|
---|
129 | crServerReturnValue(&zero, sizeof(zero));
|
---|
130 | }
|
---|
131 | /*@todo: recheck*/
|
---|
132 | hwid = crStateGetProgramHWID(obj);
|
---|
133 | if (!hwid) hwid = crStateGetShaderHWID(obj);
|
---|
134 | cr_server.head_spu->dispatch_table.GetInfoLogARB(hwid, maxLength, pLocal, (char*)&pLocal[1]);
|
---|
135 | CRASSERT((*pLocal) <= maxLength);
|
---|
136 | crServerReturnValue(pLocal, (*pLocal)+sizeof(GLsizei));
|
---|
137 | crFree(pLocal);
|
---|
138 | }
|
---|
139 |
|
---|
140 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetShaderInfoLog(GLuint shader, GLsizei bufSize, GLsizei *length, char *infoLog)
|
---|
141 | {
|
---|
142 | GLsizei *pLocal;
|
---|
143 |
|
---|
144 | pLocal = (GLsizei*) crAlloc(bufSize+sizeof(GLsizei));
|
---|
145 | if (!pLocal)
|
---|
146 | {
|
---|
147 | GLsizei zero=0;
|
---|
148 | crServerReturnValue(&zero, sizeof(zero));
|
---|
149 | }
|
---|
150 | cr_server.head_spu->dispatch_table.GetShaderInfoLog(crStateGetShaderHWID(shader), bufSize, pLocal, (char*)&pLocal[1]);
|
---|
151 | crServerReturnValue(pLocal, pLocal[0]+sizeof(GLsizei));
|
---|
152 | crFree(pLocal);
|
---|
153 | }
|
---|
154 |
|
---|
155 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetProgramInfoLog(GLuint program, GLsizei bufSize, GLsizei *length, char *infoLog)
|
---|
156 | {
|
---|
157 | GLsizei *pLocal;
|
---|
158 |
|
---|
159 | pLocal = (GLsizei*) crAlloc(bufSize+sizeof(GLsizei));
|
---|
160 | if (!pLocal)
|
---|
161 | {
|
---|
162 | GLsizei zero=0;
|
---|
163 | crServerReturnValue(&zero, sizeof(zero));
|
---|
164 | }
|
---|
165 | cr_server.head_spu->dispatch_table.GetProgramInfoLog(crStateGetProgramHWID(program), bufSize, pLocal, (char*)&pLocal[1]);
|
---|
166 | CRASSERT(pLocal[0] <= bufSize);
|
---|
167 | crServerReturnValue(pLocal, pLocal[0]+sizeof(GLsizei));
|
---|
168 | crFree(pLocal);
|
---|
169 | }
|
---|
170 |
|
---|
171 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetShaderSource(GLuint shader, GLsizei bufSize, GLsizei *length, char *source)
|
---|
172 | {
|
---|
173 | GLsizei *pLocal;
|
---|
174 |
|
---|
175 | pLocal = (GLsizei*) crAlloc(bufSize+sizeof(GLsizei));
|
---|
176 | if (!pLocal)
|
---|
177 | {
|
---|
178 | GLsizei zero=0;
|
---|
179 | crServerReturnValue(&zero, sizeof(zero));
|
---|
180 | }
|
---|
181 | cr_server.head_spu->dispatch_table.GetShaderSource(crStateGetShaderHWID(shader), bufSize, pLocal, (char*)&pLocal[1]);
|
---|
182 | CRASSERT(pLocal[0] <= bufSize);
|
---|
183 | crServerReturnValue(pLocal, pLocal[0]+sizeof(GLsizei));
|
---|
184 | crFree(pLocal);
|
---|
185 | }
|
---|
186 |
|
---|
187 | void SERVER_DISPATCH_APIENTRY
|
---|
188 | crServerDispatchGetUniformsLocations(GLuint program, GLsizei maxcbData, GLsizei * cbData, GLvoid * pData)
|
---|
189 | {
|
---|
190 | GLsizei *pLocal;
|
---|
191 |
|
---|
192 | (void) cbData;
|
---|
193 | (void) pData;
|
---|
194 |
|
---|
195 | pLocal = (GLsizei*) crAlloc(maxcbData+sizeof(GLsizei));
|
---|
196 | if (!pLocal)
|
---|
197 | {
|
---|
198 | GLsizei zero=0;
|
---|
199 | crServerReturnValue(&zero, sizeof(zero));
|
---|
200 | }
|
---|
201 |
|
---|
202 | crStateGLSLProgramCacheUniforms(program, maxcbData, pLocal, (char*)&pLocal[1]);
|
---|
203 |
|
---|
204 | crServerReturnValue(pLocal, (*pLocal)+sizeof(GLsizei));
|
---|
205 | crFree(pLocal);
|
---|
206 | }
|
---|
207 |
|
---|
208 | static GLint __GetUniformSize(GLuint program, GLint location)
|
---|
209 | {
|
---|
210 | GLint size;
|
---|
211 | GLenum type;
|
---|
212 |
|
---|
213 | /*@todo: check if index and location is the same*/
|
---|
214 | cr_server.head_spu->dispatch_table.GetActiveUniform(crStateGetProgramHWID(program), location, 0, NULL, &size, &type, NULL);
|
---|
215 |
|
---|
216 | return crStateGetUniformSize(type);
|
---|
217 | }
|
---|
218 |
|
---|
219 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetUniformfv(GLuint program, GLint location, GLfloat *params)
|
---|
220 | {
|
---|
221 | int size = __GetUniformSize(program, location) * sizeof(GLfloat);
|
---|
222 | GLfloat *pLocal;
|
---|
223 |
|
---|
224 | pLocal = (GLfloat*) crAlloc(size);
|
---|
225 | if (!pLocal)
|
---|
226 | {
|
---|
227 | GLsizei zero=0;
|
---|
228 | crServerReturnValue(&zero, sizeof(zero));
|
---|
229 | }
|
---|
230 |
|
---|
231 | cr_server.head_spu->dispatch_table.GetUniformfv(crStateGetProgramHWID(program), location, pLocal);
|
---|
232 |
|
---|
233 | crServerReturnValue(pLocal, size);
|
---|
234 | crFree(pLocal);
|
---|
235 | }
|
---|
236 |
|
---|
237 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetUniformiv(GLuint program, GLint location, GLint *params)
|
---|
238 | {
|
---|
239 | int size = __GetUniformSize(program, location) * sizeof(GLint);
|
---|
240 | GLint *pLocal;
|
---|
241 |
|
---|
242 | pLocal = (GLint*) crAlloc(size);
|
---|
243 | if (!pLocal)
|
---|
244 | {
|
---|
245 | GLsizei zero=0;
|
---|
246 | crServerReturnValue(&zero, sizeof(zero));
|
---|
247 | }
|
---|
248 |
|
---|
249 | cr_server.head_spu->dispatch_table.GetUniformiv(crStateGetProgramHWID(program), location, pLocal);
|
---|
250 |
|
---|
251 | crServerReturnValue(pLocal, size);
|
---|
252 | crFree(pLocal);
|
---|
253 | }
|
---|
254 |
|
---|
255 | GLuint SERVER_DISPATCH_APIENTRY crServerDispatchCreateShader(GLenum type)
|
---|
256 | {
|
---|
257 | GLuint retval, hwVal;
|
---|
258 | hwVal = cr_server.head_spu->dispatch_table.CreateShader(type);
|
---|
259 | retval = crStateCreateShader(hwVal, type);
|
---|
260 | crServerReturnValue(&retval, sizeof(retval));
|
---|
261 | return retval; /* ignored */
|
---|
262 | }
|
---|
263 |
|
---|
264 | GLuint SERVER_DISPATCH_APIENTRY crServerDispatchCreateProgram(void)
|
---|
265 | {
|
---|
266 | GLuint retval, hwVal;
|
---|
267 | hwVal = cr_server.head_spu->dispatch_table.CreateProgram();
|
---|
268 | retval = crStateCreateProgram(hwVal);
|
---|
269 | crServerReturnValue(&retval, sizeof(retval));
|
---|
270 | return retval; /* ignored */
|
---|
271 | }
|
---|
272 |
|
---|
273 | GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsShader(GLuint shader)
|
---|
274 | {
|
---|
275 | GLboolean retval;
|
---|
276 | retval = cr_server.head_spu->dispatch_table.IsShader(crStateGetShaderHWID(shader));
|
---|
277 | crServerReturnValue(&retval, sizeof(retval));
|
---|
278 | return retval; /* ignored */
|
---|
279 | }
|
---|
280 |
|
---|
281 | GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsProgram(GLuint program)
|
---|
282 | {
|
---|
283 | GLboolean retval;
|
---|
284 | retval = cr_server.head_spu->dispatch_table.IsProgram(crStateGetProgramHWID(program));
|
---|
285 | crServerReturnValue(&retval, sizeof(retval));
|
---|
286 | return retval; /* ignored */
|
---|
287 | }
|
---|
288 |
|
---|
289 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetObjectParameterfvARB( GLhandleARB obj, GLenum pname, GLfloat * params )
|
---|
290 | {
|
---|
291 | GLfloat local_params[1];
|
---|
292 | GLuint hwid = crStateGetProgramHWID(obj);
|
---|
293 | (void) params;
|
---|
294 |
|
---|
295 | if (!hwid)
|
---|
296 | {
|
---|
297 | hwid = crStateGetShaderHWID(obj);
|
---|
298 | if (!hwid)
|
---|
299 | {
|
---|
300 | crWarning("Unknown object %i, in crServerDispatchGetObjectParameterfvARB", obj);
|
---|
301 | }
|
---|
302 | }
|
---|
303 |
|
---|
304 | cr_server.head_spu->dispatch_table.GetObjectParameterfvARB( hwid, pname, local_params );
|
---|
305 | crServerReturnValue( &(local_params[0]), 1*sizeof(GLfloat) );
|
---|
306 | }
|
---|
307 |
|
---|
308 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetObjectParameterivARB( GLhandleARB obj, GLenum pname, GLint * params )
|
---|
309 | {
|
---|
310 | GLint local_params[1];
|
---|
311 | GLuint hwid = crStateGetProgramHWID(obj);
|
---|
312 | if (!hwid)
|
---|
313 | {
|
---|
314 | hwid = crStateGetShaderHWID(obj);
|
---|
315 | if (!hwid)
|
---|
316 | {
|
---|
317 | crWarning("Unknown object %i, in crServerDispatchGetObjectParameterivARB", obj);
|
---|
318 | }
|
---|
319 | }
|
---|
320 |
|
---|
321 | (void) params;
|
---|
322 | cr_server.head_spu->dispatch_table.GetObjectParameterivARB( hwid, pname, local_params );
|
---|
323 | crServerReturnValue( &(local_params[0]), 1*sizeof(GLint) );
|
---|
324 | }
|
---|
325 | #endif /* #ifdef CR_OPENGL_VERSION_2_0 */
|
---|