1 | /* $Id: server_getshaders.c 20147 2009-05-29 11:21:57Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox OpenGL DRI driver functions
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2009 Sun Microsystems, Inc.
|
---|
9 | *
|
---|
10 | * Sun Microsystems, Inc. confidential
|
---|
11 | * All rights reserved
|
---|
12 | */
|
---|
13 |
|
---|
14 | #include "cr_spu.h"
|
---|
15 | #include "chromium.h"
|
---|
16 | #include "cr_error.h"
|
---|
17 | #include "cr_mem.h"
|
---|
18 | #include "cr_net.h"
|
---|
19 | #include "server_dispatch.h"
|
---|
20 | #include "server.h"
|
---|
21 |
|
---|
22 | #ifdef CR_OPENGL_VERSION_2_0
|
---|
23 |
|
---|
24 | typedef struct _crGetActive_t
|
---|
25 | {
|
---|
26 | GLsizei length;
|
---|
27 | GLint size;
|
---|
28 | GLenum type;
|
---|
29 | } crGetActive_t;
|
---|
30 |
|
---|
31 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetActiveAttrib(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, char *name)
|
---|
32 | {
|
---|
33 | crGetActive_t *pLocal;
|
---|
34 |
|
---|
35 | pLocal = (crGetActive_t*) crAlloc(bufSize+sizeof(crGetActive_t));
|
---|
36 | if (!pLocal)
|
---|
37 | {
|
---|
38 | crGetActive_t zero;
|
---|
39 | zero.length = 0;
|
---|
40 | crServerReturnValue(&zero, sizeof(zero));
|
---|
41 | }
|
---|
42 | cr_server.head_spu->dispatch_table.GetActiveAttrib(program, index, bufSize, &pLocal->length, &pLocal->size, &pLocal->type, (char*)&pLocal[1]);
|
---|
43 | crServerReturnValue(pLocal, pLocal->length+1+sizeof(crGetActive_t));
|
---|
44 | crFree(pLocal);
|
---|
45 | }
|
---|
46 |
|
---|
47 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, char *name)
|
---|
48 | {
|
---|
49 | crGetActive_t *pLocal;
|
---|
50 |
|
---|
51 | pLocal = (crGetActive_t*) crAlloc(bufSize+sizeof(crGetActive_t));
|
---|
52 | if (!pLocal)
|
---|
53 | {
|
---|
54 | crGetActive_t zero;
|
---|
55 | zero.length = 0;
|
---|
56 | crServerReturnValue(&zero, sizeof(zero));
|
---|
57 | }
|
---|
58 | cr_server.head_spu->dispatch_table.GetActiveUniform(program, index, bufSize, &pLocal->length, &pLocal->size, &pLocal->type, (char*)&pLocal[1]);
|
---|
59 | crServerReturnValue(pLocal, pLocal->length+1+sizeof(crGetActive_t));
|
---|
60 | crFree(pLocal);
|
---|
61 | }
|
---|
62 |
|
---|
63 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetAttachedShaders(GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders)
|
---|
64 | {
|
---|
65 | GLsizei *pLocal;
|
---|
66 |
|
---|
67 | pLocal = (GLsizei*) crAlloc(maxCount*sizeof(GLuint)+sizeof(GLsizei));
|
---|
68 | if (!pLocal)
|
---|
69 | {
|
---|
70 | GLsizei zero=0;
|
---|
71 | crServerReturnValue(&zero, sizeof(zero));
|
---|
72 | }
|
---|
73 | cr_server.head_spu->dispatch_table.GetAttachedShaders(program, maxCount, pLocal, (GLuint*)&pLocal[1]);
|
---|
74 | crServerReturnValue(pLocal, (*pLocal)*sizeof(GLuint)+sizeof(GLsizei));
|
---|
75 | crFree(pLocal);
|
---|
76 | }
|
---|
77 |
|
---|
78 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetShaderInfoLog(GLuint shader, GLsizei bufSize, GLsizei *length, char *infoLog)
|
---|
79 | {
|
---|
80 | GLsizei *pLocal;
|
---|
81 |
|
---|
82 | pLocal = (GLsizei*) crAlloc(bufSize+sizeof(GLsizei));
|
---|
83 | if (!pLocal)
|
---|
84 | {
|
---|
85 | GLsizei zero=0;
|
---|
86 | crServerReturnValue(&zero, sizeof(zero));
|
---|
87 | }
|
---|
88 | cr_server.head_spu->dispatch_table.GetShaderInfoLog(shader, bufSize, pLocal, (char*)&pLocal[1]);
|
---|
89 | crServerReturnValue(pLocal, (*pLocal)+1+sizeof(GLsizei));
|
---|
90 | crFree(pLocal);
|
---|
91 | }
|
---|
92 |
|
---|
93 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetProgramInfoLog(GLuint program, GLsizei bufSize, GLsizei *length, char *infoLog)
|
---|
94 | {
|
---|
95 | GLsizei *pLocal;
|
---|
96 |
|
---|
97 | pLocal = (GLsizei*) crAlloc(bufSize+sizeof(GLsizei));
|
---|
98 | if (!pLocal)
|
---|
99 | {
|
---|
100 | GLsizei zero=0;
|
---|
101 | crServerReturnValue(&zero, sizeof(zero));
|
---|
102 | }
|
---|
103 | cr_server.head_spu->dispatch_table.GetProgramInfoLog(program, bufSize, pLocal, (char*)&pLocal[1]);
|
---|
104 | crServerReturnValue(pLocal, (*pLocal)+1+sizeof(GLsizei));
|
---|
105 | crFree(pLocal);
|
---|
106 | }
|
---|
107 |
|
---|
108 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetShaderSource(GLuint shader, GLsizei bufSize, GLsizei *length, char *source)
|
---|
109 | {
|
---|
110 | GLsizei *pLocal;
|
---|
111 |
|
---|
112 | pLocal = (GLsizei*) crAlloc(bufSize+sizeof(GLsizei));
|
---|
113 | if (!pLocal)
|
---|
114 | {
|
---|
115 | GLsizei zero=0;
|
---|
116 | crServerReturnValue(&zero, sizeof(zero));
|
---|
117 | }
|
---|
118 | cr_server.head_spu->dispatch_table.GetShaderSource(shader, bufSize, pLocal, (char*)pLocal+1);
|
---|
119 | crServerReturnValue(pLocal, (*pLocal)+1+sizeof(GLsizei));
|
---|
120 | crFree(pLocal);
|
---|
121 | }
|
---|
122 |
|
---|
123 | static GLint __GetUniformSize(GLuint program, GLint location)
|
---|
124 | {
|
---|
125 | GLint size;
|
---|
126 | GLenum type;
|
---|
127 |
|
---|
128 | /*@todo: check if index and location is the same*/
|
---|
129 | cr_server.head_spu->dispatch_table.GetActiveUniform(program, location, 0, NULL, &size, &type, NULL);
|
---|
130 |
|
---|
131 | switch (type)
|
---|
132 | {
|
---|
133 | case GL_FLOAT:
|
---|
134 | size = 1;
|
---|
135 | break;
|
---|
136 | case GL_FLOAT_VEC2:
|
---|
137 | size = 2;
|
---|
138 | break;
|
---|
139 | case GL_FLOAT_VEC3:
|
---|
140 | size = 3;
|
---|
141 | break;
|
---|
142 | case GL_FLOAT_VEC4:
|
---|
143 | size = 4;
|
---|
144 | break;
|
---|
145 | case GL_INT:
|
---|
146 | size = 1;
|
---|
147 | break;
|
---|
148 | case GL_INT_VEC2:
|
---|
149 | size = 2;
|
---|
150 | break;
|
---|
151 | case GL_INT_VEC3:
|
---|
152 | size = 3;
|
---|
153 | break;
|
---|
154 | case GL_INT_VEC4:
|
---|
155 | size = 4;
|
---|
156 | break;
|
---|
157 | case GL_BOOL:
|
---|
158 | size = 1;
|
---|
159 | break;
|
---|
160 | case GL_BOOL_VEC2:
|
---|
161 | size = 2;
|
---|
162 | break;
|
---|
163 | case GL_BOOL_VEC3:
|
---|
164 | size = 3;
|
---|
165 | break;
|
---|
166 | case GL_BOOL_VEC4:
|
---|
167 | size = 4;
|
---|
168 | break;
|
---|
169 | case GL_FLOAT_MAT2:
|
---|
170 | size = 8;
|
---|
171 | break;
|
---|
172 | case GL_FLOAT_MAT3:
|
---|
173 | size = 12;
|
---|
174 | break;
|
---|
175 | case GL_FLOAT_MAT4:
|
---|
176 | size = 16;
|
---|
177 | break;
|
---|
178 | case GL_SAMPLER_1D:
|
---|
179 | case GL_SAMPLER_2D:
|
---|
180 | case GL_SAMPLER_3D:
|
---|
181 | case GL_SAMPLER_CUBE:
|
---|
182 | case GL_SAMPLER_1D_SHADOW:
|
---|
183 | case GL_SAMPLER_2D_SHADOW:
|
---|
184 | size = 1;
|
---|
185 | break;
|
---|
186 | #ifdef CR_OPENGL_VERSION_2_1
|
---|
187 | case GL_FLOAT_MAT2x3:
|
---|
188 | size = 8;
|
---|
189 | break;
|
---|
190 | case GL_FLOAT_MAT2x4:
|
---|
191 | size = 8;
|
---|
192 | break;
|
---|
193 | case GL_FLOAT_MAT3x2:
|
---|
194 | size = 12;
|
---|
195 | break;
|
---|
196 | case GL_FLOAT_MAT3x4:
|
---|
197 | size = 12;
|
---|
198 | break;
|
---|
199 | case GL_FLOAT_MAT4x2:
|
---|
200 | size = 16;
|
---|
201 | break;
|
---|
202 | case GL_FLOAT_MAT4x3:
|
---|
203 | size = 16;
|
---|
204 | break;
|
---|
205 | #endif
|
---|
206 | default:
|
---|
207 | crWarning("__GetUniformSize: unknown uniform type 0x%x", (GLint)type);
|
---|
208 | size = 16;
|
---|
209 | break;
|
---|
210 | }
|
---|
211 |
|
---|
212 | return size;
|
---|
213 | }
|
---|
214 |
|
---|
215 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetUniformfv(GLuint program, GLint location, GLfloat *params)
|
---|
216 | {
|
---|
217 | int size = __GetUniformSize(program, location) * sizeof(GLfloat);
|
---|
218 | GLfloat *pLocal;
|
---|
219 |
|
---|
220 | pLocal = (GLfloat*) crAlloc(size);
|
---|
221 | if (!pLocal)
|
---|
222 | {
|
---|
223 | GLsizei zero=0;
|
---|
224 | crServerReturnValue(&zero, sizeof(zero));
|
---|
225 | }
|
---|
226 |
|
---|
227 | cr_server.head_spu->dispatch_table.GetUniformfv(program, location, pLocal);
|
---|
228 |
|
---|
229 | crServerReturnValue(pLocal, size);
|
---|
230 | crFree(pLocal);
|
---|
231 | }
|
---|
232 |
|
---|
233 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetUniformiv(GLuint program, GLint location, GLint *params)
|
---|
234 | {
|
---|
235 | int size = __GetUniformSize(program, location) * sizeof(GLint);
|
---|
236 | GLint *pLocal;
|
---|
237 |
|
---|
238 | pLocal = (GLint*) crAlloc(size);
|
---|
239 | if (!pLocal)
|
---|
240 | {
|
---|
241 | GLsizei zero=0;
|
---|
242 | crServerReturnValue(&zero, sizeof(zero));
|
---|
243 | }
|
---|
244 |
|
---|
245 | cr_server.head_spu->dispatch_table.GetUniformiv(program, location, pLocal);
|
---|
246 |
|
---|
247 | crServerReturnValue(pLocal, size);
|
---|
248 | crFree(pLocal);
|
---|
249 | }
|
---|
250 |
|
---|
251 | #endif /* #ifdef CR_OPENGL_VERSION_2_0 */
|
---|