VirtualBox

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

最後變更 在這個檔案從65521是 62783,由 vboxsync 提交於 8 年 前

HostServices,GuestHost: warnings

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 66.1 KB
 
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 GLint dRow;
591 GLuint pboId, sRow;
592 CRContext *ctx = crStateGetCurrent();
593
594 gl->GenBuffersARB(1, &pboId);
595 gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboId);
596 gl->BufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, -width*height*4, 0, GL_STATIC_COPY_ARB);
597
598#if 1
599 gl->ReadPixels(x, y, width, -height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
600 gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, ctx->bufferobject.packBuffer->hwid);
601
602 gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboId);
603 for (dRow=yoffset, sRow=-height-1; dRow<yoffset-height; dRow++, sRow--)
604 {
605 gl->TexSubImage2D(target, level, xoffset, dRow, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)((uintptr_t)sRow*width*4));
606 }
607#else /*few times slower again*/
608 for (dRow=0, sRow=y-height-1; dRow<-height; dRow++, sRow--)
609 {
610 gl->ReadPixels(x, sRow, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)((uintptr_t)dRow*width*4));
611 }
612 gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, ctx->bufferobject.packBuffer->hwid);
613
614 gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboId);
615 gl->TexSubImage2D(target, level, xoffset, yoffset, width, -height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
616#endif
617
618 gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, ctx->bufferobject.unpackBuffer->hwid);
619 gl->DeleteBuffersARB(1, &pboId);
620 }
621 }
622}
623
624#ifdef CR_CHECK_BLITS
625void crDbgFree(void *pvData)
626{
627 crFree(pvData);
628}
629
630void crDbgGetTexImage2D(GLint texTarget, GLint texName, GLvoid **ppvImage, GLint *pw, GLint *ph)
631{
632 SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table;
633 GLint ppb, pub, dstw, dsth, otex;
634 GLint pa, pr, psp, psr, ua, ur, usp, usr;
635 GLvoid *pvImage;
636 GLint rfb, dfb, rb, db;
637
638 gl->GetIntegerv(GL_READ_FRAMEBUFFER_BINDING_EXT, &rfb);
639 gl->GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING_EXT, &dfb);
640 gl->GetIntegerv(GL_READ_BUFFER, &rb);
641 gl->GetIntegerv(GL_DRAW_BUFFER, &db);
642
643 gl->BindFramebufferEXT(GL_READ_FRAMEBUFFER_BINDING_EXT, 0);
644 gl->BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_BINDING_EXT, 0);
645 gl->ReadBuffer(GL_BACK);
646 gl->DrawBuffer(GL_BACK);
647
648 gl->GetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &ppb);
649 gl->GetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &pub);
650 gl->GetIntegerv(GL_TEXTURE_BINDING_2D, &otex);
651
652 gl->GetIntegerv(GL_PACK_ROW_LENGTH, &pr);
653 gl->GetIntegerv(GL_PACK_ALIGNMENT, &pa);
654 gl->GetIntegerv(GL_PACK_SKIP_PIXELS, &psp);
655 gl->GetIntegerv(GL_PACK_SKIP_ROWS, &psr);
656
657 gl->GetIntegerv(GL_UNPACK_ROW_LENGTH, &ur);
658 gl->GetIntegerv(GL_UNPACK_ALIGNMENT, &ua);
659 gl->GetIntegerv(GL_UNPACK_SKIP_PIXELS, &usp);
660 gl->GetIntegerv(GL_UNPACK_SKIP_ROWS, &usr);
661
662 gl->BindTexture(texTarget, texName);
663 gl->GetTexLevelParameteriv(texTarget, 0, GL_TEXTURE_WIDTH, &dstw);
664 gl->GetTexLevelParameteriv(texTarget, 0, GL_TEXTURE_HEIGHT, &dsth);
665
666 gl->PixelStorei(GL_PACK_ROW_LENGTH, 0);
667 gl->PixelStorei(GL_PACK_ALIGNMENT, 1);
668 gl->PixelStorei(GL_PACK_SKIP_PIXELS, 0);
669 gl->PixelStorei(GL_PACK_SKIP_ROWS, 0);
670
671 gl->PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
672 gl->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
673 gl->PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
674 gl->PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
675
676 gl->BindBufferARB(GL_PIXEL_PACK_BUFFER, 0);
677 gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER, 0);
678
679 pvImage = crAlloc(4*dstw*dsth);
680 gl->GetTexImage(texTarget, 0, GL_BGRA, GL_UNSIGNED_BYTE, pvImage);
681
682 gl->BindTexture(texTarget, otex);
683
684 gl->PixelStorei(GL_PACK_ROW_LENGTH, pr);
685 gl->PixelStorei(GL_PACK_ALIGNMENT, pa);
686 gl->PixelStorei(GL_PACK_SKIP_PIXELS, psp);
687 gl->PixelStorei(GL_PACK_SKIP_ROWS, psr);
688
689 gl->PixelStorei(GL_UNPACK_ROW_LENGTH, ur);
690 gl->PixelStorei(GL_UNPACK_ALIGNMENT, ua);
691 gl->PixelStorei(GL_UNPACK_SKIP_PIXELS, usp);
692 gl->PixelStorei(GL_UNPACK_SKIP_ROWS, usr);
693
694 gl->BindBufferARB(GL_PIXEL_PACK_BUFFER, ppb);
695 gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER, pub);
696
697 gl->BindFramebufferEXT(GL_READ_FRAMEBUFFER_BINDING_EXT, rfb);
698 gl->BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_BINDING_EXT, dfb);
699 gl->ReadBuffer(rb);
700 gl->DrawBuffer(db);
701
702 *ppvImage = pvImage;
703 *pw = dstw;
704 *ph = dsth;
705}
706
707DECLEXPORT(void) crDbgPrint(const char *format, ... )
708{
709 va_list args;
710 static char txt[8092];
711
712 va_start(args, format);
713 vsprintf(txt, format, args);
714 va_end(args);
715
716 OutputDebugString(txt);
717}
718
719void crDbgDumpImage2D(const char* pszDesc, const void *pvData, uint32_t width, uint32_t height, uint32_t bpp, uint32_t pitch)
720{
721 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",
722 pvData, width, height, bpp, pitch,
723 pszDesc,
724 pvData, width, height, bpp, pitch);
725}
726
727void crDbgDumpTexImage2D(const char* pszDesc, GLint texTarget, GLint texName, GLboolean fBreak)
728{
729 GLvoid *pvImage;
730 GLint w, h;
731 crDbgGetTexImage2D(texTarget, texName, &pvImage, &w, &h);
732 crDbgPrint("%s target(%d), name(%d), width(%d), height(%d)", pszDesc, texTarget, texName, w, h);
733 crDbgDumpImage2D("texture data", pvImage, w, h, 32, (32 * w)/8);
734 if (fBreak)
735 {
736 CRASSERT(0);
737 }
738 crDbgFree(pvImage);
739}
740#endif
741
742PCR_BLITTER crServerVBoxBlitterGet()
743{
744 if (!CrBltIsInitialized(&cr_server.Blitter))
745 {
746 CR_BLITTER_CONTEXT Ctx;
747 int rc;
748 CRASSERT(cr_server.MainContextInfo.SpuContext);
749 Ctx.Base.id = cr_server.MainContextInfo.SpuContext;
750 Ctx.Base.visualBits = cr_server.MainContextInfo.CreateInfo.realVisualBits;
751 rc = CrBltInit(&cr_server.Blitter, &Ctx, true, true, NULL, &cr_server.TmpCtxDispatch);
752 if (RT_SUCCESS(rc))
753 {
754 CRASSERT(CrBltIsInitialized(&cr_server.Blitter));
755 }
756 else
757 {
758 crWarning("CrBltInit failed, rc %d", rc);
759 CRASSERT(!CrBltIsInitialized(&cr_server.Blitter));
760 return NULL;
761 }
762 }
763
764 if (!CrBltMuralGetCurrentInfo(&cr_server.Blitter)->Base.id)
765 {
766 CRMuralInfo *dummy = crServerGetDummyMural(cr_server.MainContextInfo.CreateInfo.realVisualBits);
767 CR_BLITTER_WINDOW DummyInfo;
768 CRASSERT(dummy);
769 crServerVBoxBlitterWinInit(&DummyInfo, dummy);
770 CrBltMuralSetCurrentInfo(&cr_server.Blitter, &DummyInfo);
771 }
772
773 return &cr_server.Blitter;
774}
775
776PCR_BLITTER crServerVBoxBlitterGetInitialized()
777{
778 if (CrBltIsInitialized(&cr_server.Blitter))
779 return &cr_server.Blitter;
780 return NULL;
781}
782
783
784int crServerVBoxBlitterTexInit(CRContext *ctx, CRMuralInfo *mural, PVBOXVR_TEXTURE pTex, GLboolean fDraw)
785{
786 CRTextureObj *tobj;
787 CRFramebufferObjectState *pBuf = &ctx->framebufferobject;
788 GLenum enmBuf;
789 CRFBOAttachmentPoint *pAp;
790 GLuint idx;
791 CRTextureLevel *tl;
792 CRFramebufferObject *pFBO = fDraw ? pBuf->drawFB : pBuf->readFB;
793
794 if (!pFBO)
795 {
796 GLuint hwid;
797
798 if (!mural->fRedirected)
799 {
800 WARN(("mural not redirected!"));
801 return VERR_NOT_IMPLEMENTED;
802 }
803
804 enmBuf = fDraw ? ctx->buffer.drawBuffer : ctx->buffer.readBuffer;
805 switch (enmBuf)
806 {
807 case GL_BACK:
808 case GL_BACK_RIGHT:
809 case GL_BACK_LEFT:
810 hwid = mural->aidColorTexs[CR_SERVER_FBO_BB_IDX(mural)];
811 break;
812 case GL_FRONT:
813 case GL_FRONT_RIGHT:
814 case GL_FRONT_LEFT:
815 hwid = mural->aidColorTexs[CR_SERVER_FBO_FB_IDX(mural)];
816 break;
817 default:
818 WARN(("unsupported enum buf %d", enmBuf));
819 return VERR_NOT_IMPLEMENTED;
820 break;
821 }
822
823 if (!hwid)
824 {
825 crWarning("offscreen render tex hwid is null");
826 return VERR_INVALID_STATE;
827 }
828
829 pTex->width = mural->width;
830 pTex->height = mural->height;
831 pTex->target = GL_TEXTURE_2D;
832 pTex->hwid = hwid;
833 return VINF_SUCCESS;
834 }
835
836 enmBuf = fDraw ? pFBO->drawbuffer[0] : pFBO->readbuffer;
837 idx = enmBuf - GL_COLOR_ATTACHMENT0_EXT;
838 if (idx >= CR_MAX_COLOR_ATTACHMENTS)
839 {
840 crWarning("idx is invalid %d, using 0", idx);
841 }
842
843 pAp = &pFBO->color[idx];
844
845 if (!pAp->name)
846 {
847 crWarning("no collor draw attachment");
848 return VERR_INVALID_STATE;
849 }
850
851 if (pAp->level)
852 {
853 WARN(("non-zero level not implemented"));
854 return VERR_NOT_IMPLEMENTED;
855 }
856
857 tobj = (CRTextureObj*)crHashtableSearch(ctx->shared->textureTable, pAp->name);
858 if (!tobj)
859 {
860 crWarning("no texture object found for name %d", pAp->name);
861 return VERR_INVALID_STATE;
862 }
863
864 if (tobj->target != GL_TEXTURE_2D && tobj->target != GL_TEXTURE_RECTANGLE_NV)
865 {
866 WARN(("non-texture[rect|2d] not implemented"));
867 return VERR_NOT_IMPLEMENTED;
868 }
869
870 CRASSERT(tobj->hwid);
871
872 tl = tobj->level[0];
873 pTex->width = tl->width;
874 pTex->height = tl->height;
875 pTex->target = tobj->target;
876 pTex->hwid = tobj->hwid;
877
878 return VINF_SUCCESS;
879}
880
881int crServerVBoxBlitterBlitCurrentCtx(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
882 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
883 GLbitfield mask, GLenum filter)
884{
885 PCR_BLITTER pBlitter;
886 CR_BLITTER_CONTEXT Ctx;
887 CRMuralInfo *mural;
888 CRContext *ctx = crStateGetCurrent();
889 PVBOXVR_TEXTURE pDrawTex, pReadTex;
890 VBOXVR_TEXTURE DrawTex, ReadTex;
891 int rc;
892 GLuint idDrawFBO, idReadFBO;
893 CR_BLITTER_WINDOW BltInfo;
894
895 if (mask != GL_COLOR_BUFFER_BIT)
896 {
897 WARN(("not supported blit mask %d", mask));
898 return VERR_NOT_IMPLEMENTED;
899 }
900
901 if (!cr_server.curClient)
902 {
903 crWarning("no current client");
904 return VERR_INVALID_STATE;
905 }
906 mural = cr_server.curClient->currentMural;
907 if (!mural)
908 {
909 crWarning("no current mural");
910 return VERR_INVALID_STATE;
911 }
912
913 rc = crServerVBoxBlitterTexInit(ctx, mural, &DrawTex, GL_TRUE);
914 if (RT_SUCCESS(rc))
915 {
916 pDrawTex = &DrawTex;
917 }
918 else
919 {
920 crWarning("crServerVBoxBlitterTexInit failed for draw");
921 return rc;
922 }
923
924 rc = crServerVBoxBlitterTexInit(ctx, mural, &ReadTex, GL_FALSE);
925 if (RT_SUCCESS(rc))
926 {
927 pReadTex = &ReadTex;
928 }
929 else
930 {
931// crWarning("crServerVBoxBlitterTexInit failed for read");
932 return rc;
933 }
934
935 pBlitter = crServerVBoxBlitterGet();
936 if (!pBlitter)
937 {
938 crWarning("crServerVBoxBlitterGet failed");
939 return VERR_GENERAL_FAILURE;
940 }
941
942 crServerVBoxBlitterWinInit(&BltInfo, mural);
943
944 crServerVBoxBlitterCtxInit(&Ctx, cr_server.curClient->currentCtxInfo);
945
946 CrBltMuralSetCurrentInfo(pBlitter, &BltInfo);
947
948 idDrawFBO = CR_SERVER_FBO_FOR_IDX(mural, mural->iCurDrawBuffer);
949 idReadFBO = CR_SERVER_FBO_FOR_IDX(mural, mural->iCurReadBuffer);
950
951 crStateSwitchPrepare(NULL, ctx, idDrawFBO, idReadFBO);
952
953 rc = CrBltEnter(pBlitter);
954 if (RT_SUCCESS(rc))
955 {
956 RTRECT ReadRect, DrawRect;
957 ReadRect.xLeft = srcX0;
958 ReadRect.yTop = srcY0;
959 ReadRect.xRight = srcX1;
960 ReadRect.yBottom = srcY1;
961 DrawRect.xLeft = dstX0;
962 DrawRect.yTop = dstY0;
963 DrawRect.xRight = dstX1;
964 DrawRect.yBottom = dstY1;
965 CrBltBlitTexTex(pBlitter, pReadTex, &ReadRect, pDrawTex, &DrawRect, 1, CRBLT_FLAGS_FROM_FILTER(filter));
966 CrBltLeave(pBlitter);
967 }
968 else
969 {
970 crWarning("CrBltEnter failed rc %d", rc);
971 }
972
973 crStateSwitchPostprocess(ctx, NULL, idDrawFBO, idReadFBO);
974
975 return rc;
976}
977
978void SERVER_DISPATCH_APIENTRY
979crServerDispatchBlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
980 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
981 GLbitfield mask, GLenum filter)
982{
983 CRContext *ctx = crStateGetCurrent();
984 bool fTryBlitter = false;
985#ifdef CR_CHECK_BLITS
986// {
987 SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table;
988 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;
989 GLint sdtex=0, srtex=0;
990 GLenum dStatus, rStatus;
991
992 CRTextureObj *tobj = 0;
993 CRTextureLevel *tl = 0;
994 GLint id, tuId, pbufId, pbufIdHw, ubufId, ubufIdHw, width, height, depth;
995
996 crDebug("===StateTracker===");
997 crDebug("Current TU: %i", ctx->texture.curTextureUnit);
998
999 tobj = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D;
1000 CRASSERT(tobj);
1001 tl = &tobj->level[0][0];
1002 crDebug("Texture %i(hw %i), w=%i, h=%i", tobj->id, tobj->hwid, tl->width, tl->height, tl->depth);
1003
1004 if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
1005 {
1006 pbufId = ctx->bufferobject.packBuffer->hwid;
1007 }
1008 else
1009 {
1010 pbufId = 0;
1011 }
1012 crDebug("Pack BufferId %i", pbufId);
1013
1014 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
1015 {
1016 ubufId = ctx->bufferobject.unpackBuffer->hwid;
1017 }
1018 else
1019 {
1020 ubufId = 0;
1021 }
1022 crDebug("Unpack BufferId %i", ubufId);
1023
1024 crDebug("===GPU===");
1025 cr_server.head_spu->dispatch_table.GetIntegerv(GL_ACTIVE_TEXTURE, &tuId);
1026 crDebug("Current TU: %i", tuId - GL_TEXTURE0_ARB);
1027 CRASSERT(tuId - GL_TEXTURE0_ARB == ctx->texture.curTextureUnit);
1028
1029 cr_server.head_spu->dispatch_table.GetIntegerv(GL_TEXTURE_BINDING_2D, &id);
1030 cr_server.head_spu->dispatch_table.GetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
1031 cr_server.head_spu->dispatch_table.GetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
1032 cr_server.head_spu->dispatch_table.GetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_DEPTH, &depth);
1033 crDebug("Texture: %i, w=%i, h=%i, d=%i", id, width, height, depth);
1034 CRASSERT(id == tobj->hwid);
1035 CRASSERT(width == tl->width);
1036 CRASSERT(height == tl->height);
1037 CRASSERT(depth == tl->depth);
1038
1039 cr_server.head_spu->dispatch_table.GetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &pbufIdHw);
1040 crDebug("Hw Pack BufferId %i", pbufIdHw);
1041 CRASSERT(pbufIdHw == pbufId);
1042
1043 cr_server.head_spu->dispatch_table.GetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &ubufIdHw);
1044 crDebug("Hw Unpack BufferId %i", ubufIdHw);
1045 CRASSERT(ubufIdHw == ubufId);
1046
1047 gl->GetIntegerv(GL_READ_FRAMEBUFFER_BINDING_EXT, &rfb);
1048 gl->GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING_EXT, &dfb);
1049 gl->GetIntegerv(GL_READ_BUFFER, &rb);
1050 gl->GetIntegerv(GL_DRAW_BUFFER, &db);
1051
1052 gl->GetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &ppb);
1053 gl->GetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &pub);
1054
1055 gl->GetIntegerv(GL_VIEWPORT, &vp[0]);
1056
1057 gl->GetIntegerv(GL_TEXTURE_BINDING_2D, &otex);
1058
1059 gl->GetFramebufferAttachmentParameterivEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT, &dtex);
1060 gl->GetFramebufferAttachmentParameterivEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT, &dlev);
1061 dStatus = gl->CheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT);
1062
1063 gl->GetFramebufferAttachmentParameterivEXT(GL_READ_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT, &rtex);
1064 gl->GetFramebufferAttachmentParameterivEXT(GL_READ_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT, &rlev);
1065 rStatus = gl->CheckFramebufferStatusEXT(GL_READ_FRAMEBUFFER_EXT);
1066
1067 if (dtex)
1068 {
1069 CRASSERT(!dlev);
1070 }
1071
1072 if (rtex)
1073 {
1074 CRASSERT(!rlev);
1075 }
1076
1077 if (ctx->framebufferobject.drawFB)
1078 {
1079 CRASSERT(dfb);
1080 CRASSERT(ctx->framebufferobject.drawFB->hwid == dfb);
1081 CRASSERT(ctx->framebufferobject.drawFB->drawbuffer[0] == db);
1082
1083 CRASSERT(dStatus==GL_FRAMEBUFFER_COMPLETE_EXT);
1084 CRASSERT(db==GL_COLOR_ATTACHMENT0_EXT);
1085
1086 CRASSERT(ctx->framebufferobject.drawFB->color[0].type == GL_TEXTURE);
1087 CRASSERT(ctx->framebufferobject.drawFB->color[0].level == 0);
1088 sdtex = ctx->framebufferobject.drawFB->color[0].name;
1089 sdtex = crStateGetTextureHWID(sdtex);
1090
1091 CRASSERT(sdtex);
1092 }
1093 else
1094 {
1095 CRASSERT(!dfb);
1096 }
1097
1098 if (ctx->framebufferobject.readFB)
1099 {
1100 CRASSERT(rfb);
1101 CRASSERT(ctx->framebufferobject.readFB->hwid == rfb);
1102
1103 CRASSERT(rStatus==GL_FRAMEBUFFER_COMPLETE_EXT);
1104
1105 CRASSERT(ctx->framebufferobject.readFB->color[0].type == GL_TEXTURE);
1106 CRASSERT(ctx->framebufferobject.readFB->color[0].level == 0);
1107 srtex = ctx->framebufferobject.readFB->color[0].name;
1108 srtex = crStateGetTextureHWID(srtex);
1109
1110 CRASSERT(srtex);
1111 }
1112 else
1113 {
1114 CRASSERT(!rfb);
1115 }
1116
1117 CRASSERT(sdtex == dtex);
1118 CRASSERT(srtex == rtex);
1119
1120// crDbgDumpTexImage2D("==> src tex:", GL_TEXTURE_2D, rtex, true);
1121// crDbgDumpTexImage2D("==> dst tex:", GL_TEXTURE_2D, dtex, true);
1122
1123// }
1124#endif
1125#ifdef CR_DUMP_BLITS
1126 SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table;
1127 GLint rfb=0, dfb=0, dtex=0, dlev=-1, rb=0, db=0, ppb=0, pub=0, vp[4], otex, dstw, dsth;
1128 GLenum status;
1129 char fname[200];
1130 void *img;
1131
1132 blitnum++;
1133
1134 crDebug("[%i]BlitFramebufferEXT(%i, %i, %i, %i, %i, %i, %i, %i, %x, %x)", blitnum, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
1135 crDebug("%i, %i <-> %i, %i", srcX1-srcX0, srcY1-srcY0, dstX1-dstX0, dstY1-dstY0);
1136
1137 gl->GetIntegerv(GL_READ_FRAMEBUFFER_BINDING_EXT, &rfb);
1138 gl->GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING_EXT, &dfb);
1139 gl->GetIntegerv(GL_READ_BUFFER, &rb);
1140 gl->GetIntegerv(GL_DRAW_BUFFER, &db);
1141
1142 gl->GetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &ppb);
1143 gl->GetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &pub);
1144
1145 gl->GetIntegerv(GL_VIEWPORT, &vp[0]);
1146
1147 gl->GetIntegerv(GL_TEXTURE_BINDING_2D, &otex);
1148
1149 CRASSERT(!rfb && dfb);
1150 gl->GetFramebufferAttachmentParameterivEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT, &dtex);
1151 gl->GetFramebufferAttachmentParameterivEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT, &dlev);
1152 status = gl->CheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT);
1153
1154 CRASSERT(status==GL_FRAMEBUFFER_COMPLETE_EXT
1155 && db==GL_COLOR_ATTACHMENT0_EXT
1156 && (rb==GL_FRONT || rb==GL_BACK)
1157 && !rfb && dfb && dtex && !dlev
1158 && !ppb && !pub);
1159
1160 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);
1161 crDebug("Viewport [%i, %i, %i, %i]", vp[0], vp[1], vp[2], vp[3]);
1162
1163 gl->PixelStorei(GL_PACK_ROW_LENGTH, 0);
1164 gl->PixelStorei(GL_PACK_ALIGNMENT, 1);
1165 gl->PixelStorei(GL_PACK_SKIP_PIXELS, 0);
1166 gl->PixelStorei(GL_PACK_SKIP_ROWS, 0);
1167
1168 gl->PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1169 gl->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
1170 gl->PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
1171 gl->PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
1172
1173 gl->BindTexture(GL_TEXTURE_2D, dtex);
1174 gl->GetTexLevelParameteriv(GL_TEXTURE_2D, dlev, GL_TEXTURE_WIDTH, &dstw);
1175 gl->GetTexLevelParameteriv(GL_TEXTURE_2D, dlev, GL_TEXTURE_HEIGHT, &dsth);
1176 gl->BindTexture(GL_TEXTURE_2D, otex);
1177 crDebug("Dst is %i, %i", dstw, dsth);
1178
1179 CRASSERT(vp[2]>=dstw && vp[3]>=dsth);
1180 img = crAlloc(vp[2]*vp[3]*4);
1181 CRASSERT(img);
1182
1183 gl->ReadPixels(0, 0, vp[2], vp[3], GL_BGRA, GL_UNSIGNED_BYTE, img);
1184 sprintf(fname, "blit%iA_src.tga", blitnum);
1185 crDumpNamedTGA(fname, vp[2], vp[3], img);
1186
1187 gl->BindTexture(GL_TEXTURE_2D, dtex);
1188 gl->GetTexImage(GL_TEXTURE_2D, dlev, GL_BGRA, GL_UNSIGNED_BYTE, img);
1189 sprintf(fname, "blit%iB_dst.tga", blitnum);
1190 crDumpNamedTGA(fname, dstw, dsth, img);
1191 gl->BindTexture(GL_TEXTURE_2D, otex);
1192#endif
1193
1194 if (srcY0 > srcY1)
1195 {
1196 /* work around Intel driver bug on Linux host */
1197 if (1 || dstY0 > dstY1)
1198 {
1199 /* use srcY1 < srcY2 && dstY1 < dstY2 whenever possible to avoid GPU driver bugs */
1200 int32_t tmp = srcY0;
1201 srcY0 = srcY1;
1202 srcY1 = tmp;
1203 tmp = dstY0;
1204 dstY0 = dstY1;
1205 dstY1 = tmp;
1206 }
1207 }
1208
1209 if (srcX0 > srcX1)
1210 {
1211 if (dstX0 > dstX1)
1212 {
1213 /* use srcX1 < srcX2 && dstX1 < dstX2 whenever possible to avoid GPU driver bugs */
1214 int32_t tmp = srcX0;
1215 srcX0 = srcX1;
1216 srcX1 = tmp;
1217 tmp = dstX0;
1218 dstX0 = dstX1;
1219 dstX1 = tmp;
1220 }
1221 }
1222
1223 if (cr_server.fBlitterMode)
1224 {
1225 fTryBlitter = true;
1226 }
1227
1228 if (fTryBlitter)
1229 {
1230 int rc = crServerVBoxBlitterBlitCurrentCtx(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
1231 if (RT_SUCCESS(rc))
1232 goto my_exit;
1233 }
1234
1235 if (ctx->viewport.scissorTest)
1236 cr_server.head_spu->dispatch_table.Disable(GL_SCISSOR_TEST);
1237
1238 cr_server.head_spu->dispatch_table.BlitFramebufferEXT(srcX0, srcY0, srcX1, srcY1,
1239 dstX0, dstY0, dstX1, dstY1,
1240 mask, filter);
1241
1242 if (ctx->viewport.scissorTest)
1243 cr_server.head_spu->dispatch_table.Enable(GL_SCISSOR_TEST);
1244
1245
1246my_exit:
1247
1248//#ifdef CR_CHECK_BLITS
1249// crDbgDumpTexImage2D("<== src tex:", GL_TEXTURE_2D, rtex, true);
1250// crDbgDumpTexImage2D("<== dst tex:", GL_TEXTURE_2D, dtex, true);
1251//#endif
1252#ifdef CR_DUMP_BLITS
1253 gl->BindTexture(GL_TEXTURE_2D, dtex);
1254 gl->GetTexImage(GL_TEXTURE_2D, dlev, GL_BGRA, GL_UNSIGNED_BYTE, img);
1255 sprintf(fname, "blit%iC_res.tga", blitnum);
1256 crDumpNamedTGA(fname, dstw, dsth, img);
1257 gl->BindTexture(GL_TEXTURE_2D, otex);
1258 crFree(img);
1259#endif
1260 return;
1261}
1262
1263void SERVER_DISPATCH_APIENTRY crServerDispatchDrawBuffer( GLenum mode )
1264{
1265 crStateDrawBuffer( mode );
1266
1267 if (!crStateGetCurrent()->framebufferobject.drawFB)
1268 {
1269 if (mode == GL_FRONT || mode == GL_FRONT_LEFT || mode == GL_FRONT_RIGHT)
1270 cr_server.curClient->currentMural->bFbDraw = GL_TRUE;
1271
1272 if (crServerIsRedirectedToFBO()
1273 && cr_server.curClient->currentMural->aidFBOs[0])
1274 {
1275 CRMuralInfo *mural = cr_server.curClient->currentMural;
1276 GLint iBufferNeeded = -1;
1277 switch (mode)
1278 {
1279 case GL_BACK:
1280 case GL_BACK_LEFT:
1281 case GL_BACK_RIGHT:
1282 mode = GL_COLOR_ATTACHMENT0;
1283 iBufferNeeded = CR_SERVER_FBO_BB_IDX(mural);
1284 break;
1285 case GL_FRONT:
1286 case GL_FRONT_LEFT:
1287 case GL_FRONT_RIGHT:
1288 mode = GL_COLOR_ATTACHMENT0;
1289 iBufferNeeded = CR_SERVER_FBO_FB_IDX(mural);
1290 break;
1291 case GL_NONE:
1292 crDebug("DrawBuffer: GL_NONE");
1293 break;
1294 case GL_AUX0:
1295 crDebug("DrawBuffer: GL_AUX0");
1296 break;
1297 case GL_AUX1:
1298 crDebug("DrawBuffer: GL_AUX1");
1299 break;
1300 case GL_AUX2:
1301 crDebug("DrawBuffer: GL_AUX2");
1302 break;
1303 case GL_AUX3:
1304 crDebug("DrawBuffer: GL_AUX3");
1305 break;
1306 case GL_LEFT:
1307 crWarning("DrawBuffer: GL_LEFT not supported properly");
1308 mode = GL_COLOR_ATTACHMENT0;
1309 iBufferNeeded = CR_SERVER_FBO_BB_IDX(mural);
1310 break;
1311 case GL_RIGHT:
1312 crWarning("DrawBuffer: GL_RIGHT not supported properly");
1313 mode = GL_COLOR_ATTACHMENT0;
1314 iBufferNeeded = CR_SERVER_FBO_BB_IDX(mural);
1315 break;
1316 case GL_FRONT_AND_BACK:
1317 crWarning("DrawBuffer: GL_FRONT_AND_BACK not supported properly");
1318 mode = GL_COLOR_ATTACHMENT0;
1319 iBufferNeeded = CR_SERVER_FBO_BB_IDX(mural);
1320 break;
1321 default:
1322 crWarning("DrawBuffer: unexpected mode! 0x%x", mode);
1323 iBufferNeeded = mural->iCurDrawBuffer;
1324 break;
1325 }
1326
1327 if (iBufferNeeded != mural->iCurDrawBuffer)
1328 {
1329 mural->iCurDrawBuffer = iBufferNeeded;
1330 cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, CR_SERVER_FBO_FOR_IDX(mural, iBufferNeeded));
1331 }
1332 }
1333 }
1334
1335 cr_server.head_spu->dispatch_table.DrawBuffer( mode );
1336}
1337
1338void SERVER_DISPATCH_APIENTRY crServerDispatchDrawBuffers( GLsizei n, const GLenum* bufs )
1339{
1340 if (n == 1)
1341 {
1342 crServerDispatchDrawBuffer( bufs[0] );
1343 }
1344 else
1345 {
1346 /** @todo State tracker. */
1347 cr_server.head_spu->dispatch_table.DrawBuffers( n, bufs );
1348 }
1349}
1350
1351void SERVER_DISPATCH_APIENTRY crServerDispatchReadBuffer( GLenum mode )
1352{
1353 crStateReadBuffer( mode );
1354
1355 if (crServerIsRedirectedToFBO()
1356 && cr_server.curClient->currentMural->aidFBOs[0]
1357 && !crStateGetCurrent()->framebufferobject.readFB)
1358 {
1359 CRMuralInfo *mural = cr_server.curClient->currentMural;
1360 GLint iBufferNeeded = -1;
1361 switch (mode)
1362 {
1363 case GL_BACK:
1364 case GL_BACK_LEFT:
1365 case GL_BACK_RIGHT:
1366 mode = GL_COLOR_ATTACHMENT0;
1367 iBufferNeeded = CR_SERVER_FBO_BB_IDX(mural);
1368 break;
1369 case GL_FRONT:
1370 case GL_FRONT_LEFT:
1371 case GL_FRONT_RIGHT:
1372 mode = GL_COLOR_ATTACHMENT0;
1373 iBufferNeeded = CR_SERVER_FBO_FB_IDX(mural);
1374 break;
1375 case GL_NONE:
1376 crDebug("ReadBuffer: GL_NONE");
1377 break;
1378 case GL_AUX0:
1379 crDebug("ReadBuffer: GL_AUX0");
1380 break;
1381 case GL_AUX1:
1382 crDebug("ReadBuffer: GL_AUX1");
1383 break;
1384 case GL_AUX2:
1385 crDebug("ReadBuffer: GL_AUX2");
1386 break;
1387 case GL_AUX3:
1388 crDebug("ReadBuffer: GL_AUX3");
1389 break;
1390 case GL_LEFT:
1391 crWarning("ReadBuffer: GL_LEFT not supported properly");
1392 mode = GL_COLOR_ATTACHMENT0;
1393 iBufferNeeded = CR_SERVER_FBO_BB_IDX(mural);
1394 break;
1395 case GL_RIGHT:
1396 crWarning("ReadBuffer: GL_RIGHT not supported properly");
1397 mode = GL_COLOR_ATTACHMENT0;
1398 iBufferNeeded = CR_SERVER_FBO_BB_IDX(mural);
1399 break;
1400 case GL_FRONT_AND_BACK:
1401 crWarning("ReadBuffer: GL_FRONT_AND_BACK not supported properly");
1402 mode = GL_COLOR_ATTACHMENT0;
1403 iBufferNeeded = CR_SERVER_FBO_BB_IDX(mural);
1404 break;
1405 default:
1406 crWarning("ReadBuffer: unexpected mode! 0x%x", mode);
1407 iBufferNeeded = mural->iCurDrawBuffer;
1408 break;
1409 }
1410
1411 Assert(CR_SERVER_FBO_FOR_IDX(mural, mural->iCurReadBuffer));
1412 if (iBufferNeeded != mural->iCurReadBuffer)
1413 {
1414 mural->iCurReadBuffer = iBufferNeeded;
1415 cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_READ_FRAMEBUFFER, CR_SERVER_FBO_FOR_IDX(mural, iBufferNeeded));
1416 }
1417 }
1418 cr_server.head_spu->dispatch_table.ReadBuffer( mode );
1419}
1420
1421GLenum SERVER_DISPATCH_APIENTRY crServerDispatchGetError( void )
1422{
1423 GLenum retval, err;
1424 CRContext *ctx = crStateGetCurrent();
1425 retval = ctx->error;
1426
1427 err = cr_server.head_spu->dispatch_table.GetError();
1428 if (retval == GL_NO_ERROR)
1429 retval = err;
1430 else
1431 ctx->error = GL_NO_ERROR;
1432
1433 /* our impl has a single error flag, so we just loop here to reset all error flags to no_error */
1434 while (err != GL_NO_ERROR)
1435 err = cr_server.head_spu->dispatch_table.GetError();
1436
1437 crServerReturnValue( &retval, sizeof(retval) );
1438 return retval; /* WILL PROBABLY BE IGNORED */
1439}
1440
1441void SERVER_DISPATCH_APIENTRY
1442crServerMakeTmpCtxCurrent( GLint window, GLint nativeWindow, GLint context )
1443{
1444 CRContext *pCtx = crStateGetCurrent();
1445 CRContext *pCurCtx = NULL;
1446 GLuint idDrawFBO = 0, idReadFBO = 0;
1447 int fDoPrePostProcess = 0;
1448
1449 if (pCtx)
1450 {
1451 CRMuralInfo *pCurrentMural = cr_server.currentMural;
1452
1453 pCurCtx = cr_server.currentCtxInfo ? cr_server.currentCtxInfo->pContext : cr_server.MainContextInfo.pContext;
1454 Assert(pCurCtx == pCtx);
1455
1456 if (!context)
1457 {
1458 if (pCurrentMural)
1459 {
1460 Assert(cr_server.currentCtxInfo);
1461 context = cr_server.currentCtxInfo->SpuContext > 0 ? cr_server.currentCtxInfo->SpuContext : cr_server.MainContextInfo.SpuContext;
1462 window = pCurrentMural->spuWindow;
1463 }
1464 else
1465 {
1466 CRMuralInfo * pDummy;
1467 Assert(!cr_server.currentCtxInfo);
1468 pDummy = crServerGetDummyMural(cr_server.MainContextInfo.CreateInfo.realVisualBits);
1469 context = cr_server.MainContextInfo.SpuContext;
1470 window = pDummy->spuWindow;
1471 }
1472
1473
1474 fDoPrePostProcess = -1;
1475 }
1476 else
1477 {
1478 fDoPrePostProcess = 1;
1479 }
1480
1481 if (pCurrentMural)
1482 {
1483 idDrawFBO = CR_SERVER_FBO_FOR_IDX(pCurrentMural, pCurrentMural->iCurDrawBuffer);
1484 idReadFBO = CR_SERVER_FBO_FOR_IDX(pCurrentMural, pCurrentMural->iCurReadBuffer);
1485 }
1486 else
1487 {
1488 idDrawFBO = 0;
1489 idReadFBO = 0;
1490 }
1491 }
1492 else
1493 {
1494 /* this is a GUI thread, so no need to do anything here */
1495 }
1496
1497 if (fDoPrePostProcess > 0)
1498 crStateSwitchPrepare(NULL, pCurCtx, idDrawFBO, idReadFBO);
1499
1500 cr_server.head_spu->dispatch_table.MakeCurrent( window, nativeWindow, context);
1501
1502 if (fDoPrePostProcess < 0)
1503 crStateSwitchPostprocess(pCurCtx, NULL, idDrawFBO, idReadFBO);
1504}
1505
1506void crServerInitTmpCtxDispatch()
1507{
1508 MakeCurrentFunc_t pfnMakeCurrent;
1509
1510 crSPUInitDispatchTable(&cr_server.TmpCtxDispatch);
1511 crSPUCopyDispatchTable(&cr_server.TmpCtxDispatch, &cr_server.head_spu->dispatch_table);
1512 cr_server.TmpCtxDispatch.MakeCurrent = crServerMakeTmpCtxCurrent;
1513
1514 pfnMakeCurrent = crServerMakeTmpCtxCurrent;
1515 cr_server.head_spu->dispatch_table.ChromiumParametervCR(GL_HH_SET_TMPCTX_MAKE_CURRENT, GL_BYTE, sizeof (void*), &pfnMakeCurrent);
1516
1517}
1518
1519/* dump stuff */
1520#ifdef VBOX_WITH_CRSERVER_DUMPER
1521
1522# ifndef VBOX_WITH_CRDUMPER
1523# error "VBOX_WITH_CRDUMPER undefined!"
1524# endif
1525
1526/* first four bits are buffer dump config
1527 * second four bits are texture dump config
1528 * config flags:
1529 * 1 - blit on enter
1530 * 2 - blit on exit
1531 *
1532 *
1533 * Example:
1534 *
1535 * 0x03 - dump buffer on enter and exit
1536 * 0x22 - dump texture and buffer on exit */
1537
1538int64_t g_CrDbgDumpPid = 0;
1539unsigned long g_CrDbgDumpEnabled = 0;
1540unsigned long g_CrDbgDumpDraw = 0
1541#if 0
1542 | CR_SERVER_DUMP_F_COMPILE_SHADER
1543 | CR_SERVER_DUMP_F_LINK_PROGRAM
1544#endif
1545 ;
1546#if 0
1547 | CR_SERVER_DUMP_F_DRAW_BUFF_ENTER
1548 | CR_SERVER_DUMP_F_DRAW_BUFF_LEAVE
1549 | CR_SERVER_DUMP_F_DRAW_PROGRAM_UNIFORMS_ENTER
1550 | CR_SERVER_DUMP_F_DRAW_PROGRAM_ATTRIBS_ENTER
1551 | CR_SERVER_DUMP_F_DRAW_TEX_ENTER
1552 | CR_SERVER_DUMP_F_DRAW_PROGRAM_ENTER
1553 | CR_SERVER_DUMP_F_DRAW_STATE_ENTER
1554 | CR_SERVER_DUMP_F_SWAPBUFFERS_ENTER
1555 | CR_SERVER_DUMP_F_DRAWEL
1556 | CR_SERVER_DUMP_F_SHADER_SOURCE
1557 ;
1558#endif
1559unsigned long g_CrDbgDumpDrawFramesSettings = CR_SERVER_DUMP_F_DRAW_BUFF_ENTER
1560 | CR_SERVER_DUMP_F_DRAW_BUFF_LEAVE
1561 | CR_SERVER_DUMP_F_DRAW_TEX_ENTER
1562 | CR_SERVER_DUMP_F_DRAW_PROGRAM_ENTER
1563 | CR_SERVER_DUMP_F_COMPILE_SHADER
1564 | CR_SERVER_DUMP_F_LINK_PROGRAM
1565 | CR_SERVER_DUMP_F_SWAPBUFFERS_ENTER;
1566unsigned long g_CrDbgDumpDrawFramesAppliedSettings = 0;
1567unsigned long g_CrDbgDumpDrawFramesSavedInitSettings = 0;
1568unsigned long g_CrDbgDumpDrawFramesCount = 0;
1569
1570uint32_t g_CrDbgDumpDrawCount = 0;
1571uint32_t g_CrDbgDumpDumpOnCount = 10;
1572uint32_t g_CrDbgDumpDumpOnCountEnabled = 0;
1573uint32_t g_CrDbgDumpDumpOnCountPerform = 0;
1574uint32_t g_CrDbgDumpDrawFlags = CR_SERVER_DUMP_F_COMPILE_SHADER
1575 | CR_SERVER_DUMP_F_SHADER_SOURCE
1576 | CR_SERVER_DUMP_F_COMPILE_SHADER
1577 | CR_SERVER_DUMP_F_LINK_PROGRAM
1578 | CR_SERVER_DUMP_F_DRAW_BUFF_ENTER
1579 | CR_SERVER_DUMP_F_DRAW_BUFF_LEAVE
1580 | CR_SERVER_DUMP_F_DRAW_TEX_ENTER
1581 | CR_SERVER_DUMP_F_DRAW_PROGRAM_UNIFORMS_ENTER
1582 | CR_SERVER_DUMP_F_DRAW_PROGRAM_ATTRIBS_ENTER
1583 | CR_SERVER_DUMP_F_DRAW_PROGRAM_ENTER
1584 | CR_SERVER_DUMP_F_DRAW_STATE_ENTER
1585 | CR_SERVER_DUMP_F_SWAPBUFFERS_ENTER
1586 | CR_SERVER_DUMP_F_DRAWEL
1587 | CR_SERVER_DUMP_F_TEXPRESENT;
1588
1589void crServerDumpCheckTerm()
1590{
1591 if (!CrBltIsInitialized(&cr_server.RecorderBlitter))
1592 return;
1593
1594 CrBltTerm(&cr_server.RecorderBlitter);
1595}
1596
1597int crServerDumpCheckInit()
1598{
1599 int rc;
1600 CR_BLITTER_WINDOW BltWin;
1601 CR_BLITTER_CONTEXT BltCtx;
1602 CRMuralInfo *pBlitterMural;
1603
1604 if (!CrBltIsInitialized(&cr_server.RecorderBlitter))
1605 {
1606 pBlitterMural = crServerGetDummyMural(cr_server.MainContextInfo.CreateInfo.realVisualBits);
1607 if (!pBlitterMural)
1608 {
1609 crWarning("crServerGetDummyMural failed");
1610 return VERR_GENERAL_FAILURE;
1611 }
1612
1613 crServerVBoxBlitterWinInit(&BltWin, pBlitterMural);
1614 crServerVBoxBlitterCtxInit(&BltCtx, &cr_server.MainContextInfo);
1615
1616 rc = CrBltInit(&cr_server.RecorderBlitter, &BltCtx, true, true, NULL, &cr_server.TmpCtxDispatch);
1617 if (!RT_SUCCESS(rc))
1618 {
1619 crWarning("CrBltInit failed rc %d", rc);
1620 return rc;
1621 }
1622
1623 rc = CrBltMuralSetCurrentInfo(&cr_server.RecorderBlitter, &BltWin);
1624 if (!RT_SUCCESS(rc))
1625 {
1626 crWarning("CrBltMuralSetCurrentInfo failed rc %d", rc);
1627 return rc;
1628 }
1629 }
1630
1631#if 0
1632 crDmpDbgPrintInit(&cr_server.DbgPrintDumper);
1633 cr_server.pDumper = &cr_server.DbgPrintDumper.Base;
1634#else
1635 if (!crDmpHtmlIsInited(&cr_server.HtmlDumper))
1636 {
1637 static int cCounter = 0;
1638// crDmpHtmlInit(&cr_server.HtmlDumper, "S:\\projects\\virtualbox\\3d\\dumps\\1", "index.html");
1639 crDmpHtmlInitF(&cr_server.HtmlDumper, "/Users/oracle-mac/vbox/dump/1", "index%d.html", cCounter);
1640 cr_server.pDumper = &cr_server.HtmlDumper.Base;
1641 ++cCounter;
1642 }
1643#endif
1644
1645 crRecInit(&cr_server.Recorder, &cr_server.RecorderBlitter, &cr_server.TmpCtxDispatch, cr_server.pDumper);
1646 return VINF_SUCCESS;
1647}
1648
1649void crServerDumpShader(GLint id)
1650{
1651 CRContext *ctx = crStateGetCurrent();
1652 crRecDumpShader(&cr_server.Recorder, ctx, id, 0);
1653}
1654
1655void crServerDumpProgram(GLint id)
1656{
1657 CRContext *ctx = crStateGetCurrent();
1658 crRecDumpProgram(&cr_server.Recorder, ctx, id, 0);
1659}
1660
1661void crServerDumpCurrentProgram()
1662{
1663 CRContext *ctx = crStateGetCurrent();
1664 crRecDumpCurrentProgram(&cr_server.Recorder, ctx);
1665}
1666
1667void crServerDumpRecompileDumpCurrentProgram()
1668{
1669 crDmpStrF(cr_server.Recorder.pDumper, "==Dump(1)==");
1670 crServerRecompileCurrentProgram();
1671 crServerDumpCurrentProgramUniforms();
1672 crServerDumpCurrentProgramAttribs();
1673 crDmpStrF(cr_server.Recorder.pDumper, "Done Dump(1)");
1674 crServerRecompileCurrentProgram();
1675 crDmpStrF(cr_server.Recorder.pDumper, "Dump(2)");
1676 crServerRecompileCurrentProgram();
1677 crServerDumpCurrentProgramUniforms();
1678 crServerDumpCurrentProgramAttribs();
1679 crDmpStrF(cr_server.Recorder.pDumper, "Done Dump(2)");
1680}
1681
1682void crServerRecompileCurrentProgram()
1683{
1684 CRContext *ctx = crStateGetCurrent();
1685 crRecRecompileCurrentProgram(&cr_server.Recorder, ctx);
1686}
1687
1688void crServerDumpCurrentProgramUniforms()
1689{
1690 CRContext *ctx = crStateGetCurrent();
1691 crDmpStrF(cr_server.Recorder.pDumper, "==Uniforms==");
1692 crRecDumpCurrentProgramUniforms(&cr_server.Recorder, ctx);
1693 crDmpStrF(cr_server.Recorder.pDumper, "==Done Uniforms==");
1694}
1695
1696void crServerDumpCurrentProgramAttribs()
1697{
1698 CRContext *ctx = crStateGetCurrent();
1699 crDmpStrF(cr_server.Recorder.pDumper, "==Attribs==");
1700 crRecDumpCurrentProgramAttribs(&cr_server.Recorder, ctx);
1701 crDmpStrF(cr_server.Recorder.pDumper, "==Done Attribs==");
1702}
1703
1704void crServerDumpState()
1705{
1706 CRContext *ctx = crStateGetCurrent();
1707 crRecDumpGlGetState(&cr_server.Recorder, ctx);
1708 crRecDumpGlEnableState(&cr_server.Recorder, ctx);
1709}
1710
1711void crServerDumpDrawel(const char*pszFormat, ...)
1712{
1713 CRContext *ctx = crStateGetCurrent();
1714 va_list pArgList;
1715 va_start(pArgList, pszFormat);
1716 crRecDumpVertAttrV(&cr_server.Recorder, ctx, pszFormat, pArgList);
1717 va_end(pArgList);
1718}
1719
1720void crServerDumpDrawelv(GLuint idx, const char*pszElFormat, uint32_t cbEl, const void *pvVal, uint32_t cVal)
1721{
1722 CRContext *ctx = crStateGetCurrent();
1723 crRecDumpVertAttrv(&cr_server.Recorder, ctx, idx, pszElFormat, cbEl, pvVal, cVal);
1724}
1725
1726void crServerDumpBuffer(int idx)
1727{
1728 CRContextInfo *pCtxInfo = cr_server.currentCtxInfo;
1729 CRContext *ctx = crStateGetCurrent();
1730 GLint idFBO;
1731 GLint idTex;
1732 VBOXVR_TEXTURE RedirTex;
1733 int rc = crServerDumpCheckInit();
1734 idx = idx >= 0 ? idx : crServerMuralFBOIdxFromBufferName(cr_server.currentMural, pCtxInfo->pContext->buffer.drawBuffer);
1735 if (!RT_SUCCESS(rc))
1736 {
1737 crWarning("crServerDumpCheckInit failed, rc %d", rc);
1738 return;
1739 }
1740
1741 if (idx < 0)
1742 {
1743 crWarning("neg idx, unsupported");
1744 return;
1745 }
1746
1747 idFBO = CR_SERVER_FBO_FOR_IDX(cr_server.currentMural, idx);
1748 idTex = CR_SERVER_FBO_TEX_FOR_IDX(cr_server.currentMural, idx);
1749
1750 RedirTex.width = cr_server.currentMural->fboWidth;
1751 RedirTex.height = cr_server.currentMural->fboHeight;
1752 RedirTex.target = GL_TEXTURE_2D;
1753 RedirTex.hwid = idTex;
1754
1755 crRecDumpBuffer(&cr_server.Recorder, ctx, idFBO, idTex ? &RedirTex : NULL);
1756}
1757
1758void crServerDumpTexture(const VBOXVR_TEXTURE *pTex)
1759{
1760 CRContextInfo *pCtxInfo = cr_server.currentCtxInfo;
1761 CR_BLITTER_WINDOW BltWin;
1762 CR_BLITTER_CONTEXT BltCtx;
1763 CRContext *ctx = crStateGetCurrent();
1764 int rc = crServerDumpCheckInit();
1765 if (!RT_SUCCESS(rc))
1766 {
1767 crWarning("crServerDumpCheckInit failed, rc %d", rc);
1768 return;
1769 }
1770
1771 crServerVBoxBlitterWinInit(&BltWin, cr_server.currentMural);
1772 crServerVBoxBlitterCtxInit(&BltCtx, pCtxInfo);
1773
1774 crRecDumpTextureF(&cr_server.Recorder, pTex, &BltCtx, &BltWin, "Tex (%d x %d), hwid (%d) target %#x", pTex->width, pTex->height, pTex->hwid, pTex->target);
1775}
1776
1777void crServerDumpTextures()
1778{
1779 CRContextInfo *pCtxInfo = cr_server.currentCtxInfo;
1780 CRContext *ctx = crStateGetCurrent();
1781 int rc = crServerDumpCheckInit();
1782 if (!RT_SUCCESS(rc))
1783 {
1784 crWarning("crServerDumpCheckInit failed, rc %d", rc);
1785 return;
1786 }
1787
1788 crRecDumpTextures(&cr_server.Recorder, ctx);
1789}
1790
1791void crServerDumpFilterOpLeave(unsigned long event, CR_DUMPER *pDumper)
1792{
1793 if (CR_SERVER_DUMP_F_DRAW_LEAVE_ALL & event)
1794 {
1795 g_CrDbgDumpDumpOnCountPerform = 0;
1796 }
1797}
1798
1799bool crServerDumpFilterOpEnter(unsigned long event, CR_DUMPER *pDumper)
1800{
1801 if ((CR_SERVER_DUMP_F_SWAPBUFFERS_ENTER & event)
1802 || (CR_SERVER_DUMP_F_TEXPRESENT & event))
1803 {
1804 if (g_CrDbgDumpDumpOnCountEnabled == 1)
1805 g_CrDbgDumpDumpOnCountEnabled = 2;
1806 else if (g_CrDbgDumpDumpOnCountEnabled)
1807 {
1808 g_CrDbgDumpDumpOnCountEnabled = 0;
1809 if (cr_server.pDumper == &cr_server.HtmlDumper.Base)
1810 {
1811 crDmpHtmlTerm(&cr_server.HtmlDumper);
1812 cr_server.pDumper = NULL;
1813 }
1814 }
1815
1816 g_CrDbgDumpDrawCount = 0;
1817 }
1818 else if (CR_SERVER_DUMP_F_DRAW_ENTER_ALL & event)
1819 {
1820 if (g_CrDbgDumpDumpOnCountEnabled == 2)
1821 {
1822 if (g_CrDbgDumpDumpOnCount == g_CrDbgDumpDrawCount)
1823 {
1824 g_CrDbgDumpDumpOnCountPerform = 1;
1825 }
1826 ++g_CrDbgDumpDrawCount;
1827 }
1828 }
1829 if (g_CrDbgDumpDumpOnCountPerform)
1830 {
1831 if (g_CrDbgDumpDrawFlags & event)
1832 return true;
1833 }
1834 return CR_SERVER_DUMP_DEFAULT_FILTER_OP(event);
1835}
1836
1837bool crServerDumpFilterDmp(unsigned long event, CR_DUMPER *pDumper)
1838{
1839 if (g_CrDbgDumpDumpOnCountPerform)
1840 {
1841 if (g_CrDbgDumpDrawFlags & event)
1842 return true;
1843 }
1844 return CR_SERVER_DUMP_DEFAULT_FILTER_DMP(event);
1845}
1846
1847void crServerDumpFramesCheck()
1848{
1849 if (!g_CrDbgDumpDrawFramesCount)
1850 return;
1851
1852 if (!g_CrDbgDumpDrawFramesAppliedSettings)
1853 {
1854 if (!g_CrDbgDumpDrawFramesSettings)
1855 {
1856 crWarning("g_CrDbgDumpDrawFramesSettings is NULL, bump will not be started");
1857 g_CrDbgDumpDrawFramesCount = 0;
1858 return;
1859 }
1860
1861 g_CrDbgDumpDrawFramesSavedInitSettings = g_CrDbgDumpDraw;
1862 g_CrDbgDumpDrawFramesAppliedSettings = g_CrDbgDumpDrawFramesSettings;
1863 g_CrDbgDumpDraw = g_CrDbgDumpDrawFramesSettings;
1864 crDmpStrF(cr_server.Recorder.pDumper, "***Starting draw dump for %d frames, settings(0x%x)", g_CrDbgDumpDrawFramesCount, g_CrDbgDumpDraw);
1865 return;
1866 }
1867
1868 --g_CrDbgDumpDrawFramesCount;
1869
1870 if (!g_CrDbgDumpDrawFramesCount)
1871 {
1872 crDmpStrF(cr_server.Recorder.pDumper, "***Stop draw dump");
1873 g_CrDbgDumpDraw = g_CrDbgDumpDrawFramesSavedInitSettings;
1874 g_CrDbgDumpDrawFramesAppliedSettings = 0;
1875 }
1876}
1877#endif
1878
1879GLvoid crServerSpriteCoordReplEnable(GLboolean fEnable)
1880{
1881 CRContext *g = crStateGetCurrent();
1882 CRTextureState *t = &(g->texture);
1883 GLuint curTextureUnit = t->curTextureUnit;
1884 GLuint curTextureUnitRestore = curTextureUnit;
1885 GLuint i;
1886
1887 for (i = 0; i < g->limits.maxTextureUnits; ++i)
1888 {
1889 if (g->point.coordReplacement[i])
1890 {
1891 if (i != curTextureUnit)
1892 {
1893 curTextureUnit = i;
1894 cr_server.head_spu->dispatch_table.ActiveTextureARB( i + GL_TEXTURE0_ARB );
1895 }
1896
1897 cr_server.head_spu->dispatch_table.TexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, (GLint)fEnable);
1898 }
1899 }
1900
1901 if (curTextureUnit != curTextureUnitRestore)
1902 {
1903 cr_server.head_spu->dispatch_table.ActiveTextureARB( curTextureUnitRestore + GL_TEXTURE0_ARB );
1904 }
1905}
1906
1907GLvoid SERVER_DISPATCH_APIENTRY crServerDispatchDrawArrays(GLenum mode, GLint first, GLsizei count)
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.DrawArrays(mode, first, count););
1917 CR_SERVER_DUMP_DRAW_LEAVE();
1918 if (mode == GL_POINTS)
1919 crServerSpriteCoordReplEnable(GL_FALSE);
1920}
1921
1922GLvoid SERVER_DISPATCH_APIENTRY crServerDispatchDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices)
1923{
1924#ifdef DEBUG
1925 GLenum status = cr_server.head_spu->dispatch_table.CheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT);
1926 Assert(GL_FRAMEBUFFER_COMPLETE == status);
1927#endif
1928 if (mode == GL_POINTS)
1929 crServerSpriteCoordReplEnable(GL_TRUE);
1930 CR_SERVER_DUMP_DRAW_ENTER();
1931 CR_GLERR_CHECK(cr_server.head_spu->dispatch_table.DrawElements(mode, count, type, indices););
1932 CR_SERVER_DUMP_DRAW_LEAVE();
1933 if (mode == GL_POINTS)
1934 crServerSpriteCoordReplEnable(GL_FALSE);
1935}
1936
1937void SERVER_DISPATCH_APIENTRY crServerDispatchEnd( void )
1938{
1939 CRContext *g = crStateGetCurrent();
1940 GLenum mode = g->current.mode;
1941
1942 crStateEnd();
1943 cr_server.head_spu->dispatch_table.End();
1944
1945 CR_SERVER_DUMP_DRAW_LEAVE();
1946
1947 if (mode == GL_POINTS)
1948 crServerSpriteCoordReplEnable(GL_FALSE);
1949}
1950
1951void SERVER_DISPATCH_APIENTRY crServerDispatchBegin(GLenum mode)
1952{
1953#ifdef DEBUG
1954 CRContext *ctx = crStateGetCurrent();
1955 SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table;
1956
1957 if (ctx->program.vpProgramBinding)
1958 {
1959 AssertRelease(ctx->program.currentVertexProgram);
1960
1961 if (ctx->program.currentVertexProgram->isARBprogram)
1962 {
1963 GLint pid=-1;
1964 gl->GetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_BINDING_ARB, &pid);
1965
1966 if (pid != ctx->program.currentVertexProgram->id)
1967 {
1968 crWarning("pid(%d) != ctx->program.currentVertexProgram->id(%d)", pid, ctx->program.currentVertexProgram->id);
1969 }
1970 AssertRelease(pid == ctx->program.currentVertexProgram->id);
1971 }
1972 else
1973 {
1974 GLint pid=-1;
1975
1976 gl->GetIntegerv(GL_VERTEX_PROGRAM_BINDING_NV, &pid);
1977 if (pid != ctx->program.currentVertexProgram->id)
1978 {
1979 crWarning("pid(%d) != ctx->program.currentVertexProgram->id(%d)", pid, ctx->program.currentVertexProgram->id);
1980 }
1981 AssertRelease(pid == ctx->program.currentVertexProgram->id);
1982 }
1983 }
1984 else if (ctx->glsl.activeProgram)
1985 {
1986 GLint pid=-1;
1987
1988 gl->GetIntegerv(GL_CURRENT_PROGRAM, &pid);
1989 //crDebug("pid %i, state: id %i, hwid %i", pid, ctx->glsl.activeProgram->id, ctx->glsl.activeProgram->hwid);
1990 if (pid != ctx->glsl.activeProgram->hwid)
1991 {
1992 crWarning("pid(%d) != ctx->glsl.activeProgram->hwid(%d)", pid, ctx->glsl.activeProgram->hwid);
1993 }
1994 AssertRelease(pid == ctx->glsl.activeProgram->hwid);
1995 }
1996#endif
1997
1998 if (mode == GL_POINTS)
1999 crServerSpriteCoordReplEnable(GL_TRUE);
2000
2001 CR_SERVER_DUMP_DRAW_ENTER();
2002
2003 crStateBegin(mode);
2004 cr_server.head_spu->dispatch_table.Begin(mode);
2005}
2006
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette