diff --git a/WickedEngine/DeferredRenderableComponent.cpp b/WickedEngine/DeferredRenderableComponent.cpp index 03eb09e3f..6af75f00e 100644 --- a/WickedEngine/DeferredRenderableComponent.cpp +++ b/WickedEngine/DeferredRenderableComponent.cpp @@ -22,15 +22,15 @@ void DeferredRenderableComponent::Initialize() Renderable3DComponent::Initialize(); rtGBuffer.Initialize( - wiRenderer::GetScreenWidth(), wiRenderer::GetScreenHeight() + wiRenderer::GetDevice()->GetScreenWidth(), wiRenderer::GetDevice()->GetScreenHeight() , 3, true, 1, 0 , DXGI_FORMAT_R16G16B16A16_FLOAT ); rtDeferred.Initialize( - wiRenderer::GetScreenWidth(), wiRenderer::GetScreenHeight() + wiRenderer::GetDevice()->GetScreenWidth(), wiRenderer::GetDevice()->GetScreenHeight() , 1, false, 1, 0, DXGI_FORMAT_R16G16B16A16_FLOAT, 0); rtLight.Initialize( - wiRenderer::GetScreenWidth(), wiRenderer::GetScreenHeight() + wiRenderer::GetDevice()->GetScreenWidth(), wiRenderer::GetDevice()->GetScreenHeight() , 1, false, 1, 0 , DXGI_FORMAT_R11G11B10_FLOAT ); @@ -61,7 +61,7 @@ void DeferredRenderableComponent::Render() workerThread->wait(); } - wiRenderer::graphicsDevice->ExecuteDeferredContexts(); + wiRenderer::GetDevice()->ExecuteDeferredContexts(); } else { @@ -82,7 +82,7 @@ void DeferredRenderableComponent::Render() void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID){ static const int tessellationQuality = 0; - wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); + wiImageEffects fx((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()); rtGBuffer.Activate(threadID); { @@ -108,7 +108,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID){ dtDepthCopy.CopyFrom(*rtGBuffer.depth, threadID); - wiRenderer::graphicsDevice->UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID); + wiRenderer::GetDevice()->UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID); wiRenderer::UpdateDepthBuffer(dtDepthCopy.GetTexture(), rtLinearDepth.GetTexture(), threadID); @@ -186,7 +186,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID){ XMFLOAT2 dir = XMFLOAT2(0, 0); static const float stren = 0.018f; if (i % 2) - dir.x = stren*((float)wiRenderer::GetScreenHeight() / (float)wiRenderer::GetScreenWidth()); + dir.x = stren*((float)wiRenderer::GetDevice()->GetScreenHeight() / (float)wiRenderer::GetDevice()->GetScreenWidth()); else dir.y = stren; fx.process.setSSSS(dir); @@ -216,7 +216,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID){ if (getSSREnabled()){ rtSSR.Activate(threadID); { - wiRenderer::graphicsDevice->GenerateMips(rtDeferred.GetTexture(0), threadID); + wiRenderer::GetDevice()->GenerateMips(rtDeferred.GetTexture(0), threadID); fx.process.setSSR(true); //fx.setDepthMap(dtDepthCopy.shaderResource); //fx.setNormalMap(rtGBuffer.shaderResource[1]); @@ -266,7 +266,7 @@ void DeferredRenderableComponent::setPreferredThreadingCount(unsigned short valu { Renderable3DComponent::setPreferredThreadingCount(value); - if (!wiRenderer::graphicsDevice->GetMultithreadingSupport()) + if (!wiRenderer::GetDevice()->GetMultithreadingSupport()) { if (value > 1) wiHelper::messageBox("Multithreaded rendering not supported by your hardware! Falling back to single threading!", "Caution"); @@ -283,7 +283,7 @@ void DeferredRenderableComponent::setPreferredThreadingCount(unsigned short valu { RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); RenderReflections(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); })); workerThreads.push_back(new wiTaskThread([&] { @@ -294,27 +294,27 @@ void DeferredRenderableComponent::setPreferredThreadingCount(unsigned short valu RenderComposition1(GetFinalRT(), GRAPHICSTHREAD_SCENE); RenderBloom(GRAPHICSTHREAD_SCENE); RenderComposition2(GRAPHICSTHREAD_SCENE); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); })); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_SCENE); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); - wiRenderer::graphicsDevice->ExecuteDeferredContexts(); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::GetDevice()->ExecuteDeferredContexts(); break; case 3: workerThreads.push_back(new wiTaskThread([&] { RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); RenderReflections(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); })); workerThreads.push_back(new wiTaskThread([&] { RenderShadows(GRAPHICSTHREAD_SCENE); RenderScene(GRAPHICSTHREAD_SCENE); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); })); workerThreads.push_back(new wiTaskThread([&] { @@ -323,16 +323,16 @@ void DeferredRenderableComponent::setPreferredThreadingCount(unsigned short valu RenderComposition1(GetFinalRT(), GRAPHICSTHREAD_MISC1); RenderBloom(GRAPHICSTHREAD_MISC1); RenderComposition2(GRAPHICSTHREAD_MISC1); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC1); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC1); })); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_SCENE); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_MISC1); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC1); - wiRenderer::graphicsDevice->ExecuteDeferredContexts(); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC1); + wiRenderer::GetDevice()->ExecuteDeferredContexts(); break; case 4: default: @@ -340,37 +340,37 @@ void DeferredRenderableComponent::setPreferredThreadingCount(unsigned short valu { RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); RenderReflections(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); })); workerThreads.push_back(new wiTaskThread([&] { RenderShadows(GRAPHICSTHREAD_SCENE); RenderScene(GRAPHICSTHREAD_SCENE); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); })); workerThreads.push_back(new wiTaskThread([&] { RenderSecondaryScene(rtGBuffer, GetFinalRT(), GRAPHICSTHREAD_MISC1); RenderLightShafts(rtGBuffer, GRAPHICSTHREAD_MISC1); RenderComposition1(GetFinalRT(), GRAPHICSTHREAD_MISC1); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC1); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC1); })); workerThreads.push_back(new wiTaskThread([&] { RenderBloom(GRAPHICSTHREAD_MISC2); RenderComposition2(GRAPHICSTHREAD_MISC2); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC2); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC2); })); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_SCENE); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_MISC1); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC1); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC1); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_MISC2); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC2); - wiRenderer::graphicsDevice->ExecuteDeferredContexts(); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC2); + wiRenderer::GetDevice()->ExecuteDeferredContexts(); break; }; } diff --git a/WickedEngine/ForwardRenderableComponent.cpp b/WickedEngine/ForwardRenderableComponent.cpp index 2a8a3591a..9ad853665 100644 --- a/WickedEngine/ForwardRenderableComponent.cpp +++ b/WickedEngine/ForwardRenderableComponent.cpp @@ -19,7 +19,7 @@ void ForwardRenderableComponent::Initialize() { Renderable3DComponent::Initialize(); - rtMain.Initialize(wiRenderer::GetScreenWidth(), wiRenderer::GetScreenHeight(), 1, true); + rtMain.Initialize(wiRenderer::GetDevice()->GetScreenWidth(), wiRenderer::GetDevice()->GetScreenHeight(), 1, true); Renderable2DComponent::Initialize(); } @@ -49,7 +49,7 @@ void ForwardRenderableComponent::Render() workerThread->wait(); } - wiRenderer::graphicsDevice->ExecuteDeferredContexts(); + wiRenderer::GetDevice()->ExecuteDeferredContexts(); } else { @@ -104,7 +104,7 @@ void ForwardRenderableComponent::setPreferredThreadingCount(unsigned short value { Renderable3DComponent::setPreferredThreadingCount(value); - if (!wiRenderer::graphicsDevice->GetMultithreadingSupport()) + if (!wiRenderer::GetDevice()->GetMultithreadingSupport()) { if (value > 1) wiHelper::messageBox("Multithreaded rendering not supported by your hardware! Falling back to single threading!", "Caution"); @@ -121,7 +121,7 @@ void ForwardRenderableComponent::setPreferredThreadingCount(unsigned short value { RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); RenderReflections(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); })); workerThreads.push_back(new wiTaskThread([&] { @@ -132,27 +132,27 @@ void ForwardRenderableComponent::setPreferredThreadingCount(unsigned short value RenderComposition1(rtMain, GRAPHICSTHREAD_SCENE); RenderBloom(GRAPHICSTHREAD_SCENE); RenderComposition2(GRAPHICSTHREAD_SCENE); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); })); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_SCENE); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); - wiRenderer::graphicsDevice->ExecuteDeferredContexts(); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::GetDevice()->ExecuteDeferredContexts(); break; case 3: workerThreads.push_back(new wiTaskThread([&] { RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); RenderReflections(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); })); workerThreads.push_back(new wiTaskThread([&] { RenderShadows(GRAPHICSTHREAD_SCENE); RenderScene(GRAPHICSTHREAD_SCENE); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); })); workerThreads.push_back(new wiTaskThread([&] { @@ -161,16 +161,16 @@ void ForwardRenderableComponent::setPreferredThreadingCount(unsigned short value RenderComposition1(rtMain, GRAPHICSTHREAD_MISC1); RenderBloom(GRAPHICSTHREAD_MISC1); RenderComposition2(GRAPHICSTHREAD_MISC1); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC1); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC1); })); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_SCENE); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_MISC1); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC1); - wiRenderer::graphicsDevice->ExecuteDeferredContexts(); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC1); + wiRenderer::GetDevice()->ExecuteDeferredContexts(); break; case 4: default: @@ -178,37 +178,37 @@ void ForwardRenderableComponent::setPreferredThreadingCount(unsigned short value { RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); RenderReflections(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); })); workerThreads.push_back(new wiTaskThread([&] { RenderShadows(GRAPHICSTHREAD_SCENE); RenderScene(GRAPHICSTHREAD_SCENE); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); })); workerThreads.push_back(new wiTaskThread([&] { RenderSecondaryScene(rtMain, rtMain, GRAPHICSTHREAD_MISC1); RenderLightShafts(rtMain, GRAPHICSTHREAD_MISC1); RenderComposition1(rtMain, GRAPHICSTHREAD_MISC1); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC1); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC1); })); workerThreads.push_back(new wiTaskThread([&] { RenderBloom(GRAPHICSTHREAD_MISC2); RenderComposition2(GRAPHICSTHREAD_MISC2); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC2); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC2); })); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_SCENE); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_MISC1); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC1); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC1); wiRenderer::RebindPersistentState(GRAPHICSTHREAD_MISC2); - wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC2); - wiRenderer::graphicsDevice->ExecuteDeferredContexts(); + wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC2); + wiRenderer::GetDevice()->ExecuteDeferredContexts(); break; }; } diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index 7bbd61635..c3a0117a9 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -130,9 +130,9 @@ void MainComponent::Render() { wiLua::GetGlobal()->Render(); - wiRenderer::graphicsDevice->LOCK(); + wiRenderer::GetDevice()->LOCK(); getActiveComponent()->Render(); - wiRenderer::graphicsDevice->UNLOCK(); + wiRenderer::GetDevice()->UNLOCK(); } void MainComponent::Compose() @@ -143,8 +143,8 @@ void MainComponent::Compose() { // display fade rect static wiImageEffects fx; - fx.siz.x = (float)wiRenderer::GetScreenWidth(); - fx.siz.y = (float)wiRenderer::GetScreenHeight(); + fx.siz.x = (float)wiRenderer::GetDevice()->GetScreenWidth(); + fx.siz.y = (float)wiRenderer::GetDevice()->GetScreenHeight(); fx.opacity = fadeManager.opacity; wiImage::Draw(wiTextureHelper::getInstance()->getColor(fadeManager.color), fx); } @@ -159,7 +159,7 @@ void MainComponent::Compose() } if (infoDisplay.resolution) { - ss << "Resolution: " << wiRenderer::GetScreenWidth() << " x " << wiRenderer::GetScreenHeight() << endl; + ss << "Resolution: " << wiRenderer::GetDevice()->GetScreenWidth() << " x " << wiRenderer::GetDevice()->GetScreenHeight() << endl; } if (infoDisplay.fpsinfo) { @@ -198,11 +198,7 @@ bool MainComponent::setWindow(HWND hWnd, HINSTANCE hInst) screenH = rect.bottom - rect.top; } - if (FAILED(wiRenderer::InitDevice(window, screenW, screenH, !fullscreen))) - { - wiHelper::messageBox("Could not initialize D3D device!", "Fatal Error!", window); - return false; - } + wiRenderer::InitDevice(hWnd, screenW, screenH, !fullscreen); return true; } @@ -211,11 +207,7 @@ bool MainComponent::setWindow(Windows::UI::Core::CoreWindow^ window) { screenW = (int)window->Bounds.Width; screenH = (int)window->Bounds.Height; - if (FAILED(wiRenderer::InitDevice(window))) - { - wiHelper::messageBox("Could not initialize D3D device!", "Fatal Error!"); - return false; - } + wiRenderer::InitDevice(window); return true; } diff --git a/WickedEngine/Renderable2DComponent.cpp b/WickedEngine/Renderable2DComponent.cpp index ee090e2bf..6e87c4498 100644 --- a/WickedEngine/Renderable2DComponent.cpp +++ b/WickedEngine/Renderable2DComponent.cpp @@ -21,7 +21,7 @@ Renderable2DComponent::~Renderable2DComponent() void Renderable2DComponent::Initialize() { rtFinal.Initialize( - wiRenderer::GetScreenWidth(), wiRenderer::GetScreenHeight() + wiRenderer::GetDevice()->GetScreenWidth(), wiRenderer::GetDevice()->GetScreenHeight() , 1, false); RenderableComponent::Initialize(); @@ -100,7 +100,7 @@ void Renderable2DComponent::Render() } void Renderable2DComponent::Compose() { - wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); + wiImageEffects fx((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()); fx.presentFullScreen = true; wiImage::Draw(rtFinal.GetTexture(), fx); diff --git a/WickedEngine/Renderable3DComponent.cpp b/WickedEngine/Renderable3DComponent.cpp index f9a291fcf..68621897b 100644 --- a/WickedEngine/Renderable3DComponent.cpp +++ b/WickedEngine/Renderable3DComponent.cpp @@ -63,98 +63,98 @@ void Renderable3DComponent::Initialize() Renderable2DComponent::Initialize(); rtSSR.Initialize( - (UINT)(wiRenderer::GetScreenWidth()), (UINT)(wiRenderer::GetScreenHeight()) + (UINT)(wiRenderer::GetDevice()->GetScreenWidth()), (UINT)(wiRenderer::GetDevice()->GetScreenHeight()) , 1, false, 1, 0, DXGI_FORMAT_R16G16B16A16_FLOAT); rtMotionBlur.Initialize( - (UINT)(wiRenderer::GetScreenWidth()), (UINT)(wiRenderer::GetScreenHeight()) + (UINT)(wiRenderer::GetDevice()->GetScreenWidth()), (UINT)(wiRenderer::GetDevice()->GetScreenHeight()) , 1, false, 1, 0, DXGI_FORMAT_R16G16B16A16_FLOAT); rtLinearDepth.Initialize( - wiRenderer::GetScreenWidth(), wiRenderer::GetScreenHeight() + wiRenderer::GetDevice()->GetScreenWidth(), wiRenderer::GetDevice()->GetScreenHeight() , 1, false, 1, 0, DXGI_FORMAT_R32_FLOAT ); rtParticle.Initialize( - (UINT)(wiRenderer::GetScreenWidth()*getAlphaParticleDownSample()), (UINT)(wiRenderer::GetScreenHeight()*getAlphaParticleDownSample()) + (UINT)(wiRenderer::GetDevice()->GetScreenWidth()*getAlphaParticleDownSample()), (UINT)(wiRenderer::GetDevice()->GetScreenHeight()*getAlphaParticleDownSample()) , 1, false, 1, 0, DXGI_FORMAT_R16G16B16A16_FLOAT ); rtParticleAdditive.Initialize( - (UINT)(wiRenderer::GetScreenWidth()*getAdditiveParticleDownSample()), (UINT)(wiRenderer::GetScreenHeight()*getAdditiveParticleDownSample()) + (UINT)(wiRenderer::GetDevice()->GetScreenWidth()*getAdditiveParticleDownSample()), (UINT)(wiRenderer::GetDevice()->GetScreenHeight()*getAdditiveParticleDownSample()) , 1, false, 1, 0, DXGI_FORMAT_R16G16B16A16_FLOAT ); rtWaterRipple.Initialize( - wiRenderer::GetScreenWidth() - , wiRenderer::GetScreenHeight() + wiRenderer::GetDevice()->GetScreenWidth() + , wiRenderer::GetDevice()->GetScreenHeight() , 1, false, 1, 0, DXGI_FORMAT_R8G8B8A8_SNORM ); rtTransparent.Initialize( - wiRenderer::GetScreenWidth(), wiRenderer::GetScreenHeight() + wiRenderer::GetDevice()->GetScreenWidth(), wiRenderer::GetDevice()->GetScreenHeight() , 1, false, 1, 0, DXGI_FORMAT_R16G16B16A16_FLOAT ); rtVolumeLight.Initialize( - wiRenderer::GetScreenWidth(), wiRenderer::GetScreenHeight() + wiRenderer::GetDevice()->GetScreenWidth(), wiRenderer::GetDevice()->GetScreenHeight() , 1, false ); rtReflection.Initialize( - (UINT)(wiRenderer::GetScreenWidth() * getReflectionQuality()) - , (UINT)(wiRenderer::GetScreenHeight() * getReflectionQuality()) + (UINT)(wiRenderer::GetDevice()->GetScreenWidth() * getReflectionQuality()) + , (UINT)(wiRenderer::GetDevice()->GetScreenHeight() * getReflectionQuality()) , 1, true, 1, 0, DXGI_FORMAT_R16G16B16A16_FLOAT ); rtFinal[0].Initialize( - wiRenderer::GetScreenWidth(), wiRenderer::GetScreenHeight() + wiRenderer::GetDevice()->GetScreenWidth(), wiRenderer::GetDevice()->GetScreenHeight() , 1, false, 1, 0, DXGI_FORMAT_R16G16B16A16_FLOAT); rtFinal[1].Initialize( - wiRenderer::GetScreenWidth(), wiRenderer::GetScreenHeight() + wiRenderer::GetDevice()->GetScreenWidth(), wiRenderer::GetDevice()->GetScreenHeight() , 1, false); rtDof[0].Initialize( - (UINT)(wiRenderer::GetScreenWidth()*0.5f), (UINT)(wiRenderer::GetScreenHeight()*0.5f) + (UINT)(wiRenderer::GetDevice()->GetScreenWidth()*0.5f), (UINT)(wiRenderer::GetDevice()->GetScreenHeight()*0.5f) , 1, false); rtDof[1].Initialize( - (UINT)(wiRenderer::GetScreenWidth()*0.5f), (UINT)(wiRenderer::GetScreenHeight()*0.5f) + (UINT)(wiRenderer::GetDevice()->GetScreenWidth()*0.5f), (UINT)(wiRenderer::GetDevice()->GetScreenHeight()*0.5f) , 1, false); rtDof[2].Initialize( - wiRenderer::GetScreenWidth(), wiRenderer::GetScreenHeight() + wiRenderer::GetDevice()->GetScreenWidth(), wiRenderer::GetDevice()->GetScreenHeight() , 1, false); - dtDepthCopy.Initialize(wiRenderer::GetScreenWidth(), wiRenderer::GetScreenHeight() + dtDepthCopy.Initialize(wiRenderer::GetDevice()->GetScreenWidth(), wiRenderer::GetDevice()->GetScreenHeight() , 1, 0 ); rtSSAO.resize(3); for (unsigned int i = 0; iGetScreenWidth()*getSSAOQuality()), (UINT)(wiRenderer::GetDevice()->GetScreenHeight()*getSSAOQuality()) , 1, false, 1, 0, DXGI_FORMAT_R8_UNORM ); rtSSS.resize(3); for (int i = 0; i < 3; ++i) rtSSS[i].Initialize( - (UINT)(wiRenderer::GetScreenWidth()), (UINT)(wiRenderer::GetScreenHeight()) + (UINT)(wiRenderer::GetDevice()->GetScreenWidth()), (UINT)(wiRenderer::GetDevice()->GetScreenHeight()) , 1, false, 1, 0, DXGI_FORMAT_R16G16B16A16_FLOAT); rtSun.resize(2); rtSun[0].Initialize( - wiRenderer::GetScreenWidth() - , wiRenderer::GetScreenHeight() + wiRenderer::GetDevice()->GetScreenWidth() + , wiRenderer::GetDevice()->GetScreenHeight() , 1, true ); rtSun[1].Initialize( - (UINT)(wiRenderer::GetScreenWidth()*getLightShaftQuality()) - , (UINT)(wiRenderer::GetScreenHeight()*getLightShaftQuality()) + (UINT)(wiRenderer::GetDevice()->GetScreenWidth()*getLightShaftQuality()) + , (UINT)(wiRenderer::GetDevice()->GetScreenHeight()*getLightShaftQuality()) , 1, false ); - rtLensFlare.Initialize(wiRenderer::GetScreenWidth(), wiRenderer::GetScreenHeight(), 1, false); + rtLensFlare.Initialize(wiRenderer::GetDevice()->GetScreenWidth(), wiRenderer::GetDevice()->GetScreenHeight(), 1, false); rtBloom.resize(3); rtBloom[0].Initialize( - wiRenderer::GetScreenWidth() - , wiRenderer::GetScreenHeight() + wiRenderer::GetDevice()->GetScreenWidth() + , wiRenderer::GetDevice()->GetScreenHeight() , 1, false, 1, 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0 ); for (unsigned int i = 1; iGetScreenWidth() / getBloomDownSample()) + , (UINT)(wiRenderer::GetDevice()->GetScreenHeight() / getBloomDownSample()) , 1, false ); } @@ -266,7 +266,7 @@ void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRende if (getVolumeLightsEnabled()) { - wiRenderer::graphicsDevice->UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID); + wiRenderer::GetDevice()->UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID); rtVolumeLight.Activate(threadID, mainRT.depth); wiRenderer::DrawVolumeLights(wiRenderer::getCamera(), threadID); } @@ -284,7 +284,7 @@ void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRende wiRenderer::DrawWaterRipples(threadID); } - wiRenderer::graphicsDevice->UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID); + wiRenderer::GetDevice()->UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID); rtTransparent.Activate(threadID, mainRT.depth); { wiRenderer::DrawWorldTransparent(wiRenderer::getCamera(), shadedSceneRT.GetTexture(), rtReflection.GetTexture() , rtWaterRipple.GetTexture(), threadID); @@ -301,7 +301,7 @@ void Renderable3DComponent::RenderBloom(GRAPHICSTHREAD threadID) } - wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); + wiImageEffects fx((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()); rtBloom[0].Activate(threadID); { @@ -316,8 +316,8 @@ void Renderable3DComponent::RenderBloom(GRAPHICSTHREAD threadID) rtBloom[1].Activate(threadID); //horizontal { - wiRenderer::graphicsDevice->GenerateMips(rtBloom[0].GetTexture(), threadID); - //wiRenderer::graphicsDevice->GenerateMips(rtBloom[0].shaderResource[0], threadID); + wiRenderer::GetDevice()->GenerateMips(rtBloom[0].GetTexture(), threadID); + //wiRenderer::GetDevice()->GenerateMips(rtBloom[0].shaderResource[0], threadID); fx.mipLevel = 5.32f; fx.blur = getBloomStrength(); fx.blurDir = 0; @@ -350,9 +350,9 @@ void Renderable3DComponent::RenderLightShafts(wiRenderTarget& mainRT, GRAPHICSTH return; } - wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); + wiImageEffects fx((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()); - wiRenderer::graphicsDevice->UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID); + wiRenderer::GetDevice()->UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID); rtSun[0].Activate(threadID, mainRT.depth); { wiRenderer::DrawSun(threadID); } @@ -360,7 +360,7 @@ void Renderable3DComponent::RenderLightShafts(wiRenderTarget& mainRT, GRAPHICSTH rtSun[1].Activate(threadID); { wiImageEffects fxs = fx; fxs.blendFlag = BLENDMODE_ADDITIVE; - XMVECTOR sunPos = XMVector3Project(wiRenderer::GetSunPosition() * 100000, 0, 0, (float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight(), 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); + XMVECTOR sunPos = XMVector3Project(wiRenderer::GetSunPosition() * 100000, 0, 0, (float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight(), 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); { XMStoreFloat2(&fxs.sunPos, sunPos); wiImage::Draw(rtSun[0].GetTexture(), fxs, threadID); @@ -375,7 +375,7 @@ void Renderable3DComponent::RenderComposition1(wiRenderTarget& shadedSceneRT, GR return; } - wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); + wiImageEffects fx((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()); fx.presentFullScreen = true; rtFinal[0].Activate(threadID); @@ -411,7 +411,7 @@ void Renderable3DComponent::RenderComposition2(GRAPHICSTHREAD threadID){ return; } - wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); + wiImageEffects fx((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()); fx.blendFlag = BLENDMODE_OPAQUE; if (getDepthOfFieldEnabled()) @@ -457,7 +457,7 @@ void Renderable3DComponent::RenderComposition2(GRAPHICSTHREAD threadID){ } void Renderable3DComponent::RenderColorGradedComposition(){ - wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); + wiImageEffects fx((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()); fx.blendFlag = BLENDMODE_OPAQUE; fx.quality = QUALITY_NEAREST; diff --git a/WickedEngine/wiBackLog.cpp b/WickedEngine/wiBackLog.cpp index f66b2108f..7119d8868 100644 --- a/WickedEngine/wiBackLog.cpp +++ b/WickedEngine/wiBackLog.cpp @@ -19,7 +19,7 @@ Texture2D* wiBackLog::backgroundTex = nullptr; wiFont wiBackLog::font; void wiBackLog::Initialize(){ - pos = (float)wiRenderer::GetScreenHeight(); + pos = (float)wiRenderer::GetDevice()->GetScreenHeight(); scroll=0; state=DISABLED; deletefromline=500; @@ -50,10 +50,10 @@ void wiBackLog::Update(){ pos+=speed; else if(state==ACTIVATING) pos-=speed; - if (pos >= wiRenderer::GetScreenHeight()) + if (pos >= wiRenderer::GetDevice()->GetScreenHeight()) { state = DISABLED; - pos = (float)wiRenderer::GetScreenHeight(); + pos = (float)wiRenderer::GetDevice()->GetScreenHeight(); } else if(pos<0) { @@ -64,14 +64,14 @@ void wiBackLog::Update(){ void wiBackLog::Draw(){ if(state!=DISABLED){ //wiImage::BatchBegin(); - wiImageEffects fx = wiImageEffects((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); + wiImageEffects fx = wiImageEffects((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()); fx.pos=XMFLOAT3(0,pos,0); - fx.opacity = wiMath::Lerp(1, 0, pos / wiRenderer::GetScreenHeight()); + fx.opacity = wiMath::Lerp(1, 0, pos / wiRenderer::GetDevice()->GetScreenHeight()); wiImage::Draw(backgroundTex, fx); font.SetText(getText()); - font.props.posY = pos - wiRenderer::GetScreenHeight() + 75 + scroll; + font.props.posY = pos - wiRenderer::GetDevice()->GetScreenHeight() + 75 + scroll; font.Draw(); - wiFont(inputArea.str().c_str(), wiFontProps(5, -(float)wiRenderer::GetScreenHeight() + 10, 0, WIFALIGN_LEFT, WIFALIGN_BOTTOM, -8)).Draw(); + wiFont(inputArea.str().c_str(), wiFontProps(5, -(float)wiRenderer::GetDevice()->GetScreenHeight() + 10, 0, WIFALIGN_LEFT, WIFALIGN_BOTTOM, -8)).Draw(); //wiFont::Draw(wiBackLog::getText(), "01", XMFLOAT4(5, pos - wiRenderer::RENDERHEIGHT + 75 + scroll, 0, -8), "left", "bottom"); //wiFont::Draw(inputArea.str().c_str(), "01", XMFLOAT4(5, -(float)wiRenderer::RENDERHEIGHT + 10, 0, -8), "left", "bottom"); } diff --git a/WickedEngine/wiCube.cpp b/WickedEngine/wiCube.cpp index 4b96656cb..bf276340b 100644 --- a/WickedEngine/wiCube.cpp +++ b/WickedEngine/wiCube.cpp @@ -53,7 +53,7 @@ void Cube::SetUpVertices() SubresourceData InitData; ZeroMemory( &InitData, sizeof(InitData) ); InitData.pSysMem = verts; - wiRenderer::graphicsDevice->CreateBuffer( &bd, &InitData, &vertexBuffer ); + wiRenderer::GetDevice()->CreateBuffer( &bd, &InitData, &vertexBuffer ); if(verts){ delete[](verts); @@ -72,7 +72,7 @@ void Cube::SetUpVertices() bd.CPUAccessFlags = 0; ZeroMemory( &InitData, sizeof(InitData) ); InitData.pSysMem = indices; - wiRenderer::graphicsDevice->CreateBuffer( &bd, &InitData, &indexBuffer ); + wiRenderer::GetDevice()->CreateBuffer( &bd, &InitData, &indexBuffer ); } void Cube::Transform(const XMFLOAT4X4& mat) diff --git a/WickedEngine/wiDepthTarget.cpp b/WickedEngine/wiDepthTarget.cpp index 68c4f99e6..9a853b422 100644 --- a/WickedEngine/wiDepthTarget.cpp +++ b/WickedEngine/wiDepthTarget.cpp @@ -42,11 +42,11 @@ void wiDepthTarget::Initialize(int width, int height, UINT MSAAC, UINT MSAAQ) depthBufferDesc.CPUAccessFlags = 0; depthBufferDesc.MiscFlags = 0; - wiRenderer::graphicsDevice->CreateTexture2D(&depthBufferDesc, nullptr, &texture); + wiRenderer::GetDevice()->CreateTexture2D(&depthBufferDesc, nullptr, &texture); //HRESULT hr; //// Create the texture for the depth buffer using the filled out description. - //hr=wiRenderer::graphicsDevice->CreateTexture2D(&depthBufferDesc, nullptr, &texture2D); + //hr=wiRenderer::GetDevice()->CreateTexture2D(&depthBufferDesc, nullptr, &texture2D); //DepthStencilViewDesc depthStencilViewDesc; //ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc)); @@ -56,7 +56,7 @@ void wiDepthTarget::Initialize(int width, int height, UINT MSAAC, UINT MSAAQ) //depthStencilViewDesc.Flags = 0; //// Create the depth stencil view. - //hr=wiRenderer::graphicsDevice->CreateDepthStencilView(texture2D, &depthStencilViewDesc, &depthTarget); + //hr=wiRenderer::GetDevice()->CreateDepthStencilView(texture2D, &depthStencilViewDesc, &depthTarget); ////Create Depth ShaderResource ////ShaderResourceViewDesc shaderResourceViewDesc; @@ -67,7 +67,7 @@ void wiDepthTarget::Initialize(int width, int height, UINT MSAAC, UINT MSAAQ) ////shaderResourceViewDesc.Texture2D.MipLevels = 1; //shaderResourceViewDesc.mipLevels = 1; - //wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D, &shaderResourceViewDesc, &shaderResource); + //wiRenderer::GetDevice()->CreateShaderResourceView(texture2D, &shaderResourceViewDesc, &shaderResource); } void wiDepthTarget::InitializeCube(int size) { @@ -92,11 +92,11 @@ void wiDepthTarget::InitializeCube(int size) depthBufferDesc.CPUAccessFlags = 0; depthBufferDesc.MiscFlags = RESOURCE_MISC_TEXTURECUBE; - wiRenderer::graphicsDevice->CreateTextureCube(&depthBufferDesc, nullptr, &textureCube); + wiRenderer::GetDevice()->CreateTextureCube(&depthBufferDesc, nullptr, &textureCube); //HRESULT hr; //// Create the texture for the depth buffer using the filled out description. - //hr=wiRenderer::graphicsDevice->CreateTexture2D(&depthBufferDesc, NULL, &texture2D); + //hr=wiRenderer::GetDevice()->CreateTexture2D(&depthBufferDesc, NULL, &texture2D); //DepthStencilViewDesc depthStencilViewDesc; //ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc)); @@ -109,7 +109,7 @@ void wiDepthTarget::InitializeCube(int size) //depthStencilViewDesc.Flags = 0; //// Create the depth stencil view. - //hr=wiRenderer::graphicsDevice->CreateDepthStencilView(texture2D, &depthStencilViewDesc, &depthTarget); + //hr=wiRenderer::GetDevice()->CreateDepthStencilView(texture2D, &depthStencilViewDesc, &depthTarget); ////Create Depth ShaderResource ////ShaderResourceViewDesc shaderResourceViewDesc; @@ -120,21 +120,21 @@ void wiDepthTarget::InitializeCube(int size) ////shaderResourceViewDesc.Texture2D.MipLevels = 1; //shaderResourceViewDesc.mipLevels = 1; - //wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D, &shaderResourceViewDesc, &shaderResource); + //wiRenderer::GetDevice()->CreateShaderResourceView(texture2D, &shaderResourceViewDesc, &shaderResource); } void wiDepthTarget::Clear(GRAPHICSTHREAD threadID) { - wiRenderer::graphicsDevice->ClearDepthStencil(GetTexture(), CLEAR_DEPTH | CLEAR_STENCIL, 1.0f, 0); + wiRenderer::GetDevice()->ClearDepthStencil(GetTexture(), CLEAR_DEPTH | CLEAR_STENCIL, 1.0f, 0); } void wiDepthTarget::CopyFrom(const wiDepthTarget& from, GRAPHICSTHREAD threadID) { //if(shaderResource) shaderResource->Release(); ////static ShaderResourceViewDesc desc; ////from.shaderResource->GetDesc(&desc); - //wiRenderer::graphicsDevice->CopyResource(texture2D,from.texture2D); - //HRESULT r = wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D,&from.shaderResourceViewDesc,&shaderResource); + //wiRenderer::GetDevice()->CopyResource(texture2D,from.texture2D); + //HRESULT r = wiRenderer::GetDevice()->CreateShaderResourceView(texture2D,&from.shaderResourceViewDesc,&shaderResource); - wiRenderer::graphicsDevice->CopyTexture2D(GetTexture(), from.GetTexture(), threadID); + wiRenderer::GetDevice()->CopyTexture2D(GetTexture(), from.GetTexture(), threadID); } diff --git a/WickedEngine/wiEmittedParticle.cpp b/WickedEngine/wiEmittedParticle.cpp index a3278e345..6e3bd66b5 100644 --- a/WickedEngine/wiEmittedParticle.cpp +++ b/WickedEngine/wiEmittedParticle.cpp @@ -238,17 +238,17 @@ void wiEmittedParticle::Draw(Camera* camera, GRAPHICSTHREAD threadID, int FLAG) if(camera->frustum.CheckBox(bounding_box->corners)){ vector renderPoints=vector(points.begin(),points.end()); - wiRenderer::graphicsDevice->UpdateBuffer(vertexBuffer,renderPoints.data(),threadID,sizeof(Point)* renderPoints.size()); + wiRenderer::GetDevice()->UpdateBuffer(vertexBuffer,renderPoints.data(),threadID,sizeof(Point)* renderPoints.size()); bool additive = (material->blendFlag==BLENDMODE_ADDITIVE || material->premultipliedTexture); - wiRenderer::graphicsDevice->BindPrimitiveTopology(PRIMITIVETOPOLOGY::POINTLIST,threadID); - wiRenderer::graphicsDevice->BindVertexLayout(vertexLayout,threadID); - wiRenderer::graphicsDevice->BindPS(wireRender?simplestPS:pixelShader,threadID); - wiRenderer::graphicsDevice->BindVS(vertexShader,threadID); - wiRenderer::graphicsDevice->BindGS(geometryShader,threadID); + wiRenderer::GetDevice()->BindPrimitiveTopology(PRIMITIVETOPOLOGY::POINTLIST,threadID); + wiRenderer::GetDevice()->BindVertexLayout(vertexLayout,threadID); + wiRenderer::GetDevice()->BindPS(wireRender?simplestPS:pixelShader,threadID); + wiRenderer::GetDevice()->BindVS(vertexShader,threadID); + wiRenderer::GetDevice()->BindGS(geometryShader,threadID); - //wiRenderer::graphicsDevice->BindTexturePS(depth,1,threadID); + //wiRenderer::GetDevice()->BindTexturePS(depth,1,threadID); static thread_local ConstantBuffer* cb = new ConstantBuffer; (*cb).mAdd.x = additive; @@ -256,22 +256,22 @@ void wiEmittedParticle::Draw(Camera* camera, GRAPHICSTHREAD threadID, int FLAG) (*cb).mMotionBlurAmount = motionBlurAmount; - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffer,cb,threadID); - wiRenderer::graphicsDevice->BindConstantBufferGS(constantBuffer, CB_GETBINDSLOT(ConstantBuffer),threadID); + wiRenderer::GetDevice()->UpdateBuffer(constantBuffer,cb,threadID); + wiRenderer::GetDevice()->BindConstantBufferGS(constantBuffer, CB_GETBINDSLOT(ConstantBuffer),threadID); - wiRenderer::graphicsDevice->BindRasterizerState(wireRender?wireFrameRS:rasterizerState,threadID); - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencilState,1,threadID); + wiRenderer::GetDevice()->BindRasterizerState(wireRender?wireFrameRS:rasterizerState,threadID); + wiRenderer::GetDevice()->BindDepthStencilState(depthStencilState,1,threadID); - wiRenderer::graphicsDevice->BindBlendState((additive?blendStateAdd:blendStateAlpha),threadID); + wiRenderer::GetDevice()->BindBlendState((additive?blendStateAdd:blendStateAlpha),threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(vertexBuffer,0,sizeof(Point),threadID); + wiRenderer::GetDevice()->BindVertexBuffer(vertexBuffer,0,sizeof(Point),threadID); if(!wireRender && material->texture) - wiRenderer::graphicsDevice->BindTexturePS(material->texture,TEXSLOT_ONDEMAND0,threadID); - wiRenderer::graphicsDevice->Draw(renderPoints.size(),threadID); + wiRenderer::GetDevice()->BindTexturePS(material->texture,TEXSLOT_ONDEMAND0,threadID); + wiRenderer::GetDevice()->Draw(renderPoints.size(),threadID); - wiRenderer::graphicsDevice->BindGS(nullptr,threadID); + wiRenderer::GetDevice()->BindGS(nullptr,threadID); } } } @@ -336,7 +336,7 @@ void wiEmittedParticle::SetUpCB() bd.ByteWidth = sizeof(ConstantBuffer); bd.BindFlags = BIND_CONSTANT_BUFFER; bd.CPUAccessFlags = CPU_ACCESS_WRITE; - wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &constantBuffer ); + wiRenderer::GetDevice()->CreateBuffer( &bd, NULL, &constantBuffer ); } void wiEmittedParticle::SetUpStates() { @@ -351,7 +351,7 @@ void wiEmittedParticle::SetUpStates() rs.ScissorEnable=false; rs.MultisampleEnable=false; rs.AntialiasedLineEnable=false; - wiRenderer::graphicsDevice->CreateRasterizerState(&rs,&rasterizerState); + wiRenderer::GetDevice()->CreateRasterizerState(&rs,&rasterizerState); rs.FillMode=FILL_WIREFRAME; @@ -364,7 +364,7 @@ void wiEmittedParticle::SetUpStates() rs.ScissorEnable=false; rs.MultisampleEnable=false; rs.AntialiasedLineEnable=false; - wiRenderer::graphicsDevice->CreateRasterizerState(&rs,&wireFrameRS); + wiRenderer::GetDevice()->CreateRasterizerState(&rs,&wireFrameRS); @@ -392,7 +392,7 @@ void wiEmittedParticle::SetUpStates() dsd.BackFace.StencilFunc = COMPARISON_ALWAYS; // Create the depth stencil state. - wiRenderer::graphicsDevice->CreateDepthStencilState(&dsd, &depthStencilState); + wiRenderer::GetDevice()->CreateDepthStencilState(&dsd, &depthStencilState); @@ -407,7 +407,7 @@ void wiEmittedParticle::SetUpStates() bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; bd.IndependentBlendEnable=true; - wiRenderer::graphicsDevice->CreateBlendState(&bd,&blendStateAlpha); + wiRenderer::GetDevice()->CreateBlendState(&bd,&blendStateAlpha); ZeroMemory(&bd, sizeof(bd)); bd.RenderTarget[0].BlendEnable=true; @@ -419,7 +419,7 @@ void wiEmittedParticle::SetUpStates() bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; bd.IndependentBlendEnable=true; - wiRenderer::graphicsDevice->CreateBlendState(&bd,&blendStateAdd); + wiRenderer::GetDevice()->CreateBlendState(&bd,&blendStateAdd); } void wiEmittedParticle::LoadVertexBuffer() { @@ -431,7 +431,7 @@ void wiEmittedParticle::LoadVertexBuffer() bd.ByteWidth = sizeof( Point ) * MAX_PARTICLES; bd.BindFlags = BIND_VERTEX_BUFFER; bd.CPUAccessFlags = CPU_ACCESS_WRITE; - wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &vertexBuffer ); + wiRenderer::GetDevice()->CreateBuffer( &bd, NULL, &vertexBuffer ); } void wiEmittedParticle::SetUpStatic() { diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp index b9ee1be86..1c9683321 100644 --- a/WickedEngine/wiFont.cpp +++ b/WickedEngine/wiFont.cpp @@ -56,7 +56,7 @@ void wiFont::SetUpStates() rs.ScissorEnable=FALSE; rs.MultisampleEnable=FALSE; rs.AntialiasedLineEnable=FALSE; - wiRenderer::graphicsDevice->CreateRasterizerState(&rs,&rasterizerState); + wiRenderer::GetDevice()->CreateRasterizerState(&rs,&rasterizerState); @@ -84,7 +84,7 @@ void wiFont::SetUpStates() dsd.BackFace.StencilFunc = COMPARISON_ALWAYS; // Create the depth stencil state. - wiRenderer::graphicsDevice->CreateDepthStencilState(&dsd, &depthStencilState); + wiRenderer::GetDevice()->CreateDepthStencilState(&dsd, &depthStencilState); @@ -98,7 +98,7 @@ void wiFont::SetUpStates() bd.RenderTarget[0].DestBlendAlpha = BLEND_INV_SRC_ALPHA; bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; - wiRenderer::graphicsDevice->CreateBlendState(&bd,&blendState); + wiRenderer::GetDevice()->CreateBlendState(&bd,&blendState); } void wiFont::SetUpCB() { @@ -108,7 +108,7 @@ void wiFont::SetUpCB() bd.ByteWidth = sizeof(ConstantBuffer); bd.BindFlags = BIND_CONSTANT_BUFFER; bd.CPUAccessFlags = CPU_ACCESS_WRITE; - wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &constantBuffer ); + wiRenderer::GetDevice()->CreateBuffer( &bd, NULL, &constantBuffer ); BindPersistentState(GRAPHICSTHREAD_IMMEDIATE); } @@ -159,11 +159,11 @@ void wiFont::CleanUpStatic() void wiFont::BindPersistentState(GRAPHICSTHREAD threadID) { - wiRenderer::graphicsDevice->LOCK(); + wiRenderer::GetDevice()->LOCK(); - wiRenderer::graphicsDevice->BindConstantBufferVS(constantBuffer, CB_GETBINDSLOT(ConstantBuffer), threadID); + wiRenderer::GetDevice()->BindConstantBufferVS(constantBuffer, CB_GETBINDSLOT(ConstantBuffer), threadID); - wiRenderer::graphicsDevice->UNLOCK(); + wiRenderer::GetDevice()->UNLOCK(); } @@ -214,7 +214,7 @@ void wiFont::ModifyGeo(const wstring& text, wiFontProps props, int style, GRAPHI } } - wiRenderer::graphicsDevice->UpdateBuffer(vertexBuffer,vertexList.data(),threadID,sizeof(Vertex) * text.length() * 4); + wiRenderer::GetDevice()->UpdateBuffer(vertexBuffer,vertexList.data(),threadID,sizeof(Vertex) * text.length() * 4); } @@ -226,7 +226,7 @@ void wiFont::LoadVertexBuffer() bd.ByteWidth = sizeof( Vertex ) * MAX_TEXT * 4; bd.BindFlags = BIND_VERTEX_BUFFER; bd.CPUAccessFlags = CPU_ACCESS_WRITE; - wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &vertexBuffer ); + wiRenderer::GetDevice()->CreateBuffer( &bd, NULL, &vertexBuffer ); } void wiFont::LoadIndices() { @@ -250,7 +250,7 @@ void wiFont::LoadIndices() SubresourceData InitData; ZeroMemory( &InitData, sizeof(InitData) ); InitData.pSysMem = indices.data(); - wiRenderer::graphicsDevice->CreateBuffer( &bd, &InitData, &indexBuffer ); + wiRenderer::GetDevice()->CreateBuffer( &bd, &InitData, &indexBuffer ); } void wiFont::Draw(GRAPHICSTHREAD threadID){ @@ -271,29 +271,29 @@ void wiFont::Draw(GRAPHICSTHREAD threadID){ if(text.length()>0){ - wiRenderer::graphicsDevice->BindPrimitiveTopology(PRIMITIVETOPOLOGY::TRIANGLELIST,threadID); - wiRenderer::graphicsDevice->BindVertexLayout(vertexLayout,threadID); - wiRenderer::graphicsDevice->BindVS(vertexShader,threadID); - wiRenderer::graphicsDevice->BindPS(pixelShader,threadID); + wiRenderer::GetDevice()->BindPrimitiveTopology(PRIMITIVETOPOLOGY::TRIANGLELIST,threadID); + wiRenderer::GetDevice()->BindVertexLayout(vertexLayout,threadID); + wiRenderer::GetDevice()->BindVS(vertexShader,threadID); + wiRenderer::GetDevice()->BindPS(pixelShader,threadID); static thread_local ConstantBuffer* cb = new ConstantBuffer; - (*cb).mProjection = XMMatrixTranspose( XMMatrixOrthographicLH((float)wiRenderer::GetScreenWidth(),(float)wiRenderer::GetScreenHeight(),0,100) ); + (*cb).mProjection = XMMatrixTranspose( XMMatrixOrthographicLH((float)wiRenderer::GetDevice()->GetScreenWidth(),(float)wiRenderer::GetDevice()->GetScreenHeight(),0,100) ); (*cb).mTrans = XMMatrixTranspose(XMMatrixTranslation(newProps.posX, newProps.posY, 0)); - (*cb).mDimensions = XMFLOAT4((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight(), 0, 0); + (*cb).mDimensions = XMFLOAT4((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight(), 0, 0); - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffer,cb,threadID); + wiRenderer::GetDevice()->UpdateBuffer(constantBuffer,cb,threadID); - wiRenderer::graphicsDevice->BindRasterizerState(rasterizerState,threadID); - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencilState,1,threadID); + wiRenderer::GetDevice()->BindRasterizerState(rasterizerState,threadID); + wiRenderer::GetDevice()->BindDepthStencilState(depthStencilState,1,threadID); - wiRenderer::graphicsDevice->BindBlendState(blendState,threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(vertexBuffer,0,sizeof(Vertex),threadID); - wiRenderer::graphicsDevice->BindIndexBuffer(indexBuffer,threadID); + wiRenderer::GetDevice()->BindBlendState(blendState,threadID); + wiRenderer::GetDevice()->BindVertexBuffer(vertexBuffer,0,sizeof(Vertex),threadID); + wiRenderer::GetDevice()->BindIndexBuffer(indexBuffer,threadID); - wiRenderer::graphicsDevice->BindTexturePS(fontStyles[style].texture,TEXSLOT_ONDEMAND0,threadID); - wiRenderer::graphicsDevice->DrawIndexed(text.length()*6,threadID); + wiRenderer::GetDevice()->BindTexturePS(fontStyles[style].texture,TEXSLOT_ONDEMAND0,threadID); + wiRenderer::GetDevice()->DrawIndexed(text.length()*6,threadID); } } @@ -351,7 +351,7 @@ string wiFont::GetTextA() wiFont::wiFontStyle::wiFontStyle(const string& newName){ - wiRenderer::graphicsDevice->LOCK(); + wiRenderer::GetDevice()->LOCK(); name=newName; @@ -378,7 +378,7 @@ wiFont::wiFontStyle::wiFontStyle(const string& newName){ wiHelper::messageBox(name,"Could not load Font Data!"); } - wiRenderer::graphicsDevice->UNLOCK(); + wiRenderer::GetDevice()->UNLOCK(); } void wiFont::wiFontStyle::CleanUp(){ SAFE_DELETE(texture); diff --git a/WickedEngine/wiGraphicsAPI.h b/WickedEngine/wiGraphicsAPI.h index 363bd376b..9859900fd 100644 --- a/WickedEngine/wiGraphicsAPI.h +++ b/WickedEngine/wiGraphicsAPI.h @@ -9,15 +9,6 @@ #include "ConstantBufferMapping.h" -#ifndef WINSTORE_SUPPORT -typedef IDXGISwapChain* SwapChain; -#else -typedef IDXGISwapChain1* SwapChain; -#endif -typedef IUnknown* APIInterface; -typedef ID3D11DeviceContext* DeviceContext; -//typedef ID3D11Device* GraphicsDevice; -typedef ID3D11CommandList* CommandList; typedef ID3D11RenderTargetView* RenderTargetView; typedef ID3D11ShaderResourceView* ShaderResourceView; typedef ID3D11Texture2D* APITexture2D; @@ -47,186 +38,169 @@ enum PRIMITIVETOPOLOGY LINELIST, PATCHLIST, }; -enum COMPARISON_FUNC +enum COMPARISON_FUNC { - COMPARISON_NEVER = D3D11_COMPARISON_NEVER, - COMPARISON_LESS = D3D11_COMPARISON_LESS, - COMPARISON_EQUAL = D3D11_COMPARISON_EQUAL, - COMPARISON_LESS_EQUAL = D3D11_COMPARISON_LESS_EQUAL, - COMPARISON_GREATER = D3D11_COMPARISON_GREATER, - COMPARISON_NOT_EQUAL = D3D11_COMPARISON_NOT_EQUAL, - COMPARISON_GREATER_EQUAL = D3D11_COMPARISON_GREATER_EQUAL, - COMPARISON_ALWAYS = D3D11_COMPARISON_ALWAYS, + COMPARISON_NEVER, + COMPARISON_LESS, + COMPARISON_EQUAL, + COMPARISON_LESS_EQUAL, + COMPARISON_GREATER, + COMPARISON_NOT_EQUAL, + COMPARISON_GREATER_EQUAL, + COMPARISON_ALWAYS, }; enum DEPTH_WRITE_MASK { - DEPTH_WRITE_MASK_ZERO = D3D11_DEPTH_WRITE_MASK_ZERO, - DEPTH_WRITE_MASK_ALL = D3D11_DEPTH_WRITE_MASK_ALL, + DEPTH_WRITE_MASK_ZERO, + DEPTH_WRITE_MASK_ALL, }; enum STENCIL_OP { - STENCIL_OP_KEEP = D3D11_STENCIL_OP_KEEP, - STENCIL_OP_ZERO = D3D11_STENCIL_OP_ZERO, - STENCIL_OP_REPLACE = D3D11_STENCIL_OP_REPLACE, - STENCIL_OP_INCR_SAT = D3D11_STENCIL_OP_INCR_SAT, - STENCIL_OP_DECR_SAT = D3D11_STENCIL_OP_DECR_SAT, - STENCIL_OP_INVERT = D3D11_STENCIL_OP_INVERT, - STENCIL_OP_INCR = D3D11_STENCIL_OP_INCR, - STENCIL_OP_DECR = D3D11_STENCIL_OP_DECR, + STENCIL_OP_KEEP, + STENCIL_OP_ZERO, + STENCIL_OP_REPLACE, + STENCIL_OP_INCR_SAT, + STENCIL_OP_DECR_SAT, + STENCIL_OP_INVERT, + STENCIL_OP_INCR, + STENCIL_OP_DECR, }; enum BLEND { - BLEND_ZERO = D3D11_BLEND_ZERO, - BLEND_ONE = D3D11_BLEND_ONE, - BLEND_SRC_COLOR = D3D11_BLEND_SRC_COLOR, - BLEND_INV_SRC_COLOR = D3D11_BLEND_INV_SRC_COLOR, - BLEND_SRC_ALPHA = D3D11_BLEND_SRC_ALPHA, - BLEND_INV_SRC_ALPHA = D3D11_BLEND_INV_SRC_ALPHA, - BLEND_DEST_ALPHA = D3D11_BLEND_DEST_ALPHA, - BLEND_INV_DEST_ALPHA = D3D11_BLEND_INV_DEST_ALPHA, - BLEND_DEST_COLOR = D3D11_BLEND_DEST_COLOR, - BLEND_INV_DEST_COLOR = D3D11_BLEND_INV_DEST_COLOR, - BLEND_SRC_ALPHA_SAT = D3D11_BLEND_SRC_ALPHA_SAT, - BLEND_BLEND_FACTOR = D3D11_BLEND_BLEND_FACTOR, - BLEND_INV_BLEND_FACTOR = D3D11_BLEND_INV_BLEND_FACTOR, - BLEND_SRC1_COLOR = D3D11_BLEND_SRC1_COLOR, - BLEND_INV_SRC1_COLOR = D3D11_BLEND_INV_SRC1_COLOR, - BLEND_SRC1_ALPHA = D3D11_BLEND_SRC1_ALPHA, - BLEND_INV_SRC1_ALPHA = D3D11_BLEND_INV_SRC1_ALPHA, + BLEND_ZERO, + BLEND_ONE, + BLEND_SRC_COLOR, + BLEND_INV_SRC_COLOR, + BLEND_SRC_ALPHA, + BLEND_INV_SRC_ALPHA, + BLEND_DEST_ALPHA, + BLEND_INV_DEST_ALPHA, + BLEND_DEST_COLOR, + BLEND_INV_DEST_COLOR, + BLEND_SRC_ALPHA_SAT, + BLEND_BLEND_FACTOR, + BLEND_INV_BLEND_FACTOR, + BLEND_SRC1_COLOR, + BLEND_INV_SRC1_COLOR, + BLEND_SRC1_ALPHA, + BLEND_INV_SRC1_ALPHA, }; enum BLEND_OP { - BLEND_OP_ADD = D3D11_BLEND_OP_ADD, - BLEND_OP_SUBTRACT = D3D11_BLEND_OP_SUBTRACT, - BLEND_OP_REV_SUBTRACT = D3D11_BLEND_OP_REV_SUBTRACT, - BLEND_OP_MIN = D3D11_BLEND_OP_MIN, - BLEND_OP_MAX = D3D11_BLEND_OP_MAX, -}; -enum COLORWRITE -{ - COLOR_WRITE_ENABLE_RED = D3D11_COLOR_WRITE_ENABLE_RED, - COLOR_WRITE_ENABLE_GREEN = D3D11_COLOR_WRITE_ENABLE_GREEN, - COLOR_WRITE_ENABLE_BLUE = D3D11_COLOR_WRITE_ENABLE_BLUE, - COLOR_WRITE_ENABLE_ALPHA = D3D11_COLOR_WRITE_ENABLE_ALPHA, - COLOR_WRITE_ENABLE_ALL = (((COLOR_WRITE_ENABLE_RED | COLOR_WRITE_ENABLE_GREEN) | COLOR_WRITE_ENABLE_BLUE) | COLOR_WRITE_ENABLE_ALPHA), + BLEND_OP_ADD, + BLEND_OP_SUBTRACT, + BLEND_OP_REV_SUBTRACT, + BLEND_OP_MIN, + BLEND_OP_MAX, }; enum FILL_MODE { - FILL_WIREFRAME = D3D11_FILL_WIREFRAME, - FILL_SOLID = D3D11_FILL_SOLID, + FILL_WIREFRAME, + FILL_SOLID, }; enum CULL_MODE { - CULL_NONE = D3D11_CULL_NONE, - CULL_FRONT = D3D11_CULL_FRONT, - CULL_BACK = D3D11_CULL_BACK, + CULL_NONE, + CULL_FRONT, + CULL_BACK, }; enum INPUT_CLASSIFICATION { - INPUT_PER_VERTEX_DATA = D3D11_INPUT_PER_VERTEX_DATA, - INPUT_PER_INSTANCE_DATA = D3D11_INPUT_PER_INSTANCE_DATA, -}; -enum BIND_FLAG -{ - BIND_VERTEX_BUFFER = D3D11_BIND_VERTEX_BUFFER, - BIND_INDEX_BUFFER = D3D11_BIND_INDEX_BUFFER, - BIND_CONSTANT_BUFFER = D3D11_BIND_CONSTANT_BUFFER, - BIND_SHADER_RESOURCE = D3D11_BIND_SHADER_RESOURCE, - BIND_STREAM_OUTPUT = D3D11_BIND_STREAM_OUTPUT, - BIND_RENDER_TARGET = D3D11_BIND_RENDER_TARGET, - BIND_DEPTH_STENCIL = D3D11_BIND_DEPTH_STENCIL, - BIND_UNORDERED_ACCESS = D3D11_BIND_UNORDERED_ACCESS, - BIND_DECODER = D3D11_BIND_DECODER, - BIND_VIDEO_ENCODER = D3D11_BIND_VIDEO_ENCODER, + INPUT_PER_VERTEX_DATA, + INPUT_PER_INSTANCE_DATA, }; enum USAGE { - USAGE_DEFAULT = D3D11_USAGE_DEFAULT, - USAGE_IMMUTABLE = D3D11_USAGE_IMMUTABLE, - USAGE_DYNAMIC = D3D11_USAGE_DYNAMIC, - USAGE_STAGING = D3D11_USAGE_STAGING, -}; -enum CPU_ACCESS -{ - CPU_ACCESS_WRITE = D3D11_CPU_ACCESS_WRITE, - CPU_ACCESS_READ = D3D11_CPU_ACCESS_READ, -}; -enum CLEAR_FLAG -{ - CLEAR_DEPTH = D3D11_CLEAR_DEPTH, - CLEAR_STENCIL = D3D11_CLEAR_STENCIL, + USAGE_DEFAULT, + USAGE_IMMUTABLE, + USAGE_DYNAMIC, + USAGE_STAGING, }; enum TEXTURE_ADDRESS_MODE { - TEXTURE_ADDRESS_WRAP = D3D11_TEXTURE_ADDRESS_WRAP, - TEXTURE_ADDRESS_MIRROR = D3D11_TEXTURE_ADDRESS_MIRROR, - TEXTURE_ADDRESS_CLAMP = D3D11_TEXTURE_ADDRESS_CLAMP, - TEXTURE_ADDRESS_BORDER = D3D11_TEXTURE_ADDRESS_BORDER, - TEXTURE_ADDRESS_MIRROR_ONCE = D3D11_TEXTURE_ADDRESS_MIRROR_ONCE, + TEXTURE_ADDRESS_WRAP, + TEXTURE_ADDRESS_MIRROR, + TEXTURE_ADDRESS_CLAMP, + TEXTURE_ADDRESS_BORDER, + TEXTURE_ADDRESS_MIRROR_ONCE, }; enum FILTER { - FILTER_MIN_MAG_MIP_POINT = D3D11_FILTER_MIN_MAG_MIP_POINT, - FILTER_MIN_MAG_POINT_MIP_LINEAR = D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, - FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT = D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, - FILTER_MIN_POINT_MAG_MIP_LINEAR = D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, - FILTER_MIN_LINEAR_MAG_MIP_POINT = D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, - FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR = D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, - FILTER_MIN_MAG_LINEAR_MIP_POINT = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, - FILTER_MIN_MAG_MIP_LINEAR = D3D11_FILTER_MIN_MAG_MIP_LINEAR, - FILTER_ANISOTROPIC = D3D11_FILTER_ANISOTROPIC, - FILTER_COMPARISON_MIN_MAG_MIP_POINT = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, - FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR = D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, - FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT = D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT, - FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR = D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, - FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT = D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, - FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR = D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR, - FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT = D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, - FILTER_COMPARISON_MIN_MAG_MIP_LINEAR = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, - FILTER_COMPARISON_ANISOTROPIC = D3D11_FILTER_COMPARISON_ANISOTROPIC, - FILTER_MINIMUM_MIN_MAG_MIP_POINT = D3D11_FILTER_MINIMUM_MIN_MAG_MIP_POINT, - FILTER_MINIMUM_MIN_MAG_POINT_MIP_LINEAR = D3D11_FILTER_MINIMUM_MIN_MAG_POINT_MIP_LINEAR, - FILTER_MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT = D3D11_FILTER_MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT, - FILTER_MINIMUM_MIN_POINT_MAG_MIP_LINEAR = D3D11_FILTER_MINIMUM_MIN_POINT_MAG_MIP_LINEAR, - FILTER_MINIMUM_MIN_LINEAR_MAG_MIP_POINT = D3D11_FILTER_MINIMUM_MIN_LINEAR_MAG_MIP_POINT, - FILTER_MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR = D3D11_FILTER_MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR, - FILTER_MINIMUM_MIN_MAG_LINEAR_MIP_POINT = D3D11_FILTER_MINIMUM_MIN_MAG_LINEAR_MIP_POINT, - FILTER_MINIMUM_MIN_MAG_MIP_LINEAR = D3D11_FILTER_MINIMUM_MIN_MAG_MIP_LINEAR, - FILTER_MINIMUM_ANISOTROPIC = D3D11_FILTER_MINIMUM_ANISOTROPIC, - FILTER_MAXIMUM_MIN_MAG_MIP_POINT = D3D11_FILTER_MAXIMUM_MIN_MAG_MIP_POINT, - FILTER_MAXIMUM_MIN_MAG_POINT_MIP_LINEAR = D3D11_FILTER_MAXIMUM_MIN_MAG_POINT_MIP_LINEAR, - FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT = D3D11_FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT, - FILTER_MAXIMUM_MIN_POINT_MAG_MIP_LINEAR = D3D11_FILTER_MAXIMUM_MIN_POINT_MAG_MIP_LINEAR, - FILTER_MAXIMUM_MIN_LINEAR_MAG_MIP_POINT = D3D11_FILTER_MAXIMUM_MIN_LINEAR_MAG_MIP_POINT, - FILTER_MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR = D3D11_FILTER_MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR, - FILTER_MAXIMUM_MIN_MAG_LINEAR_MIP_POINT = D3D11_FILTER_MAXIMUM_MIN_MAG_LINEAR_MIP_POINT, - FILTER_MAXIMUM_MIN_MAG_MIP_LINEAR = D3D11_FILTER_MAXIMUM_MIN_MAG_MIP_LINEAR, - FILTER_MAXIMUM_ANISOTROPIC = D3D11_FILTER_MAXIMUM_ANISOTROPIC, + FILTER_MIN_MAG_MIP_POINT, + FILTER_MIN_MAG_POINT_MIP_LINEAR, + FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, + FILTER_MIN_POINT_MAG_MIP_LINEAR, + FILTER_MIN_LINEAR_MAG_MIP_POINT, + FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, + FILTER_MIN_MAG_LINEAR_MIP_POINT, + FILTER_MIN_MAG_MIP_LINEAR, + FILTER_ANISOTROPIC, + FILTER_COMPARISON_MIN_MAG_MIP_POINT, + FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, + FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT, + FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, + FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, + FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR, + FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, + FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, + FILTER_COMPARISON_ANISOTROPIC, + FILTER_MINIMUM_MIN_MAG_MIP_POINT, + FILTER_MINIMUM_MIN_MAG_POINT_MIP_LINEAR, + FILTER_MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT, + FILTER_MINIMUM_MIN_POINT_MAG_MIP_LINEAR, + FILTER_MINIMUM_MIN_LINEAR_MAG_MIP_POINT, + FILTER_MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR, + FILTER_MINIMUM_MIN_MAG_LINEAR_MIP_POINT, + FILTER_MINIMUM_MIN_MAG_MIP_LINEAR, + FILTER_MINIMUM_ANISOTROPIC, + FILTER_MAXIMUM_MIN_MAG_MIP_POINT, + FILTER_MAXIMUM_MIN_MAG_POINT_MIP_LINEAR, + FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT, + FILTER_MAXIMUM_MIN_POINT_MAG_MIP_LINEAR, + FILTER_MAXIMUM_MIN_LINEAR_MAG_MIP_POINT, + FILTER_MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR, + FILTER_MAXIMUM_MIN_MAG_LINEAR_MIP_POINT, + FILTER_MAXIMUM_MIN_MAG_MIP_LINEAR, + FILTER_MAXIMUM_ANISOTROPIC, +}; + +// Flags //////////////////////////////////////////// +enum CLEAR_FLAG +{ + CLEAR_DEPTH = 0x1L, + CLEAR_STENCIL = 0x2L, +}; +enum BIND_FLAG +{ + BIND_VERTEX_BUFFER = 0x1L, + BIND_INDEX_BUFFER = 0x2L, + BIND_CONSTANT_BUFFER = 0x4L, + BIND_SHADER_RESOURCE = 0x8L, + BIND_STREAM_OUTPUT = 0x10L, + BIND_RENDER_TARGET = 0x20L, + BIND_DEPTH_STENCIL = 0x40L, + BIND_UNORDERED_ACCESS = 0x80L, +}; +enum CPU_ACCESS +{ + CPU_ACCESS_WRITE = 0x10000L, + CPU_ACCESS_READ = 0x20000L, }; enum RESOURCE_MISC_FLAG { - RESOURCE_MISC_GENERATE_MIPS = D3D11_RESOURCE_MISC_GENERATE_MIPS, - RESOURCE_MISC_SHARED = D3D11_RESOURCE_MISC_SHARED, - RESOURCE_MISC_TEXTURECUBE = D3D11_RESOURCE_MISC_TEXTURECUBE, - RESOURCE_MISC_DRAWINDIRECT_ARGS = D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, - RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, - RESOURCE_MISC_BUFFER_STRUCTURED = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, - RESOURCE_MISC_RESOURCE_CLAMP = D3D11_RESOURCE_MISC_RESOURCE_CLAMP, - RESOURCE_MISC_SHARED_KEYEDMUTEX = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, - RESOURCE_MISC_GDI_COMPATIBLE = D3D11_RESOURCE_MISC_GDI_COMPATIBLE, - RESOURCE_MISC_SHARED_NTHANDLE = D3D11_RESOURCE_MISC_SHARED_NTHANDLE, - RESOURCE_MISC_RESTRICTED_CONTENT = D3D11_RESOURCE_MISC_RESTRICTED_CONTENT, - RESOURCE_MISC_RESTRICT_SHARED_RESOURCE = D3D11_RESOURCE_MISC_RESTRICT_SHARED_RESOURCE, - RESOURCE_MISC_RESTRICT_SHARED_RESOURCE_DRIVER = D3D11_RESOURCE_MISC_RESTRICT_SHARED_RESOURCE_DRIVER, - RESOURCE_MISC_GUARDED = D3D11_RESOURCE_MISC_GUARDED, - RESOURCE_MISC_TILE_POOL = D3D11_RESOURCE_MISC_TILE_POOL, - RESOURCE_MISC_TILED = D3D11_RESOURCE_MISC_TILED, + RESOURCE_MISC_GENERATE_MIPS = 0x1L, + RESOURCE_MISC_SHARED = 0x2L, + RESOURCE_MISC_TEXTURECUBE = 0x4L, + RESOURCE_MISC_BUFFER_STRUCTURED = 0x40L, + RESOURCE_MISC_TILED = 0x40000L, }; -#define APPEND_ALIGNED_ELEMENT D3D11_APPEND_ALIGNED_ELEMENT -#define FLOAT32_MAX D3D11_FLOAT32_MAX -#define DEFAULT_STENCIL_READ_MASK D3D11_DEFAULT_STENCIL_READ_MASK -#define SO_NO_RASTERIZED_STREAM D3D11_SO_NO_RASTERIZED_STREAM +#define APPEND_ALIGNED_ELEMENT ( 0xffffffff ) +#define FLOAT32_MAX ( 3.402823466e+38f ) +#define DEFAULT_STENCIL_READ_MASK ( 0xff ) +#define SO_NO_RASTERIZED_STREAM ( 0xffffffff ) + +// Structs ///////////////////////////////////////////// struct ViewPort { @@ -392,7 +366,13 @@ public: class GraphicsDevice : public wiThreadSafeManager { +protected: + bool oddFrame; + bool VSYNC; + int SCREENWIDTH, SCREENHEIGHT; public: + GraphicsDevice() :oddFrame(false), VSYNC(true), SCREENWIDTH(0), SCREENHEIGHT(0) {} + virtual HRESULT CreateBuffer(const BufferDesc *pDesc, const SubresourceData* pInitialData, BufferResource *ppBuffer) = 0; virtual HRESULT CreateTexture1D() = 0; virtual HRESULT CreateTexture2D(const Texture2DDesc* pDesc, const SubresourceData *pInitialData, Texture2D **ppTexture2D) = 0; @@ -424,8 +404,14 @@ public: virtual bool GetMultithreadingSupport() = 0; - virtual bool GetVSyncEnabled() = 0; - virtual void SetVSyncEnabled(bool value) = 0; + bool GetVSyncEnabled() { return VSYNC; } + void SetVSyncEnabled(bool value) { VSYNC = value; } + + int GetScreenWidth() { return SCREENWIDTH; } + int GetScreenHeight() { return SCREENHEIGHT; } + + virtual void SetScreenWidth(int value) = 0; + virtual void SetScreenHeight(int value) = 0; ///////////////Thread-sensitive//////////////////////// diff --git a/WickedEngine/wiGraphicsAPI_DX11.cpp b/WickedEngine/wiGraphicsAPI_DX11.cpp index 98d6cdc86..3caf32054 100644 --- a/WickedEngine/wiGraphicsAPI_DX11.cpp +++ b/WickedEngine/wiGraphicsAPI_DX11.cpp @@ -1,4 +1,3 @@ -#include "CommonInclude.h" #include "wiGraphicsAPI_DX11.h" #include "wiHelper.h" #include "TextureMapping.h" @@ -6,7 +5,11 @@ #include "Utility/WicTextureLoader.h" #include "Utility/DDSTextureLoader.h" -GraphicsDevice_DX11::GraphicsDevice_DX11(HWND window, int screenW, int screenH, bool windowed) +#ifndef WINSTORE_SUPPORT +GraphicsDevice_DX11::GraphicsDevice_DX11(HWND window, int screenW, int screenH, bool windowed) : GraphicsDevice() +#else +GraphicsDevice_DX11::GraphicsDevice_DX11(Windows::UI::Core::CoreWindow^ window) +#endif { HRESULT hr = S_OK; @@ -123,7 +126,7 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(HWND window, int screenW, int screenH, // Create a render target view - APITexture2D pBackBuffer = NULL; + ID3D11Texture2D* pBackBuffer = NULL; hr = swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); if (FAILED(hr)) { wiHelper::messageBox("BackBuffer creation Failed!", "Error!", nullptr); @@ -145,6 +148,9 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(HWND window, int screenW, int screenH, viewPort.MaxDepth = 1.0f; viewPort.TopLeftX = 0; viewPort.TopLeftY = 0; + + SCREENWIDTH = screenW; + SCREENHEIGHT = screenH; } GraphicsDevice_DX11::~GraphicsDevice_DX11() { @@ -159,51 +165,443 @@ GraphicsDevice_DX11::~GraphicsDevice_DX11() SAFE_RELEASE(device); } +void GraphicsDevice_DX11::SetScreenWidth(int value) +{ + SCREENWIDTH = value; + // TODO: resize backbuffer +} +void GraphicsDevice_DX11::SetScreenHeight(int value) +{ + SCREENHEIGHT = value; + // TODO: resize backbuffer +} + +inline UINT _ParseBindFlags(UINT value) +{ + UINT _flag = 0; + + if (value & BIND_VERTEX_BUFFER) + _flag |= D3D11_BIND_VERTEX_BUFFER; + if (value & BIND_INDEX_BUFFER) + _flag |= D3D11_BIND_INDEX_BUFFER; + if (value & BIND_CONSTANT_BUFFER) + _flag |= D3D11_BIND_CONSTANT_BUFFER; + if (value & BIND_SHADER_RESOURCE) + _flag |= D3D11_BIND_SHADER_RESOURCE; + if (value & BIND_STREAM_OUTPUT) + _flag |= D3D11_BIND_STREAM_OUTPUT; + if (value & BIND_RENDER_TARGET) + _flag |= D3D11_BIND_RENDER_TARGET; + if (value & BIND_DEPTH_STENCIL) + _flag |= D3D11_BIND_DEPTH_STENCIL; + if (value & BIND_UNORDERED_ACCESS) + _flag |= D3D11_BIND_UNORDERED_ACCESS; + + return _flag; +} +inline UINT _ParseCPUAccessFlags(UINT value) +{ + UINT _flag = 0; + + if (value & CPU_ACCESS_WRITE) + _flag |= D3D11_CPU_ACCESS_WRITE; + if (value & CPU_ACCESS_READ) + _flag |= D3D11_CPU_ACCESS_READ; + + return _flag; +} +inline UINT _ParseResourceMiscFlags(UINT value) +{ + UINT _flag = 0; + + if (value & RESOURCE_MISC_GENERATE_MIPS) + _flag |= D3D11_RESOURCE_MISC_GENERATE_MIPS; + if (value & RESOURCE_MISC_SHARED) + _flag |= D3D11_RESOURCE_MISC_SHARED; + if (value & RESOURCE_MISC_TEXTURECUBE) + _flag |= D3D11_RESOURCE_MISC_TEXTURECUBE; + if (value & RESOURCE_MISC_BUFFER_STRUCTURED) + _flag |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; + if (value & RESOURCE_MISC_TILED) + _flag |= D3D11_RESOURCE_MISC_TILED; + + return _flag; +} -// TODO! inline D3D11_FILTER _ConvertFilter(FILTER value) { - return (D3D11_FILTER)value; + switch (value) + { + case FILTER_MIN_MAG_MIP_POINT: + return D3D11_FILTER_MIN_MAG_MIP_POINT; + break; + case FILTER_MIN_MAG_POINT_MIP_LINEAR: + return D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR; + break; + case FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT: + return D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT; + break; + case FILTER_MIN_POINT_MAG_MIP_LINEAR: + return D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR; + break; + case FILTER_MIN_LINEAR_MAG_MIP_POINT: + return D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT; + break; + case FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR: + return D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR; + break; + case FILTER_MIN_MAG_LINEAR_MIP_POINT: + return D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; + break; + case FILTER_MIN_MAG_MIP_LINEAR: + return D3D11_FILTER_MIN_MAG_MIP_LINEAR; + break; + case FILTER_ANISOTROPIC: + return D3D11_FILTER_ANISOTROPIC; + break; + case FILTER_COMPARISON_MIN_MAG_MIP_POINT: + return D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT; + break; + case FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR: + return D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR; + break; + case FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT: + return D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT; + break; + case FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR: + return D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR; + break; + case FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT: + return D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT; + break; + case FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR: + return D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR; + break; + case FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT: + return D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT; + break; + case FILTER_COMPARISON_MIN_MAG_MIP_LINEAR: + return D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR; + break; + case FILTER_COMPARISON_ANISOTROPIC: + return D3D11_FILTER_COMPARISON_ANISOTROPIC; + break; + case FILTER_MINIMUM_MIN_MAG_MIP_POINT: + return D3D11_FILTER_MINIMUM_MIN_MAG_MIP_POINT; + break; + case FILTER_MINIMUM_MIN_MAG_POINT_MIP_LINEAR: + return D3D11_FILTER_MINIMUM_MIN_MAG_POINT_MIP_LINEAR; + break; + case FILTER_MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT: + return D3D11_FILTER_MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT; + break; + case FILTER_MINIMUM_MIN_POINT_MAG_MIP_LINEAR: + return D3D11_FILTER_MINIMUM_MIN_POINT_MAG_MIP_LINEAR; + break; + case FILTER_MINIMUM_MIN_LINEAR_MAG_MIP_POINT: + return D3D11_FILTER_MINIMUM_MIN_LINEAR_MAG_MIP_POINT; + break; + case FILTER_MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR: + return D3D11_FILTER_MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR; + break; + case FILTER_MINIMUM_MIN_MAG_LINEAR_MIP_POINT: + return D3D11_FILTER_MINIMUM_MIN_MAG_LINEAR_MIP_POINT; + break; + case FILTER_MINIMUM_MIN_MAG_MIP_LINEAR: + return D3D11_FILTER_MINIMUM_MIN_MAG_MIP_LINEAR; + break; + case FILTER_MINIMUM_ANISOTROPIC: + return D3D11_FILTER_MINIMUM_ANISOTROPIC; + break; + case FILTER_MAXIMUM_MIN_MAG_MIP_POINT: + return D3D11_FILTER_MAXIMUM_MIN_MAG_MIP_POINT; + break; + case FILTER_MAXIMUM_MIN_MAG_POINT_MIP_LINEAR: + return D3D11_FILTER_MAXIMUM_MIN_MAG_POINT_MIP_LINEAR; + break; + case FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT: + return D3D11_FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT; + break; + case FILTER_MAXIMUM_MIN_POINT_MAG_MIP_LINEAR: + return D3D11_FILTER_MAXIMUM_MIN_POINT_MAG_MIP_LINEAR; + break; + case FILTER_MAXIMUM_MIN_LINEAR_MAG_MIP_POINT: + return D3D11_FILTER_MAXIMUM_MIN_LINEAR_MAG_MIP_POINT; + break; + case FILTER_MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR: + return D3D11_FILTER_MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR; + break; + case FILTER_MAXIMUM_MIN_MAG_LINEAR_MIP_POINT: + return D3D11_FILTER_MAXIMUM_MIN_MAG_LINEAR_MIP_POINT; + break; + case FILTER_MAXIMUM_MIN_MAG_MIP_LINEAR: + return D3D11_FILTER_MAXIMUM_MIN_MAG_MIP_LINEAR; + break; + case FILTER_MAXIMUM_ANISOTROPIC: + return D3D11_FILTER_MAXIMUM_ANISOTROPIC; + break; + default: + break; + } + return D3D11_FILTER_MIN_MAG_MIP_POINT; } inline D3D11_TEXTURE_ADDRESS_MODE _ConvertTextureAddressMode(TEXTURE_ADDRESS_MODE value) { - return (D3D11_TEXTURE_ADDRESS_MODE)value; + switch (value) + { + case TEXTURE_ADDRESS_WRAP: + return D3D11_TEXTURE_ADDRESS_WRAP; + break; + case TEXTURE_ADDRESS_MIRROR: + return D3D11_TEXTURE_ADDRESS_MIRROR; + break; + case TEXTURE_ADDRESS_CLAMP: + return D3D11_TEXTURE_ADDRESS_CLAMP; + break; + case TEXTURE_ADDRESS_BORDER: + return D3D11_TEXTURE_ADDRESS_BORDER; + break; + case TEXTURE_ADDRESS_MIRROR_ONCE: + return D3D11_TEXTURE_ADDRESS_MIRROR_ONCE; + break; + default: + break; + } + return D3D11_TEXTURE_ADDRESS_WRAP; } inline D3D11_COMPARISON_FUNC _ConvertComparisonFunc(COMPARISON_FUNC value) { - return (D3D11_COMPARISON_FUNC)value; + switch (value) + { + case COMPARISON_NEVER: + return D3D11_COMPARISON_NEVER; + break; + case COMPARISON_LESS: + return D3D11_COMPARISON_LESS; + break; + case COMPARISON_EQUAL: + return D3D11_COMPARISON_EQUAL; + break; + case COMPARISON_LESS_EQUAL: + return D3D11_COMPARISON_LESS_EQUAL; + break; + case COMPARISON_GREATER: + return D3D11_COMPARISON_GREATER; + break; + case COMPARISON_NOT_EQUAL: + return D3D11_COMPARISON_NOT_EQUAL; + break; + case COMPARISON_GREATER_EQUAL: + return D3D11_COMPARISON_GREATER_EQUAL; + break; + case COMPARISON_ALWAYS: + return D3D11_COMPARISON_ALWAYS; + break; + default: + break; + } + return D3D11_COMPARISON_NEVER; } inline D3D11_FILL_MODE _ConvertFillMode(FILL_MODE value) { - return (D3D11_FILL_MODE)value; + switch (value) + { + case FILL_WIREFRAME: + return D3D11_FILL_WIREFRAME; + break; + case FILL_SOLID: + return D3D11_FILL_SOLID; + break; + default: + break; + } + return D3D11_FILL_WIREFRAME; } inline D3D11_CULL_MODE _ConvertCullMode(CULL_MODE value) { - return (D3D11_CULL_MODE)value; + switch (value) + { + case CULL_NONE: + return D3D11_CULL_NONE; + break; + case CULL_FRONT: + return D3D11_CULL_FRONT; + break; + case CULL_BACK: + return D3D11_CULL_BACK; + break; + default: + break; + } + return D3D11_CULL_NONE; } inline D3D11_DEPTH_WRITE_MASK _ConvertDepthWriteMask(DEPTH_WRITE_MASK value) { - return (D3D11_DEPTH_WRITE_MASK)value; + switch (value) + { + case DEPTH_WRITE_MASK_ZERO: + return D3D11_DEPTH_WRITE_MASK_ZERO; + break; + case DEPTH_WRITE_MASK_ALL: + return D3D11_DEPTH_WRITE_MASK_ALL; + break; + default: + break; + } + return D3D11_DEPTH_WRITE_MASK_ZERO; } inline D3D11_STENCIL_OP _ConvertStencilOp(STENCIL_OP value) { - return (D3D11_STENCIL_OP)value; + switch (value) + { + case STENCIL_OP_KEEP: + return D3D11_STENCIL_OP_KEEP; + break; + case STENCIL_OP_ZERO: + return D3D11_STENCIL_OP_ZERO; + break; + case STENCIL_OP_REPLACE: + return D3D11_STENCIL_OP_REPLACE; + break; + case STENCIL_OP_INCR_SAT: + return D3D11_STENCIL_OP_INCR_SAT; + break; + case STENCIL_OP_DECR_SAT: + return D3D11_STENCIL_OP_DECR_SAT; + break; + case STENCIL_OP_INVERT: + return D3D11_STENCIL_OP_INVERT; + break; + case STENCIL_OP_INCR: + return D3D11_STENCIL_OP_INCR; + break; + case STENCIL_OP_DECR: + return D3D11_STENCIL_OP_DECR; + break; + default: + break; + } + return D3D11_STENCIL_OP_KEEP; } inline D3D11_BLEND _ConvertBlend(BLEND value) { - return (D3D11_BLEND)value; + switch (value) + { + case BLEND_ZERO: + return D3D11_BLEND_ZERO; + break; + case BLEND_ONE: + return D3D11_BLEND_ONE; + break; + case BLEND_SRC_COLOR: + return D3D11_BLEND_SRC_COLOR; + break; + case BLEND_INV_SRC_COLOR: + return D3D11_BLEND_INV_SRC_COLOR; + break; + case BLEND_SRC_ALPHA: + return D3D11_BLEND_SRC_ALPHA; + break; + case BLEND_INV_SRC_ALPHA: + return D3D11_BLEND_INV_SRC_ALPHA; + break; + case BLEND_DEST_ALPHA: + return D3D11_BLEND_DEST_ALPHA; + break; + case BLEND_INV_DEST_ALPHA: + return D3D11_BLEND_INV_DEST_ALPHA; + break; + case BLEND_DEST_COLOR: + return D3D11_BLEND_DEST_COLOR; + break; + case BLEND_INV_DEST_COLOR: + return D3D11_BLEND_INV_DEST_COLOR; + break; + case BLEND_SRC_ALPHA_SAT: + return D3D11_BLEND_SRC_ALPHA_SAT; + break; + case BLEND_BLEND_FACTOR: + return D3D11_BLEND_BLEND_FACTOR; + break; + case BLEND_INV_BLEND_FACTOR: + return D3D11_BLEND_INV_BLEND_FACTOR; + break; + case BLEND_SRC1_COLOR: + return D3D11_BLEND_SRC1_COLOR; + break; + case BLEND_INV_SRC1_COLOR: + return D3D11_BLEND_INV_SRC1_COLOR; + break; + case BLEND_SRC1_ALPHA: + return D3D11_BLEND_SRC1_ALPHA; + break; + case BLEND_INV_SRC1_ALPHA: + return D3D11_BLEND_INV_SRC1_ALPHA; + break; + default: + break; + } + return D3D11_BLEND_ZERO; } inline D3D11_BLEND_OP _ConvertBlendOp(BLEND_OP value) { - return (D3D11_BLEND_OP)value; + switch (value) + { + case BLEND_OP_ADD: + return D3D11_BLEND_OP_ADD; + break; + case BLEND_OP_SUBTRACT: + return D3D11_BLEND_OP_SUBTRACT; + break; + case BLEND_OP_REV_SUBTRACT: + return D3D11_BLEND_OP_REV_SUBTRACT; + break; + case BLEND_OP_MIN: + return D3D11_BLEND_OP_MIN; + break; + case BLEND_OP_MAX: + return D3D11_BLEND_OP_MAX; + break; + default: + break; + } + return D3D11_BLEND_OP_ADD; } inline D3D11_USAGE _ConvertUsage(USAGE value) { - return (D3D11_USAGE)value; + switch (value) + { + case USAGE_DEFAULT: + return D3D11_USAGE_DEFAULT; + break; + case USAGE_IMMUTABLE: + return D3D11_USAGE_IMMUTABLE; + break; + case USAGE_DYNAMIC: + return D3D11_USAGE_DYNAMIC; + break; + case USAGE_STAGING: + return D3D11_USAGE_STAGING; + break; + default: + break; + } + return D3D11_USAGE_DEFAULT; } inline D3D11_INPUT_CLASSIFICATION _ConvertInputClassification(INPUT_CLASSIFICATION value) { - return (D3D11_INPUT_CLASSIFICATION)value; + switch (value) + { + case INPUT_PER_VERTEX_DATA: + return D3D11_INPUT_PER_VERTEX_DATA; + break; + case INPUT_PER_INSTANCE_DATA: + return D3D11_INPUT_PER_INSTANCE_DATA; + break; + default: + break; + } + return D3D11_INPUT_PER_VERTEX_DATA; } inline DXGI_FORMAT _ConvertFormat(DXGI_FORMAT value) { @@ -224,9 +622,9 @@ inline D3D11_TEXTURE2D_DESC _ConvertTexture2DDesc(const Texture2DDesc* pDesc) desc.Format = _ConvertFormat(pDesc->Format); desc.SampleDesc = _ConvertSampleDesc(pDesc->SampleDesc); desc.Usage = _ConvertUsage(pDesc->Usage); - desc.BindFlags = pDesc->BindFlags; - desc.CPUAccessFlags = pDesc->CPUAccessFlags; - desc.MiscFlags = pDesc->MiscFlags; + desc.BindFlags = _ParseBindFlags(pDesc->BindFlags); + desc.CPUAccessFlags = _ParseCPUAccessFlags(pDesc->CPUAccessFlags); + desc.MiscFlags = _ParseResourceMiscFlags(pDesc->MiscFlags); return desc; } @@ -249,9 +647,9 @@ HRESULT GraphicsDevice_DX11::CreateBuffer(const BufferDesc *pDesc, const Subreso D3D11_BUFFER_DESC desc; desc.ByteWidth = pDesc->ByteWidth; desc.Usage = _ConvertUsage(pDesc->Usage); - desc.BindFlags = pDesc->BindFlags; - desc.CPUAccessFlags = pDesc->CPUAccessFlags; - desc.MiscFlags = pDesc->MiscFlags; + desc.BindFlags = _ParseBindFlags(pDesc->BindFlags); + desc.CPUAccessFlags = _ParseCPUAccessFlags(pDesc->CPUAccessFlags); + desc.MiscFlags = _ParseResourceMiscFlags(pDesc->MiscFlags); desc.StructureByteStride = pDesc->StructureByteStride; D3D11_SUBRESOURCE_DATA* data = _ConvertSubresourceData(pInitialData); @@ -300,9 +698,9 @@ HRESULT GraphicsDevice_DX11::CreateTextureCube(const Texture2DDesc* pDesc, const HRESULT hr = S_OK; - if (!(desc.MiscFlags & RESOURCE_MISC_TEXTURECUBE)) + if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE)) { - desc.MiscFlags |= RESOURCE_MISC_TEXTURECUBE; + desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE; } hr = device->CreateTexture2D(&desc, data, &((*ppTextureCube)->texture2D)); @@ -321,7 +719,7 @@ HRESULT GraphicsDevice_DX11::CreateShaderResourceView(Texture2D* pTexture) if (pTexture->desc.BindFlags & D3D11_BIND_SHADER_RESOURCE) { D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc; - if (pTexture->desc.MiscFlags & RESOURCE_MISC_TEXTURECUBE) + if (pTexture->desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE) { shaderResourceViewDesc.Format = pTexture->desc.Format; if (pTexture->desc.BindFlags & D3D11_BIND_DEPTH_STENCIL) @@ -354,7 +752,7 @@ HRESULT GraphicsDevice_DX11::CreateRenderTargetView(Texture2D* pTexture) if (pTexture->desc.BindFlags & D3D11_BIND_RENDER_TARGET) { D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc; - if (pTexture->desc.MiscFlags & RESOURCE_MISC_TEXTURECUBE) + if (pTexture->desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE) { renderTargetViewDesc.Format = pTexture->desc.Format; renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; @@ -379,7 +777,7 @@ HRESULT GraphicsDevice_DX11::CreateDepthStencilView(Texture2D* pTexture) if (pTexture->desc.BindFlags & D3D11_BIND_DEPTH_STENCIL) { D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc; - if (pTexture->desc.MiscFlags & RESOURCE_MISC_TEXTURECUBE) + if (pTexture->desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE) { ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc)); depthStencilViewDesc.Format = DXGI_FORMAT_D32_FLOAT; @@ -413,6 +811,8 @@ HRESULT GraphicsDevice_DX11::CreateInputLayout(const VertexLayoutDesc *pInputEle desc[i].Format = _ConvertFormat(pInputElementDescs[i].Format); desc[i].InputSlot = pInputElementDescs[i].InputSlot; desc[i].AlignedByteOffset = pInputElementDescs[i].AlignedByteOffset; + if (desc[i].AlignedByteOffset == APPEND_ALIGNED_ELEMENT) + desc[i].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; desc[i].InputSlotClass = _ConvertInputClassification(pInputElementDescs[i].InputSlotClass); desc[i].InstanceDataStepRate = pInputElementDescs[i].InstanceDataStepRate; } @@ -449,6 +849,9 @@ HRESULT GraphicsDevice_DX11::CreateGeometryShaderWithStreamOutput(const void *pS decl[i].OutputSlot = pSODeclaration[i].OutputSlot; } + if (RasterizedStream == SO_NO_RASTERIZED_STREAM) + RasterizedStream = D3D11_SO_NO_RASTERIZED_STREAM; + HRESULT hr = device->CreateGeometryShaderWithStreamOutput(pShaderBytecode, BytecodeLength, decl, NumEntries, pBufferStrides, NumStrides, RasterizedStream, pClassLinkage, ppGeometryShader); @@ -563,6 +966,8 @@ void GraphicsDevice_DX11::PresentEnd() UnbindTextures(0, TEXSLOT_COUNT, GRAPHICSTHREAD_IMMEDIATE); + oddFrame = !oddFrame; + UNLOCK(); } diff --git a/WickedEngine/wiGraphicsAPI_DX11.h b/WickedEngine/wiGraphicsAPI_DX11.h index b78408b63..39d90a6cd 100644 --- a/WickedEngine/wiGraphicsAPI_DX11.h +++ b/WickedEngine/wiGraphicsAPI_DX11.h @@ -1,4 +1,5 @@ #pragma once +#include "CommonInclude.h" #include "wiGraphicsAPI.h" class GraphicsDevice_DX11 : public GraphicsDevice @@ -7,15 +8,20 @@ private: ID3D11Device* device; D3D_DRIVER_TYPE driverType; D3D_FEATURE_LEVEL featureLevel; - SwapChain swapChain; - RenderTargetView renderTargetView; + IDXGISwapChain* swapChain; + ID3D11RenderTargetView* renderTargetView; ViewPort viewPort; - DeviceContext deviceContexts[GRAPHICSTHREAD_COUNT]; - CommandList commandLists[GRAPHICSTHREAD_COUNT]; - bool DX11, VSYNC, DEFERREDCONTEXT_SUPPORT; + ID3D11DeviceContext* deviceContexts[GRAPHICSTHREAD_COUNT]; + ID3D11CommandList* commandLists[GRAPHICSTHREAD_COUNT]; + bool DX11, DEFERREDCONTEXT_SUPPORT; public: +#ifndef WINSTORE_SUPPORT GraphicsDevice_DX11(HWND window, int screenW, int screenH, bool windowed); +#else + GraphicsDevice_DX11(Windows::UI::Core::CoreWindow^ window); +#endif + ~GraphicsDevice_DX11(); virtual HRESULT CreateBuffer(const BufferDesc *pDesc, const SubresourceData* pInitialData, BufferResource *ppBuffer); @@ -49,8 +55,8 @@ public: virtual bool GetMultithreadingSupport() { return DEFERREDCONTEXT_SUPPORT; } - virtual bool GetVSyncEnabled() { return VSYNC; } - virtual void SetVSyncEnabled(bool value) { VSYNC = value; } + virtual void SetScreenWidth(int value); + virtual void SetScreenHeight(int value); ///////////////Thread-sensitive//////////////////////// @@ -88,7 +94,12 @@ public: } virtual void ClearDepthStencil(Texture2D* pTexture, UINT ClearFlags, FLOAT Depth, UINT8 Stencil, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { if (deviceContexts[threadID] != nullptr && pTexture != nullptr && pTexture->depthStencilView != nullptr) { - deviceContexts[threadID]->ClearDepthStencilView(pTexture->depthStencilView, ClearFlags, Depth, Stencil); + UINT _flags = 0; + if (ClearFlags & CLEAR_DEPTH) + _flags |= D3D11_CLEAR_DEPTH; + if (ClearFlags & CLEAR_STENCIL) + _flags |= D3D11_CLEAR_STENCIL; + deviceContexts[threadID]->ClearDepthStencilView(pTexture->depthStencilView, _flags, Depth, Stencil); } } virtual void BindTexturePS(const Texture* texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { @@ -365,9 +376,23 @@ public: desc.Usage = USAGE_STAGING; break; }; - desc.BindFlags = d3dDesc.BindFlags; - desc.CPUAccessFlags = d3dDesc.CPUAccessFlags; - desc.MiscFlags = d3dDesc.MiscFlags; + desc.BindFlags = 0; + { + if (d3dDesc.BindFlags & D3D11_BIND_CONSTANT_BUFFER) + desc.BindFlags |= BIND_CONSTANT_BUFFER; + if (d3dDesc.BindFlags & D3D11_BIND_VERTEX_BUFFER) + desc.BindFlags |= BIND_VERTEX_BUFFER; + if (d3dDesc.BindFlags & D3D11_BIND_INDEX_BUFFER) + desc.BindFlags |= BIND_INDEX_BUFFER; + } + desc.CPUAccessFlags = 0; + { + if (d3dDesc.CPUAccessFlags & D3D11_CPU_ACCESS_WRITE) + desc.CPUAccessFlags |= CPU_ACCESS_WRITE; + if (d3dDesc.CPUAccessFlags & D3D11_CPU_ACCESS_READ) + desc.CPUAccessFlags |= CPU_ACCESS_READ; + } + desc.MiscFlags = 0; desc.StructureByteStride = d3dDesc.StructureByteStride; hr = CreateBuffer(&desc, nullptr, &buffer); diff --git a/WickedEngine/wiHairParticle.cpp b/WickedEngine/wiHairParticle.cpp index c4fe2614b..a8d2bbdbf 100644 --- a/WickedEngine/wiHairParticle.cpp +++ b/WickedEngine/wiHairParticle.cpp @@ -107,7 +107,7 @@ void wiHairParticle::SetUpStatic(){ bd.ByteWidth = sizeof(ConstantBuffer); bd.BindFlags = BIND_CONSTANT_BUFFER; bd.CPUAccessFlags = CPU_ACCESS_WRITE; - wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &cbgs ); + wiRenderer::GetDevice()->CreateBuffer( &bd, NULL, &cbgs ); @@ -123,7 +123,7 @@ void wiHairParticle::SetUpStatic(){ rsd.ScissorEnable=false; rsd.MultisampleEnable=false; rsd.AntialiasedLineEnable=false; - wiRenderer::graphicsDevice->CreateRasterizerState(&rsd,&rs); + wiRenderer::GetDevice()->CreateRasterizerState(&rsd,&rs); rsd.FillMode=FILL_SOLID; rsd.CullMode=CULL_NONE; rsd.FrontCounterClockwise=true; @@ -134,7 +134,7 @@ void wiHairParticle::SetUpStatic(){ rsd.ScissorEnable=false; rsd.MultisampleEnable=false; rsd.AntialiasedLineEnable=false; - wiRenderer::graphicsDevice->CreateRasterizerState(&rsd,&ncrs); + wiRenderer::GetDevice()->CreateRasterizerState(&rsd,&ncrs); DepthStencilDesc dsd; @@ -154,7 +154,7 @@ void wiHairParticle::SetUpStatic(){ dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; // Create the depth stencil state. - wiRenderer::graphicsDevice->CreateDepthStencilState(&dsd, &dss); + wiRenderer::GetDevice()->CreateDepthStencilState(&dsd, &dss); BlendDesc bld; @@ -168,7 +168,7 @@ void wiHairParticle::SetUpStatic(){ bld.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bld.RenderTarget[0].RenderTargetWriteMask = 0x0f; bld.AlphaToCoverageEnable=false; - wiRenderer::graphicsDevice->CreateBlendState(&bld,&bs); + wiRenderer::GetDevice()->CreateBlendState(&bld,&bs); } void wiHairParticle::Settings(int l0,int l1,int l2) { @@ -192,9 +192,9 @@ void wiHairParticle::SetUpPatches() bd.ByteWidth = sizeof(Point)*MAX_PARTICLES; bd.BindFlags = BIND_VERTEX_BUFFER; bd.CPUAccessFlags = CPU_ACCESS_WRITE; - wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &vb[0] ); - wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &vb[1] ); - wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &vb[2] ); + wiRenderer::GetDevice()->CreateBuffer( &bd, NULL, &vb[0] ); + wiRenderer::GetDevice()->CreateBuffer( &bd, NULL, &vb[1] ); + wiRenderer::GetDevice()->CreateBuffer( &bd, NULL, &vb[2] ); const int triangleperpatch = 4; int currentTris=0; @@ -389,19 +389,19 @@ void wiHairParticle::Draw(Camera* camera, GRAPHICSTHREAD threadID) { Texture2D* texture = material->texture; - wiRenderer::graphicsDevice->BindPrimitiveTopology(PRIMITIVETOPOLOGY::POINTLIST,threadID); - wiRenderer::graphicsDevice->BindVertexLayout(il,threadID); - wiRenderer::graphicsDevice->BindPS(texture?qps:ps,threadID); - wiRenderer::graphicsDevice->BindVS(vs,threadID); + wiRenderer::GetDevice()->BindPrimitiveTopology(PRIMITIVETOPOLOGY::POINTLIST,threadID); + wiRenderer::GetDevice()->BindVertexLayout(il,threadID); + wiRenderer::GetDevice()->BindPS(texture?qps:ps,threadID); + wiRenderer::GetDevice()->BindVS(vs,threadID); if(texture){ - wiRenderer::graphicsDevice->BindTexturePS(texture,TEXSLOT_ONDEMAND0,threadID); - wiRenderer::graphicsDevice->BindTextureGS(texture,TEXSLOT_ONDEMAND0,threadID); + wiRenderer::GetDevice()->BindTexturePS(texture,TEXSLOT_ONDEMAND0,threadID); + wiRenderer::GetDevice()->BindTextureGS(texture,TEXSLOT_ONDEMAND0,threadID); - wiRenderer::graphicsDevice->BindBlendState(bs,threadID); + wiRenderer::GetDevice()->BindBlendState(bs,threadID); } else - wiRenderer::graphicsDevice->BindRasterizerState(ncrs,threadID); + wiRenderer::GetDevice()->BindRasterizerState(ncrs,threadID); static thread_local ConstantBuffer* gcb = new ConstantBuffer; @@ -409,10 +409,10 @@ void wiHairParticle::Draw(Camera* camera, GRAPHICSTHREAD threadID) (*gcb).color=material->diffuseColor; (*gcb).drawdistance = (float)LOD[2]; - wiRenderer::graphicsDevice->UpdateBuffer(cbgs,gcb,threadID); - wiRenderer::graphicsDevice->BindConstantBufferGS(cbgs, CB_GETBINDSLOT(ConstantBuffer),threadID); + wiRenderer::GetDevice()->UpdateBuffer(cbgs,gcb,threadID); + wiRenderer::GetDevice()->BindConstantBufferGS(cbgs, CB_GETBINDSLOT(ConstantBuffer),threadID); - wiRenderer::graphicsDevice->BindDepthStencilState(dss,STENCILREF_DEFAULT,threadID); + wiRenderer::GetDevice()->BindDepthStencilState(dss,STENCILREF_DEFAULT,threadID); for(int i=0;i<3;++i){ @@ -420,11 +420,11 @@ void wiHairParticle::Draw(Camera* camera, GRAPHICSTHREAD threadID) renderPoints.reserve(MAX_PARTICLES); if(texture){ - wiRenderer::graphicsDevice->BindGS(i<2?qgs[0]:qgs[1],threadID); - wiRenderer::graphicsDevice->BindRasterizerState(i<2?ncrs:rs,threadID); + wiRenderer::GetDevice()->BindGS(i<2?qgs[0]:qgs[1],threadID); + wiRenderer::GetDevice()->BindRasterizerState(i<2?ncrs:rs,threadID); } else - wiRenderer::graphicsDevice->BindGS(gs[i],threadID); + wiRenderer::GetDevice()->BindGS(gs[i],threadID); CulledList::iterator iter = culledPatches.begin(); while(iter != culledPatches.end()){ Cullable* culled = *iter; @@ -441,12 +441,12 @@ void wiHairParticle::Draw(Camera* camera, GRAPHICSTHREAD threadID) ++iter; } - wiRenderer::graphicsDevice->UpdateBuffer(vb[i],renderPoints.data(),threadID,sizeof(Point)*renderPoints.size()); - wiRenderer::graphicsDevice->BindVertexBuffer(vb[i],0,sizeof(Point),threadID); - wiRenderer::graphicsDevice->Draw(renderPoints.size(),threadID); + wiRenderer::GetDevice()->UpdateBuffer(vb[i],renderPoints.data(),threadID,sizeof(Point)*renderPoints.size()); + wiRenderer::GetDevice()->BindVertexBuffer(vb[i],0,sizeof(Point),threadID); + wiRenderer::GetDevice()->Draw(renderPoints.size(),threadID); } - wiRenderer::graphicsDevice->BindGS(nullptr,threadID); + wiRenderer::GetDevice()->BindGS(nullptr,threadID); } } diff --git a/WickedEngine/wiImage.cpp b/WickedEngine/wiImage.cpp index 2472c4a18..e7f8f8222 100644 --- a/WickedEngine/wiImage.cpp +++ b/WickedEngine/wiImage.cpp @@ -34,14 +34,14 @@ void wiImage::LoadBuffers() bd.ByteWidth = sizeof(ImageCB); bd.BindFlags = BIND_CONSTANT_BUFFER; bd.CPUAccessFlags = CPU_ACCESS_WRITE; - wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &constantBuffer ); + wiRenderer::GetDevice()->CreateBuffer( &bd, NULL, &constantBuffer ); ZeroMemory(&bd, sizeof(bd)); bd.Usage = USAGE_DYNAMIC; bd.ByteWidth = sizeof(PostProcessCB); bd.BindFlags = BIND_CONSTANT_BUFFER; bd.CPUAccessFlags = CPU_ACCESS_WRITE; - wiRenderer::graphicsDevice->CreateBuffer(&bd, NULL, &processCb); + wiRenderer::GetDevice()->CreateBuffer(&bd, NULL, &processCb); BindPersistentState(GRAPHICSTHREAD_IMMEDIATE); } @@ -86,7 +86,7 @@ void wiImage::SetUpStates() rs.ScissorEnable=FALSE; rs.MultisampleEnable=FALSE; rs.AntialiasedLineEnable=FALSE; - wiRenderer::graphicsDevice->CreateRasterizerState(&rs,&rasterizerState); + wiRenderer::GetDevice()->CreateRasterizerState(&rs,&rasterizerState); @@ -109,7 +109,7 @@ void wiImage::SetUpStates() dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; // Create the depth stencil state. - wiRenderer::graphicsDevice->CreateDepthStencilState(&dsd, &depthStencilStateLess); + wiRenderer::GetDevice()->CreateDepthStencilState(&dsd, &depthStencilStateLess); dsd.DepthEnable = false; @@ -128,10 +128,10 @@ void wiImage::SetUpStates() dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; // Create the depth stencil state. - wiRenderer::graphicsDevice->CreateDepthStencilState(&dsd, &depthStencilStateGreater); + wiRenderer::GetDevice()->CreateDepthStencilState(&dsd, &depthStencilStateGreater); dsd.StencilEnable = false; - wiRenderer::graphicsDevice->CreateDepthStencilState(&dsd, &depthNoStencilState); + wiRenderer::GetDevice()->CreateDepthStencilState(&dsd, &depthNoStencilState); BlendDesc bd; @@ -145,7 +145,7 @@ void wiImage::SetUpStates() bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; bd.IndependentBlendEnable=true; - wiRenderer::graphicsDevice->CreateBlendState(&bd,&blendState); + wiRenderer::GetDevice()->CreateBlendState(&bd,&blendState); ZeroMemory(&bd, sizeof(bd)); bd.RenderTarget[0].BlendEnable=false; @@ -157,7 +157,7 @@ void wiImage::SetUpStates() bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; //bd.IndependentBlendEnable=true; - wiRenderer::graphicsDevice->CreateBlendState(&bd,&blendStateNoBlend); + wiRenderer::GetDevice()->CreateBlendState(&bd,&blendStateNoBlend); ZeroMemory(&bd, sizeof(bd)); bd.RenderTarget[0].BlendEnable=true; @@ -169,7 +169,7 @@ void wiImage::SetUpStates() bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; //bd.IndependentBlendEnable=true; - wiRenderer::graphicsDevice->CreateBlendState(&bd,&blendStateAdd); + wiRenderer::GetDevice()->CreateBlendState(&bd,&blendStateAdd); ZeroMemory(&bd, sizeof(bd)); bd.RenderTarget[0].BlendEnable=true; @@ -181,19 +181,19 @@ void wiImage::SetUpStates() bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_MAX; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; //bd.IndependentBlendEnable=true; - wiRenderer::graphicsDevice->CreateBlendState(&bd,&blendStateAvg); + wiRenderer::GetDevice()->CreateBlendState(&bd,&blendStateAvg); } void wiImage::BindPersistentState(GRAPHICSTHREAD threadID) { - wiRenderer::graphicsDevice->LOCK(); + wiRenderer::GetDevice()->LOCK(); - wiRenderer::graphicsDevice->BindConstantBufferVS(constantBuffer, CB_GETBINDSLOT(ImageCB), threadID); - wiRenderer::graphicsDevice->BindConstantBufferPS(constantBuffer, CB_GETBINDSLOT(ImageCB), threadID); + wiRenderer::GetDevice()->BindConstantBufferVS(constantBuffer, CB_GETBINDSLOT(ImageCB), threadID); + wiRenderer::GetDevice()->BindConstantBufferPS(constantBuffer, CB_GETBINDSLOT(ImageCB), threadID); - wiRenderer::graphicsDevice->BindConstantBufferPS(processCb, CB_GETBINDSLOT(PostProcessCB), threadID); + wiRenderer::GetDevice()->BindConstantBufferPS(processCb, CB_GETBINDSLOT(PostProcessCB), threadID); - wiRenderer::graphicsDevice->UNLOCK(); + wiRenderer::GetDevice()->UNLOCK(); } void wiImage::Draw(Texture2D* texture, const wiImageEffects& effects){ @@ -204,30 +204,30 @@ void wiImage::Draw(Texture2D* texture, const wiImageEffects& effects,GRAPHICSTHR bool fullScreenEffect = false; - wiRenderer::graphicsDevice->BindVertexLayout(nullptr, threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(nullptr, 0, 0, threadID); - wiRenderer::graphicsDevice->BindIndexBuffer(nullptr, threadID); - wiRenderer::graphicsDevice->BindPrimitiveTopology(PRIMITIVETOPOLOGY::TRIANGLESTRIP, threadID); - wiRenderer::graphicsDevice->BindRasterizerState(rasterizerState, threadID); + wiRenderer::GetDevice()->BindVertexLayout(nullptr, threadID); + wiRenderer::GetDevice()->BindVertexBuffer(nullptr, 0, 0, threadID); + wiRenderer::GetDevice()->BindIndexBuffer(nullptr, threadID); + wiRenderer::GetDevice()->BindPrimitiveTopology(PRIMITIVETOPOLOGY::TRIANGLESTRIP, threadID); + wiRenderer::GetDevice()->BindRasterizerState(rasterizerState, threadID); - wiRenderer::graphicsDevice->BindTexturePS(texture, TEXSLOT_ONDEMAND0, threadID); + wiRenderer::GetDevice()->BindTexturePS(texture, TEXSLOT_ONDEMAND0, threadID); if (effects.blendFlag == BLENDMODE_ALPHA) - wiRenderer::graphicsDevice->BindBlendState(blendState, threadID); + wiRenderer::GetDevice()->BindBlendState(blendState, threadID); else if (effects.blendFlag == BLENDMODE_ADDITIVE) - wiRenderer::graphicsDevice->BindBlendState(blendStateAdd, threadID); + wiRenderer::GetDevice()->BindBlendState(blendStateAdd, threadID); else if (effects.blendFlag == BLENDMODE_OPAQUE) - wiRenderer::graphicsDevice->BindBlendState(blendStateNoBlend, threadID); + wiRenderer::GetDevice()->BindBlendState(blendStateNoBlend, threadID); else if (effects.blendFlag == BLENDMODE_MAX) - wiRenderer::graphicsDevice->BindBlendState(blendStateAvg, threadID); + wiRenderer::GetDevice()->BindBlendState(blendStateAvg, threadID); else - wiRenderer::graphicsDevice->BindBlendState(blendState, threadID); + wiRenderer::GetDevice()->BindBlendState(blendState, threadID); if (effects.presentFullScreen) { - wiRenderer::graphicsDevice->BindVS(screenVS, threadID); - wiRenderer::graphicsDevice->BindPS(screenPS, threadID); - wiRenderer::graphicsDevice->Draw(3, threadID); + wiRenderer::GetDevice()->BindVS(screenVS, threadID); + wiRenderer::GetDevice()->BindPS(screenPS, threadID); + wiRenderer::GetDevice()->Draw(3, threadID); return; } @@ -237,13 +237,13 @@ void wiImage::Draw(Texture2D* texture, const wiImageEffects& effects,GRAPHICSTHR switch (effects.stencilComp) { case COMPARISON_LESS: - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencilStateLess, effects.stencilRef, threadID); + wiRenderer::GetDevice()->BindDepthStencilState(depthStencilStateLess, effects.stencilRef, threadID); break; case COMPARISON_GREATER: - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencilStateGreater, effects.stencilRef, threadID); + wiRenderer::GetDevice()->BindDepthStencilState(depthStencilStateGreater, effects.stencilRef, threadID); break; default: - wiRenderer::graphicsDevice->BindDepthStencilState(depthNoStencilState, effects.stencilRef, threadID); + wiRenderer::GetDevice()->BindDepthStencilState(depthNoStencilState, effects.stencilRef, threadID); break; } } @@ -251,10 +251,10 @@ void wiImage::Draw(Texture2D* texture, const wiImageEffects& effects,GRAPHICSTHR if(!effects.blur){ if(!effects.process.active && !effects.bloom.separate && !effects.sunPos.x && !effects.sunPos.y){ if(effects.typeFlag==SCREEN){ - (*cb).mViewProjection = XMMatrixTranspose(XMMatrixOrthographicLH((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight(), 0, 100)); - (*cb).mTrans = XMMatrixTranspose(XMMatrixTranslation(wiRenderer::GetScreenWidth() / 2 - effects.siz.x / 2, -wiRenderer::GetScreenHeight() / 2 + effects.siz.y / 2, 0) * XMMatrixRotationZ(effects.rotation) - * XMMatrixTranslation(-wiRenderer::GetScreenWidth() / 2 + effects.pos.x + effects.siz.x*0.5f, wiRenderer::GetScreenHeight() / 2 + effects.pos.y - effects.siz.y*0.5f, 0)); //AUTO ORIGIN CORRECTION APPLIED! NO FURTHER TRANSLATIONS NEEDED! - (*cb).mDimensions = XMFLOAT4((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight(), effects.siz.x, effects.siz.y); + (*cb).mViewProjection = XMMatrixTranspose(XMMatrixOrthographicLH((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight(), 0, 100)); + (*cb).mTrans = XMMatrixTranspose(XMMatrixTranslation(wiRenderer::GetDevice()->GetScreenWidth() / 2 - effects.siz.x / 2, -wiRenderer::GetDevice()->GetScreenHeight() / 2 + effects.siz.y / 2, 0) * XMMatrixRotationZ(effects.rotation) + * XMMatrixTranslation(-wiRenderer::GetDevice()->GetScreenWidth() / 2 + effects.pos.x + effects.siz.x*0.5f, wiRenderer::GetDevice()->GetScreenHeight() / 2 + effects.pos.y - effects.siz.y*0.5f, 0)); //AUTO ORIGIN CORRECTION APPLIED! NO FURTHER TRANSLATIONS NEEDED! + (*cb).mDimensions = XMFLOAT4((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight(), effects.siz.x, effects.siz.y); } else if(effects.typeFlag==WORLD){ (*cb).mViewProjection = XMMatrixTranspose( wiRenderer::getCamera()->GetView() * wiRenderer::getCamera()->GetProjection() ); @@ -300,38 +300,38 @@ void wiImage::Draw(Texture2D* texture, const wiImageEffects& effects,GRAPHICSTHR (*cb).mNormalmapSeparate = normalmapmode; (*cb).mMipLevel = effects.mipLevel; - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffer,cb,threadID); + wiRenderer::GetDevice()->UpdateBuffer(constantBuffer,cb,threadID); - wiRenderer::graphicsDevice->BindVS(vertexShader, threadID); - wiRenderer::graphicsDevice->BindPS(pixelShader, threadID); + wiRenderer::GetDevice()->BindVS(vertexShader, threadID); + wiRenderer::GetDevice()->BindPS(pixelShader, threadID); fullScreenEffect = false; } else if(!effects.sunPos.x && !effects.sunPos.y){ - wiRenderer::graphicsDevice->BindVS(screenVS, threadID); + wiRenderer::GetDevice()->BindVS(screenVS, threadID); fullScreenEffect = true; if(effects.process.outline) - wiRenderer::graphicsDevice->BindPS(outlinePS,threadID); + wiRenderer::GetDevice()->BindPS(outlinePS,threadID); else if(effects.process.motionBlur) - wiRenderer::graphicsDevice->BindPS(motionBlurPS,threadID); + wiRenderer::GetDevice()->BindPS(motionBlurPS,threadID); else if(effects.process.dofStrength) - wiRenderer::graphicsDevice->BindPS(dofPS,threadID); + wiRenderer::GetDevice()->BindPS(dofPS,threadID); else if(effects.process.fxaa) - wiRenderer::graphicsDevice->BindPS(fxaaPS,threadID); + wiRenderer::GetDevice()->BindPS(fxaaPS,threadID); else if(effects.process.ssao) - wiRenderer::graphicsDevice->BindPS(ssaoPS,threadID); + wiRenderer::GetDevice()->BindPS(ssaoPS,threadID); else if(effects.process.linDepth) - wiRenderer::graphicsDevice->BindPS(linDepthPS, threadID); + wiRenderer::GetDevice()->BindPS(linDepthPS, threadID); else if (effects.process.colorGrade) - wiRenderer::graphicsDevice->BindPS(colorGradePS, threadID); + wiRenderer::GetDevice()->BindPS(colorGradePS, threadID); else if (effects.process.ssr) - wiRenderer::graphicsDevice->BindPS(ssrPS, threadID); + wiRenderer::GetDevice()->BindPS(ssrPS, threadID); else if (effects.process.stereogram) - wiRenderer::graphicsDevice->BindPS(stereogramPS, threadID); + wiRenderer::GetDevice()->BindPS(stereogramPS, threadID); else if(effects.process.ssss.x + effects.process.ssss.y > 0) - wiRenderer::graphicsDevice->BindPS(ssssPS,threadID); + wiRenderer::GetDevice()->BindPS(ssssPS,threadID); else if(effects.bloom.separate) - wiRenderer::graphicsDevice->BindPS(bloomSeparatePS,threadID); + wiRenderer::GetDevice()->BindPS(bloomSeparatePS,threadID); else wiHelper::messageBox("Postprocess branch not implemented!"); @@ -344,11 +344,11 @@ void wiImage::Draw(Texture2D* texture, const wiImageEffects& effects,GRAPHICSTHR (*prcb).params1[2] = effects.bloom.saturation; (*prcb).params1[3] = effects.process.ssss.y; - wiRenderer::graphicsDevice->UpdateBuffer(processCb,prcb,threadID); + wiRenderer::GetDevice()->UpdateBuffer(processCb,prcb,threadID); } else{ - wiRenderer::graphicsDevice->BindVS(screenVS,threadID); - wiRenderer::graphicsDevice->BindPS(shaftPS,threadID); + wiRenderer::GetDevice()->BindVS(screenVS,threadID); + wiRenderer::GetDevice()->BindPS(shaftPS,threadID); fullScreenEffect = true; //Density|Weight|Decay|Exposure @@ -359,23 +359,23 @@ void wiImage::Draw(Texture2D* texture, const wiImageEffects& effects,GRAPHICSTHR (*prcb).params1[0] = effects.sunPos.x; (*prcb).params1[1] = effects.sunPos.y; - wiRenderer::graphicsDevice->UpdateBuffer(processCb,prcb,threadID); + wiRenderer::GetDevice()->UpdateBuffer(processCb,prcb,threadID); } - wiRenderer::graphicsDevice->BindTexturePS(effects.maskMap, TEXSLOT_ONDEMAND1, threadID); - wiRenderer::graphicsDevice->BindTexturePS(effects.distortionMap, TEXSLOT_ONDEMAND2, threadID); - wiRenderer::graphicsDevice->BindTexturePS(effects.refractionSource, TEXSLOT_ONDEMAND3, threadID); + wiRenderer::GetDevice()->BindTexturePS(effects.maskMap, TEXSLOT_ONDEMAND1, threadID); + wiRenderer::GetDevice()->BindTexturePS(effects.distortionMap, TEXSLOT_ONDEMAND2, threadID); + wiRenderer::GetDevice()->BindTexturePS(effects.refractionSource, TEXSLOT_ONDEMAND3, threadID); } else{ //BLUR - wiRenderer::graphicsDevice->BindVS(screenVS,threadID); + wiRenderer::GetDevice()->BindVS(screenVS,threadID); fullScreenEffect = true; if(effects.blurDir==0){ - wiRenderer::graphicsDevice->BindPS(blurHPS,threadID); - (*prcb).params1[3] = 1.0f / wiRenderer::GetScreenWidth(); + wiRenderer::GetDevice()->BindPS(blurHPS,threadID); + (*prcb).params1[3] = 1.0f / wiRenderer::GetDevice()->GetScreenWidth(); } else{ - wiRenderer::graphicsDevice->BindPS(blurVPS,threadID); - (*prcb).params1[3] = 1.0f / wiRenderer::GetScreenHeight(); + wiRenderer::GetDevice()->BindPS(blurVPS,threadID); + (*prcb).params1[3] = 1.0f / wiRenderer::GetDevice()->GetScreenHeight(); } static float weight0 = 1.0f; @@ -392,64 +392,64 @@ void wiImage::Draw(Texture2D* texture, const wiImageEffects& effects,GRAPHICSTHR (*prcb).params1[1] = effects.blur; (*prcb).params1[2] = effects.mipLevel; - wiRenderer::graphicsDevice->UpdateBuffer(processCb,prcb,threadID); + wiRenderer::GetDevice()->UpdateBuffer(processCb,prcb,threadID); } if(effects.quality==QUALITY_NEAREST){ if (effects.sampleFlag == SAMPLEMODE_MIRROR) - wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_POINT_MIRROR], SSLOT_ONDEMAND0, threadID); + wiRenderer::GetDevice()->BindSamplerPS(wiRenderer::samplers[SSLOT_POINT_MIRROR], SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_WRAP) - wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_POINT_WRAP], SSLOT_ONDEMAND0, threadID); + wiRenderer::GetDevice()->BindSamplerPS(wiRenderer::samplers[SSLOT_POINT_WRAP], SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_CLAMP) - wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, threadID); + wiRenderer::GetDevice()->BindSamplerPS(wiRenderer::samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, threadID); } else if(effects.quality==QUALITY_BILINEAR){ if (effects.sampleFlag == SAMPLEMODE_MIRROR) - wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_LINEAR_MIRROR], SSLOT_ONDEMAND0, threadID); + wiRenderer::GetDevice()->BindSamplerPS(wiRenderer::samplers[SSLOT_LINEAR_MIRROR], SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_WRAP) - wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_LINEAR_WRAP], SSLOT_ONDEMAND0, threadID); + wiRenderer::GetDevice()->BindSamplerPS(wiRenderer::samplers[SSLOT_LINEAR_WRAP], SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_CLAMP) - wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, threadID); + wiRenderer::GetDevice()->BindSamplerPS(wiRenderer::samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, threadID); } else if(effects.quality==QUALITY_ANISOTROPIC){ if (effects.sampleFlag == SAMPLEMODE_MIRROR) - wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_ANISO_MIRROR], SSLOT_ONDEMAND0, threadID); + wiRenderer::GetDevice()->BindSamplerPS(wiRenderer::samplers[SSLOT_ANISO_MIRROR], SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_WRAP) - wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_ANISO_WRAP], SSLOT_ONDEMAND0, threadID); + wiRenderer::GetDevice()->BindSamplerPS(wiRenderer::samplers[SSLOT_ANISO_WRAP], SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_CLAMP) - wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_ANISO_CLAMP], SSLOT_ONDEMAND0, threadID); + wiRenderer::GetDevice()->BindSamplerPS(wiRenderer::samplers[SSLOT_ANISO_CLAMP], SSLOT_ONDEMAND0, threadID); } - wiRenderer::graphicsDevice->Draw((fullScreenEffect ? 3 : 4), threadID); + wiRenderer::GetDevice()->Draw((fullScreenEffect ? 3 : 4), threadID); } void wiImage::DrawDeferred(Texture2D* texture , Texture2D* depth, Texture2D* lightmap, Texture2D* normal , Texture2D* ao, GRAPHICSTHREAD threadID, int stencilRef){ - wiRenderer::graphicsDevice->BindPrimitiveTopology(PRIMITIVETOPOLOGY::TRIANGLELIST,threadID); - wiRenderer::graphicsDevice->BindRasterizerState(rasterizerState,threadID); - wiRenderer::graphicsDevice->BindDepthStencilState(depthNoStencilState,stencilRef,threadID); + wiRenderer::GetDevice()->BindPrimitiveTopology(PRIMITIVETOPOLOGY::TRIANGLELIST,threadID); + wiRenderer::GetDevice()->BindRasterizerState(rasterizerState,threadID); + wiRenderer::GetDevice()->BindDepthStencilState(depthNoStencilState,stencilRef,threadID); - wiRenderer::graphicsDevice->BindVertexLayout(nullptr, threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(nullptr, 0, 0, threadID); - wiRenderer::graphicsDevice->BindIndexBuffer(nullptr, threadID); + wiRenderer::GetDevice()->BindVertexLayout(nullptr, threadID); + wiRenderer::GetDevice()->BindVertexBuffer(nullptr, 0, 0, threadID); + wiRenderer::GetDevice()->BindIndexBuffer(nullptr, threadID); - wiRenderer::graphicsDevice->BindVS(screenVS,threadID); - wiRenderer::graphicsDevice->BindPS(deferredPS,threadID); + wiRenderer::GetDevice()->BindVS(screenVS,threadID); + wiRenderer::GetDevice()->BindPS(deferredPS,threadID); - //wiRenderer::graphicsDevice->BindTexturePS(depth,0,threadID); - //wiRenderer::graphicsDevice->BindTexturePS(normal,1,threadID); - //wiRenderer::graphicsDevice->BindTexturePS(texture,6,threadID); - wiRenderer::graphicsDevice->BindTexturePS(lightmap,TEXSLOT_ONDEMAND0,threadID); - wiRenderer::graphicsDevice->BindTexturePS(ao,TEXSLOT_ONDEMAND1,threadID); + //wiRenderer::GetDevice()->BindTexturePS(depth,0,threadID); + //wiRenderer::GetDevice()->BindTexturePS(normal,1,threadID); + //wiRenderer::GetDevice()->BindTexturePS(texture,6,threadID); + wiRenderer::GetDevice()->BindTexturePS(lightmap,TEXSLOT_ONDEMAND0,threadID); + wiRenderer::GetDevice()->BindTexturePS(ao,TEXSLOT_ONDEMAND1,threadID); - wiRenderer::graphicsDevice->BindBlendState(blendStateNoBlend,threadID); + wiRenderer::GetDevice()->BindBlendState(blendStateNoBlend,threadID); - wiRenderer::graphicsDevice->Draw(3,threadID); + wiRenderer::GetDevice()->Draw(3,threadID); } diff --git a/WickedEngine/wiLensFlare.cpp b/WickedEngine/wiLensFlare.cpp index e230b1080..5cbb0dc7d 100644 --- a/WickedEngine/wiLensFlare.cpp +++ b/WickedEngine/wiLensFlare.cpp @@ -34,40 +34,40 @@ void wiLensFlare::Draw(GRAPHICSTHREAD threadID, const XMVECTOR& lightPos, vector if(!rims.empty()){ - wiRenderer::graphicsDevice->BindPrimitiveTopology(POINTLIST,threadID); - wiRenderer::graphicsDevice->BindVertexLayout(inputLayout,threadID); - wiRenderer::graphicsDevice->BindPS(pixelShader,threadID); - wiRenderer::graphicsDevice->BindVS(vertexShader,threadID); - wiRenderer::graphicsDevice->BindGS(geometryShader,threadID); + wiRenderer::GetDevice()->BindPrimitiveTopology(POINTLIST,threadID); + wiRenderer::GetDevice()->BindVertexLayout(inputLayout,threadID); + wiRenderer::GetDevice()->BindPS(pixelShader,threadID); + wiRenderer::GetDevice()->BindVS(vertexShader,threadID); + wiRenderer::GetDevice()->BindGS(geometryShader,threadID); static thread_local ConstantBuffer* cb = new ConstantBuffer; - (*cb).mSunPos = lightPos / XMVectorSet((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight(), 1, 1); - (*cb).mScreen = XMFLOAT4((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight(), 0, 0); + (*cb).mSunPos = lightPos / XMVectorSet((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight(), 1, 1); + (*cb).mScreen = XMFLOAT4((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight(), 0, 0); - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffer,cb,threadID); - wiRenderer::graphicsDevice->BindConstantBufferGS(constantBuffer, CB_GETBINDSLOT(ConstantBuffer),threadID); + wiRenderer::GetDevice()->UpdateBuffer(constantBuffer,cb,threadID); + wiRenderer::GetDevice()->BindConstantBufferGS(constantBuffer, CB_GETBINDSLOT(ConstantBuffer),threadID); - wiRenderer::graphicsDevice->BindRasterizerState(rasterizerState,threadID); - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencilState,1,threadID); - wiRenderer::graphicsDevice->BindBlendState(blendState,threadID); + wiRenderer::GetDevice()->BindRasterizerState(rasterizerState,threadID); + wiRenderer::GetDevice()->BindDepthStencilState(depthStencilState,1,threadID); + wiRenderer::GetDevice()->BindBlendState(blendState,threadID); - //wiRenderer::graphicsDevice->BindTextureGS(depthMap,0,threadID); + //wiRenderer::GetDevice()->BindTextureGS(depthMap,0,threadID); int i=0; for(Texture2D* x : rims){ if(x!=nullptr){ - wiRenderer::graphicsDevice->BindTexturePS(x, TEXSLOT_ONDEMAND0 + i, threadID); - wiRenderer::graphicsDevice->BindTextureGS(x, TEXSLOT_ONDEMAND0 + i, threadID); + wiRenderer::GetDevice()->BindTexturePS(x, TEXSLOT_ONDEMAND0 + i, threadID); + wiRenderer::GetDevice()->BindTextureGS(x, TEXSLOT_ONDEMAND0 + i, threadID); i++; } } - wiRenderer::graphicsDevice->Draw(i,threadID); + wiRenderer::GetDevice()->Draw(i,threadID); - wiRenderer::graphicsDevice->BindGS(nullptr,threadID); + wiRenderer::GetDevice()->BindGS(nullptr,threadID); } } @@ -98,7 +98,7 @@ void wiLensFlare::SetUpCB() bd.ByteWidth = sizeof(ConstantBuffer); bd.BindFlags = BIND_CONSTANT_BUFFER; bd.CPUAccessFlags = CPU_ACCESS_WRITE; - wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &constantBuffer ); + wiRenderer::GetDevice()->CreateBuffer( &bd, NULL, &constantBuffer ); } void wiLensFlare::SetUpStates() @@ -114,7 +114,7 @@ void wiLensFlare::SetUpStates() rs.ScissorEnable=false; rs.MultisampleEnable=false; rs.AntialiasedLineEnable=false; - wiRenderer::graphicsDevice->CreateRasterizerState(&rs,&rasterizerState); + wiRenderer::GetDevice()->CreateRasterizerState(&rs,&rasterizerState); @@ -142,7 +142,7 @@ void wiLensFlare::SetUpStates() dsd.BackFace.StencilFunc = COMPARISON_ALWAYS; // Create the depth stencil state. - wiRenderer::graphicsDevice->CreateDepthStencilState(&dsd, &depthStencilState); + wiRenderer::GetDevice()->CreateDepthStencilState(&dsd, &depthStencilState); @@ -156,5 +156,5 @@ void wiLensFlare::SetUpStates() bd.RenderTarget[0].DestBlendAlpha = BLEND_ZERO; bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; - wiRenderer::graphicsDevice->CreateBlendState(&bd,&blendState); + wiRenderer::GetDevice()->CreateBlendState(&bd,&blendState); } diff --git a/WickedEngine/wiLines.cpp b/WickedEngine/wiLines.cpp index c0004dd5a..e2a8ee7ff 100644 --- a/WickedEngine/wiLines.cpp +++ b/WickedEngine/wiLines.cpp @@ -42,7 +42,7 @@ Lines::Lines(const XMFLOAT3& a, const XMFLOAT3& b, const XMFLOAT4& c) SubresourceData InitData; ZeroMemory( &InitData, sizeof(InitData) ); InitData.pSysMem = verts; - wiRenderer::graphicsDevice->CreateBuffer( &bd, &InitData, &vertexBuffer ); + wiRenderer::GetDevice()->CreateBuffer( &bd, &InitData, &vertexBuffer ); if(verts){ delete[](verts); @@ -78,7 +78,7 @@ void Lines::SetUpVertices() SubresourceData InitData; ZeroMemory( &InitData, sizeof(InitData) ); InitData.pSysMem = verts; - wiRenderer::graphicsDevice->CreateBuffer( &bd, &InitData, &vertexBuffer ); + wiRenderer::GetDevice()->CreateBuffer( &bd, &InitData, &vertexBuffer ); if(verts){ delete[](verts); diff --git a/WickedEngine/wiLoader.cpp b/WickedEngine/wiLoader.cpp index 7eca6f6d2..594675277 100644 --- a/WickedEngine/wiLoader.cpp +++ b/WickedEngine/wiLoader.cpp @@ -485,7 +485,7 @@ void LoadWiObjects(const string& directory, const string& name, const string& id // bd.ByteWidth = sizeof( RibbonVertex ) * 1000; // bd.BindFlags = BIND_VERTEX_BUFFER; // bd.CPUAccessFlags = CPU_ACCESS_WRITE; - // wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &objects[i]->trailBuff ); + // wiRenderer::GetDevice()->CreateBuffer( &bd, NULL, &objects[i]->trailBuff ); // objects[i]->trailTex = wiTextureHelper::getInstance()->getTransparent(); // objects[i]->trailDistortTex = wiTextureHelper::getInstance()->getNormalMapDefault(); // } @@ -951,7 +951,7 @@ void LoadWiLights(const string& directory, const string& name, const string& ide // bd.ByteWidth = sizeof( Instance )*iMesh->usedBy.size(); // bd.BindFlags = BIND_VERTEX_BUFFER; // bd.CPUAccessFlags = CPU_ACCESS_WRITE; - // wiRenderer::graphicsDevice->CreateBuffer( &bd, 0, &iMesh->meshInstanceBuffer ); + // wiRenderer::GetDevice()->CreateBuffer( &bd, 0, &iMesh->meshInstanceBuffer ); //} } file.close(); @@ -1682,7 +1682,7 @@ void Mesh::CreateBuffers(Object* object) { bd.ByteWidth = sizeof(Instance) * 2; bd.BindFlags = BIND_VERTEX_BUFFER; bd.CPUAccessFlags = CPU_ACCESS_WRITE; - wiRenderer::graphicsDevice->CreateBuffer(&bd, 0, &meshInstanceBuffer); + wiRenderer::GetDevice()->CreateBuffer(&bd, 0, &meshInstanceBuffer); } @@ -1713,7 +1713,7 @@ void Mesh::CreateBuffers(Object* object) { InitData.pSysMem = vertices.data(); else InitData.pSysMem = skinnedVertices.data(); - wiRenderer::graphicsDevice->CreateBuffer(&bd, &InitData, &meshVertBuff); + wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &meshVertBuff); ZeroMemory(&bd, sizeof(bd)); @@ -1723,7 +1723,7 @@ void Mesh::CreateBuffers(Object* object) { bd.CPUAccessFlags = 0; ZeroMemory(&InitData, sizeof(InitData)); InitData.pSysMem = indices.data(); - wiRenderer::graphicsDevice->CreateBuffer(&bd, &InitData, &meshIndexBuff); + wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &meshIndexBuff); if (renderable) { @@ -1735,7 +1735,7 @@ void Mesh::CreateBuffers(Object* object) { bd.BindFlags = BIND_STREAM_OUTPUT | BIND_VERTEX_BUFFER; bd.CPUAccessFlags = 0; bd.StructureByteStride = 0; - wiRenderer::graphicsDevice->CreateBuffer(&bd, NULL, &sOutBuffer); + wiRenderer::GetDevice()->CreateBuffer(&bd, NULL, &sOutBuffer); } //PHYSICALMAPPING @@ -1783,7 +1783,7 @@ void Mesh::AddRenderableInstance(const Instance& instance, int numerator) } void Mesh::UpdateRenderableInstances(int count, GRAPHICSTHREAD threadID) { - wiRenderer::graphicsDevice->UpdateBuffer(meshInstanceBuffer, instances.data(), threadID, sizeof(Instance)*count); + wiRenderer::GetDevice()->UpdateBuffer(meshInstanceBuffer, instances.data(), threadID, sizeof(Instance)*count); } #pragma endregion @@ -1932,7 +1932,7 @@ void Model::LoadFromDisk(const string& dir, const string& name, const string& id bd.ByteWidth = sizeof(RibbonVertex) * 1000; bd.BindFlags = BIND_VERTEX_BUFFER; bd.CPUAccessFlags = CPU_ACCESS_WRITE; - wiRenderer::graphicsDevice->CreateBuffer(&bd, NULL, &x->trailBuff); + wiRenderer::GetDevice()->CreateBuffer(&bd, NULL, &x->trailBuff); x->trailTex = wiTextureHelper::getInstance()->getTransparent(); x->trailDistortTex = wiTextureHelper::getInstance()->getNormalMapDefault(); } @@ -2171,7 +2171,7 @@ void HitSphere::SetUpStatic() SubresourceData InitData; ZeroMemory( &InitData, sizeof(InitData) ); InitData.pSysMem = verts.data(); - wiRenderer::graphicsDevice->CreateBuffer( &bd, &InitData, &vertexBuffer ); + wiRenderer::GetDevice()->CreateBuffer( &bd, &InitData, &vertexBuffer ); } void HitSphere::CleanUpStatic() { @@ -3001,10 +3001,10 @@ void Light::SetUp() float lerp1 = 0.12f; float lerp2 = 0.016f; XMVECTOR a0, a, b0, b; - a0 = XMVector3Unproject(XMVectorSet(0, (float)wiRenderer::GetScreenHeight(), 0, 1), 0, 0, (float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight(), 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); - a = XMVector3Unproject(XMVectorSet(0, (float)wiRenderer::GetScreenHeight(), 1, 1), 0, 0, (float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight(), 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); - b0 = XMVector3Unproject(XMVectorSet((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight(), 0, 1), 0, 0, (float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight(), 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); - b = XMVector3Unproject(XMVectorSet((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight(), 1, 1), 0, 0, (float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight(), 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); + a0 = XMVector3Unproject(XMVectorSet(0, (float)wiRenderer::GetDevice()->GetScreenHeight(), 0, 1), 0, 0, (float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight(), 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); + a = XMVector3Unproject(XMVectorSet(0, (float)wiRenderer::GetDevice()->GetScreenHeight(), 1, 1), 0, 0, (float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight(), 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); + b0 = XMVector3Unproject(XMVectorSet((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight(), 0, 1), 0, 0, (float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight(), 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); + b = XMVector3Unproject(XMVectorSet((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight(), 1, 1), 0, 0, (float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight(), 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); float size = XMVectorGetX(XMVector3Length(XMVectorSubtract(XMVectorLerp(b0, b, lerp), XMVectorLerp(a0, a, lerp)))); float size1 = XMVectorGetX(XMVector3Length(XMVectorSubtract(XMVectorLerp(b0, b, lerp1), XMVectorLerp(a0, a, lerp1)))); float size2 = XMVectorGetX(XMVector3Length(XMVectorSubtract(XMVectorLerp(b0, b, lerp2), XMVectorLerp(a0, a, lerp2)))); @@ -3042,8 +3042,8 @@ void Light::UpdateLight() float lerp1 = 0.12f;//second slice distance from cam (percentage) float lerp2 = 0.016f;//first slice distance from cam (percentage) XMVECTOR c, d, e, e1, e2; - c = XMVector3Unproject(XMVectorSet((float)wiRenderer::GetScreenWidth() * 0.5f, (float)wiRenderer::GetScreenHeight() * 0.5f, 1, 1), 0, 0, (float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight(), 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); - d = XMVector3Unproject(XMVectorSet((float)wiRenderer::GetScreenWidth() * 0.5f, (float)wiRenderer::GetScreenHeight() * 0.5f, 0, 1), 0, 0, (float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight(), 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); + c = XMVector3Unproject(XMVectorSet((float)wiRenderer::GetDevice()->GetScreenWidth() * 0.5f, (float)wiRenderer::GetDevice()->GetScreenHeight() * 0.5f, 1, 1), 0, 0, (float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight(), 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); + d = XMVector3Unproject(XMVectorSet((float)wiRenderer::GetDevice()->GetScreenWidth() * 0.5f, (float)wiRenderer::GetDevice()->GetScreenHeight() * 0.5f, 0, 1), 0, 0, (float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight(), 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); if (!shadowCam.empty()) { diff --git a/WickedEngine/wiRenderTarget.cpp b/WickedEngine/wiRenderTarget.cpp index 96d1fd906..799de4fcd 100644 --- a/WickedEngine/wiRenderTarget.cpp +++ b/WickedEngine/wiRenderTarget.cpp @@ -82,13 +82,13 @@ void wiRenderTarget::Initialize(UINT width, UINT height, int numViews, bool hasD //shaderResourceViewDesc.mipLevels = -1; //for(int i=0;iCreateTexture2D(&textureDesc, nullptr, &texture2D[i]); - // wiRenderer::graphicsDevice->CreateRenderTargetView(texture2D[i], &renderTargetViewDesc, &renderTarget[i]); - // wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D[i], &shaderResourceViewDesc, &shaderResource[i]); + // wiRenderer::GetDevice()->CreateTexture2D(&textureDesc, nullptr, &texture2D[i]); + // wiRenderer::GetDevice()->CreateRenderTargetView(texture2D[i], &renderTargetViewDesc, &renderTarget[i]); + // wiRenderer::GetDevice()->CreateShaderResourceView(texture2D[i], &shaderResourceViewDesc, &shaderResource[i]); //} for (int i = 0; i < numViews; ++i) { - wiRenderer::graphicsDevice->CreateTexture2D(&textureDesc, nullptr, &renderTargets[i]); + wiRenderer::GetDevice()->CreateTexture2D(&textureDesc, nullptr, &renderTargets[i]); } viewPort.Width = (FLOAT)width; @@ -151,14 +151,14 @@ void wiRenderTarget::InitializeCube(UINT size, int numViews, bool hasDepth, DXGI //shaderResourceViewDesc.mipLevels = -1; //for(int i=0;iCreateTexture2D(&textureDesc, NULL, &texture2D[i]); - // wiRenderer::graphicsDevice->CreateRenderTargetView(texture2D[i], &renderTargetViewDesc, &renderTarget[i]); - // wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D[i], &shaderResourceViewDesc, &shaderResource[0]); + // wiRenderer::GetDevice()->CreateTexture2D(&textureDesc, NULL, &texture2D[i]); + // wiRenderer::GetDevice()->CreateRenderTargetView(texture2D[i], &renderTargetViewDesc, &renderTarget[i]); + // wiRenderer::GetDevice()->CreateShaderResourceView(texture2D[i], &shaderResourceViewDesc, &shaderResource[0]); //} for (int i = 0; i < numViews; ++i) { - wiRenderer::graphicsDevice->CreateTextureCube(&textureDesc, nullptr, &renderTargets_Cube[i]); + wiRenderer::GetDevice()->CreateTextureCube(&textureDesc, nullptr, &renderTargets_Cube[i]); } viewPort.Width = (FLOAT)size; @@ -187,7 +187,7 @@ void wiRenderTarget::Activate(GRAPHICSTHREAD threadID, float r, float g, float b Set(threadID); float ClearColor[4] = { r, g, b, a }; for(int i=0;iClearRenderTarget(GetTexture(i), ClearColor); + wiRenderer::GetDevice()->ClearRenderTarget(GetTexture(i), ClearColor); if(depth) depth->Clear(threadID); } void wiRenderTarget::Activate(GRAPHICSTHREAD threadID, wiDepthTarget* getDepth, float r, float g, float b, float a) @@ -195,7 +195,7 @@ void wiRenderTarget::Activate(GRAPHICSTHREAD threadID, wiDepthTarget* getDepth, Set(threadID,getDepth); float ClearColor[4] = { r, g, b, a }; for(int i=0;iClearRenderTarget(GetTexture(i), ClearColor); + wiRenderer::GetDevice()->ClearRenderTarget(GetTexture(i), ClearColor); } void wiRenderTarget::Activate(GRAPHICSTHREAD threadID, wiDepthTarget* getDepth) { @@ -203,18 +203,18 @@ void wiRenderTarget::Activate(GRAPHICSTHREAD threadID, wiDepthTarget* getDepth) } void wiRenderTarget::Deactivate(GRAPHICSTHREAD threadID) { - wiRenderer::graphicsDevice->BindRenderTargets(0, nullptr, nullptr); + wiRenderer::GetDevice()->BindRenderTargets(0, nullptr, nullptr); } void wiRenderTarget::Set(GRAPHICSTHREAD threadID) { - wiRenderer::graphicsDevice->BindViewports(1, &viewPort); - wiRenderer::graphicsDevice->BindRenderTargets(numViews, (isCube ? (Texture2D**)renderTargets_Cube.data() : renderTargets.data()), (depth ? depth->GetTexture() : nullptr)); + wiRenderer::GetDevice()->BindViewports(1, &viewPort); + wiRenderer::GetDevice()->BindRenderTargets(numViews, (isCube ? (Texture2D**)renderTargets_Cube.data() : renderTargets.data()), (depth ? depth->GetTexture() : nullptr)); } void wiRenderTarget::Set(GRAPHICSTHREAD threadID, wiDepthTarget* getDepth) { depth = getDepth; - wiRenderer::graphicsDevice->BindViewports(1, &viewPort); - wiRenderer::graphicsDevice->BindRenderTargets(numViews, (isCube ? (Texture2D**)renderTargets_Cube.data() : renderTargets.data()), (depth ? depth->GetTexture() : nullptr)); + wiRenderer::GetDevice()->BindViewports(1, &viewPort); + wiRenderer::GetDevice()->BindRenderTargets(numViews, (isCube ? (Texture2D**)renderTargets_Cube.data() : renderTargets.data()), (depth ? depth->GetTexture() : nullptr)); } //void wiRenderTarget::Retarget(Texture2D* resource) //{ diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 853d6a1d2..23d09c218 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -25,7 +25,6 @@ #pragma region STATICS GraphicsDevice* wiRenderer::graphicsDevice = nullptr; - Sampler wiRenderer::samplers[SSLOT_COUNT]; BufferResource wiRenderer::constantBuffers[CBTYPE_LAST]; @@ -39,7 +38,7 @@ DepthStencilState wiRenderer::depthStencils[DSSTYPE_LAST]; VertexLayout wiRenderer::vertexLayouts[VLTYPE_LAST]; BlendState wiRenderer::blendStates[BSTYPE_LAST]; -int wiRenderer::SCREENWIDTH=1280,wiRenderer::SCREENHEIGHT=720,wiRenderer::SHADOWMAPRES=1024,wiRenderer::SOFTSHADOW=2 +int wiRenderer::SHADOWMAPRES=1024,wiRenderer::SOFTSHADOW=2 ,wiRenderer::POINTLIGHTSHADOW=2,wiRenderer::POINTLIGHTSHADOWRES=256, wiRenderer::SPOTLIGHTSHADOW=2, wiRenderer::SPOTLIGHTSHADOWRES=512; bool wiRenderer::HAIRPARTICLEENABLED=true,wiRenderer::EMITTERSENABLED=true; bool wiRenderer::wireRender = false, wiRenderer::debugSpheres = false, wiRenderer::debugBoneLines = false, wiRenderer::debugBoxes = false; @@ -79,26 +78,22 @@ wiRenderer::wiRenderer() } #ifndef WINSTORE_SUPPORT -HRESULT wiRenderer::InitDevice(HWND window, int screenW, int screenH, bool windowed) -#else -HRESULT wiRenderer::InitDevice(Windows::UI::Core::CoreWindow^ window) -#endif -{ - SCREENWIDTH = screenW; - SCREENHEIGHT = screenH; - - graphicsDevice = new GraphicsDevice_DX11(window, screenW, screenH, windowed); - - return (graphicsDevice != nullptr ? S_OK : E_FAIL); -} -void wiRenderer::DestroyDevice() +void wiRenderer::InitDevice(HWND window, int screenW, int screenH, bool windowed) { SAFE_DELETE(graphicsDevice); + graphicsDevice = new GraphicsDevice_DX11(window, screenW, screenH, windowed); } +#else +void wiRenderer::InitDevice(Windows::UI::Core::CoreWindow^ window) +{ + graphicsDevice = new GraphicsDevice_DX11(window); +} +#endif + void wiRenderer::Present(function drawToScreen1,function drawToScreen2,function drawToScreen3) { - graphicsDevice->PresentBegin(); + GetDevice()->PresentBegin(); if(drawToScreen1!=nullptr) drawToScreen1(); @@ -111,7 +106,7 @@ void wiRenderer::Present(function drawToScreen1,function drawToS wiFrameRate::Frame(); - graphicsDevice->PresentEnd(); + GetDevice()->PresentEnd(); *prevFrameCam = *cam; } @@ -183,11 +178,11 @@ void wiRenderer::SetUpStaticComponents() LoadWaterShaders(); LoadTessShaders(); - //cam = new Camera(SCREENWIDTH, SCREENHEIGHT, 0.1f, 800, XMVectorSet(0, 4, -4, 1)); + //cam = new Camera(GetDevice()->GetScreenWidth(), GetDevice()->GetScreenHeight(), 0.1f, 800, XMVectorSet(0, 4, -4, 1)); cam = new Camera(); - cam->SetUp(SCREENWIDTH, SCREENHEIGHT, 0.1f, 800); + cam->SetUp(GetDevice()->GetScreenWidth(), GetDevice()->GetScreenHeight(), 0.1f, 800); refCam = new Camera(); - refCam->SetUp(SCREENWIDTH, SCREENHEIGHT, 0.1f, 800); + refCam->SetUp(GetDevice()->GetScreenWidth(), GetDevice()->GetScreenHeight(), 0.1f, 800); prevFrameCam = new Camera; @@ -217,18 +212,18 @@ void wiRenderer::SetUpStaticComponents() normalMapRT.Initialize( - SCREENWIDTH - ,SCREENHEIGHT + GetDevice()->GetScreenWidth() + ,GetDevice()->GetScreenHeight() ,1,false,1,0,DXGI_FORMAT_R8G8B8A8_SNORM ); imagesRTAdd.Initialize( - SCREENWIDTH - ,SCREENHEIGHT + GetDevice()->GetScreenWidth() + ,GetDevice()->GetScreenHeight() ,1,false ); imagesRT.Initialize( - SCREENWIDTH - ,SCREENHEIGHT + GetDevice()->GetScreenWidth() + ,GetDevice()->GetScreenHeight() ,1,false ); @@ -302,6 +297,8 @@ void wiRenderer::CleanUpStatic() } if (physicsEngine) physicsEngine->CleanUp(); + + SAFE_DELETE(graphicsDevice); } void wiRenderer::CleanUpStaticTemp(){ @@ -499,48 +496,48 @@ void wiRenderer::LoadBuffers() //Persistent buffers... bd.ByteWidth = sizeof(WorldCB); - graphicsDevice->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_WORLD]); + GetDevice()->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_WORLD]); bd.ByteWidth = sizeof(FrameCB); - graphicsDevice->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_FRAME]); + GetDevice()->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_FRAME]); bd.ByteWidth = sizeof(CameraCB); - graphicsDevice->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_CAMERA]); + GetDevice()->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_CAMERA]); bd.ByteWidth = sizeof(MaterialCB); - graphicsDevice->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_MATERIAL]); + GetDevice()->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_MATERIAL]); bd.ByteWidth = sizeof(DirectionalLightCB); - graphicsDevice->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_DIRLIGHT]); + GetDevice()->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_DIRLIGHT]); bd.ByteWidth = sizeof(MiscCB); - graphicsDevice->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_MISC]); + GetDevice()->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_MISC]); bd.ByteWidth = sizeof(ShadowCB); - graphicsDevice->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_SHADOW]); + GetDevice()->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_SHADOW]); bd.ByteWidth = sizeof(APICB); - graphicsDevice->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_CLIPPLANE]); + GetDevice()->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_CLIPPLANE]); // On demand buffers... bd.ByteWidth = sizeof(PointLightCB); - graphicsDevice->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_POINTLIGHT]); + GetDevice()->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_POINTLIGHT]); bd.ByteWidth = sizeof(SpotLightCB); - graphicsDevice->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_SPOTLIGHT]); + GetDevice()->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_SPOTLIGHT]); bd.ByteWidth = sizeof(VolumeLightCB); - graphicsDevice->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_VOLUMELIGHT]); + GetDevice()->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_VOLUMELIGHT]); bd.ByteWidth = sizeof(DecalCB); - graphicsDevice->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_DECAL]); + GetDevice()->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_DECAL]); bd.ByteWidth = sizeof(CubeMapRenderCB); - graphicsDevice->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_CUBEMAPRENDER]); + GetDevice()->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_CUBEMAPRENDER]); bd.ByteWidth = sizeof(BoneCB); - graphicsDevice->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_BONEBUFFER]); + GetDevice()->CreateBuffer(&bd, NULL, &constantBuffers[CBTYPE_BONEBUFFER]); } @@ -710,7 +707,7 @@ void wiRenderer::ReloadShaders(const string& path) SHADERPATH = path; } - graphicsDevice->LOCK(); + GetDevice()->LOCK(); wiResourceManager::GetShaderManager()->CleanUp(); LoadBasicShaders(); @@ -726,7 +723,7 @@ void wiRenderer::ReloadShaders(const string& path) wiImage::LoadShaders(); wiLensFlare::LoadShaders(); - graphicsDevice->UNLOCK(); + GetDevice()->UNLOCK(); } @@ -746,57 +743,57 @@ void wiRenderer::SetUpStates() samplerDesc.BorderColor[3] = 0; samplerDesc.MinLOD = 0; samplerDesc.MaxLOD = FLOAT32_MAX; - graphicsDevice->CreateSamplerState(&samplerDesc, &samplers[SSLOT_LINEAR_MIRROR]); + GetDevice()->CreateSamplerState(&samplerDesc, &samplers[SSLOT_LINEAR_MIRROR]); samplerDesc.Filter = FILTER_MIN_MAG_LINEAR_MIP_POINT; samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP; samplerDesc.AddressV = TEXTURE_ADDRESS_CLAMP; samplerDesc.AddressW = TEXTURE_ADDRESS_CLAMP; - graphicsDevice->CreateSamplerState(&samplerDesc, &samplers[SSLOT_LINEAR_CLAMP]); + GetDevice()->CreateSamplerState(&samplerDesc, &samplers[SSLOT_LINEAR_CLAMP]); samplerDesc.Filter = FILTER_MIN_MAG_LINEAR_MIP_POINT; samplerDesc.AddressU = TEXTURE_ADDRESS_WRAP; samplerDesc.AddressV = TEXTURE_ADDRESS_WRAP; samplerDesc.AddressW = TEXTURE_ADDRESS_WRAP; - graphicsDevice->CreateSamplerState(&samplerDesc, &samplers[SSLOT_LINEAR_WRAP]); + GetDevice()->CreateSamplerState(&samplerDesc, &samplers[SSLOT_LINEAR_WRAP]); samplerDesc.Filter = FILTER_MIN_MAG_MIP_POINT; samplerDesc.AddressU = TEXTURE_ADDRESS_MIRROR; samplerDesc.AddressV = TEXTURE_ADDRESS_MIRROR; samplerDesc.AddressW = TEXTURE_ADDRESS_MIRROR; - graphicsDevice->CreateSamplerState(&samplerDesc, &samplers[SSLOT_POINT_MIRROR]); + GetDevice()->CreateSamplerState(&samplerDesc, &samplers[SSLOT_POINT_MIRROR]); samplerDesc.Filter = FILTER_MIN_MAG_MIP_POINT; samplerDesc.AddressU = TEXTURE_ADDRESS_WRAP; samplerDesc.AddressV = TEXTURE_ADDRESS_WRAP; samplerDesc.AddressW = TEXTURE_ADDRESS_WRAP; - graphicsDevice->CreateSamplerState(&samplerDesc, &samplers[SSLOT_POINT_WRAP]); + GetDevice()->CreateSamplerState(&samplerDesc, &samplers[SSLOT_POINT_WRAP]); samplerDesc.Filter = FILTER_MIN_MAG_MIP_POINT; samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP; samplerDesc.AddressV = TEXTURE_ADDRESS_CLAMP; samplerDesc.AddressW = TEXTURE_ADDRESS_CLAMP; - graphicsDevice->CreateSamplerState(&samplerDesc, &samplers[SSLOT_POINT_CLAMP]); + GetDevice()->CreateSamplerState(&samplerDesc, &samplers[SSLOT_POINT_CLAMP]); samplerDesc.Filter = FILTER_ANISOTROPIC; samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP; samplerDesc.AddressV = TEXTURE_ADDRESS_CLAMP; samplerDesc.AddressW = TEXTURE_ADDRESS_CLAMP; samplerDesc.MaxAnisotropy = 16; - graphicsDevice->CreateSamplerState(&samplerDesc, &samplers[SSLOT_ANISO_CLAMP]); + GetDevice()->CreateSamplerState(&samplerDesc, &samplers[SSLOT_ANISO_CLAMP]); samplerDesc.Filter = FILTER_ANISOTROPIC; samplerDesc.AddressU = TEXTURE_ADDRESS_WRAP; samplerDesc.AddressV = TEXTURE_ADDRESS_WRAP; samplerDesc.AddressW = TEXTURE_ADDRESS_WRAP; - graphicsDevice->CreateSamplerState(&samplerDesc, &samplers[SSLOT_ANISO_WRAP]); + GetDevice()->CreateSamplerState(&samplerDesc, &samplers[SSLOT_ANISO_WRAP]); samplerDesc.Filter = FILTER_ANISOTROPIC; samplerDesc.AddressU = TEXTURE_ADDRESS_MIRROR; samplerDesc.AddressV = TEXTURE_ADDRESS_MIRROR; samplerDesc.AddressW = TEXTURE_ADDRESS_MIRROR; - graphicsDevice->CreateSamplerState(&samplerDesc, &samplers[SSLOT_ANISO_MIRROR]); + GetDevice()->CreateSamplerState(&samplerDesc, &samplers[SSLOT_ANISO_MIRROR]); ZeroMemory( &samplerDesc, sizeof(SamplerDesc) ); samplerDesc.Filter = FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT; @@ -806,7 +803,7 @@ void wiRenderer::SetUpStates() samplerDesc.MipLODBias = 0.0f; samplerDesc.MaxAnisotropy = 16; samplerDesc.ComparisonFunc = COMPARISON_LESS_EQUAL; - graphicsDevice->CreateSamplerState(&samplerDesc, &samplers[SSLOT_CMP_DEPTH]); + GetDevice()->CreateSamplerState(&samplerDesc, &samplers[SSLOT_CMP_DEPTH]); RasterizerDesc rs; rs.FillMode=FILL_SOLID; @@ -819,7 +816,7 @@ void wiRenderer::SetUpStates() rs.ScissorEnable=false; rs.MultisampleEnable=false; rs.AntialiasedLineEnable=false; - graphicsDevice->CreateRasterizerState(&rs,&rasterizers[RSTYPE_FRONT]); + GetDevice()->CreateRasterizerState(&rs,&rasterizers[RSTYPE_FRONT]); rs.FillMode=FILL_SOLID; @@ -832,7 +829,7 @@ void wiRenderer::SetUpStates() rs.ScissorEnable=false; rs.MultisampleEnable=false; rs.AntialiasedLineEnable=false; - graphicsDevice->CreateRasterizerState(&rs,&rasterizers[RSTYPE_SHADOW]); + GetDevice()->CreateRasterizerState(&rs,&rasterizers[RSTYPE_SHADOW]); rs.FillMode=FILL_SOLID; rs.CullMode=CULL_NONE; @@ -844,7 +841,7 @@ void wiRenderer::SetUpStates() rs.ScissorEnable=false; rs.MultisampleEnable=false; rs.AntialiasedLineEnable=false; - graphicsDevice->CreateRasterizerState(&rs,&rasterizers[RSTYPE_SHADOW_DOUBLESIDED]); + GetDevice()->CreateRasterizerState(&rs,&rasterizers[RSTYPE_SHADOW_DOUBLESIDED]); rs.FillMode=FILL_WIREFRAME; rs.CullMode=CULL_BACK; @@ -856,7 +853,7 @@ void wiRenderer::SetUpStates() rs.ScissorEnable=false; rs.MultisampleEnable=false; rs.AntialiasedLineEnable=false; - graphicsDevice->CreateRasterizerState(&rs,&rasterizers[RSTYPE_WIRE]); + GetDevice()->CreateRasterizerState(&rs,&rasterizers[RSTYPE_WIRE]); rs.FillMode=FILL_SOLID; rs.CullMode=CULL_NONE; @@ -868,7 +865,7 @@ void wiRenderer::SetUpStates() rs.ScissorEnable=false; rs.MultisampleEnable=false; rs.AntialiasedLineEnable=false; - graphicsDevice->CreateRasterizerState(&rs,&rasterizers[RSTYPE_DOUBLESIDED]); + GetDevice()->CreateRasterizerState(&rs,&rasterizers[RSTYPE_DOUBLESIDED]); rs.FillMode=FILL_WIREFRAME; rs.CullMode=CULL_NONE; @@ -880,7 +877,7 @@ void wiRenderer::SetUpStates() rs.ScissorEnable=false; rs.MultisampleEnable=false; rs.AntialiasedLineEnable=false; - graphicsDevice->CreateRasterizerState(&rs,&rasterizers[RSTYPE_WIRE_DOUBLESIDED]); + GetDevice()->CreateRasterizerState(&rs,&rasterizers[RSTYPE_WIRE_DOUBLESIDED]); rs.FillMode=FILL_SOLID; rs.CullMode=CULL_FRONT; @@ -892,7 +889,7 @@ void wiRenderer::SetUpStates() rs.ScissorEnable=false; rs.MultisampleEnable=false; rs.AntialiasedLineEnable=false; - graphicsDevice->CreateRasterizerState(&rs,&rasterizers[RSTYPE_BACK]); + GetDevice()->CreateRasterizerState(&rs,&rasterizers[RSTYPE_BACK]); DepthStencilDesc dsd; dsd.DepthEnable = true; @@ -911,7 +908,7 @@ void wiRenderer::SetUpStates() dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; // Create the depth stencil state. - graphicsDevice->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_DEFAULT]); + GetDevice()->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_DEFAULT]); dsd.DepthWriteMask = DEPTH_WRITE_MASK_ZERO; @@ -928,7 +925,7 @@ void wiRenderer::SetUpStates() dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; // Create the depth stencil state. - graphicsDevice->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_STENCILREAD]); + GetDevice()->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_STENCILREAD]); dsd.DepthEnable = false; @@ -943,18 +940,18 @@ void wiRenderer::SetUpStates() dsd.BackFace.StencilPassOp = STENCIL_OP_KEEP; dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; - graphicsDevice->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_STENCILREAD_MATCH]); + GetDevice()->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_STENCILREAD_MATCH]); dsd.DepthEnable = true; dsd.StencilEnable = false; dsd.DepthWriteMask = DEPTH_WRITE_MASK_ZERO; dsd.DepthFunc = COMPARISON_LESS_EQUAL; - graphicsDevice->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_DEPTHREAD]); + GetDevice()->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_DEPTHREAD]); dsd.DepthEnable = false; dsd.StencilEnable=false; - graphicsDevice->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_XRAY]); + GetDevice()->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_XRAY]); BlendDesc bd; @@ -968,7 +965,7 @@ void wiRenderer::SetUpStates() bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; bd.AlphaToCoverageEnable=false; - graphicsDevice->CreateBlendState(&bd,&blendStates[BSTYPE_OPAQUE]); + GetDevice()->CreateBlendState(&bd,&blendStates[BSTYPE_OPAQUE]); bd.RenderTarget[0].SrcBlend = BLEND_SRC_ALPHA; bd.RenderTarget[0].DestBlend = BLEND_INV_SRC_ALPHA; @@ -979,7 +976,7 @@ void wiRenderer::SetUpStates() bd.RenderTarget[0].BlendEnable=true; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; bd.AlphaToCoverageEnable=false; - graphicsDevice->CreateBlendState(&bd,&blendStates[BSTYPE_TRANSPARENT]); + GetDevice()->CreateBlendState(&bd,&blendStates[BSTYPE_TRANSPARENT]); bd.RenderTarget[0].BlendEnable=true; @@ -991,63 +988,63 @@ void wiRenderer::SetUpStates() bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_MAX; bd.IndependentBlendEnable=true, bd.AlphaToCoverageEnable=false; - graphicsDevice->CreateBlendState(&bd,&blendStates[BSTYPE_ADDITIVE]); + GetDevice()->CreateBlendState(&bd,&blendStates[BSTYPE_ADDITIVE]); } void wiRenderer::BindPersistentState(GRAPHICSTHREAD threadID) { - graphicsDevice->LOCK(); + GetDevice()->LOCK(); for (int i = 0; i < SSLOT_COUNT; ++i) { if (samplers[i] == nullptr) continue; - graphicsDevice->BindSamplerPS(samplers[i], i, threadID); - graphicsDevice->BindSamplerVS(samplers[i], i, threadID); - graphicsDevice->BindSamplerGS(samplers[i], i, threadID); - graphicsDevice->BindSamplerDS(samplers[i], i, threadID); - graphicsDevice->BindSamplerHS(samplers[i], i, threadID); + GetDevice()->BindSamplerPS(samplers[i], i, threadID); + GetDevice()->BindSamplerVS(samplers[i], i, threadID); + GetDevice()->BindSamplerGS(samplers[i], i, threadID); + GetDevice()->BindSamplerDS(samplers[i], i, threadID); + GetDevice()->BindSamplerHS(samplers[i], i, threadID); } - graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); - graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); - graphicsDevice->BindConstantBufferGS(constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); - graphicsDevice->BindConstantBufferHS(constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); - graphicsDevice->BindConstantBufferDS(constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); + GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); + GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); + GetDevice()->BindConstantBufferGS(constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); + GetDevice()->BindConstantBufferHS(constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); + GetDevice()->BindConstantBufferDS(constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), threadID); - graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); - graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); - graphicsDevice->BindConstantBufferGS(constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); - graphicsDevice->BindConstantBufferHS(constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); - graphicsDevice->BindConstantBufferDS(constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); + GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); + GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); + GetDevice()->BindConstantBufferGS(constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); + GetDevice()->BindConstantBufferHS(constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); + GetDevice()->BindConstantBufferDS(constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); - graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); - graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); - graphicsDevice->BindConstantBufferGS(constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); - graphicsDevice->BindConstantBufferHS(constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); - graphicsDevice->BindConstantBufferDS(constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); + GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); + GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); + GetDevice()->BindConstantBufferGS(constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); + GetDevice()->BindConstantBufferHS(constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); + GetDevice()->BindConstantBufferDS(constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); - graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_MATERIAL], CB_GETBINDSLOT(MaterialCB), threadID); - graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_MATERIAL], CB_GETBINDSLOT(MaterialCB), threadID); - graphicsDevice->BindConstantBufferGS(constantBuffers[CBTYPE_MATERIAL], CB_GETBINDSLOT(MaterialCB), threadID); - graphicsDevice->BindConstantBufferHS(constantBuffers[CBTYPE_MATERIAL], CB_GETBINDSLOT(MaterialCB), threadID); - graphicsDevice->BindConstantBufferDS(constantBuffers[CBTYPE_MATERIAL], CB_GETBINDSLOT(MaterialCB), threadID); + GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_MATERIAL], CB_GETBINDSLOT(MaterialCB), threadID); + GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_MATERIAL], CB_GETBINDSLOT(MaterialCB), threadID); + GetDevice()->BindConstantBufferGS(constantBuffers[CBTYPE_MATERIAL], CB_GETBINDSLOT(MaterialCB), threadID); + GetDevice()->BindConstantBufferHS(constantBuffers[CBTYPE_MATERIAL], CB_GETBINDSLOT(MaterialCB), threadID); + GetDevice()->BindConstantBufferDS(constantBuffers[CBTYPE_MATERIAL], CB_GETBINDSLOT(MaterialCB), threadID); - graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_DIRLIGHT], CB_GETBINDSLOT(DirectionalLightCB), threadID); - graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_DIRLIGHT], CB_GETBINDSLOT(DirectionalLightCB), threadID); + GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_DIRLIGHT], CB_GETBINDSLOT(DirectionalLightCB), threadID); + GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_DIRLIGHT], CB_GETBINDSLOT(DirectionalLightCB), threadID); - graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); - graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); - graphicsDevice->BindConstantBufferGS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); - graphicsDevice->BindConstantBufferDS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); - graphicsDevice->BindConstantBufferHS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + GetDevice()->BindConstantBufferGS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + GetDevice()->BindConstantBufferDS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + GetDevice()->BindConstantBufferHS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); - graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_SHADOW], CB_GETBINDSLOT(ShadowCB), threadID); + GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_SHADOW], CB_GETBINDSLOT(ShadowCB), threadID); - graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_CLIPPLANE], CB_GETBINDSLOT(APICB), threadID); + GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_CLIPPLANE], CB_GETBINDSLOT(APICB), threadID); - graphicsDevice->UNLOCK(); + GetDevice()->UNLOCK(); } void wiRenderer::RebindPersistentState(GRAPHICSTHREAD threadID) { @@ -1274,13 +1271,13 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) if (!streamOutSetUp) { streamOutSetUp = true; - wiRenderer::graphicsDevice->BindPrimitiveTopology(POINTLIST, threadID); - wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_STREAMOUT], threadID); - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_STREAMOUT], threadID); - wiRenderer::graphicsDevice->BindGS(geometryShaders[GSTYPE_STREAMOUT], threadID); - wiRenderer::graphicsDevice->BindPS(nullptr, threadID); - wiRenderer::graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_BONEBUFFER], CB_GETBINDSLOT(BoneCB), threadID); - wiRenderer::graphicsDevice->BindConstantBufferGS(constantBuffers[CBTYPE_BONEBUFFER], CB_GETBINDSLOT(BoneCB), threadID); + GetDevice()->BindPrimitiveTopology(POINTLIST, threadID); + GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_STREAMOUT], threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_STREAMOUT], threadID); + GetDevice()->BindGS(geometryShaders[GSTYPE_STREAMOUT], threadID); + GetDevice()->BindPS(nullptr, threadID); + GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_BONEBUFFER], CB_GETBINDSLOT(BoneCB), threadID); + GetDevice()->BindConstantBufferGS(constantBuffers[CBTYPE_BONEBUFFER], CB_GETBINDSLOT(BoneCB), threadID); } // Upload bones for skinning to shader @@ -1289,13 +1286,13 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) bonebuf->pose[k] = XMMatrixTranspose(XMLoadFloat4x4(&mesh->armature->boneCollection[k]->boneRelativity)); bonebuf->prev[k] = XMMatrixTranspose(XMLoadFloat4x4(&mesh->armature->boneCollection[k]->boneRelativityPrev)); } - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_BONEBUFFER], bonebuf, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_BONEBUFFER], bonebuf, threadID); // Do the skinning - wiRenderer::graphicsDevice->BindVertexBuffer(mesh->meshVertBuff, 0, sizeof(SkinnedVertex), threadID); - wiRenderer::graphicsDevice->BindStreamOutTarget(mesh->sOutBuffer, threadID); - wiRenderer::graphicsDevice->Draw(mesh->vertices.size(), threadID); + GetDevice()->BindVertexBuffer(mesh->meshVertBuff, 0, sizeof(SkinnedVertex), threadID); + GetDevice()->BindStreamOutTarget(mesh->sOutBuffer, threadID); + GetDevice()->Draw(mesh->vertices.size(), threadID); #else // Doing skinning on the CPU for (int vi = 0; vi < mesh->skinnedVertices.size(); ++vi) @@ -1312,7 +1309,7 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) if (mesh->softBody || mesh->hasArmature()) #endif { - wiRenderer::graphicsDevice->UpdateBuffer(mesh->meshVertBuff, mesh->skinnedVertices.data(), threadID, sizeof(Vertex)*mesh->skinnedVertices.size()); + GetDevice()->UpdateBuffer(mesh->meshVertBuff, mesh->skinnedVertices.data(), threadID, sizeof(Vertex)*mesh->skinnedVertices.size()); } } } @@ -1321,9 +1318,9 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) if (streamOutSetUp) { // Unload skinning shader - wiRenderer::graphicsDevice->BindGS(nullptr, threadID); - wiRenderer::graphicsDevice->BindVS(nullptr, threadID); - wiRenderer::graphicsDevice->BindStreamOutTarget(nullptr, threadID); + GetDevice()->BindGS(nullptr, threadID); + GetDevice()->BindVS(nullptr, threadID); + GetDevice()->BindStreamOutTarget(nullptr, threadID); } #endif @@ -1426,26 +1423,26 @@ void wiRenderer::DrawDebugSpheres(Camera* camera, GRAPHICSTHREAD threadID) void wiRenderer::DrawDebugBoneLines(Camera* camera, GRAPHICSTHREAD threadID) { if(debugBoneLines){ - wiRenderer::graphicsDevice->BindPrimitiveTopology(LINELIST,threadID); - wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_LINE],threadID); + GetDevice()->BindPrimitiveTopology(LINELIST,threadID); + GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_LINE],threadID); - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_SHADOW],threadID); - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_XRAY],STENCILREF_EMPTY,threadID); - wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_SHADOW],threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_XRAY],STENCILREF_EMPTY,threadID); + GetDevice()->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_LINE],threadID); - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_LINE],threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_LINE],threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_LINE],threadID); static thread_local MiscCB* sb = new MiscCB; for (unsigned int i = 0; idesc.transform)*camera->GetViewProjection()); (*sb).mColor = boneLines[i]->desc.color; - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MISC], sb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], sb, threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(boneLines[i]->vertexBuffer, 0, sizeof(XMFLOAT3A), threadID); - wiRenderer::graphicsDevice->Draw(2, threadID); + GetDevice()->BindVertexBuffer(boneLines[i]->vertexBuffer, 0, sizeof(XMFLOAT3A), threadID); + GetDevice()->Draw(2, threadID); } } } @@ -1454,26 +1451,26 @@ void wiRenderer::DrawDebugLines(Camera* camera, GRAPHICSTHREAD threadID) if (linesTemp.empty()) return; - wiRenderer::graphicsDevice->BindPrimitiveTopology(LINELIST, threadID); - wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_LINE], threadID); + GetDevice()->BindPrimitiveTopology(LINELIST, threadID); + GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_LINE], threadID); - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_SHADOW], threadID); - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_XRAY], STENCILREF_EMPTY, threadID); - wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE], threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_SHADOW], threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_XRAY], STENCILREF_EMPTY, threadID); + GetDevice()->BindBlendState(blendStates[BSTYPE_OPAQUE], threadID); - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_LINE], threadID); - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_LINE], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_LINE], threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_LINE], threadID); static thread_local MiscCB* sb = new MiscCB; for (unsigned int i = 0; idesc.transform)*camera->GetViewProjection()); (*sb).mColor = linesTemp[i]->desc.color; - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MISC], sb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], sb, threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(linesTemp[i]->vertexBuffer, 0, sizeof(XMFLOAT3A), threadID); - wiRenderer::graphicsDevice->Draw(2, threadID); + GetDevice()->BindVertexBuffer(linesTemp[i]->vertexBuffer, 0, sizeof(XMFLOAT3A), threadID); + GetDevice()->Draw(2, threadID); } for (Lines* x : linesTemp) @@ -1483,28 +1480,28 @@ void wiRenderer::DrawDebugLines(Camera* camera, GRAPHICSTHREAD threadID) void wiRenderer::DrawDebugBoxes(Camera* camera, GRAPHICSTHREAD threadID) { if(debugBoxes){ - wiRenderer::graphicsDevice->BindPrimitiveTopology(LINELIST,threadID); - wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_LINE],threadID); + GetDevice()->BindPrimitiveTopology(LINELIST,threadID); + GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_LINE],threadID); - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_WIRE_DOUBLESIDED],threadID); - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_XRAY],STENCILREF_EMPTY,threadID); - wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_WIRE_DOUBLESIDED],threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_XRAY],STENCILREF_EMPTY,threadID); + GetDevice()->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_LINE],threadID); - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_LINE],threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_LINE],threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_LINE],threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(Cube::vertexBuffer,0,sizeof(XMFLOAT3A),threadID); - wiRenderer::graphicsDevice->BindIndexBuffer(Cube::indexBuffer,threadID); + GetDevice()->BindVertexBuffer(Cube::vertexBuffer,0,sizeof(XMFLOAT3A),threadID); + GetDevice()->BindIndexBuffer(Cube::indexBuffer,threadID); static thread_local MiscCB* sb = new MiscCB; for (unsigned int i = 0; iGetViewProjection()); (*sb).mColor=cubes[i].desc.color; - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MISC],sb,threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC],sb,threadID); - wiRenderer::graphicsDevice->DrawIndexed(24,threadID); + GetDevice()->DrawIndexed(24,threadID); } } @@ -1536,24 +1533,24 @@ void wiRenderer::DrawSoftPremulParticles(Camera* camera, GRAPHICSTHREAD threadID } } void wiRenderer::DrawTrails(GRAPHICSTHREAD threadID, Texture2D* refracRes){ - wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLESTRIP,threadID); - wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_TRAIL],threadID); + GetDevice()->BindPrimitiveTopology(TRIANGLESTRIP,threadID); + GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_TRAIL],threadID); - wiRenderer::graphicsDevice->BindRasterizerState(wireRender?rasterizers[RSTYPE_WIRE_DOUBLESIDED]:rasterizers[RSTYPE_DOUBLESIDED],threadID); - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT],STENCILREF_EMPTY,threadID); - wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); + GetDevice()->BindRasterizerState(wireRender?rasterizers[RSTYPE_WIRE_DOUBLESIDED]:rasterizers[RSTYPE_DOUBLESIDED],threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT],STENCILREF_EMPTY,threadID); + GetDevice()->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_TRAIL],threadID); - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_TRAIL],threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_TRAIL],threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_TRAIL],threadID); - wiRenderer::graphicsDevice->BindTexturePS(refracRes,TEXSLOT_ONDEMAND0,threadID); + GetDevice()->BindTexturePS(refracRes,TEXSLOT_ONDEMAND0,threadID); for (Object* o : objectsWithTrails) { if(o->trailBuff && o->trail.size()>=4){ - wiRenderer::graphicsDevice->BindTexturePS(o->trailDistortTex, TEXSLOT_ONDEMAND1, threadID); - wiRenderer::graphicsDevice->BindTexturePS(o->trailTex, TEXSLOT_ONDEMAND2, threadID); + GetDevice()->BindTexturePS(o->trailDistortTex, TEXSLOT_ONDEMAND1, threadID); + GetDevice()->BindTexturePS(o->trailTex, TEXSLOT_ONDEMAND2, threadID); vector trails; @@ -1595,10 +1592,10 @@ void wiRenderer::DrawTrails(GRAPHICSTHREAD threadID, Texture2D* refracRes){ } } if(!trails.empty()){ - wiRenderer::graphicsDevice->UpdateBuffer(o->trailBuff,trails.data(),threadID,sizeof(RibbonVertex)*trails.size()); + GetDevice()->UpdateBuffer(o->trailBuff,trails.data(),threadID,sizeof(RibbonVertex)*trails.size()); - wiRenderer::graphicsDevice->BindVertexBuffer(o->trailBuff,0,sizeof(RibbonVertex),threadID); - wiRenderer::graphicsDevice->Draw(trails.size(),threadID); + GetDevice()->BindVertexBuffer(o->trailBuff,0,sizeof(RibbonVertex),threadID); + GetDevice()->Draw(trails.size(),threadID); trails.clear(); } @@ -1664,49 +1661,49 @@ void wiRenderer::DrawLights(Camera* camera, GRAPHICSTHREAD threadID, unsigned in { - wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLELIST,threadID); + GetDevice()->BindPrimitiveTopology(TRIANGLELIST,threadID); //BindTexturePS(depth,0,threadID); //BindTexturePS(normal,1,threadID); //BindTexturePS(material,2,threadID); - wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_ADDITIVE],threadID); - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_STENCILREAD],stencilRef,threadID); - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_BACK],threadID); + GetDevice()->BindBlendState(blendStates[BSTYPE_ADDITIVE],threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_STENCILREAD],stencilRef,threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_BACK],threadID); - wiRenderer::graphicsDevice->BindVertexLayout(nullptr, threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(nullptr, 0, 0, threadID); - wiRenderer::graphicsDevice->BindIndexBuffer(nullptr, threadID); + GetDevice()->BindVertexLayout(nullptr, threadID); + GetDevice()->BindVertexBuffer(nullptr, 0, 0, threadID); + GetDevice()->BindIndexBuffer(nullptr, threadID); - wiRenderer::graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_POINTLIGHT], CB_GETBINDSLOT(PointLightCB), threadID); - wiRenderer::graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_POINTLIGHT], CB_GETBINDSLOT(PointLightCB), threadID); + GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_POINTLIGHT], CB_GETBINDSLOT(PointLightCB), threadID); + GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_POINTLIGHT], CB_GETBINDSLOT(PointLightCB), threadID); - wiRenderer::graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_SPOTLIGHT], CB_GETBINDSLOT(SpotLightCB), threadID); - wiRenderer::graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_SPOTLIGHT], CB_GETBINDSLOT(SpotLightCB), threadID); + GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_SPOTLIGHT], CB_GETBINDSLOT(SpotLightCB), threadID); + GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_SPOTLIGHT], CB_GETBINDSLOT(SpotLightCB), threadID); for(int type=0;type<3;++type){ - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_DIRLIGHT + type],threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_DIRLIGHT + type],threadID); switch (type) { case 0: if (SOFTSHADOW) { - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_DIRLIGHT_SOFT], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_DIRLIGHT_SOFT], threadID); } else { - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_DIRLIGHT], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_DIRLIGHT], threadID); } break; case 1: - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_POINTLIGHT], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_POINTLIGHT], threadID); break; case 2: - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_SPOTLIGHT], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_SPOTLIGHT], threadID); break; default: break; @@ -1729,11 +1726,11 @@ void wiRenderer::DrawLights(Camera* camera, GRAPHICSTHREAD threadID, unsigned in for (unsigned int shmap = 0; shmap < l->shadowMaps_dirLight.size(); ++shmap){ (*lcb).mShM[shmap]=l->shadowCam[shmap].getVP(); if(l->shadowMaps_dirLight[shmap].depth) - wiRenderer::graphicsDevice->BindTexturePS(l->shadowMaps_dirLight[shmap].depth->GetTexture(),TEXSLOT_SHADOW0+shmap,threadID); + GetDevice()->BindTexturePS(l->shadowMaps_dirLight[shmap].depth->GetTexture(),TEXSLOT_SHADOW0+shmap,threadID); } - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_DIRLIGHT],lcb,threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_DIRLIGHT],lcb,threadID); - wiRenderer::graphicsDevice->Draw(3, threadID); + GetDevice()->Draw(3, threadID); } else if(type==1) //point { @@ -1747,11 +1744,11 @@ void wiRenderer::DrawLights(Camera* camera, GRAPHICSTHREAD threadID, unsigned in { (*lcb).enerdis.w = 1.f; if(Light::shadowMaps_pointLight[l->shadowMap_index].depth) - wiRenderer::graphicsDevice->BindTexturePS(Light::shadowMaps_pointLight[l->shadowMap_index].depth->GetTexture(), TEXSLOT_SHADOW_CUBE, threadID); + GetDevice()->BindTexturePS(Light::shadowMaps_pointLight[l->shadowMap_index].depth->GetTexture(), TEXSLOT_SHADOW_CUBE, threadID); } - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_POINTLIGHT], lcb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_POINTLIGHT], lcb, threadID); - wiRenderer::graphicsDevice->Draw(240, threadID); + GetDevice()->Draw(240, threadID); } else if(type==2) //spot { @@ -1778,11 +1775,11 @@ void wiRenderer::DrawLights(Camera* camera, GRAPHICSTHREAD threadID, unsigned in { (*lcb).mShM = l->shadowCam[0].getVP(); if(Light::shadowMaps_spotLight[l->shadowMap_index].depth) - wiRenderer::graphicsDevice->BindTexturePS(Light::shadowMaps_spotLight[l->shadowMap_index].depth->GetTexture(), TEXSLOT_SHADOW0, threadID); + GetDevice()->BindTexturePS(Light::shadowMaps_spotLight[l->shadowMap_index].depth->GetTexture(), TEXSLOT_SHADOW0, threadID); } - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_SPOTLIGHT], lcb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_SPOTLIGHT], lcb, threadID); - wiRenderer::graphicsDevice->Draw(192, threadID); + GetDevice()->Draw(192, threadID); } } @@ -1805,29 +1802,29 @@ void wiRenderer::DrawVolumeLights(Camera* camera, GRAPHICSTHREAD threadID) if(!culledObjects.empty()) { - wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLELIST,threadID); - wiRenderer::graphicsDevice->BindVertexLayout(nullptr); - wiRenderer::graphicsDevice->BindVertexBuffer(nullptr, 0, 0, threadID); - wiRenderer::graphicsDevice->BindIndexBuffer(nullptr, threadID); - wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_ADDITIVE],threadID); - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD],STENCILREF_DEFAULT,threadID); - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_DOUBLESIDED],threadID); + GetDevice()->BindPrimitiveTopology(TRIANGLELIST,threadID); + GetDevice()->BindVertexLayout(nullptr); + GetDevice()->BindVertexBuffer(nullptr, 0, 0, threadID); + GetDevice()->BindIndexBuffer(nullptr, threadID); + GetDevice()->BindBlendState(blendStates[BSTYPE_ADDITIVE],threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD],STENCILREF_DEFAULT,threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_DOUBLESIDED],threadID); - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_VOLUMELIGHT],threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_VOLUMELIGHT],threadID); - wiRenderer::graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_VOLUMELIGHT], CB_GETBINDSLOT(VolumeLightCB), threadID); - wiRenderer::graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_VOLUMELIGHT], CB_GETBINDSLOT(VolumeLightCB), threadID); + GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_VOLUMELIGHT], CB_GETBINDSLOT(VolumeLightCB), threadID); + GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_VOLUMELIGHT], CB_GETBINDSLOT(VolumeLightCB), threadID); for(int type=1;type<3;++type){ if(type<=1){ - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_VOLUMEPOINTLIGHT],threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_VOLUMEPOINTLIGHT],threadID); } else{ - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_VOLUMESPOTLIGHT],threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_VOLUMESPOTLIGHT],threadID); } for(Cullable* c : culledObjects){ @@ -1867,12 +1864,12 @@ void wiRenderer::DrawVolumeLights(Camera* camera, GRAPHICSTHREAD threadID) (*lcb).enerdis=l->enerDis; (*lcb).enerdis.w=sca; - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_VOLUMELIGHT],lcb,threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_VOLUMELIGHT],lcb,threadID); if(type<=1) - wiRenderer::graphicsDevice->Draw(108,threadID); + GetDevice()->Draw(108,threadID); else - wiRenderer::graphicsDevice->Draw(192,threadID); + GetDevice()->Draw(192,threadID); } } @@ -1908,7 +1905,7 @@ void wiRenderer::DrawLensFlares(GRAPHICSTHREAD threadID){ )*100000; } - XMVECTOR flarePos = XMVector3Project(POS,0.f,0.f,(float)GetScreenWidth(),(float)GetScreenHeight(),0.1f,1.0f,getCamera()->GetProjection(),getCamera()->GetView(),XMMatrixIdentity()); + XMVECTOR flarePos = XMVector3Project(POS,0.f,0.f,(float)GetDevice()->GetScreenWidth(),(float)GetDevice()->GetScreenHeight(),0.1f,1.0f,getCamera()->GetProjection(),getCamera()->GetView(),XMMatrixIdentity()); if( XMVectorGetX(XMVector3Dot( XMVectorSubtract(POS,getCamera()->GetEye()),getCamera()->GetAt() ))>0 ) wiLensFlare::Draw(threadID,flarePos,l->lensFlareRimTextures); @@ -1920,7 +1917,7 @@ void wiRenderer::DrawLensFlares(GRAPHICSTHREAD threadID){ void wiRenderer::ClearShadowMaps(GRAPHICSTHREAD threadID){ if (GetGameSpeed()) { - wiRenderer::graphicsDevice->UnbindTextures(TEXSLOT_SHADOW0, 1 + TEXSLOT_SHADOW_CUBE - TEXSLOT_SHADOW0, threadID); + GetDevice()->UnbindTextures(TEXSLOT_SHADOW0, 1 + TEXSLOT_SHADOW_CUBE - TEXSLOT_SHADOW0, threadID); for (unsigned int index = 0; index < Light::shadowMaps_pointLight.size(); ++index) { Light::shadowMaps_pointLight[index].Activate(threadID); @@ -1941,17 +1938,17 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) if (culledLights.size() > 0) { - wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLELIST, threadID); - wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_EFFECT], threadID); + GetDevice()->BindPrimitiveTopology(TRIANGLELIST, threadID); + GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_EFFECT], threadID); - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_DEFAULT, threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_DEFAULT, threadID); - wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE], threadID); + GetDevice()->BindBlendState(blendStates[BSTYPE_OPAQUE], threadID); - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_SHADOW], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_SHADOW], threadID); - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_SHADOW], threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_SHADOW], threadID); set orderedSpotLights; @@ -2020,14 +2017,14 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) if (visibleInstances.size() && !mesh->isBillboarded) { if (!mesh->doubleSided) - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_SHADOW], threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_SHADOW], threadID); else - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_SHADOW_DOUBLESIDED], threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_SHADOW_DOUBLESIDED], threadID); //MAPPED_SUBRESOURCE mappedResource; static thread_local ShadowCB* cb = new ShadowCB; (*cb).mVP = l->shadowCam[index].getVP(); - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_SHADOW], cb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_SHADOW], cb, threadID); int k = 0; @@ -2046,9 +2043,9 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) Mesh::UpdateRenderableInstances(visibleInstances.size(), threadID); - wiRenderer::graphicsDevice->BindVertexBuffer((mesh->sOutBuffer ? mesh->sOutBuffer : mesh->meshVertBuff), 0, sizeof(Vertex), threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(mesh->meshInstanceBuffer, 1, sizeof(Instance), threadID); - wiRenderer::graphicsDevice->BindIndexBuffer(mesh->meshIndexBuff, threadID); + GetDevice()->BindVertexBuffer((mesh->sOutBuffer ? mesh->sOutBuffer : mesh->meshVertBuff), 0, sizeof(Vertex), threadID); + GetDevice()->BindVertexBuffer(mesh->meshInstanceBuffer, 1, sizeof(Instance), threadID); + GetDevice()->BindIndexBuffer(mesh->meshIndexBuff, threadID); int matsiz = mesh->materialIndices.size(); @@ -2056,17 +2053,17 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) for (Material* iMat : mesh->materials) { if (!wireRender && !iMat->isSky && !iMat->water && iMat->cast_shadow) { - wiRenderer::graphicsDevice->BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0, threadID); + GetDevice()->BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0, threadID); static thread_local MaterialCB* mcb = new MaterialCB; (*mcb).Create(*iMat, m); - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); - wiRenderer::graphicsDevice->DrawIndexedInstanced(mesh->indices.size(), visibleInstances.size(), threadID); + GetDevice()->DrawIndexedInstanced(mesh->indices.size(), visibleInstances.size(), threadID); m++; } @@ -2121,14 +2118,14 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) if (visibleInstances.size() && !mesh->isBillboarded) { if (!mesh->doubleSided) - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_SHADOW], threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_SHADOW], threadID); else - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_SHADOW_DOUBLESIDED], threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_SHADOW_DOUBLESIDED], threadID); //MAPPED_SUBRESOURCE mappedResource; static thread_local ShadowCB* cb = new ShadowCB; (*cb).mVP = l->shadowCam[index].getVP(); - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_SHADOW], cb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_SHADOW], cb, threadID); int k = 0; @@ -2147,9 +2144,9 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) Mesh::UpdateRenderableInstances(visibleInstances.size(), threadID); - wiRenderer::graphicsDevice->BindVertexBuffer((mesh->sOutBuffer ? mesh->sOutBuffer : mesh->meshVertBuff), 0, sizeof(Vertex), threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(mesh->meshInstanceBuffer, 1, sizeof(Instance), threadID); - wiRenderer::graphicsDevice->BindIndexBuffer(mesh->meshIndexBuff, threadID); + GetDevice()->BindVertexBuffer((mesh->sOutBuffer ? mesh->sOutBuffer : mesh->meshVertBuff), 0, sizeof(Vertex), threadID); + GetDevice()->BindVertexBuffer(mesh->meshInstanceBuffer, 1, sizeof(Instance), threadID); + GetDevice()->BindIndexBuffer(mesh->meshIndexBuff, threadID); int matsiz = mesh->materialIndices.size(); @@ -2157,17 +2154,17 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) for (Material* iMat : mesh->materials) { if (!wireRender && !iMat->isSky && !iMat->water && iMat->cast_shadow) { - wiRenderer::graphicsDevice->BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0, threadID); + GetDevice()->BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0, threadID); static thread_local MaterialCB* mcb = new MaterialCB; (*mcb).Create(*iMat, m); - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); - wiRenderer::graphicsDevice->DrawIndexedInstanced(mesh->indices.size(), visibleInstances.size(), threadID); + GetDevice()->DrawIndexedInstanced(mesh->indices.size(), visibleInstances.size(), threadID); m++; } @@ -2187,12 +2184,12 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) //POINTLIGHTS if(!orderedPointLights.empty()) { - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_SHADOWCUBEMAPRENDER], threadID); - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_SHADOWCUBEMAPRENDER], threadID); - wiRenderer::graphicsDevice->BindGS(geometryShaders[GSTYPE_SHADOWCUBEMAPRENDER], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_SHADOWCUBEMAPRENDER], threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_SHADOWCUBEMAPRENDER], threadID); + GetDevice()->BindGS(geometryShaders[GSTYPE_SHADOWCUBEMAPRENDER], threadID); - wiRenderer::graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_POINTLIGHT], CB_GETBINDSLOT(PointLightCB), threadID); - wiRenderer::graphicsDevice->BindConstantBufferGS(constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubeMapRenderCB), threadID); + GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_POINTLIGHT], CB_GETBINDSLOT(PointLightCB), threadID); + GetDevice()->BindConstantBufferGS(constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubeMapRenderCB), threadID); int i = 0; for (Light* l : orderedPointLights) @@ -2208,13 +2205,13 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) static thread_local PointLightCB* lcb = new PointLightCB; (*lcb).enerdis = l->enerDis; (*lcb).pos = l->translation; - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_POINTLIGHT], lcb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_POINTLIGHT], lcb, threadID); static thread_local CubeMapRenderCB* cb = new CubeMapRenderCB; for (unsigned int shcam = 0; shcam < l->shadowCam.size(); ++shcam) (*cb).mViewProjection[shcam] = l->shadowCam[shcam].getVP(); - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_CUBEMAPRENDER], cb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_CUBEMAPRENDER], cb, threadID); CulledList culledObjects; CulledCollection culledRenderer; @@ -2232,9 +2229,9 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) if (!mesh->isBillboarded && !visibleInstances.empty()) { if (!mesh->doubleSided) - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_SHADOW], threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_SHADOW], threadID); else - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_SHADOW_DOUBLESIDED], threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_SHADOW_DOUBLESIDED], threadID); @@ -2254,23 +2251,23 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) Mesh::UpdateRenderableInstances(visibleInstances.size(), threadID); - wiRenderer::graphicsDevice->BindVertexBuffer((mesh->sOutBuffer ? mesh->sOutBuffer : mesh->meshVertBuff), 0, sizeof(Vertex), threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(mesh->meshInstanceBuffer, 1, sizeof(Instance), threadID); - wiRenderer::graphicsDevice->BindIndexBuffer(mesh->meshIndexBuff, threadID); + GetDevice()->BindVertexBuffer((mesh->sOutBuffer ? mesh->sOutBuffer : mesh->meshVertBuff), 0, sizeof(Vertex), threadID); + GetDevice()->BindVertexBuffer(mesh->meshInstanceBuffer, 1, sizeof(Instance), threadID); + GetDevice()->BindIndexBuffer(mesh->meshIndexBuff, threadID); int matsiz = mesh->materialIndices.size(); int m = 0; for (Material* iMat : mesh->materials) { if (!wireRender && !iMat->isSky && !iMat->water && iMat->cast_shadow) { - wiRenderer::graphicsDevice->BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0, threadID); + GetDevice()->BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0, threadID); static thread_local MaterialCB* mcb = new MaterialCB; (*mcb).Create(*iMat, m); - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); - wiRenderer::graphicsDevice->DrawIndexedInstanced(mesh->indices.size(), visibleInstances.size(), threadID); + GetDevice()->DrawIndexedInstanced(mesh->indices.size(), visibleInstances.size(), threadID); } m++; } @@ -2281,7 +2278,7 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) i++; } - wiRenderer::graphicsDevice->BindGS(nullptr, threadID); + GetDevice()->BindGS(nullptr, threadID); } } } @@ -2369,9 +2366,9 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, GRAPHICSTHRE envProbeCB->mTransform.r[0] = XMLoadFloat3(&envMapPositions[0]); envProbeCB->mTransform.r[1] = XMLoadFloat3(&envMapPositions[1]); envProbeCB->mTransform = XMMatrixTranspose(envProbeCB->mTransform); - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MISC], envProbeCB, threadID); - wiRenderer::graphicsDevice->BindTexturePS(envMaps[0], TEXSLOT_ENV0, threadID); - wiRenderer::graphicsDevice->BindTexturePS(envMaps[1], TEXSLOT_ENV1, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], envProbeCB, threadID); + GetDevice()->BindTexturePS(envMaps[0], TEXSLOT_ENV0, threadID); + GetDevice()->BindTexturePS(envMaps[1], TEXSLOT_ENV1, threadID); @@ -2385,61 +2382,61 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, GRAPHICSTHRE } if(DX11Eff && tessF) - wiRenderer::graphicsDevice->BindPrimitiveTopology(PATCHLIST,threadID); + GetDevice()->BindPrimitiveTopology(PATCHLIST,threadID); else - wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLELIST,threadID); - wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_EFFECT],threadID); + GetDevice()->BindPrimitiveTopology(TRIANGLELIST,threadID); + GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_EFFECT],threadID); if(DX11Eff && tessF) - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_OBJECT],threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_OBJECT],threadID); else { if (isReflection) { - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_OBJECT_REFLECTION], threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_OBJECT_REFLECTION], threadID); } else { - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_OBJECT10], threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_OBJECT10], threadID); } } if(DX11Eff && tessF) - wiRenderer::graphicsDevice->BindHS(hullShaders[HSTYPE_OBJECT],threadID); + GetDevice()->BindHS(hullShaders[HSTYPE_OBJECT],threadID); else - wiRenderer::graphicsDevice->BindHS(nullptr,threadID); + GetDevice()->BindHS(nullptr,threadID); if(DX11Eff && tessF) - wiRenderer::graphicsDevice->BindDS(domainShaders[DSTYPE_OBJECT],threadID); + GetDevice()->BindDS(domainShaders[DSTYPE_OBJECT],threadID); else - wiRenderer::graphicsDevice->BindDS(nullptr,threadID); + GetDevice()->BindDS(nullptr,threadID); if (wireRender) - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_SIMPLEST], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_SIMPLEST], threadID); else if (BlackOut) - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_BLACKOUT], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_BLACKOUT], threadID); else if (shaded == SHADERTYPE_NONE) - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_TEXTUREONLY], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_TEXTUREONLY], threadID); else if (shaded == SHADERTYPE_DEFERRED) - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_OBJECT], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_OBJECT], threadID); else if (shaded == SHADERTYPE_FORWARD_SIMPLE) - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_OBJECT_FORWARDSIMPLE], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_OBJECT_FORWARDSIMPLE], threadID); else return; - wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); + GetDevice()->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); if(!wireRender) { if (enviroMap != nullptr) { - wiRenderer::graphicsDevice->BindTexturePS(enviroMap, TEXSLOT_ENV_GLOBAL, threadID); + GetDevice()->BindTexturePS(enviroMap, TEXSLOT_ENV_GLOBAL, threadID); } else { - wiRenderer::graphicsDevice->UnbindTextures(TEXSLOT_ENV_GLOBAL, 1, threadID); + GetDevice()->UnbindTextures(TEXSLOT_ENV_GLOBAL, 1, threadID); } if(refRes != nullptr) - wiRenderer::graphicsDevice->BindTexturePS(refRes,TEXSLOT_ONDEMAND5,threadID); + GetDevice()->BindTexturePS(refRes,TEXSLOT_ONDEMAND5,threadID); } @@ -2449,9 +2446,9 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, GRAPHICSTHRE if(!mesh->doubleSided) - wiRenderer::graphicsDevice->BindRasterizerState(wireRender?rasterizers[RSTYPE_WIRE]:rasterizers[RSTYPE_FRONT],threadID); + GetDevice()->BindRasterizerState(wireRender?rasterizers[RSTYPE_WIRE]:rasterizers[RSTYPE_FRONT],threadID); else - wiRenderer::graphicsDevice->BindRasterizerState(wireRender?rasterizers[RSTYPE_WIRE]:rasterizers[RSTYPE_DOUBLESIDED],threadID); + GetDevice()->BindRasterizerState(wireRender?rasterizers[RSTYPE_WIRE]:rasterizers[RSTYPE_DOUBLESIDED],threadID); int matsiz = mesh->materialIndices.size(); @@ -2471,9 +2468,9 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, GRAPHICSTHRE Mesh::UpdateRenderableInstances(visibleInstances.size(), threadID); - wiRenderer::graphicsDevice->BindIndexBuffer(mesh->meshIndexBuff,threadID); - wiRenderer::graphicsDevice->BindVertexBuffer((mesh->sOutBuffer?mesh->sOutBuffer:mesh->meshVertBuff),0,sizeof(Vertex),threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(mesh->meshInstanceBuffer,1,sizeof(Instance),threadID); + GetDevice()->BindIndexBuffer(mesh->meshIndexBuff,threadID); + GetDevice()->BindVertexBuffer((mesh->sOutBuffer?mesh->sOutBuffer:mesh->meshVertBuff),0,sizeof(Vertex),threadID); + GetDevice()->BindVertexBuffer(mesh->meshInstanceBuffer,1,sizeof(Instance),threadID); int m=0; for(Material* iMat : mesh->materials){ @@ -2481,27 +2478,27 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, GRAPHICSTHRE if(!iMat->IsTransparent() && !iMat->isSky && !iMat->water){ if(iMat->shadeless) - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT],STENCILREF_SHADELESS,threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT],STENCILREF_SHADELESS,threadID); if(iMat->subsurface_scattering) - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT],STENCILREF_SKIN,threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT],STENCILREF_SKIN,threadID); else - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT],mesh->stencilRef,threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT],mesh->stencilRef,threadID); static thread_local MaterialCB* mcb = new MaterialCB; (*mcb).Create(*iMat, m); - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); - if(!wireRender) wiRenderer::graphicsDevice->BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0,threadID); - if(!wireRender) wiRenderer::graphicsDevice->BindTexturePS(iMat->refMap, TEXSLOT_ONDEMAND1,threadID); - if(!wireRender) wiRenderer::graphicsDevice->BindTexturePS(iMat->normalMap, TEXSLOT_ONDEMAND2,threadID); - if(!wireRender) wiRenderer::graphicsDevice->BindTexturePS(iMat->specularMap, TEXSLOT_ONDEMAND3,threadID); + if(!wireRender) GetDevice()->BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0,threadID); + if(!wireRender) GetDevice()->BindTexturePS(iMat->refMap, TEXSLOT_ONDEMAND1,threadID); + if(!wireRender) GetDevice()->BindTexturePS(iMat->normalMap, TEXSLOT_ONDEMAND2,threadID); + if(!wireRender) GetDevice()->BindTexturePS(iMat->specularMap, TEXSLOT_ONDEMAND3,threadID); if(DX11Eff) - wiRenderer::graphicsDevice->BindTextureDS(iMat->displacementMap, TEXSLOT_ONDEMAND4,threadID); + GetDevice()->BindTextureDS(iMat->displacementMap, TEXSLOT_ONDEMAND4,threadID); - wiRenderer::graphicsDevice->DrawIndexedInstanced(mesh->indices.size(),visibleInstances.size(),threadID); + GetDevice()->DrawIndexedInstanced(mesh->indices.size(),visibleInstances.size(),threadID); } m++; } @@ -2509,10 +2506,10 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, GRAPHICSTHRE } - wiRenderer::graphicsDevice->BindPS(nullptr,threadID); - wiRenderer::graphicsDevice->BindVS(nullptr,threadID); - wiRenderer::graphicsDevice->BindDS(nullptr,threadID); - wiRenderer::graphicsDevice->BindHS(nullptr,threadID); + GetDevice()->BindPS(nullptr,threadID); + GetDevice()->BindVS(nullptr,threadID); + GetDevice()->BindDS(nullptr,threadID); + GetDevice()->BindHS(nullptr,threadID); } @@ -2548,9 +2545,9 @@ void wiRenderer::DrawWorldTransparent(Camera* camera, Texture2D* refracRes, Text for(Cullable* object : culledObjects) culledRenderer[((Object*)object)->mesh].insert((Object*)object); - wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLELIST,threadID); - wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_EFFECT],threadID); - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_OBJECT10],threadID); + GetDevice()->BindPrimitiveTopology(TRIANGLELIST,threadID); + GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_EFFECT],threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_OBJECT10],threadID); if (!wireRender) @@ -2558,20 +2555,20 @@ void wiRenderer::DrawWorldTransparent(Camera* camera, Texture2D* refracRes, Text if (enviroMap != nullptr) { - wiRenderer::graphicsDevice->BindTexturePS(enviroMap, TEXSLOT_ENV_GLOBAL, threadID); + GetDevice()->BindTexturePS(enviroMap, TEXSLOT_ENV_GLOBAL, threadID); } else { - wiRenderer::graphicsDevice->UnbindTextures(TEXSLOT_ENV_GLOBAL, 1, threadID); + GetDevice()->UnbindTextures(TEXSLOT_ENV_GLOBAL, 1, threadID); } - wiRenderer::graphicsDevice->BindTexturePS(refRes, TEXSLOT_ONDEMAND5,threadID); - wiRenderer::graphicsDevice->BindTexturePS(refracRes, TEXSLOT_ONDEMAND6,threadID); + GetDevice()->BindTexturePS(refRes, TEXSLOT_ONDEMAND5,threadID); + GetDevice()->BindTexturePS(refracRes, TEXSLOT_ONDEMAND6,threadID); //BindTexturePS(depth,7,threadID); - wiRenderer::graphicsDevice->BindTexturePS(waterRippleNormals, TEXSLOT_ONDEMAND7, threadID); + GetDevice()->BindTexturePS(waterRippleNormals, TEXSLOT_ONDEMAND7, threadID); } - wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); + GetDevice()->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); RENDERTYPE lastRenderType = RENDERTYPE_VOID; @@ -2592,9 +2589,9 @@ void wiRenderer::DrawWorldTransparent(Camera* camera, Texture2D* refracRes, Text continue; if (!mesh->doubleSided) - wiRenderer::graphicsDevice->BindRasterizerState(wireRender ? rasterizers[RSTYPE_WIRE] : rasterizers[RSTYPE_FRONT], threadID); + GetDevice()->BindRasterizerState(wireRender ? rasterizers[RSTYPE_WIRE] : rasterizers[RSTYPE_FRONT], threadID); else - wiRenderer::graphicsDevice->BindRasterizerState(wireRender ? rasterizers[RSTYPE_WIRE] : rasterizers[RSTYPE_DOUBLESIDED], threadID); + GetDevice()->BindRasterizerState(wireRender ? rasterizers[RSTYPE_WIRE] : rasterizers[RSTYPE_DOUBLESIDED], threadID); int matsiz = mesh->materialIndices.size(); @@ -2617,9 +2614,9 @@ void wiRenderer::DrawWorldTransparent(Camera* camera, Texture2D* refracRes, Text Mesh::UpdateRenderableInstances(visibleInstances.size(), threadID); - wiRenderer::graphicsDevice->BindIndexBuffer(mesh->meshIndexBuff,threadID); - wiRenderer::graphicsDevice->BindVertexBuffer((mesh->sOutBuffer?mesh->sOutBuffer:mesh->meshVertBuff),0,sizeof(Vertex),threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(mesh->meshInstanceBuffer,1,sizeof(Instance),threadID); + GetDevice()->BindIndexBuffer(mesh->meshIndexBuff,threadID); + GetDevice()->BindVertexBuffer((mesh->sOutBuffer?mesh->sOutBuffer:mesh->meshVertBuff),0,sizeof(Vertex),threadID); + GetDevice()->BindVertexBuffer(mesh->meshInstanceBuffer,1,sizeof(Instance),threadID); int m=0; @@ -2632,30 +2629,30 @@ void wiRenderer::DrawWorldTransparent(Camera* camera, Texture2D* refracRes, Text static thread_local MaterialCB* mcb = new MaterialCB; (*mcb).Create(*iMat, m); - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); - if(!wireRender) wiRenderer::graphicsDevice->BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0,threadID); - if(!wireRender) wiRenderer::graphicsDevice->BindTexturePS(iMat->refMap, TEXSLOT_ONDEMAND1,threadID); - if(!wireRender) wiRenderer::graphicsDevice->BindTexturePS(iMat->normalMap, TEXSLOT_ONDEMAND2,threadID); - if(!wireRender) wiRenderer::graphicsDevice->BindTexturePS(iMat->specularMap, TEXSLOT_ONDEMAND3,threadID); + if(!wireRender) GetDevice()->BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0,threadID); + if(!wireRender) GetDevice()->BindTexturePS(iMat->refMap, TEXSLOT_ONDEMAND1,threadID); + if(!wireRender) GetDevice()->BindTexturePS(iMat->normalMap, TEXSLOT_ONDEMAND2,threadID); + if(!wireRender) GetDevice()->BindTexturePS(iMat->specularMap, TEXSLOT_ONDEMAND3,threadID); if (iMat->IsTransparent() && lastRenderType != RENDERTYPE_TRANSPARENT) { lastRenderType = RENDERTYPE_TRANSPARENT; - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_TRANSPARENT, threadID); - wiRenderer::graphicsDevice->BindPS(wireRender ? pixelShaders[PSTYPE_SIMPLEST] : pixelShaders[PSTYPE_OBJECT_TRANSPARENT], threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_TRANSPARENT, threadID); + GetDevice()->BindPS(wireRender ? pixelShaders[PSTYPE_SIMPLEST] : pixelShaders[PSTYPE_OBJECT_TRANSPARENT], threadID); } if (iMat->IsWater() && lastRenderType != RENDERTYPE_WATER) { lastRenderType = RENDERTYPE_WATER; - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD], STENCILREF_EMPTY, threadID); - wiRenderer::graphicsDevice->BindPS(wireRender ? pixelShaders[PSTYPE_SIMPLEST] : pixelShaders[PSTYPE_WATER], threadID); - wiRenderer::graphicsDevice->BindRasterizerState(wireRender ? rasterizers[RSTYPE_WIRE] : rasterizers[RSTYPE_DOUBLESIDED], threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD], STENCILREF_EMPTY, threadID); + GetDevice()->BindPS(wireRender ? pixelShaders[PSTYPE_SIMPLEST] : pixelShaders[PSTYPE_WATER], threadID); + GetDevice()->BindRasterizerState(wireRender ? rasterizers[RSTYPE_WIRE] : rasterizers[RSTYPE_DOUBLESIDED], threadID); } - wiRenderer::graphicsDevice->DrawIndexedInstanced(mesh->indices.size(),visibleInstances.size(),threadID); + GetDevice()->DrawIndexedInstanced(mesh->indices.size(),visibleInstances.size(),threadID); } m++; } @@ -2670,41 +2667,41 @@ void wiRenderer::DrawSky(GRAPHICSTHREAD threadID, bool isReflection) if (enviroMap == nullptr) return; - wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLELIST,threadID); - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_BACK],threadID); - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD],STENCILREF_SKY,threadID); - wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); + GetDevice()->BindPrimitiveTopology(TRIANGLELIST,threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_BACK],threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD],STENCILREF_SKY,threadID); + GetDevice()->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); if (!isReflection) { - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_SKY], threadID); - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_SKY], threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_SKY], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_SKY], threadID); } else { - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_SKY_REFLECTION], threadID); - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_SKY_REFLECTION], threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_SKY_REFLECTION], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_SKY_REFLECTION], threadID); } - wiRenderer::graphicsDevice->BindTexturePS(enviroMap, TEXSLOT_ENV_GLOBAL, threadID); + GetDevice()->BindTexturePS(enviroMap, TEXSLOT_ENV_GLOBAL, threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(nullptr,0,0,threadID); - wiRenderer::graphicsDevice->BindVertexLayout(nullptr, threadID); - wiRenderer::graphicsDevice->Draw(240,threadID); + GetDevice()->BindVertexBuffer(nullptr,0,0,threadID); + GetDevice()->BindVertexLayout(nullptr, threadID); + GetDevice()->Draw(240,threadID); } void wiRenderer::DrawSun(GRAPHICSTHREAD threadID) { - wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLELIST, threadID); - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_BACK], threadID); - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD], STENCILREF_SKY, threadID); - wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_ADDITIVE], threadID); + GetDevice()->BindPrimitiveTopology(TRIANGLELIST, threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_BACK], threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD], STENCILREF_SKY, threadID); + GetDevice()->BindBlendState(blendStates[BSTYPE_ADDITIVE], threadID); - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_SKY], threadID); - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_SUN], threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_SKY], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_SUN], threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(nullptr, 0, 0, threadID); - wiRenderer::graphicsDevice->BindVertexLayout(nullptr, threadID); - wiRenderer::graphicsDevice->Draw(240, threadID); + GetDevice()->BindVertexBuffer(nullptr, 0, 0, threadID); + GetDevice()->BindVertexLayout(nullptr, threadID); + GetDevice()->Draw(240, threadID); } void wiRenderer::DrawDecals(Camera* camera, GRAPHICSTHREAD threadID) @@ -2718,28 +2715,28 @@ void wiRenderer::DrawDecals(Camera* camera, GRAPHICSTHREAD threadID) if (!boundCB) { boundCB = true; - wiRenderer::graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_DECAL], CB_GETBINDSLOT(DecalCB),threadID); + GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_DECAL], CB_GETBINDSLOT(DecalCB),threadID); } //BindTexturePS(depth, 1, threadID); - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_DECAL], threadID); - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_DECAL], threadID); - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_BACK], threadID); - wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_TRANSPARENT], threadID); - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_STENCILREAD_MATCH], STENCILREF::STENCILREF_DEFAULT, threadID); - wiRenderer::graphicsDevice->BindVertexLayout(nullptr, threadID); - wiRenderer::graphicsDevice->BindPrimitiveTopology(PRIMITIVETOPOLOGY::TRIANGLELIST, threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_DECAL], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_DECAL], threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_BACK], threadID); + GetDevice()->BindBlendState(blendStates[BSTYPE_TRANSPARENT], threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_STENCILREAD_MATCH], STENCILREF::STENCILREF_DEFAULT, threadID); + GetDevice()->BindVertexLayout(nullptr, threadID); + GetDevice()->BindPrimitiveTopology(PRIMITIVETOPOLOGY::TRIANGLELIST, threadID); for (Decal* decal : model->decals) { if ((decal->texture || decal->normal) && camera->frustum.CheckBox(decal->bounds.corners)) { - wiRenderer::graphicsDevice->BindTexturePS(decal->texture, TEXSLOT_ONDEMAND0, threadID); - wiRenderer::graphicsDevice->BindTexturePS(decal->normal, TEXSLOT_ONDEMAND1, threadID); + GetDevice()->BindTexturePS(decal->texture, TEXSLOT_ONDEMAND0, threadID); + GetDevice()->BindTexturePS(decal->normal, TEXSLOT_ONDEMAND1, threadID); static thread_local MiscCB* dcbvs = new MiscCB; (*dcbvs).mTransform =XMMatrixTranspose(XMLoadFloat4x4(&decal->world)*camera->GetViewProjection()); - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MISC], dcbvs, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], dcbvs, threadID); static thread_local DecalCB* dcbps = new DecalCB; dcbps->mDecalVP = @@ -2754,9 +2751,9 @@ void wiRenderer::DrawDecals(Camera* camera, GRAPHICSTHREAD threadID) XMStoreFloat3(&dcbps->eye, camera->GetEye()); dcbps->opacity = wiMath::Clamp((decal->life <= -2 ? 1 : decal->life < decal->fadeStart ? decal->life / decal->fadeStart : 1), 0, 1); dcbps->front = decal->front; - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_DECAL], dcbps, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_DECAL], dcbps, threadID); - wiRenderer::graphicsDevice->Draw(36, threadID); + GetDevice()->Draw(36, threadID); } @@ -2773,11 +2770,11 @@ void wiRenderer::UpdateWorldCB(GRAPHICSTHREAD threadID) (*cb).mFog = world.fogSEH; (*cb).mHorizon = world.horizon; (*cb).mZenith = world.zenith; - (*cb).mScreenWidthHeight = XMFLOAT2((float)GetScreenWidth(), (float)GetScreenHeight()); + (*cb).mScreenWidthHeight = XMFLOAT2((float)GetDevice()->GetScreenWidth(), (float)GetDevice()->GetScreenHeight()); XMStoreFloat4(&(*cb).mSun, GetSunPosition()); (*cb).mSunColor = GetSunColor(); - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_WORLD], cb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_WORLD], cb, threadID); } void wiRenderer::UpdateFrameCB(GRAPHICSTHREAD threadID) { @@ -2789,7 +2786,7 @@ void wiRenderer::UpdateFrameCB(GRAPHICSTHREAD threadID) (*cb).mWindWaveSize = wind.waveSize; (*cb).mWindDirection = wind.direction; - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_FRAME], cb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_FRAME], cb, threadID); } void wiRenderer::UpdateCameraCB(GRAPHICSTHREAD threadID) { @@ -2813,29 +2810,29 @@ void wiRenderer::UpdateCameraCB(GRAPHICSTHREAD threadID) (*cb).mZNearP = camera->zNearP; (*cb).mZFarP = camera->zFarP; - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_CAMERA], cb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_CAMERA], cb, threadID); } void wiRenderer::SetClipPlane(XMFLOAT4 clipPlane, GRAPHICSTHREAD threadID) { - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_CLIPPLANE], &clipPlane, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_CLIPPLANE], &clipPlane, threadID); } void wiRenderer::UpdateGBuffer(Texture2D* slot0, Texture2D* slot1, Texture2D* slot2, Texture2D* slot3, Texture2D* slot4, GRAPHICSTHREAD threadID) { - wiRenderer::graphicsDevice->BindTexturePS(slot0, TEXSLOT_GBUFFER0, threadID); - wiRenderer::graphicsDevice->BindTexturePS(slot1, TEXSLOT_GBUFFER1, threadID); - wiRenderer::graphicsDevice->BindTexturePS(slot2, TEXSLOT_GBUFFER2, threadID); - wiRenderer::graphicsDevice->BindTexturePS(slot3, TEXSLOT_GBUFFER3, threadID); - wiRenderer::graphicsDevice->BindTexturePS(slot4, TEXSLOT_GBUFFER4, threadID); + GetDevice()->BindTexturePS(slot0, TEXSLOT_GBUFFER0, threadID); + GetDevice()->BindTexturePS(slot1, TEXSLOT_GBUFFER1, threadID); + GetDevice()->BindTexturePS(slot2, TEXSLOT_GBUFFER2, threadID); + GetDevice()->BindTexturePS(slot3, TEXSLOT_GBUFFER3, threadID); + GetDevice()->BindTexturePS(slot4, TEXSLOT_GBUFFER4, threadID); } void wiRenderer::UpdateDepthBuffer(Texture2D* depth, Texture2D* linearDepth, GRAPHICSTHREAD threadID) { - wiRenderer::graphicsDevice->BindTexturePS(depth, TEXSLOT_DEPTH, threadID); - wiRenderer::graphicsDevice->BindTextureVS(depth, TEXSLOT_DEPTH, threadID); - wiRenderer::graphicsDevice->BindTextureGS(depth, TEXSLOT_DEPTH, threadID); + GetDevice()->BindTexturePS(depth, TEXSLOT_DEPTH, threadID); + GetDevice()->BindTextureVS(depth, TEXSLOT_DEPTH, threadID); + GetDevice()->BindTextureGS(depth, TEXSLOT_DEPTH, threadID); - wiRenderer::graphicsDevice->BindTexturePS(linearDepth, TEXSLOT_LINEARDEPTH, threadID); - wiRenderer::graphicsDevice->BindTextureVS(linearDepth, TEXSLOT_LINEARDEPTH, threadID); - wiRenderer::graphicsDevice->BindTextureGS(linearDepth, TEXSLOT_LINEARDEPTH, threadID); + GetDevice()->BindTexturePS(linearDepth, TEXSLOT_LINEARDEPTH, threadID); + GetDevice()->BindTextureVS(linearDepth, TEXSLOT_LINEARDEPTH, threadID); + GetDevice()->BindTextureGS(linearDepth, TEXSLOT_LINEARDEPTH, threadID); } void wiRenderer::FinishLoading() @@ -2881,9 +2878,9 @@ wiRenderer::Picked wiRenderer::Pick(long cursorX, long cursorY, int pickType, co RAY wiRenderer::getPickRay(long cursorX, long cursorY){ XMVECTOR& lineStart = XMVector3Unproject(XMVectorSet((float)cursorX,(float)cursorY,0,1),0,0 - , (float)SCREENWIDTH, (float)SCREENHEIGHT, 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); + , (float)GetDevice()->GetScreenWidth(), (float)GetDevice()->GetScreenHeight(), 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); XMVECTOR& lineEnd = XMVector3Unproject(XMVectorSet((float)cursorX, (float)cursorY, 1, 1), 0, 0 - , (float)SCREENWIDTH, (float)SCREENHEIGHT, 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); + , (float)GetDevice()->GetScreenWidth(), (float)GetDevice()->GetScreenHeight(), 0.1f, 1.0f, wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity()); XMVECTOR& rayDirection = XMVector3Normalize(XMVectorSubtract(lineEnd,lineStart)); return RAY(lineStart,rayDirection); } @@ -3054,7 +3051,7 @@ Model* wiRenderer::LoadModel(const string& dir, const string& name, const XMMATR } } - wiRenderer::graphicsDevice->LOCK(); + GetDevice()->LOCK(); Update(); @@ -3082,7 +3079,7 @@ Model* wiRenderer::LoadModel(const string& dir, const string& name, const XMMATR SetUpCubes(); SetUpBoneLines(); - wiRenderer::graphicsDevice->UNLOCK(); + GetDevice()->UNLOCK(); LoadWorldInfo(dir, name); @@ -3094,9 +3091,9 @@ void wiRenderer::LoadWorldInfo(const string& dir, const string& name) { LoadWiWorldInfo(dir, name+".wiw", GetScene().worldInfo, GetScene().wind); - wiRenderer::graphicsDevice->LOCK(); + GetDevice()->LOCK(); UpdateWorldCB(GRAPHICSTHREAD_IMMEDIATE); - wiRenderer::graphicsDevice->UNLOCK(); + GetDevice()->UNLOCK(); } Scene& wiRenderer::GetScene() { @@ -3184,21 +3181,21 @@ void wiRenderer::PutEnvProbe(const XMFLOAT3& position, int resolution) probe->transform(position); probe->cubeMap.InitializeCube(resolution, 1, true, DXGI_FORMAT_R16G16B16A16_FLOAT, 0); - wiRenderer::graphicsDevice->LOCK(); + GetDevice()->LOCK(); GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE; probe->cubeMap.Activate(threadID, 0, 0, 0, 1); - wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_EFFECT], threadID); - wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLELIST, threadID); - wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE], threadID); + GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_EFFECT], threadID); + GetDevice()->BindPrimitiveTopology(TRIANGLELIST, threadID); + GetDevice()->BindBlendState(blendStates[BSTYPE_OPAQUE], threadID); - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_ENVMAP], threadID); - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_ENVMAP], threadID); - wiRenderer::graphicsDevice->BindGS(geometryShaders[GSTYPE_ENVMAP], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_ENVMAP], threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_ENVMAP], threadID); + GetDevice()->BindGS(geometryShaders[GSTYPE_ENVMAP], threadID); - wiRenderer::graphicsDevice->BindConstantBufferGS(constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubeMapRenderCB), threadID); + GetDevice()->BindConstantBufferGS(constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubeMapRenderCB), threadID); vector cameras; @@ -3223,7 +3220,7 @@ void wiRenderer::PutEnvProbe(const XMFLOAT3& position, int resolution) (*cb).mViewProjection[i] = cameras[i].getVP(); } - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_CUBEMAPRENDER], cb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_CUBEMAPRENDER], cb, threadID); CulledList culledObjects; @@ -3244,9 +3241,9 @@ void wiRenderer::PutEnvProbe(const XMFLOAT3& position, int resolution) if (!mesh->isBillboarded && !visibleInstances.empty()) { if (!mesh->doubleSided) - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_FRONT], threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_FRONT], threadID); else - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_DOUBLESIDED], threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_DOUBLESIDED], threadID); @@ -3266,9 +3263,9 @@ void wiRenderer::PutEnvProbe(const XMFLOAT3& position, int resolution) Mesh::UpdateRenderableInstances(visibleInstances.size(), threadID); - wiRenderer::graphicsDevice->BindVertexBuffer((mesh->sOutBuffer ? mesh->sOutBuffer : mesh->meshVertBuff), 0, sizeof(Vertex), threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(mesh->meshInstanceBuffer, 1, sizeof(Instance), threadID); - wiRenderer::graphicsDevice->BindIndexBuffer(mesh->meshIndexBuff, threadID); + GetDevice()->BindVertexBuffer((mesh->sOutBuffer ? mesh->sOutBuffer : mesh->meshVertBuff), 0, sizeof(Vertex), threadID); + GetDevice()->BindVertexBuffer(mesh->meshInstanceBuffer, 1, sizeof(Instance), threadID); + GetDevice()->BindIndexBuffer(mesh->meshIndexBuff, threadID); int matsiz = mesh->materialIndices.size(); @@ -3277,20 +3274,20 @@ void wiRenderer::PutEnvProbe(const XMFLOAT3& position, int resolution) if (!wireRender && !iMat->isSky && !iMat->water && iMat->cast_shadow) { if (iMat->shadeless) - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_SHADELESS, threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_SHADELESS, threadID); if (iMat->subsurface_scattering) - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_SKIN, threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_SKIN, threadID); else - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], mesh->stencilRef, threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], mesh->stencilRef, threadID); - wiRenderer::graphicsDevice->BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0, threadID); + GetDevice()->BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0, threadID); static thread_local MaterialCB* mcb = new MaterialCB; (*mcb).Create(*iMat, m); - wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); - wiRenderer::graphicsDevice->DrawIndexedInstanced(mesh->indices.size(), visibleInstances.size(), threadID); + GetDevice()->DrawIndexedInstanced(mesh->indices.size(), visibleInstances.size(), threadID); } m++; } @@ -3302,35 +3299,35 @@ void wiRenderer::PutEnvProbe(const XMFLOAT3& position, int resolution) // sky { - wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLELIST, threadID); - wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_BACK], threadID); - wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD], STENCILREF_SKY, threadID); - wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE], threadID); + GetDevice()->BindPrimitiveTopology(TRIANGLELIST, threadID); + GetDevice()->BindRasterizerState(rasterizers[RSTYPE_BACK], threadID); + GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD], STENCILREF_SKY, threadID); + GetDevice()->BindBlendState(blendStates[BSTYPE_OPAQUE], threadID); - wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_ENVMAP_SKY], threadID); - wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_ENVMAP_SKY], threadID); - wiRenderer::graphicsDevice->BindGS(geometryShaders[GSTYPE_ENVMAP_SKY], threadID); + GetDevice()->BindVS(vertexShaders[VSTYPE_ENVMAP_SKY], threadID); + GetDevice()->BindPS(pixelShaders[PSTYPE_ENVMAP_SKY], threadID); + GetDevice()->BindGS(geometryShaders[GSTYPE_ENVMAP_SKY], threadID); - wiRenderer::graphicsDevice->BindTexturePS(enviroMap, TEXSLOT_ENV_GLOBAL, threadID); + GetDevice()->BindTexturePS(enviroMap, TEXSLOT_ENV_GLOBAL, threadID); - wiRenderer::graphicsDevice->BindVertexBuffer(nullptr, 0, 0, threadID); - wiRenderer::graphicsDevice->BindVertexLayout(nullptr, threadID); - wiRenderer::graphicsDevice->Draw(240, threadID); + GetDevice()->BindVertexBuffer(nullptr, 0, 0, threadID); + GetDevice()->BindVertexLayout(nullptr, threadID); + GetDevice()->Draw(240, threadID); } - wiRenderer::graphicsDevice->BindGS(nullptr, threadID); + GetDevice()->BindGS(nullptr, threadID); probe->cubeMap.Deactivate(threadID); - wiRenderer::graphicsDevice->GenerateMips(probe->cubeMap.GetTexture(), threadID); + GetDevice()->GenerateMips(probe->cubeMap.GetTexture(), threadID); enviroMap = probe->cubeMap.GetTexture(); scene->environmentProbes.push_back(probe); - wiRenderer::graphicsDevice->UNLOCK(); + GetDevice()->UNLOCK(); } void wiRenderer::MaterialCB::Create(const Material& mat,UINT materialIndex){ diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index daa259f9d..938f9e220 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -48,28 +48,23 @@ typedef map MaterialCollection; class wiRenderer { public: + static GraphicsDevice* graphicsDevice; + static GraphicsDevice* GetDevice() { return graphicsDevice; } - static GraphicsDevice* graphicsDevice; #ifndef WINSTORE_SUPPORT - static HRESULT InitDevice(HWND window, int screenW, int screenH, bool windowed); + static void InitDevice(HWND window, int screenW, int screenH, bool windowed); #else - static HRESULT InitDevice(Windows::UI::Core::CoreWindow^ window); + static void InitDevice(Windows::UI::Core::CoreWindow^ window); #endif - static void DestroyDevice(); static void Present(function drawToScreen1=nullptr,function drawToScreen2=nullptr,function drawToScreen3=nullptr); static Sampler samplers[SSLOT_COUNT]; - static int SCREENWIDTH,SCREENHEIGHT; static int SHADOWMAPRES,SOFTSHADOW,POINTLIGHTSHADOW,POINTLIGHTSHADOWRES,SPOTLIGHTSHADOW,SPOTLIGHTSHADOWRES; static bool HAIRPARTICLEENABLED, EMITTERSENABLED; - static int GetScreenWidth(){ return SCREENWIDTH; } - static int GetScreenHeight(){ return SCREENHEIGHT; } - static int SetScreenWidth(int value){ SCREENWIDTH = value; } - static int SetScreenHeight(int value){ SCREENHEIGHT = value; } static void SetDirectionalLightShadowProps(int resolution, int softShadowQuality); static void SetPointLightShadowProps(int shadowMapCount, int resolution); static void SetSpotLightShadowProps(int count, int resolution); diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp index 760b015ec..e2c00b120 100644 --- a/WickedEngine/wiRenderer_BindLua.cpp +++ b/WickedEngine/wiRenderer_BindLua.cpp @@ -233,12 +233,12 @@ namespace wiRenderer_BindLua } int GetScreenWidth(lua_State* L) { - wiLua::SSetInt(L, wiRenderer::SCREENWIDTH); + wiLua::SSetInt(L, wiRenderer::GetDevice()->GetScreenWidth()); return 1; } int GetScreenHeight(lua_State* L) { - wiLua::SSetInt(L, wiRenderer::SCREENHEIGHT); + wiLua::SSetInt(L, wiRenderer::GetDevice()->GetScreenHeight()); return 1; } int GetCamera(lua_State* L) @@ -425,7 +425,7 @@ namespace wiRenderer_BindLua int argc = wiLua::SGetArgCount(L); if (argc > 0) { - wiRenderer::graphicsDevice->SetVSyncEnabled(wiLua::SGetBool(L, 1)); + wiRenderer::GetDevice()->SetVSyncEnabled(wiLua::SGetBool(L, 1)); } return 0; } diff --git a/WickedEngine/wiResourceManager.cpp b/WickedEngine/wiResourceManager.cpp index 6630d629b..bcccad566 100644 --- a/WickedEngine/wiResourceManager.cpp +++ b/WickedEngine/wiResourceManager.cpp @@ -97,13 +97,13 @@ void* wiResourceManager::add(const string& name, Data_Type newType // || !ext.compare("PNG") // ) { - //wiRenderer::graphicsDevice->LOCK(); - wiRenderer::graphicsDevice->CreateTextureFromFile(wstring(name.begin(), name.end()).c_str(), &image, true); - //CreateWICTextureFromFile(true,wiRenderer::graphicsDevice,context,(wchar_t*)(wstring(name.begin(),name.end()).c_str()),nullptr,&image); - //wiRenderer::graphicsDevice->UNLOCK(); + //wiRenderer::GetDevice()->LOCK(); + wiRenderer::GetDevice()->CreateTextureFromFile(wstring(name.begin(), name.end()).c_str(), &image, true); + //CreateWICTextureFromFile(true,wiRenderer::GetDevice(),context,(wchar_t*)(wstring(name.begin(),name.end()).c_str()),nullptr,&image); + //wiRenderer::GetDevice()->UNLOCK(); } //else if(!ext.compare("dds")){ - // CreateDDSTextureFromFile(wiRenderer::graphicsDevice,(wchar_t*)(wstring(name.begin(),name.end()).c_str()),nullptr,&image); + // CreateDDSTextureFromFile(wiRenderer::GetDevice(),(wchar_t*)(wstring(name.begin(),name.end()).c_str()),nullptr,&image); //} if(image) @@ -114,7 +114,7 @@ void* wiResourceManager::add(const string& name, Data_Type newType { APIResource image=nullptr; //if(!ext.compare("dds")){ - // CreateDDSTextureFromFileEx(wiRenderer::graphicsDevice,(wchar_t*)(wstring(name.begin(),name.end()).c_str()),0 + // CreateDDSTextureFromFileEx(wiRenderer::GetDevice(),(wchar_t*)(wstring(name.begin(),name.end()).c_str()),0 // ,USAGE_STAGING,0,CPU_ACCESS_READ | CPU_ACCESS_WRITE,0,false // ,&image,nullptr); //} @@ -140,9 +140,9 @@ void* wiResourceManager::add(const string& name, Data_Type newType size_t bufferSize; if (wiHelper::readByteData(name, &buffer, bufferSize)){ VertexShaderInfo* vertexShaderInfo = new VertexShaderInfo; - wiRenderer::graphicsDevice->CreateVertexShader(buffer, bufferSize, NULL, &vertexShaderInfo->vertexShader); + wiRenderer::GetDevice()->CreateVertexShader(buffer, bufferSize, NULL, &vertexShaderInfo->vertexShader); if (vertexLayoutDesc != nullptr && elementCount > 0){ - wiRenderer::graphicsDevice->CreateInputLayout(vertexLayoutDesc, elementCount, buffer, bufferSize, &vertexShaderInfo->vertexLayout); + wiRenderer::GetDevice()->CreateInputLayout(vertexLayoutDesc, elementCount, buffer, bufferSize, &vertexShaderInfo->vertexLayout); } success = vertexShaderInfo; delete[] buffer; @@ -158,7 +158,7 @@ void* wiResourceManager::add(const string& name, Data_Type newType size_t bufferSize; if (wiHelper::readByteData(name, &buffer, bufferSize)){ PixelShader shader = nullptr; - wiRenderer::graphicsDevice->CreatePixelShader(buffer, bufferSize, nullptr, &shader); + wiRenderer::GetDevice()->CreatePixelShader(buffer, bufferSize, nullptr, &shader); delete[] buffer; success = shader; } @@ -173,9 +173,9 @@ void* wiResourceManager::add(const string& name, Data_Type newType size_t bufferSize; if (wiHelper::readByteData(name, &buffer, bufferSize)){ GeometryShader shader = nullptr; - wiRenderer::graphicsDevice->CreateGeometryShader(buffer, bufferSize, nullptr, &shader); + wiRenderer::GetDevice()->CreateGeometryShader(buffer, bufferSize, nullptr, &shader); if (streamOutDecl != nullptr && elementCount > 0){ - wiRenderer::graphicsDevice->CreateGeometryShaderWithStreamOutput(buffer, bufferSize, streamOutDecl, + wiRenderer::GetDevice()->CreateGeometryShaderWithStreamOutput(buffer, bufferSize, streamOutDecl, elementCount, NULL, 0, shader ? 0 : SO_NO_RASTERIZED_STREAM, NULL, &shader); } delete[] buffer; @@ -192,7 +192,7 @@ void* wiResourceManager::add(const string& name, Data_Type newType size_t bufferSize; if (wiHelper::readByteData(name, &buffer, bufferSize)){ HullShader shader = nullptr; - wiRenderer::graphicsDevice->CreateHullShader(buffer, bufferSize, nullptr, &shader); + wiRenderer::GetDevice()->CreateHullShader(buffer, bufferSize, nullptr, &shader); delete[] buffer; success = shader; } @@ -207,7 +207,7 @@ void* wiResourceManager::add(const string& name, Data_Type newType size_t bufferSize; if (wiHelper::readByteData(name, &buffer, bufferSize)){ DomainShader shader = nullptr; - wiRenderer::graphicsDevice->CreateDomainShader(buffer, bufferSize, nullptr, &shader); + wiRenderer::GetDevice()->CreateDomainShader(buffer, bufferSize, nullptr, &shader); delete[] buffer; success = shader; } diff --git a/WickedEngine/wiTextureHelper.h b/WickedEngine/wiTextureHelper.h index c3123d66a..539f67a28 100644 --- a/WickedEngine/wiTextureHelper.h +++ b/WickedEngine/wiTextureHelper.h @@ -81,12 +81,12 @@ public: //Texture2D* texture2D = nullptr; HRESULT hr; - hr = wiRenderer::graphicsDevice->CreateTexture2D(&textureDesc, &InitData, &texture); + hr = wiRenderer::GetDevice()->CreateTexture2D(&textureDesc, &InitData, &texture); //if (FAILED(hr)) //{ // return hr; //} - //hr = wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D, &shaderResourceViewDesc, &texture); + //hr = wiRenderer::GetDevice()->CreateShaderResourceView(texture2D, &shaderResourceViewDesc, &texture); //SAFE_RELEASE(texture2D); return hr;