Operating System: Windows 10 x64
Render System: OpenGL for the first problem, D3D 9 for the second
Hi,
I have a depth map that I need to update. With OpenGL, I have a crash when updating my render texture by calling this:
Code: Select all
pDepthMapRT->update();
The exact place where it crash is in bindGpuProgramParameters() method:
Code: Select all
//---------------------------------------------------------------------
void GLRenderSystem::bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask)
{
if (mask & (uint16)GPV_GLOBAL)
{
// We could maybe use GL_EXT_bindable_uniform here to produce Dx10-style
// shared constant buffers, but GPU support seems fairly weak?
// for now, just copy
params->_copySharedParams();
}
switch (gptype)
{
case GPT_VERTEX_PROGRAM:
mActiveVertexGpuProgramParameters = params;
mCurrentVertexProgram->bindProgramParameters(params, mask); <-------- It crashes here
break;
case GPT_GEOMETRY_PROGRAM:
mActiveGeometryGpuProgramParameters = params;
mCurrentGeometryProgram->bindProgramParameters(params, mask);
break;
case GPT_FRAGMENT_PROGRAM:
mActiveFragmentGpuProgramParameters = params;
mCurrentFragmentProgram->bindProgramParameters(params, mask);
break;
case GPT_COMPUTE_PROGRAM:
case GPT_DOMAIN_PROGRAM:
case GPT_HULL_PROGRAM:
break;
}
}
With D3D, the crash occurs when trying to copy the pixel buffer contents to a pixel box using the blitToMemoryMethod:
Code: Select all
Ogre::Box extents(0, 0, nXSize, nYSize);
Ogre::PixelBox pb(extents, format, data);
pPixelBuffer->blitToMemory(pb);
The exact place where it crash is:
Code: Select all
// Lock temp surface and copy it to memory
D3DLOCKED_RECT lrect; // Filled in by D3D
if(surface->LockRect(&lrect, NULL, D3DLOCK_READONLY) != D3D_OK) <------- It crashes here
{
surface->Release();
tmp->Release();
OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "surface->LockRect",
"D3D9HardwarePixelBuffer::blitToMemory");
}
// Copy it
PixelBox locked(dst.getWidth(), dst.getHeight(), dst.getDepth(), tmpFormat);
fromD3DLock(locked, lrect);
PixelUtil::bulkPixelConversion(locked, dst);
surface->UnlockRect();
// Release temporary surface and texture
surface->Release();
tmp->Release();
Code: Select all
// Create the texture
Ogre::TexturePtr texPtr = Ogre::TextureManager::getSingleton().getByName("DepthMap");
if (!texPtr)
{
texPtr = Ogre::TextureManager::getSingleton().createManual("DepthMap", kDefaultRessourceGroupName, Ogre::TEX_TYPE_2D, nXSize, nYSize, 0, Ogre::PF_FLOAT32_R, Ogre::TU_RENDERTARGET);
if (!texPtr)
{
ASSERT(FALSE);
return FALSE;
}
}
else
{
texPtr->setWidth(nXSize);
texPtr->setHeight(nYSize);
}
// create the render texture
Ogre::RenderTexture *pDepthMapRT = texPtr->getBuffer()->getRenderTarget();
pDepthMapRT->setAutoUpdated(false);
pDepthMapRT->setPriority(0);
if (pDepthMapRT->getNumViewports() == 0)
{
Ogre::Viewport* pViewport = pDepthMapRT->addViewport(pCamera);
if (pViewport != nullptr)
{
pViewport->setClearEveryFrame(true);
}
}
// Create the material
Ogre::MaterialPtr matPtr = Ogre::MaterialManager::getSingleton().getByName("DepthMap", kMountainsDefaultRessourceGroupName);
if (!matPtr)
{
ASSERT(FALSE);
return FALSE;
}
Ogre::TextureUnitState* pTextUnitState = matPtr->getTechnique(0)->getPass(0)->getTextureUnitState("DepthMap");
if (pTextUnitState == nullptr)
{
matPtr->getTechnique(0)->getPass(0)->createTextureUnitState("DepthMap");
}
matPtr->getTechnique(0)->getPass(0)->setDepthCheckEnabled(true);
matPtr->getTechnique(0)->getPass(0)->setDepthWriteEnabled(true);
matPtr->getTechnique(0)->getPass(0)->setLightingEnabled(false);
// This is the problematic line (with OpenGL)
pDepthMapRT->update();
// Create a buffer to recieve the content of the texture
unsigned char *data = new unsigned char[nXSize * nYSize * outBytesPerPixel];
Ogre::HardwarePixelBufferSharedPtr pPixelBuffer = texPtr->getBuffer();
if (!pPixelBuffer)
{
ASSERT(FALSE);
return FALSE;
}
Ogre::Box extents(0, 0, nXSize, nYSize);
Ogre::PixelBox pb(extents, format, data);
// Copy the pixel buffer contents to the pixel box
// This is the line which leads to a crash with D3D
pPixelBuffer->blitToMemory(pb);
// Get the datas as floats
float* pValues = (float*)pb.data;
Thanks !