//----------------------------------------------------------------------------// void OpenGLTexture::grabTexture() { // if texture has already been grabbed, do nothing. if (d_grabBuffer) return; std::size_t buffer_size(0); if (OpenGLInfo::getSingleton().isUsingOpenglEs()) { /* OpenGL ES 3.1 or below doesn't support "glGetTexImage"/"glGetCompressedTexImage", so we need to emulate it with "glReadPixels", which will return the data in (umcompressed) format (GL_RGBA, GL_UNSIGNED_BYTE). */ buffer_size = static_cast<std::size_t>(d_dataSize.d_width) *static_cast<std::size_t>(d_dataSize.d_height) *4; d_isCompressed = false; d_format = GL_RGBA; d_subpixelFormat = GL_UNSIGNED_BYTE; } else // Desktop OpenGL buffer_size = static_cast<std::size_t>(d_size.d_width) *static_cast<std::size_t>(d_size.d_height) *4; d_grabBuffer = new std::uint8_t[buffer_size]; blitToMemory(d_grabBuffer); glDeleteTextures(1, &d_ogltexture); }
//----------------------------------------------------------------------------- void D3D9HardwarePixelBuffer::bind(IDirect3DDevice9 *dev, IDirect3DVolume9 *volume, IDirect3DBaseTexture9 *mipTex) { D3D9_DEVICE_ACCESS_CRITICAL_SECTION BufferResources* bufferResources = getBufferResources(dev); bool isNewBuffer = false; if (bufferResources == NULL) { bufferResources = createBufferResources(); mMapDeviceToBufferResources[dev] = bufferResources; isNewBuffer = true; } bufferResources->mipTex = mipTex; bufferResources->volume = volume; bufferResources->volume->AddRef(); D3DVOLUME_DESC desc; if(volume->GetDesc(&desc) != D3D_OK) OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Could not get volume information", "D3D9HardwarePixelBuffer::D3D9HardwarePixelBuffer"); mWidth = desc.Width; mHeight = desc.Height; mDepth = desc.Depth; mFormat = D3D9Mappings::_getPF(desc.Format); // Default mRowPitch = mWidth; mSlicePitch = mHeight*mWidth; mSizeInBytes = PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat); if (isNewBuffer && mOwnerTexture->isManuallyLoaded()) { DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin(); while (it != mMapDeviceToBufferResources.end()) { if (it->second != bufferResources && it->second->volume != NULL && it->first->TestCooperativeLevel() == D3D_OK && dev->TestCooperativeLevel() == D3D_OK) { Box fullBufferBox(0,0,0,mWidth,mHeight,mDepth); PixelBox dstBox(fullBufferBox, mFormat); dstBox.data = OGRE_MALLOC(getSizeInBytes(), MEMCATEGORY_RESOURCE); blitToMemory(fullBufferBox, dstBox, it->second, it->first); blitFromMemory(dstBox, fullBufferBox, bufferResources); OGRE_FREE(dstBox.data, MEMCATEGORY_RESOURCE); break; } ++it; } } }