------------------------------------------------------------------------------
| 1459 | |
| 1460 | //------------------------------------------------------------------------------ |
| 1461 | vtkPixelBufferObject* vtkTextureObject::Download(unsigned int target, unsigned int level) |
| 1462 | { |
| 1463 | assert(this->Context); |
| 1464 | assert(this->Handle); |
| 1465 | |
| 1466 | vtkPixelBufferObject* pbo = vtkPixelBufferObject::New(); |
| 1467 | pbo->SetContext(this->Context); |
| 1468 | |
| 1469 | int vtktype = ::vtkGetVTKType(this->Type); |
| 1470 | if (vtktype == 0) |
| 1471 | { |
| 1472 | vtkErrorMacro("Failed to determine type."); |
| 1473 | return nullptr; |
| 1474 | } |
| 1475 | |
| 1476 | unsigned int size = this->Width * this->Height * this->Depth; |
| 1477 | |
| 1478 | // doesn't matter which Upload*D method we use since we are not really |
| 1479 | // uploading any data, simply allocating GPU space. |
| 1480 | if (!pbo->Upload1D(vtktype, nullptr, size, this->Components, 0)) |
| 1481 | { |
| 1482 | vtkErrorMacro("Could not allocate memory for PBO."); |
| 1483 | pbo->Delete(); |
| 1484 | return nullptr; |
| 1485 | } |
| 1486 | |
| 1487 | pbo->Bind(vtkPixelBufferObject::PACKED_BUFFER); |
| 1488 | this->Bind(); |
| 1489 | |
| 1490 | #ifndef GL_ES_VERSION_3_0 |
| 1491 | glGetTexImage(target, level, this->Format, this->Type, BUFFER_OFFSET(0)); |
| 1492 | #else |
| 1493 | (void)level; |
| 1494 | (void)target; |
| 1495 | // you can do something with glReadPixels and binding a texture as a FBO |
| 1496 | // I believe for ES 2.0 |
| 1497 | #endif |
| 1498 | |
| 1499 | vtkOpenGLCheckErrorMacro("failed at glGetTexImage"); |
| 1500 | this->Deactivate(); |
| 1501 | pbo->UnBind(); |
| 1502 | |
| 1503 | pbo->SetComponents(this->Components); |
| 1504 | |
| 1505 | return pbo; |
| 1506 | } |
| 1507 | |
| 1508 | //------------------------------------------------------------------------------ |
| 1509 | vtkPixelBufferObject* vtkTextureObject::Download() |