From 3371e10b016d31bc7aecd2821198a66a503dfed5 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Mon, 9 Sep 2019 16:06:00 +0200 Subject: [PATCH] ~ fixed segmentation fault when creating a scene + added check for texture rendering on startup ~ fixed possibly wrong texture size for passes ~ changed camera position Signed-off-by: Alexis Maiquez --- main.cpp | 7 +++ src/WallpaperEngine/Core/Scenes/CCamera.cpp | 6 +- src/WallpaperEngine/Render/CCamera.cpp | 6 +- src/WallpaperEngine/Render/CScene.cpp | 14 ++--- src/WallpaperEngine/Render/Objects/CImage.cpp | 58 ++++++++++--------- 5 files changed, 51 insertions(+), 40 deletions(-) diff --git a/main.cpp b/main.cpp index 8146fd0..c140b4a 100644 --- a/main.cpp +++ b/main.cpp @@ -132,6 +132,12 @@ int init_irrlicht() IrrlichtContext->getDevice ()->getLogger ()->log ("WARNING: Vertex shaders disabled because of missing driver/hardware support"); } + if (IrrlichtContext->getDevice ()->getVideoDriver ()->queryFeature (irr::video::EVDF_RENDER_TO_TARGET) == false) + { + IrrlichtContext->getDevice ()->getLogger ()->log ("ERROR: Your hardware or this renderer do not support rendering to texture"); + return 1; + } + return 0; } @@ -299,6 +305,7 @@ int main (int argc, char* argv[]) irr::u32 startTime = 0; irr::u32 endTime = 0; + IrrlichtContext->getDevice ()->getSceneManager ()->setAmbientLight (sceneRender->getScene ()->getAmbientColor ().toSColor ()); while (IrrlichtContext && IrrlichtContext->getDevice () && IrrlichtContext->getDevice ()->run ()) { if (IrrlichtContext->getDevice ()->getVideoDriver () == nullptr) diff --git a/src/WallpaperEngine/Core/Scenes/CCamera.cpp b/src/WallpaperEngine/Core/Scenes/CCamera.cpp index 743a50b..b9fd2ba 100644 --- a/src/WallpaperEngine/Core/Scenes/CCamera.cpp +++ b/src/WallpaperEngine/Core/Scenes/CCamera.cpp @@ -47,8 +47,8 @@ CCamera* CCamera::fromJSON (json data) } return new CCamera ( - WallpaperEngine::Core::ato3vf (*center_it), - WallpaperEngine::Core::ato3vf (*eye_it), - WallpaperEngine::Core::ato3vf (*up_it) + WallpaperEngine::Core::ato3vf (*center_it), + WallpaperEngine::Core::ato3vf (*eye_it), + WallpaperEngine::Core::ato3vf (*up_it) ); } \ No newline at end of file diff --git a/src/WallpaperEngine/Render/CCamera.cpp b/src/WallpaperEngine/Render/CCamera.cpp index a337df7..1d52d58 100644 --- a/src/WallpaperEngine/Render/CCamera.cpp +++ b/src/WallpaperEngine/Render/CCamera.cpp @@ -8,7 +8,7 @@ CCamera::CCamera (CScene* scene, Core::Scenes::CCamera* camera) : m_scene (scene) { this->m_sceneCamera = scene->getContext ()->getDevice ()->getSceneManager ()->addCameraSceneNode ( - scene, *this->getCenter (), *this->getEye (), scene->nextId () + scene, *this->getEye (), *this->getCenter (), scene->nextId () ); } @@ -37,8 +37,8 @@ void CCamera::setOrthogonalProjection (irr::f32 width, irr::f32 height) irr::core::matrix4 identity; identity.makeIdentity (); irr::core::matrix4 orthogonalProjection; orthogonalProjection.buildProjectionMatrixOrthoLH ( width, height, - this->getEye ()->Z, - this->getCenter ()->Z + this->getCenter ()->Z, + this->getEye ()->Z ); this->m_sceneCamera->setProjectionMatrix (orthogonalProjection); diff --git a/src/WallpaperEngine/Render/CScene.cpp b/src/WallpaperEngine/Render/CScene.cpp index 54def38..b71e697 100644 --- a/src/WallpaperEngine/Render/CScene.cpp +++ b/src/WallpaperEngine/Render/CScene.cpp @@ -18,6 +18,12 @@ CScene::CScene (Core::CProject* project, Irrlicht::CContext* context) : m_scene (project->getScene ()), m_context (context) { + this->m_camera = new CCamera (this, this->m_project->getScene ()->getCamera ()); + this->m_camera->setOrthogonalProjection ( + this->m_scene->getOrthogonalProjection ()->getWidth (), + this->m_scene->getOrthogonalProjection ()->getHeight () + ); + std::vector::const_iterator cur = this->m_scene->getObjects ()->begin (); std::vector::const_iterator end = this->m_scene->getObjects ()->end (); @@ -41,12 +47,6 @@ CScene::CScene (Core::CProject* project, Irrlicht::CContext* context) : this->m_nextId = ++highestId; this->setAutomaticCulling (irr::scene::EAC_OFF); this->m_boundingBox = irr::core::aabbox3d(0, 0, 0, 0, 0, 0); - - this->m_camera = new CCamera (this, this->m_project->getScene ()->getCamera ()); - this->m_camera->setOrthogonalProjection ( - this->m_scene->getOrthogonalProjection ()->getWidth (), - this->m_scene->getOrthogonalProjection ()->getHeight () - ); } CScene::~CScene () @@ -77,7 +77,7 @@ void CScene::render () { } -const irr::core::aabbox3d& CScene::getBoundingBox() const +const irr::core::aabbox3d& CScene::getBoundingBox () const { return this->m_boundingBox; } diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index 23e4db9..0767c6d 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -54,7 +54,7 @@ void CImage::render() { uint16_t indices [] = { - 0, 1, 2, 3 + 3, 2, 1, 0 }; irr::video::IVideoDriver* driver = SceneManager->getVideoDriver (); @@ -69,7 +69,7 @@ void CImage::render() { if (textureCur == textureEnd) { - driver->setRenderTarget (0, false, false); + driver->setRenderTarget (irr::video::ERT_FRAME_BUFFER, false, false); } else { @@ -87,9 +87,6 @@ void CImage::render() void CImage::generateMaterial () { - if (this->m_image->getMaterial ()->getPasses ()->empty () == true) - return; - std::vector::const_iterator cur = this->m_image->getMaterial ()->getPasses ()->begin (); std::vector::const_iterator end = this->m_image->getMaterial ()->getPasses ()->end (); @@ -135,13 +132,17 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) if (textureNumber == 0 && this->m_passes > 0) { + irr::video::ITexture* originalTexture = this->getScene ()->getContext ()->getDevice ()->getVideoDriver ()->getTexture (texturepath); + texture = this->getScene ()->getContext ()->getDevice ()->getVideoDriver ()->addRenderTargetTexture ( irr::core::dimension2d ( - this->getScene ()->getScene ()->getOrthogonalProjection()->getWidth (), - this->getScene ()->getScene ()->getOrthogonalProjection()->getHeight () + originalTexture->getSize ().Width, + originalTexture->getSize ().Height ), ("_RT_" + this->m_image->getName () + std::to_string (textureNumber) + "_" + std::to_string (this->m_passes)).c_str () ); + //originalTexture->drop (); + this->m_renderTextures.push_back (texture); } else @@ -149,6 +150,8 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) texture = this->getScene ()->getContext ()->getDevice ()->getVideoDriver ()->getTexture (texturepath); } + //texture->grab (); + material.setTexture (textureNumber, texture); } @@ -165,6 +168,7 @@ void CImage::generatePass (Core::Objects::Images::Materials::CPassess* pass) this, irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL, this->m_passes, irr::video::EGSL_DEFAULT ); + // TODO: TAKE INTO ACCOUNT BLENDING AND CULLING METHODS FROM THE JSON material.setFlag (irr::video::EMF_LIGHTING, false); material.setFlag (irr::video::EMF_BLEND_OPERATION, true); material.Wireframe = false; @@ -192,30 +196,30 @@ void CImage::OnSetConstants (irr::video::IMaterialRendererServices *services, in irr::f32 g_Texture6 = 6; irr::f32 g_Texture7 = 7; - irr::f32 g_Texture0Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; - irr::f32 g_Texture1Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; - irr::f32 g_Texture2Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; - irr::f32 g_Texture3Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; - irr::f32 g_Texture4Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; - irr::f32 g_Texture5Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; - irr::f32 g_Texture6Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; - irr::f32 g_Texture7Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z}; + irr::f32 g_Texture0Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; + irr::f32 g_Texture1Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; + irr::f32 g_Texture2Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; + irr::f32 g_Texture3Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; + irr::f32 g_Texture4Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; + irr::f32 g_Texture5Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; + irr::f32 g_Texture6Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; + irr::f32 g_Texture7Rotation [4] = { this->m_image->getAngles ()->X, this->m_image->getAngles ()->Y, this->m_image->getAngles ()->Z, this->m_image->getAngles ()->Z }; - irr::f32 g_Texture0Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; - irr::f32 g_Texture1Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; - irr::f32 g_Texture2Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; - irr::f32 g_Texture3Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; - irr::f32 g_Texture4Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; - irr::f32 g_Texture5Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; - irr::f32 g_Texture6Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; - irr::f32 g_Texture7Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y}; + irr::f32 g_Texture0Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; + irr::f32 g_Texture1Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; + irr::f32 g_Texture2Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; + irr::f32 g_Texture3Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; + irr::f32 g_Texture4Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; + irr::f32 g_Texture5Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; + irr::f32 g_Texture6Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; + irr::f32 g_Texture7Resolution [4] = { this->m_image->getSize ()->X, this->m_image->getSize ()->Y, this->m_image->getSize ()->X, this->m_image->getSize ()->Y }; irr::video::IVideoDriver* driver = services->getVideoDriver (); - irr::core::matrix4 worldViewProj;worldViewProj.makeIdentity(); - worldViewProj = driver->getTransform(irr::video::ETS_PROJECTION); - worldViewProj *= driver->getTransform(irr::video::ETS_VIEW); - worldViewProj *= driver->getTransform(irr::video::ETS_WORLD); + irr::core::matrix4 worldViewProj; + worldViewProj = driver->getTransform (irr::video::ETS_PROJECTION); + worldViewProj *= driver->getTransform (irr::video::ETS_VIEW); + worldViewProj *= driver->getTransform (irr::video::ETS_WORLD); Render::Shaders::Compiler* vertexShader = this->m_vertexShaders.at (userData); Render::Shaders::Compiler* pixelShader = this->m_pixelShaders.at (userData);