diff --git a/examples/13.RenderToTexture/main.cpp b/examples/13.RenderToTexture/main.cpp index 1d3166ac..f0145ff3 100644 --- a/examples/13.RenderToTexture/main.cpp +++ b/examples/13.RenderToTexture/main.cpp @@ -175,7 +175,7 @@ int main() // draw scene into render target // set render target texture - driver->setRenderTarget(renderTarget, video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(0,0,0,255)); + driver->setRenderTargetEx(renderTarget, video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(0,0,0,255)); // make cube invisible and set fixed camera as active camera test->setVisible(false); @@ -186,7 +186,7 @@ int main() // set back old render target // The buffer might have been distorted, so clear it - driver->setRenderTarget((video::IRenderTarget*)0, 0, video::SColor(0)); + driver->setRenderTargetEx(0, 0, video::SColor(0)); // make the cube visible and set the user controlled camera as active one test->setVisible(true); diff --git a/include/IVideoDriver.h b/include/IVideoDriver.h index 3a3b22ee..4de489d3 100644 --- a/include/IVideoDriver.h +++ b/include/IVideoDriver.h @@ -576,14 +576,15 @@ namespace video geometry with a render target as texture on it when you are rendering the scene into this render target at the same time. It is usually only possible to render into a texture between the - IVideoDriver::beginScene() and endScene() method calls. + IVideoDriver::beginScene() and endScene() method calls. If you need the + best performance use this method instead of setRenderTarget. \param target Render target object. \param clearFlag A combination of the E_CLEAR_BUFFER_FLAG bit-flags. \param clearColor The clear color for the color buffer. \param clearDepth The clear value for the depth buffer. \param clearStencil The clear value for the stencil buffer. \return True if sucessful and false if not. */ - virtual bool setRenderTarget(IRenderTarget* target, u16 clearFlag, SColor clearColor = SColor(255,0,0,0), + virtual bool setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor = SColor(255,0,0,0), f32 clearDepth = 1.f, u8 clearStencil = 0) = 0; //! Sets a new render target. diff --git a/source/Irrlicht/CD3D9Driver.cpp b/source/Irrlicht/CD3D9Driver.cpp index 3da393e4..6a2fb1e9 100644 --- a/source/Irrlicht/CD3D9Driver.cpp +++ b/source/Irrlicht/CD3D9Driver.cpp @@ -764,7 +764,7 @@ void CD3D9Driver::setTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag, CNullDriver::setTextureCreationFlag(flag, enabled); } -bool CD3D9Driver::setRenderTarget(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) +bool CD3D9Driver::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) { if (target && target->getDriverType() != EDT_DIRECT3D9) { diff --git a/source/Irrlicht/CD3D9Driver.h b/source/Irrlicht/CD3D9Driver.h index 3e24b700..0cb3b667 100644 --- a/source/Irrlicht/CD3D9Driver.h +++ b/source/Irrlicht/CD3D9Driver.h @@ -58,7 +58,7 @@ namespace video //! sets a material virtual void setMaterial(const SMaterial& material) _IRR_OVERRIDE_; - virtual bool setRenderTarget(IRenderTarget* target, u16 clearFlag, SColor clearColor = SColor(255,0,0,0), + virtual bool setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor = SColor(255,0,0,0), f32 clearDepth = 1.f, u8 clearStencil = 0) _IRR_OVERRIDE_; //! sets a viewport diff --git a/source/Irrlicht/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp index f5b19fd3..17d6ec27 100644 --- a/source/Irrlicht/CNullDriver.cpp +++ b/source/Irrlicht/CNullDriver.cpp @@ -678,7 +678,7 @@ ITexture* CNullDriver::createDeviceDependentTextureCubemap(const io::path& name, return new SDummyTexture(name, ETT_CUBEMAP); } -bool CNullDriver::setRenderTarget(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) +bool CNullDriver::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) { return false; } @@ -713,11 +713,11 @@ bool CNullDriver::setRenderTarget(ITexture* texture, u16 clearFlag, SColor clear SharedRenderTarget->setTexture(texture, depthTexture); - return setRenderTarget(SharedRenderTarget, clearFlag, clearColor, clearDepth, clearStencil); + return setRenderTargetEx(SharedRenderTarget, clearFlag, clearColor, clearDepth, clearStencil); } else { - return setRenderTarget((IRenderTarget*)0, clearFlag, clearColor, clearDepth, clearStencil); + return setRenderTargetEx(0, clearFlag, clearColor, clearDepth, clearStencil); } } diff --git a/source/Irrlicht/CNullDriver.h b/source/Irrlicht/CNullDriver.h index c64b8095..1fefe708 100644 --- a/source/Irrlicht/CNullDriver.h +++ b/source/Irrlicht/CNullDriver.h @@ -102,7 +102,7 @@ namespace video virtual ITexture* addTextureCubemap(const io::path& name, IImage* imagePosX, IImage* imageNegX, IImage* imagePosY, IImage* imageNegY, IImage* imagePosZ, IImage* imageNegZ) _IRR_OVERRIDE_; - virtual bool setRenderTarget(IRenderTarget* target, u16 clearFlag, SColor clearColor = SColor(255,0,0,0), + virtual bool setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor = SColor(255,0,0,0), f32 clearDepth = 1.f, u8 clearStencil = 0) _IRR_OVERRIDE_; virtual bool setRenderTarget(ITexture* texture, u16 clearFlag, SColor clearColor = SColor(255,0,0,0), diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index 7a7f456f..3d52c32e 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -3665,7 +3665,7 @@ u32 COpenGLDriver::getMaximalPrimitiveCount() const return 0x7fffffff; } -bool COpenGLDriver::setRenderTarget(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) +bool COpenGLDriver::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) { if (target && target->getDriverType() != EDT_OPENGL) { diff --git a/source/Irrlicht/COpenGLDriver.h b/source/Irrlicht/COpenGLDriver.h index f29daa39..962c1442 100644 --- a/source/Irrlicht/COpenGLDriver.h +++ b/source/Irrlicht/COpenGLDriver.h @@ -335,7 +335,7 @@ namespace video virtual ITexture* addRenderTargetTexture(const core::dimension2d& size, const io::path& name, const ECOLOR_FORMAT format = ECF_UNKNOWN) _IRR_OVERRIDE_; - virtual bool setRenderTarget(IRenderTarget* target, u16 clearFlag, SColor clearColor = SColor(255,0,0,0), + virtual bool setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor = SColor(255,0,0,0), f32 clearDepth = 1.f, u8 clearStencil = 0) _IRR_OVERRIDE_; virtual void clearBuffers(u16 flag, SColor color = SColor(255,0,0,0), f32 depth = 1.f, u8 stencil = 0) _IRR_OVERRIDE_; diff --git a/source/Irrlicht/CSoftwareDriver.cpp b/source/Irrlicht/CSoftwareDriver.cpp index bbaea417..f539af7b 100644 --- a/source/Irrlicht/CSoftwareDriver.cpp +++ b/source/Irrlicht/CSoftwareDriver.cpp @@ -252,7 +252,7 @@ ITexture* CSoftwareDriver::createDeviceDependentTexture(const io::path& name, II return texture; } -bool CSoftwareDriver::setRenderTarget(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) +bool CSoftwareDriver::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) { if (target && target->getDriverType() != EDT_SOFTWARE) { diff --git a/source/Irrlicht/CSoftwareDriver.h b/source/Irrlicht/CSoftwareDriver.h index bc79a398..4c867f2f 100644 --- a/source/Irrlicht/CSoftwareDriver.h +++ b/source/Irrlicht/CSoftwareDriver.h @@ -36,7 +36,7 @@ namespace video //! sets a material virtual void setMaterial(const SMaterial& material) _IRR_OVERRIDE_; - virtual bool setRenderTarget(IRenderTarget* target, u16 clearFlag, SColor clearColor = SColor(255,0,0,0), + virtual bool setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor = SColor(255,0,0,0), f32 clearDepth = 1.f, u8 clearStencil = 0) _IRR_OVERRIDE_; //! sets a viewport diff --git a/source/Irrlicht/CSoftwareDriver2.cpp b/source/Irrlicht/CSoftwareDriver2.cpp index 689a22d3..1b95f239 100644 --- a/source/Irrlicht/CSoftwareDriver2.cpp +++ b/source/Irrlicht/CSoftwareDriver2.cpp @@ -409,7 +409,7 @@ bool CBurningVideoDriver::endScene() return Presenter->present(BackBuffer, WindowId, SceneSourceRect); } -bool CBurningVideoDriver::setRenderTarget(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) +bool CBurningVideoDriver::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) { if (target && target->getDriverType() != EDT_BURNINGSVIDEO) { diff --git a/source/Irrlicht/CSoftwareDriver2.h b/source/Irrlicht/CSoftwareDriver2.h index 5966b9ee..2f3cae16 100644 --- a/source/Irrlicht/CSoftwareDriver2.h +++ b/source/Irrlicht/CSoftwareDriver2.h @@ -39,7 +39,7 @@ namespace video //! sets a material virtual void setMaterial(const SMaterial& material) _IRR_OVERRIDE_; - virtual bool setRenderTarget(IRenderTarget* target, u16 clearFlag, SColor clearColor = SColor(255,0,0,0), + virtual bool setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor = SColor(255,0,0,0), f32 clearDepth = 1.f, u8 clearStencil = 0) _IRR_OVERRIDE_; //! sets a viewport diff --git a/tests/draw2DImage.cpp b/tests/draw2DImage.cpp index 4508f8c5..1d80c041 100644 --- a/tests/draw2DImage.cpp +++ b/tests/draw2DImage.cpp @@ -41,9 +41,9 @@ bool testWithRenderTarget(video::E_DRIVER_TYPE driverType) //draw the 256x256 water image on the rendertarget: - driver->setRenderTarget(renderTarget,video::ECBF_COLOR|video::ECBF_DEPTH,video::SColor(255,0,0,255));//Rendertarget background is blue + driver->setRenderTargetEx(renderTarget,video::ECBF_COLOR|video::ECBF_DEPTH,video::SColor(255,0,0,255));//Rendertarget background is blue driver->draw2DImage(tex, core::position2d(0,0), core::recti(0,0,32,32)); - driver->setRenderTarget((video::IRenderTarget*)0, 0); + driver->setRenderTargetEx(0, 0); //draw the rendertarget on screen: //this should normally draw a 64x64 image containing a 32x32 image in the top left corner @@ -165,9 +165,9 @@ bool testExactPlacement(video::E_DRIVER_TYPE driverType) video::ITexture* tex=driver->getTexture("../media/fireball.bmp"); driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,40,40,255));//Backbuffer background is blue - driver->setRenderTarget(renderTarget, 0, video::ECBF_COLOR | video::ECBF_DEPTH); + driver->setRenderTargetEx(renderTarget, 0, video::ECBF_COLOR | video::ECBF_DEPTH); driver->draw2DImage(tex, core::recti(0,0,32,32), core::recti(0,0,64,64)); - driver->setRenderTarget((video::IRenderTarget*)0, 0, 0); + driver->setRenderTargetEx(0, 0, 0); driver->endScene(); video::IImage* img = driver->createImage(renderTargetTex, core::vector2di(), renderTargetTex->getSize()); diff --git a/tests/mrt.cpp b/tests/mrt.cpp index b13de27d..78db98fc 100644 --- a/tests/mrt.cpp +++ b/tests/mrt.cpp @@ -64,9 +64,9 @@ static bool testWithDriver(video::E_DRIVER_TYPE driverType) driver->beginScene(video::ECBF_COLOR, video::SColor(255, 0, 0, 0)); // render - driver->setRenderTarget(renderTarget, video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,0,0,0)); + driver->setRenderTargetEx(renderTarget, video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,0,0,0)); device->getSceneManager()->drawAll(); - driver->setRenderTarget((video::IRenderTarget*)0, 0, video::SColor(255, 0, 0, 0)); + driver->setRenderTargetEx(0, 0, video::SColor(255, 0, 0, 0)); // draw debug rt driver->draw2DImage(renderTargetTex[0], core::position2d(0,0)); @@ -80,9 +80,9 @@ static bool testWithDriver(video::E_DRIVER_TYPE driverType) driver->beginScene(video::ECBF_COLOR, video::SColor(255, 0, 0, 0)); // render device->getSceneManager()->getActiveCamera()->setPosition(core::vector3df(0,0,-15)); - driver->setRenderTarget(renderTarget, video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,0,0,0)); + driver->setRenderTargetEx(renderTarget, video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,0,0,0)); device->getSceneManager()->drawAll(); - driver->setRenderTarget((video::IRenderTarget*)0, 0, video::SColor(255,0,0,0)); + driver->setRenderTargetEx(0, 0, video::SColor(255,0,0,0)); // draw debug rt driver->draw2DImage(renderTargetTex[0], core::position2d(0,0)); diff --git a/tests/renderTargetTexture.cpp b/tests/renderTargetTexture.cpp index 1cc6d510..65daec33 100644 --- a/tests/renderTargetTexture.cpp +++ b/tests/renderTargetTexture.cpp @@ -190,9 +190,9 @@ bool rttAndZBuffer(video::E_DRIVER_TYPE driverType) { vd->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255, 0, 0, 0)); - vd->setRenderTarget(renderTarget, 0, video::ECBF_COLOR | video::ECBF_DEPTH); + vd->setRenderTargetEx(renderTarget, 0, video::ECBF_COLOR | video::ECBF_DEPTH); sm->drawAll(); - vd->setRenderTarget((video::IRenderTarget*)0, 0, 0); + vd->setRenderTargetEx(0, 0, 0); vd->setTransform(video::ETS_WORLD, core::IdentityMatrix); vd->setTransform(video::ETS_VIEW, core::IdentityMatrix); vd->setTransform(video::ETS_PROJECTION, core::IdentityMatrix); @@ -242,10 +242,10 @@ bool rttAndText(video::E_DRIVER_TYPE driverType) stabilizeScreenBackground(driver); driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,255, 255, 255)); - driver->setRenderTarget(renderTarget, video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,255,0,255)); + driver->setRenderTargetEx(renderTarget, video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,255,0,255)); driver->draw2DImage(driver->getTexture("../media/fireball.bmp"), core::recti(0, 0, renderTargetTex->getSize().Width, renderTargetTex->getSize().Height), core::recti(0, 0, 64, 64)); guienv->getBuiltInFont()->draw(L"OMGGG =!", core::rect(120, 100, 256, 256), video::SColor(255, 0, 0, 255)); - driver->setRenderTarget((video::IRenderTarget*)0, 0, 0); + driver->setRenderTargetEx(0, 0, 0); driver->endScene(); scene::ISceneManager* smgr = device->getSceneManager(); @@ -286,7 +286,7 @@ static void Render(IrrlichtDevice* device, video::IRenderTarget* rt, core::vecto core::vector3df& pos2, scene::IAnimatedMesh* sphereMesh, core::vector3df& pos3, core::vector3df& pos4) { video::IVideoDriver* driver = device->getVideoDriver(); - driver->setRenderTarget(rt, 0, video::ECBF_COLOR | video::ECBF_DEPTH); + driver->setRenderTargetEx(rt, 0, video::ECBF_COLOR | video::ECBF_DEPTH); device->getSceneManager()->drawAll(); video::SMaterial mat; @@ -398,7 +398,7 @@ bool rttAndAntiAliasing(video::E_DRIVER_TYPE driverType) Render(device, renderTarget3, pos1, pos2, sphereMesh, pos3, pos4); Render(device, renderTarget4, pos1, pos2, sphereMesh, pos3, pos4); - device->getVideoDriver()->setRenderTarget((video::IRenderTarget*)0, 0, 0); + device->getVideoDriver()->setRenderTargetEx(0, 0, 0); device->getVideoDriver()->draw2DImage(renderTargetTex1, core::position2di(0, 0)); device->getVideoDriver()->draw2DImage(renderTargetTex2, core::position2di(80, 0)); device->getVideoDriver()->draw2DImage(renderTargetTex3, core::position2di(0, 60)); diff --git a/tests/testUtils.cpp b/tests/testUtils.cpp index ba2553a9..ef3707d6 100644 --- a/tests/testUtils.cpp +++ b/tests/testUtils.cpp @@ -280,8 +280,8 @@ static float fuzzyCompareImages(irr::video::IImage * image1, return 0.f; } - u8 * image1Data = (u8*)image1->lock(); - u8 * image2Data = (u8*)image2->lock(); + u8 * image1Data = (u8*)image1->getData(); + u8 * image2Data = (u8*)image2->getData(); const u32 pixels = (image1->getPitch() * image1->getDimension().Height) / 4; u32 mismatchedColours = 0; @@ -304,9 +304,6 @@ static float fuzzyCompareImages(irr::video::IImage * image1, mismatchedColours += abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2); } - image1->unlock(); - image2->unlock(); - const u32 totalColours = pixels * 255*3; return 100.f * (totalColours - mismatchedColours) / totalColours; } @@ -358,7 +355,7 @@ void stabilizeScreenBackground(irr::video::IVideoDriver * driver, screenshot = fixedScreenshot; } - u8 * image1Data = (u8*)screenshot->lock(); + u8 * image1Data = (u8*)screenshot->getData(); const u32 pixels = (screenshot->getPitch() * screenshot->getDimension().Height) / 4; bool status = true; diff --git a/tests/textureFeatures.cpp b/tests/textureFeatures.cpp index d1a51b50..9076b3e5 100644 --- a/tests/textureFeatures.cpp +++ b/tests/textureFeatures.cpp @@ -53,7 +53,8 @@ bool renderMipLevels(video::E_DRIVER_TYPE driverType) } } - video::ITexture* tex = driver->addTexture("miptest", image, mipdata); + image->setMipMapsData(mipdata, false, true); + video::ITexture* tex = driver->addTexture("miptest", image); if (!tex) // is probably an error in the mipdata handling return false; @@ -131,7 +132,9 @@ bool lockAllMipLevels(video::E_DRIVER_TYPE driverType) } } - video::ITexture* tex = driver->addTexture("miptest", image, mipdata); + image->setMipMapsData(mipdata, false, true); + video::ITexture* tex = driver->addTexture("miptest", image); + if (!tex) // is probably an error in the mipdata handling return false;