Changeset 32240 in vbox for trunk/src/VBox/HostServices/SharedOpenGL
- Timestamp:
- Sep 5, 2010 2:59:54 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 65564
- Location:
- trunk/src/VBox/HostServices/SharedOpenGL/crserverlib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_getteximage.c
r27983 r32240 42 42 43 43 size = crTextureSize(format, type, width, height, depth); 44 45 #if 0 46 { 47 CRContext *ctx = crStateGetCurrent(); 48 CRTextureObj *tobj; 49 CRTextureLevel *tl; 50 GLint id; 51 52 crDebug("GetTexImage: %d, %i, %d, %d", target, level, format, type); 53 crDebug("===StateTracker==="); 54 crDebug("Current TU: %i", ctx->texture.curTextureUnit); 55 56 if (target==GL_TEXTURE_2D) 57 { 58 tobj = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D; 59 CRASSERT(tobj); 60 tl = &tobj->level[0][level]; 61 crDebug("Texture %i(hw %i), w=%i, h=%i", tobj->id, tobj->hwid, tl->width, tl->height, tl->depth); 62 } 63 else 64 { 65 crDebug("Not 2D tex"); 66 } 67 68 crDebug("===GPU==="); 69 cr_server.head_spu->dispatch_table.GetIntegerv(GL_ACTIVE_TEXTURE, &id); 70 crDebug("Current TU: %i", id); 71 if (target==GL_TEXTURE_2D) 72 { 73 cr_server.head_spu->dispatch_table.GetIntegerv(GL_TEXTURE_BINDING_2D, &id); 74 crDebug("Texture: %i, w=%i, h=%i, d=%i", id, width, height, depth); 75 } 76 } 77 #endif 44 78 45 79 if (size && (buffer = crAlloc(size))) { -
trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_misc.c
r31808 r32240 9 9 #include "cr_error.h" 10 10 #include "cr_mem.h" 11 #include "cr_string.h" 12 #include "cr_pixeldata.h" 11 13 12 14 void SERVER_DISPATCH_APIENTRY crServerDispatchSelectBuffer( GLsizei size, GLuint *buffer ) … … 268 270 } 269 271 272 void SERVER_DISPATCH_APIENTRY 273 crServerDispatchCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) 274 { 275 /*@todo pbo/fbo disabled for now as it's slower, check on other gpus*/ 276 static int siHavePBO = 0; 277 static int siHaveFBO = 0; 278 279 if ((target!=GL_TEXTURE_2D) || (height>=0)) 280 { 281 cr_server.head_spu->dispatch_table.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); 282 } 283 else /* negative height, means we have to Yinvert the source pixels while copying */ 284 { 285 SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table; 286 287 if (siHavePBO<0) 288 { 289 const char *ext = gl->GetString(GL_EXTENSIONS); 290 siHavePBO = crStrstr(ext, "GL_ARB_pixel_buffer_object") ? 1:0; 291 } 292 293 if (siHaveFBO<0) 294 { 295 const char *ext = gl->GetString(GL_EXTENSIONS); 296 siHaveFBO = crStrstr(ext, "GL_EXT_framebuffer_object") ? 1:0; 297 } 298 299 if (siHavePBO==0 && siHaveFBO==0) 300 { 301 GLint dRow, sRow; 302 for (dRow=yoffset, sRow=y-height-1; dRow<yoffset-height; dRow++, sRow--) 303 { 304 gl->CopyTexSubImage2D(target, level, xoffset, dRow, x, sRow, width, 1); 305 } 306 } 307 else if (siHaveFBO==1) /*@todo more states to set and restore here*/ 308 { 309 GLint tID, fboID; 310 GLenum status; 311 CRContext *ctx = crStateGetCurrent(); 312 313 gl->GenTextures(1, &tID); 314 gl->BindTexture(target, tID); 315 gl->CopyTexImage2D(target, level, GL_RGBA, x, y, width, -height, 0); 316 gl->GenFramebuffersEXT(1, &fboID); 317 gl->BindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboID); 318 gl->FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, target, 319 ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->hwid, level); 320 status = gl->CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); 321 if (status != GL_FRAMEBUFFER_COMPLETE_EXT) 322 { 323 crWarning("Framebuffer status 0x%x", status); 324 } 325 326 gl->Enable(target); 327 gl->PushAttrib(GL_VIEWPORT_BIT); 328 gl->Viewport(xoffset, yoffset, width, -height); 329 gl->MatrixMode(GL_PROJECTION); 330 gl->PushMatrix(); 331 gl->LoadIdentity(); 332 gl->MatrixMode(GL_MODELVIEW); 333 gl->PushMatrix(); 334 gl->LoadIdentity(); 335 336 gl->Disable(GL_DEPTH_TEST); 337 gl->Disable(GL_CULL_FACE); 338 gl->Disable(GL_STENCIL_TEST); 339 gl->Disable(GL_SCISSOR_TEST); 340 341 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 342 gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 343 gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 344 gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 345 gl->TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 346 347 gl->Begin(GL_QUADS); 348 gl->TexCoord2f(0.0f, 1.0f); 349 gl->Vertex2f(-1.0, -1.0); 350 351 gl->TexCoord2f(0.0f, 0.0f); 352 gl->Vertex2f(-1.0f, 1.0f); 353 354 gl->TexCoord2f(1.0f, 0.0f); 355 gl->Vertex2f(1.0f, 1.0f); 356 357 gl->TexCoord2f(1.0f, 1.0f); 358 gl->Vertex2f(1.0f, -1.0f); 359 gl->End(); 360 361 gl->PopMatrix(); 362 gl->MatrixMode(GL_PROJECTION); 363 gl->PopMatrix(); 364 gl->PopAttrib(); 365 366 gl->FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, target, 0, level); 367 gl->BindFramebufferEXT(GL_FRAMEBUFFER_EXT, ctx->framebufferobject.drawFB ? ctx->framebufferobject.drawFB->hwid:0); 368 gl->BindTexture(target, ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->hwid); 369 gl->DeleteFramebuffersEXT(1, &fboID); 370 gl->DeleteTextures(1, &tID); 371 372 #if 0 373 { 374 GLint dRow, sRow, w, h; 375 void *img1, *img2; 376 377 w = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->level[0][level].width; 378 h = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->level[0][level].height; 379 380 img1 = crAlloc(4*w*h); 381 img2 = crAlloc(4*w*h); 382 CRASSERT(img1 && img2); 383 384 gl->GetTexImage(target, level, GL_BGRA, GL_UNSIGNED_BYTE, img1); 385 386 387 for (dRow=yoffset, sRow=y-height-1; dRow<yoffset-height; dRow++, sRow--) 388 { 389 gl->CopyTexSubImage2D(target, level, xoffset, dRow, x, sRow, width, 1); 390 } 391 392 gl->GetTexImage(target, level, GL_BGRA, GL_UNSIGNED_BYTE, img2); 393 394 if (crMemcmp(img1, img2, 4*w*h)) 395 { 396 crDebug("MISMATCH! (%x, %i, ->%i,%i <-%i, %i [%ix%i])", target, level, xoffset, yoffset, x, y, width, height); 397 crDumpTGA(w, h, img1); 398 crDumpTGA(w, h, img2); 399 DebugBreak(); 400 } 401 crFree(img1); 402 crFree(img2); 403 } 404 #endif 405 } 406 else 407 { 408 GLint pboId, dRow, sRow; 409 CRContext *ctx = crStateGetCurrent(); 410 411 gl->GenBuffersARB(1, &pboId); 412 gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboId); 413 gl->BufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, -width*height*4, 0, GL_STATIC_COPY_ARB); 414 415 #if 1 416 gl->ReadPixels(x, y, width, -height, GL_RGBA, GL_UNSIGNED_BYTE, 0); 417 gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, ctx->bufferobject.packBuffer->hwid); 418 419 gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboId); 420 for (dRow=yoffset, sRow=-height-1; dRow<yoffset-height; dRow++, sRow--) 421 { 422 gl->TexSubImage2D(target, level, xoffset, dRow, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)((uintptr_t)sRow*width*4)); 423 } 424 #else /*few times slower again*/ 425 for (dRow=0, sRow=y-height-1; dRow<-height; dRow++, sRow--) 426 { 427 gl->ReadPixels(x, sRow, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)((uintptr_t)dRow*width*4)); 428 } 429 gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, ctx->bufferobject.packBuffer->hwid); 430 431 gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboId); 432 gl->TexSubImage2D(target, level, xoffset, yoffset, width, -height, GL_RGBA, GL_UNSIGNED_BYTE, 0); 433 #endif 434 435 gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, ctx->bufferobject.unpackBuffer->hwid); 436 gl->DeleteBuffersARB(1, &pboId); 437 } 438 } 439 } -
trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_special
r31808 r32240 242 242 GetHandleARB 243 243 GetUniformLocation 244 CopyTexSubImage2D
Note:
See TracChangeset
for help on using the changeset viewer.