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