1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include "server_dispatch.h"
|
---|
8 | #include "server.h"
|
---|
9 | #include "cr_error.h"
|
---|
10 | #include "cr_mem.h"
|
---|
11 | #include "cr_string.h"
|
---|
12 | #include "cr_pixeldata.h"
|
---|
13 |
|
---|
14 | void SERVER_DISPATCH_APIENTRY crServerDispatchSelectBuffer( GLsizei size, GLuint *buffer )
|
---|
15 | {
|
---|
16 | (void) size;
|
---|
17 | (void) buffer;
|
---|
18 | crError( "Unsupported network glSelectBuffer call." );
|
---|
19 | }
|
---|
20 |
|
---|
21 | void SERVER_DISPATCH_APIENTRY crServerDispatchGetChromiumParametervCR(GLenum target, GLuint index, GLenum type, GLsizei count, GLvoid *values)
|
---|
22 | {
|
---|
23 | GLubyte local_storage[4096];
|
---|
24 | GLint bytes = 0;
|
---|
25 |
|
---|
26 | switch (type) {
|
---|
27 | case GL_BYTE:
|
---|
28 | case GL_UNSIGNED_BYTE:
|
---|
29 | bytes = count * sizeof(GLbyte);
|
---|
30 | break;
|
---|
31 | case GL_SHORT:
|
---|
32 | case GL_UNSIGNED_SHORT:
|
---|
33 | bytes = count * sizeof(GLshort);
|
---|
34 | break;
|
---|
35 | case GL_INT:
|
---|
36 | case GL_UNSIGNED_INT:
|
---|
37 | bytes = count * sizeof(GLint);
|
---|
38 | break;
|
---|
39 | case GL_FLOAT:
|
---|
40 | bytes = count * sizeof(GLfloat);
|
---|
41 | break;
|
---|
42 | case GL_DOUBLE:
|
---|
43 | bytes = count * sizeof(GLdouble);
|
---|
44 | break;
|
---|
45 | default:
|
---|
46 | crError("Bad type in crServerDispatchGetChromiumParametervCR");
|
---|
47 | }
|
---|
48 |
|
---|
49 | CRASSERT(bytes >= 0);
|
---|
50 | CRASSERT(bytes < 4096);
|
---|
51 |
|
---|
52 | switch (target)
|
---|
53 | {
|
---|
54 | case GL_DBG_CHECK_BREAK_CR:
|
---|
55 | {
|
---|
56 | if (bytes > 0)
|
---|
57 | {
|
---|
58 | GLubyte *pbRc = local_storage;
|
---|
59 | GLuint *puRc = (GLuint *)(bytes >=4 ? local_storage : NULL);
|
---|
60 | int rc;
|
---|
61 | memset(local_storage, 0, bytes);
|
---|
62 | if (cr_server.RcToGuestOnce)
|
---|
63 | {
|
---|
64 | rc = cr_server.RcToGuestOnce;
|
---|
65 | cr_server.RcToGuestOnce = 0;
|
---|
66 | }
|
---|
67 | else
|
---|
68 | {
|
---|
69 | rc = cr_server.RcToGuest;
|
---|
70 | }
|
---|
71 | if (puRc)
|
---|
72 | *puRc = rc;
|
---|
73 | else
|
---|
74 | *pbRc = !!rc;
|
---|
75 | }
|
---|
76 | else
|
---|
77 | {
|
---|
78 | crWarning("zero bytes for GL_DBG_CHECK_BREAK_CR");
|
---|
79 | }
|
---|
80 | break;
|
---|
81 | }
|
---|
82 | default:
|
---|
83 | cr_server.head_spu->dispatch_table.GetChromiumParametervCR( target, index, type, count, local_storage );
|
---|
84 | break;
|
---|
85 | }
|
---|
86 |
|
---|
87 | crServerReturnValue( local_storage, bytes );
|
---|
88 | }
|
---|
89 |
|
---|
90 | void SERVER_DISPATCH_APIENTRY crServerDispatchChromiumParametervCR(GLenum target, GLenum type, GLsizei count, const GLvoid *values)
|
---|
91 | {
|
---|
92 | CRMuralInfo *mural = cr_server.curClient->currentMural;
|
---|
93 | static int gather_connect_count = 0;
|
---|
94 |
|
---|
95 | switch (target) {
|
---|
96 | case GL_SET_MAX_VIEWPORT_CR:
|
---|
97 | {
|
---|
98 | GLint *maxDims = (GLint *)values;
|
---|
99 | cr_server.limits.maxViewportDims[0] = maxDims[0];
|
---|
100 | cr_server.limits.maxViewportDims[1] = maxDims[1];
|
---|
101 | }
|
---|
102 | break;
|
---|
103 |
|
---|
104 | case GL_TILE_INFO_CR:
|
---|
105 | /* message from tilesort SPU to set new tile bounds */
|
---|
106 | {
|
---|
107 | GLint numTiles, muralWidth, muralHeight, server, tiles;
|
---|
108 | GLint *tileBounds;
|
---|
109 | CRASSERT(count >= 4);
|
---|
110 | CRASSERT((count - 4) % 4 == 0); /* must be multiple of four */
|
---|
111 | CRASSERT(type == GL_INT);
|
---|
112 | numTiles = (count - 4) / 4;
|
---|
113 | tileBounds = (GLint *) values;
|
---|
114 | server = tileBounds[0];
|
---|
115 | muralWidth = tileBounds[1];
|
---|
116 | muralHeight = tileBounds[2];
|
---|
117 | tiles = tileBounds[3];
|
---|
118 | CRASSERT(tiles == numTiles);
|
---|
119 | tileBounds += 4; /* skip over header values */
|
---|
120 | /*crServerNewMuralTiling(mural, muralWidth, muralHeight, numTiles, tileBounds);
|
---|
121 | mural->viewportValidated = GL_FALSE;*/
|
---|
122 | }
|
---|
123 | break;
|
---|
124 |
|
---|
125 | case GL_GATHER_DRAWPIXELS_CR:
|
---|
126 | if (cr_server.only_swap_once && cr_server.curClient != cr_server.clients[0])
|
---|
127 | break;
|
---|
128 | cr_server.head_spu->dispatch_table.ChromiumParametervCR( target, type, count, values );
|
---|
129 | break;
|
---|
130 |
|
---|
131 | case GL_GATHER_CONNECT_CR:
|
---|
132 | /*
|
---|
133 | * We want the last connect to go through,
|
---|
134 | * otherwise we might deadlock in CheckWindowSize()
|
---|
135 | * in the readback spu
|
---|
136 | */
|
---|
137 | gather_connect_count++;
|
---|
138 | if (cr_server.only_swap_once && (gather_connect_count != cr_server.numClients))
|
---|
139 | {
|
---|
140 | break;
|
---|
141 | }
|
---|
142 | cr_server.head_spu->dispatch_table.ChromiumParametervCR( target, type, count, values );
|
---|
143 | gather_connect_count = 0;
|
---|
144 | break;
|
---|
145 |
|
---|
146 | case GL_SERVER_VIEW_MATRIX_CR:
|
---|
147 | /* Set this server's view matrix which will get premultiplied onto the
|
---|
148 | * modelview matrix. For non-planar tilesort and stereo.
|
---|
149 | */
|
---|
150 | CRASSERT(count == 18);
|
---|
151 | CRASSERT(type == GL_FLOAT);
|
---|
152 | /* values[0] is the server index. Ignored here but used in tilesort SPU */
|
---|
153 | /* values[1] is the left/right eye index (0 or 1) */
|
---|
154 | {
|
---|
155 | const GLfloat *v = (const GLfloat *) values;
|
---|
156 | const int eye = v[1] == 0.0 ? 0 : 1;
|
---|
157 | crMatrixInitFromFloats(&cr_server.viewMatrix[eye], v + 2);
|
---|
158 |
|
---|
159 | crDebug("Got GL_SERVER_VIEW_MATRIX_CR:\n"
|
---|
160 | " %f %f %f %f\n"
|
---|
161 | " %f %f %f %f\n"
|
---|
162 | " %f %f %f %f\n"
|
---|
163 | " %f %f %f %f",
|
---|
164 | cr_server.viewMatrix[eye].m00,
|
---|
165 | cr_server.viewMatrix[eye].m10,
|
---|
166 | cr_server.viewMatrix[eye].m20,
|
---|
167 | cr_server.viewMatrix[eye].m30,
|
---|
168 | cr_server.viewMatrix[eye].m01,
|
---|
169 | cr_server.viewMatrix[eye].m11,
|
---|
170 | cr_server.viewMatrix[eye].m21,
|
---|
171 | cr_server.viewMatrix[eye].m31,
|
---|
172 | cr_server.viewMatrix[eye].m02,
|
---|
173 | cr_server.viewMatrix[eye].m12,
|
---|
174 | cr_server.viewMatrix[eye].m22,
|
---|
175 | cr_server.viewMatrix[eye].m32,
|
---|
176 | cr_server.viewMatrix[eye].m03,
|
---|
177 | cr_server.viewMatrix[eye].m13,
|
---|
178 | cr_server.viewMatrix[eye].m23,
|
---|
179 | cr_server.viewMatrix[eye].m33);
|
---|
180 | }
|
---|
181 | cr_server.viewOverride = GL_TRUE;
|
---|
182 | break;
|
---|
183 |
|
---|
184 | case GL_SERVER_PROJECTION_MATRIX_CR:
|
---|
185 | /* Set this server's projection matrix which will get replace the user's
|
---|
186 | * projection matrix. For non-planar tilesort and stereo.
|
---|
187 | */
|
---|
188 | CRASSERT(count == 18);
|
---|
189 | CRASSERT(type == GL_FLOAT);
|
---|
190 | /* values[0] is the server index. Ignored here but used in tilesort SPU */
|
---|
191 | /* values[1] is the left/right eye index (0 or 1) */
|
---|
192 | {
|
---|
193 | const GLfloat *v = (const GLfloat *) values;
|
---|
194 | const int eye = v[1] == 0.0 ? 0 : 1;
|
---|
195 | crMatrixInitFromFloats(&cr_server.projectionMatrix[eye], v + 2);
|
---|
196 |
|
---|
197 | crDebug("Got GL_SERVER_PROJECTION_MATRIX_CR:\n"
|
---|
198 | " %f %f %f %f\n"
|
---|
199 | " %f %f %f %f\n"
|
---|
200 | " %f %f %f %f\n"
|
---|
201 | " %f %f %f %f",
|
---|
202 | cr_server.projectionMatrix[eye].m00,
|
---|
203 | cr_server.projectionMatrix[eye].m10,
|
---|
204 | cr_server.projectionMatrix[eye].m20,
|
---|
205 | cr_server.projectionMatrix[eye].m30,
|
---|
206 | cr_server.projectionMatrix[eye].m01,
|
---|
207 | cr_server.projectionMatrix[eye].m11,
|
---|
208 | cr_server.projectionMatrix[eye].m21,
|
---|
209 | cr_server.projectionMatrix[eye].m31,
|
---|
210 | cr_server.projectionMatrix[eye].m02,
|
---|
211 | cr_server.projectionMatrix[eye].m12,
|
---|
212 | cr_server.projectionMatrix[eye].m22,
|
---|
213 | cr_server.projectionMatrix[eye].m32,
|
---|
214 | cr_server.projectionMatrix[eye].m03,
|
---|
215 | cr_server.projectionMatrix[eye].m13,
|
---|
216 | cr_server.projectionMatrix[eye].m23,
|
---|
217 | cr_server.projectionMatrix[eye].m33);
|
---|
218 |
|
---|
219 | if (cr_server.projectionMatrix[eye].m33 == 0.0f) {
|
---|
220 | float x = cr_server.projectionMatrix[eye].m00;
|
---|
221 | float y = cr_server.projectionMatrix[eye].m11;
|
---|
222 | float a = cr_server.projectionMatrix[eye].m20;
|
---|
223 | float b = cr_server.projectionMatrix[eye].m21;
|
---|
224 | float c = cr_server.projectionMatrix[eye].m22;
|
---|
225 | float d = cr_server.projectionMatrix[eye].m32;
|
---|
226 | float znear = -d / (1.0f - c);
|
---|
227 | float zfar = (c - 1.0f) * znear / (c + 1.0f);
|
---|
228 | float left = znear * (a - 1.0f) / x;
|
---|
229 | float right = 2.0f * znear / x + left;
|
---|
230 | float bottom = znear * (b - 1.0f) / y;
|
---|
231 | float top = 2.0f * znear / y + bottom;
|
---|
232 | crDebug("Frustum: left, right, bottom, top, near, far: %f, %f, %f, %f, %f, %f", left, right, bottom, top, znear, zfar);
|
---|
233 | }
|
---|
234 | else {
|
---|
235 | /* Todo: Add debug output for orthographic projection*/
|
---|
236 | }
|
---|
237 |
|
---|
238 | }
|
---|
239 | cr_server.projectionOverride = GL_TRUE;
|
---|
240 | break;
|
---|
241 |
|
---|
242 | case GL_HH_SET_TMPCTX_MAKE_CURRENT:
|
---|
243 | /*we should not receive it from the guest! */
|
---|
244 | break;
|
---|
245 |
|
---|
246 | default:
|
---|
247 | /* Pass the parameter info to the head SPU */
|
---|
248 | cr_server.head_spu->dispatch_table.ChromiumParametervCR( target, type, count, values );
|
---|
249 | break;
|
---|
250 | }
|
---|
251 | }
|
---|
252 |
|
---|
253 |
|
---|
254 | void SERVER_DISPATCH_APIENTRY crServerDispatchChromiumParameteriCR(GLenum target, GLint value)
|
---|
255 | {
|
---|
256 | switch (target) {
|
---|
257 | case GL_SHARE_CONTEXT_RESOURCES_CR:
|
---|
258 | crStateShareContext(value);
|
---|
259 | break;
|
---|
260 | case GL_RCUSAGE_TEXTURE_SET_CR:
|
---|
261 | crStateSetTextureUsed(value, GL_TRUE);
|
---|
262 | break;
|
---|
263 | case GL_RCUSAGE_TEXTURE_CLEAR_CR:
|
---|
264 | crStateSetTextureUsed(value, GL_FALSE);
|
---|
265 | break;
|
---|
266 | case GL_SHARED_DISPLAY_LISTS_CR:
|
---|
267 | cr_server.sharedDisplayLists = value;
|
---|
268 | break;
|
---|
269 | case GL_SHARED_TEXTURE_OBJECTS_CR:
|
---|
270 | cr_server.sharedTextureObjects = value;
|
---|
271 | break;
|
---|
272 | case GL_SHARED_PROGRAMS_CR:
|
---|
273 | cr_server.sharedPrograms = value;
|
---|
274 | break;
|
---|
275 | case GL_SERVER_CURRENT_EYE_CR:
|
---|
276 | cr_server.currentEye = value ? 1 : 0;
|
---|
277 | break;
|
---|
278 | case GL_HOST_WND_CREATED_HIDDEN_CR:
|
---|
279 | cr_server.bWindowsInitiallyHidden = value ? 1 : 0;
|
---|
280 | break;
|
---|
281 | case GL_HH_SET_DEFAULT_SHARED_CTX:
|
---|
282 | crWarning("Recieved GL_HH_SET_DEFAULT_SHARED_CTX from guest, ignoring");
|
---|
283 | break;
|
---|
284 | case GL_HH_RENDERTHREAD_INFORM:
|
---|
285 | crWarning("Recieved GL_HH_RENDERTHREAD_INFORM from guest, ignoring");
|
---|
286 | break;
|
---|
287 | default:
|
---|
288 | /* Pass the parameter info to the head SPU */
|
---|
289 | cr_server.head_spu->dispatch_table.ChromiumParameteriCR( target, value );
|
---|
290 | }
|
---|
291 | }
|
---|
292 |
|
---|
293 |
|
---|
294 | void SERVER_DISPATCH_APIENTRY crServerDispatchChromiumParameterfCR(GLenum target, GLfloat value)
|
---|
295 | {
|
---|
296 | switch (target) {
|
---|
297 | case GL_SHARED_DISPLAY_LISTS_CR:
|
---|
298 | cr_server.sharedDisplayLists = (int) value;
|
---|
299 | break;
|
---|
300 | case GL_SHARED_TEXTURE_OBJECTS_CR:
|
---|
301 | cr_server.sharedTextureObjects = (int) value;
|
---|
302 | break;
|
---|
303 | case GL_SHARED_PROGRAMS_CR:
|
---|
304 | cr_server.sharedPrograms = (int) value;
|
---|
305 | break;
|
---|
306 | default:
|
---|
307 | /* Pass the parameter info to the head SPU */
|
---|
308 | cr_server.head_spu->dispatch_table.ChromiumParameterfCR( target, value );
|
---|
309 | }
|
---|
310 | }
|
---|
311 |
|
---|
312 | GLint crServerGenerateID(GLint *pCounter)
|
---|
313 | {
|
---|
314 | return (*pCounter)++;
|
---|
315 | }
|
---|
316 |
|
---|
317 | /*#define CR_DUMP_BLITS*/
|
---|
318 |
|
---|
319 | #ifdef CR_DUMP_BLITS
|
---|
320 | static int blitnum=0;
|
---|
321 | static int copynum=0;
|
---|
322 | #endif
|
---|
323 |
|
---|
324 | # ifdef DEBUG_misha
|
---|
325 | //# define CR_CHECK_BLITS
|
---|
326 | # include <iprt/assert.h>
|
---|
327 | # undef CRASSERT /* iprt assert's int3 are inlined that is why are more convenient to use since they can be easily disabled individually */
|
---|
328 | # define CRASSERT Assert
|
---|
329 | # endif
|
---|
330 |
|
---|
331 |
|
---|
332 | void SERVER_DISPATCH_APIENTRY
|
---|
333 | crServerDispatchCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
|
---|
334 | {
|
---|
335 | /*@todo pbo/fbo disabled for now as it's slower, check on other gpus*/
|
---|
336 | static int siHavePBO = 0;
|
---|
337 | static int siHaveFBO = 0;
|
---|
338 |
|
---|
339 | if ((target!=GL_TEXTURE_2D) || (height>=0))
|
---|
340 | {
|
---|
341 | cr_server.head_spu->dispatch_table.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
|
---|
342 |
|
---|
343 | #ifdef CR_DUMP_BLITS
|
---|
344 | {
|
---|
345 | SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table;
|
---|
346 | void *img;
|
---|
347 | GLint w, h;
|
---|
348 | char fname[200];
|
---|
349 |
|
---|
350 | copynum++;
|
---|
351 |
|
---|
352 | gl->GetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
---|
353 | gl->GetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
---|
354 |
|
---|
355 | img = crAlloc(w*h*4);
|
---|
356 | CRASSERT(img);
|
---|
357 |
|
---|
358 | gl->GetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_BYTE, img);
|
---|
359 | sprintf(fname, "copy_blit%i_copy_%i.tga", blitnum, copynum);
|
---|
360 | crDumpNamedTGA(fname, w, h, img);
|
---|
361 | crFree(img);
|
---|
362 | }
|
---|
363 | #endif
|
---|
364 | }
|
---|
365 | else /* negative height, means we have to Yinvert the source pixels while copying */
|
---|
366 | {
|
---|
367 | SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table;
|
---|
368 |
|
---|
369 | if (siHavePBO<0)
|
---|
370 | {
|
---|
371 | const char *ext = (const char*)gl->GetString(GL_EXTENSIONS);
|
---|
372 | siHavePBO = crStrstr(ext, "GL_ARB_pixel_buffer_object") ? 1:0;
|
---|
373 | }
|
---|
374 |
|
---|
375 | if (siHaveFBO<0)
|
---|
376 | {
|
---|
377 | const char *ext = (const char*)gl->GetString(GL_EXTENSIONS);
|
---|
378 | siHaveFBO = crStrstr(ext, "GL_EXT_framebuffer_object") ? 1:0;
|
---|
379 | }
|
---|
380 |
|
---|
381 | if (siHavePBO==0 && siHaveFBO==0)
|
---|
382 | {
|
---|
383 | #if 1
|
---|
384 | GLint dRow, sRow;
|
---|
385 | for (dRow=yoffset, sRow=y-height-1; dRow<yoffset-height; dRow++, sRow--)
|
---|
386 | {
|
---|
387 | gl->CopyTexSubImage2D(target, level, xoffset, dRow, x, sRow, width, 1);
|
---|
388 | }
|
---|
389 | #else
|
---|
390 | {
|
---|
391 | GLint w, h, i;
|
---|
392 | char *img1, *img2, *sPtr, *dPtr;
|
---|
393 | CRContext *ctx = crStateGetCurrent();
|
---|
394 |
|
---|
395 | w = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->level[0][level].width;
|
---|
396 | h = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->level[0][level].height;
|
---|
397 |
|
---|
398 | img1 = crAlloc(4*w*h);
|
---|
399 | img2 = crAlloc(4*width*(-height));
|
---|
400 | CRASSERT(img1 && img2);
|
---|
401 |
|
---|
402 | gl->CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, -height);
|
---|
403 | gl->GetTexImage(target, level, GL_RGBA, GL_UNSIGNED_BYTE, img1);
|
---|
404 |
|
---|
405 | sPtr=img1+4*xoffset+4*w*yoffset;
|
---|
406 | dPtr=img2+4*width*(-height-1);
|
---|
407 |
|
---|
408 | for (i=0; i<-height; ++i)
|
---|
409 | {
|
---|
410 | crMemcpy(dPtr, sPtr, 4*width);
|
---|
411 | sPtr += 4*w;
|
---|
412 | dPtr -= 4*width;
|
---|
413 | }
|
---|
414 |
|
---|
415 | gl->TexSubImage2D(target, level, xoffset, yoffset, width, -height, GL_RGBA, GL_UNSIGNED_BYTE, img2);
|
---|
416 |
|
---|
417 | crFree(img1);
|
---|
418 | crFree(img2);
|
---|
419 | }
|
---|
420 | #endif
|
---|
421 | }
|
---|
422 | else if (siHaveFBO==1) /*@todo more states to set and restore here*/
|
---|
423 | {
|
---|
424 | GLuint tID, fboID;
|
---|
425 | GLenum status;
|
---|
426 | CRContext *ctx = crStateGetCurrent();
|
---|
427 |
|
---|
428 | gl->GenTextures(1, &tID);
|
---|
429 | gl->BindTexture(target, tID);
|
---|
430 | gl->CopyTexImage2D(target, level, GL_RGBA, x, y, width, -height, 0);
|
---|
431 | gl->GenFramebuffersEXT(1, &fboID);
|
---|
432 | gl->BindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboID);
|
---|
433 | gl->FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, target,
|
---|
434 | ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->hwid, level);
|
---|
435 | status = gl->CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
---|
436 | if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
|
---|
437 | {
|
---|
438 | crWarning("Framebuffer status 0x%x", status);
|
---|
439 | }
|
---|
440 |
|
---|
441 | gl->Enable(target);
|
---|
442 | gl->PushAttrib(GL_VIEWPORT_BIT);
|
---|
443 | gl->Viewport(xoffset, yoffset, width, -height);
|
---|
444 | gl->MatrixMode(GL_PROJECTION);
|
---|
445 | gl->PushMatrix();
|
---|
446 | gl->LoadIdentity();
|
---|
447 | gl->MatrixMode(GL_MODELVIEW);
|
---|
448 | gl->PushMatrix();
|
---|
449 | gl->LoadIdentity();
|
---|
450 |
|
---|
451 | gl->Disable(GL_DEPTH_TEST);
|
---|
452 | gl->Disable(GL_CULL_FACE);
|
---|
453 | gl->Disable(GL_STENCIL_TEST);
|
---|
454 | gl->Disable(GL_SCISSOR_TEST);
|
---|
455 |
|
---|
456 | gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
---|
457 | gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
---|
458 | gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
---|
459 | gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
---|
460 | gl->TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
---|
461 |
|
---|
462 | gl->Begin(GL_QUADS);
|
---|
463 | gl->TexCoord2f(0.0f, 1.0f);
|
---|
464 | gl->Vertex2f(-1.0, -1.0);
|
---|
465 |
|
---|
466 | gl->TexCoord2f(0.0f, 0.0f);
|
---|
467 | gl->Vertex2f(-1.0f, 1.0f);
|
---|
468 |
|
---|
469 | gl->TexCoord2f(1.0f, 0.0f);
|
---|
470 | gl->Vertex2f(1.0f, 1.0f);
|
---|
471 |
|
---|
472 | gl->TexCoord2f(1.0f, 1.0f);
|
---|
473 | gl->Vertex2f(1.0f, -1.0f);
|
---|
474 | gl->End();
|
---|
475 |
|
---|
476 | gl->PopMatrix();
|
---|
477 | gl->MatrixMode(GL_PROJECTION);
|
---|
478 | gl->PopMatrix();
|
---|
479 | gl->PopAttrib();
|
---|
480 |
|
---|
481 | gl->FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, target, 0, level);
|
---|
482 | gl->BindFramebufferEXT(GL_FRAMEBUFFER_EXT, ctx->framebufferobject.drawFB ? ctx->framebufferobject.drawFB->hwid:0);
|
---|
483 | gl->BindTexture(target, ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->hwid);
|
---|
484 | gl->DeleteFramebuffersEXT(1, &fboID);
|
---|
485 | gl->DeleteTextures(1, &tID);
|
---|
486 |
|
---|
487 | #if 0
|
---|
488 | {
|
---|
489 | GLint dRow, sRow, w, h;
|
---|
490 | void *img1, *img2;
|
---|
491 |
|
---|
492 | w = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->level[0][level].width;
|
---|
493 | h = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->level[0][level].height;
|
---|
494 |
|
---|
495 | img1 = crAlloc(4*w*h);
|
---|
496 | img2 = crAlloc(4*w*h);
|
---|
497 | CRASSERT(img1 && img2);
|
---|
498 |
|
---|
499 | gl->GetTexImage(target, level, GL_BGRA, GL_UNSIGNED_BYTE, img1);
|
---|
500 |
|
---|
501 |
|
---|
502 | for (dRow=yoffset, sRow=y-height-1; dRow<yoffset-height; dRow++, sRow--)
|
---|
503 | {
|
---|
504 | gl->CopyTexSubImage2D(target, level, xoffset, dRow, x, sRow, width, 1);
|
---|
505 | }
|
---|
506 |
|
---|
507 | gl->GetTexImage(target, level, GL_BGRA, GL_UNSIGNED_BYTE, img2);
|
---|
508 |
|
---|
509 | if (crMemcmp(img1, img2, 4*w*h))
|
---|
510 | {
|
---|
511 | crDebug("MISMATCH! (%x, %i, ->%i,%i <-%i, %i [%ix%i])", target, level, xoffset, yoffset, x, y, width, height);
|
---|
512 | crDumpTGA(w, h, img1);
|
---|
513 | crDumpTGA(w, h, img2);
|
---|
514 | DebugBreak();
|
---|
515 | }
|
---|
516 | crFree(img1);
|
---|
517 | crFree(img2);
|
---|
518 | }
|
---|
519 | #endif
|
---|
520 | }
|
---|
521 | else
|
---|
522 | {
|
---|
523 | GLuint pboId, dRow, sRow;
|
---|
524 | CRContext *ctx = crStateGetCurrent();
|
---|
525 |
|
---|
526 | gl->GenBuffersARB(1, &pboId);
|
---|
527 | gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboId);
|
---|
528 | gl->BufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, -width*height*4, 0, GL_STATIC_COPY_ARB);
|
---|
529 |
|
---|
530 | #if 1
|
---|
531 | gl->ReadPixels(x, y, width, -height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
---|
532 | gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, ctx->bufferobject.packBuffer->hwid);
|
---|
533 |
|
---|
534 | gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboId);
|
---|
535 | for (dRow=yoffset, sRow=-height-1; dRow<yoffset-height; dRow++, sRow--)
|
---|
536 | {
|
---|
537 | gl->TexSubImage2D(target, level, xoffset, dRow, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)((uintptr_t)sRow*width*4));
|
---|
538 | }
|
---|
539 | #else /*few times slower again*/
|
---|
540 | for (dRow=0, sRow=y-height-1; dRow<-height; dRow++, sRow--)
|
---|
541 | {
|
---|
542 | gl->ReadPixels(x, sRow, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)((uintptr_t)dRow*width*4));
|
---|
543 | }
|
---|
544 | gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, ctx->bufferobject.packBuffer->hwid);
|
---|
545 |
|
---|
546 | gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboId);
|
---|
547 | gl->TexSubImage2D(target, level, xoffset, yoffset, width, -height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
---|
548 | #endif
|
---|
549 |
|
---|
550 | gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, ctx->bufferobject.unpackBuffer->hwid);
|
---|
551 | gl->DeleteBuffersARB(1, &pboId);
|
---|
552 | }
|
---|
553 | }
|
---|
554 | }
|
---|
555 |
|
---|
556 | #ifdef CR_CHECK_BLITS
|
---|
557 | void crDbgFree(void *pvData)
|
---|
558 | {
|
---|
559 | crFree(pvData);
|
---|
560 | }
|
---|
561 |
|
---|
562 | void crDbgGetTexImage2D(GLint texTarget, GLint texName, GLvoid **ppvImage, GLint *pw, GLint *ph)
|
---|
563 | {
|
---|
564 | SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table;
|
---|
565 | GLint ppb, pub, dstw, dsth, otex;
|
---|
566 | GLint pa, pr, psp, psr, ua, ur, usp, usr;
|
---|
567 | GLvoid *pvImage;
|
---|
568 | GLint rfb, dfb, rb, db;
|
---|
569 |
|
---|
570 | gl->GetIntegerv(GL_READ_FRAMEBUFFER_BINDING_EXT, &rfb);
|
---|
571 | gl->GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING_EXT, &dfb);
|
---|
572 | gl->GetIntegerv(GL_READ_BUFFER, &rb);
|
---|
573 | gl->GetIntegerv(GL_DRAW_BUFFER, &db);
|
---|
574 |
|
---|
575 | gl->BindFramebufferEXT(GL_READ_FRAMEBUFFER_BINDING_EXT, 0);
|
---|
576 | gl->BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_BINDING_EXT, 0);
|
---|
577 | gl->ReadBuffer(GL_BACK);
|
---|
578 | gl->DrawBuffer(GL_BACK);
|
---|
579 |
|
---|
580 | gl->GetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &ppb);
|
---|
581 | gl->GetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &pub);
|
---|
582 | gl->GetIntegerv(GL_TEXTURE_BINDING_2D, &otex);
|
---|
583 |
|
---|
584 | gl->GetIntegerv(GL_PACK_ROW_LENGTH, &pr);
|
---|
585 | gl->GetIntegerv(GL_PACK_ALIGNMENT, &pa);
|
---|
586 | gl->GetIntegerv(GL_PACK_SKIP_PIXELS, &psp);
|
---|
587 | gl->GetIntegerv(GL_PACK_SKIP_ROWS, &psr);
|
---|
588 |
|
---|
589 | gl->GetIntegerv(GL_UNPACK_ROW_LENGTH, &ur);
|
---|
590 | gl->GetIntegerv(GL_UNPACK_ALIGNMENT, &ua);
|
---|
591 | gl->GetIntegerv(GL_UNPACK_SKIP_PIXELS, &usp);
|
---|
592 | gl->GetIntegerv(GL_UNPACK_SKIP_ROWS, &usr);
|
---|
593 |
|
---|
594 | gl->BindTexture(texTarget, texName);
|
---|
595 | gl->GetTexLevelParameteriv(texTarget, 0, GL_TEXTURE_WIDTH, &dstw);
|
---|
596 | gl->GetTexLevelParameteriv(texTarget, 0, GL_TEXTURE_HEIGHT, &dsth);
|
---|
597 |
|
---|
598 | gl->PixelStorei(GL_PACK_ROW_LENGTH, 0);
|
---|
599 | gl->PixelStorei(GL_PACK_ALIGNMENT, 1);
|
---|
600 | gl->PixelStorei(GL_PACK_SKIP_PIXELS, 0);
|
---|
601 | gl->PixelStorei(GL_PACK_SKIP_ROWS, 0);
|
---|
602 |
|
---|
603 | gl->PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
---|
604 | gl->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
---|
605 | gl->PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
|
---|
606 | gl->PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
|
---|
607 |
|
---|
608 | gl->BindBufferARB(GL_PIXEL_PACK_BUFFER, 0);
|
---|
609 | gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER, 0);
|
---|
610 |
|
---|
611 | pvImage = crAlloc(4*dstw*dsth);
|
---|
612 | gl->GetTexImage(texTarget, 0, GL_BGRA, GL_UNSIGNED_BYTE, pvImage);
|
---|
613 |
|
---|
614 | gl->BindTexture(texTarget, otex);
|
---|
615 |
|
---|
616 | gl->PixelStorei(GL_PACK_ROW_LENGTH, pr);
|
---|
617 | gl->PixelStorei(GL_PACK_ALIGNMENT, pa);
|
---|
618 | gl->PixelStorei(GL_PACK_SKIP_PIXELS, psp);
|
---|
619 | gl->PixelStorei(GL_PACK_SKIP_ROWS, psr);
|
---|
620 |
|
---|
621 | gl->PixelStorei(GL_UNPACK_ROW_LENGTH, ur);
|
---|
622 | gl->PixelStorei(GL_UNPACK_ALIGNMENT, ua);
|
---|
623 | gl->PixelStorei(GL_UNPACK_SKIP_PIXELS, usp);
|
---|
624 | gl->PixelStorei(GL_UNPACK_SKIP_ROWS, usr);
|
---|
625 |
|
---|
626 | gl->BindBufferARB(GL_PIXEL_PACK_BUFFER, ppb);
|
---|
627 | gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER, pub);
|
---|
628 |
|
---|
629 | gl->BindFramebufferEXT(GL_READ_FRAMEBUFFER_BINDING_EXT, rfb);
|
---|
630 | gl->BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_BINDING_EXT, dfb);
|
---|
631 | gl->ReadBuffer(rb);
|
---|
632 | gl->DrawBuffer(db);
|
---|
633 |
|
---|
634 | *ppvImage = pvImage;
|
---|
635 | *pw = dstw;
|
---|
636 | *ph = dsth;
|
---|
637 | }
|
---|
638 |
|
---|
639 | DECLEXPORT(void) crDbgPrint(const char *format, ... )
|
---|
640 | {
|
---|
641 | va_list args;
|
---|
642 | static char txt[8092];
|
---|
643 |
|
---|
644 | va_start( args, format );
|
---|
645 | vsprintf( txt, format, args );
|
---|
646 |
|
---|
647 | OutputDebugString(txt);
|
---|
648 | }
|
---|
649 |
|
---|
650 | void crDbgDumpImage2D(const char* pszDesc, const void *pvData, uint32_t width, uint32_t height, uint32_t bpp, uint32_t pitch)
|
---|
651 | {
|
---|
652 | crDbgPrint("<?dml?><exec cmd=\"!vbvdbg.ms 0x%p 0n%d 0n%d 0n%d 0n%d\">%s</exec>, ( !vbvdbg.ms 0x%p 0n%d 0n%d 0n%d 0n%d )\n",
|
---|
653 | pvData, width, height, bpp, pitch,
|
---|
654 | pszDesc,
|
---|
655 | pvData, width, height, bpp, pitch);
|
---|
656 | }
|
---|
657 |
|
---|
658 | void crDbgDumpTexImage2D(const char* pszDesc, GLint texTarget, GLint texName, GLboolean fBreak)
|
---|
659 | {
|
---|
660 | GLvoid *pvImage;
|
---|
661 | GLint w, h;
|
---|
662 | crDbgGetTexImage2D(texTarget, texName, &pvImage, &w, &h);
|
---|
663 | crDbgPrint("%s target(%d), name(%d), width(%d), height(%d)", pszDesc, texTarget, texName, w, h);
|
---|
664 | crDbgDumpImage2D("texture data", pvImage, w, h, 32, (32 * w)/8);
|
---|
665 | if (fBreak)
|
---|
666 | {
|
---|
667 | CRASSERT(0);
|
---|
668 | }
|
---|
669 | crDbgFree(pvImage);
|
---|
670 | }
|
---|
671 | #endif
|
---|
672 |
|
---|
673 | PCR_BLITTER crServerVBoxBlitterGet()
|
---|
674 | {
|
---|
675 | if (!CrBltIsInitialized(&cr_server.Blitter))
|
---|
676 | {
|
---|
677 | CR_BLITTER_CONTEXT Ctx;
|
---|
678 | int rc;
|
---|
679 | CRASSERT(cr_server.MainContextInfo.SpuContext);
|
---|
680 | Ctx.Base.id = cr_server.MainContextInfo.SpuContext;
|
---|
681 | Ctx.Base.visualBits = cr_server.MainContextInfo.CreateInfo.realVisualBits;
|
---|
682 | rc = CrBltInit(&cr_server.Blitter, &Ctx, true, true, NULL, &cr_server.TmpCtxDispatch);
|
---|
683 | if (RT_SUCCESS(rc))
|
---|
684 | {
|
---|
685 | CRASSERT(CrBltIsInitialized(&cr_server.Blitter));
|
---|
686 | }
|
---|
687 | else
|
---|
688 | {
|
---|
689 | crWarning("CrBltInit failed, rc %d", rc);
|
---|
690 | CRASSERT(!CrBltIsInitialized(&cr_server.Blitter));
|
---|
691 | return NULL;
|
---|
692 | }
|
---|
693 | }
|
---|
694 |
|
---|
695 | if (!CrBltMuralGetCurrentInfo(&cr_server.Blitter)->Base.id)
|
---|
696 | {
|
---|
697 | CRMuralInfo *dummy = crServerGetDummyMural(cr_server.MainContextInfo.CreateInfo.realVisualBits);
|
---|
698 | CR_BLITTER_WINDOW DummyInfo;
|
---|
699 | CRASSERT(dummy);
|
---|
700 | crServerVBoxBlitterWinInit(&DummyInfo, dummy);
|
---|
701 | CrBltMuralSetCurrentInfo(&cr_server.Blitter, &DummyInfo);
|
---|
702 | }
|
---|
703 |
|
---|
704 | return &cr_server.Blitter;
|
---|
705 | }
|
---|
706 |
|
---|
707 | PCR_BLITTER crServerVBoxBlitterGetInitialized()
|
---|
708 | {
|
---|
709 | if (CrBltIsInitialized(&cr_server.Blitter))
|
---|
710 | return &cr_server.Blitter;
|
---|
711 | return NULL;
|
---|
712 | }
|
---|
713 |
|
---|
714 |
|
---|
715 | int crServerVBoxBlitterTexInit(CRContext *ctx, CRMuralInfo *mural, PVBOXVR_TEXTURE pTex, GLboolean fDraw)
|
---|
716 | {
|
---|
717 | CRTextureObj *tobj;
|
---|
718 | CRFramebufferObjectState *pBuf = &ctx->framebufferobject;
|
---|
719 | GLenum enmBuf;
|
---|
720 | CRFBOAttachmentPoint *pAp;
|
---|
721 | GLuint idx;
|
---|
722 | CRTextureLevel *tl;
|
---|
723 | CRFramebufferObject *pFBO = fDraw ? pBuf->drawFB : pBuf->readFB;
|
---|
724 |
|
---|
725 | if (!pFBO)
|
---|
726 | {
|
---|
727 | GLuint hwid;
|
---|
728 |
|
---|
729 | if (!mural->fRedirected)
|
---|
730 | return VERR_NOT_IMPLEMENTED;
|
---|
731 |
|
---|
732 | enmBuf = fDraw ? ctx->buffer.drawBuffer : ctx->buffer.readBuffer;
|
---|
733 | switch (enmBuf)
|
---|
734 | {
|
---|
735 | case GL_BACK:
|
---|
736 | case GL_BACK_RIGHT:
|
---|
737 | case GL_BACK_LEFT:
|
---|
738 | hwid = mural->aidColorTexs[CR_SERVER_FBO_BB_IDX(mural)];
|
---|
739 | break;
|
---|
740 | case GL_FRONT:
|
---|
741 | case GL_FRONT_RIGHT:
|
---|
742 | case GL_FRONT_LEFT:
|
---|
743 | hwid = mural->aidColorTexs[CR_SERVER_FBO_FB_IDX(mural)];
|
---|
744 | break;
|
---|
745 | default:
|
---|
746 | crWarning("unsupported enum buf");
|
---|
747 | return VERR_NOT_IMPLEMENTED;
|
---|
748 | break;
|
---|
749 | }
|
---|
750 |
|
---|
751 | if (!hwid)
|
---|
752 | {
|
---|
753 | crWarning("offscreen render tex hwid is null");
|
---|
754 | return VERR_INVALID_STATE;
|
---|
755 | }
|
---|
756 |
|
---|
757 | pTex->width = mural->width;
|
---|
758 | pTex->height = mural->height;
|
---|
759 | pTex->target = GL_TEXTURE_2D;
|
---|
760 | pTex->hwid = hwid;
|
---|
761 | return VINF_SUCCESS;
|
---|
762 | }
|
---|
763 |
|
---|
764 | enmBuf = fDraw ? pFBO->drawbuffer[0] : pFBO->readbuffer;
|
---|
765 | idx = enmBuf - GL_COLOR_ATTACHMENT0_EXT;
|
---|
766 | if (idx >= CR_MAX_COLOR_ATTACHMENTS)
|
---|
767 | {
|
---|
768 | crWarning("idx is invalid %d, using 0", idx);
|
---|
769 | }
|
---|
770 |
|
---|
771 | pAp = &pFBO->color[idx];
|
---|
772 |
|
---|
773 | if (!pAp->name)
|
---|
774 | {
|
---|
775 | crWarning("no collor draw attachment");
|
---|
776 | return VERR_INVALID_STATE;
|
---|
777 | }
|
---|
778 |
|
---|
779 | if (pAp->level)
|
---|
780 | {
|
---|
781 | crWarning("non-zero level not implemented");
|
---|
782 | return VERR_NOT_IMPLEMENTED;
|
---|
783 | }
|
---|
784 |
|
---|
785 | tobj = (CRTextureObj*)crHashtableSearch(ctx->shared->textureTable, pAp->name);
|
---|
786 | if (!tobj)
|
---|
787 | {
|
---|
788 | crWarning("no texture object found for name %d", pAp->name);
|
---|
789 | return VERR_INVALID_STATE;
|
---|
790 | }
|
---|
791 |
|
---|
792 | if (tobj->target != GL_TEXTURE_2D && tobj->target != GL_TEXTURE_RECTANGLE_NV)
|
---|
793 | {
|
---|
794 | crWarning("non-texture[rect|2d] not implemented");
|
---|
795 | return VERR_NOT_IMPLEMENTED;
|
---|
796 | }
|
---|
797 |
|
---|
798 | CRASSERT(tobj->hwid);
|
---|
799 |
|
---|
800 | tl = tobj->level[0];
|
---|
801 | pTex->width = tl->width;
|
---|
802 | pTex->height = tl->height;
|
---|
803 | pTex->target = tobj->target;
|
---|
804 | pTex->hwid = tobj->hwid;
|
---|
805 |
|
---|
806 | return VINF_SUCCESS;
|
---|
807 | }
|
---|
808 |
|
---|
809 | int crServerVBoxBlitterBlitCurrentCtx(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
|
---|
810 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
|
---|
811 | GLbitfield mask, GLenum filter)
|
---|
812 | {
|
---|
813 | PCR_BLITTER pBlitter;
|
---|
814 | CR_BLITTER_CONTEXT Ctx;
|
---|
815 | CRMuralInfo *mural;
|
---|
816 | CRContext *ctx = crStateGetCurrent();
|
---|
817 | PVBOXVR_TEXTURE pDrawTex, pReadTex;
|
---|
818 | VBOXVR_TEXTURE DrawTex, ReadTex;
|
---|
819 | int rc;
|
---|
820 | GLuint idDrawFBO, idReadFBO;
|
---|
821 | CR_BLITTER_WINDOW BltInfo;
|
---|
822 |
|
---|
823 | if (mask != GL_COLOR_BUFFER_BIT)
|
---|
824 | {
|
---|
825 | crWarning("not supported blit mask %d", mask);
|
---|
826 | return VERR_NOT_IMPLEMENTED;
|
---|
827 | }
|
---|
828 |
|
---|
829 | if (!cr_server.curClient)
|
---|
830 | {
|
---|
831 | crWarning("no current client");
|
---|
832 | return VERR_INVALID_STATE;
|
---|
833 | }
|
---|
834 | mural = cr_server.curClient->currentMural;
|
---|
835 | if (!mural)
|
---|
836 | {
|
---|
837 | crWarning("no current mural");
|
---|
838 | return VERR_INVALID_STATE;
|
---|
839 | }
|
---|
840 |
|
---|
841 | rc = crServerVBoxBlitterTexInit(ctx, mural, &DrawTex, GL_TRUE);
|
---|
842 | if (RT_SUCCESS(rc))
|
---|
843 | {
|
---|
844 | pDrawTex = &DrawTex;
|
---|
845 | }
|
---|
846 | else
|
---|
847 | {
|
---|
848 | crWarning("crServerVBoxBlitterTexInit failed for draw");
|
---|
849 | return rc;
|
---|
850 | }
|
---|
851 |
|
---|
852 | rc = crServerVBoxBlitterTexInit(ctx, mural, &ReadTex, GL_FALSE);
|
---|
853 | if (RT_SUCCESS(rc))
|
---|
854 | {
|
---|
855 | pReadTex = &ReadTex;
|
---|
856 | }
|
---|
857 | else
|
---|
858 | {
|
---|
859 | // crWarning("crServerVBoxBlitterTexInit failed for read");
|
---|
860 | return rc;
|
---|
861 | }
|
---|
862 |
|
---|
863 | pBlitter = crServerVBoxBlitterGet();
|
---|
864 | if (!pBlitter)
|
---|
865 | {
|
---|
866 | crWarning("crServerVBoxBlitterGet failed");
|
---|
867 | return VERR_GENERAL_FAILURE;
|
---|
868 | }
|
---|
869 |
|
---|
870 | crServerVBoxBlitterWinInit(&BltInfo, mural);
|
---|
871 |
|
---|
872 | crServerVBoxBlitterCtxInit(&Ctx, cr_server.curClient->currentCtxInfo);
|
---|
873 |
|
---|
874 | CrBltMuralSetCurrentInfo(pBlitter, &BltInfo);
|
---|
875 |
|
---|
876 | idDrawFBO = CR_SERVER_FBO_FOR_IDX(mural, mural->iCurDrawBuffer);
|
---|
877 | idReadFBO = CR_SERVER_FBO_FOR_IDX(mural, mural->iCurReadBuffer);
|
---|
878 |
|
---|
879 | crStateSwitchPrepare(NULL, ctx, idDrawFBO, idReadFBO);
|
---|
880 |
|
---|
881 | rc = CrBltEnter(pBlitter);
|
---|
882 | if (RT_SUCCESS(rc))
|
---|
883 | {
|
---|
884 | RTRECT ReadRect, DrawRect;
|
---|
885 | ReadRect.xLeft = srcX0;
|
---|
886 | ReadRect.yTop = srcY0;
|
---|
887 | ReadRect.xRight = srcX1;
|
---|
888 | ReadRect.yBottom = srcY1;
|
---|
889 | DrawRect.xLeft = dstX0;
|
---|
890 | DrawRect.yTop = dstY0;
|
---|
891 | DrawRect.xRight = dstX1;
|
---|
892 | DrawRect.yBottom = dstY1;
|
---|
893 | CrBltBlitTexTex(pBlitter, pReadTex, &ReadRect, pDrawTex, &DrawRect, 1, CRBLT_FLAGS_FROM_FILTER(filter));
|
---|
894 | CrBltLeave(pBlitter);
|
---|
895 | }
|
---|
896 | else
|
---|
897 | {
|
---|
898 | crWarning("CrBltEnter failed rc %d", rc);
|
---|
899 | }
|
---|
900 |
|
---|
901 | crStateSwitchPostprocess(ctx, NULL, idDrawFBO, idReadFBO);
|
---|
902 |
|
---|
903 | return rc;
|
---|
904 | }
|
---|
905 |
|
---|
906 | void SERVER_DISPATCH_APIENTRY
|
---|
907 | crServerDispatchBlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
|
---|
908 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
|
---|
909 | GLbitfield mask, GLenum filter)
|
---|
910 | {
|
---|
911 | CRContext *ctx = crStateGetCurrent();
|
---|
912 | bool fTryBlitter = false;
|
---|
913 | #ifdef CR_CHECK_BLITS
|
---|
914 | // {
|
---|
915 | SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table;
|
---|
916 | GLint rfb=0, dfb=0, dtex=0, dlev=-1, rtex=0, rlev=-1, rb=0, db=0, ppb=0, pub=0, vp[4], otex, dstw, dsth;
|
---|
917 | GLint sdtex=0, srtex=0;
|
---|
918 | GLenum dStatus, rStatus;
|
---|
919 |
|
---|
920 | CRTextureObj *tobj = 0;
|
---|
921 | CRTextureLevel *tl = 0;
|
---|
922 | GLint id, tuId, pbufId, pbufIdHw, ubufId, ubufIdHw, width, height, depth;
|
---|
923 |
|
---|
924 | crDebug("===StateTracker===");
|
---|
925 | crDebug("Current TU: %i", ctx->texture.curTextureUnit);
|
---|
926 |
|
---|
927 | tobj = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D;
|
---|
928 | CRASSERT(tobj);
|
---|
929 | tl = &tobj->level[0][0];
|
---|
930 | crDebug("Texture %i(hw %i), w=%i, h=%i", tobj->id, tobj->hwid, tl->width, tl->height, tl->depth);
|
---|
931 |
|
---|
932 | if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
|
---|
933 | {
|
---|
934 | pbufId = ctx->bufferobject.packBuffer->hwid;
|
---|
935 | }
|
---|
936 | else
|
---|
937 | {
|
---|
938 | pbufId = 0;
|
---|
939 | }
|
---|
940 | crDebug("Pack BufferId %i", pbufId);
|
---|
941 |
|
---|
942 | if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
|
---|
943 | {
|
---|
944 | ubufId = ctx->bufferobject.unpackBuffer->hwid;
|
---|
945 | }
|
---|
946 | else
|
---|
947 | {
|
---|
948 | ubufId = 0;
|
---|
949 | }
|
---|
950 | crDebug("Unpack BufferId %i", ubufId);
|
---|
951 |
|
---|
952 | crDebug("===GPU===");
|
---|
953 | cr_server.head_spu->dispatch_table.GetIntegerv(GL_ACTIVE_TEXTURE, &tuId);
|
---|
954 | crDebug("Current TU: %i", tuId - GL_TEXTURE0_ARB);
|
---|
955 | CRASSERT(tuId - GL_TEXTURE0_ARB == ctx->texture.curTextureUnit);
|
---|
956 |
|
---|
957 | cr_server.head_spu->dispatch_table.GetIntegerv(GL_TEXTURE_BINDING_2D, &id);
|
---|
958 | cr_server.head_spu->dispatch_table.GetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
|
---|
959 | cr_server.head_spu->dispatch_table.GetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
|
---|
960 | cr_server.head_spu->dispatch_table.GetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_DEPTH, &depth);
|
---|
961 | crDebug("Texture: %i, w=%i, h=%i, d=%i", id, width, height, depth);
|
---|
962 | CRASSERT(id == tobj->hwid);
|
---|
963 | CRASSERT(width == tl->width);
|
---|
964 | CRASSERT(height == tl->height);
|
---|
965 | CRASSERT(depth == tl->depth);
|
---|
966 |
|
---|
967 | cr_server.head_spu->dispatch_table.GetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &pbufIdHw);
|
---|
968 | crDebug("Hw Pack BufferId %i", pbufIdHw);
|
---|
969 | CRASSERT(pbufIdHw == pbufId);
|
---|
970 |
|
---|
971 | cr_server.head_spu->dispatch_table.GetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &ubufIdHw);
|
---|
972 | crDebug("Hw Unpack BufferId %i", ubufIdHw);
|
---|
973 | CRASSERT(ubufIdHw == ubufId);
|
---|
974 |
|
---|
975 | gl->GetIntegerv(GL_READ_FRAMEBUFFER_BINDING_EXT, &rfb);
|
---|
976 | gl->GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING_EXT, &dfb);
|
---|
977 | gl->GetIntegerv(GL_READ_BUFFER, &rb);
|
---|
978 | gl->GetIntegerv(GL_DRAW_BUFFER, &db);
|
---|
979 |
|
---|
980 | gl->GetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &ppb);
|
---|
981 | gl->GetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &pub);
|
---|
982 |
|
---|
983 | gl->GetIntegerv(GL_VIEWPORT, &vp[0]);
|
---|
984 |
|
---|
985 | gl->GetIntegerv(GL_TEXTURE_BINDING_2D, &otex);
|
---|
986 |
|
---|
987 | gl->GetFramebufferAttachmentParameterivEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT, &dtex);
|
---|
988 | gl->GetFramebufferAttachmentParameterivEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT, &dlev);
|
---|
989 | dStatus = gl->CheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT);
|
---|
990 |
|
---|
991 | gl->GetFramebufferAttachmentParameterivEXT(GL_READ_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT, &rtex);
|
---|
992 | gl->GetFramebufferAttachmentParameterivEXT(GL_READ_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT, &rlev);
|
---|
993 | rStatus = gl->CheckFramebufferStatusEXT(GL_READ_FRAMEBUFFER_EXT);
|
---|
994 |
|
---|
995 | if (dtex)
|
---|
996 | {
|
---|
997 | CRASSERT(!dlev);
|
---|
998 | }
|
---|
999 |
|
---|
1000 | if (rtex)
|
---|
1001 | {
|
---|
1002 | CRASSERT(!rlev);
|
---|
1003 | }
|
---|
1004 |
|
---|
1005 | if (ctx->framebufferobject.drawFB)
|
---|
1006 | {
|
---|
1007 | CRASSERT(dfb);
|
---|
1008 | CRASSERT(ctx->framebufferobject.drawFB->hwid == dfb);
|
---|
1009 | CRASSERT(ctx->framebufferobject.drawFB->drawbuffer[0] == db);
|
---|
1010 |
|
---|
1011 | CRASSERT(dStatus==GL_FRAMEBUFFER_COMPLETE_EXT);
|
---|
1012 | CRASSERT(db==GL_COLOR_ATTACHMENT0_EXT);
|
---|
1013 |
|
---|
1014 | CRASSERT(ctx->framebufferobject.drawFB->color[0].type == GL_TEXTURE);
|
---|
1015 | CRASSERT(ctx->framebufferobject.drawFB->color[0].level == 0);
|
---|
1016 | sdtex = ctx->framebufferobject.drawFB->color[0].name;
|
---|
1017 | sdtex = crStateGetTextureHWID(sdtex);
|
---|
1018 |
|
---|
1019 | CRASSERT(sdtex);
|
---|
1020 | }
|
---|
1021 | else
|
---|
1022 | {
|
---|
1023 | CRASSERT(!dfb);
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 | if (ctx->framebufferobject.readFB)
|
---|
1027 | {
|
---|
1028 | CRASSERT(rfb);
|
---|
1029 | CRASSERT(ctx->framebufferobject.readFB->hwid == rfb);
|
---|
1030 |
|
---|
1031 | CRASSERT(rStatus==GL_FRAMEBUFFER_COMPLETE_EXT);
|
---|
1032 |
|
---|
1033 | CRASSERT(ctx->framebufferobject.readFB->color[0].type == GL_TEXTURE);
|
---|
1034 | CRASSERT(ctx->framebufferobject.readFB->color[0].level == 0);
|
---|
1035 | srtex = ctx->framebufferobject.readFB->color[0].name;
|
---|
1036 | srtex = crStateGetTextureHWID(srtex);
|
---|
1037 |
|
---|
1038 | CRASSERT(srtex);
|
---|
1039 | }
|
---|
1040 | else
|
---|
1041 | {
|
---|
1042 | CRASSERT(!rfb);
|
---|
1043 | }
|
---|
1044 |
|
---|
1045 | CRASSERT(sdtex == dtex);
|
---|
1046 | CRASSERT(srtex == rtex);
|
---|
1047 |
|
---|
1048 | // crDbgDumpTexImage2D("==> src tex:", GL_TEXTURE_2D, rtex, true);
|
---|
1049 | // crDbgDumpTexImage2D("==> dst tex:", GL_TEXTURE_2D, dtex, true);
|
---|
1050 |
|
---|
1051 | // }
|
---|
1052 | #endif
|
---|
1053 | #ifdef CR_DUMP_BLITS
|
---|
1054 | SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table;
|
---|
1055 | GLint rfb=0, dfb=0, dtex=0, dlev=-1, rb=0, db=0, ppb=0, pub=0, vp[4], otex, dstw, dsth;
|
---|
1056 | GLenum status;
|
---|
1057 | char fname[200];
|
---|
1058 | void *img;
|
---|
1059 |
|
---|
1060 | blitnum++;
|
---|
1061 |
|
---|
1062 | crDebug("[%i]BlitFramebufferEXT(%i, %i, %i, %i, %i, %i, %i, %i, %x, %x)", blitnum, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
|
---|
1063 | crDebug("%i, %i <-> %i, %i", srcX1-srcX0, srcY1-srcY0, dstX1-dstX0, dstY1-dstY0);
|
---|
1064 |
|
---|
1065 | gl->GetIntegerv(GL_READ_FRAMEBUFFER_BINDING_EXT, &rfb);
|
---|
1066 | gl->GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING_EXT, &dfb);
|
---|
1067 | gl->GetIntegerv(GL_READ_BUFFER, &rb);
|
---|
1068 | gl->GetIntegerv(GL_DRAW_BUFFER, &db);
|
---|
1069 |
|
---|
1070 | gl->GetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &ppb);
|
---|
1071 | gl->GetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &pub);
|
---|
1072 |
|
---|
1073 | gl->GetIntegerv(GL_VIEWPORT, &vp[0]);
|
---|
1074 |
|
---|
1075 | gl->GetIntegerv(GL_TEXTURE_BINDING_2D, &otex);
|
---|
1076 |
|
---|
1077 | CRASSERT(!rfb && dfb);
|
---|
1078 | gl->GetFramebufferAttachmentParameterivEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT, &dtex);
|
---|
1079 | gl->GetFramebufferAttachmentParameterivEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT, &dlev);
|
---|
1080 | status = gl->CheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT);
|
---|
1081 |
|
---|
1082 | CRASSERT(status==GL_FRAMEBUFFER_COMPLETE_EXT
|
---|
1083 | && db==GL_COLOR_ATTACHMENT0_EXT
|
---|
1084 | && (rb==GL_FRONT || rb==GL_BACK)
|
---|
1085 | && !rfb && dfb && dtex && !dlev
|
---|
1086 | && !ppb && !pub);
|
---|
1087 |
|
---|
1088 | crDebug("Src[rb 0x%x, fbo %i] Dst[db 0x%x, fbo %i(0x%x), tex %i.%i]", rb, rfb, db, dfb, status, dtex, dlev);
|
---|
1089 | crDebug("Viewport [%i, %i, %i, %i]", vp[0], vp[1], vp[2], vp[3]);
|
---|
1090 |
|
---|
1091 | gl->PixelStorei(GL_PACK_ROW_LENGTH, 0);
|
---|
1092 | gl->PixelStorei(GL_PACK_ALIGNMENT, 1);
|
---|
1093 | gl->PixelStorei(GL_PACK_SKIP_PIXELS, 0);
|
---|
1094 | gl->PixelStorei(GL_PACK_SKIP_ROWS, 0);
|
---|
1095 |
|
---|
1096 | gl->PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
---|
1097 | gl->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
---|
1098 | gl->PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
|
---|
1099 | gl->PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
|
---|
1100 |
|
---|
1101 | gl->BindTexture(GL_TEXTURE_2D, dtex);
|
---|
1102 | gl->GetTexLevelParameteriv(GL_TEXTURE_2D, dlev, GL_TEXTURE_WIDTH, &dstw);
|
---|
1103 | gl->GetTexLevelParameteriv(GL_TEXTURE_2D, dlev, GL_TEXTURE_HEIGHT, &dsth);
|
---|
1104 | gl->BindTexture(GL_TEXTURE_2D, otex);
|
---|
1105 | crDebug("Dst is %i, %i", dstw, dsth);
|
---|
1106 |
|
---|
1107 | CRASSERT(vp[2]>=dstw && vp[3]>=dsth);
|
---|
1108 | img = crAlloc(vp[2]*vp[3]*4);
|
---|
1109 | CRASSERT(img);
|
---|
1110 |
|
---|
1111 | gl->ReadPixels(0, 0, vp[2], vp[3], GL_BGRA, GL_UNSIGNED_BYTE, img);
|
---|
1112 | sprintf(fname, "blit%iA_src.tga", blitnum);
|
---|
1113 | crDumpNamedTGA(fname, vp[2], vp[3], img);
|
---|
1114 |
|
---|
1115 | gl->BindTexture(GL_TEXTURE_2D, dtex);
|
---|
1116 | gl->GetTexImage(GL_TEXTURE_2D, dlev, GL_BGRA, GL_UNSIGNED_BYTE, img);
|
---|
1117 | sprintf(fname, "blit%iB_dst.tga", blitnum);
|
---|
1118 | crDumpNamedTGA(fname, dstw, dsth, img);
|
---|
1119 | gl->BindTexture(GL_TEXTURE_2D, otex);
|
---|
1120 | #endif
|
---|
1121 |
|
---|
1122 | if (srcY0 > srcY1)
|
---|
1123 | {
|
---|
1124 | /* work around Intel driver bug on Linux host */
|
---|
1125 | if (1 || dstY0 > dstY1)
|
---|
1126 | {
|
---|
1127 | /* use srcY1 < srcY2 && dstY1 < dstY2 whenever possible to avoid GPU driver bugs */
|
---|
1128 | int32_t tmp = srcY0;
|
---|
1129 | srcY0 = srcY1;
|
---|
1130 | srcY1 = tmp;
|
---|
1131 | tmp = dstY0;
|
---|
1132 | dstY0 = dstY1;
|
---|
1133 | dstY1 = tmp;
|
---|
1134 | }
|
---|
1135 | }
|
---|
1136 |
|
---|
1137 | if (srcX0 > srcX1)
|
---|
1138 | {
|
---|
1139 | if (dstX0 > dstX1)
|
---|
1140 | {
|
---|
1141 | /* use srcX1 < srcX2 && dstX1 < dstX2 whenever possible to avoid GPU driver bugs */
|
---|
1142 | int32_t tmp = srcX0;
|
---|
1143 | srcX0 = srcX1;
|
---|
1144 | srcX1 = tmp;
|
---|
1145 | tmp = dstX0;
|
---|
1146 | dstX0 = dstX1;
|
---|
1147 | dstX1 = tmp;
|
---|
1148 | }
|
---|
1149 | }
|
---|
1150 |
|
---|
1151 | if (cr_server.fBlitterMode)
|
---|
1152 | {
|
---|
1153 | fTryBlitter = true;
|
---|
1154 | }
|
---|
1155 |
|
---|
1156 | if (fTryBlitter)
|
---|
1157 | {
|
---|
1158 | int rc = crServerVBoxBlitterBlitCurrentCtx(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
|
---|
1159 | if (RT_SUCCESS(rc))
|
---|
1160 | goto my_exit;
|
---|
1161 | }
|
---|
1162 |
|
---|
1163 | if (ctx->viewport.scissorTest)
|
---|
1164 | cr_server.head_spu->dispatch_table.Disable(GL_SCISSOR_TEST);
|
---|
1165 |
|
---|
1166 | cr_server.head_spu->dispatch_table.BlitFramebufferEXT(srcX0, srcY0, srcX1, srcY1,
|
---|
1167 | dstX0, dstY0, dstX1, dstY1,
|
---|
1168 | mask, filter);
|
---|
1169 |
|
---|
1170 | if (ctx->viewport.scissorTest)
|
---|
1171 | cr_server.head_spu->dispatch_table.Enable(GL_SCISSOR_TEST);
|
---|
1172 |
|
---|
1173 |
|
---|
1174 | my_exit:
|
---|
1175 |
|
---|
1176 | //#ifdef CR_CHECK_BLITS
|
---|
1177 | // crDbgDumpTexImage2D("<== src tex:", GL_TEXTURE_2D, rtex, true);
|
---|
1178 | // crDbgDumpTexImage2D("<== dst tex:", GL_TEXTURE_2D, dtex, true);
|
---|
1179 | //#endif
|
---|
1180 | #ifdef CR_DUMP_BLITS
|
---|
1181 | gl->BindTexture(GL_TEXTURE_2D, dtex);
|
---|
1182 | gl->GetTexImage(GL_TEXTURE_2D, dlev, GL_BGRA, GL_UNSIGNED_BYTE, img);
|
---|
1183 | sprintf(fname, "blit%iC_res.tga", blitnum);
|
---|
1184 | crDumpNamedTGA(fname, dstw, dsth, img);
|
---|
1185 | gl->BindTexture(GL_TEXTURE_2D, otex);
|
---|
1186 | crFree(img);
|
---|
1187 | #endif
|
---|
1188 | return;
|
---|
1189 | }
|
---|
1190 |
|
---|
1191 | void SERVER_DISPATCH_APIENTRY crServerDispatchDrawBuffer( GLenum mode )
|
---|
1192 | {
|
---|
1193 | crStateDrawBuffer( mode );
|
---|
1194 |
|
---|
1195 | if (!crStateGetCurrent()->framebufferobject.drawFB)
|
---|
1196 | {
|
---|
1197 | if (mode == GL_FRONT || mode == GL_FRONT_LEFT || mode == GL_FRONT_RIGHT)
|
---|
1198 | cr_server.curClient->currentMural->bFbDraw = GL_TRUE;
|
---|
1199 |
|
---|
1200 | if (crServerIsRedirectedToFBO()
|
---|
1201 | && cr_server.curClient->currentMural->aidFBOs[0])
|
---|
1202 | {
|
---|
1203 | CRMuralInfo *mural = cr_server.curClient->currentMural;
|
---|
1204 | GLint iBufferNeeded = -1;
|
---|
1205 | switch (mode)
|
---|
1206 | {
|
---|
1207 | case GL_BACK:
|
---|
1208 | case GL_BACK_LEFT:
|
---|
1209 | case GL_BACK_RIGHT:
|
---|
1210 | mode = GL_COLOR_ATTACHMENT0;
|
---|
1211 | iBufferNeeded = CR_SERVER_FBO_BB_IDX(mural);
|
---|
1212 | break;
|
---|
1213 | case GL_FRONT:
|
---|
1214 | case GL_FRONT_LEFT:
|
---|
1215 | case GL_FRONT_RIGHT:
|
---|
1216 | mode = GL_COLOR_ATTACHMENT0;
|
---|
1217 | iBufferNeeded = CR_SERVER_FBO_FB_IDX(mural);
|
---|
1218 | break;
|
---|
1219 | case GL_NONE:
|
---|
1220 | crDebug("DrawBuffer: GL_NONE");
|
---|
1221 | break;
|
---|
1222 | case GL_AUX0:
|
---|
1223 | crDebug("DrawBuffer: GL_AUX0");
|
---|
1224 | break;
|
---|
1225 | case GL_AUX1:
|
---|
1226 | crDebug("DrawBuffer: GL_AUX1");
|
---|
1227 | break;
|
---|
1228 | case GL_AUX2:
|
---|
1229 | crDebug("DrawBuffer: GL_AUX2");
|
---|
1230 | break;
|
---|
1231 | case GL_AUX3:
|
---|
1232 | crDebug("DrawBuffer: GL_AUX3");
|
---|
1233 | break;
|
---|
1234 | case GL_LEFT:
|
---|
1235 | crWarning("DrawBuffer: GL_LEFT not supported properly");
|
---|
1236 | mode = GL_COLOR_ATTACHMENT0;
|
---|
1237 | iBufferNeeded = CR_SERVER_FBO_BB_IDX(mural);
|
---|
1238 | break;
|
---|
1239 | case GL_RIGHT:
|
---|
1240 | crWarning("DrawBuffer: GL_RIGHT not supported properly");
|
---|
1241 | mode = GL_COLOR_ATTACHMENT0;
|
---|
1242 | iBufferNeeded = CR_SERVER_FBO_BB_IDX(mural);
|
---|
1243 | break;
|
---|
1244 | case GL_FRONT_AND_BACK:
|
---|
1245 | crWarning("DrawBuffer: GL_FRONT_AND_BACK not supported properly");
|
---|
1246 | mode = GL_COLOR_ATTACHMENT0;
|
---|
1247 | iBufferNeeded = CR_SERVER_FBO_BB_IDX(mural);
|
---|
1248 | break;
|
---|
1249 | default:
|
---|
1250 | crWarning("DrawBuffer: unexpected mode! 0x%x", mode);
|
---|
1251 | iBufferNeeded = mural->iCurDrawBuffer;
|
---|
1252 | break;
|
---|
1253 | }
|
---|
1254 |
|
---|
1255 | if (iBufferNeeded != mural->iCurDrawBuffer)
|
---|
1256 | {
|
---|
1257 | mural->iCurDrawBuffer = iBufferNeeded;
|
---|
1258 | cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, CR_SERVER_FBO_FOR_IDX(mural, iBufferNeeded));
|
---|
1259 | }
|
---|
1260 | }
|
---|
1261 | }
|
---|
1262 |
|
---|
1263 | cr_server.head_spu->dispatch_table.DrawBuffer( mode );
|
---|
1264 | }
|
---|
1265 |
|
---|
1266 | void SERVER_DISPATCH_APIENTRY crServerDispatchReadBuffer( GLenum mode )
|
---|
1267 | {
|
---|
1268 | crStateReadBuffer( mode );
|
---|
1269 |
|
---|
1270 | if (crServerIsRedirectedToFBO()
|
---|
1271 | && cr_server.curClient->currentMural->aidFBOs[0]
|
---|
1272 | && !crStateGetCurrent()->framebufferobject.readFB)
|
---|
1273 | {
|
---|
1274 | CRMuralInfo *mural = cr_server.curClient->currentMural;
|
---|
1275 | GLint iBufferNeeded = -1;
|
---|
1276 | switch (mode)
|
---|
1277 | {
|
---|
1278 | case GL_BACK:
|
---|
1279 | case GL_BACK_LEFT:
|
---|
1280 | case GL_BACK_RIGHT:
|
---|
1281 | mode = GL_COLOR_ATTACHMENT0;
|
---|
1282 | iBufferNeeded = CR_SERVER_FBO_BB_IDX(mural);
|
---|
1283 | break;
|
---|
1284 | case GL_FRONT:
|
---|
1285 | case GL_FRONT_LEFT:
|
---|
1286 | case GL_FRONT_RIGHT:
|
---|
1287 | mode = GL_COLOR_ATTACHMENT0;
|
---|
1288 | iBufferNeeded = CR_SERVER_FBO_FB_IDX(mural);
|
---|
1289 | break;
|
---|
1290 | case GL_NONE:
|
---|
1291 | crDebug("ReadBuffer: GL_NONE");
|
---|
1292 | break;
|
---|
1293 | case GL_AUX0:
|
---|
1294 | crDebug("ReadBuffer: GL_AUX0");
|
---|
1295 | break;
|
---|
1296 | case GL_AUX1:
|
---|
1297 | crDebug("ReadBuffer: GL_AUX1");
|
---|
1298 | break;
|
---|
1299 | case GL_AUX2:
|
---|
1300 | crDebug("ReadBuffer: GL_AUX2");
|
---|
1301 | break;
|
---|
1302 | case GL_AUX3:
|
---|
1303 | crDebug("ReadBuffer: GL_AUX3");
|
---|
1304 | break;
|
---|
1305 | case GL_LEFT:
|
---|
1306 | crWarning("ReadBuffer: GL_LEFT not supported properly");
|
---|
1307 | mode = GL_COLOR_ATTACHMENT0;
|
---|
1308 | iBufferNeeded = CR_SERVER_FBO_BB_IDX(mural);
|
---|
1309 | break;
|
---|
1310 | case GL_RIGHT:
|
---|
1311 | crWarning("ReadBuffer: GL_RIGHT not supported properly");
|
---|
1312 | mode = GL_COLOR_ATTACHMENT0;
|
---|
1313 | iBufferNeeded = CR_SERVER_FBO_BB_IDX(mural);
|
---|
1314 | break;
|
---|
1315 | case GL_FRONT_AND_BACK:
|
---|
1316 | crWarning("ReadBuffer: GL_FRONT_AND_BACK not supported properly");
|
---|
1317 | mode = GL_COLOR_ATTACHMENT0;
|
---|
1318 | iBufferNeeded = CR_SERVER_FBO_BB_IDX(mural);
|
---|
1319 | break;
|
---|
1320 | default:
|
---|
1321 | crWarning("ReadBuffer: unexpected mode! 0x%x", mode);
|
---|
1322 | iBufferNeeded = mural->iCurDrawBuffer;
|
---|
1323 | break;
|
---|
1324 | }
|
---|
1325 |
|
---|
1326 | Assert(CR_SERVER_FBO_FOR_IDX(mural, mural->iCurReadBuffer));
|
---|
1327 | if (iBufferNeeded != mural->iCurReadBuffer)
|
---|
1328 | {
|
---|
1329 | mural->iCurReadBuffer = iBufferNeeded;
|
---|
1330 | cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, CR_SERVER_FBO_FOR_IDX(mural, iBufferNeeded));
|
---|
1331 | }
|
---|
1332 | }
|
---|
1333 | cr_server.head_spu->dispatch_table.ReadBuffer( mode );
|
---|
1334 | }
|
---|
1335 |
|
---|
1336 | GLenum SERVER_DISPATCH_APIENTRY crServerDispatchGetError( void )
|
---|
1337 | {
|
---|
1338 | GLenum retval, err;
|
---|
1339 | CRContext *ctx = crStateGetCurrent();
|
---|
1340 | retval = ctx->error;
|
---|
1341 |
|
---|
1342 | err = cr_server.head_spu->dispatch_table.GetError();
|
---|
1343 | if (retval == GL_NO_ERROR)
|
---|
1344 | retval = err;
|
---|
1345 | else
|
---|
1346 | ctx->error = GL_NO_ERROR;
|
---|
1347 |
|
---|
1348 | /* our impl has a single error flag, so we just loop here to reset all error flags to no_error */
|
---|
1349 | while (err != GL_NO_ERROR)
|
---|
1350 | err = cr_server.head_spu->dispatch_table.GetError();
|
---|
1351 |
|
---|
1352 | crServerReturnValue( &retval, sizeof(retval) );
|
---|
1353 | return retval; /* WILL PROBABLY BE IGNORED */
|
---|
1354 | }
|
---|
1355 |
|
---|
1356 | void SERVER_DISPATCH_APIENTRY
|
---|
1357 | crServerMakeTmpCtxCurrent( GLint window, GLint nativeWindow, GLint context )
|
---|
1358 | {
|
---|
1359 | CRContext *pCtx = crStateGetCurrent();
|
---|
1360 | CRContext *pCurCtx = NULL;
|
---|
1361 | GLuint idDrawFBO = 0, idReadFBO = 0;
|
---|
1362 | int fDoPrePostProcess = 0;
|
---|
1363 |
|
---|
1364 | if (pCtx)
|
---|
1365 | {
|
---|
1366 | CRMuralInfo *pCurrentMural = cr_server.currentMural;
|
---|
1367 |
|
---|
1368 | pCurCtx = cr_server.currentCtxInfo ? cr_server.currentCtxInfo->pContext : cr_server.MainContextInfo.pContext;
|
---|
1369 | Assert(pCurCtx == pCtx);
|
---|
1370 |
|
---|
1371 | if (!context)
|
---|
1372 | {
|
---|
1373 | if (pCurrentMural)
|
---|
1374 | {
|
---|
1375 | Assert(cr_server.currentCtxInfo);
|
---|
1376 | context = cr_server.currentCtxInfo->SpuContext > 0 ? cr_server.currentCtxInfo->SpuContext : cr_server.MainContextInfo.SpuContext;
|
---|
1377 | window = pCurrentMural->spuWindow;
|
---|
1378 | }
|
---|
1379 | else
|
---|
1380 | {
|
---|
1381 | CRMuralInfo * pDummy;
|
---|
1382 | Assert(!cr_server.currentCtxInfo);
|
---|
1383 | pDummy = crServerGetDummyMural(cr_server.MainContextInfo.CreateInfo.realVisualBits);
|
---|
1384 | context = cr_server.MainContextInfo.SpuContext;
|
---|
1385 | window = pDummy->spuWindow;
|
---|
1386 | }
|
---|
1387 |
|
---|
1388 |
|
---|
1389 | fDoPrePostProcess = -1;
|
---|
1390 | }
|
---|
1391 | else
|
---|
1392 | {
|
---|
1393 | fDoPrePostProcess = 1;
|
---|
1394 | }
|
---|
1395 |
|
---|
1396 | if (pCurrentMural)
|
---|
1397 | {
|
---|
1398 | idDrawFBO = CR_SERVER_FBO_FOR_IDX(pCurrentMural, pCurrentMural->iCurDrawBuffer);
|
---|
1399 | idReadFBO = CR_SERVER_FBO_FOR_IDX(pCurrentMural, pCurrentMural->iCurReadBuffer);
|
---|
1400 | }
|
---|
1401 | else
|
---|
1402 | {
|
---|
1403 | idDrawFBO = 0;
|
---|
1404 | idReadFBO = 0;
|
---|
1405 | }
|
---|
1406 | }
|
---|
1407 | else
|
---|
1408 | {
|
---|
1409 | /* this is a GUI thread, so no need to do anything here */
|
---|
1410 | }
|
---|
1411 |
|
---|
1412 | if (fDoPrePostProcess > 0)
|
---|
1413 | crStateSwitchPrepare(NULL, pCurCtx, idDrawFBO, idReadFBO);
|
---|
1414 |
|
---|
1415 | cr_server.head_spu->dispatch_table.MakeCurrent( window, nativeWindow, context);
|
---|
1416 |
|
---|
1417 | if (fDoPrePostProcess < 0)
|
---|
1418 | crStateSwitchPostprocess(pCurCtx, NULL, idDrawFBO, idReadFBO);
|
---|
1419 | }
|
---|
1420 |
|
---|
1421 | void crServerInitTmpCtxDispatch()
|
---|
1422 | {
|
---|
1423 | MakeCurrentFunc_t pfnMakeCurrent;
|
---|
1424 |
|
---|
1425 | crSPUInitDispatchTable(&cr_server.TmpCtxDispatch);
|
---|
1426 | crSPUCopyDispatchTable(&cr_server.TmpCtxDispatch, &cr_server.head_spu->dispatch_table);
|
---|
1427 | cr_server.TmpCtxDispatch.MakeCurrent = crServerMakeTmpCtxCurrent;
|
---|
1428 |
|
---|
1429 | pfnMakeCurrent = crServerMakeTmpCtxCurrent;
|
---|
1430 | cr_server.head_spu->dispatch_table.ChromiumParametervCR(GL_HH_SET_TMPCTX_MAKE_CURRENT, GL_BYTE, sizeof (void*), &pfnMakeCurrent);
|
---|
1431 |
|
---|
1432 | }
|
---|
1433 |
|
---|
1434 | /* dump stuff */
|
---|
1435 | #ifdef VBOX_WITH_CRSERVER_DUMPER
|
---|
1436 |
|
---|
1437 | /* first four bits are buffer dump config
|
---|
1438 | * second four bits are texture dump config
|
---|
1439 | * config flags:
|
---|
1440 | * 1 - blit on enter
|
---|
1441 | * 2 - blit on exit
|
---|
1442 | *
|
---|
1443 | *
|
---|
1444 | * Example:
|
---|
1445 | *
|
---|
1446 | * 0x03 - dump buffer on enter and exit
|
---|
1447 | * 0x22 - dump texture and buffer on exit */
|
---|
1448 |
|
---|
1449 | int64_t g_CrDbgDumpPid = 0;
|
---|
1450 | unsigned long g_CrDbgDumpEnabled = 0;
|
---|
1451 | unsigned long g_CrDbgDumpDraw = 0
|
---|
1452 | #if 0
|
---|
1453 | | CR_SERVER_DUMP_F_COMPILE_SHADER
|
---|
1454 | | CR_SERVER_DUMP_F_LINK_PROGRAM
|
---|
1455 | #endif
|
---|
1456 | ;
|
---|
1457 | #if 0
|
---|
1458 | | CR_SERVER_DUMP_F_DRAW_BUFF_ENTER
|
---|
1459 | | CR_SERVER_DUMP_F_DRAW_BUFF_LEAVE
|
---|
1460 | | CR_SERVER_DUMP_F_DRAW_PROGRAM_UNIFORMS_ENTER
|
---|
1461 | | CR_SERVER_DUMP_F_DRAW_PROGRAM_ATTRIBS_ENTER
|
---|
1462 | | CR_SERVER_DUMP_F_DRAW_TEX_ENTER
|
---|
1463 | | CR_SERVER_DUMP_F_DRAW_PROGRAM_ENTER
|
---|
1464 | | CR_SERVER_DUMP_F_DRAW_STATE_ENTER
|
---|
1465 | | CR_SERVER_DUMP_F_SWAPBUFFERS_ENTER
|
---|
1466 | | CR_SERVER_DUMP_F_DRAWEL
|
---|
1467 | | CR_SERVER_DUMP_F_SHADER_SOURCE
|
---|
1468 | ;
|
---|
1469 | #endif
|
---|
1470 | unsigned long g_CrDbgDumpDrawFramesSettings = CR_SERVER_DUMP_F_DRAW_BUFF_ENTER
|
---|
1471 | | CR_SERVER_DUMP_F_DRAW_BUFF_LEAVE
|
---|
1472 | | CR_SERVER_DUMP_F_DRAW_TEX_ENTER
|
---|
1473 | | CR_SERVER_DUMP_F_DRAW_PROGRAM_ENTER
|
---|
1474 | | CR_SERVER_DUMP_F_COMPILE_SHADER
|
---|
1475 | | CR_SERVER_DUMP_F_LINK_PROGRAM
|
---|
1476 | | CR_SERVER_DUMP_F_SWAPBUFFERS_ENTER;
|
---|
1477 | unsigned long g_CrDbgDumpDrawFramesAppliedSettings = 0;
|
---|
1478 | unsigned long g_CrDbgDumpDrawFramesSavedInitSettings = 0;
|
---|
1479 | unsigned long g_CrDbgDumpDrawFramesCount = 0;
|
---|
1480 |
|
---|
1481 | uint32_t g_CrDbgDumpDrawCount = 0;
|
---|
1482 | uint32_t g_CrDbgDumpDumpOnCount = 10;
|
---|
1483 | uint32_t g_CrDbgDumpDumpOnCountEnabled = 0;
|
---|
1484 | uint32_t g_CrDbgDumpDumpOnCountPerform = 0;
|
---|
1485 | uint32_t g_CrDbgDumpDrawFlags = CR_SERVER_DUMP_F_COMPILE_SHADER
|
---|
1486 | | CR_SERVER_DUMP_F_SHADER_SOURCE
|
---|
1487 | | CR_SERVER_DUMP_F_COMPILE_SHADER
|
---|
1488 | | CR_SERVER_DUMP_F_LINK_PROGRAM
|
---|
1489 | | CR_SERVER_DUMP_F_DRAW_BUFF_ENTER
|
---|
1490 | | CR_SERVER_DUMP_F_DRAW_BUFF_LEAVE
|
---|
1491 | | CR_SERVER_DUMP_F_DRAW_TEX_ENTER
|
---|
1492 | | CR_SERVER_DUMP_F_DRAW_PROGRAM_UNIFORMS_ENTER
|
---|
1493 | | CR_SERVER_DUMP_F_DRAW_PROGRAM_ATTRIBS_ENTER
|
---|
1494 | | CR_SERVER_DUMP_F_DRAW_PROGRAM_ENTER
|
---|
1495 | | CR_SERVER_DUMP_F_DRAW_STATE_ENTER
|
---|
1496 | | CR_SERVER_DUMP_F_SWAPBUFFERS_ENTER
|
---|
1497 | | CR_SERVER_DUMP_F_DRAWEL
|
---|
1498 | | CR_SERVER_DUMP_F_TEXPRESENT;
|
---|
1499 |
|
---|
1500 | void crServerDumpCheckTerm()
|
---|
1501 | {
|
---|
1502 | if (!CrBltIsInitialized(&cr_server.RecorderBlitter))
|
---|
1503 | return;
|
---|
1504 |
|
---|
1505 | CrBltTerm(&cr_server.RecorderBlitter);
|
---|
1506 | }
|
---|
1507 |
|
---|
1508 | int crServerDumpCheckInit()
|
---|
1509 | {
|
---|
1510 | int rc;
|
---|
1511 | CR_BLITTER_WINDOW BltWin;
|
---|
1512 | CR_BLITTER_CONTEXT BltCtx;
|
---|
1513 | CRMuralInfo *pBlitterMural;
|
---|
1514 |
|
---|
1515 | if (!CrBltIsInitialized(&cr_server.RecorderBlitter))
|
---|
1516 | {
|
---|
1517 | pBlitterMural = crServerGetDummyMural(cr_server.MainContextInfo.CreateInfo.realVisualBits);
|
---|
1518 | if (!pBlitterMural)
|
---|
1519 | {
|
---|
1520 | crWarning("crServerGetDummyMural failed");
|
---|
1521 | return VERR_GENERAL_FAILURE;
|
---|
1522 | }
|
---|
1523 |
|
---|
1524 | crServerVBoxBlitterWinInit(&BltWin, pBlitterMural);
|
---|
1525 | crServerVBoxBlitterCtxInit(&BltCtx, &cr_server.MainContextInfo);
|
---|
1526 |
|
---|
1527 | rc = CrBltInit(&cr_server.RecorderBlitter, &BltCtx, true, true, NULL, &cr_server.TmpCtxDispatch);
|
---|
1528 | if (!RT_SUCCESS(rc))
|
---|
1529 | {
|
---|
1530 | crWarning("CrBltInit failed rc %d", rc);
|
---|
1531 | return rc;
|
---|
1532 | }
|
---|
1533 |
|
---|
1534 | rc = CrBltMuralSetCurrentInfo(&cr_server.RecorderBlitter, &BltWin);
|
---|
1535 | if (!RT_SUCCESS(rc))
|
---|
1536 | {
|
---|
1537 | crWarning("CrBltMuralSetCurrentInfo failed rc %d", rc);
|
---|
1538 | return rc;
|
---|
1539 | }
|
---|
1540 | }
|
---|
1541 |
|
---|
1542 | #if 0
|
---|
1543 | crDmpDbgPrintInit(&cr_server.DbgPrintDumper);
|
---|
1544 | cr_server.pDumper = &cr_server.DbgPrintDumper.Base;
|
---|
1545 | #else
|
---|
1546 | if (!crDmpHtmlIsInited(&cr_server.HtmlDumper))
|
---|
1547 | {
|
---|
1548 | static int cCounter = 0;
|
---|
1549 | // crDmpHtmlInit(&cr_server.HtmlDumper, "S:\\projects\\virtualbox\\3d\\dumps\\1", "index.html");
|
---|
1550 | crDmpHtmlInitF(&cr_server.HtmlDumper, "/Users/oracle-mac/vbox/dump/1", "index%d.html", cCounter);
|
---|
1551 | cr_server.pDumper = &cr_server.HtmlDumper.Base;
|
---|
1552 | ++cCounter;
|
---|
1553 | }
|
---|
1554 | #endif
|
---|
1555 |
|
---|
1556 | crRecInit(&cr_server.Recorder, &cr_server.RecorderBlitter, &cr_server.TmpCtxDispatch, cr_server.pDumper);
|
---|
1557 | return VINF_SUCCESS;
|
---|
1558 | }
|
---|
1559 |
|
---|
1560 | void crServerDumpShader(GLint id)
|
---|
1561 | {
|
---|
1562 | CRContext *ctx = crStateGetCurrent();
|
---|
1563 | crRecDumpShader(&cr_server.Recorder, ctx, id, 0);
|
---|
1564 | }
|
---|
1565 |
|
---|
1566 | void crServerDumpProgram(GLint id)
|
---|
1567 | {
|
---|
1568 | CRContext *ctx = crStateGetCurrent();
|
---|
1569 | crRecDumpProgram(&cr_server.Recorder, ctx, id, 0);
|
---|
1570 | }
|
---|
1571 |
|
---|
1572 | void crServerDumpCurrentProgram()
|
---|
1573 | {
|
---|
1574 | CRContext *ctx = crStateGetCurrent();
|
---|
1575 | crRecDumpCurrentProgram(&cr_server.Recorder, ctx);
|
---|
1576 | }
|
---|
1577 |
|
---|
1578 | void crServerDumpRecompileDumpCurrentProgram()
|
---|
1579 | {
|
---|
1580 | crDmpStrF(cr_server.Recorder.pDumper, "==Dump(1)==");
|
---|
1581 | crServerRecompileCurrentProgram();
|
---|
1582 | crServerDumpCurrentProgramUniforms();
|
---|
1583 | crServerDumpCurrentProgramAttribs();
|
---|
1584 | crDmpStrF(cr_server.Recorder.pDumper, "Done Dump(1)");
|
---|
1585 | crServerRecompileCurrentProgram();
|
---|
1586 | crDmpStrF(cr_server.Recorder.pDumper, "Dump(2)");
|
---|
1587 | crServerRecompileCurrentProgram();
|
---|
1588 | crServerDumpCurrentProgramUniforms();
|
---|
1589 | crServerDumpCurrentProgramAttribs();
|
---|
1590 | crDmpStrF(cr_server.Recorder.pDumper, "Done Dump(2)");
|
---|
1591 | }
|
---|
1592 |
|
---|
1593 | void crServerRecompileCurrentProgram()
|
---|
1594 | {
|
---|
1595 | CRContext *ctx = crStateGetCurrent();
|
---|
1596 | crRecRecompileCurrentProgram(&cr_server.Recorder, ctx);
|
---|
1597 | }
|
---|
1598 |
|
---|
1599 | void crServerDumpCurrentProgramUniforms()
|
---|
1600 | {
|
---|
1601 | CRContext *ctx = crStateGetCurrent();
|
---|
1602 | crDmpStrF(cr_server.Recorder.pDumper, "==Uniforms==");
|
---|
1603 | crRecDumpCurrentProgramUniforms(&cr_server.Recorder, ctx);
|
---|
1604 | crDmpStrF(cr_server.Recorder.pDumper, "==Done Uniforms==");
|
---|
1605 | }
|
---|
1606 |
|
---|
1607 | void crServerDumpCurrentProgramAttribs()
|
---|
1608 | {
|
---|
1609 | CRContext *ctx = crStateGetCurrent();
|
---|
1610 | crDmpStrF(cr_server.Recorder.pDumper, "==Attribs==");
|
---|
1611 | crRecDumpCurrentProgramAttribs(&cr_server.Recorder, ctx);
|
---|
1612 | crDmpStrF(cr_server.Recorder.pDumper, "==Done Attribs==");
|
---|
1613 | }
|
---|
1614 |
|
---|
1615 | void crServerDumpState()
|
---|
1616 | {
|
---|
1617 | CRContext *ctx = crStateGetCurrent();
|
---|
1618 | crRecDumpGlGetState(&cr_server.Recorder, ctx);
|
---|
1619 | crRecDumpGlEnableState(&cr_server.Recorder, ctx);
|
---|
1620 | }
|
---|
1621 |
|
---|
1622 | void crServerDumpDrawel(const char*pszFormat, ...)
|
---|
1623 | {
|
---|
1624 | CRContext *ctx = crStateGetCurrent();
|
---|
1625 | va_list pArgList;
|
---|
1626 | va_start(pArgList, pszFormat);
|
---|
1627 | crRecDumpVertAttrV(&cr_server.Recorder, ctx, pszFormat, pArgList);
|
---|
1628 | va_end(pArgList);
|
---|
1629 | }
|
---|
1630 |
|
---|
1631 | void crServerDumpDrawelv(GLuint idx, const char*pszElFormat, uint32_t cbEl, const void *pvVal, uint32_t cVal)
|
---|
1632 | {
|
---|
1633 | CRContext *ctx = crStateGetCurrent();
|
---|
1634 | crRecDumpVertAttrv(&cr_server.Recorder, ctx, idx, pszElFormat, cbEl, pvVal, cVal);
|
---|
1635 | }
|
---|
1636 |
|
---|
1637 | void crServerDumpBuffer(int idx)
|
---|
1638 | {
|
---|
1639 | CRContextInfo *pCtxInfo = cr_server.currentCtxInfo;
|
---|
1640 | CR_BLITTER_WINDOW BltWin;
|
---|
1641 | CR_BLITTER_CONTEXT BltCtx;
|
---|
1642 | CRContext *ctx = crStateGetCurrent();
|
---|
1643 | GLint idFBO;
|
---|
1644 | GLint idTex;
|
---|
1645 | VBOXVR_TEXTURE RedirTex;
|
---|
1646 | int rc = crServerDumpCheckInit();
|
---|
1647 | idx = idx >= 0 ? idx : crServerMuralFBOIdxFromBufferName(cr_server.currentMural, pCtxInfo->pContext->buffer.drawBuffer);
|
---|
1648 | if (!RT_SUCCESS(rc))
|
---|
1649 | {
|
---|
1650 | crWarning("crServerDumpCheckInit failed, rc %d", rc);
|
---|
1651 | return;
|
---|
1652 | }
|
---|
1653 |
|
---|
1654 | if (idx < 0)
|
---|
1655 | {
|
---|
1656 | crWarning("neg idx, unsupported");
|
---|
1657 | return;
|
---|
1658 | }
|
---|
1659 |
|
---|
1660 | idFBO = CR_SERVER_FBO_FOR_IDX(cr_server.currentMural, idx);
|
---|
1661 | idTex = CR_SERVER_FBO_TEX_FOR_IDX(cr_server.currentMural, idx);
|
---|
1662 |
|
---|
1663 | crServerVBoxBlitterWinInit(&BltWin, cr_server.currentMural);
|
---|
1664 | crServerVBoxBlitterCtxInit(&BltCtx, pCtxInfo);
|
---|
1665 |
|
---|
1666 | RedirTex.width = cr_server.currentMural->fboWidth;
|
---|
1667 | RedirTex.height = cr_server.currentMural->fboHeight;
|
---|
1668 | RedirTex.target = GL_TEXTURE_2D;
|
---|
1669 | RedirTex.hwid = idTex;
|
---|
1670 |
|
---|
1671 | crRecDumpBuffer(&cr_server.Recorder, ctx, &BltCtx, &BltWin, idFBO, idTex ? &RedirTex : NULL);
|
---|
1672 | }
|
---|
1673 |
|
---|
1674 | void crServerDumpTexture(const VBOXVR_TEXTURE *pTex)
|
---|
1675 | {
|
---|
1676 | CRContextInfo *pCtxInfo = cr_server.currentCtxInfo;
|
---|
1677 | CR_BLITTER_WINDOW BltWin;
|
---|
1678 | CR_BLITTER_CONTEXT BltCtx;
|
---|
1679 | CRContext *ctx = crStateGetCurrent();
|
---|
1680 | int rc = crServerDumpCheckInit();
|
---|
1681 | if (!RT_SUCCESS(rc))
|
---|
1682 | {
|
---|
1683 | crWarning("crServerDumpCheckInit failed, rc %d", rc);
|
---|
1684 | return;
|
---|
1685 | }
|
---|
1686 |
|
---|
1687 | crServerVBoxBlitterWinInit(&BltWin, cr_server.currentMural);
|
---|
1688 | crServerVBoxBlitterCtxInit(&BltCtx, pCtxInfo);
|
---|
1689 |
|
---|
1690 | crRecDumpTextureF(&cr_server.Recorder, pTex, &BltCtx, &BltWin, "Tex (%d x %d), hwid (%d) target %#x", pTex->width, pTex->height, pTex->hwid, pTex->target);
|
---|
1691 | }
|
---|
1692 |
|
---|
1693 | void crServerDumpTextures()
|
---|
1694 | {
|
---|
1695 | CRContextInfo *pCtxInfo = cr_server.currentCtxInfo;
|
---|
1696 | CR_BLITTER_WINDOW BltWin;
|
---|
1697 | CR_BLITTER_CONTEXT BltCtx;
|
---|
1698 | CRContext *ctx = crStateGetCurrent();
|
---|
1699 | int rc = crServerDumpCheckInit();
|
---|
1700 | if (!RT_SUCCESS(rc))
|
---|
1701 | {
|
---|
1702 | crWarning("crServerDumpCheckInit failed, rc %d", rc);
|
---|
1703 | return;
|
---|
1704 | }
|
---|
1705 |
|
---|
1706 | crServerVBoxBlitterWinInit(&BltWin, cr_server.currentMural);
|
---|
1707 | crServerVBoxBlitterCtxInit(&BltCtx, pCtxInfo);
|
---|
1708 |
|
---|
1709 | crRecDumpTextures(&cr_server.Recorder, ctx, &BltCtx, &BltWin);
|
---|
1710 | }
|
---|
1711 |
|
---|
1712 | void crServerDumpFilterOpLeave(unsigned long event, CR_DUMPER *pDumper)
|
---|
1713 | {
|
---|
1714 | if (CR_SERVER_DUMP_F_DRAW_LEAVE_ALL & event)
|
---|
1715 | {
|
---|
1716 | g_CrDbgDumpDumpOnCountPerform = 0;
|
---|
1717 | }
|
---|
1718 | }
|
---|
1719 |
|
---|
1720 | bool crServerDumpFilterOpEnter(unsigned long event, CR_DUMPER *pDumper)
|
---|
1721 | {
|
---|
1722 | if ((CR_SERVER_DUMP_F_SWAPBUFFERS_ENTER & event)
|
---|
1723 | || (CR_SERVER_DUMP_F_TEXPRESENT & event))
|
---|
1724 | {
|
---|
1725 | if (g_CrDbgDumpDumpOnCountEnabled == 1)
|
---|
1726 | g_CrDbgDumpDumpOnCountEnabled = 2;
|
---|
1727 | else if (g_CrDbgDumpDumpOnCountEnabled)
|
---|
1728 | {
|
---|
1729 | g_CrDbgDumpDumpOnCountEnabled = 0;
|
---|
1730 | if (cr_server.pDumper == &cr_server.HtmlDumper.Base)
|
---|
1731 | {
|
---|
1732 | crDmpHtmlTerm(&cr_server.HtmlDumper);
|
---|
1733 | cr_server.pDumper = NULL;
|
---|
1734 | }
|
---|
1735 | }
|
---|
1736 |
|
---|
1737 | g_CrDbgDumpDrawCount = 0;
|
---|
1738 | }
|
---|
1739 | else if (CR_SERVER_DUMP_F_DRAW_ENTER_ALL & event)
|
---|
1740 | {
|
---|
1741 | if (g_CrDbgDumpDumpOnCountEnabled == 2)
|
---|
1742 | {
|
---|
1743 | if (g_CrDbgDumpDumpOnCount == g_CrDbgDumpDrawCount)
|
---|
1744 | {
|
---|
1745 | g_CrDbgDumpDumpOnCountPerform = 1;
|
---|
1746 | }
|
---|
1747 | ++g_CrDbgDumpDrawCount;
|
---|
1748 | }
|
---|
1749 | }
|
---|
1750 | if (g_CrDbgDumpDumpOnCountPerform)
|
---|
1751 | {
|
---|
1752 | if (g_CrDbgDumpDrawFlags & event)
|
---|
1753 | return true;
|
---|
1754 | }
|
---|
1755 | return CR_SERVER_DUMP_DEFAULT_FILTER_OP(event);
|
---|
1756 | }
|
---|
1757 |
|
---|
1758 | bool crServerDumpFilterDmp(unsigned long event, CR_DUMPER *pDumper)
|
---|
1759 | {
|
---|
1760 | if (g_CrDbgDumpDumpOnCountPerform)
|
---|
1761 | {
|
---|
1762 | if (g_CrDbgDumpDrawFlags & event)
|
---|
1763 | return true;
|
---|
1764 | }
|
---|
1765 | return CR_SERVER_DUMP_DEFAULT_FILTER_DMP(event);
|
---|
1766 | }
|
---|
1767 |
|
---|
1768 | void crServerDumpFramesCheck()
|
---|
1769 | {
|
---|
1770 | if (!g_CrDbgDumpDrawFramesCount)
|
---|
1771 | return;
|
---|
1772 |
|
---|
1773 | if (!g_CrDbgDumpDrawFramesAppliedSettings)
|
---|
1774 | {
|
---|
1775 | if (!g_CrDbgDumpDrawFramesSettings)
|
---|
1776 | {
|
---|
1777 | crWarning("g_CrDbgDumpDrawFramesSettings is NULL, bump will not be started");
|
---|
1778 | g_CrDbgDumpDrawFramesCount = 0;
|
---|
1779 | return;
|
---|
1780 | }
|
---|
1781 |
|
---|
1782 | g_CrDbgDumpDrawFramesSavedInitSettings = g_CrDbgDumpDraw;
|
---|
1783 | g_CrDbgDumpDrawFramesAppliedSettings = g_CrDbgDumpDrawFramesSettings;
|
---|
1784 | g_CrDbgDumpDraw = g_CrDbgDumpDrawFramesSettings;
|
---|
1785 | crDmpStrF(cr_server.Recorder.pDumper, "***Starting draw dump for %d frames, settings(0x%x)", g_CrDbgDumpDrawFramesCount, g_CrDbgDumpDraw);
|
---|
1786 | return;
|
---|
1787 | }
|
---|
1788 |
|
---|
1789 | --g_CrDbgDumpDrawFramesCount;
|
---|
1790 |
|
---|
1791 | if (!g_CrDbgDumpDrawFramesCount)
|
---|
1792 | {
|
---|
1793 | crDmpStrF(cr_server.Recorder.pDumper, "***Stop draw dump");
|
---|
1794 | g_CrDbgDumpDraw = g_CrDbgDumpDrawFramesSavedInitSettings;
|
---|
1795 | g_CrDbgDumpDrawFramesAppliedSettings = 0;
|
---|
1796 | }
|
---|
1797 | }
|
---|
1798 | #endif
|
---|
1799 |
|
---|
1800 | GLvoid crServerSpriteCoordReplEnable(GLboolean fEnable)
|
---|
1801 | {
|
---|
1802 | CRContext *g = crStateGetCurrent();
|
---|
1803 | CRTextureState *t = &(g->texture);
|
---|
1804 | GLuint curTextureUnit = t->curTextureUnit;
|
---|
1805 | GLuint curTextureUnitRestore = curTextureUnit;
|
---|
1806 | GLuint i;
|
---|
1807 |
|
---|
1808 | for (i = 0; i < g->limits.maxTextureUnits; ++i)
|
---|
1809 | {
|
---|
1810 | if (g->point.coordReplacement[i])
|
---|
1811 | {
|
---|
1812 | if (i != curTextureUnit)
|
---|
1813 | {
|
---|
1814 | curTextureUnit = i;
|
---|
1815 | cr_server.head_spu->dispatch_table.ActiveTextureARB( i + GL_TEXTURE0_ARB );
|
---|
1816 | }
|
---|
1817 |
|
---|
1818 | cr_server.head_spu->dispatch_table.TexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, (GLint)fEnable);
|
---|
1819 | }
|
---|
1820 | }
|
---|
1821 |
|
---|
1822 | if (curTextureUnit != curTextureUnitRestore)
|
---|
1823 | {
|
---|
1824 | cr_server.head_spu->dispatch_table.ActiveTextureARB( curTextureUnitRestore + GL_TEXTURE0_ARB );
|
---|
1825 | }
|
---|
1826 | }
|
---|
1827 |
|
---|
1828 | GLvoid SERVER_DISPATCH_APIENTRY crServerDispatchDrawArrays(GLenum mode, GLint first, GLsizei count)
|
---|
1829 | {
|
---|
1830 | #ifdef DEBUG
|
---|
1831 | GLenum status = cr_server.head_spu->dispatch_table.CheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT);
|
---|
1832 | Assert(GL_FRAMEBUFFER_COMPLETE == status);
|
---|
1833 | #endif
|
---|
1834 | if (mode == GL_POINTS)
|
---|
1835 | crServerSpriteCoordReplEnable(GL_TRUE);
|
---|
1836 | CR_SERVER_DUMP_DRAW_ENTER();
|
---|
1837 | CR_GLERR_CHECK(cr_server.head_spu->dispatch_table.DrawArrays(mode, first, count););
|
---|
1838 | CR_SERVER_DUMP_DRAW_LEAVE();
|
---|
1839 | if (mode == GL_POINTS)
|
---|
1840 | crServerSpriteCoordReplEnable(GL_FALSE);
|
---|
1841 | }
|
---|
1842 |
|
---|
1843 | GLvoid SERVER_DISPATCH_APIENTRY crServerDispatchDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices)
|
---|
1844 | {
|
---|
1845 | #ifdef DEBUG
|
---|
1846 | GLenum status = cr_server.head_spu->dispatch_table.CheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT);
|
---|
1847 | Assert(GL_FRAMEBUFFER_COMPLETE == status);
|
---|
1848 | #endif
|
---|
1849 | if (mode == GL_POINTS)
|
---|
1850 | crServerSpriteCoordReplEnable(GL_TRUE);
|
---|
1851 | CR_SERVER_DUMP_DRAW_ENTER();
|
---|
1852 | CR_GLERR_CHECK(cr_server.head_spu->dispatch_table.DrawElements(mode, count, type, indices););
|
---|
1853 | CR_SERVER_DUMP_DRAW_LEAVE();
|
---|
1854 | if (mode == GL_POINTS)
|
---|
1855 | crServerSpriteCoordReplEnable(GL_FALSE);
|
---|
1856 | }
|
---|
1857 |
|
---|
1858 | void SERVER_DISPATCH_APIENTRY crServerDispatchEnd( void )
|
---|
1859 | {
|
---|
1860 | CRContext *g = crStateGetCurrent();
|
---|
1861 | GLenum mode = g->current.mode;
|
---|
1862 |
|
---|
1863 | crStateEnd();
|
---|
1864 | cr_server.head_spu->dispatch_table.End();
|
---|
1865 |
|
---|
1866 | CR_SERVER_DUMP_DRAW_LEAVE();
|
---|
1867 |
|
---|
1868 | if (mode == GL_POINTS)
|
---|
1869 | crServerSpriteCoordReplEnable(GL_FALSE);
|
---|
1870 | }
|
---|
1871 |
|
---|
1872 | void SERVER_DISPATCH_APIENTRY crServerDispatchBegin(GLenum mode)
|
---|
1873 | {
|
---|
1874 | #ifdef DEBUG
|
---|
1875 | CRContext *ctx = crStateGetCurrent();
|
---|
1876 | SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table;
|
---|
1877 |
|
---|
1878 | if (ctx->program.vpProgramBinding)
|
---|
1879 | {
|
---|
1880 | AssertRelease(ctx->program.currentVertexProgram);
|
---|
1881 |
|
---|
1882 | if (ctx->program.currentVertexProgram->isARBprogram)
|
---|
1883 | {
|
---|
1884 | GLint pid=-1;
|
---|
1885 | gl->GetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_BINDING_ARB, &pid);
|
---|
1886 |
|
---|
1887 | if (pid != ctx->program.currentVertexProgram->id)
|
---|
1888 | {
|
---|
1889 | crWarning("pid(%d) != ctx->program.currentVertexProgram->id(%d)", pid, ctx->program.currentVertexProgram->id);
|
---|
1890 | }
|
---|
1891 | AssertRelease(pid == ctx->program.currentVertexProgram->id);
|
---|
1892 | }
|
---|
1893 | else
|
---|
1894 | {
|
---|
1895 | GLint pid=-1;
|
---|
1896 |
|
---|
1897 | gl->GetIntegerv(GL_VERTEX_PROGRAM_BINDING_NV, &pid);
|
---|
1898 | if (pid != ctx->program.currentVertexProgram->id)
|
---|
1899 | {
|
---|
1900 | crWarning("pid(%d) != ctx->program.currentVertexProgram->id(%d)", pid, ctx->program.currentVertexProgram->id);
|
---|
1901 | }
|
---|
1902 | AssertRelease(pid == ctx->program.currentVertexProgram->id);
|
---|
1903 | }
|
---|
1904 | }
|
---|
1905 | else if (ctx->glsl.activeProgram)
|
---|
1906 | {
|
---|
1907 | GLint pid=-1;
|
---|
1908 |
|
---|
1909 | gl->GetIntegerv(GL_CURRENT_PROGRAM, &pid);
|
---|
1910 | crDebug("pid %i, state: id %i, hwid %i", pid, ctx->glsl.activeProgram->id, ctx->glsl.activeProgram->hwid);
|
---|
1911 | if (pid != ctx->glsl.activeProgram->hwid)
|
---|
1912 | {
|
---|
1913 | crWarning("pid(%d) != ctx->glsl.activeProgram->hwid(%d)", pid, ctx->glsl.activeProgram->hwid);
|
---|
1914 | }
|
---|
1915 | AssertRelease(pid == ctx->glsl.activeProgram->hwid);
|
---|
1916 | }
|
---|
1917 | #endif
|
---|
1918 |
|
---|
1919 | if (mode == GL_POINTS)
|
---|
1920 | crServerSpriteCoordReplEnable(GL_TRUE);
|
---|
1921 |
|
---|
1922 | CR_SERVER_DUMP_DRAW_ENTER();
|
---|
1923 |
|
---|
1924 | crStateBegin(mode);
|
---|
1925 | cr_server.head_spu->dispatch_table.Begin(mode);
|
---|
1926 | }
|
---|
1927 |
|
---|