VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_misc.c@ 55998

Last change on this file since 55998 was 53088, checked in by vboxsync, 10 years ago

Host 3D: reduce amount of debug logging.

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