VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_glsl.cpp@ 78375

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

Additions/common/crOpengl,GuestHost/OpenGL,HostServices/SharedOpenGL: Eliminate all global variables from the state tracker library (state_tracker) in preparation of the SPU DLL merging, bugref:9435

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