Go to function:
Code: Select all
void D3D11HardwarePixelBuffer::blit(const HardwarePixelBufferSharedPtr &rsrc, const Image::Box &srcBox, const Image::Box &dstBox)
You will notice that dstZ of the CopySubresourceRegion() function is set to mFace whereas in fact mFace is selected by the D3D11CalcSubresource and simply changing the mFace to 0 fixes the blit for 2d textures to a cubemap face..
Code: Select all
case TEX_TYPE_2D:
{
mDevice.GetImmediateContext()->CopySubresourceRegion(
mParentTexture->GetTex2D(),
D3D11CalcSubresource(static_cast<UINT>(mSubresourceIndex), mFace, mParentTexture->getNumMipmaps() + 1),
static_cast<UINT>(dstBox.left),
static_cast<UINT>(dstBox.top),
0, // <<<<< ------- this changed from mFace to zero as we are not working with a 3D texture.
rsrcDx11->mParentTexture->GetTex2D(),
static_cast<UINT>(rsrcDx11->mSubresourceIndex),
&srcBoxDx11);
if (mDevice.isError())
{
String errorDescription = mDevice.getErrorDescription();
OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR,
"D3D11 device cannot copy 2d subresource Region\nError Description:" + errorDescription,
"D3D11HardwarePixelBuffer::blit");
}
}
break;
The resolution of the end reflection or skybox image is adjustable as are the number of mip maps as they are based on the original resolution..
Code: Select all
void PbsMaterialsGameState::createReflection()
{
size_t imagewidth = 32;
size_t imageheight = 32;
size_t imageDepth = 1;
Ogre::PixelFormat format = Ogre::PF_A8B8G8R8;
parentTex = Ogre::TextureManager::getSingleton().createManual("reflectionTest", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_CUBE_MAP, imagewidth, imageheight, imageDepth, 11, format);
Ogre::String skyboxNames[6] = {"SunSetFront.png" , "SunSetBack.png", "SunSetRight.png", "SunSetLeft.png", "SunSetUp.png" , "SunSetDown.png"};
for (size_t i = 0; i < 6; i++){
Ogre::String texname = skyboxNames[i];
int face = i;
switch (i){ case 0: face = 4; break; case 1: face = 5; break; case 2: face = 1; break; case 3: face = 0; break; case 4: face = 2; break; case 5: face = 3; break; }
Ogre::Image image; image.load(texname, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
image.resize(imagewidth, imageheight);
image.generateMipmaps(true);
Ogre::TexturePtr texPtr = Ogre::TextureManager::getSingleton().loadImage("tempsky1", "General", image, Ogre::TEX_TYPE_2D, image.getNumMipmaps(), 1.0, false, Ogre::PF_A8B8G8R8, true);
Ogre::uint8 minMipmaps = std::min<Ogre::uint8>(image.getNumMipmaps(), parentTex->getNumMipmaps());
for (size_t mip = 0; mip < image.getNumMipmaps(); mip++){
Ogre::v1::HardwarePixelBufferSharedPtr sourceBuffer = texPtr->getBuffer(0, mip);
Ogre::v1::HardwarePixelBufferSharedPtr destBuffer = parentTex->getBuffer(face, mip);
if (sourceBuffer.isNull() || destBuffer.isNull()) {
continue;
}
destBuffer->blit(sourceBuffer);
}
// Remove the temporary texture we used.
Ogre::TextureManager::getSingleton().remove(texPtr);
}
}
So hope this helps and enjoy
Edit: You can apply the texture like other standard 2D textures by calling this on the datablock:
Code: Select all
datablock->setTexture( Ogre::PBSM_REFLECTION, 0, parentTex);