1 | /* $Id: server_glsl.c 55014 2015-03-30 17:35:12Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox OpenGL: GLSL related 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 | #ifdef CR_OPENGL_VERSION_2_0
|
---|
28 |
|
---|
29 | void SERVER_DISPATCH_APIENTRY crServerDispatchShaderSource(GLuint shader, GLsizei count, const char ** string, const GLint * length)
|
---|
30 | {
|
---|
31 | /*@todo?crStateShaderSource(shader...);*/
|
---|
32 | #ifdef DEBUG_misha
|
---|
33 | GLenum err = cr_server.head_spu->dispatch_table.GetError();
|
---|
34 | #endif
|
---|
35 | cr_server.head_spu->dispatch_table.ShaderSource(crStateGetShaderHWID(shader), count, string, length);
|
---|
36 | #ifdef DEBUG_misha
|
---|
37 | err = cr_server.head_spu->dispatch_table.GetError();
|
---|
38 | CRASSERT(err == GL_NO_ERROR);
|
---|
39 | #endif
|
---|
40 | CR_SERVER_DUMP_SHADER_SOURCE(shader);
|
---|
41 | }
|
---|
42 |
|
---|
43 | void SERVER_DISPATCH_APIENTRY crServerDispatchCompileShader(GLuint shader)
|
---|
44 | {
|
---|
45 | #ifdef DEBUG_misha
|
---|
46 | GLint iCompileStatus = GL_FALSE;
|
---|
47 | #endif
|
---|
48 | crStateCompileShader(shader);
|
---|
49 | cr_server.head_spu->dispatch_table.CompileShader(crStateGetShaderHWID(shader));
|
---|
50 | #ifdef DEBUG_misha
|
---|
51 | cr_server.head_spu->dispatch_table.GetShaderiv(crStateGetShaderHWID(shader), GL_COMPILE_STATUS, &iCompileStatus);
|
---|
52 | Assert(iCompileStatus == GL_TRUE);
|
---|
53 | #endif
|
---|
54 | CR_SERVER_DUMP_COMPILE_SHADER(shader);
|
---|
55 | }
|
---|
56 |
|
---|
57 | void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteShader(GLuint shader)
|
---|
58 | {
|
---|
59 | GLuint shaderHW = crStateGetShaderHWID(shader);
|
---|
60 | crStateDeleteShader(shader);
|
---|
61 | if (shaderHW)
|
---|
62 | cr_server.head_spu->dispatch_table.DeleteShader(shaderHW);
|
---|
63 | else
|
---|
64 | crWarning("crServerDispatchDeleteShader: hwid not found for shader(%d)", shader);
|
---|
65 | }
|
---|
66 |
|
---|
67 | void SERVER_DISPATCH_APIENTRY crServerDispatchAttachShader(GLuint program, GLuint shader)
|
---|
68 | {
|
---|
69 | crStateAttachShader(program, shader);
|
---|
70 | cr_server.head_spu->dispatch_table.AttachShader(crStateGetProgramHWID(program), crStateGetShaderHWID(shader));
|
---|
71 | }
|
---|
72 |
|
---|
73 | void SERVER_DISPATCH_APIENTRY crServerDispatchDetachShader(GLuint program, GLuint shader)
|
---|
74 | {
|
---|
75 | crStateDetachShader(program, shader);
|
---|
76 | cr_server.head_spu->dispatch_table.DetachShader(crStateGetProgramHWID(program), crStateGetShaderHWID(shader));
|
---|
77 | }
|
---|
78 |
|
---|
79 | void SERVER_DISPATCH_APIENTRY crServerDispatchLinkProgram(GLuint program)
|
---|
80 | {
|
---|
81 | crStateLinkProgram(program);
|
---|
82 | cr_server.head_spu->dispatch_table.LinkProgram(crStateGetProgramHWID(program));
|
---|
83 | CR_SERVER_DUMP_LINK_PROGRAM(program);
|
---|
84 | }
|
---|
85 |
|
---|
86 | void SERVER_DISPATCH_APIENTRY crServerDispatchUseProgram(GLuint program)
|
---|
87 | {
|
---|
88 | crStateUseProgram(program);
|
---|
89 | cr_server.head_spu->dispatch_table.UseProgram(crStateGetProgramHWID(program));
|
---|
90 | }
|
---|
91 |
|
---|
92 | void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteProgram(GLuint program)
|
---|
93 | {
|
---|
94 | GLuint hwId = crStateGetProgramHWID(program);
|
---|
95 | crStateDeleteProgram(program);
|
---|
96 | if (hwId)
|
---|
97 | cr_server.head_spu->dispatch_table.DeleteProgram(hwId);
|
---|
98 | else
|
---|
99 | crWarning("crServerDispatchDeleteProgram: hwid not found for program(%d)", program);
|
---|
100 | }
|
---|
101 |
|
---|
102 | void SERVER_DISPATCH_APIENTRY crServerDispatchValidateProgram(GLuint program)
|
---|
103 | {
|
---|
104 | crStateValidateProgram(program);
|
---|
105 | cr_server.head_spu->dispatch_table.ValidateProgram(crStateGetProgramHWID(program));
|
---|
106 | }
|
---|
107 |
|
---|
108 | void SERVER_DISPATCH_APIENTRY crServerDispatchBindAttribLocation(GLuint program, GLuint index, const char * name)
|
---|
109 | {
|
---|
110 | crStateBindAttribLocation(program, index, name);
|
---|
111 | cr_server.head_spu->dispatch_table.BindAttribLocation(crStateGetProgramHWID(program), index, name);
|
---|
112 | }
|
---|
113 |
|
---|
114 | void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteObjectARB(VBoxGLhandleARB obj)
|
---|
115 | {
|
---|
116 | GLuint hwid = crStateDeleteObjectARB(obj);
|
---|
117 |
|
---|
118 | if (hwid)
|
---|
119 | cr_server.head_spu->dispatch_table.DeleteObjectARB(hwid);
|
---|
120 | else
|
---|
121 | crWarning("zero hwid for object %d", obj);
|
---|
122 | }
|
---|
123 |
|
---|
124 | GLint SERVER_DISPATCH_APIENTRY crServerDispatchGetAttribLocation( GLuint program, const char * name )
|
---|
125 | {
|
---|
126 | GLint retval;
|
---|
127 | retval = cr_server.head_spu->dispatch_table.GetAttribLocation(crStateGetProgramHWID(program), name );
|
---|
128 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
129 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
130 | }
|
---|
131 |
|
---|
132 | VBoxGLhandleARB SERVER_DISPATCH_APIENTRY crServerDispatchGetHandleARB( GLenum pname )
|
---|
133 | {
|
---|
134 | VBoxGLhandleARB retval;
|
---|
135 | retval = cr_server.head_spu->dispatch_table.GetHandleARB(pname);
|
---|
136 | if (pname==GL_PROGRAM_OBJECT_ARB)
|
---|
137 | {
|
---|
138 | retval = crStateGLSLProgramHWIDtoID(retval);
|
---|
139 | }
|
---|
140 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
141 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
142 | }
|
---|
143 |
|
---|
144 | GLint SERVER_DISPATCH_APIENTRY crServerDispatchGetUniformLocation(GLuint program, const char * name)
|
---|
145 | {
|
---|
146 | GLint retval;
|
---|
147 | retval = cr_server.head_spu->dispatch_table.GetUniformLocation(crStateGetProgramHWID(program), name);
|
---|
148 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
149 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
150 | }
|
---|
151 |
|
---|
152 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetProgramiv( GLuint program, GLenum pname, GLint * params )
|
---|
153 | {
|
---|
154 | GLint local_params[1];
|
---|
155 | (void) params;
|
---|
156 | cr_server.head_spu->dispatch_table.GetProgramiv(crStateGetProgramHWID(program), pname, local_params);
|
---|
157 | crServerReturnValue( &(local_params[0]), 1*sizeof(GLint) );
|
---|
158 | }
|
---|
159 |
|
---|
160 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetShaderiv( GLuint shader, GLenum pname, GLint * params )
|
---|
161 | {
|
---|
162 | GLint local_params[1];
|
---|
163 | (void) params;
|
---|
164 | cr_server.head_spu->dispatch_table.GetShaderiv( crStateGetShaderHWID(shader), pname, local_params );
|
---|
165 | crServerReturnValue( &(local_params[0]), 1*sizeof(GLint) );
|
---|
166 | }
|
---|
167 | #endif /* #ifdef CR_OPENGL_VERSION_2_0 */
|
---|
168 |
|
---|
169 | /* XXXX Note: shared/separate Program ID numbers aren't totally implemented! */
|
---|
170 | GLuint crServerTranslateProgramID( GLuint id )
|
---|
171 | {
|
---|
172 | if (!cr_server.sharedPrograms && id) {
|
---|
173 | int client = cr_server.curClient->number;
|
---|
174 | return id + client * 100000;
|
---|
175 | }
|
---|
176 | return id;
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 | void SERVER_DISPATCH_APIENTRY crServerDispatchDeleteProgramsARB(GLsizei n, const GLuint * programs)
|
---|
181 | {
|
---|
182 | GLuint *pLocalProgs = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
183 | GLint i;
|
---|
184 | if (!pLocalProgs) {
|
---|
185 | crError("crServerDispatchDeleteProgramsARB: out of memory");
|
---|
186 | return;
|
---|
187 | }
|
---|
188 | for (i = 0; i < n; i++) {
|
---|
189 | pLocalProgs[i] = crServerTranslateProgramID(programs[i]);
|
---|
190 | }
|
---|
191 | crStateDeleteProgramsARB(n, pLocalProgs);
|
---|
192 | cr_server.head_spu->dispatch_table.DeleteProgramsARB(n, pLocalProgs);
|
---|
193 | crFree(pLocalProgs);
|
---|
194 | }
|
---|
195 |
|
---|
196 |
|
---|
197 | /*@todo will fail for progs loaded from snapshot */
|
---|
198 | GLboolean SERVER_DISPATCH_APIENTRY crServerDispatchIsProgramARB( GLuint program )
|
---|
199 | {
|
---|
200 | GLboolean retval;
|
---|
201 | program = crServerTranslateProgramID(program);
|
---|
202 | retval = cr_server.head_spu->dispatch_table.IsProgramARB( program );
|
---|
203 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
204 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
205 | }
|
---|
206 |
|
---|
207 |
|
---|
208 | GLboolean SERVER_DISPATCH_APIENTRY
|
---|
209 | crServerDispatchAreProgramsResidentNV(GLsizei n, const GLuint *programs,
|
---|
210 | GLboolean *residences)
|
---|
211 | {
|
---|
212 | GLboolean retval;
|
---|
213 | GLboolean *res = (GLboolean *) crAlloc(n * sizeof(GLboolean));
|
---|
214 | GLsizei i;
|
---|
215 |
|
---|
216 | (void) residences;
|
---|
217 |
|
---|
218 | if (!cr_server.sharedTextureObjects) {
|
---|
219 | GLuint *programs2 = (GLuint *) crAlloc(n * sizeof(GLuint));
|
---|
220 | for (i = 0; i < n; i++)
|
---|
221 | programs2[i] = crServerTranslateProgramID(programs[i]);
|
---|
222 | retval = cr_server.head_spu->dispatch_table.AreProgramsResidentNV(n, programs2, res);
|
---|
223 | crFree(programs2);
|
---|
224 | }
|
---|
225 | else {
|
---|
226 | retval = cr_server.head_spu->dispatch_table.AreProgramsResidentNV(n, programs, res);
|
---|
227 | }
|
---|
228 |
|
---|
229 | crServerReturnValue(res, n * sizeof(GLboolean));
|
---|
230 | crFree(res);
|
---|
231 |
|
---|
232 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
233 | }
|
---|
234 |
|
---|