diff --git a/WickedEngine.sln b/WickedEngine.sln index c6e510321..382e174fe 100644 --- a/WickedEngine.sln +++ b/WickedEngine.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WickedEngine", "WickedEngine\WickedEngine.vcxproj", "{A94A5B28-B5B0-4386-8281-8AE3C6984762}" EndProject diff --git a/WickedEngine/CommonInclude.h b/WickedEngine/CommonInclude.h index 3f86af12a..9948dc5f4 100644 --- a/WickedEngine/CommonInclude.h +++ b/WickedEngine/CommonInclude.h @@ -37,6 +37,7 @@ using namespace DirectX; using namespace std; #define ALIGN_16 void* operator new(size_t i){return _mm_malloc(i, 16);} void operator delete(void* p){_mm_free(p);} +#define SAFE_INIT(a) a = nullptr; #define SAFE_RELEASE(a) if(a!=nullptr){a->Release();a=nullptr;} #define SAFE_DELETE(a) if(a!=nullptr){delete a;a=nullptr;} #define SAFE_DELETE_ARRAY(a) if(a!=nullptr){delete[]a;a=nullptr;} diff --git a/WickedEngine/DeferredRenderableComponent.cpp b/WickedEngine/DeferredRenderableComponent.cpp index 784ed3c8a..576838edb 100644 --- a/WickedEngine/DeferredRenderableComponent.cpp +++ b/WickedEngine/DeferredRenderableComponent.cpp @@ -61,7 +61,7 @@ void DeferredRenderableComponent::Render() workerThread->wait(); } - wiRenderer::ExecuteDeferredContexts(); + wiRenderer::graphicsDevice->ExecuteDeferredContexts(); } else { @@ -80,37 +80,37 @@ void DeferredRenderableComponent::Render() } -void DeferredRenderableComponent::RenderScene(DeviceContext context){ +void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID){ static const int tessellationQuality = 0; wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); - rtGBuffer.Activate(context); { + rtGBuffer.Activate(threadID); { - wiRenderer::SetClipPlane(XMFLOAT4(0, 0, 0, 0), context); + wiRenderer::SetClipPlane(XMFLOAT4(0, 0, 0, 0), threadID); - wiRenderer::DrawWorld(wiRenderer::getCamera(), wiRenderer::DX11, tessellationQuality, context, false, false + wiRenderer::DrawWorld(wiRenderer::getCamera(), false, tessellationQuality, threadID, false, false , SHADERTYPE_DEFERRED, rtReflection.shaderResource.front(), true, GRAPHICSTHREAD_SCENE); - wiRenderer::DrawSky(context); + wiRenderer::DrawSky(threadID); } - rtLinearDepth.Activate(context); { + rtLinearDepth.Activate(threadID); { fx.blendFlag = BLENDMODE_OPAQUE; fx.sampleFlag = SAMPLEMODE_CLAMP; fx.quality = QUALITY_NEAREST; fx.process.setLinDepth(true); - wiImage::Draw(rtGBuffer.depth->shaderResource, fx, context); + wiImage::Draw(rtGBuffer.depth->shaderResource, fx, threadID); fx.process.clear(); } - rtLinearDepth.Deactivate(context); - dtDepthCopy.CopyFrom(*rtGBuffer.depth, context); + rtLinearDepth.Deactivate(threadID); + dtDepthCopy.CopyFrom(*rtGBuffer.depth, threadID); - wiRenderer::UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, context); + wiRenderer::graphicsDevice->UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID); - wiRenderer::UpdateDepthBuffer(dtDepthCopy.shaderResource, rtLinearDepth.shaderResource.front(), context); + wiRenderer::UpdateDepthBuffer(dtDepthCopy.shaderResource, rtLinearDepth.shaderResource.front(), threadID); if (getStereogramEnabled()) { @@ -119,43 +119,43 @@ void DeferredRenderableComponent::RenderScene(DeviceContext context){ } - rtGBuffer.Set(context); { - wiRenderer::DrawDecals(wiRenderer::getCamera(), context); + rtGBuffer.Set(threadID); { + wiRenderer::DrawDecals(wiRenderer::getCamera(), threadID); } - rtGBuffer.Deactivate(context); + rtGBuffer.Deactivate(threadID); - wiRenderer::UpdateGBuffer(rtGBuffer.shaderResource, context); + wiRenderer::UpdateGBuffer(rtGBuffer.shaderResource, threadID); - rtLight.Activate(context, rtGBuffer.depth); { - wiRenderer::DrawLights(wiRenderer::getCamera(), context); + rtLight.Activate(threadID, rtGBuffer.depth); { + wiRenderer::DrawLights(wiRenderer::getCamera(), threadID); } if (getSSAOEnabled()){ fx.stencilRef = STENCILREF_DEFAULT; - fx.stencilComp = D3D11_COMPARISON_LESS; - rtSSAO[0].Activate(context); { + fx.stencilComp = COMPARISON_LESS; + rtSSAO[0].Activate(threadID); { fx.process.setSSAO(true); //fx.setDepthMap(rtLinearDepth.shaderResource.back()); //fx.setNormalMap(rtGBuffer.shaderResource[1]); fx.setMaskMap(wiTextureHelper::getInstance()->getRandom64x64()); fx.quality = QUALITY_BILINEAR; fx.sampleFlag = SAMPLEMODE_MIRROR; - wiImage::Draw(nullptr, fx, context); + wiImage::Draw(nullptr, fx, threadID); fx.process.clear(); } - rtSSAO[1].Activate(context); { + rtSSAO[1].Activate(threadID); { fx.blur = getSSAOBlur(); fx.blurDir = 0; fx.blendFlag = BLENDMODE_OPAQUE; - wiImage::Draw(rtSSAO[0].shaderResource.back(), fx, context); + wiImage::Draw(rtSSAO[0].shaderResource.back(), fx, threadID); } - rtSSAO[2].Activate(context); { + rtSSAO[2].Activate(threadID); { fx.blur = getSSAOBlur(); fx.blurDir = 1; fx.blendFlag = BLENDMODE_OPAQUE; - wiImage::Draw(rtSSAO[1].shaderResource.back(), fx, context); + wiImage::Draw(rtSSAO[1].shaderResource.back(), fx, threadID); fx.blur = 0; } fx.stencilRef = 0; @@ -163,26 +163,26 @@ void DeferredRenderableComponent::RenderScene(DeviceContext context){ } - rtDeferred.Activate(context); { + rtDeferred.Activate(threadID); { wiImage::DrawDeferred(rtGBuffer.shaderResource[0] , rtLinearDepth.shaderResource.back(), rtLight.shaderResource.front(), rtGBuffer.shaderResource[1] , getSSAOEnabled() ? rtSSAO.back().shaderResource.back() : wiTextureHelper::getInstance()->getWhite() - , context, 0); - wiRenderer::DrawDebugBoneLines(wiRenderer::getCamera(), context); - wiRenderer::DrawDebugLines(wiRenderer::getCamera(), context); - wiRenderer::DrawDebugBoxes(wiRenderer::getCamera(), context); + , threadID, 0); + wiRenderer::DrawDebugBoneLines(wiRenderer::getCamera(), threadID); + wiRenderer::DrawDebugLines(wiRenderer::getCamera(), threadID); + wiRenderer::DrawDebugBoxes(wiRenderer::getCamera(), threadID); } if (getSSSEnabled()) { - //wiRenderer::UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, context); + //wiRenderer::UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID); fx.stencilRef = STENCILREF_SKIN; - fx.stencilComp = D3D11_COMPARISON_LESS; + fx.stencilComp = COMPARISON_LESS; fx.quality = QUALITY_BILINEAR; fx.sampleFlag = SAMPLEMODE_CLAMP; //fx.setDepthMap(rtLinearDepth.shaderResource.back()); for (unsigned int i = 0; iGenerateMips(rtDeferred.shaderResource[0], threadID); fx.process.setSSR(true); //fx.setDepthMap(dtDepthCopy.shaderResource); //fx.setNormalMap(rtGBuffer.shaderResource[1]); //fx.setVelocityMap(rtGBuffer.shaderResource[2]); fx.setMaskMap(rtLinearDepth.shaderResource.front()); if (getSSSEnabled()) - wiImage::Draw(rtSSS.back().shaderResource.front(), fx, context); + wiImage::Draw(rtSSS.back().shaderResource.front(), fx, threadID); else - wiImage::Draw(rtDeferred.shaderResource.front(), fx, context); + wiImage::Draw(rtDeferred.shaderResource.front(), fx, threadID); fx.process.clear(); } } if (getMotionBlurEnabled()){ //MOTIONBLUR - rtMotionBlur.Activate(context); + rtMotionBlur.Activate(threadID); fx.process.setMotionBlur(true); //fx.setVelocityMap(rtGBuffer.shaderResource.back()); //fx.setDepthMap(rtLinearDepth.shaderResource.back()); fx.blendFlag = BLENDMODE_OPAQUE; if (getSSREnabled()){ - wiImage::Draw(rtSSR.shaderResource.front(), fx, context); + wiImage::Draw(rtSSR.shaderResource.front(), fx, threadID); } else if (getSSSEnabled()) { - wiImage::Draw(rtSSS.back().shaderResource.front(), fx, context); + wiImage::Draw(rtSSS.back().shaderResource.front(), fx, threadID); } else{ - wiImage::Draw(rtDeferred.shaderResource.front(), fx, context); + wiImage::Draw(rtDeferred.shaderResource.front(), fx, threadID); } fx.process.clear(); } @@ -266,7 +266,7 @@ void DeferredRenderableComponent::setPreferredThreadingCount(unsigned short valu { Renderable3DComponent::setPreferredThreadingCount(value); - if (!wiRenderer::getMultithreadingSupport()) + if (!wiRenderer::graphicsDevice->GetMultithreadingSupport()) { if (value > 1) wiHelper::messageBox("Multithreaded rendering not supported by your hardware! Falling back to single threading!", "Caution"); @@ -276,101 +276,101 @@ void DeferredRenderableComponent::setPreferredThreadingCount(unsigned short valu switch (value){ case 0: case 1: - wiRenderer::RebindPersistentState(wiRenderer::getImmediateContext()); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_IMMEDIATE); break; case 2: workerThreads.push_back(new wiTaskThread([&] { - RenderFrameSetUp(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - RenderReflections(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); + RenderReflections(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); })); workerThreads.push_back(new wiTaskThread([&] { - RenderShadows(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - RenderScene(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - RenderSecondaryScene(rtGBuffer, GetFinalRT(), wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - RenderLightShafts(rtGBuffer, wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - RenderComposition1(GetFinalRT(), wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - RenderBloom(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - RenderComposition2(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_SCENE); + RenderShadows(GRAPHICSTHREAD_SCENE); + RenderScene(GRAPHICSTHREAD_SCENE); + RenderSecondaryScene(rtGBuffer, GetFinalRT(), GRAPHICSTHREAD_SCENE); + RenderLightShafts(rtGBuffer, GRAPHICSTHREAD_SCENE); + RenderComposition1(GetFinalRT(), GRAPHICSTHREAD_SCENE); + RenderBloom(GRAPHICSTHREAD_SCENE); + RenderComposition2(GRAPHICSTHREAD_SCENE); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); })); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_SCENE); - wiRenderer::ExecuteDeferredContexts(); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_SCENE); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::graphicsDevice->ExecuteDeferredContexts(); break; case 3: workerThreads.push_back(new wiTaskThread([&] { - RenderFrameSetUp(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - RenderReflections(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); + RenderReflections(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); })); workerThreads.push_back(new wiTaskThread([&] { - RenderShadows(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - RenderScene(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_SCENE); + RenderShadows(GRAPHICSTHREAD_SCENE); + RenderScene(GRAPHICSTHREAD_SCENE); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); })); workerThreads.push_back(new wiTaskThread([&] { - RenderSecondaryScene(rtGBuffer, GetFinalRT(), wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - RenderLightShafts(rtGBuffer, wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - RenderComposition1(GetFinalRT(), wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - RenderBloom(wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - RenderComposition2(wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_MISC1); + RenderSecondaryScene(rtGBuffer, GetFinalRT(), GRAPHICSTHREAD_MISC1); + RenderLightShafts(rtGBuffer, GRAPHICSTHREAD_MISC1); + RenderComposition1(GetFinalRT(), GRAPHICSTHREAD_MISC1); + RenderBloom(GRAPHICSTHREAD_MISC1); + RenderComposition2(GRAPHICSTHREAD_MISC1); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC1); })); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_SCENE); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_MISC1); - wiRenderer::ExecuteDeferredContexts(); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_SCENE); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_MISC1); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC1); + wiRenderer::graphicsDevice->ExecuteDeferredContexts(); break; case 4: default: workerThreads.push_back(new wiTaskThread([&] { - RenderFrameSetUp(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - RenderReflections(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); + RenderReflections(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); })); workerThreads.push_back(new wiTaskThread([&] { - RenderShadows(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - RenderScene(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_SCENE); + RenderShadows(GRAPHICSTHREAD_SCENE); + RenderScene(GRAPHICSTHREAD_SCENE); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); })); workerThreads.push_back(new wiTaskThread([&] { - RenderSecondaryScene(rtGBuffer, GetFinalRT(), wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - RenderLightShafts(rtGBuffer, wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - RenderComposition1(GetFinalRT(), wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_MISC1); + RenderSecondaryScene(rtGBuffer, GetFinalRT(), GRAPHICSTHREAD_MISC1); + RenderLightShafts(rtGBuffer, GRAPHICSTHREAD_MISC1); + RenderComposition1(GetFinalRT(), GRAPHICSTHREAD_MISC1); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC1); })); workerThreads.push_back(new wiTaskThread([&] { - RenderBloom(wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC2)); - RenderComposition2(wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC2)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_MISC2); + RenderBloom(GRAPHICSTHREAD_MISC2); + RenderComposition2(GRAPHICSTHREAD_MISC2); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC2); })); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_SCENE); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_MISC1); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC2)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_MISC2); - wiRenderer::ExecuteDeferredContexts(); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_SCENE); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_MISC1); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC1); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_MISC2); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC2); + wiRenderer::graphicsDevice->ExecuteDeferredContexts(); break; }; } diff --git a/WickedEngine/DeferredRenderableComponent.h b/WickedEngine/DeferredRenderableComponent.h index 9db80ea5c..5815a5204 100644 --- a/WickedEngine/DeferredRenderableComponent.h +++ b/WickedEngine/DeferredRenderableComponent.h @@ -8,7 +8,7 @@ class DeferredRenderableComponent : protected: wiRenderTarget rtGBuffer, rtDeferred, rtLight; - virtual void RenderScene(DeviceContext context = wiRenderer::getImmediateContext()); + virtual void RenderScene(GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); wiRenderTarget& GetFinalRT(); public: diff --git a/WickedEngine/ForwardRenderableComponent.cpp b/WickedEngine/ForwardRenderableComponent.cpp index 53b529b8a..4e2df4c41 100644 --- a/WickedEngine/ForwardRenderableComponent.cpp +++ b/WickedEngine/ForwardRenderableComponent.cpp @@ -49,7 +49,7 @@ void ForwardRenderableComponent::Render() workerThread->wait(); } - wiRenderer::ExecuteDeferredContexts(); + wiRenderer::graphicsDevice->ExecuteDeferredContexts(); } else { @@ -68,35 +68,35 @@ void ForwardRenderableComponent::Render() } -void ForwardRenderableComponent::RenderScene(DeviceContext context) +void ForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) { - rtMain.Activate(context, 0, 0, 0, 1); + rtMain.Activate(threadID, 0, 0, 0, 1); { - wiRenderer::SetClipPlane(XMFLOAT4(0, 0, 0, 0), context); + wiRenderer::SetClipPlane(XMFLOAT4(0, 0, 0, 0), threadID); - wiRenderer::DrawWorld(wiRenderer::getCamera(), false, 0, context + wiRenderer::DrawWorld(wiRenderer::getCamera(), false, 0, threadID , false, false, SHADERTYPE_FORWARD_SIMPLE , nullptr, true, GRAPHICSTHREAD_SCENE); - wiRenderer::DrawSky(context); - wiRenderer::DrawDebugBoneLines(wiRenderer::getCamera(), context); - wiRenderer::DrawDebugLines(wiRenderer::getCamera(), context); - wiRenderer::DrawDebugBoxes(wiRenderer::getCamera(), context); + wiRenderer::DrawSky(threadID); + wiRenderer::DrawDebugBoneLines(wiRenderer::getCamera(), threadID); + wiRenderer::DrawDebugLines(wiRenderer::getCamera(), threadID); + wiRenderer::DrawDebugBoxes(wiRenderer::getCamera(), threadID); } - rtLinearDepth.Activate(context); { + rtLinearDepth.Activate(threadID); { wiImageEffects fx; fx.blendFlag = BLENDMODE_OPAQUE; fx.sampleFlag = SAMPLEMODE_CLAMP; fx.quality = QUALITY_NEAREST; fx.process.setLinDepth(true); - //wiImage::BatchBegin(context); - wiImage::Draw(rtMain.depth->shaderResource, fx, context); + //wiImage::BatchBegin(threadID); + wiImage::Draw(rtMain.depth->shaderResource, fx, threadID); } - rtLinearDepth.Deactivate(context); - dtDepthCopy.CopyFrom(*rtMain.depth, context); + rtLinearDepth.Deactivate(threadID); + dtDepthCopy.CopyFrom(*rtMain.depth, threadID); - wiRenderer::UpdateDepthBuffer(dtDepthCopy.shaderResource, rtLinearDepth.shaderResource.front(), context); + wiRenderer::UpdateDepthBuffer(dtDepthCopy.shaderResource, rtLinearDepth.shaderResource.front(), threadID); } @@ -104,7 +104,7 @@ void ForwardRenderableComponent::setPreferredThreadingCount(unsigned short value { Renderable3DComponent::setPreferredThreadingCount(value); - if (!wiRenderer::getMultithreadingSupport()) + if (!wiRenderer::graphicsDevice->GetMultithreadingSupport()) { if (value > 1) wiHelper::messageBox("Multithreaded rendering not supported by your hardware! Falling back to single threading!", "Caution"); @@ -114,101 +114,101 @@ void ForwardRenderableComponent::setPreferredThreadingCount(unsigned short value switch (value) { case 0: case 1: - wiRenderer::RebindPersistentState(wiRenderer::getImmediateContext()); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_IMMEDIATE); break; case 2: workerThreads.push_back(new wiTaskThread([&] { - RenderFrameSetUp(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - RenderReflections(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); + RenderReflections(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); })); workerThreads.push_back(new wiTaskThread([&] { - RenderShadows(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - RenderScene(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - RenderSecondaryScene(rtMain, rtMain, wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - RenderLightShafts(rtMain, wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - RenderComposition1(rtMain, wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - RenderBloom(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - RenderComposition2(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_SCENE); + RenderShadows(GRAPHICSTHREAD_SCENE); + RenderScene(GRAPHICSTHREAD_SCENE); + RenderSecondaryScene(rtMain, rtMain, GRAPHICSTHREAD_SCENE); + RenderLightShafts(rtMain, GRAPHICSTHREAD_SCENE); + RenderComposition1(rtMain, GRAPHICSTHREAD_SCENE); + RenderBloom(GRAPHICSTHREAD_SCENE); + RenderComposition2(GRAPHICSTHREAD_SCENE); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); })); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_SCENE); - wiRenderer::ExecuteDeferredContexts(); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_SCENE); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::graphicsDevice->ExecuteDeferredContexts(); break; case 3: workerThreads.push_back(new wiTaskThread([&] { - RenderFrameSetUp(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - RenderReflections(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); + RenderReflections(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); })); workerThreads.push_back(new wiTaskThread([&] { - RenderShadows(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - RenderScene(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_SCENE); + RenderShadows(GRAPHICSTHREAD_SCENE); + RenderScene(GRAPHICSTHREAD_SCENE); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); })); workerThreads.push_back(new wiTaskThread([&] { - RenderSecondaryScene(rtMain, rtMain, wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - RenderLightShafts(rtMain, wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - RenderComposition1(rtMain, wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - RenderBloom(wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - RenderComposition2(wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_MISC1); + RenderSecondaryScene(rtMain, rtMain, GRAPHICSTHREAD_MISC1); + RenderLightShafts(rtMain, GRAPHICSTHREAD_MISC1); + RenderComposition1(rtMain, GRAPHICSTHREAD_MISC1); + RenderBloom(GRAPHICSTHREAD_MISC1); + RenderComposition2(GRAPHICSTHREAD_MISC1); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC1); })); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_SCENE); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_MISC1); - wiRenderer::ExecuteDeferredContexts(); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_SCENE); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_MISC1); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC1); + wiRenderer::graphicsDevice->ExecuteDeferredContexts(); break; case 4: default: workerThreads.push_back(new wiTaskThread([&] { - RenderFrameSetUp(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - RenderReflections(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); + RenderReflections(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); })); workerThreads.push_back(new wiTaskThread([&] { - RenderShadows(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - RenderScene(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_SCENE); + RenderShadows(GRAPHICSTHREAD_SCENE); + RenderScene(GRAPHICSTHREAD_SCENE); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); })); workerThreads.push_back(new wiTaskThread([&] { - RenderSecondaryScene(rtMain, rtMain, wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - RenderLightShafts(rtMain, wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - RenderComposition1(rtMain, wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_MISC1); + RenderSecondaryScene(rtMain, rtMain, GRAPHICSTHREAD_MISC1); + RenderLightShafts(rtMain, GRAPHICSTHREAD_MISC1); + RenderComposition1(rtMain, GRAPHICSTHREAD_MISC1); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC1); })); workerThreads.push_back(new wiTaskThread([&] { - RenderBloom(wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC2)); - RenderComposition2(wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC2)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_MISC2); + RenderBloom(GRAPHICSTHREAD_MISC2); + RenderComposition2(GRAPHICSTHREAD_MISC2); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC2); })); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_REFLECTIONS)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_SCENE)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_SCENE); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC1)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_MISC1); - wiRenderer::RebindPersistentState(wiRenderer::getDeferredContext(GRAPHICSTHREAD_MISC2)); - wiRenderer::FinishCommandList(GRAPHICSTHREAD_MISC2); - wiRenderer::ExecuteDeferredContexts(); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_SCENE); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_SCENE); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_MISC1); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC1); + wiRenderer::RebindPersistentState(GRAPHICSTHREAD_MISC2); + wiRenderer::graphicsDevice->FinishCommandList(GRAPHICSTHREAD_MISC2); + wiRenderer::graphicsDevice->ExecuteDeferredContexts(); break; }; } diff --git a/WickedEngine/ForwardRenderableComponent.h b/WickedEngine/ForwardRenderableComponent.h index 311598c34..052fcfc95 100644 --- a/WickedEngine/ForwardRenderableComponent.h +++ b/WickedEngine/ForwardRenderableComponent.h @@ -8,7 +8,7 @@ class ForwardRenderableComponent : protected: wiRenderTarget rtMain; - virtual void RenderScene(DeviceContext context = wiRenderer::getImmediateContext()); + virtual void RenderScene(GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); public: ForwardRenderableComponent(); ~ForwardRenderableComponent(); diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index d0e5dd465..7bbd61635 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -130,9 +130,9 @@ void MainComponent::Render() { wiLua::GetGlobal()->Render(); - wiRenderer::Lock(); + wiRenderer::graphicsDevice->LOCK(); getActiveComponent()->Render(); - wiRenderer::Unlock(); + wiRenderer::graphicsDevice->UNLOCK(); } void MainComponent::Compose() diff --git a/WickedEngine/Renderable2DComponent.cpp b/WickedEngine/Renderable2DComponent.cpp index fcb2f90a2..ef66d0130 100644 --- a/WickedEngine/Renderable2DComponent.cpp +++ b/WickedEngine/Renderable2DComponent.cpp @@ -78,7 +78,7 @@ void Renderable2DComponent::Update() } void Renderable2DComponent::Render() { - rtFinal.Activate(wiRenderer::getImmediateContext(), 0, 0, 0, 0); + rtFinal.Activate(GRAPHICSTHREAD_IMMEDIATE, 0, 0, 0, 0); for (auto& x : layers) diff --git a/WickedEngine/Renderable3DComponent.cpp b/WickedEngine/Renderable3DComponent.cpp index 791cbabda..d1bafb820 100644 --- a/WickedEngine/Renderable3DComponent.cpp +++ b/WickedEngine/Renderable3DComponent.cpp @@ -191,18 +191,18 @@ void Renderable3DComponent::Compose(){ Renderable2DComponent::Compose(); } -void Renderable3DComponent::RenderFrameSetUp(DeviceContext context) +void Renderable3DComponent::RenderFrameSetUp(GRAPHICSTHREAD threadID) { if (!_needToUpdateRenderData.load()) { return; } - wiRenderer::UpdateRenderData(context); + wiRenderer::UpdateRenderData(threadID); _needToUpdateRenderData.store(false); } -void Renderable3DComponent::RenderReflections(DeviceContext context) +void Renderable3DComponent::RenderReflections(GRAPHICSTHREAD threadID) { if (getStereogramEnabled()) { @@ -215,7 +215,7 @@ void Renderable3DComponent::RenderReflections(DeviceContext context) return; } - rtReflection.Activate(context); { + rtReflection.Activate(threadID); { // reverse clipping if underwater XMFLOAT4 water = getWaterPlane().getXMFLOAT4(); if (XMVectorGetX(XMPlaneDot(XMLoadFloat4(&getWaterPlane().getXMFLOAT4()), wiRenderer::getCamera()->GetEye())) < 0 ) @@ -225,15 +225,15 @@ void Renderable3DComponent::RenderReflections(DeviceContext context) water.z *= -1; } - wiRenderer::SetClipPlane(water, context); + wiRenderer::SetClipPlane(water, threadID); - wiRenderer::DrawWorld(wiRenderer::getRefCamera(), false, 0, context + wiRenderer::DrawWorld(wiRenderer::getRefCamera(), false, 0, threadID , false, true, SHADERTYPE_NONE , nullptr, getHairParticlesReflectionEnabled(), GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::DrawSky(context,true); + wiRenderer::DrawSky(threadID,true); } } -void Renderable3DComponent::RenderShadows(DeviceContext context) +void Renderable3DComponent::RenderShadows(GRAPHICSTHREAD threadID) { if (getStereogramEnabled()) { @@ -246,10 +246,10 @@ void Renderable3DComponent::RenderShadows(DeviceContext context) return; } - wiRenderer::ClearShadowMaps(context); - wiRenderer::DrawForShadowMap(context); + wiRenderer::ClearShadowMaps(threadID); + wiRenderer::DrawForShadowMap(threadID); } -void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRenderTarget& shadedSceneRT, DeviceContext context) +void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRenderTarget& shadedSceneRT, GRAPHICSTHREAD threadID) { if (getStereogramEnabled()) { @@ -259,40 +259,40 @@ void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRende if (getLensFlareEnabled()) { - rtLensFlare.Activate(context); + rtLensFlare.Activate(threadID); if (!wiRenderer::GetRasterizer()) - wiRenderer::DrawLensFlares(context); + wiRenderer::DrawLensFlares(threadID); } if (getVolumeLightsEnabled()) { - wiRenderer::UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, context); - rtVolumeLight.Activate(context, mainRT.depth); - wiRenderer::DrawVolumeLights(wiRenderer::getCamera(), context); + wiRenderer::graphicsDevice->UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID); + rtVolumeLight.Activate(threadID, mainRT.depth); + wiRenderer::DrawVolumeLights(wiRenderer::getCamera(), threadID); } if (getEmittedParticlesEnabled()) { - rtParticle.Activate(context, 0, 0, 0, 0); //OFFSCREEN RENDER ALPHAPARTICLES - wiRenderer::DrawSoftParticles(wiRenderer::getCamera(), context); + rtParticle.Activate(threadID, 0, 0, 0, 0); //OFFSCREEN RENDER ALPHAPARTICLES + wiRenderer::DrawSoftParticles(wiRenderer::getCamera(), threadID); - rtParticleAdditive.Activate(context, 0, 0, 0, 1); //OFFSCREEN RENDER ADDITIVEPARTICLES - wiRenderer::DrawSoftPremulParticles(wiRenderer::getCamera(), context); + rtParticleAdditive.Activate(threadID, 0, 0, 0, 1); //OFFSCREEN RENDER ADDITIVEPARTICLES + wiRenderer::DrawSoftPremulParticles(wiRenderer::getCamera(), threadID); } - rtWaterRipple.Activate(context, 0, 0, 0, 0); { - wiRenderer::DrawWaterRipples(context); + rtWaterRipple.Activate(threadID, 0, 0, 0, 0); { + wiRenderer::DrawWaterRipples(threadID); } - //wiRenderer::UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, context); - rtTransparent.Activate(context, mainRT.depth); { + //wiRenderer::UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID); + rtTransparent.Activate(threadID, mainRT.depth); { wiRenderer::DrawWorldTransparent(wiRenderer::getCamera(), shadedSceneRT.shaderResource.front(), rtReflection.shaderResource.front() - , rtWaterRipple.shaderResource.back(), context); - wiRenderer::DrawTrails(context, shadedSceneRT.shaderResource.front()); + , rtWaterRipple.shaderResource.back(), threadID); + wiRenderer::DrawTrails(threadID, shadedSceneRT.shaderResource.front()); } } -void Renderable3DComponent::RenderBloom(DeviceContext context) +void Renderable3DComponent::RenderBloom(GRAPHICSTHREAD threadID) { if (getStereogramEnabled()) { @@ -303,36 +303,36 @@ void Renderable3DComponent::RenderBloom(DeviceContext context) wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); - rtBloom[0].Activate(context); + rtBloom[0].Activate(threadID); { fx.bloom.separate = true; fx.bloom.saturation = getBloomSaturation(); fx.bloom.threshold = getBloomThreshold(); fx.blendFlag = BLENDMODE_OPAQUE; fx.sampleFlag = SAMPLEMODE_CLAMP; - wiImage::Draw(rtFinal[0].shaderResource.front(), fx, context); + wiImage::Draw(rtFinal[0].shaderResource.front(), fx, threadID); } - rtBloom[1].Activate(context); //horizontal + rtBloom[1].Activate(threadID); //horizontal { - wiRenderer::GenerateMips(rtBloom[0].shaderResource[0], context); - wiRenderer::GenerateMips(rtBloom[0].shaderResource[0], context); + wiRenderer::graphicsDevice->GenerateMips(rtBloom[0].shaderResource[0], threadID); + //wiRenderer::graphicsDevice->GenerateMips(rtBloom[0].shaderResource[0], threadID); fx.mipLevel = 5.32f; fx.blur = getBloomStrength(); fx.blurDir = 0; fx.blendFlag = BLENDMODE_OPAQUE; - wiImage::Draw(rtBloom[0].shaderResource.back(), fx, context); + wiImage::Draw(rtBloom[0].shaderResource.back(), fx, threadID); } - rtBloom[2].Activate(context); //vertical + rtBloom[2].Activate(threadID); //vertical { fx.blur = getBloomStrength(); fx.blurDir = 1; fx.blendFlag = BLENDMODE_OPAQUE; - wiImage::Draw(rtBloom[1].shaderResource.back(), fx, context); + wiImage::Draw(rtBloom[1].shaderResource.back(), fx, threadID); } } -void Renderable3DComponent::RenderLightShafts(wiRenderTarget& mainRT, DeviceContext context) +void Renderable3DComponent::RenderLightShafts(wiRenderTarget& mainRT, GRAPHICSTHREAD threadID) { if (getStereogramEnabled()) { @@ -352,22 +352,22 @@ void Renderable3DComponent::RenderLightShafts(wiRenderTarget& mainRT, DeviceCont wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); - //wiRenderer::UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, context); - rtSun[0].Activate(context, mainRT.depth); { - wiRenderer::DrawSun(context); + //wiRenderer::UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID); + rtSun[0].Activate(threadID, mainRT.depth); { + wiRenderer::DrawSun(threadID); } - rtSun[1].Activate(context); { + 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()); { XMStoreFloat2(&fxs.sunPos, sunPos); - wiImage::Draw(rtSun[0].shaderResource.back(), fxs, context); + wiImage::Draw(rtSun[0].shaderResource.back(), fxs, threadID); } } } -void Renderable3DComponent::RenderComposition1(wiRenderTarget& shadedSceneRT, DeviceContext context) +void Renderable3DComponent::RenderComposition1(wiRenderTarget& shadedSceneRT, GRAPHICSTHREAD threadID) { if (getStereogramEnabled()) { @@ -378,33 +378,33 @@ void Renderable3DComponent::RenderComposition1(wiRenderTarget& shadedSceneRT, De wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); fx.presentFullScreen = true; - rtFinal[0].Activate(context); + rtFinal[0].Activate(threadID); fx.blendFlag = BLENDMODE_OPAQUE; - wiImage::Draw(shadedSceneRT.shaderResource.front(), fx, context); + wiImage::Draw(shadedSceneRT.shaderResource.front(), fx, threadID); fx.blendFlag = BLENDMODE_ALPHA; - wiImage::Draw(rtTransparent.shaderResource.back(), fx, context); + wiImage::Draw(rtTransparent.shaderResource.back(), fx, threadID); if (getEmittedParticlesEnabled()){ - wiImage::Draw(rtParticle.shaderResource.back(), fx, context); + wiImage::Draw(rtParticle.shaderResource.back(), fx, threadID); } fx.blendFlag = BLENDMODE_ADDITIVE; if (getVolumeLightsEnabled()){ - wiImage::Draw(rtVolumeLight.shaderResource.back(), fx, context); + wiImage::Draw(rtVolumeLight.shaderResource.back(), fx, threadID); } if (getEmittedParticlesEnabled()){ - wiImage::Draw(rtParticleAdditive.shaderResource.back(), fx, context); + wiImage::Draw(rtParticleAdditive.shaderResource.back(), fx, threadID); } if (getLightShaftsEnabled()){ - wiImage::Draw(rtSun.back().shaderResource.back(), fx, context); + wiImage::Draw(rtSun.back().shaderResource.back(), fx, threadID); } if (getLensFlareEnabled()){ - wiImage::Draw(rtLensFlare.shaderResource.back(), fx, context); + wiImage::Draw(rtLensFlare.shaderResource.back(), fx, threadID); } } -void Renderable3DComponent::RenderComposition2(DeviceContext context){ +void Renderable3DComponent::RenderComposition2(GRAPHICSTHREAD threadID){ if (getStereogramEnabled()) { // We don't need the following for stereograms... @@ -417,42 +417,42 @@ void Renderable3DComponent::RenderComposition2(DeviceContext context){ if (getDepthOfFieldEnabled()) { // downsample + blur - rtDof[0].Activate(context); + rtDof[0].Activate(threadID); fx.blur = getDepthOfFieldStrength(); fx.blurDir = 0; - wiImage::Draw(rtFinal[0].shaderResource.back(), fx, context); + wiImage::Draw(rtFinal[0].shaderResource.back(), fx, threadID); - rtDof[1].Activate(context); + rtDof[1].Activate(threadID); fx.blurDir = 1; - wiImage::Draw(rtDof[0].shaderResource.back(), fx, context); + wiImage::Draw(rtDof[0].shaderResource.back(), fx, threadID); fx.blur = 0; fx.process.clear(); // depth of field compose pass - rtDof[2].Activate(context); + rtDof[2].Activate(threadID); fx.process.setDOF(getDepthOfFieldFocus()); fx.setMaskMap(rtDof[1].shaderResource.back()); //fx.setDepthMap(rtLinearDepth.shaderResource.back()); - wiImage::Draw(rtFinal[0].shaderResource.back(), fx, context); + wiImage::Draw(rtFinal[0].shaderResource.back(), fx, threadID); fx.setMaskMap(nullptr); //fx.setDepthMap(nullptr); fx.process.clear(); } - rtFinal[1].Activate(context); + rtFinal[1].Activate(threadID); fx.process.setFXAA(getFXAAEnabled()); if (getDepthOfFieldEnabled()) - wiImage::Draw(rtDof[2].shaderResource.back(), fx, context); + wiImage::Draw(rtDof[2].shaderResource.back(), fx, threadID); else - wiImage::Draw(rtFinal[0].shaderResource.back(), fx, context); + wiImage::Draw(rtFinal[0].shaderResource.back(), fx, threadID); fx.process.clear(); if (getBloomEnabled()) { fx.blendFlag = BLENDMODE_ADDITIVE; fx.presentFullScreen = true; - wiImage::Draw(rtBloom.back().shaderResource.back(), fx, context); + wiImage::Draw(rtBloom.back().shaderResource.back(), fx, threadID); } } void Renderable3DComponent::RenderColorGradedComposition(){ diff --git a/WickedEngine/Renderable3DComponent.h b/WickedEngine/Renderable3DComponent.h index d469c81b9..892247267 100644 --- a/WickedEngine/Renderable3DComponent.h +++ b/WickedEngine/Renderable3DComponent.h @@ -64,15 +64,15 @@ protected: vector workerThreads; - virtual void RenderFrameSetUp(DeviceContext context = wiRenderer::getImmediateContext()); - virtual void RenderReflections(DeviceContext context = wiRenderer::getImmediateContext()); - virtual void RenderShadows(DeviceContext context = wiRenderer::getImmediateContext()); - virtual void RenderScene(DeviceContext context = wiRenderer::getImmediateContext()) = 0; - virtual void RenderSecondaryScene(wiRenderTarget& mainRT, wiRenderTarget& shadedSceneRT, DeviceContext context = wiRenderer::getImmediateContext()); - virtual void RenderBloom(DeviceContext context = wiRenderer::getImmediateContext()); - virtual void RenderLightShafts(wiRenderTarget& mainRT, DeviceContext context = wiRenderer::getImmediateContext()); - virtual void RenderComposition1(wiRenderTarget& shadedSceneRT, DeviceContext context = wiRenderer::getImmediateContext()); - virtual void RenderComposition2(DeviceContext context = wiRenderer::getImmediateContext()); + virtual void RenderFrameSetUp(GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); + virtual void RenderReflections(GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); + virtual void RenderShadows(GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); + virtual void RenderScene(GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void RenderSecondaryScene(wiRenderTarget& mainRT, wiRenderTarget& shadedSceneRT, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); + virtual void RenderBloom(GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); + virtual void RenderLightShafts(wiRenderTarget& mainRT, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); + virtual void RenderComposition1(wiRenderTarget& shadedSceneRT, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); + virtual void RenderComposition2(GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); virtual void RenderColorGradedComposition(); public: inline float getLightShaftQuality(){ return lightShaftQuality; } diff --git a/WickedEngine/WickedEngine.vcxproj b/WickedEngine/WickedEngine.vcxproj index c6463da87..17595b552 100644 --- a/WickedEngine/WickedEngine.vcxproj +++ b/WickedEngine/WickedEngine.vcxproj @@ -294,6 +294,7 @@ + @@ -514,6 +515,7 @@ + diff --git a/WickedEngine/WickedEngine.vcxproj.filters b/WickedEngine/WickedEngine.vcxproj.filters index ae37129d6..9ae47491e 100644 --- a/WickedEngine/WickedEngine.vcxproj.filters +++ b/WickedEngine/WickedEngine.vcxproj.filters @@ -815,6 +815,9 @@ ComponentTemplates + + Source Files + @@ -1804,6 +1807,9 @@ Resource Mapping + + Header Files + diff --git a/WickedEngine/wiCube.cpp b/WickedEngine/wiCube.cpp index 80d94acfb..4b96656cb 100644 --- a/WickedEngine/wiCube.cpp +++ b/WickedEngine/wiCube.cpp @@ -44,13 +44,13 @@ void Cube::SetUpVertices() verts[6].pos=max; verts[7].pos=XMFLOAT3(max.x,min.y,max.z); - D3D11_BUFFER_DESC bd; + BufferDesc bd; ZeroMemory( &bd, sizeof(bd) ); - bd.Usage = D3D11_USAGE_DEFAULT; + bd.Usage = USAGE_DEFAULT; bd.ByteWidth = sizeof( Vertex ) * 8; - bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; + bd.BindFlags = BIND_VERTEX_BUFFER; bd.CPUAccessFlags = 0; - D3D11_SUBRESOURCE_DATA InitData; + SubresourceData InitData; ZeroMemory( &InitData, sizeof(InitData) ); InitData.pSysMem = verts; wiRenderer::graphicsDevice->CreateBuffer( &bd, &InitData, &vertexBuffer ); @@ -66,9 +66,9 @@ void Cube::SetUpVertices() }; ZeroMemory( &bd, sizeof(bd) ); - bd.Usage = D3D11_USAGE_DEFAULT; + bd.Usage = USAGE_DEFAULT; bd.ByteWidth = sizeof( unsigned int ) * 24; - bd.BindFlags = D3D11_BIND_INDEX_BUFFER; + bd.BindFlags = BIND_INDEX_BUFFER; bd.CPUAccessFlags = 0; ZeroMemory( &InitData, sizeof(InitData) ); InitData.pSysMem = indices; diff --git a/WickedEngine/wiDepthTarget.cpp b/WickedEngine/wiDepthTarget.cpp index 679911c1b..7d9ab7e9b 100644 --- a/WickedEngine/wiDepthTarget.cpp +++ b/WickedEngine/wiDepthTarget.cpp @@ -30,8 +30,8 @@ void wiDepthTarget::Initialize(int width, int height, UINT MSAAC, UINT MSAAQ) depthBufferDesc.Format = DXGI_FORMAT_R24G8_TYPELESS; depthBufferDesc.SampleDesc.Count = MSAAC; depthBufferDesc.SampleDesc.Quality = MSAAQ; - depthBufferDesc.Usage = D3D11_USAGE_DEFAULT; - depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE; + depthBufferDesc.Usage = USAGE_DEFAULT; + depthBufferDesc.BindFlags = BIND_DEPTH_STENCIL | BIND_SHADER_RESOURCE; depthBufferDesc.CPUAccessFlags = 0; depthBufferDesc.MiscFlags = 0; @@ -39,23 +39,24 @@ void wiDepthTarget::Initialize(int width, int height, UINT MSAAC, UINT MSAAQ) // Create the texture for the depth buffer using the filled out description. hr=wiRenderer::graphicsDevice->CreateTexture2D(&depthBufferDesc, nullptr, &texture2D); - D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc; + DepthStencilViewDesc depthStencilViewDesc; ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc)); depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; - depthStencilViewDesc.ViewDimension = (MSAAQ==0 ? D3D11_DSV_DIMENSION_TEXTURE2D : D3D11_DSV_DIMENSION_TEXTURE2DMS); - depthStencilViewDesc.Texture2D.MipSlice = 0; + depthStencilViewDesc.ViewDimension = (MSAAQ==0 ? RESOURCE_DIMENSION_TEXTURE2D : RESOURCE_DIMENSION_TEXTURE2DMS); + //depthStencilViewDesc.Texture2D.MipSlice = 0; depthStencilViewDesc.Flags = 0; // Create the depth stencil view. hr=wiRenderer::graphicsDevice->CreateDepthStencilView(texture2D, &depthStencilViewDesc, &depthTarget); //Create Depth ShaderResource - D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc; + //ShaderResourceViewDesc shaderResourceViewDesc; ZeroMemory(&shaderResourceViewDesc, sizeof(shaderResourceViewDesc)); shaderResourceViewDesc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS; - shaderResourceViewDesc.ViewDimension = (MSAAQ==0 ? D3D11_SRV_DIMENSION_TEXTURE2D : D3D11_SRV_DIMENSION_TEXTURE2DMS); - shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; - shaderResourceViewDesc.Texture2D.MipLevels = 1; + shaderResourceViewDesc.ViewDimension = (MSAAQ==0 ? RESOURCE_DIMENSION_TEXTURE2D : RESOURCE_DIMENSION_TEXTURE2DMS); + //shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; + //shaderResourceViewDesc.Texture2D.MipLevels = 1; + shaderResourceViewDesc.mipLevels = 1; wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D, &shaderResourceViewDesc, &shaderResource); } @@ -72,48 +73,50 @@ void wiDepthTarget::InitializeCube(int size) depthBufferDesc.Format = DXGI_FORMAT_R32_TYPELESS; depthBufferDesc.SampleDesc.Count = 1; depthBufferDesc.SampleDesc.Quality = 0; - depthBufferDesc.Usage = D3D11_USAGE_DEFAULT; - depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE; + depthBufferDesc.Usage = USAGE_DEFAULT; + depthBufferDesc.BindFlags = BIND_DEPTH_STENCIL | BIND_SHADER_RESOURCE; depthBufferDesc.CPUAccessFlags = 0; - depthBufferDesc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE; + depthBufferDesc.MiscFlags = RESOURCE_MISC_TEXTURECUBE; HRESULT hr; // Create the texture for the depth buffer using the filled out description. hr=wiRenderer::graphicsDevice->CreateTexture2D(&depthBufferDesc, NULL, &texture2D); - D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc; + DepthStencilViewDesc depthStencilViewDesc; ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc)); depthStencilViewDesc.Format = DXGI_FORMAT_D32_FLOAT; - depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY; - depthStencilViewDesc.Texture2DArray.FirstArraySlice = 0; - depthStencilViewDesc.Texture2DArray.ArraySize = 6; - depthStencilViewDesc.Texture2DArray.MipSlice = 0; + depthStencilViewDesc.ViewDimension = RESOURCE_DIMENSION_TEXTURE2DARRAY; + // depthStencilViewDesc.Texture2DArray.FirstArraySlice = 0; + //depthStencilViewDesc.Texture2DArray.ArraySize = 6; + // depthStencilViewDesc.Texture2DArray.MipSlice = 0; + depthStencilViewDesc.ArraySize = 6; depthStencilViewDesc.Flags = 0; // Create the depth stencil view. hr=wiRenderer::graphicsDevice->CreateDepthStencilView(texture2D, &depthStencilViewDesc, &depthTarget); //Create Depth ShaderResource - D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc; + //ShaderResourceViewDesc shaderResourceViewDesc; ZeroMemory(&shaderResourceViewDesc, sizeof(shaderResourceViewDesc)); shaderResourceViewDesc.Format = DXGI_FORMAT_R32_FLOAT; - shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; - shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; - shaderResourceViewDesc.Texture2D.MipLevels = 1; + shaderResourceViewDesc.ViewDimension = RESOURCE_DIMENSION_TEXTURECUBE; + //shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; + //shaderResourceViewDesc.Texture2D.MipLevels = 1; + shaderResourceViewDesc.mipLevels = 1; wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D, &shaderResourceViewDesc, &shaderResource); } -void wiDepthTarget::Clear(DeviceContext context) +void wiDepthTarget::Clear(GRAPHICSTHREAD threadID) { - context->ClearDepthStencilView( depthTarget, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); + wiRenderer::graphicsDevice->ClearDepthStencil( depthTarget, CLEAR_DEPTH | CLEAR_STENCIL, 1.0f, 0); } -void wiDepthTarget::CopyFrom(const wiDepthTarget& from, DeviceContext context) +void wiDepthTarget::CopyFrom(const wiDepthTarget& from, GRAPHICSTHREAD threadID) { if(shaderResource) shaderResource->Release(); - static D3D11_SHADER_RESOURCE_VIEW_DESC desc; - from.shaderResource->GetDesc(&desc); - context->CopyResource(texture2D,from.texture2D); - HRESULT r = wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D,&desc,&shaderResource); + //static ShaderResourceViewDesc desc; + //from.shaderResource->GetDesc(&desc); + wiRenderer::graphicsDevice->CopyResource(texture2D,from.texture2D); + HRESULT r = wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D,&from.shaderResourceViewDesc,&shaderResource); } diff --git a/WickedEngine/wiDepthTarget.h b/WickedEngine/wiDepthTarget.h index 7f519f64b..441401967 100644 --- a/WickedEngine/wiDepthTarget.h +++ b/WickedEngine/wiDepthTarget.h @@ -9,12 +9,14 @@ public: DepthStencilView depthTarget; TextureView shaderResource; + ShaderResourceViewDesc shaderResourceViewDesc; + wiDepthTarget(); ~wiDepthTarget(); void Initialize(int width, int height, UINT MSAAC, UINT MSAAQ); void InitializeCube(int size); - void Clear(DeviceContext context); - void CopyFrom(const wiDepthTarget&, DeviceContext); + void Clear(GRAPHICSTHREAD threadID); + void CopyFrom(const wiDepthTarget&, GRAPHICSTHREAD threadID); }; diff --git a/WickedEngine/wiEmittedParticle.cpp b/WickedEngine/wiEmittedParticle.cpp index 2925abfff..a3278e345 100644 --- a/WickedEngine/wiEmittedParticle.cpp +++ b/WickedEngine/wiEmittedParticle.cpp @@ -144,8 +144,8 @@ void wiEmittedParticle::Update(float gamespeed) systems.insert(this); - XMFLOAT3 minP=XMFLOAT3(D3D11_FLOAT32_MAX,D3D11_FLOAT32_MAX,D3D11_FLOAT32_MAX) - ,maxP=XMFLOAT3(-D3D11_FLOAT32_MAX,-D3D11_FLOAT32_MAX,-D3D11_FLOAT32_MAX); + XMFLOAT3 minP=XMFLOAT3(FLOAT32_MAX,FLOAT32_MAX,FLOAT32_MAX) + ,maxP=XMFLOAT3(-FLOAT32_MAX,-FLOAT32_MAX,-FLOAT32_MAX); for (unsigned int i = 0; iUpdateLight(); } - //D3D11_MAPPED_SUBRESOURCE mappedResource; + //MAPPED_SUBRESOURCE mappedResource; //Point* vertexPtr; - //wiRenderer::getImmediateContext()->Map(vertexBuffer,0,D3D11_MAP_WRITE_DISCARD,0,&mappedResource); + //GRAPHICSTHREAD_IMMEDIATE->Map(vertexBuffer,0,MAP_WRITE_DISCARD,0,&mappedResource); //vertexPtr = (Point*)mappedResource.pData; //memcpy(vertexPtr,renderPoints.data(),sizeof(Point)* renderPoints.size()); - //wiRenderer::getImmediateContext()->Unmap(vertexBuffer,0); + //GRAPHICSTHREAD_IMMEDIATE->Unmap(vertexBuffer,0); } void wiEmittedParticle::Burst(float num) { @@ -230,7 +230,7 @@ void wiEmittedParticle::Burst(float num) } -void wiEmittedParticle::Draw(Camera* camera, ID3D11DeviceContext *context, int FLAG) +void wiEmittedParticle::Draw(Camera* camera, GRAPHICSTHREAD threadID, int FLAG) { if(!points.empty()){ @@ -238,17 +238,17 @@ void wiEmittedParticle::Draw(Camera* camera, ID3D11DeviceContext *context, int F if(camera->frustum.CheckBox(bounding_box->corners)){ vector renderPoints=vector(points.begin(),points.end()); - wiRenderer::UpdateBuffer(vertexBuffer,renderPoints.data(),context,sizeof(Point)* renderPoints.size()); + wiRenderer::graphicsDevice->UpdateBuffer(vertexBuffer,renderPoints.data(),threadID,sizeof(Point)* renderPoints.size()); bool additive = (material->blendFlag==BLENDMODE_ADDITIVE || material->premultipliedTexture); - wiRenderer::BindPrimitiveTopology(PRIMITIVETOPOLOGY::POINTLIST,context); - wiRenderer::BindVertexLayout(vertexLayout,context); - wiRenderer::BindPS(wireRender?simplestPS:pixelShader,context); - wiRenderer::BindVS(vertexShader,context); - wiRenderer::BindGS(geometryShader,context); + 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::BindTexturePS(depth,1,context); + //wiRenderer::graphicsDevice->BindTexturePS(depth,1,threadID); static thread_local ConstantBuffer* cb = new ConstantBuffer; (*cb).mAdd.x = additive; @@ -256,32 +256,32 @@ void wiEmittedParticle::Draw(Camera* camera, ID3D11DeviceContext *context, int F (*cb).mMotionBlurAmount = motionBlurAmount; - wiRenderer::UpdateBuffer(constantBuffer,cb,context); - wiRenderer::BindConstantBufferGS(constantBuffer, CB_GETBINDSLOT(ConstantBuffer),context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffer,cb,threadID); + wiRenderer::graphicsDevice->BindConstantBufferGS(constantBuffer, CB_GETBINDSLOT(ConstantBuffer),threadID); - wiRenderer::BindRasterizerState(wireRender?wireFrameRS:rasterizerState,context); - wiRenderer::BindDepthStencilState(depthStencilState,1,context); + wiRenderer::graphicsDevice->BindRasterizerState(wireRender?wireFrameRS:rasterizerState,threadID); + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencilState,1,threadID); - wiRenderer::BindBlendState((additive?blendStateAdd:blendStateAlpha),context); + wiRenderer::graphicsDevice->BindBlendState((additive?blendStateAdd:blendStateAlpha),threadID); - wiRenderer::BindVertexBuffer(vertexBuffer,0,sizeof(Point),context); + wiRenderer::graphicsDevice->BindVertexBuffer(vertexBuffer,0,sizeof(Point),threadID); if(!wireRender && material->texture) - wiRenderer::BindTexturePS(material->texture,TEXSLOT_ONDEMAND0,context); - wiRenderer::Draw(renderPoints.size(),context); + wiRenderer::graphicsDevice->BindTexturePS(material->texture,TEXSLOT_ONDEMAND0,threadID); + wiRenderer::graphicsDevice->Draw(renderPoints.size(),threadID); - wiRenderer::BindGS(nullptr,context); + wiRenderer::graphicsDevice->BindGS(nullptr,threadID); } } } -void wiEmittedParticle::DrawPremul(Camera* camera, ID3D11DeviceContext *context, int FLAG){ +void wiEmittedParticle::DrawPremul(Camera* camera, GRAPHICSTHREAD threadID, int FLAG){ if(material->premultipliedTexture) - Draw(camera,context,FLAG); + Draw(camera,threadID,FLAG); } -void wiEmittedParticle::DrawNonPremul(Camera* camera, ID3D11DeviceContext *context, int FLAG){ +void wiEmittedParticle::DrawNonPremul(Camera* camera, GRAPHICSTHREAD threadID, int FLAG){ if(!material->premultipliedTexture) - Draw(camera,context,FLAG); + Draw(camera,threadID,FLAG); } @@ -306,11 +306,11 @@ void wiEmittedParticle::LoadShaders() { VertexLayoutDesc layout[] = { - { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - //{ "TEXCOORD", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "ROTATION", 0, DXGI_FORMAT_R32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "VELOCITY", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + //{ "TEXCOORD", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "ROTATION", 0, DXGI_FORMAT_R32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "VELOCITY", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, }; UINT numElements = ARRAYSIZE(layout); VertexShaderInfo* vsinfo = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "pointspriteVS.cso", wiResourceManager::VERTEXSHADER, layout, numElements)); @@ -330,19 +330,19 @@ void wiEmittedParticle::LoadShaders() } void wiEmittedParticle::SetUpCB() { - D3D11_BUFFER_DESC bd; + BufferDesc bd; ZeroMemory( &bd, sizeof(bd) ); - bd.Usage = D3D11_USAGE_DYNAMIC; + bd.Usage = USAGE_DYNAMIC; bd.ByteWidth = sizeof(ConstantBuffer); - bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + bd.BindFlags = BIND_CONSTANT_BUFFER; + bd.CPUAccessFlags = CPU_ACCESS_WRITE; wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &constantBuffer ); } void wiEmittedParticle::SetUpStates() { - D3D11_RASTERIZER_DESC rs; - rs.FillMode=D3D11_FILL_SOLID; - rs.CullMode=D3D11_CULL_BACK; + RasterizerDesc rs; + rs.FillMode=FILL_SOLID; + rs.CullMode=CULL_BACK; rs.FrontCounterClockwise=true; rs.DepthBias=0; rs.DepthBiasClamp=0; @@ -354,8 +354,8 @@ void wiEmittedParticle::SetUpStates() wiRenderer::graphicsDevice->CreateRasterizerState(&rs,&rasterizerState); - rs.FillMode=D3D11_FILL_WIREFRAME; - rs.CullMode=D3D11_CULL_NONE; + rs.FillMode=FILL_WIREFRAME; + rs.CullMode=CULL_NONE; rs.FrontCounterClockwise=true; rs.DepthBias=0; rs.DepthBiasClamp=0; @@ -370,53 +370,53 @@ void wiEmittedParticle::SetUpStates() - D3D11_DEPTH_STENCIL_DESC dsd; + DepthStencilDesc dsd; dsd.DepthEnable = false; - dsd.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO; - dsd.DepthFunc = D3D11_COMPARISON_LESS; + dsd.DepthWriteMask = DEPTH_WRITE_MASK_ZERO; + dsd.DepthFunc = COMPARISON_LESS; dsd.StencilEnable = false; dsd.StencilReadMask = 0xFF; dsd.StencilWriteMask = 0xFF; // Stencil operations if pixel is front-facing. - dsd.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR; - dsd.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - dsd.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; + dsd.FrontFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.FrontFace.StencilDepthFailOp = STENCIL_OP_INCR; + dsd.FrontFace.StencilPassOp = STENCIL_OP_KEEP; + dsd.FrontFace.StencilFunc = COMPARISON_ALWAYS; // Stencil operations if pixel is back-facing. - dsd.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR; - dsd.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; + dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilDepthFailOp = STENCIL_OP_DECR; + dsd.BackFace.StencilPassOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilFunc = COMPARISON_ALWAYS; // Create the depth stencil state. wiRenderer::graphicsDevice->CreateDepthStencilState(&dsd, &depthStencilState); - D3D11_BLEND_DESC bd; + BlendDesc bd; ZeroMemory(&bd, sizeof(bd)); bd.RenderTarget[0].BlendEnable=true; - bd.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; - bd.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; - bd.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - bd.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; - bd.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; - bd.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlend = BLEND_SRC_ALPHA; + bd.RenderTarget[0].DestBlend = BLEND_INV_SRC_ALPHA; + bd.RenderTarget[0].BlendOp = BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlendAlpha = BLEND_ONE; + bd.RenderTarget[0].DestBlendAlpha = BLEND_INV_SRC_ALPHA; + bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; bd.IndependentBlendEnable=true; wiRenderer::graphicsDevice->CreateBlendState(&bd,&blendStateAlpha); ZeroMemory(&bd, sizeof(bd)); bd.RenderTarget[0].BlendEnable=true; - bd.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; - bd.RenderTarget[0].DestBlend = D3D11_BLEND_ONE; - bd.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - bd.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; - bd.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE; - bd.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlend = BLEND_ONE; + bd.RenderTarget[0].DestBlend = BLEND_ONE; + bd.RenderTarget[0].BlendOp = BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlendAlpha = BLEND_ONE; + bd.RenderTarget[0].DestBlendAlpha = BLEND_ONE; + bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; bd.IndependentBlendEnable=true; wiRenderer::graphicsDevice->CreateBlendState(&bd,&blendStateAdd); @@ -425,12 +425,12 @@ void wiEmittedParticle::LoadVertexBuffer() { vertexBuffer=NULL; - D3D11_BUFFER_DESC bd; + BufferDesc bd; ZeroMemory( &bd, sizeof(bd) ); - bd.Usage = D3D11_USAGE_DYNAMIC; + bd.Usage = USAGE_DYNAMIC; bd.ByteWidth = sizeof( Point ) * MAX_PARTICLES; - bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + bd.BindFlags = BIND_VERTEX_BUFFER; + bd.CPUAccessFlags = CPU_ACCESS_WRITE; wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &vertexBuffer ); } void wiEmittedParticle::SetUpStatic() diff --git a/WickedEngine/wiEmittedParticle.h b/WickedEngine/wiEmittedParticle.h index 425309089..2dd9827f9 100644 --- a/WickedEngine/wiEmittedParticle.h +++ b/WickedEngine/wiEmittedParticle.h @@ -99,9 +99,9 @@ public: #define DRAW_DEFAULT 0 #define DRAW_DARK 1 - void Draw(Camera* camera, ID3D11DeviceContext *context, int FLAG = DRAW_DEFAULT); - void DrawPremul(Camera* camera, ID3D11DeviceContext *context, int FLAG = DRAW_DEFAULT); - void DrawNonPremul(Camera* camera, ID3D11DeviceContext *context, int FLAG = DRAW_DEFAULT); + void Draw(Camera* camera, GRAPHICSTHREAD threadID, int FLAG = DRAW_DEFAULT); + void DrawPremul(Camera* camera, GRAPHICSTHREAD threadID, int FLAG = DRAW_DEFAULT); + void DrawNonPremul(Camera* camera, GRAPHICSTHREAD threadID, int FLAG = DRAW_DEFAULT); void CleanUp(); string name; diff --git a/WickedEngine/wiEnums.h b/WickedEngine/wiEnums.h index b863577f1..aa4157434 100644 --- a/WickedEngine/wiEnums.h +++ b/WickedEngine/wiEnums.h @@ -3,6 +3,7 @@ // deferred context ids enum GRAPHICSTHREAD { + GRAPHICSTHREAD_IMMEDIATE, GRAPHICSTHREAD_REFLECTIONS, GRAPHICSTHREAD_SCENE, GRAPHICSTHREAD_MISC1, diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp index 46404f4d6..f6366aadc 100644 --- a/WickedEngine/wiFont.cpp +++ b/WickedEngine/wiFont.cpp @@ -45,9 +45,9 @@ void wiFont::Initialize() void wiFont::SetUpStates() { - D3D11_RASTERIZER_DESC rs; - rs.FillMode=D3D11_FILL_SOLID; - rs.CullMode=D3D11_CULL_BACK; + RasterizerDesc rs; + rs.FillMode=FILL_SOLID; + rs.CullMode=CULL_BACK; rs.FrontCounterClockwise=TRUE; rs.DepthBias=0; rs.DepthBiasClamp=0; @@ -62,63 +62,63 @@ void wiFont::SetUpStates() - D3D11_DEPTH_STENCIL_DESC dsd; + DepthStencilDesc dsd; dsd.DepthEnable = false; - dsd.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO; - dsd.DepthFunc = D3D11_COMPARISON_LESS; + dsd.DepthWriteMask = DEPTH_WRITE_MASK_ZERO; + dsd.DepthFunc = COMPARISON_LESS; dsd.StencilEnable = false; dsd.StencilReadMask = 0xFF; dsd.StencilWriteMask = 0xFF; // Stencil operations if pixel is front-facing. - dsd.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR; - dsd.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - dsd.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; + dsd.FrontFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.FrontFace.StencilDepthFailOp = STENCIL_OP_INCR; + dsd.FrontFace.StencilPassOp = STENCIL_OP_KEEP; + dsd.FrontFace.StencilFunc = COMPARISON_ALWAYS; // Stencil operations if pixel is back-facing. - dsd.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR; - dsd.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; + dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilDepthFailOp = STENCIL_OP_DECR; + dsd.BackFace.StencilPassOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilFunc = COMPARISON_ALWAYS; // Create the depth stencil state. wiRenderer::graphicsDevice->CreateDepthStencilState(&dsd, &depthStencilState); - D3D11_BLEND_DESC bd; + BlendDesc bd; ZeroMemory(&bd, sizeof(bd)); bd.RenderTarget[0].BlendEnable = TRUE; - bd.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; - bd.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; - bd.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - bd.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; - bd.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; - bd.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlend = BLEND_SRC_ALPHA; + bd.RenderTarget[0].DestBlend = BLEND_INV_SRC_ALPHA; + bd.RenderTarget[0].BlendOp = BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlendAlpha = BLEND_ONE; + 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); } void wiFont::SetUpCB() { - D3D11_BUFFER_DESC bd; + BufferDesc bd; ZeroMemory( &bd, sizeof(bd) ); - bd.Usage = D3D11_USAGE_DYNAMIC; + bd.Usage = USAGE_DYNAMIC; bd.ByteWidth = sizeof(ConstantBuffer); - bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + bd.BindFlags = BIND_CONSTANT_BUFFER; + bd.CPUAccessFlags = CPU_ACCESS_WRITE; wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &constantBuffer ); - BindPersistentState(wiRenderer::getImmediateContext()); + BindPersistentState(GRAPHICSTHREAD_IMMEDIATE); } void wiFont::LoadShaders() { VertexLayoutDesc layout[] = { - { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, }; UINT numElements = ARRAYSIZE(layout); VertexShaderInfo* vsinfo = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "fontVS.cso", wiResourceManager::VERTEXSHADER, layout, numElements)); @@ -157,17 +157,17 @@ void wiFont::CleanUpStatic() if(depthStencilState) depthStencilState->Release(); depthStencilState=NULL; } -void wiFont::BindPersistentState(DeviceContext context) +void wiFont::BindPersistentState(GRAPHICSTHREAD threadID) { - wiRenderer::Lock(); + wiRenderer::graphicsDevice->LOCK(); - wiRenderer::BindConstantBufferVS(constantBuffer, CB_GETBINDSLOT(ConstantBuffer), context); + wiRenderer::graphicsDevice->BindConstantBufferVS(constantBuffer, CB_GETBINDSLOT(ConstantBuffer), threadID); - wiRenderer::Unlock(); + wiRenderer::graphicsDevice->UNLOCK(); } -void wiFont::ModifyGeo(const wstring& text, wiFontProps props, int style, DeviceContext context) +void wiFont::ModifyGeo(const wstring& text, wiFontProps props, int style, GRAPHICSTHREAD threadID) { int line = 0, pos = 0; vertexList.resize(text.length()*4); @@ -214,18 +214,18 @@ void wiFont::ModifyGeo(const wstring& text, wiFontProps props, int style, Device } } - wiRenderer::UpdateBuffer(vertexBuffer,vertexList.data(),context==nullptr?wiRenderer::getImmediateContext():context,sizeof(Vertex) * text.length() * 4); + wiRenderer::graphicsDevice->UpdateBuffer(vertexBuffer,vertexList.data(),threadID,sizeof(Vertex) * text.length() * 4); } void wiFont::LoadVertexBuffer() { - D3D11_BUFFER_DESC bd; + BufferDesc bd; ZeroMemory( &bd, sizeof(bd) ); - bd.Usage = D3D11_USAGE_DYNAMIC; + bd.Usage = USAGE_DYNAMIC; bd.ByteWidth = sizeof( Vertex ) * MAX_TEXT * 4; - bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + bd.BindFlags = BIND_VERTEX_BUFFER; + bd.CPUAccessFlags = CPU_ACCESS_WRITE; wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &vertexBuffer ); } void wiFont::LoadIndices() @@ -241,19 +241,19 @@ void wiFont::LoadIndices() indices[i/4*6+5]=i/4*4+3; } - D3D11_BUFFER_DESC bd; + BufferDesc bd; ZeroMemory( &bd, sizeof(bd) ); - bd.Usage = D3D11_USAGE_DEFAULT; + bd.Usage = USAGE_DEFAULT; bd.ByteWidth = sizeof( unsigned long ) * MAX_TEXT * 6; - bd.BindFlags = D3D11_BIND_INDEX_BUFFER; + bd.BindFlags = BIND_INDEX_BUFFER; bd.CPUAccessFlags = 0; - D3D11_SUBRESOURCE_DATA InitData; + SubresourceData InitData; ZeroMemory( &InitData, sizeof(InitData) ); InitData.pSysMem = indices.data(); wiRenderer::graphicsDevice->CreateBuffer( &bd, &InitData, &indexBuffer ); } -void wiFont::Draw(DeviceContext context){ +void wiFont::Draw(GRAPHICSTHREAD threadID){ wiFontProps newProps = props; @@ -267,19 +267,14 @@ void wiFont::Draw(DeviceContext context){ newProps.posY += textHeight(); - ModifyGeo(text, newProps, style, context); + ModifyGeo(text, newProps, style, threadID); if(text.length()>0){ - - if(context==nullptr) - context=wiRenderer::getImmediateContext(); - if (context == nullptr) - return; - wiRenderer::BindPrimitiveTopology(PRIMITIVETOPOLOGY::TRIANGLELIST,context); - wiRenderer::BindVertexLayout(vertexLayout,context); - wiRenderer::BindVS(vertexShader,context); - wiRenderer::BindPS(pixelShader,context); + wiRenderer::graphicsDevice->BindPrimitiveTopology(PRIMITIVETOPOLOGY::TRIANGLELIST,threadID); + wiRenderer::graphicsDevice->BindVertexLayout(vertexLayout,threadID); + wiRenderer::graphicsDevice->BindVS(vertexShader,threadID); + wiRenderer::graphicsDevice->BindPS(pixelShader,threadID); static thread_local ConstantBuffer* cb = new ConstantBuffer; @@ -287,18 +282,18 @@ void wiFont::Draw(DeviceContext context){ (*cb).mTrans = XMMatrixTranspose(XMMatrixTranslation(newProps.posX, newProps.posY, 0)); (*cb).mDimensions = XMFLOAT4((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight(), 0, 0); - wiRenderer::UpdateBuffer(constantBuffer,cb,context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffer,cb,threadID); - wiRenderer::BindRasterizerState(rasterizerState,context); - wiRenderer::BindDepthStencilState(depthStencilState,1,context); + wiRenderer::graphicsDevice->BindRasterizerState(rasterizerState,threadID); + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencilState,1,threadID); - wiRenderer::BindBlendState(blendState,context); - wiRenderer::BindVertexBuffer(vertexBuffer,0,sizeof(Vertex),context); - wiRenderer::BindIndexBuffer(indexBuffer,context); + wiRenderer::graphicsDevice->BindBlendState(blendState,threadID); + wiRenderer::graphicsDevice->BindVertexBuffer(vertexBuffer,0,sizeof(Vertex),threadID); + wiRenderer::graphicsDevice->BindIndexBuffer(indexBuffer,threadID); - wiRenderer::BindTexturePS(fontStyles[style].texture,TEXSLOT_ONDEMAND0,context); - wiRenderer::DrawIndexed(text.length()*6,context); + wiRenderer::graphicsDevice->BindTexturePS(fontStyles[style].texture,TEXSLOT_ONDEMAND0,threadID); + wiRenderer::graphicsDevice->DrawIndexed(text.length()*6,threadID); } } @@ -356,7 +351,7 @@ string wiFont::GetTextA() wiFont::wiFontStyle::wiFontStyle(const string& newName){ - wiRenderer::Lock(); + wiRenderer::graphicsDevice->LOCK(); name=newName; @@ -383,7 +378,7 @@ wiFont::wiFontStyle::wiFontStyle(const string& newName){ wiHelper::messageBox(name,"Could not load Font Data!"); } - wiRenderer::Unlock(); + wiRenderer::graphicsDevice->UNLOCK(); } void wiFont::wiFontStyle::CleanUp(){ SAFE_RELEASE(texture); diff --git a/WickedEngine/wiFont.h b/WickedEngine/wiFont.h index ddb27f787..2cf76436a 100644 --- a/WickedEngine/wiFont.h +++ b/WickedEngine/wiFont.h @@ -67,7 +67,7 @@ protected: static void SetUpCB(); public: static void LoadShaders(); - static void BindPersistentState(DeviceContext context); + static void BindPersistentState(GRAPHICSTHREAD threadID); private: static void LoadVertexBuffer(); static void LoadIndices(); @@ -92,7 +92,7 @@ private: static vector fontStyles; - static void ModifyGeo(const wstring& text, wiFontProps props, int style, DeviceContext context = nullptr); + static void ModifyGeo(const wstring& text, wiFontProps props, int style, GRAPHICSTHREAD threadID); public: static void Initialize(); @@ -108,7 +108,7 @@ public: ~wiFont(); - void Draw(DeviceContext context = nullptr); + void Draw(GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); int textWidth(); diff --git a/WickedEngine/wiGraphicsAPI.h b/WickedEngine/wiGraphicsAPI.h index 5e485fe3d..8888e3bf1 100644 --- a/WickedEngine/wiGraphicsAPI.h +++ b/WickedEngine/wiGraphicsAPI.h @@ -1,5 +1,7 @@ #pragma once #include "CommonInclude.h" +#include "wiThreadSafeManager.h" +#include "wiEnums.h" #include #include @@ -14,8 +16,7 @@ typedef IDXGISwapChain1* SwapChain; #endif typedef IUnknown* APIInterface; typedef ID3D11DeviceContext* DeviceContext; -typedef ID3D11Device* GraphicsDevice; -typedef D3D11_VIEWPORT ViewPort; +//typedef ID3D11Device* GraphicsDevice; typedef ID3D11CommandList* CommandList; typedef ID3D11RenderTargetView* RenderTargetView; typedef ID3D11ShaderResourceView* TextureView; @@ -30,21 +31,353 @@ typedef ID3D11HullShader* HullShader; typedef ID3D11DomainShader* DomainShader; typedef ID3D11ComputeShader* ComputeShader; typedef ID3D11InputLayout* VertexLayout; -typedef D3D11_INPUT_ELEMENT_DESC VertexLayoutDesc; typedef ID3D11BlendState* BlendState; typedef ID3D11DepthStencilState* DepthStencilState; typedef ID3D11DepthStencilView* DepthStencilView; typedef ID3D11RasterizerState* RasterizerState; -typedef D3D11_SO_DECLARATION_ENTRY StreamOutDeclaration; -typedef D3D11_TEXTURE2D_DESC Texture2DDesc; +typedef ID3D11ClassLinkage* ClassLinkage; -enum PRIMITIVETOPOLOGY { - TRIANGLELIST = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, - TRIANGLESTRIP = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, - POINTLIST = D3D11_PRIMITIVE_TOPOLOGY_POINTLIST, - LINELIST = D3D11_PRIMITIVE_TOPOLOGY_LINELIST, - PATCHLIST = D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST, + +enum PRIMITIVETOPOLOGY +{ + TRIANGLELIST, + TRIANGLESTRIP, + POINTLIST, + LINELIST, + PATCHLIST, +}; +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, +}; +enum DEPTH_WRITE_MASK +{ + DEPTH_WRITE_MASK_ZERO = D3D11_DEPTH_WRITE_MASK_ZERO, + DEPTH_WRITE_MASK_ALL = D3D11_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, +}; +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, +}; +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), +}; +enum FILL_MODE +{ + FILL_WIREFRAME = D3D11_FILL_WIREFRAME, + FILL_SOLID = D3D11_FILL_SOLID, +}; +enum CULL_MODE +{ + CULL_NONE = D3D11_CULL_NONE, + CULL_FRONT = D3D11_CULL_FRONT, + CULL_BACK = D3D11_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, +}; +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, +}; +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, +}; +enum RESOURCE_DIMENSION +{ + RESOURCE_DIMENSION_UNKNOWN = D3D_SRV_DIMENSION_UNKNOWN, + RESOURCE_DIMENSION_BUFFER = D3D_SRV_DIMENSION_BUFFER, + RESOURCE_DIMENSION_TEXTURE1D = D3D_SRV_DIMENSION_TEXTURE1D, + RESOURCE_DIMENSION_TEXTURE1DARRAY = D3D_SRV_DIMENSION_TEXTURE1DARRAY, + RESOURCE_DIMENSION_TEXTURE2D = D3D_SRV_DIMENSION_TEXTURE2D, + RESOURCE_DIMENSION_TEXTURE2DARRAY = D3D_SRV_DIMENSION_TEXTURE2DARRAY, + RESOURCE_DIMENSION_TEXTURE2DMS = D3D_SRV_DIMENSION_TEXTURE2DMS, + RESOURCE_DIMENSION_TEXTURE2DMSARRAY = D3D_SRV_DIMENSION_TEXTURE2DMSARRAY, + RESOURCE_DIMENSION_TEXTURE3D = D3D_SRV_DIMENSION_TEXTURE3D, + RESOURCE_DIMENSION_TEXTURECUBE = D3D_SRV_DIMENSION_TEXTURECUBE, + RESOURCE_DIMENSION_TEXTURECUBEARRAY = D3D_SRV_DIMENSION_TEXTURECUBEARRAY, + RESOURCE_DIMENSION_BUFFEREX = D3D_SRV_DIMENSION_BUFFEREX +}; +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, +}; +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, +}; + +#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 + +struct ViewPort +{ + FLOAT TopLeftX; + FLOAT TopLeftY; + FLOAT Width; + FLOAT Height; + FLOAT MinDepth; + FLOAT MaxDepth; +}; +struct VertexLayoutDesc +{ + LPCSTR SemanticName; + UINT SemanticIndex; + DXGI_FORMAT Format; + UINT InputSlot; + UINT AlignedByteOffset; + INPUT_CLASSIFICATION InputSlotClass; + UINT InstanceDataStepRate; +}; +struct StreamOutDeclaration +{ + UINT Stream; + LPCSTR SemanticName; + UINT SemanticIndex; + BYTE StartComponent; + BYTE ComponentCount; + BYTE OutputSlot; +}; +struct Texture2DDesc +{ + UINT Width; + UINT Height; + UINT MipLevels; + UINT ArraySize; + DXGI_FORMAT Format; + DXGI_SAMPLE_DESC SampleDesc; + USAGE Usage; + UINT BindFlags; + UINT CPUAccessFlags; + UINT MiscFlags; +}; +struct ShaderResourceViewDesc +{ + DXGI_FORMAT Format; + RESOURCE_DIMENSION ViewDimension; + UINT mipLevels; +}; +struct RenderTargetViewDesc +{ + DXGI_FORMAT Format; + RESOURCE_DIMENSION ViewDimension; + UINT ArraySize; +}; +struct DepthStencilViewDesc +{ + DXGI_FORMAT Format; + RESOURCE_DIMENSION ViewDimension; + UINT Flags; + UINT ArraySize; +}; +struct SamplerDesc +{ + FILTER Filter; + TEXTURE_ADDRESS_MODE AddressU; + TEXTURE_ADDRESS_MODE AddressV; + TEXTURE_ADDRESS_MODE AddressW; + FLOAT MipLODBias; + UINT MaxAnisotropy; + COMPARISON_FUNC ComparisonFunc; + FLOAT BorderColor[4]; + FLOAT MinLOD; + FLOAT MaxLOD; +}; +struct RasterizerDesc +{ + FILL_MODE FillMode; + CULL_MODE CullMode; + BOOL FrontCounterClockwise; + INT DepthBias; + FLOAT DepthBiasClamp; + FLOAT SlopeScaledDepthBias; + BOOL DepthClipEnable; + BOOL ScissorEnable; + BOOL MultisampleEnable; + BOOL AntialiasedLineEnable; +}; +struct DepthStencilOpDesc +{ + STENCIL_OP StencilFailOp; + STENCIL_OP StencilDepthFailOp; + STENCIL_OP StencilPassOp; + COMPARISON_FUNC StencilFunc; +}; +struct DepthStencilDesc +{ + BOOL DepthEnable; + DEPTH_WRITE_MASK DepthWriteMask; + COMPARISON_FUNC DepthFunc; + BOOL StencilEnable; + UINT8 StencilReadMask; + UINT8 StencilWriteMask; + DepthStencilOpDesc FrontFace; + DepthStencilOpDesc BackFace; +}; +struct RenderTargetBlendDesc +{ + BOOL BlendEnable; + BLEND SrcBlend; + BLEND DestBlend; + BLEND_OP BlendOp; + BLEND SrcBlendAlpha; + BLEND DestBlendAlpha; + BLEND_OP BlendOpAlpha; + UINT8 RenderTargetWriteMask; +}; +struct BlendDesc +{ + BOOL AlphaToCoverageEnable; + BOOL IndependentBlendEnable; + RenderTargetBlendDesc RenderTarget[8]; +}; +struct BufferDesc +{ + UINT ByteWidth; + USAGE Usage; + UINT BindFlags; + UINT CPUAccessFlags; + UINT MiscFlags; + UINT StructureByteStride; +}; +struct SubresourceData +{ + const void *pSysMem; + UINT SysMemPitch; + UINT SysMemSlicePitch; }; struct VertexShaderInfo { @@ -57,4 +390,117 @@ struct VertexShaderInfo { } }; +class GraphicsDevice : public wiThreadSafeManager +{ +public: + 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; + virtual HRESULT CreateTexture3D() = 0; + virtual HRESULT CreateShaderResourceView(APIResource pResource, const ShaderResourceViewDesc* pDesc, TextureView *ppSRView) = 0; + virtual HRESULT CreateUnorderedAccessView() = 0; + virtual HRESULT CreateRenderTargetView(APIResource pResource, const RenderTargetViewDesc* pDesc, RenderTargetView *ppRTView) = 0; + virtual HRESULT CreateDepthStencilView(APIResource pResource, const DepthStencilViewDesc* pDesc, DepthStencilView *ppDepthStencilView) = 0; + virtual HRESULT CreateInputLayout(const VertexLayoutDesc *pInputElementDescs, UINT NumElements, + const void *pShaderBytecodeWithInputSignature, SIZE_T BytecodeLength, VertexLayout *ppInputLayout) = 0; + virtual HRESULT CreateVertexShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, VertexShader *ppVertexShader) = 0; + virtual HRESULT CreatePixelShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, PixelShader *ppPixelShader) = 0; + virtual HRESULT CreateGeometryShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, GeometryShader *ppGeometryShader) = 0; + virtual HRESULT CreateGeometryShaderWithStreamOutput( const void *pShaderBytecode, SIZE_T BytecodeLength, const StreamOutDeclaration *pSODeclaration, + UINT NumEntries, const UINT *pBufferStrides, UINT NumStrides, UINT RasterizedStream, ClassLinkage pClassLinkage, GeometryShader *ppGeometryShader) = 0; + virtual HRESULT CreateHullShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, HullShader *ppHullShader) = 0; + virtual HRESULT CreateDomainShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, DomainShader *ppDomainShader) = 0; + virtual HRESULT CreateComputeShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, ComputeShader *ppComputeShader) = 0; + virtual HRESULT CreateClassLinkage() = 0; + virtual HRESULT CreateBlendState(const BlendDesc *pBlendStateDesc, BlendState *ppBlendState) = 0; + virtual HRESULT CreateDepthStencilState(const DepthStencilDesc *pDepthStencilDesc, DepthStencilState *ppDepthStencilState) = 0; + virtual HRESULT CreateRasterizerState(const RasterizerDesc *pRasterizerDesc, RasterizerState *ppRasterizerState) = 0; + virtual HRESULT CreateSamplerState(const SamplerDesc *pSamplerDesc, Sampler *ppSamplerState) = 0; + virtual HRESULT CreateQuery() = 0; + virtual HRESULT CreatePredicate() = 0; + virtual HRESULT CreateDeferredContext(UINT ContextFlags, DeviceContext *ppDeferredContext) = 0; + virtual HRESULT OpenSharedResource() = 0; + virtual HRESULT CheckFormatSupport() = 0; + virtual HRESULT CheckMultiSampleQualityLevels() = 0; + virtual HRESULT CheckCounterInfo() = 0; + virtual HRESULT CheckCounter() = 0; + virtual HRESULT CheckFeatureSupport() = 0; + virtual HRESULT GetPrivateData() = 0; + virtual HRESULT SetPrivateData() = 0; + virtual HRESULT SetPrivateDataInterface() = 0; + virtual UINT GetCreationFlags() = 0; + virtual HRESULT GetDeviceRemovedReason() = 0; + virtual DeviceContext GetImmediateContext() = 0; + + virtual void PresentBegin() = 0; + virtual void PresentEnd() = 0; + + virtual void ExecuteDeferredContexts() = 0; + virtual void FinishCommandList(GRAPHICSTHREAD thread) = 0; + + virtual bool GetMultithreadingSupport() = 0; + virtual DeviceContext GetDeferredContext(GRAPHICSTHREAD thread) = 0; + + virtual bool GetVSyncEnabled() = 0; + virtual void SetVSyncEnabled(bool value) = 0; + + ///////////////Thread-sensitive//////////////////////// + + virtual void BindViewports(UINT NumViewports, const ViewPort *pViewports, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindRenderTargets(UINT NumViews, RenderTargetView const *ppRenderTargetViews, DepthStencilView pDepthStencilView, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void ClearRenderTarget(RenderTargetView pRenderTargetView, const FLOAT ColorRGBA[4], GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void ClearDepthStencil(DepthStencilView pDepthStencilView, UINT ClearFlags, FLOAT Depth, UINT8 Stencil, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindTexturePS(TextureView texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindTexturesPS(TextureView textures[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindTextureVS(TextureView texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindTexturesVS(TextureView textures[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindTextureGS(TextureView texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindTexturesGS(TextureView textures[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindTextureDS(TextureView texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindTexturesDS(TextureView textures[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindTextureHS(TextureView texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindTexturesHS(TextureView textures[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void UnbindTextures(int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindSamplerPS(Sampler sampler, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindSamplersPS(Sampler samplers[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindSamplerVS(Sampler sampler, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindSamplersVS(Sampler samplers[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindSamplerGS(Sampler sampler, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindSamplersGS(Sampler samplers[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindSamplerHS(Sampler sampler, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindSamplersHS(Sampler samplers[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindSamplerDS(Sampler sampler, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindSamplersDS(Sampler samplers[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindConstantBufferPS(BufferResource buffer, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindConstantBufferVS(BufferResource buffer, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindConstantBufferGS(BufferResource buffer, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindConstantBufferDS(BufferResource buffer, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindConstantBufferHS(BufferResource buffer, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindVertexBuffer(BufferResource vertexBuffer, int slot, UINT stride, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindIndexBuffer(BufferResource indexBuffer, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindPrimitiveTopology(PRIMITIVETOPOLOGY type, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindVertexLayout(VertexLayout layout, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindBlendState(BlendState state, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindBlendStateEx(BlendState state, const XMFLOAT4& blendFactor = XMFLOAT4(1, 1, 1, 1), UINT sampleMask = 0xffffffff, + GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindDepthStencilState(DepthStencilState state, UINT stencilRef, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindRasterizerState(RasterizerState state, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindStreamOutTarget(BufferResource buffer, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindPS(PixelShader shader, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindVS(VertexShader shader, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindGS(GeometryShader shader, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindHS(HullShader shader, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindDS(DomainShader shader, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void Draw(int vertexCount, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void DrawIndexed(int indexCount, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void DrawIndexedInstanced(int indexCount, int instanceCount, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void GenerateMips(TextureView texture, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void CopyResource(APIResource pDstResource, APIResource pSrcResource, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void UpdateBuffer(BufferResource& buffer, const void* data, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE, int dataSize = -1) = 0; + + virtual HRESULT CreateTextureFromFile(const wstring& fileName, TextureView *ppShaderResourceView, bool mipMaps = true, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + +}; + + diff --git a/WickedEngine/wiGraphicsAPI_DX11.cpp b/WickedEngine/wiGraphicsAPI_DX11.cpp new file mode 100644 index 000000000..b20636185 --- /dev/null +++ b/WickedEngine/wiGraphicsAPI_DX11.cpp @@ -0,0 +1,313 @@ +#include "CommonInclude.h" +#include "wiGraphicsAPI_DX11.h" +#include "wiHelper.h" +#include "TextureMapping.h" + +#include "Utility/WicTextureLoader.h" +#include "Utility/DDSTextureLoader.h" + +GraphicsDevice_DX11::GraphicsDevice_DX11(HWND window, int screenW, int screenH, bool windowed) +{ + HRESULT hr = S_OK; + + UINT createDeviceFlags = 0; +#ifdef _DEBUG + createDeviceFlags |= CREATE_DEVICE_DEBUG; +#endif + + D3D_DRIVER_TYPE driverTypes[] = + { + D3D_DRIVER_TYPE_HARDWARE, + D3D_DRIVER_TYPE_WARP, + D3D_DRIVER_TYPE_REFERENCE, + }; + UINT numDriverTypes = ARRAYSIZE(driverTypes); + + D3D_FEATURE_LEVEL featureLevels[] = + { + D3D_FEATURE_LEVEL_11_1, + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, + //D3D_FEATURE_LEVEL_10_0, + }; + UINT numFeatureLevels = ARRAYSIZE(featureLevels); + +#ifndef WINSTORE_SUPPORT + DXGI_SWAP_CHAIN_DESC sd; + ZeroMemory(&sd, sizeof(sd)); + sd.BufferCount = 2; + sd.BufferDesc.Width = screenW; + sd.BufferDesc.Height = screenH; + sd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; + sd.BufferDesc.RefreshRate.Numerator = 60; + sd.BufferDesc.RefreshRate.Denominator = 1; + sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + sd.OutputWindow = window; + sd.SampleDesc.Count = 1; + sd.SampleDesc.Quality = 0; + sd.Windowed = windowed; +#endif + + for (UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++) + { + driverType = driverTypes[driverTypeIndex]; +#ifndef WINSTORE_SUPPORT + hr = D3D11CreateDeviceAndSwapChain(NULL, driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels, + D3D11_SDK_VERSION, &sd, &swapChain, &device, &featureLevel, &deviceContexts[GRAPHICSTHREAD_IMMEDIATE]); +#else + hr = D3D11CreateDevice(nullptr, driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels, SDK_VERSION, &graphicsDevice + , &featureLevel, &immediateContext); +#endif + + if (SUCCEEDED(hr)) + break; + } + if (FAILED(hr)) { + wiHelper::messageBox("SwapChain Creation Failed!", "Error!", nullptr); +#ifdef BACKLOG + wiBackLog::post("SwapChain Creation Failed!"); +#endif + exit(1); + } + DX11 = ((device->GetFeatureLevel() >= D3D_FEATURE_LEVEL_11_0) ? true : false); + + +#ifdef WINSTORE_SUPPORT + DXGI_SWAP_CHAIN_DESC1 sd = { 0 }; + sd.Width = SCREENWIDTH = (int)window->Bounds.Width; + sd.Height = SCREENHEIGHT = (int)window->Bounds.Height; + sd.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // This is the most common swap chain format. + sd.Stereo = false; + sd.SampleDesc.Count = 1; // Don't use multi-sampling. + sd.SampleDesc.Quality = 0; + sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + sd.BufferCount = 2; // Use double-buffering to minimize latency. + sd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Windows Store apps must use this SwapEffect. + sd.Flags = 0; + sd.Scaling = DXGI_SCALING_NONE; + sd.AlphaMode = DXGI_ALPHA_MODE_IGNORE; + + IDXGIDevice2 * pDXGIDevice; + hr = graphicsDevice->QueryInterface(__uuidof(IDXGIDevice2), (void **)&pDXGIDevice); + + IDXGIAdapter * pDXGIAdapter; + hr = pDXGIDevice->GetParent(__uuidof(IDXGIAdapter), (void **)&pDXGIAdapter); + + IDXGIFactory2 * pIDXGIFactory; + pDXGIAdapter->GetParent(__uuidof(IDXGIFactory2), (void **)&pIDXGIFactory); + + + hr = pIDXGIFactory->CreateSwapChainForCoreWindow(graphicsDevice, reinterpret_cast(window), &sd + , nullptr, &swapChain); + + if (FAILED(hr)) { + wiHelper::messageBox("Swap chain creation failed!", "Error!"); + exit(1); + } +#endif + + DEFERREDCONTEXT_SUPPORT = false; + D3D11_FEATURE_DATA_THREADING threadingFeature; + device->CheckFeatureSupport(D3D11_FEATURE_THREADING, &threadingFeature, sizeof(threadingFeature)); + if (threadingFeature.DriverConcurrentCreates && threadingFeature.DriverCommandLists) { + DEFERREDCONTEXT_SUPPORT = true; + for (int i = 0; iGetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); + if (FAILED(hr)) { + wiHelper::messageBox("BackBuffer creation Failed!", "Error!", nullptr); + exit(0); + } + + hr = CreateRenderTargetView(pBackBuffer, NULL, &renderTargetView); + //pBackBuffer->Release(); + if (FAILED(hr)) { + wiHelper::messageBox("Main Rendertarget creation Failed!", "Error!", nullptr); + exit(0); + } + + + // Setup the main viewport + viewPort.Width = (FLOAT)screenW; + viewPort.Height = (FLOAT)screenH; + viewPort.MinDepth = 0.0f; + viewPort.MaxDepth = 1.0f; + viewPort.TopLeftX = 0; + viewPort.TopLeftY = 0; +} +GraphicsDevice_DX11::~GraphicsDevice_DX11() +{ + SAFE_RELEASE(renderTargetView); + SAFE_RELEASE(swapChain); + + for (int i = 0; iOMSetRenderTargets(1, &renderTargetView, 0); + float ClearColor[4] = { 0, 0, 0, 1.0f }; // red,green,blue,alpha + GetImmediateContext()->ClearRenderTargetView(renderTargetView, ClearColor); + +} +void GraphicsDevice_DX11::PresentEnd() +{ + swapChain->Present(VSYNC, 0); + + + GetImmediateContext()->OMSetRenderTargets(0, nullptr, nullptr); + + UnbindTextures(0, TEXSLOT_COUNT, GRAPHICSTHREAD_IMMEDIATE); + + UNLOCK(); +} + +void GraphicsDevice_DX11::ExecuteDeferredContexts() +{ + for (int i = 0; i < GRAPHICSTHREAD_COUNT; i++) + { + if (i != (GRAPHICSTHREAD)GRAPHICSTHREAD_IMMEDIATE &&commandLists[i]) + { + GetImmediateContext()->ExecuteCommandList(commandLists[i], true); + commandLists[i]->Release(); + commandLists[i] = nullptr; + + UnbindTextures(0, TEXSLOT_COUNT, (GRAPHICSTHREAD)i); + } + } +} +void GraphicsDevice_DX11::FinishCommandList(GRAPHICSTHREAD thread) +{ + if (thread == GRAPHICSTHREAD_IMMEDIATE) + return; + deviceContexts[thread]->FinishCommandList(true, &commandLists[thread]); +} + + + +HRESULT GraphicsDevice_DX11::CreateTextureFromFile(const wstring& fileName, TextureView *ppShaderResourceView, bool mipMaps, GRAPHICSTHREAD threadID) +{ + if (!fileName.substr(fileName.length() - 4).compare(wstring(L".dds"))) + { + // Load dds + CreateDDSTextureFromFile(device, fileName.c_str(), nullptr, ppShaderResourceView); + } + else + { + // Load WIC + if (mipMaps && threadID == GRAPHICSTHREAD_IMMEDIATE) + LOCK(); + CreateWICTextureFromFile(mipMaps, device, deviceContexts[threadID], fileName.c_str(), nullptr, ppShaderResourceView); + if (mipMaps && threadID == GRAPHICSTHREAD_IMMEDIATE) + UNLOCK(); + } +} diff --git a/WickedEngine/wiGraphicsAPI_DX11.h b/WickedEngine/wiGraphicsAPI_DX11.h new file mode 100644 index 000000000..7a834b83c --- /dev/null +++ b/WickedEngine/wiGraphicsAPI_DX11.h @@ -0,0 +1,421 @@ +#pragma once +#include "wiGraphicsAPI.h" + +class GraphicsDevice_DX11 : public GraphicsDevice +{ +private: + ID3D11Device* device; + D3D_DRIVER_TYPE driverType; + D3D_FEATURE_LEVEL featureLevel; + SwapChain swapChain; + RenderTargetView renderTargetView; + ViewPort viewPort; + DeviceContext deviceContexts[GRAPHICSTHREAD_COUNT]; + CommandList commandLists[GRAPHICSTHREAD_COUNT]; + bool DX11, VSYNC, DEFERREDCONTEXT_SUPPORT; + +public: + GraphicsDevice_DX11(HWND window, int screenW, int screenH, bool windowed); + ~GraphicsDevice_DX11(); + + virtual HRESULT CreateBuffer(const BufferDesc *pDesc, const SubresourceData* pInitialData, BufferResource *ppBuffer); + virtual HRESULT CreateTexture1D(); + virtual HRESULT CreateTexture2D(const Texture2DDesc* pDesc, const SubresourceData *pInitialData, Texture2D *ppTexture2D); + virtual HRESULT CreateTexture3D(); + virtual HRESULT CreateShaderResourceView(APIResource pResource, const ShaderResourceViewDesc* pDesc, TextureView *ppSRView); + virtual HRESULT CreateUnorderedAccessView(); + virtual HRESULT CreateRenderTargetView(APIResource pResource, const RenderTargetViewDesc* pDesc, RenderTargetView *ppRTView); + virtual HRESULT CreateDepthStencilView(APIResource pResource, const DepthStencilViewDesc* pDesc, DepthStencilView *ppDepthStencilView); + virtual HRESULT CreateInputLayout(const VertexLayoutDesc *pInputElementDescs, UINT NumElements, + const void *pShaderBytecodeWithInputSignature, SIZE_T BytecodeLength, VertexLayout *ppInputLayout); + virtual HRESULT CreateVertexShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, VertexShader *ppVertexShader); + virtual HRESULT CreatePixelShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, PixelShader *ppPixelShader); + virtual HRESULT CreateGeometryShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, GeometryShader *ppGeometryShader); + virtual HRESULT CreateGeometryShaderWithStreamOutput(const void *pShaderBytecode, SIZE_T BytecodeLength, const StreamOutDeclaration *pSODeclaration, + UINT NumEntries, const UINT *pBufferStrides, UINT NumStrides, UINT RasterizedStream, ClassLinkage pClassLinkage, GeometryShader *ppGeometryShader); + virtual HRESULT CreateHullShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, HullShader *ppHullShader); + virtual HRESULT CreateDomainShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, DomainShader *ppDomainShader); + virtual HRESULT CreateComputeShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, ComputeShader *ppComputeShader); + virtual HRESULT CreateClassLinkage(); + virtual HRESULT CreateBlendState(const BlendDesc *pBlendStateDesc, BlendState *ppBlendState); + virtual HRESULT CreateDepthStencilState(const DepthStencilDesc *pDepthStencilDesc, DepthStencilState *ppDepthStencilState); + virtual HRESULT CreateRasterizerState(const RasterizerDesc *pRasterizerDesc, RasterizerState *ppRasterizerState); + virtual HRESULT CreateSamplerState(const SamplerDesc *pSamplerDesc, Sampler *ppSamplerState); + virtual HRESULT CreateQuery(); + virtual HRESULT CreatePredicate(); + virtual HRESULT CreateDeferredContext(UINT ContextFlags, DeviceContext *ppDeferredContext); + virtual HRESULT OpenSharedResource(); + virtual HRESULT CheckFormatSupport(); + virtual HRESULT CheckMultiSampleQualityLevels(); + virtual HRESULT CheckCounterInfo(); + virtual HRESULT CheckCounter(); + virtual HRESULT CheckFeatureSupport(); + virtual HRESULT GetPrivateData(); + virtual HRESULT SetPrivateData(); + virtual HRESULT SetPrivateDataInterface(); + virtual UINT GetCreationFlags(); + virtual HRESULT GetDeviceRemovedReason(); + virtual DeviceContext GetImmediateContext(); + + virtual void PresentBegin(); + virtual void PresentEnd(); + + virtual void ExecuteDeferredContexts(); + virtual void FinishCommandList(GRAPHICSTHREAD thread); + + virtual bool GetMultithreadingSupport(); + virtual DeviceContext GetDeferredContext(GRAPHICSTHREAD thread); + + virtual bool GetVSyncEnabled() { return VSYNC; } + virtual void SetVSyncEnabled(bool value) { VSYNC = value; } + + ///////////////Thread-sensitive//////////////////////// + + virtual void BindViewports(UINT NumViewports, const ViewPort *pViewports, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + D3D11_VIEWPORT* pd3dViewPorts = new D3D11_VIEWPORT[NumViewports]; + for (UINT i = 0; i < NumViewports; ++i) + { + pd3dViewPorts[i].TopLeftX = pViewports[i].TopLeftX; + pd3dViewPorts[i].TopLeftY = pViewports[i].TopLeftY; + pd3dViewPorts[i].Width = pViewports[i].Width; + pd3dViewPorts[i].Height = pViewports[i].Height; + pd3dViewPorts[i].MinDepth = pViewports[i].MinDepth; + pd3dViewPorts[i].MaxDepth = pViewports[i].MaxDepth; + } + deviceContexts[threadID]->RSSetViewports(NumViewports, pd3dViewPorts); + SAFE_DELETE_ARRAY(pd3dViewPorts); + } + } + virtual void BindRenderTargets(UINT NumViews, RenderTargetView const *ppRenderTargetViews, DepthStencilView pDepthStencilView, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->OMSetRenderTargets(NumViews, ppRenderTargetViews, pDepthStencilView); + } + } + virtual void ClearRenderTarget(RenderTargetView pRenderTargetView, const FLOAT ColorRGBA[4], GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->ClearRenderTargetView(pRenderTargetView, ColorRGBA); + } + } + virtual void ClearDepthStencil(DepthStencilView pDepthStencilView, UINT ClearFlags, FLOAT Depth, UINT8 Stencil, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->ClearDepthStencilView(pDepthStencilView, ClearFlags, Depth, Stencil); + } + } + virtual void BindTexturePS(TextureView texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && texture != nullptr) { + deviceContexts[threadID]->PSSetShaderResources(slot, 1, &texture); + } + } + virtual void BindTexturesPS(TextureView textures[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && textures != nullptr) { + deviceContexts[threadID]->PSSetShaderResources(slot, num, textures); + } + } + virtual void BindTextureVS(TextureView texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && texture != nullptr) { + deviceContexts[threadID]->VSSetShaderResources(slot, 1, &texture); + } + } + virtual void BindTexturesVS(TextureView textures[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && textures != nullptr) { + deviceContexts[threadID]->VSSetShaderResources(slot, num, textures); + } + } + virtual void BindTextureGS(TextureView texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && texture != nullptr) { + deviceContexts[threadID]->GSSetShaderResources(slot, 1, &texture); + } + } + virtual void BindTexturesGS(TextureView textures[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && textures != nullptr) { + deviceContexts[threadID]->GSSetShaderResources(slot, num, textures); + } + } + virtual void BindTextureDS(TextureView texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && texture != nullptr) { + deviceContexts[threadID]->DSSetShaderResources(slot, 1, &texture); + } + } + virtual void BindTexturesDS(TextureView textures[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && textures != nullptr) { + deviceContexts[threadID]->DSSetShaderResources(slot, num, textures); + } + } + virtual void BindTextureHS(TextureView texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && texture != nullptr) { + deviceContexts[threadID]->HSSetShaderResources(slot, 1, &texture); + } + } + virtual void BindTexturesHS(TextureView textures[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && textures != nullptr) { + deviceContexts[threadID]->HSSetShaderResources(slot, num, textures); + } + } + virtual void UnbindTextures(int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) + { + assert(num <= 32 && "UnbindTextures limit of 32 reached!"); + if (deviceContexts[threadID] != nullptr) + { + static TextureView empties[32] = { + nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, + nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, + nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, + nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, + }; + deviceContexts[threadID]->PSSetShaderResources(slot, num, empties); + deviceContexts[threadID]->VSSetShaderResources(slot, num, empties); + deviceContexts[threadID]->GSSetShaderResources(slot, num, empties); + deviceContexts[threadID]->HSSetShaderResources(slot, num, empties); + deviceContexts[threadID]->DSSetShaderResources(slot, num, empties); + } + } + virtual void BindSamplerPS(Sampler sampler, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && sampler != nullptr) { + deviceContexts[threadID]->PSSetSamplers(slot, 1, &sampler); + } + } + virtual void BindSamplersPS(Sampler samplers[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && samplers != nullptr) { + deviceContexts[threadID]->PSSetSamplers(slot, num, samplers); + } + } + virtual void BindSamplerVS(Sampler sampler, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && sampler != nullptr) { + deviceContexts[threadID]->VSSetSamplers(slot, 1, &sampler); + } + } + virtual void BindSamplersVS(Sampler samplers[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && samplers != nullptr) { + deviceContexts[threadID]->VSSetSamplers(slot, num, samplers); + } + } + virtual void BindSamplerGS(Sampler sampler, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && sampler != nullptr) { + deviceContexts[threadID]->GSSetSamplers(slot, 1, &sampler); + } + } + virtual void BindSamplersGS(Sampler samplers[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && samplers != nullptr) { + deviceContexts[threadID]->GSSetSamplers(slot, num, samplers); + } + } + virtual void BindSamplerHS(Sampler sampler, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && sampler != nullptr) { + deviceContexts[threadID]->HSSetSamplers(slot, 1, &sampler); + } + } + virtual void BindSamplersHS(Sampler samplers[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && samplers != nullptr) { + deviceContexts[threadID]->HSSetSamplers(slot, num, samplers); + } + } + virtual void BindSamplerDS(Sampler sampler, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && sampler != nullptr) { + deviceContexts[threadID]->DSSetSamplers(slot, 1, &sampler); + } + } + virtual void BindSamplersDS(Sampler samplers[], int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && samplers != nullptr) { + deviceContexts[threadID]->DSSetSamplers(slot, num, samplers); + } + } + virtual void BindConstantBufferPS(BufferResource buffer, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->PSSetConstantBuffers(slot, 1, &buffer); + } + } + virtual void BindConstantBufferVS(BufferResource buffer, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->VSSetConstantBuffers(slot, 1, &buffer); + + } + } + virtual void BindConstantBufferGS(BufferResource buffer, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->GSSetConstantBuffers(slot, 1, &buffer); + } + } + virtual void BindConstantBufferDS(BufferResource buffer, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + + deviceContexts[threadID]->DSSetConstantBuffers(slot, 1, &buffer); + } + } + virtual void BindConstantBufferHS(BufferResource buffer, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->HSSetConstantBuffers(slot, 1, &buffer); + } + } + virtual void BindVertexBuffer(BufferResource vertexBuffer, int slot, UINT stride, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + UINT offset = 0; + deviceContexts[threadID]->IASetVertexBuffers(slot, 1, &vertexBuffer, &stride, &offset); + } + } + virtual void BindIndexBuffer(BufferResource indexBuffer, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->IASetIndexBuffer(indexBuffer, DXGI_FORMAT_R32_UINT, 0); + } + } + virtual void BindPrimitiveTopology(PRIMITIVETOPOLOGY type, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + D3D11_PRIMITIVE_TOPOLOGY d3dType = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST; + switch (type) + { + case TRIANGLELIST: + d3dType = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST; + break; + case TRIANGLESTRIP: + d3dType = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP; + break; + case POINTLIST: + d3dType = D3D11_PRIMITIVE_TOPOLOGY_POINTLIST; + break; + case LINELIST: + d3dType = D3D11_PRIMITIVE_TOPOLOGY_LINELIST; + break; + case PATCHLIST: + d3dType = D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST; + break; + default: + break; + }; + deviceContexts[threadID]->IASetPrimitiveTopology(d3dType); + } + } + virtual void BindVertexLayout(VertexLayout layout, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->IASetInputLayout(layout); + } + } + virtual void BindBlendState(BlendState state, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + static float blendFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + static UINT sampleMask = 0xffffffff; + deviceContexts[threadID]->OMSetBlendState(state, blendFactor, sampleMask); + } + } + virtual void BindBlendStateEx(BlendState state, const XMFLOAT4& blendFactor = XMFLOAT4(1, 1, 1, 1), UINT sampleMask = 0xffffffff, + GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + float fblendFactor[4] = { blendFactor.x, blendFactor.y, blendFactor.z, blendFactor.w }; + } + } + virtual void BindDepthStencilState(DepthStencilState state, UINT stencilRef, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->OMSetDepthStencilState(state, stencilRef); + } + } + virtual void BindRasterizerState(RasterizerState state, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->RSSetState(state); + } + } + virtual void BindStreamOutTarget(BufferResource buffer, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + UINT offsetSO[1] = { 0 }; + deviceContexts[threadID]->SOSetTargets(1, &buffer, offsetSO); + } + } + virtual void BindPS(PixelShader shader, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->PSSetShader(shader, nullptr, 0); + } + } + virtual void BindVS(VertexShader shader, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->VSSetShader(shader, nullptr, 0); + } + } + virtual void BindGS(GeometryShader shader, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->GSSetShader(shader, nullptr, 0); + } + } + virtual void BindHS(HullShader shader, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->HSSetShader(shader, nullptr, 0); + } + } + virtual void BindDS(DomainShader shader, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->DSSetShader(shader, nullptr, 0); + } + } + virtual void Draw(int vertexCount, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->Draw(vertexCount, 0); + } + } + virtual void DrawIndexed(int indexCount, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->DrawIndexed(indexCount, 0, 0); + } + } + virtual void DrawIndexedInstanced(int indexCount, int instanceCount, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->DrawIndexedInstanced(indexCount, instanceCount, 0, 0, 0); + } + } + virtual void GenerateMips(TextureView texture, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) + { + deviceContexts[threadID]->GenerateMips(texture); + } + virtual void CopyResource(APIResource pDstResource, APIResource pSrcResource, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + deviceContexts[threadID]->CopyResource(pDstResource, pSrcResource); + } + } + virtual void UpdateBuffer(BufferResource& buffer, const void* data, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE, int dataSize = -1) + { + if (buffer != nullptr && data != nullptr && deviceContexts[threadID] != nullptr) { + static thread_local D3D11_BUFFER_DESC d3dDesc; + buffer->GetDesc(&d3dDesc); + HRESULT hr; + if (dataSize>(int)d3dDesc.ByteWidth) { //recreate the buffer if new datasize exceeds buffer size + buffer->Release(); + d3dDesc.ByteWidth = dataSize * 2; + + BufferDesc desc; + desc.ByteWidth = d3dDesc.ByteWidth; + switch (desc.Usage) + { + case D3D11_USAGE_DEFAULT: + desc.Usage = USAGE_DEFAULT; + break; + case D3D11_USAGE_IMMUTABLE: + desc.Usage = USAGE_IMMUTABLE; + break; + case D3D11_USAGE_DYNAMIC: + desc.Usage = USAGE_DYNAMIC; + break; + case D3D11_USAGE_STAGING: + desc.Usage = USAGE_STAGING; + break; + }; + desc.BindFlags = d3dDesc.BindFlags; + desc.CPUAccessFlags = d3dDesc.CPUAccessFlags; + desc.MiscFlags = d3dDesc.MiscFlags; + desc.StructureByteStride = d3dDesc.StructureByteStride; + + hr = CreateBuffer(&desc, nullptr, &buffer); + } + if (d3dDesc.Usage == D3D11_USAGE_DYNAMIC) { + static thread_local D3D11_MAPPED_SUBRESOURCE mappedResource; + void* dataPtr; + deviceContexts[threadID]->Map(buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); + dataPtr = (void*)mappedResource.pData; + memcpy(dataPtr, data, (dataSize >= 0 ? dataSize : d3dDesc.ByteWidth)); + deviceContexts[threadID]->Unmap(buffer, 0); + } + else { + deviceContexts[threadID]->UpdateSubresource(buffer, 0, nullptr, data, 0, 0); + } + } + } + + + virtual HRESULT CreateTextureFromFile(const wstring& fileName, TextureView *ppShaderResourceView, bool mipMaps = true, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); + +}; diff --git a/WickedEngine/wiHairParticle.cpp b/WickedEngine/wiHairParticle.cpp index 616fa8808..009fd583f 100644 --- a/WickedEngine/wiHairParticle.cpp +++ b/WickedEngine/wiHairParticle.cpp @@ -46,9 +46,9 @@ void wiHairParticle::CleanUp(){ for (unsigned int i = 0; iCleanUp(); patches.clear(); - wiRenderer::SafeRelease(vb[0]); - wiRenderer::SafeRelease(vb[1]); - wiRenderer::SafeRelease(vb[2]); + SAFE_RELEASE(vb[0]); + SAFE_RELEASE(vb[1]); + SAFE_RELEASE(vb[2]); } void wiHairParticle::CleanUpStatic(){ @@ -71,9 +71,9 @@ void wiHairParticle::LoadShaders() VertexLayoutDesc layout[] = { - { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "NORMAL", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TANGENT", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "NORMAL", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "TANGENT", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, }; UINT numElements = ARRAYSIZE(layout); VertexShaderInfo* vsinfo = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "grassVS.cso", wiResourceManager::VERTEXSHADER, layout, numElements)); @@ -101,20 +101,20 @@ void wiHairParticle::SetUpStatic(){ LoadShaders(); - D3D11_BUFFER_DESC bd; + BufferDesc bd; ZeroMemory( &bd, sizeof(bd) ); - bd.Usage = D3D11_USAGE_DYNAMIC; + bd.Usage = USAGE_DYNAMIC; bd.ByteWidth = sizeof(ConstantBuffer); - bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + bd.BindFlags = BIND_CONSTANT_BUFFER; + bd.CPUAccessFlags = CPU_ACCESS_WRITE; wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &cbgs ); - D3D11_RASTERIZER_DESC rsd; - rsd.FillMode=D3D11_FILL_SOLID; - rsd.CullMode=D3D11_CULL_BACK; + RasterizerDesc rsd; + rsd.FillMode=FILL_SOLID; + rsd.CullMode=CULL_BACK; rsd.FrontCounterClockwise=true; rsd.DepthBias=0; rsd.DepthBiasClamp=0; @@ -124,8 +124,8 @@ void wiHairParticle::SetUpStatic(){ rsd.MultisampleEnable=false; rsd.AntialiasedLineEnable=false; wiRenderer::graphicsDevice->CreateRasterizerState(&rsd,&rs); - rsd.FillMode=D3D11_FILL_SOLID; - rsd.CullMode=D3D11_CULL_NONE; + rsd.FillMode=FILL_SOLID; + rsd.CullMode=CULL_NONE; rsd.FrontCounterClockwise=true; rsd.DepthBias=0; rsd.DepthBiasClamp=0; @@ -137,35 +137,35 @@ void wiHairParticle::SetUpStatic(){ wiRenderer::graphicsDevice->CreateRasterizerState(&rsd,&ncrs); - D3D11_DEPTH_STENCIL_DESC dsd; + DepthStencilDesc dsd; dsd.DepthEnable = true; - dsd.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; - dsd.DepthFunc = D3D11_COMPARISON_LESS; + dsd.DepthWriteMask = DEPTH_WRITE_MASK_ALL; + dsd.DepthFunc = COMPARISON_LESS; dsd.StencilEnable = true; dsd.StencilReadMask = 0xFF; dsd.StencilWriteMask = 0xFF; - dsd.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; - dsd.FrontFace.StencilPassOp = D3D11_STENCIL_OP_REPLACE; - dsd.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; - dsd.BackFace.StencilPassOp = D3D11_STENCIL_OP_REPLACE; - dsd.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; + dsd.FrontFace.StencilFunc = COMPARISON_ALWAYS; + dsd.FrontFace.StencilPassOp = STENCIL_OP_REPLACE; + dsd.FrontFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.FrontFace.StencilDepthFailOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilFunc = COMPARISON_ALWAYS; + dsd.BackFace.StencilPassOp = STENCIL_OP_REPLACE; + dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; // Create the depth stencil state. wiRenderer::graphicsDevice->CreateDepthStencilState(&dsd, &dss); - D3D11_BLEND_DESC bld; + BlendDesc bld; ZeroMemory(&bld, sizeof(bld)); bld.RenderTarget[0].BlendEnable=false; - bld.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; - bld.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; - bld.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - bld.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; - bld.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; - bld.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + bld.RenderTarget[0].SrcBlend = BLEND_SRC_ALPHA; + bld.RenderTarget[0].DestBlend = BLEND_INV_SRC_ALPHA; + bld.RenderTarget[0].BlendOp = BLEND_OP_ADD; + bld.RenderTarget[0].SrcBlendAlpha = BLEND_ONE; + bld.RenderTarget[0].DestBlendAlpha = BLEND_ZERO; + bld.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bld.RenderTarget[0].RenderTargetWriteMask = 0x0f; bld.AlphaToCoverageEnable=false; wiRenderer::graphicsDevice->CreateBlendState(&bld,&bs); @@ -186,12 +186,12 @@ struct PatchHolder:public Cullable void wiHairParticle::SetUpPatches() { - D3D11_BUFFER_DESC bd; + BufferDesc bd; ZeroMemory( &bd, sizeof(bd) ); - bd.Usage = D3D11_USAGE_DYNAMIC; + bd.Usage = USAGE_DYNAMIC; bd.ByteWidth = sizeof(Point)*MAX_PARTICLES; - bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + 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] ); @@ -352,7 +352,7 @@ void wiHairParticle::SetUpPatches() GenerateSPTree(spTree,vector(pholder.begin(),pholder.end()),SPTREE_GENERATE_OCTREE); return; } -void wiHairParticle::Draw(Camera* camera, ID3D11DeviceContext *context) +void wiHairParticle::Draw(Camera* camera, GRAPHICSTHREAD threadID) { XMMATRIX inverseMat = XMLoadFloat4x4(&OriginalMatrix_Inverse); XMMATRIX renderMatrix = inverseMat * object->getMatrix(); @@ -389,19 +389,19 @@ void wiHairParticle::Draw(Camera* camera, ID3D11DeviceContext *context) { TextureView texture = material->texture; - wiRenderer::BindPrimitiveTopology(PRIMITIVETOPOLOGY::POINTLIST,context); - wiRenderer::BindVertexLayout(il,context); - wiRenderer::BindPS(texture?qps:ps,context); - wiRenderer::BindVS(vs,context); + wiRenderer::graphicsDevice->BindPrimitiveTopology(PRIMITIVETOPOLOGY::POINTLIST,threadID); + wiRenderer::graphicsDevice->BindVertexLayout(il,threadID); + wiRenderer::graphicsDevice->BindPS(texture?qps:ps,threadID); + wiRenderer::graphicsDevice->BindVS(vs,threadID); if(texture){ - wiRenderer::BindTexturePS(texture,TEXSLOT_ONDEMAND0,context); - wiRenderer::BindTextureGS(texture,TEXSLOT_ONDEMAND0,context); + wiRenderer::graphicsDevice->BindTexturePS(texture,TEXSLOT_ONDEMAND0,threadID); + wiRenderer::graphicsDevice->BindTextureGS(texture,TEXSLOT_ONDEMAND0,threadID); - wiRenderer::BindBlendState(bs,context); + wiRenderer::graphicsDevice->BindBlendState(bs,threadID); } else - wiRenderer::BindRasterizerState(ncrs,context); + wiRenderer::graphicsDevice->BindRasterizerState(ncrs,threadID); static thread_local ConstantBuffer* gcb = new ConstantBuffer; @@ -409,10 +409,10 @@ void wiHairParticle::Draw(Camera* camera, ID3D11DeviceContext *context) (*gcb).color=material->diffuseColor; (*gcb).drawdistance = (float)LOD[2]; - wiRenderer::UpdateBuffer(cbgs,gcb,context); - wiRenderer::BindConstantBufferGS(cbgs, CB_GETBINDSLOT(ConstantBuffer),context); + wiRenderer::graphicsDevice->UpdateBuffer(cbgs,gcb,threadID); + wiRenderer::graphicsDevice->BindConstantBufferGS(cbgs, CB_GETBINDSLOT(ConstantBuffer),threadID); - wiRenderer::BindDepthStencilState(dss,STENCILREF_DEFAULT,context); + wiRenderer::graphicsDevice->BindDepthStencilState(dss,STENCILREF_DEFAULT,threadID); for(int i=0;i<3;++i){ @@ -420,11 +420,11 @@ void wiHairParticle::Draw(Camera* camera, ID3D11DeviceContext *context) renderPoints.reserve(MAX_PARTICLES); if(texture){ - wiRenderer::BindGS(i<2?qgs[0]:qgs[1],context); - wiRenderer::BindRasterizerState(i<2?ncrs:rs,context); + wiRenderer::graphicsDevice->BindGS(i<2?qgs[0]:qgs[1],threadID); + wiRenderer::graphicsDevice->BindRasterizerState(i<2?ncrs:rs,threadID); } else - wiRenderer::BindGS(gs[i],context); + wiRenderer::graphicsDevice->BindGS(gs[i],threadID); CulledList::iterator iter = culledPatches.begin(); while(iter != culledPatches.end()){ Cullable* culled = *iter; @@ -441,19 +441,19 @@ void wiHairParticle::Draw(Camera* camera, ID3D11DeviceContext *context) ++iter; } - wiRenderer::UpdateBuffer(vb[i],renderPoints.data(),context,sizeof(Point)*renderPoints.size()); - wiRenderer::BindVertexBuffer(vb[i],0,sizeof(Point),context); - wiRenderer::Draw(renderPoints.size(),context); + 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::BindGS(nullptr,context); + wiRenderer::graphicsDevice->BindGS(nullptr,threadID); } } wiHairParticle::Patch::Patch(){ p.resize(0); - min=XMFLOAT3(D3D11_FLOAT32_MAX,D3D11_FLOAT32_MAX,D3D11_FLOAT32_MAX); - max=XMFLOAT3(-D3D11_FLOAT32_MAX,-D3D11_FLOAT32_MAX,-D3D11_FLOAT32_MAX); + min=XMFLOAT3(FLOAT32_MAX,FLOAT32_MAX,FLOAT32_MAX); + max=XMFLOAT3(-FLOAT32_MAX,-FLOAT32_MAX,-FLOAT32_MAX); //vb=NULL; } void wiHairParticle::Patch::add(const Point& pp){ diff --git a/WickedEngine/wiHairParticle.h b/WickedEngine/wiHairParticle.h index 89c790c89..092056e7c 100644 --- a/WickedEngine/wiHairParticle.h +++ b/WickedEngine/wiHairParticle.h @@ -61,7 +61,7 @@ public: void CleanUp(); void SetUpPatches(); - void Draw(Camera* camera, ID3D11DeviceContext *context); + void Draw(Camera* camera, GRAPHICSTHREAD threadID); static void CleanUpStatic(); static void SetUpStatic(); diff --git a/WickedEngine/wiHelper.cpp b/WickedEngine/wiHelper.cpp index f78adb641..1eb7a4c5e 100644 --- a/WickedEngine/wiHelper.cpp +++ b/WickedEngine/wiHelper.cpp @@ -45,27 +45,27 @@ namespace wiHelper void screenshot(const string& name) { -#ifndef WINSTORE_SUPPORT - CreateDirectoryA("screenshots", 0); - stringstream ss(""); - if (name.length() <= 0) - ss << "screenshots/sc_" << getCurrentDateTimeAsString() << ".png"; - else - ss << name; - wstringstream wss(L""); - wss << ss.str().c_str(); - APIResource res = nullptr; - wiRenderer::renderTargetView->GetResource(&res); - HRESULT h = SaveWICTextureToFile(wiRenderer::immediateContext, res, GUID_ContainerFormatPng, wss.str().c_str()); - if (FAILED(h)) - wiBackLog::post("Screenshot failed"); - else - { - ss << " Saved successfully!"; - wiBackLog::post(ss.str().c_str()); - } - res->Release(); -#endif +//#ifndef WINSTORE_SUPPORT +// CreateDirectoryA("screenshots", 0); +// stringstream ss(""); +// if (name.length() <= 0) +// ss << "screenshots/sc_" << getCurrentDateTimeAsString() << ".png"; +// else +// ss << name; +// wstringstream wss(L""); +// wss << ss.str().c_str(); +// APIResource res = nullptr; +// wiRenderer::renderTargetView->GetResource(&res); +// HRESULT h = SaveWICTextureToFile(wiRenderer::immediateContext, res, GUID_ContainerFormatPng, wss.str().c_str()); +// if (FAILED(h)) +// wiBackLog::post("Screenshot failed"); +// else +// { +// ss << " Saved successfully!"; +// wiBackLog::post(ss.str().c_str()); +// } +// res->Release(); +//#endif } string getCurrentDateTimeAsString() diff --git a/WickedEngine/wiImage.cpp b/WickedEngine/wiImage.cpp index 0b6ae9cbe..9cad2084a 100644 --- a/WickedEngine/wiImage.cpp +++ b/WickedEngine/wiImage.cpp @@ -28,22 +28,22 @@ wiImage::wiImage() void wiImage::LoadBuffers() { - D3D11_BUFFER_DESC bd; + BufferDesc bd; ZeroMemory( &bd, sizeof(bd) ); - bd.Usage = D3D11_USAGE_DYNAMIC; + bd.Usage = USAGE_DYNAMIC; bd.ByteWidth = sizeof(ImageCB); - bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + bd.BindFlags = BIND_CONSTANT_BUFFER; + bd.CPUAccessFlags = CPU_ACCESS_WRITE; wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &constantBuffer ); ZeroMemory(&bd, sizeof(bd)); - bd.Usage = D3D11_USAGE_DYNAMIC; + bd.Usage = USAGE_DYNAMIC; bd.ByteWidth = sizeof(PostProcessCB); - bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + bd.BindFlags = BIND_CONSTANT_BUFFER; + bd.CPUAccessFlags = CPU_ACCESS_WRITE; wiRenderer::graphicsDevice->CreateBuffer(&bd, NULL, &processCb); - BindPersistentState(wiRenderer::getImmediateContext()); + BindPersistentState(GRAPHICSTHREAD_IMMEDIATE); } void wiImage::LoadShaders() @@ -75,9 +75,9 @@ void wiImage::SetUpStates() { - D3D11_RASTERIZER_DESC rs; - rs.FillMode=D3D11_FILL_SOLID; - rs.CullMode=D3D11_CULL_BACK; + RasterizerDesc rs; + rs.FillMode=FILL_SOLID; + rs.CullMode=CULL_BACK; rs.FrontCounterClockwise=false; rs.DepthBias=0; rs.DepthBiasClamp=0; @@ -92,41 +92,41 @@ void wiImage::SetUpStates() - D3D11_DEPTH_STENCIL_DESC dsd; + DepthStencilDesc dsd; dsd.DepthEnable = false; - dsd.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO; - dsd.DepthFunc = D3D11_COMPARISON_LESS; + dsd.DepthWriteMask = DEPTH_WRITE_MASK_ZERO; + dsd.DepthFunc = COMPARISON_LESS; dsd.StencilEnable = true; - dsd.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK; + dsd.StencilReadMask = DEFAULT_STENCIL_READ_MASK; dsd.StencilWriteMask = 0; - dsd.FrontFace.StencilFunc = D3D11_COMPARISON_LESS_EQUAL; - dsd.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - dsd.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilFunc = D3D11_COMPARISON_LESS_EQUAL; - dsd.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; + dsd.FrontFace.StencilFunc = COMPARISON_LESS_EQUAL; + dsd.FrontFace.StencilPassOp = STENCIL_OP_KEEP; + dsd.FrontFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.FrontFace.StencilDepthFailOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilFunc = COMPARISON_LESS_EQUAL; + dsd.BackFace.StencilPassOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; // Create the depth stencil state. wiRenderer::graphicsDevice->CreateDepthStencilState(&dsd, &depthStencilStateLess); dsd.DepthEnable = false; - dsd.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO; - dsd.DepthFunc = D3D11_COMPARISON_LESS; + dsd.DepthWriteMask = DEPTH_WRITE_MASK_ZERO; + dsd.DepthFunc = COMPARISON_LESS; dsd.StencilEnable = true; - dsd.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK; + dsd.StencilReadMask = DEFAULT_STENCIL_READ_MASK; dsd.StencilWriteMask = 0; - dsd.FrontFace.StencilFunc = D3D11_COMPARISON_GREATER; - dsd.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - dsd.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilFunc = D3D11_COMPARISON_GREATER; - dsd.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; + dsd.FrontFace.StencilFunc = COMPARISON_GREATER; + dsd.FrontFace.StencilPassOp = STENCIL_OP_KEEP; + dsd.FrontFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.FrontFace.StencilDepthFailOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilFunc = COMPARISON_GREATER; + dsd.BackFace.StencilPassOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; // Create the depth stencil state. wiRenderer::graphicsDevice->CreateDepthStencilState(&dsd, &depthStencilStateGreater); @@ -134,101 +134,100 @@ void wiImage::SetUpStates() wiRenderer::graphicsDevice->CreateDepthStencilState(&dsd, &depthNoStencilState); - D3D11_BLEND_DESC bd; + BlendDesc bd; ZeroMemory(&bd, sizeof(bd)); bd.RenderTarget[0].BlendEnable=true; - bd.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; - bd.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; - bd.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - bd.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; - bd.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; - bd.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlend = BLEND_SRC_ALPHA; + bd.RenderTarget[0].DestBlend = BLEND_INV_SRC_ALPHA; + bd.RenderTarget[0].BlendOp = BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlendAlpha = BLEND_ONE; + bd.RenderTarget[0].DestBlendAlpha = BLEND_INV_SRC_ALPHA; + bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; bd.IndependentBlendEnable=true; wiRenderer::graphicsDevice->CreateBlendState(&bd,&blendState); ZeroMemory(&bd, sizeof(bd)); bd.RenderTarget[0].BlendEnable=false; - bd.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; - bd.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; - bd.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - bd.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; - bd.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; - bd.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlend = BLEND_SRC_ALPHA; + bd.RenderTarget[0].DestBlend = BLEND_INV_SRC_ALPHA; + bd.RenderTarget[0].BlendOp = BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlendAlpha = BLEND_ONE; + bd.RenderTarget[0].DestBlendAlpha = BLEND_ZERO; + bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; //bd.IndependentBlendEnable=true; wiRenderer::graphicsDevice->CreateBlendState(&bd,&blendStateNoBlend); ZeroMemory(&bd, sizeof(bd)); bd.RenderTarget[0].BlendEnable=true; - bd.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; - bd.RenderTarget[0].DestBlend = D3D11_BLEND_ONE; - bd.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - bd.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; - bd.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; - bd.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlend = BLEND_ONE; + bd.RenderTarget[0].DestBlend = BLEND_ONE; + bd.RenderTarget[0].BlendOp = BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlendAlpha = BLEND_ONE; + bd.RenderTarget[0].DestBlendAlpha = BLEND_ZERO; + bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; //bd.IndependentBlendEnable=true; wiRenderer::graphicsDevice->CreateBlendState(&bd,&blendStateAdd); ZeroMemory(&bd, sizeof(bd)); bd.RenderTarget[0].BlendEnable=true; - bd.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_COLOR; - bd.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; - bd.RenderTarget[0].BlendOp = D3D11_BLEND_OP_MAX; - bd.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; - bd.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; - bd.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_MAX; + bd.RenderTarget[0].SrcBlend = BLEND_SRC_COLOR; + bd.RenderTarget[0].DestBlend = BLEND_INV_SRC_ALPHA; + bd.RenderTarget[0].BlendOp = BLEND_OP_MAX; + bd.RenderTarget[0].SrcBlendAlpha = BLEND_ONE; + bd.RenderTarget[0].DestBlendAlpha = BLEND_ZERO; + bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_MAX; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; //bd.IndependentBlendEnable=true; wiRenderer::graphicsDevice->CreateBlendState(&bd,&blendStateAvg); } -void wiImage::BindPersistentState(DeviceContext context) +void wiImage::BindPersistentState(GRAPHICSTHREAD threadID) { - wiRenderer::Lock(); + wiRenderer::graphicsDevice->LOCK(); - wiRenderer::BindConstantBufferVS(constantBuffer, CB_GETBINDSLOT(ImageCB), context); - wiRenderer::BindConstantBufferPS(constantBuffer, CB_GETBINDSLOT(ImageCB), context); + wiRenderer::graphicsDevice->BindConstantBufferVS(constantBuffer, CB_GETBINDSLOT(ImageCB), threadID); + wiRenderer::graphicsDevice->BindConstantBufferPS(constantBuffer, CB_GETBINDSLOT(ImageCB), threadID); - wiRenderer::BindConstantBufferPS(processCb, CB_GETBINDSLOT(PostProcessCB), context); + wiRenderer::graphicsDevice->BindConstantBufferPS(processCb, CB_GETBINDSLOT(PostProcessCB), threadID); - wiRenderer::Unlock(); + wiRenderer::graphicsDevice->LOCK(); } void wiImage::Draw(TextureView texture, const wiImageEffects& effects){ - Draw(texture,effects,wiRenderer::getImmediateContext()); + Draw(texture,effects,GRAPHICSTHREAD_IMMEDIATE); } -void wiImage::Draw(TextureView texture, const wiImageEffects& effects,DeviceContext context){ - if(!context) - return; +void wiImage::Draw(TextureView texture, const wiImageEffects& effects,GRAPHICSTHREAD threadID) +{ bool fullScreenEffect = false; - wiRenderer::BindVertexLayout(nullptr, context); - wiRenderer::BindVertexBuffer(nullptr, 0, 0, context); - wiRenderer::BindIndexBuffer(nullptr, context); - wiRenderer::BindPrimitiveTopology(PRIMITIVETOPOLOGY::TRIANGLESTRIP, context); - wiRenderer::BindRasterizerState(rasterizerState, context); + 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::BindTexturePS(texture, TEXSLOT_ONDEMAND0, context); + wiRenderer::graphicsDevice->BindTexturePS(texture, TEXSLOT_ONDEMAND0, threadID); if (effects.blendFlag == BLENDMODE_ALPHA) - wiRenderer::BindBlendState(blendState, context); + wiRenderer::graphicsDevice->BindBlendState(blendState, threadID); else if (effects.blendFlag == BLENDMODE_ADDITIVE) - wiRenderer::BindBlendState(blendStateAdd, context); + wiRenderer::graphicsDevice->BindBlendState(blendStateAdd, threadID); else if (effects.blendFlag == BLENDMODE_OPAQUE) - wiRenderer::BindBlendState(blendStateNoBlend, context); + wiRenderer::graphicsDevice->BindBlendState(blendStateNoBlend, threadID); else if (effects.blendFlag == BLENDMODE_MAX) - wiRenderer::BindBlendState(blendStateAvg, context); + wiRenderer::graphicsDevice->BindBlendState(blendStateAvg, threadID); else - wiRenderer::BindBlendState(blendState, context); + wiRenderer::graphicsDevice->BindBlendState(blendState, threadID); if (effects.presentFullScreen) { - wiRenderer::BindVS(screenVS, context); - wiRenderer::BindPS(screenPS, context); - wiRenderer::Draw(3, context); + wiRenderer::graphicsDevice->BindVS(screenVS, threadID); + wiRenderer::graphicsDevice->BindPS(screenPS, threadID); + wiRenderer::graphicsDevice->Draw(3, threadID); return; } @@ -237,14 +236,14 @@ void wiImage::Draw(TextureView texture, const wiImageEffects& effects,DeviceCont { switch (effects.stencilComp) { - case D3D11_COMPARISON_LESS: - wiRenderer::BindDepthStencilState(depthStencilStateLess, effects.stencilRef, context); + case COMPARISON_LESS: + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencilStateLess, effects.stencilRef, threadID); break; - case D3D11_COMPARISON_GREATER: - wiRenderer::BindDepthStencilState(depthStencilStateGreater, effects.stencilRef, context); + case COMPARISON_GREATER: + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencilStateGreater, effects.stencilRef, threadID); break; default: - wiRenderer::BindDepthStencilState(depthNoStencilState, effects.stencilRef, context); + wiRenderer::graphicsDevice->BindDepthStencilState(depthNoStencilState, effects.stencilRef, threadID); break; } } @@ -301,38 +300,38 @@ void wiImage::Draw(TextureView texture, const wiImageEffects& effects,DeviceCont (*cb).mNormalmapSeparate = normalmapmode; (*cb).mMipLevel = effects.mipLevel; - wiRenderer::UpdateBuffer(constantBuffer,cb,context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffer,cb,threadID); - wiRenderer::BindVS(vertexShader, context); - wiRenderer::BindPS(pixelShader, context); + wiRenderer::graphicsDevice->BindVS(vertexShader, threadID); + wiRenderer::graphicsDevice->BindPS(pixelShader, threadID); fullScreenEffect = false; } else if(!effects.sunPos.x && !effects.sunPos.y){ - wiRenderer::BindVS(screenVS, context); + wiRenderer::graphicsDevice->BindVS(screenVS, threadID); fullScreenEffect = true; if(effects.process.outline) - wiRenderer::BindPS(outlinePS,context); + wiRenderer::graphicsDevice->BindPS(outlinePS,threadID); else if(effects.process.motionBlur) - wiRenderer::BindPS(motionBlurPS,context); + wiRenderer::graphicsDevice->BindPS(motionBlurPS,threadID); else if(effects.process.dofStrength) - wiRenderer::BindPS(dofPS,context); + wiRenderer::graphicsDevice->BindPS(dofPS,threadID); else if(effects.process.fxaa) - wiRenderer::BindPS(fxaaPS,context); + wiRenderer::graphicsDevice->BindPS(fxaaPS,threadID); else if(effects.process.ssao) - wiRenderer::BindPS(ssaoPS,context); + wiRenderer::graphicsDevice->BindPS(ssaoPS,threadID); else if(effects.process.linDepth) - wiRenderer::BindPS(linDepthPS, context); + wiRenderer::graphicsDevice->BindPS(linDepthPS, threadID); else if (effects.process.colorGrade) - wiRenderer::BindPS(colorGradePS, context); + wiRenderer::graphicsDevice->BindPS(colorGradePS, threadID); else if (effects.process.ssr) - wiRenderer::BindPS(ssrPS, context); + wiRenderer::graphicsDevice->BindPS(ssrPS, threadID); else if (effects.process.stereogram) - wiRenderer::BindPS(stereogramPS, context); + wiRenderer::graphicsDevice->BindPS(stereogramPS, threadID); else if(effects.process.ssss.x + effects.process.ssss.y > 0) - wiRenderer::BindPS(ssssPS,context); + wiRenderer::graphicsDevice->BindPS(ssssPS,threadID); else if(effects.bloom.separate) - wiRenderer::BindPS(bloomSeparatePS,context); + wiRenderer::graphicsDevice->BindPS(bloomSeparatePS,threadID); else wiHelper::messageBox("Postprocess branch not implemented!"); @@ -345,11 +344,11 @@ void wiImage::Draw(TextureView texture, const wiImageEffects& effects,DeviceCont (*prcb).params1[2] = effects.bloom.saturation; (*prcb).params1[3] = effects.process.ssss.y; - wiRenderer::UpdateBuffer(processCb,prcb,context); + wiRenderer::graphicsDevice->UpdateBuffer(processCb,prcb,threadID); } else{ - wiRenderer::BindVS(screenVS,context); - wiRenderer::BindPS(shaftPS,context); + wiRenderer::graphicsDevice->BindVS(screenVS,threadID); + wiRenderer::graphicsDevice->BindPS(shaftPS,threadID); fullScreenEffect = true; //Density|Weight|Decay|Exposure @@ -360,22 +359,22 @@ void wiImage::Draw(TextureView texture, const wiImageEffects& effects,DeviceCont (*prcb).params1[0] = effects.sunPos.x; (*prcb).params1[1] = effects.sunPos.y; - wiRenderer::UpdateBuffer(processCb,prcb,context); + wiRenderer::graphicsDevice->UpdateBuffer(processCb,prcb,threadID); } - wiRenderer::BindTexturePS(effects.maskMap, TEXSLOT_ONDEMAND1, context); - wiRenderer::BindTexturePS(effects.distortionMap, TEXSLOT_ONDEMAND2, context); - wiRenderer::BindTexturePS(effects.refractionSource, TEXSLOT_ONDEMAND3, context); + wiRenderer::graphicsDevice->BindTexturePS(effects.maskMap, TEXSLOT_ONDEMAND1, threadID); + wiRenderer::graphicsDevice->BindTexturePS(effects.distortionMap, TEXSLOT_ONDEMAND2, threadID); + wiRenderer::graphicsDevice->BindTexturePS(effects.refractionSource, TEXSLOT_ONDEMAND3, threadID); } else{ //BLUR - wiRenderer::BindVS(screenVS,context); + wiRenderer::graphicsDevice->BindVS(screenVS,threadID); fullScreenEffect = true; if(effects.blurDir==0){ - wiRenderer::BindPS(blurHPS,context); + wiRenderer::graphicsDevice->BindPS(blurHPS,threadID); (*prcb).params1[3] = 1.0f / wiRenderer::GetScreenWidth(); } else{ - wiRenderer::BindPS(blurVPS,context); + wiRenderer::graphicsDevice->BindPS(blurVPS,threadID); (*prcb).params1[3] = 1.0f / wiRenderer::GetScreenHeight(); } @@ -393,64 +392,64 @@ void wiImage::Draw(TextureView texture, const wiImageEffects& effects,DeviceCont (*prcb).params1[1] = effects.blur; (*prcb).params1[2] = effects.mipLevel; - wiRenderer::UpdateBuffer(processCb,prcb,context); + wiRenderer::graphicsDevice->UpdateBuffer(processCb,prcb,threadID); } if(effects.quality==QUALITY_NEAREST){ if (effects.sampleFlag == SAMPLEMODE_MIRROR) - wiRenderer::BindSamplerPS(wiRenderer::samplers[SSLOT_POINT_MIRROR], SSLOT_ONDEMAND0, context); + wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_POINT_MIRROR], SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_WRAP) - wiRenderer::BindSamplerPS(wiRenderer::samplers[SSLOT_POINT_WRAP], SSLOT_ONDEMAND0, context); + wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_POINT_WRAP], SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_CLAMP) - wiRenderer::BindSamplerPS(wiRenderer::samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, context); + wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, threadID); } else if(effects.quality==QUALITY_BILINEAR){ if (effects.sampleFlag == SAMPLEMODE_MIRROR) - wiRenderer::BindSamplerPS(wiRenderer::samplers[SSLOT_LINEAR_MIRROR], SSLOT_ONDEMAND0, context); + wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_LINEAR_MIRROR], SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_WRAP) - wiRenderer::BindSamplerPS(wiRenderer::samplers[SSLOT_LINEAR_WRAP], SSLOT_ONDEMAND0, context); + wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_LINEAR_WRAP], SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_CLAMP) - wiRenderer::BindSamplerPS(wiRenderer::samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, context); + wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, threadID); } else if(effects.quality==QUALITY_ANISOTROPIC){ if (effects.sampleFlag == SAMPLEMODE_MIRROR) - wiRenderer::BindSamplerPS(wiRenderer::samplers[SSLOT_ANISO_MIRROR], SSLOT_ONDEMAND0, context); + wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_ANISO_MIRROR], SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_WRAP) - wiRenderer::BindSamplerPS(wiRenderer::samplers[SSLOT_ANISO_WRAP], SSLOT_ONDEMAND0, context); + wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_ANISO_WRAP], SSLOT_ONDEMAND0, threadID); else if (effects.sampleFlag == SAMPLEMODE_CLAMP) - wiRenderer::BindSamplerPS(wiRenderer::samplers[SSLOT_ANISO_CLAMP], SSLOT_ONDEMAND0, context); + wiRenderer::graphicsDevice->BindSamplerPS(wiRenderer::samplers[SSLOT_ANISO_CLAMP], SSLOT_ONDEMAND0, threadID); } - wiRenderer::Draw((fullScreenEffect ? 3 : 4), context); + wiRenderer::graphicsDevice->Draw((fullScreenEffect ? 3 : 4), threadID); } void wiImage::DrawDeferred(TextureView texture , TextureView depth, TextureView lightmap, TextureView normal - , TextureView ao, DeviceContext context, int stencilRef){ + , TextureView ao, GRAPHICSTHREAD threadID, int stencilRef){ - wiRenderer::BindPrimitiveTopology(PRIMITIVETOPOLOGY::TRIANGLELIST,context); - wiRenderer::BindRasterizerState(rasterizerState,context); - wiRenderer::BindDepthStencilState(depthNoStencilState,stencilRef,context); + wiRenderer::graphicsDevice->BindPrimitiveTopology(PRIMITIVETOPOLOGY::TRIANGLELIST,threadID); + wiRenderer::graphicsDevice->BindRasterizerState(rasterizerState,threadID); + wiRenderer::graphicsDevice->BindDepthStencilState(depthNoStencilState,stencilRef,threadID); - wiRenderer::BindVertexLayout(nullptr, context); - wiRenderer::BindVertexBuffer(nullptr, 0, 0, context); - wiRenderer::BindIndexBuffer(nullptr, context); + wiRenderer::graphicsDevice->BindVertexLayout(nullptr, threadID); + wiRenderer::graphicsDevice->BindVertexBuffer(nullptr, 0, 0, threadID); + wiRenderer::graphicsDevice->BindIndexBuffer(nullptr, threadID); - wiRenderer::BindVS(screenVS,context); - wiRenderer::BindPS(deferredPS,context); + wiRenderer::graphicsDevice->BindVS(screenVS,threadID); + wiRenderer::graphicsDevice->BindPS(deferredPS,threadID); - //wiRenderer::BindTexturePS(depth,0,context); - //wiRenderer::BindTexturePS(normal,1,context); - //wiRenderer::BindTexturePS(texture,6,context); - wiRenderer::BindTexturePS(lightmap,TEXSLOT_ONDEMAND0,context); - wiRenderer::BindTexturePS(ao,TEXSLOT_ONDEMAND1,context); + //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::BindBlendState(blendStateNoBlend,context); + wiRenderer::graphicsDevice->BindBlendState(blendStateNoBlend,threadID); - wiRenderer::Draw(3,context); + wiRenderer::graphicsDevice->Draw(3,threadID); } @@ -473,10 +472,10 @@ void wiImage::CleanUp() if(outlinePS) outlinePS->Release(); if(fxaaPS) fxaaPS->Release(); if(deferredPS) deferredPS->Release(); - wiRenderer::SafeRelease(colorGradePS); - wiRenderer::SafeRelease(ssrPS); - wiRenderer::SafeRelease(screenPS); - wiRenderer::SafeRelease(stereogramPS); + SAFE_RELEASE(colorGradePS); + SAFE_RELEASE(ssrPS); + SAFE_RELEASE(screenPS); + SAFE_RELEASE(stereogramPS); if(constantBuffer) constantBuffer->Release(); if(processCb) processCb->Release(); diff --git a/WickedEngine/wiImage.h b/WickedEngine/wiImage.h index 866ca82b9..4065fbfca 100644 --- a/WickedEngine/wiImage.h +++ b/WickedEngine/wiImage.h @@ -57,7 +57,7 @@ protected: public: static void LoadShaders(); - static void BindPersistentState(DeviceContext context); + static void BindPersistentState(GRAPHICSTHREAD threadID); private: static void LoadBuffers(); static void SetUpStates(); @@ -66,11 +66,11 @@ public: wiImage(); static void Draw(TextureView texture, const wiImageEffects& effects); - static void Draw(TextureView texture, const wiImageEffects& effects,DeviceContext context); + static void Draw(TextureView texture, const wiImageEffects& effects,GRAPHICSTHREAD threadID); static void DrawDeferred(TextureView texture , TextureView depth, TextureView lightmap, TextureView normal - , TextureView ao, DeviceContext context, int stencilref = 0); + , TextureView ao, GRAPHICSTHREAD threadID, int stencilref = 0); static void Load(); static void CleanUp(); diff --git a/WickedEngine/wiLensFlare.cpp b/WickedEngine/wiLensFlare.cpp index 17461d0c2..8de72cc1a 100644 --- a/WickedEngine/wiLensFlare.cpp +++ b/WickedEngine/wiLensFlare.cpp @@ -30,44 +30,44 @@ void wiLensFlare::CleanUp(){ if(blendState) blendState->Release(); blendState = NULL; if(depthStencilState) depthStencilState->Release(); depthStencilState = NULL; } -void wiLensFlare::Draw(DeviceContext context, const XMVECTOR& lightPos, vector& rims){ +void wiLensFlare::Draw(GRAPHICSTHREAD threadID, const XMVECTOR& lightPos, vector& rims){ if(!rims.empty()){ - wiRenderer::BindPrimitiveTopology(POINTLIST,context); - wiRenderer::BindVertexLayout(inputLayout,context); - wiRenderer::BindPS(pixelShader,context); - wiRenderer::BindVS(vertexShader,context); - wiRenderer::BindGS(geometryShader,context); + 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); 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); - wiRenderer::UpdateBuffer(constantBuffer,cb,context); - wiRenderer::BindConstantBufferGS(constantBuffer, CB_GETBINDSLOT(ConstantBuffer),context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffer,cb,threadID); + wiRenderer::graphicsDevice->BindConstantBufferGS(constantBuffer, CB_GETBINDSLOT(ConstantBuffer),threadID); - wiRenderer::BindRasterizerState(rasterizerState,context); - wiRenderer::BindDepthStencilState(depthStencilState,1,context); - wiRenderer::BindBlendState(blendState,context); + wiRenderer::graphicsDevice->BindRasterizerState(rasterizerState,threadID); + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencilState,1,threadID); + wiRenderer::graphicsDevice->BindBlendState(blendState,threadID); - //wiRenderer::BindTextureGS(depthMap,0,context); + //wiRenderer::graphicsDevice->BindTextureGS(depthMap,0,threadID); int i=0; for(TextureView x : rims){ if(x!=nullptr){ - wiRenderer::BindTexturePS(x, TEXSLOT_ONDEMAND0 + i, context); - wiRenderer::BindTextureGS(x, TEXSLOT_ONDEMAND0 + i, context); + wiRenderer::graphicsDevice->BindTexturePS(x, TEXSLOT_ONDEMAND0 + i, threadID); + wiRenderer::graphicsDevice->BindTextureGS(x, TEXSLOT_ONDEMAND0 + i, threadID); i++; } } - wiRenderer::Draw(i,context); + wiRenderer::graphicsDevice->Draw(i,threadID); - wiRenderer::BindGS(nullptr,context); + wiRenderer::graphicsDevice->BindGS(nullptr,threadID); } } @@ -75,7 +75,7 @@ void wiLensFlare::LoadShaders(){ VertexLayoutDesc layout[] = { - { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, }; UINT numElements = ARRAYSIZE(layout); VertexShaderInfo* vsinfo = static_cast(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "lensFlareVS.cso", wiResourceManager::VERTEXSHADER, layout, numElements)); @@ -92,20 +92,20 @@ void wiLensFlare::LoadShaders(){ } void wiLensFlare::SetUpCB() { - D3D11_BUFFER_DESC bd; + BufferDesc bd; ZeroMemory( &bd, sizeof(bd) ); - bd.Usage = D3D11_USAGE_DYNAMIC; + bd.Usage = USAGE_DYNAMIC; bd.ByteWidth = sizeof(ConstantBuffer); - bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + bd.BindFlags = BIND_CONSTANT_BUFFER; + bd.CPUAccessFlags = CPU_ACCESS_WRITE; wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &constantBuffer ); } void wiLensFlare::SetUpStates() { - D3D11_RASTERIZER_DESC rs; - rs.FillMode=D3D11_FILL_SOLID; - rs.CullMode=D3D11_CULL_NONE; + RasterizerDesc rs; + rs.FillMode=FILL_SOLID; + rs.CullMode=CULL_NONE; rs.FrontCounterClockwise=true; rs.DepthBias=0; rs.DepthBiasClamp=0; @@ -120,41 +120,41 @@ void wiLensFlare::SetUpStates() - D3D11_DEPTH_STENCIL_DESC dsd; + DepthStencilDesc dsd; dsd.DepthEnable = false; - dsd.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO; - dsd.DepthFunc = D3D11_COMPARISON_LESS; + dsd.DepthWriteMask = DEPTH_WRITE_MASK_ZERO; + dsd.DepthFunc = COMPARISON_LESS; dsd.StencilEnable = false; dsd.StencilReadMask = 0xFF; dsd.StencilWriteMask = 0xFF; // Stencil operations if pixel is front-facing. - dsd.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR; - dsd.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - dsd.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; + dsd.FrontFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.FrontFace.StencilDepthFailOp = STENCIL_OP_INCR; + dsd.FrontFace.StencilPassOp = STENCIL_OP_KEEP; + dsd.FrontFace.StencilFunc = COMPARISON_ALWAYS; // Stencil operations if pixel is back-facing. - dsd.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR; - dsd.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; + dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilDepthFailOp = STENCIL_OP_DECR; + dsd.BackFace.StencilPassOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilFunc = COMPARISON_ALWAYS; // Create the depth stencil state. wiRenderer::graphicsDevice->CreateDepthStencilState(&dsd, &depthStencilState); - D3D11_BLEND_DESC bd; + BlendDesc bd; ZeroMemory(&bd, sizeof(bd)); bd.RenderTarget[0].BlendEnable=true; - bd.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; - bd.RenderTarget[0].DestBlend = D3D11_BLEND_ONE; - bd.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - bd.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; - bd.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; - bd.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlend = BLEND_ONE; + bd.RenderTarget[0].DestBlend = BLEND_ONE; + bd.RenderTarget[0].BlendOp = BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlendAlpha = BLEND_ONE; + bd.RenderTarget[0].DestBlendAlpha = BLEND_ZERO; + bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; wiRenderer::graphicsDevice->CreateBlendState(&bd,&blendState); } diff --git a/WickedEngine/wiLensFlare.h b/WickedEngine/wiLensFlare.h index 9c0a5fc85..1bc0df17e 100644 --- a/WickedEngine/wiLensFlare.h +++ b/WickedEngine/wiLensFlare.h @@ -33,7 +33,7 @@ private: public: static void Initialize(); static void CleanUp(); - static void Draw(DeviceContext context, const XMVECTOR& lightPos, vector& rims); + static void Draw(GRAPHICSTHREAD threadID, const XMVECTOR& lightPos, vector& rims); }; #endif diff --git a/WickedEngine/wiLines.cpp b/WickedEngine/wiLines.cpp index 1cd6acd07..c0004dd5a 100644 --- a/WickedEngine/wiLines.cpp +++ b/WickedEngine/wiLines.cpp @@ -33,13 +33,13 @@ Lines::Lines(const XMFLOAT3& a, const XMFLOAT3& b, const XMFLOAT4& c) verts[0].pos = XMFLOAT3(a.x,a.y,a.z); verts[1].pos = XMFLOAT3(b.x,b.y,b.z); - D3D11_BUFFER_DESC bd; + BufferDesc bd; ZeroMemory( &bd, sizeof(bd) ); - bd.Usage = D3D11_USAGE_DEFAULT; + bd.Usage = USAGE_DEFAULT; bd.ByteWidth = sizeof( Vertex ) * 2; - bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; + bd.BindFlags = BIND_VERTEX_BUFFER; bd.CPUAccessFlags = 0; - D3D11_SUBRESOURCE_DATA InitData; + SubresourceData InitData; ZeroMemory( &InitData, sizeof(InitData) ); InitData.pSysMem = verts; wiRenderer::graphicsDevice->CreateBuffer( &bd, &InitData, &vertexBuffer ); @@ -69,13 +69,13 @@ void Lines::SetUpVertices() verts[0].pos = XMFLOAT3(0,0,0); verts[1].pos = XMFLOAT3(0,0,desc.length); - D3D11_BUFFER_DESC bd; + BufferDesc bd; ZeroMemory( &bd, sizeof(bd) ); - bd.Usage = D3D11_USAGE_DEFAULT; + bd.Usage = USAGE_DEFAULT; bd.ByteWidth = sizeof( Vertex ) * 2; - bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; + bd.BindFlags = BIND_VERTEX_BUFFER; bd.CPUAccessFlags = 0; - D3D11_SUBRESOURCE_DATA InitData; + SubresourceData InitData; ZeroMemory( &InitData, sizeof(InitData) ); InitData.pSysMem = verts; wiRenderer::graphicsDevice->CreateBuffer( &bd, &InitData, &vertexBuffer ); diff --git a/WickedEngine/wiLoader.cpp b/WickedEngine/wiLoader.cpp index 83f1e907e..94c7545c5 100644 --- a/WickedEngine/wiLoader.cpp +++ b/WickedEngine/wiLoader.cpp @@ -479,12 +479,12 @@ void LoadWiObjects(const string& directory, const string& name, const string& id // if(objects[i]->mesh){ // if(objects[i]->mesh->trailInfo.base>=0 && objects[i]->mesh->trailInfo.tip>=0){ // //objects[i]->trail.resize(MAX_RIBBONTRAILS); - // D3D11_BUFFER_DESC bd; + // BufferDesc bd; // ZeroMemory( &bd, sizeof(bd) ); - // bd.Usage = D3D11_USAGE_DYNAMIC; + // bd.Usage = USAGE_DYNAMIC; // bd.ByteWidth = sizeof( RibbonVertex ) * 1000; - // bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; - // bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + // bd.BindFlags = BIND_VERTEX_BUFFER; + // bd.CPUAccessFlags = CPU_ACCESS_WRITE; // wiRenderer::graphicsDevice->CreateBuffer( &bd, NULL, &objects[i]->trailBuff ); // objects[i]->trailTex = wiTextureHelper::getInstance()->getTransparent(); // objects[i]->trailDistortTex = wiTextureHelper::getInstance()->getNormalMapDefault(); @@ -945,12 +945,12 @@ void LoadWiLights(const string& directory, const string& name, const string& ide //for(MeshCollection::iterator iter=lightGwiRenderer.begin(); iter!=lightGwiRenderer.end(); ++iter){ // Mesh* iMesh = iter->second; - // D3D11_BUFFER_DESC bd; + // BufferDesc bd; // ZeroMemory( &bd, sizeof(bd) ); - // bd.Usage = D3D11_USAGE_DYNAMIC; + // bd.Usage = USAGE_DYNAMIC; // bd.ByteWidth = sizeof( Instance )*iMesh->usedBy.size(); - // bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; - // bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + // bd.BindFlags = BIND_VERTEX_BUFFER; + // bd.CPUAccessFlags = CPU_ACCESS_WRITE; // wiRenderer::graphicsDevice->CreateBuffer( &bd, 0, &iMesh->meshInstanceBuffer ); //} } @@ -1674,14 +1674,14 @@ void Mesh::Optimize() void Mesh::CreateBuffers(Object* object) { if (!buffersComplete) { - D3D11_BUFFER_DESC bd; + BufferDesc bd; if (meshInstanceBuffer == nullptr) { ZeroMemory(&bd, sizeof(bd)); - bd.Usage = D3D11_USAGE_DYNAMIC; + bd.Usage = USAGE_DYNAMIC; bd.ByteWidth = sizeof(Instance) * 2; - bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + bd.BindFlags = BIND_VERTEX_BUFFER; + bd.CPUAccessFlags = CPU_ACCESS_WRITE; wiRenderer::graphicsDevice->CreateBuffer(&bd, 0, &meshInstanceBuffer); } @@ -1695,19 +1695,19 @@ void Mesh::CreateBuffers(Object* object) { ZeroMemory(&bd, sizeof(bd)); #ifdef USE_GPU_SKINNING - bd.Usage = (softBody ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_IMMUTABLE); - bd.CPUAccessFlags = (softBody ? D3D11_CPU_ACCESS_WRITE : 0); + bd.Usage = (softBody ? USAGE_DYNAMIC : USAGE_IMMUTABLE); + bd.CPUAccessFlags = (softBody ? CPU_ACCESS_WRITE : 0); if (object->isArmatureDeformed() && !softBody) bd.ByteWidth = sizeof(SkinnedVertex) * vertices.size(); else bd.ByteWidth = sizeof(Vertex) * vertices.size(); #else - bd.Usage = ((softBody || object->isArmatureDeformed()) ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_IMMUTABLE); - bd.CPUAccessFlags = ((softBody || object->isArmatureDeformed()) ? D3D11_CPU_ACCESS_WRITE : 0); + bd.Usage = ((softBody || object->isArmatureDeformed()) ? USAGE_DYNAMIC : USAGE_IMMUTABLE); + bd.CPUAccessFlags = ((softBody || object->isArmatureDeformed()) ? CPU_ACCESS_WRITE : 0); bd.ByteWidth = sizeof(Vertex) * vertices.size(); #endif - bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; - D3D11_SUBRESOURCE_DATA InitData; + bd.BindFlags = BIND_VERTEX_BUFFER; + SubresourceData InitData; ZeroMemory(&InitData, sizeof(InitData)); if (object->isArmatureDeformed() && !softBody) InitData.pSysMem = vertices.data(); @@ -1717,9 +1717,9 @@ void Mesh::CreateBuffers(Object* object) { ZeroMemory(&bd, sizeof(bd)); - bd.Usage = D3D11_USAGE_IMMUTABLE; + bd.Usage = USAGE_IMMUTABLE; bd.ByteWidth = sizeof(unsigned int) * indices.size(); - bd.BindFlags = D3D11_BIND_INDEX_BUFFER; + bd.BindFlags = BIND_INDEX_BUFFER; bd.CPUAccessFlags = 0; ZeroMemory(&InitData, sizeof(InitData)); InitData.pSysMem = indices.data(); @@ -1730,9 +1730,9 @@ void Mesh::CreateBuffers(Object* object) { if (object->isArmatureDeformed() && !softBody) { ZeroMemory(&bd, sizeof(bd)); - bd.Usage = D3D11_USAGE_DEFAULT; + bd.Usage = USAGE_DEFAULT; bd.ByteWidth = sizeof(Vertex) * vertices.size(); - bd.BindFlags = D3D11_BIND_STREAM_OUTPUT | D3D11_BIND_VERTEX_BUFFER; + bd.BindFlags = BIND_STREAM_OUTPUT | BIND_VERTEX_BUFFER; bd.CPUAccessFlags = 0; bd.StructureByteStride = 0; wiRenderer::graphicsDevice->CreateBuffer(&bd, NULL, &sOutBuffer); @@ -1781,9 +1781,9 @@ void Mesh::AddRenderableInstance(const Instance& instance, int numerator) } instances[numerator] = instance; } -void Mesh::UpdateRenderableInstances(int count, DeviceContext context) +void Mesh::UpdateRenderableInstances(int count, GRAPHICSTHREAD threadID) { - wiRenderer::UpdateBuffer(meshInstanceBuffer, instances.data(), context, sizeof(Instance)*count); + wiRenderer::graphicsDevice->UpdateBuffer(meshInstanceBuffer, instances.data(), threadID, sizeof(Instance)*count); } #pragma endregion @@ -1926,12 +1926,12 @@ void Model::LoadFromDisk(const string& dir, const string& name, const string& id { // Ribbon trails if (x->mesh->trailInfo.base >= 0 && x->mesh->trailInfo.tip >= 0) { - D3D11_BUFFER_DESC bd; + BufferDesc bd; ZeroMemory(&bd, sizeof(bd)); - bd.Usage = D3D11_USAGE_DYNAMIC; + bd.Usage = USAGE_DYNAMIC; bd.ByteWidth = sizeof(RibbonVertex) * 1000; - bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + bd.BindFlags = BIND_VERTEX_BUFFER; + bd.CPUAccessFlags = CPU_ACCESS_WRITE; wiRenderer::graphicsDevice->CreateBuffer(&bd, NULL, &x->trailBuff); x->trailTex = wiTextureHelper::getInstance()->getTransparent(); x->trailDistortTex = wiTextureHelper::getInstance()->getNormalMapDefault(); @@ -2162,13 +2162,13 @@ void HitSphere::SetUpStatic() verts.push_back(XMFLOAT3A(XMFLOAT3A(0,0,0))); } - D3D11_BUFFER_DESC bd; + BufferDesc bd; ZeroMemory( &bd, sizeof(bd) ); - bd.Usage = D3D11_USAGE_IMMUTABLE; + bd.Usage = USAGE_IMMUTABLE; bd.ByteWidth = sizeof( XMFLOAT3A )*verts.size(); - bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; + bd.BindFlags = BIND_VERTEX_BUFFER; bd.CPUAccessFlags = 0; - D3D11_SUBRESOURCE_DATA InitData; + SubresourceData InitData; ZeroMemory( &InitData, sizeof(InitData) ); InitData.pSysMem = verts.data(); wiRenderer::graphicsDevice->CreateBuffer( &bd, &InitData, &vertexBuffer ); diff --git a/WickedEngine/wiLoader.h b/WickedEngine/wiLoader.h index bced7d3bc..a69ad08f6 100644 --- a/WickedEngine/wiLoader.h +++ b/WickedEngine/wiLoader.h @@ -347,7 +347,7 @@ struct Mesh{ void CreateBuffers(Object* object); void CreateVertexArrays(); static void AddRenderableInstance(const Instance& instance, int numerator); - static void UpdateRenderableInstances(int count, DeviceContext context); + static void UpdateRenderableInstances(int count, GRAPHICSTHREAD threadID); void init(){ parent=""; vertices.resize(0); diff --git a/WickedEngine/wiRenderTarget.cpp b/WickedEngine/wiRenderTarget.cpp index 13d891c98..ce13e76b1 100644 --- a/WickedEngine/wiRenderTarget.cpp +++ b/WickedEngine/wiRenderTarget.cpp @@ -54,26 +54,27 @@ void wiRenderTarget::Initialize(UINT width, UINT height, int numViews, bool hasD textureDesc.Format = format; textureDesc.SampleDesc.Count = MSAAC; textureDesc.SampleDesc.Quality = MSAAQ; - textureDesc.Usage = D3D11_USAGE_DEFAULT; - textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; + textureDesc.Usage = USAGE_DEFAULT; + textureDesc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; textureDesc.CPUAccessFlags = 0; textureDesc.MiscFlags = 0; if (mipMapLevelCount != 1) { - textureDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS; + textureDesc.MiscFlags = RESOURCE_MISC_GENERATE_MIPS; } - D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc; + RenderTargetViewDesc renderTargetViewDesc; renderTargetViewDesc.Format = format; - renderTargetViewDesc.ViewDimension = (MSAAQ==0 ? D3D11_RTV_DIMENSION_TEXTURE2D : D3D11_RTV_DIMENSION_TEXTURE2DMS); - renderTargetViewDesc.Texture2D.MipSlice = 0; + renderTargetViewDesc.ViewDimension = (MSAAQ==0 ? RESOURCE_DIMENSION_TEXTURE2D : RESOURCE_DIMENSION_TEXTURE2DMS); + //renderTargetViewDesc.Texture2D.MipSlice = 0; - D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc; + ShaderResourceViewDesc shaderResourceViewDesc; shaderResourceViewDesc.Format = format; - shaderResourceViewDesc.ViewDimension = (MSAAQ==0 ? D3D11_SRV_DIMENSION_TEXTURE2D : D3D11_SRV_DIMENSION_TEXTURE2DMS); - shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; //from most detailed... - shaderResourceViewDesc.Texture2D.MipLevels = -1; //...to least detailed + shaderResourceViewDesc.ViewDimension = (MSAAQ==0 ? RESOURCE_DIMENSION_TEXTURE2D : RESOURCE_DIMENSION_TEXTURE2DMS); + //shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; //from most detailed... + //shaderResourceViewDesc.Texture2D.MipLevels = -1; //...to least detailed + shaderResourceViewDesc.mipLevels = -1; for(int i=0;iCreateTexture2D(&textureDesc, nullptr, &texture2D[i]); @@ -109,29 +110,30 @@ void wiRenderTarget::InitializeCube(UINT size, int numViews, bool hasDepth, DXGI textureDesc.Format = format; textureDesc.SampleDesc.Count = 1; textureDesc.SampleDesc.Quality = 0; - textureDesc.Usage = D3D11_USAGE_DEFAULT; - textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; + textureDesc.Usage = USAGE_DEFAULT; + textureDesc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; textureDesc.CPUAccessFlags = 0; - textureDesc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE; + textureDesc.MiscFlags = RESOURCE_MISC_TEXTURECUBE; if (mipMapLevelCount != 1) { - textureDesc.MiscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS; + textureDesc.MiscFlags |= RESOURCE_MISC_GENERATE_MIPS; } - D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc; + RenderTargetViewDesc renderTargetViewDesc; renderTargetViewDesc.Format = format; - renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; - renderTargetViewDesc.Texture2DArray.FirstArraySlice = 0; - renderTargetViewDesc.Texture2DArray.ArraySize = 6; - renderTargetViewDesc.Texture2DArray.MipSlice = 0; - + renderTargetViewDesc.ViewDimension = RESOURCE_DIMENSION_TEXTURE2DARRAY; + // renderTargetViewDesc.Texture2DArray.FirstArraySlice = 0; + //renderTargetViewDesc.Texture2DArray.ArraySize = 6; + // renderTargetViewDesc.Texture2DArray.MipSlice = 0; + renderTargetViewDesc.ArraySize = 6; - D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc; + ShaderResourceViewDesc shaderResourceViewDesc; shaderResourceViewDesc.Format = format; - shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; - shaderResourceViewDesc.TextureCube.MostDetailedMip = 0; //from most detailed... - shaderResourceViewDesc.TextureCube.MipLevels = -1; //...to least detailed + shaderResourceViewDesc.ViewDimension = RESOURCE_DIMENSION_TEXTURECUBE; + //shaderResourceViewDesc.TextureCube.MostDetailedMip = 0; //from most detailed... + //shaderResourceViewDesc.TextureCube.MipLevels = -1; //...to least detailed + shaderResourceViewDesc.mipLevels = -1; for(int i=0;iCreateTexture2D(&textureDesc, NULL, &texture2D[i]); @@ -156,51 +158,43 @@ void wiRenderTarget::InitializeCube(UINT size, int numViews, bool hasDepth) InitializeCube(size,numViews,hasDepth,DXGI_FORMAT_R8G8B8A8_UNORM); } -void wiRenderTarget::Activate(DeviceContext context) +void wiRenderTarget::Activate(GRAPHICSTHREAD threadID) { - Activate(context,0,0,0,0); + Activate(threadID,0,0,0,0); } -void wiRenderTarget::Activate(DeviceContext context, float r, float g, float b, float a) +void wiRenderTarget::Activate(GRAPHICSTHREAD threadID, float r, float g, float b, float a) { - if(context!=nullptr){ - Set(context); - float ClearColor[4] = { r, g, b, a }; - for(int i=0;iClearRenderTargetView(renderTarget[i], ClearColor); - if(depth) depth->Clear(context); - } + Set(threadID); + float ClearColor[4] = { r, g, b, a }; + for(int i=0;iClearRenderTarget(renderTarget[i], ClearColor); + if(depth) depth->Clear(threadID); } -void wiRenderTarget::Activate(DeviceContext context, wiDepthTarget* getDepth, float r, float g, float b, float a) +void wiRenderTarget::Activate(GRAPHICSTHREAD threadID, wiDepthTarget* getDepth, float r, float g, float b, float a) { - if(context!=nullptr){ - Set(context,getDepth); - float ClearColor[4] = { r, g, b, a }; - for(int i=0;iClearRenderTargetView(renderTarget[i], ClearColor); - } + Set(threadID,getDepth); + float ClearColor[4] = { r, g, b, a }; + for(int i=0;iClearRenderTarget(renderTarget[i], ClearColor); } -void wiRenderTarget::Activate(DeviceContext context, wiDepthTarget* getDepth) +void wiRenderTarget::Activate(GRAPHICSTHREAD threadID, wiDepthTarget* getDepth) { - Activate(context,getDepth,0,0,0,0); + Activate(threadID,getDepth,0,0,0,0); } -void wiRenderTarget::Deactivate(DeviceContext context) +void wiRenderTarget::Deactivate(GRAPHICSTHREAD threadID) { - context->OMSetRenderTargets(0, nullptr, nullptr); + wiRenderer::graphicsDevice->BindRenderTargets(0, nullptr, nullptr); } -void wiRenderTarget::Set(DeviceContext context) +void wiRenderTarget::Set(GRAPHICSTHREAD threadID) { - if(context!=nullptr){ - context->RSSetViewports(1, &viewPort); - context->OMSetRenderTargets(numViews, renderTarget.data(),(depth?depth->depthTarget:nullptr)); - } + wiRenderer::graphicsDevice->BindViewports(1, &viewPort); + wiRenderer::graphicsDevice->BindRenderTargets(numViews, renderTarget.data(),(depth?depth->depthTarget:nullptr)); } -void wiRenderTarget::Set(DeviceContext context, wiDepthTarget* getDepth) +void wiRenderTarget::Set(GRAPHICSTHREAD threadID, wiDepthTarget* getDepth) { - if(context!=nullptr){ - depth = getDepth; - context->RSSetViewports(1, &viewPort); - context->OMSetRenderTargets(numViews, renderTarget.data(),(depth?depth->depthTarget:nullptr)); - } + depth = getDepth; + wiRenderer::graphicsDevice->BindViewports(1, &viewPort); + wiRenderer::graphicsDevice->BindRenderTargets(numViews, renderTarget.data(),(depth?depth->depthTarget:nullptr)); } void wiRenderTarget::Retarget(TextureView resource) { diff --git a/WickedEngine/wiRenderTarget.h b/WickedEngine/wiRenderTarget.h index 82a92aa7f..609f5efe6 100644 --- a/WickedEngine/wiRenderTarget.h +++ b/WickedEngine/wiRenderTarget.h @@ -26,13 +26,13 @@ public: void Initialize(UINT width, UINT height, int numViews = 1, bool hasDepth = false, UINT MSAAC = 1, UINT MSAAQ = 0, DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM, UINT mipMapLevelCount = 1); void InitializeCube(UINT size, int numViews, bool hasDepth, DXGI_FORMAT format, UINT mipMapLevelCount = 1); void InitializeCube(UINT size, int numViews, bool hasDepth); - void Activate(DeviceContext); - void Activate(DeviceContext context, float r, float g, float b, float a); - void Activate(DeviceContext context, wiDepthTarget*, float r, float g, float b, float a); - void Activate(DeviceContext context, wiDepthTarget*); - void Deactivate(DeviceContext context); - void Set(DeviceContext context); - void Set(DeviceContext context, wiDepthTarget*); + void Activate(GRAPHICSTHREAD threadID); + void Activate(GRAPHICSTHREAD threadID, float r, float g, float b, float a); + void Activate(GRAPHICSTHREAD threadID, wiDepthTarget*, float r, float g, float b, float a); + void Activate(GRAPHICSTHREAD threadID, wiDepthTarget*); + void Deactivate(GRAPHICSTHREAD threadID); + void Set(GRAPHICSTHREAD threadID); + void Set(GRAPHICSTHREAD threadID, wiDepthTarget*); void Retarget(TextureView resource); void Restore(); diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 080403d80..608bfd6a0 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -21,22 +21,11 @@ #include "wiRandom.h" #include "wiFont.h" #include "TextureMapping.h" +#include "wiGraphicsAPI_DX11.h" #pragma region STATICS -D3D_DRIVER_TYPE wiRenderer::driverType; -D3D_FEATURE_LEVEL wiRenderer::featureLevel; -SwapChain wiRenderer::swapChain; -RenderTargetView wiRenderer::renderTargetView; -ViewPort wiRenderer::viewPort; -GraphicsDevice wiRenderer::graphicsDevice; -DeviceContext wiRenderer::immediateContext; -bool wiRenderer::DX11 = false,wiRenderer::VSYNC=true,wiRenderer::DEFERREDCONTEXT_SUPPORT=false; -DeviceContext wiRenderer::deferredContexts[]; -CommandList wiRenderer::commandLists[]; -mutex wiRenderer::graphicsMutex; Sampler wiRenderer::samplers[SSLOT_COUNT]; -map wiRenderer::drawCalls; BufferResource wiRenderer::constantBuffers[CBTYPE_LAST]; VertexShader wiRenderer::vertexShaders[VSTYPE_LAST]; PixelShader wiRenderer::pixelShaders[PSTYPE_LAST]; @@ -93,186 +82,21 @@ HRESULT wiRenderer::InitDevice(HWND window, int screenW, int screenH, bool windo HRESULT wiRenderer::InitDevice(Windows::UI::Core::CoreWindow^ window) #endif { - HRESULT hr = S_OK; + SCREENWIDTH = screenW; + SCREENHEIGHT = screenH; - UINT createDeviceFlags = 0; -#ifdef _DEBUG - createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; -#endif + graphicsDevice = new GraphicsDevice_DX11(window, screenW, screenH, windowed); - D3D_DRIVER_TYPE driverTypes[] = - { - D3D_DRIVER_TYPE_HARDWARE, - D3D_DRIVER_TYPE_WARP, - D3D_DRIVER_TYPE_REFERENCE, - }; - UINT numDriverTypes = ARRAYSIZE( driverTypes ); - - D3D_FEATURE_LEVEL featureLevels[] = - { - D3D_FEATURE_LEVEL_11_1, - D3D_FEATURE_LEVEL_11_0, - D3D_FEATURE_LEVEL_10_1, - //D3D_FEATURE_LEVEL_10_0, - }; - UINT numFeatureLevels = ARRAYSIZE( featureLevels ); - -#ifndef WINSTORE_SUPPORT - DXGI_SWAP_CHAIN_DESC sd; - ZeroMemory( &sd, sizeof( sd ) ); - sd.BufferCount = 2; - sd.BufferDesc.Width = SCREENWIDTH = screenW; - sd.BufferDesc.Height = SCREENHEIGHT = screenH; - sd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; - sd.BufferDesc.RefreshRate.Numerator = 60; - sd.BufferDesc.RefreshRate.Denominator = 1; - sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - sd.OutputWindow = window; - sd.SampleDesc.Count = 1; - sd.SampleDesc.Quality = 0; - sd.Windowed = windowed; -#endif - - for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ ) - { - driverType = driverTypes[driverTypeIndex]; -#ifndef WINSTORE_SUPPORT - hr = D3D11CreateDeviceAndSwapChain( NULL, driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels, - D3D11_SDK_VERSION, &sd, &swapChain, &graphicsDevice, &featureLevel, &immediateContext ); -#else - hr = D3D11CreateDevice(nullptr, driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &graphicsDevice - , &featureLevel, &immediateContext); -#endif - - if( SUCCEEDED( hr ) ) - break; - } - if(FAILED(hr)){ - wiHelper::messageBox("SwapChain Creation Failed!","Error!",nullptr); -#ifdef BACKLOG - wiBackLog::post("SwapChain Creation Failed!"); -#endif - exit(1); - } - DX11 = ( ( wiRenderer::graphicsDevice->GetFeatureLevel() >= D3D_FEATURE_LEVEL_11_0 ) ? true:false ); - drawCalls.insert(pair(immediateContext,0)); - - -#ifdef WINSTORE_SUPPORT - DXGI_SWAP_CHAIN_DESC1 sd = { 0 }; - sd.Width = SCREENWIDTH = (int)window->Bounds.Width; - sd.Height = SCREENHEIGHT = (int)window->Bounds.Height; - sd.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // This is the most common swap chain format. - sd.Stereo = false; - sd.SampleDesc.Count = 1; // Don't use multi-sampling. - sd.SampleDesc.Quality = 0; - sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - sd.BufferCount = 2; // Use double-buffering to minimize latency. - sd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Windows Store apps must use this SwapEffect. - sd.Flags = 0; - sd.Scaling = DXGI_SCALING_NONE; - sd.AlphaMode = DXGI_ALPHA_MODE_IGNORE; - - IDXGIDevice2 * pDXGIDevice; - hr = graphicsDevice->QueryInterface(__uuidof(IDXGIDevice2), (void **)&pDXGIDevice); - - IDXGIAdapter * pDXGIAdapter; - hr = pDXGIDevice->GetParent(__uuidof(IDXGIAdapter), (void **)&pDXGIAdapter); - - IDXGIFactory2 * pIDXGIFactory; - pDXGIAdapter->GetParent(__uuidof(IDXGIFactory2), (void **)&pIDXGIFactory); - - - hr = pIDXGIFactory->CreateSwapChainForCoreWindow(graphicsDevice, reinterpret_cast(window), &sd - , nullptr, &swapChain); - - if (FAILED(hr)){ - wiHelper::messageBox("Swap chain creation failed!", "Error!"); - exit(1); - } -#endif - - DEFERREDCONTEXT_SUPPORT = false; - D3D11_FEATURE_DATA_THREADING threadingFeature; - wiRenderer::graphicsDevice->CheckFeatureSupport( D3D11_FEATURE_THREADING,&threadingFeature,sizeof(threadingFeature) ); - if (threadingFeature.DriverConcurrentCreates && threadingFeature.DriverCommandLists){ - DEFERREDCONTEXT_SUPPORT = true; - for (int i = 0; iCreateDeferredContext( 0,&deferredContexts[i] ); - drawCalls.insert(pair(deferredContexts[i],0)); - } -#ifdef BACKLOG - stringstream ss(""); - ss<GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer ); - if( FAILED( hr ) ){ - wiHelper::messageBox("BackBuffer creation Failed!", "Error!", nullptr); - exit(0); - } - - hr = wiRenderer::graphicsDevice->CreateRenderTargetView( pBackBuffer, NULL, &renderTargetView ); - //pBackBuffer->Release(); - if( FAILED( hr ) ){ - wiHelper::messageBox("Main Rendertarget creation Failed!", "Error!", nullptr); - exit(0); - } - - - // Setup the main viewport - viewPort.Width = (FLOAT)SCREENWIDTH; - viewPort.Height = (FLOAT)SCREENHEIGHT; - viewPort.MinDepth = 0.0f; - viewPort.MaxDepth = 1.0f; - viewPort.TopLeftX = 0; - viewPort.TopLeftY = 0; - - - return S_OK; + return (graphicsDevice != nullptr ? S_OK : E_FAIL); } void wiRenderer::DestroyDevice() { - - if( renderTargetView ) - renderTargetView->Release(); - if( swapChain ) - swapChain->Release(); - if( wiRenderer::getImmediateContext() ) - wiRenderer::getImmediateContext()->ClearState(); - if( wiRenderer::getImmediateContext() ) - wiRenderer::getImmediateContext()->Release(); - if( graphicsDevice ) - graphicsDevice->Release(); - - for(int i=0;iRelease(); commandLists[i]=0;} - if(deferredContexts[i]) {deferredContexts[i]->Release(); deferredContexts[i]=0;} - } + SAFE_DELETE(graphicsDevice); } void wiRenderer::Present(function drawToScreen1,function drawToScreen2,function drawToScreen3) { - Lock(); - - immediateContext->RSSetViewports( 1, &viewPort ); - immediateContext->OMSetRenderTargets( 1, &renderTargetView, 0 ); - float ClearColor[4] = { 0, 0, 0, 1.0f }; // red,green,blue,alpha - immediateContext->ClearRenderTargetView( renderTargetView, ClearColor ); - //wiRenderer::getImmediateContext()->ClearDepthStencilView( g_pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0); + graphicsDevice->PresentBegin(); if(drawToScreen1!=nullptr) drawToScreen1(); @@ -285,47 +109,11 @@ void wiRenderer::Present(function drawToScreen1,function drawToS wiFrameRate::Frame(); - swapChain->Present( VSYNC, 0 ); - - for(auto& d : drawCalls){ - d.second=0; - } - - - immediateContext->OMSetRenderTargets(0,nullptr,nullptr); - - UnbindTextures(0, TEXSLOT_COUNT, immediateContext); - - Unlock(); + graphicsDevice->PresentEnd(); *prevFrameCam = *cam; } -void wiRenderer::ExecuteDeferredContexts() -{ - for (int i = 0; i < GRAPHICSTHREAD_COUNT; i++) - { - if (commandLists[i]) - { - immediateContext->ExecuteCommandList(commandLists[i], true); - commandLists[i]->Release(); - commandLists[i] = nullptr; - UnbindTextures(0, TEXSLOT_COUNT, deferredContexts[i]); - } - } -} -void wiRenderer::FinishCommandList(GRAPHICSTHREAD thread) -{ - deferredContexts[thread]->FinishCommandList(true, &commandLists[thread]); -} - -long wiRenderer::getDrawCallCount(){ - long retVal=0; - for(auto d:drawCalls){ - retVal+=d.second; - } - return retVal; -} void wiRenderer::CleanUp() { @@ -338,43 +126,43 @@ void wiRenderer::SetUpStaticComponents() { for (int i = 0; i < CBTYPE_LAST; ++i) { - SafeInit(constantBuffers[i]); + SAFE_INIT(constantBuffers[i]); } for (int i = 0; i < VSTYPE_LAST; ++i) { - SafeInit(vertexShaders[i]); + SAFE_INIT(vertexShaders[i]); } for (int i = 0; i < PSTYPE_LAST; ++i) { - SafeInit(pixelShaders[i]); + SAFE_INIT(pixelShaders[i]); } for (int i = 0; i < GSTYPE_LAST; ++i) { - SafeInit(geometryShaders[i]); + SAFE_INIT(geometryShaders[i]); } for (int i = 0; i < HSTYPE_LAST; ++i) { - SafeInit(hullShaders[i]); + SAFE_INIT(hullShaders[i]); } for (int i = 0; i < DSTYPE_LAST; ++i) { - SafeInit(domainShaders[i]); + SAFE_INIT(domainShaders[i]); } for (int i = 0; i < RSTYPE_LAST; ++i) { - SafeInit(rasterizers[i]); + SAFE_INIT(rasterizers[i]); } for (int i = 0; i < DSSTYPE_LAST; ++i) { - SafeInit(depthStencils[i]); + SAFE_INIT(depthStencils[i]); } for (int i = 0; i < VLTYPE_LAST; ++i) { - SafeInit(vertexLayouts[i]); + SAFE_INIT(vertexLayouts[i]); } for (int i = 0; i < SSLOT_COUNT_PERSISTENT; ++i) { - SafeInit(samplers[i]); + SAFE_INIT(samplers[i]); } //thread t1(LoadBasicShaders); @@ -446,7 +234,7 @@ void wiRenderer::SetUpStaticComponents() SetPointLightShadowProps(2, 512); SetSpotLightShadowProps(2, 512); - BindPersistentState(getImmediateContext()); + BindPersistentState(GRAPHICSTHREAD_IMMEDIATE); //t1.join(); //t2.join(); @@ -468,47 +256,47 @@ void wiRenderer::CleanUpStatic() for (int i = 0; i < CBTYPE_LAST; ++i) { - SafeRelease(constantBuffers[i]); + SAFE_RELEASE(constantBuffers[i]); } for (int i = 0; i < VSTYPE_LAST; ++i) { - SafeRelease(vertexShaders[i]); + SAFE_RELEASE(vertexShaders[i]); } for (int i = 0; i < PSTYPE_LAST; ++i) { - SafeRelease(pixelShaders[i]); + SAFE_RELEASE(pixelShaders[i]); } for (int i = 0; i < GSTYPE_LAST; ++i) { - SafeRelease(geometryShaders[i]); + SAFE_RELEASE(geometryShaders[i]); } for (int i = 0; i < HSTYPE_LAST; ++i) { - SafeRelease(hullShaders[i]); + SAFE_RELEASE(hullShaders[i]); } for (int i = 0; i < DSTYPE_LAST; ++i) { - SafeRelease(domainShaders[i]); + SAFE_RELEASE(domainShaders[i]); } for (int i = 0; i < RSTYPE_LAST; ++i) { - SafeRelease(rasterizers[i]); + SAFE_RELEASE(rasterizers[i]); } for (int i = 0; i < DSSTYPE_LAST; ++i) { - SafeRelease(depthStencils[i]); + SAFE_RELEASE(depthStencils[i]); } for (int i = 0; i < VLTYPE_LAST; ++i) { - SafeRelease(vertexLayouts[i]); + SAFE_RELEASE(vertexLayouts[i]); } for (int i = 0; i < BSTYPE_LAST; ++i) { - SafeRelease(blendStates[i]); + SAFE_RELEASE(blendStates[i]); } for (int i = 0; i < SSLOT_COUNT_PERSISTENT; ++i) { - SafeRelease(samplers[i]); + SAFE_RELEASE(samplers[i]); } if (physicsEngine) physicsEngine->CleanUp(); @@ -701,11 +489,11 @@ void wiRenderer::LoadBuffers() constantBuffers[i] = nullptr; } - D3D11_BUFFER_DESC bd; + BufferDesc bd; ZeroMemory( &bd, sizeof(bd) ); - bd.Usage = D3D11_USAGE_DYNAMIC; - bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + bd.Usage = USAGE_DYNAMIC; + bd.BindFlags = BIND_CONSTANT_BUFFER; + bd.CPUAccessFlags = CPU_ACCESS_WRITE; //Persistent buffers... bd.ByteWidth = sizeof(WorldCB); @@ -759,15 +547,15 @@ void wiRenderer::LoadBasicShaders() { VertexLayoutDesc layout[] = { - { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "NORMAL", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "NORMAL", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, - { "MATI", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, - { "MATI", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, - { "MATI", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, - { "COLOR_DITHER", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, + { "MATI", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "MATI", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "MATI", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "COLOR_DITHER", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, }; UINT numElements = ARRAYSIZE(layout); VertexShaderInfo* vsinfo = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS10.cso", wiResourceManager::VERTEXSHADER, layout, numElements)); @@ -781,11 +569,11 @@ void wiRenderer::LoadBasicShaders() VertexLayoutDesc oslayout[] = { - { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "NORMAL", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "NORMAL", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, }; UINT numElements = ARRAYSIZE(oslayout); @@ -845,7 +633,7 @@ void wiRenderer::LoadLineShaders() { VertexLayoutDesc layout[] = { - { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, }; UINT numElements = ARRAYSIZE(layout); @@ -895,9 +683,9 @@ void wiRenderer::LoadWaterShaders() void wiRenderer::LoadTrailShaders(){ VertexLayoutDesc layout[] = { - { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, }; UINT numElements = ARRAYSIZE(layout); @@ -920,7 +708,8 @@ void wiRenderer::ReloadShaders(const string& path) SHADERPATH = path; } - Lock(); + graphicsDevice->LOCK(); + wiResourceManager::GetShaderManager()->CleanUp(); LoadBasicShaders(); LoadLineShaders(); @@ -934,91 +723,92 @@ void wiRenderer::ReloadShaders(const string& path) wiFont::LoadShaders(); wiImage::LoadShaders(); wiLensFlare::LoadShaders(); - Unlock(); + + graphicsDevice->UNLOCK(); } void wiRenderer::SetUpStates() { - D3D11_SAMPLER_DESC samplerDesc; - samplerDesc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; - samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_MIRROR; - samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_MIRROR; - samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_MIRROR; + SamplerDesc samplerDesc; + samplerDesc.Filter = FILTER_MIN_MAG_LINEAR_MIP_POINT; + samplerDesc.AddressU = TEXTURE_ADDRESS_MIRROR; + samplerDesc.AddressV = TEXTURE_ADDRESS_MIRROR; + samplerDesc.AddressW = TEXTURE_ADDRESS_MIRROR; samplerDesc.MipLODBias = 0.0f; samplerDesc.MaxAnisotropy = 0; - samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; + samplerDesc.ComparisonFunc = COMPARISON_NEVER; samplerDesc.BorderColor[0] = 0; samplerDesc.BorderColor[1] = 0; samplerDesc.BorderColor[2] = 0; samplerDesc.BorderColor[3] = 0; samplerDesc.MinLOD = 0; - samplerDesc.MaxLOD = D3D11_FLOAT32_MAX; + samplerDesc.MaxLOD = FLOAT32_MAX; graphicsDevice->CreateSamplerState(&samplerDesc, &samplers[SSLOT_LINEAR_MIRROR]); - samplerDesc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; - samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; - samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; - samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; + 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]); - samplerDesc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; - samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; - samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; - samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; + 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]); - samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; - samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_MIRROR; - samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_MIRROR; - samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_MIRROR; + 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]); - samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; - samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; - samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; - samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; + 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]); - samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; - samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; - samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; - samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; + 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]); - samplerDesc.Filter = D3D11_FILTER_ANISOTROPIC; - samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; - samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; - samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_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]); - samplerDesc.Filter = D3D11_FILTER_ANISOTROPIC; - samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; - samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; - samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; + 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]); - samplerDesc.Filter = D3D11_FILTER_ANISOTROPIC; - samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_MIRROR; - samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_MIRROR; - samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_MIRROR; + 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]); - ZeroMemory( &samplerDesc, sizeof(D3D11_SAMPLER_DESC) ); - samplerDesc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT; - samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; - samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; - samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; + ZeroMemory( &samplerDesc, sizeof(SamplerDesc) ); + samplerDesc.Filter = FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT; + samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP; + samplerDesc.AddressV = TEXTURE_ADDRESS_CLAMP; + samplerDesc.AddressW = TEXTURE_ADDRESS_CLAMP; samplerDesc.MipLODBias = 0.0f; samplerDesc.MaxAnisotropy = 16; - samplerDesc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL; + samplerDesc.ComparisonFunc = COMPARISON_LESS_EQUAL; graphicsDevice->CreateSamplerState(&samplerDesc, &samplers[SSLOT_CMP_DEPTH]); - D3D11_RASTERIZER_DESC rs; - rs.FillMode=D3D11_FILL_SOLID; - rs.CullMode=D3D11_CULL_BACK; + RasterizerDesc rs; + rs.FillMode=FILL_SOLID; + rs.CullMode=CULL_BACK; rs.FrontCounterClockwise=true; rs.DepthBias=0; rs.DepthBiasClamp=0; @@ -1030,8 +820,8 @@ void wiRenderer::SetUpStates() graphicsDevice->CreateRasterizerState(&rs,&rasterizers[RSTYPE_FRONT]); - rs.FillMode=D3D11_FILL_SOLID; - rs.CullMode=D3D11_CULL_BACK; + rs.FillMode=FILL_SOLID; + rs.CullMode=CULL_BACK; rs.FrontCounterClockwise=true; rs.DepthBias=0; rs.DepthBiasClamp=0; @@ -1042,8 +832,8 @@ void wiRenderer::SetUpStates() rs.AntialiasedLineEnable=false; graphicsDevice->CreateRasterizerState(&rs,&rasterizers[RSTYPE_SHADOW]); - rs.FillMode=D3D11_FILL_SOLID; - rs.CullMode=D3D11_CULL_NONE; + rs.FillMode=FILL_SOLID; + rs.CullMode=CULL_NONE; rs.FrontCounterClockwise=true; rs.DepthBias=0; rs.DepthBiasClamp=0; @@ -1054,8 +844,8 @@ void wiRenderer::SetUpStates() rs.AntialiasedLineEnable=false; graphicsDevice->CreateRasterizerState(&rs,&rasterizers[RSTYPE_SHADOW_DOUBLESIDED]); - rs.FillMode=D3D11_FILL_WIREFRAME; - rs.CullMode=D3D11_CULL_BACK; + rs.FillMode=FILL_WIREFRAME; + rs.CullMode=CULL_BACK; rs.FrontCounterClockwise=true; rs.DepthBias=0; rs.DepthBiasClamp=0; @@ -1066,8 +856,8 @@ void wiRenderer::SetUpStates() rs.AntialiasedLineEnable=false; graphicsDevice->CreateRasterizerState(&rs,&rasterizers[RSTYPE_WIRE]); - rs.FillMode=D3D11_FILL_SOLID; - rs.CullMode=D3D11_CULL_NONE; + rs.FillMode=FILL_SOLID; + rs.CullMode=CULL_NONE; rs.FrontCounterClockwise=true; rs.DepthBias=0; rs.DepthBiasClamp=0; @@ -1078,8 +868,8 @@ void wiRenderer::SetUpStates() rs.AntialiasedLineEnable=false; graphicsDevice->CreateRasterizerState(&rs,&rasterizers[RSTYPE_DOUBLESIDED]); - rs.FillMode=D3D11_FILL_WIREFRAME; - rs.CullMode=D3D11_CULL_NONE; + rs.FillMode=FILL_WIREFRAME; + rs.CullMode=CULL_NONE; rs.FrontCounterClockwise=true; rs.DepthBias=0; rs.DepthBiasClamp=0; @@ -1090,8 +880,8 @@ void wiRenderer::SetUpStates() rs.AntialiasedLineEnable=false; graphicsDevice->CreateRasterizerState(&rs,&rasterizers[RSTYPE_WIRE_DOUBLESIDED]); - rs.FillMode=D3D11_FILL_SOLID; - rs.CullMode=D3D11_CULL_FRONT; + rs.FillMode=FILL_SOLID; + rs.CullMode=CULL_FRONT; rs.FrontCounterClockwise=true; rs.DepthBias=0; rs.DepthBiasClamp=0; @@ -1102,39 +892,39 @@ void wiRenderer::SetUpStates() rs.AntialiasedLineEnable=false; graphicsDevice->CreateRasterizerState(&rs,&rasterizers[RSTYPE_BACK]); - D3D11_DEPTH_STENCIL_DESC dsd; + DepthStencilDesc dsd; dsd.DepthEnable = true; - dsd.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; - dsd.DepthFunc = D3D11_COMPARISON_LESS_EQUAL; + dsd.DepthWriteMask = DEPTH_WRITE_MASK_ALL; + dsd.DepthFunc = COMPARISON_LESS_EQUAL; dsd.StencilEnable = true; dsd.StencilReadMask = 0xFF; dsd.StencilWriteMask = 0xFF; - dsd.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; - dsd.FrontFace.StencilPassOp = D3D11_STENCIL_OP_REPLACE; - dsd.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; - dsd.BackFace.StencilPassOp = D3D11_STENCIL_OP_REPLACE; - dsd.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; + dsd.FrontFace.StencilFunc = COMPARISON_ALWAYS; + dsd.FrontFace.StencilPassOp = STENCIL_OP_REPLACE; + dsd.FrontFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.FrontFace.StencilDepthFailOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilFunc = COMPARISON_ALWAYS; + dsd.BackFace.StencilPassOp = STENCIL_OP_REPLACE; + dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; // Create the depth stencil state. graphicsDevice->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_DEFAULT]); - dsd.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO; + dsd.DepthWriteMask = DEPTH_WRITE_MASK_ZERO; dsd.DepthEnable = false; dsd.StencilEnable = true; dsd.StencilReadMask = 0xFF; dsd.StencilWriteMask = 0xFF; - dsd.FrontFace.StencilFunc = D3D11_COMPARISON_LESS_EQUAL; - dsd.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - dsd.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilFunc = D3D11_COMPARISON_LESS_EQUAL; - dsd.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; + dsd.FrontFace.StencilFunc = COMPARISON_LESS_EQUAL; + dsd.FrontFace.StencilPassOp = STENCIL_OP_KEEP; + dsd.FrontFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.FrontFace.StencilDepthFailOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilFunc = COMPARISON_LESS_EQUAL; + dsd.BackFace.StencilPassOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; // Create the depth stencil state. graphicsDevice->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_STENCILREAD]); @@ -1143,21 +933,21 @@ void wiRenderer::SetUpStates() dsd.StencilEnable = true; dsd.StencilReadMask = 0xFF; dsd.StencilWriteMask = 0xFF; - dsd.FrontFace.StencilFunc = D3D11_COMPARISON_EQUAL; - dsd.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - dsd.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilFunc = D3D11_COMPARISON_EQUAL; - dsd.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; - dsd.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; + dsd.FrontFace.StencilFunc = COMPARISON_EQUAL; + dsd.FrontFace.StencilPassOp = STENCIL_OP_KEEP; + dsd.FrontFace.StencilFailOp = STENCIL_OP_KEEP; + dsd.FrontFace.StencilDepthFailOp = STENCIL_OP_KEEP; + dsd.BackFace.StencilFunc = COMPARISON_EQUAL; + 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]); dsd.DepthEnable = true; dsd.StencilEnable = false; - dsd.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO; - dsd.DepthFunc = D3D11_COMPARISON_LESS_EQUAL; + dsd.DepthWriteMask = DEPTH_WRITE_MASK_ZERO; + dsd.DepthFunc = COMPARISON_LESS_EQUAL; graphicsDevice->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_DEPTHREAD]); dsd.DepthEnable = false; @@ -1165,25 +955,25 @@ void wiRenderer::SetUpStates() graphicsDevice->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_XRAY]); - D3D11_BLEND_DESC bd; + BlendDesc bd; ZeroMemory(&bd, sizeof(bd)); bd.RenderTarget[0].BlendEnable=false; - bd.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; - bd.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; - bd.RenderTarget[0].BlendOp = D3D11_BLEND_OP_MAX; - bd.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; - bd.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; - bd.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlend = BLEND_SRC_ALPHA; + bd.RenderTarget[0].DestBlend = BLEND_INV_SRC_ALPHA; + bd.RenderTarget[0].BlendOp = BLEND_OP_MAX; + bd.RenderTarget[0].SrcBlendAlpha = BLEND_ONE; + bd.RenderTarget[0].DestBlendAlpha = BLEND_ZERO; + bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; bd.AlphaToCoverageEnable=false; graphicsDevice->CreateBlendState(&bd,&blendStates[BSTYPE_OPAQUE]); - bd.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; - bd.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; - bd.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - bd.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; - bd.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; - bd.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlend = BLEND_SRC_ALPHA; + bd.RenderTarget[0].DestBlend = BLEND_INV_SRC_ALPHA; + bd.RenderTarget[0].BlendOp = BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlendAlpha = BLEND_ONE; + bd.RenderTarget[0].DestBlendAlpha = BLEND_INV_SRC_ALPHA; + bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].BlendEnable=true; bd.RenderTarget[0].RenderTargetWriteMask = 0x0f; bd.AlphaToCoverageEnable=false; @@ -1191,78 +981,78 @@ void wiRenderer::SetUpStates() bd.RenderTarget[0].BlendEnable=true; - bd.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; - bd.RenderTarget[0].DestBlend = D3D11_BLEND_ONE; - bd.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - bd.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; - bd.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; - bd.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_MAX; + bd.RenderTarget[0].SrcBlend = BLEND_ONE; + bd.RenderTarget[0].DestBlend = BLEND_ONE; + bd.RenderTarget[0].BlendOp = BLEND_OP_ADD; + bd.RenderTarget[0].SrcBlendAlpha = BLEND_ONE; + bd.RenderTarget[0].DestBlendAlpha = BLEND_ZERO; + bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_MAX; bd.IndependentBlendEnable=true, bd.AlphaToCoverageEnable=false; graphicsDevice->CreateBlendState(&bd,&blendStates[BSTYPE_ADDITIVE]); } -void wiRenderer::BindPersistentState(DeviceContext context) +void wiRenderer::BindPersistentState(GRAPHICSTHREAD threadID) { - Lock(); + graphicsDevice->LOCK(); for (int i = 0; i < SSLOT_COUNT; ++i) { if (samplers[i] == nullptr) continue; - BindSamplerPS(samplers[i], i, context); - BindSamplerVS(samplers[i], i, context); - BindSamplerGS(samplers[i], i, context); - BindSamplerDS(samplers[i], i, context); - BindSamplerHS(samplers[i], i, context); + 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); } - BindConstantBufferPS(constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), context); - BindConstantBufferVS(constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), context); - BindConstantBufferGS(constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), context); - BindConstantBufferHS(constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), context); - BindConstantBufferDS(constantBuffers[CBTYPE_WORLD], CB_GETBINDSLOT(WorldCB), context); + 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); - BindConstantBufferPS(constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), context); - BindConstantBufferVS(constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), context); - BindConstantBufferGS(constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), context); - BindConstantBufferHS(constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), context); - BindConstantBufferDS(constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), context); + 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); - BindConstantBufferPS(constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), context); - BindConstantBufferVS(constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), context); - BindConstantBufferGS(constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), context); - BindConstantBufferHS(constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), context); - BindConstantBufferDS(constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), context); + 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); - BindConstantBufferPS(constantBuffers[CBTYPE_MATERIAL], CB_GETBINDSLOT(MaterialCB), context); - BindConstantBufferVS(constantBuffers[CBTYPE_MATERIAL], CB_GETBINDSLOT(MaterialCB), context); - BindConstantBufferGS(constantBuffers[CBTYPE_MATERIAL], CB_GETBINDSLOT(MaterialCB), context); - BindConstantBufferHS(constantBuffers[CBTYPE_MATERIAL], CB_GETBINDSLOT(MaterialCB), context); - BindConstantBufferDS(constantBuffers[CBTYPE_MATERIAL], CB_GETBINDSLOT(MaterialCB), context); + 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); - BindConstantBufferPS(constantBuffers[CBTYPE_DIRLIGHT], CB_GETBINDSLOT(DirectionalLightCB), context); - BindConstantBufferVS(constantBuffers[CBTYPE_DIRLIGHT], CB_GETBINDSLOT(DirectionalLightCB), context); + graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_DIRLIGHT], CB_GETBINDSLOT(DirectionalLightCB), threadID); + graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_DIRLIGHT], CB_GETBINDSLOT(DirectionalLightCB), threadID); - BindConstantBufferVS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), context); - BindConstantBufferPS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), context); - BindConstantBufferGS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), context); - BindConstantBufferDS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), context); - BindConstantBufferHS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), context); + 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); - BindConstantBufferVS(constantBuffers[CBTYPE_SHADOW], CB_GETBINDSLOT(ShadowCB), context); + graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_SHADOW], CB_GETBINDSLOT(ShadowCB), threadID); - BindConstantBufferVS(constantBuffers[CBTYPE_CLIPPLANE], CB_GETBINDSLOT(APICB), context); + graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_CLIPPLANE], CB_GETBINDSLOT(APICB), threadID); - Unlock(); + graphicsDevice->UNLOCK(); } -void wiRenderer::RebindPersistentState(DeviceContext context) +void wiRenderer::RebindPersistentState(GRAPHICSTHREAD threadID) { - BindPersistentState(context); + BindPersistentState(threadID); - wiImage::BindPersistentState(context); - wiFont::BindPersistentState(context); + wiImage::BindPersistentState(threadID); + wiFont::BindPersistentState(threadID); } Transform* wiRenderer::getTransformByName(const string& get) @@ -1458,14 +1248,11 @@ void wiRenderer::UpdatePerFrameData() GetScene().wind.time = (float)((wiTimer::TotalTime()) / 1000.0*GameSpeed / 2.0*3.1415)*XMVectorGetX(XMVector3Length(XMLoadFloat3(&GetScene().wind.direction)))*0.1f; } -void wiRenderer::UpdateRenderData(DeviceContext context) +void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) { - if (context == nullptr) - return; - - //UpdateWorldCB(context); - UpdateFrameCB(context); - UpdateCameraCB(context); + //UpdateWorldCB(threadID); + UpdateFrameCB(threadID); + UpdateCameraCB(threadID); { @@ -1485,13 +1272,13 @@ void wiRenderer::UpdateRenderData(DeviceContext context) if (!streamOutSetUp) { streamOutSetUp = true; - BindPrimitiveTopology(POINTLIST, context); - BindVertexLayout(vertexLayouts[VLTYPE_STREAMOUT], context); - BindVS(vertexShaders[VSTYPE_STREAMOUT], context); - BindGS(geometryShaders[GSTYPE_STREAMOUT], context); - BindPS(nullptr, context); - BindConstantBufferVS(constantBuffers[CBTYPE_BONEBUFFER], CB_GETBINDSLOT(BoneCB), context); - BindConstantBufferGS(constantBuffers[CBTYPE_BONEBUFFER], CB_GETBINDSLOT(BoneCB), context); + 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); } // Upload bones for skinning to shader @@ -1500,13 +1287,13 @@ void wiRenderer::UpdateRenderData(DeviceContext context) bonebuf->pose[k] = XMMatrixTranspose(XMLoadFloat4x4(&mesh->armature->boneCollection[k]->boneRelativity)); bonebuf->prev[k] = XMMatrixTranspose(XMLoadFloat4x4(&mesh->armature->boneCollection[k]->boneRelativityPrev)); } - UpdateBuffer(constantBuffers[CBTYPE_BONEBUFFER], bonebuf, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_BONEBUFFER], bonebuf, threadID); // Do the skinning - BindVertexBuffer(mesh->meshVertBuff, 0, sizeof(SkinnedVertex), context); - BindStreamOutTarget(mesh->sOutBuffer, context); - Draw(mesh->vertices.size(), context); + wiRenderer::graphicsDevice->BindVertexBuffer(mesh->meshVertBuff, 0, sizeof(SkinnedVertex), threadID); + wiRenderer::graphicsDevice->BindStreamOutTarget(mesh->sOutBuffer, threadID); + wiRenderer::graphicsDevice->Draw(mesh->vertices.size(), threadID); #else // Doing skinning on the CPU for (int vi = 0; vi < mesh->skinnedVertices.size(); ++vi) @@ -1523,7 +1310,7 @@ void wiRenderer::UpdateRenderData(DeviceContext context) if (mesh->softBody || mesh->hasArmature()) #endif { - UpdateBuffer(mesh->meshVertBuff, mesh->skinnedVertices.data(), context, sizeof(Vertex)*mesh->skinnedVertices.size()); + wiRenderer::graphicsDevice->UpdateBuffer(mesh->meshVertBuff, mesh->skinnedVertices.data(), threadID, sizeof(Vertex)*mesh->skinnedVertices.size()); } } } @@ -1532,9 +1319,9 @@ void wiRenderer::UpdateRenderData(DeviceContext context) if (streamOutSetUp) { // Unload skinning shader - BindGS(nullptr, context); - BindVS(nullptr, context); - BindStreamOutTarget(nullptr, context); + wiRenderer::graphicsDevice->BindGS(nullptr, threadID); + wiRenderer::graphicsDevice->BindVS(nullptr, threadID); + wiRenderer::graphicsDevice->BindStreamOutTarget(nullptr, threadID); } #endif @@ -1585,31 +1372,31 @@ void wiRenderer::ManageWaterRipples(){ ) waterRipples.pop_front(); } -void wiRenderer::DrawWaterRipples(DeviceContext context){ - //wiImage::BatchBegin(context); +void wiRenderer::DrawWaterRipples(GRAPHICSTHREAD threadID){ + //wiImage::BatchBegin(threadID); for(wiSprite* i:waterRipples){ - i->DrawNormal(context); + i->DrawNormal(threadID); } } -void wiRenderer::DrawDebugSpheres(Camera* camera, DeviceContext context) +void wiRenderer::DrawDebugSpheres(Camera* camera, GRAPHICSTHREAD threadID) { //if(debugSpheres){ - // BindPrimitiveTopology(TRIANGLESTRIP,context); - // BindVertexLayout(vertexLayouts[VLTYPE_EFFECT] : vertexLayouts[VLTYPE_LINE],context); + // BindPrimitiveTopology(TRIANGLESTRIP,threadID); + // BindVertexLayout(vertexLayouts[VLTYPE_EFFECT] : vertexLayouts[VLTYPE_LINE],threadID); // - // BindRasterizerState(rasterizers[RSTYPE_FRONT],context); - // BindDepthStencilState(depthStencils[DSSTYPE_XRAY],STENCILREF_EMPTY,context); - // BindBlendState(blendStates[BSTYPE_TRANSPARENT],context); + // BindRasterizerState(rasterizers[RSTYPE_FRONT],threadID); + // BindDepthStencilState(depthStencils[DSSTYPE_XRAY],STENCILREF_EMPTY,threadID); + // BindBlendState(blendStates[BSTYPE_TRANSPARENT],threadID); - // BindPS(linePS,context); - // BindVS(lineVS,context); + // BindPS(linePS,threadID); + // BindVS(lineVS,threadID); - // BindVertexBuffer(HitSphere::vertexBuffer,0,sizeof(XMFLOAT3A),context); + // BindVertexBuffer(HitSphere::vertexBuffer,0,sizeof(XMFLOAT3A),threadID); // for (unsigned int i = 0; irotation))* @@ -1624,104 +1411,104 @@ void wiRenderer::DrawDebugSpheres(Camera* camera, DeviceContext context) // else if(spheres[i]->TYPE==HitSphere::HitSphereType::ATKTYPE) propColor=XMFLOAT4A(0.96f,0,0,1); // sb.color=propColor; - // UpdateBuffer(lineBuffer,&sb,context); + // UpdateBuffer(lineBuffer,&sb,threadID); - // //context->Draw((HitSphere::RESOLUTION+1)*2,0); - // Draw((HitSphere::RESOLUTION+1)*2,context); + // //threadID->Draw((HitSphere::RESOLUTION+1)*2,0); + // Draw((HitSphere::RESOLUTION+1)*2,threadID); // } //} } -void wiRenderer::DrawDebugBoneLines(Camera* camera, DeviceContext context) +void wiRenderer::DrawDebugBoneLines(Camera* camera, GRAPHICSTHREAD threadID) { if(debugBoneLines){ - BindPrimitiveTopology(LINELIST,context); - BindVertexLayout(vertexLayouts[VLTYPE_LINE],context); + wiRenderer::graphicsDevice->BindPrimitiveTopology(LINELIST,threadID); + wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_LINE],threadID); - BindRasterizerState(rasterizers[RSTYPE_SHADOW],context); - BindDepthStencilState(depthStencils[DSSTYPE_XRAY],STENCILREF_EMPTY,context); - BindBlendState(blendStates[BSTYPE_OPAQUE],context); + wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_SHADOW],threadID); + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_XRAY],STENCILREF_EMPTY,threadID); + wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); - BindPS(pixelShaders[PSTYPE_LINE],context); - BindVS(vertexShaders[VSTYPE_LINE],context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_LINE],threadID); + wiRenderer::graphicsDevice->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; - UpdateBuffer(constantBuffers[CBTYPE_MISC], sb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MISC], sb, threadID); - BindVertexBuffer(boneLines[i]->vertexBuffer, 0, sizeof(XMFLOAT3A), context); - Draw(2, context); + wiRenderer::graphicsDevice->BindVertexBuffer(boneLines[i]->vertexBuffer, 0, sizeof(XMFLOAT3A), threadID); + wiRenderer::graphicsDevice->Draw(2, threadID); } } } -void wiRenderer::DrawDebugLines(Camera* camera, DeviceContext context) +void wiRenderer::DrawDebugLines(Camera* camera, GRAPHICSTHREAD threadID) { if (linesTemp.empty()) return; - BindPrimitiveTopology(LINELIST, context); - BindVertexLayout(vertexLayouts[VLTYPE_LINE], context); + wiRenderer::graphicsDevice->BindPrimitiveTopology(LINELIST, threadID); + wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_LINE], threadID); - BindRasterizerState(rasterizers[RSTYPE_SHADOW], context); - BindDepthStencilState(depthStencils[DSSTYPE_XRAY], STENCILREF_EMPTY, context); - BindBlendState(blendStates[BSTYPE_OPAQUE], context); + wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_SHADOW], threadID); + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_XRAY], STENCILREF_EMPTY, threadID); + wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE], threadID); - BindPS(pixelShaders[PSTYPE_LINE], context); - BindVS(vertexShaders[VSTYPE_LINE], context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_LINE], threadID); + wiRenderer::graphicsDevice->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; - UpdateBuffer(constantBuffers[CBTYPE_MISC], sb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MISC], sb, threadID); - BindVertexBuffer(linesTemp[i]->vertexBuffer, 0, sizeof(XMFLOAT3A), context); - Draw(2, context); + wiRenderer::graphicsDevice->BindVertexBuffer(linesTemp[i]->vertexBuffer, 0, sizeof(XMFLOAT3A), threadID); + wiRenderer::graphicsDevice->Draw(2, threadID); } for (Lines* x : linesTemp) delete x; linesTemp.clear(); } -void wiRenderer::DrawDebugBoxes(Camera* camera, DeviceContext context) +void wiRenderer::DrawDebugBoxes(Camera* camera, GRAPHICSTHREAD threadID) { if(debugBoxes){ - BindPrimitiveTopology(LINELIST,context); - BindVertexLayout(vertexLayouts[VLTYPE_LINE],context); + wiRenderer::graphicsDevice->BindPrimitiveTopology(LINELIST,threadID); + wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_LINE],threadID); - BindRasterizerState(rasterizers[RSTYPE_WIRE_DOUBLESIDED],context); - BindDepthStencilState(depthStencils[DSSTYPE_XRAY],STENCILREF_EMPTY,context); - BindBlendState(blendStates[BSTYPE_OPAQUE],context); + wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_WIRE_DOUBLESIDED],threadID); + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_XRAY],STENCILREF_EMPTY,threadID); + wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); - BindPS(pixelShaders[PSTYPE_LINE],context); - BindVS(vertexShaders[VSTYPE_LINE],context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_LINE],threadID); + wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_LINE],threadID); - BindVertexBuffer(Cube::vertexBuffer,0,sizeof(XMFLOAT3A),context); - BindIndexBuffer(Cube::indexBuffer,context); + wiRenderer::graphicsDevice->BindVertexBuffer(Cube::vertexBuffer,0,sizeof(XMFLOAT3A),threadID); + wiRenderer::graphicsDevice->BindIndexBuffer(Cube::indexBuffer,threadID); static thread_local MiscCB* sb = new MiscCB; for (unsigned int i = 0; iGetViewProjection()); (*sb).mColor=cubes[i].desc.color; - UpdateBuffer(constantBuffers[CBTYPE_MISC],sb,context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MISC],sb,threadID); - DrawIndexed(24,context); + wiRenderer::graphicsDevice->DrawIndexed(24,threadID); } } } -void wiRenderer::DrawSoftParticles(Camera* camera, ID3D11DeviceContext *context, bool dark) +void wiRenderer::DrawSoftParticles(Camera* camera, GRAPHICSTHREAD threadID, bool dark) { struct particlesystem_comparator { bool operator() (const wiEmittedParticle* a, const wiEmittedParticle* b) const{ @@ -1736,35 +1523,35 @@ void wiRenderer::DrawSoftParticles(Camera* camera, ID3D11DeviceContext *context, } for(wiEmittedParticle* e:psystems){ - e->DrawNonPremul(camera,context,dark); + e->DrawNonPremul(camera,threadID,dark); } } -void wiRenderer::DrawSoftPremulParticles(Camera* camera, ID3D11DeviceContext *context, bool dark) +void wiRenderer::DrawSoftPremulParticles(Camera* camera, GRAPHICSTHREAD threadID, bool dark) { for (wiEmittedParticle* e : emitterSystems) { - e->DrawPremul(camera, context, dark); + e->DrawPremul(camera, threadID, dark); } } -void wiRenderer::DrawTrails(DeviceContext context, TextureView refracRes){ - BindPrimitiveTopology(TRIANGLESTRIP,context); - BindVertexLayout(vertexLayouts[VLTYPE_TRAIL],context); +void wiRenderer::DrawTrails(GRAPHICSTHREAD threadID, TextureView refracRes){ + wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLESTRIP,threadID); + wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_TRAIL],threadID); - BindRasterizerState(wireRender?rasterizers[RSTYPE_WIRE_DOUBLESIDED]:rasterizers[RSTYPE_DOUBLESIDED],context); - BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT],STENCILREF_EMPTY,context); - BindBlendState(blendStates[BSTYPE_OPAQUE],context); + 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); - BindPS(pixelShaders[PSTYPE_TRAIL],context); - BindVS(vertexShaders[VSTYPE_TRAIL],context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_TRAIL],threadID); + wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_TRAIL],threadID); - BindTexturePS(refracRes,TEXSLOT_ONDEMAND0,context); + wiRenderer::graphicsDevice->BindTexturePS(refracRes,TEXSLOT_ONDEMAND0,threadID); for (Object* o : objectsWithTrails) { if(o->trailBuff && o->trail.size()>=4){ - BindTexturePS(o->trailDistortTex, TEXSLOT_ONDEMAND1, context); - BindTexturePS(o->trailTex, TEXSLOT_ONDEMAND2, context); + wiRenderer::graphicsDevice->BindTexturePS(o->trailDistortTex, TEXSLOT_ONDEMAND1, threadID); + wiRenderer::graphicsDevice->BindTexturePS(o->trailTex, TEXSLOT_ONDEMAND2, threadID); vector trails; @@ -1806,19 +1593,19 @@ void wiRenderer::DrawTrails(DeviceContext context, TextureView refracRes){ } } if(!trails.empty()){ - UpdateBuffer(o->trailBuff,trails.data(),context,sizeof(RibbonVertex)*trails.size()); + wiRenderer::graphicsDevice->UpdateBuffer(o->trailBuff,trails.data(),threadID,sizeof(RibbonVertex)*trails.size()); - BindVertexBuffer(o->trailBuff,0,sizeof(RibbonVertex),context); - Draw(trails.size(),context); + wiRenderer::graphicsDevice->BindVertexBuffer(o->trailBuff,0,sizeof(RibbonVertex),threadID); + wiRenderer::graphicsDevice->Draw(trails.size(),threadID); trails.clear(); } } } } -void wiRenderer::DrawImagesAdd(DeviceContext context, TextureView refracRes){ - imagesRTAdd.Activate(context,0,0,0,1); - //wiImage::BatchBegin(context); +void wiRenderer::DrawImagesAdd(GRAPHICSTHREAD threadID, TextureView refracRes){ + imagesRTAdd.Activate(threadID,0,0,0,1); + //wiImage::BatchBegin(threadID); for(wiSprite* x : images){ if(x->effects.blendFlag==BLENDMODE_ADDITIVE){ /*TextureView nor = x->effects.normalMap; @@ -1828,16 +1615,16 @@ void wiRenderer::DrawImagesAdd(DeviceContext context, TextureView refracRes){ x->effects.blendFlag=BLENDMODE_ADDITIVE; changedBlend=true; }*/ - x->Draw(refracRes, context); + x->Draw(refracRes, threadID); /*if(changedBlend) x->effects.blendFlag=BLENDMODE_OPAQUE; x->effects.setNormalMap(nor);*/ } } } -void wiRenderer::DrawImages(DeviceContext context, TextureView refracRes){ - imagesRT.Activate(context,0,0,0,0); - //wiImage::BatchBegin(context); +void wiRenderer::DrawImages(GRAPHICSTHREAD threadID, TextureView refracRes){ + imagesRT.Activate(threadID,0,0,0,0); + //wiImage::BatchBegin(threadID); for(wiSprite* x : images){ if(x->effects.blendFlag==BLENDMODE_ALPHA || x->effects.blendFlag==BLENDMODE_OPAQUE){ /*TextureView nor = x->effects.normalMap; @@ -1847,21 +1634,21 @@ void wiRenderer::DrawImages(DeviceContext context, TextureView refracRes){ x->effects.blendFlag=BLENDMODE_ADDITIVE; changedBlend=true; }*/ - x->Draw(refracRes, context); + x->Draw(refracRes, threadID); /*if(changedBlend) x->effects.blendFlag=BLENDMODE_OPAQUE; x->effects.setNormalMap(nor);*/ } } } -void wiRenderer::DrawImagesNormals(DeviceContext context, TextureView refracRes){ - normalMapRT.Activate(context,0,0,0,0); - //wiImage::BatchBegin(context); +void wiRenderer::DrawImagesNormals(GRAPHICSTHREAD threadID, TextureView refracRes){ + normalMapRT.Activate(threadID,0,0,0,0); + //wiImage::BatchBegin(threadID); for(wiSprite* x : images){ - x->DrawNormal(context); + x->DrawNormal(threadID); } } -void wiRenderer::DrawLights(Camera* camera, DeviceContext context, unsigned int stencilRef){ +void wiRenderer::DrawLights(Camera* camera, GRAPHICSTHREAD threadID, unsigned int stencilRef){ static thread_local Frustum frustum = Frustum(); @@ -1875,49 +1662,49 @@ void wiRenderer::DrawLights(Camera* camera, DeviceContext context, unsigned int { - BindPrimitiveTopology(TRIANGLELIST,context); + wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLELIST,threadID); - //BindTexturePS(depth,0,context); - //BindTexturePS(normal,1,context); - //BindTexturePS(material,2,context); + //BindTexturePS(depth,0,threadID); + //BindTexturePS(normal,1,threadID); + //BindTexturePS(material,2,threadID); - BindBlendState(blendStates[BSTYPE_ADDITIVE],context); - BindDepthStencilState(depthStencils[DSSTYPE_STENCILREAD],stencilRef,context); - BindRasterizerState(rasterizers[RSTYPE_BACK],context); + wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_ADDITIVE],threadID); + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_STENCILREAD],stencilRef,threadID); + wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_BACK],threadID); - BindVertexLayout(nullptr, context); - BindVertexBuffer(nullptr, 0, 0, context); - BindIndexBuffer(nullptr, context); + wiRenderer::graphicsDevice->BindVertexLayout(nullptr, threadID); + wiRenderer::graphicsDevice->BindVertexBuffer(nullptr, 0, 0, threadID); + wiRenderer::graphicsDevice->BindIndexBuffer(nullptr, threadID); - BindConstantBufferPS(constantBuffers[CBTYPE_POINTLIGHT], CB_GETBINDSLOT(PointLightCB), context); - BindConstantBufferVS(constantBuffers[CBTYPE_POINTLIGHT], CB_GETBINDSLOT(PointLightCB), context); + wiRenderer::graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_POINTLIGHT], CB_GETBINDSLOT(PointLightCB), threadID); + wiRenderer::graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_POINTLIGHT], CB_GETBINDSLOT(PointLightCB), threadID); - BindConstantBufferPS(constantBuffers[CBTYPE_SPOTLIGHT], CB_GETBINDSLOT(SpotLightCB), context); - BindConstantBufferVS(constantBuffers[CBTYPE_SPOTLIGHT], CB_GETBINDSLOT(SpotLightCB), context); + wiRenderer::graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_SPOTLIGHT], CB_GETBINDSLOT(SpotLightCB), threadID); + wiRenderer::graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_SPOTLIGHT], CB_GETBINDSLOT(SpotLightCB), threadID); for(int type=0;type<3;++type){ - BindVS(vertexShaders[VSTYPE_DIRLIGHT + type],context); + wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_DIRLIGHT + type],threadID); switch (type) { case 0: if (SOFTSHADOW) { - BindPS(pixelShaders[PSTYPE_DIRLIGHT_SOFT], context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_DIRLIGHT_SOFT], threadID); } else { - BindPS(pixelShaders[PSTYPE_DIRLIGHT], context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_DIRLIGHT], threadID); } break; case 1: - BindPS(pixelShaders[PSTYPE_POINTLIGHT], context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_POINTLIGHT], threadID); break; case 2: - BindPS(pixelShaders[PSTYPE_SPOTLIGHT], context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_SPOTLIGHT], threadID); break; default: break; @@ -1940,11 +1727,11 @@ void wiRenderer::DrawLights(Camera* camera, DeviceContext context, unsigned int for (unsigned int shmap = 0; shmap < l->shadowMaps_dirLight.size(); ++shmap){ (*lcb).mShM[shmap]=l->shadowCam[shmap].getVP(); if(l->shadowMaps_dirLight[shmap].depth) - BindTexturePS(l->shadowMaps_dirLight[shmap].depth->shaderResource,TEXSLOT_SHADOW0+shmap,context); + wiRenderer::graphicsDevice->BindTexturePS(l->shadowMaps_dirLight[shmap].depth->shaderResource,TEXSLOT_SHADOW0+shmap,threadID); } - UpdateBuffer(constantBuffers[CBTYPE_DIRLIGHT],lcb,context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_DIRLIGHT],lcb,threadID); - Draw(3, context); + wiRenderer::graphicsDevice->Draw(3, threadID); } else if(type==1) //point { @@ -1958,11 +1745,11 @@ void wiRenderer::DrawLights(Camera* camera, DeviceContext context, unsigned int { (*lcb).enerdis.w = 1.f; if(Light::shadowMaps_pointLight[l->shadowMap_index].depth) - BindTexturePS(Light::shadowMaps_pointLight[l->shadowMap_index].depth->shaderResource, TEXSLOT_SHADOW_CUBE, context); + wiRenderer::graphicsDevice->BindTexturePS(Light::shadowMaps_pointLight[l->shadowMap_index].depth->shaderResource, TEXSLOT_SHADOW_CUBE, threadID); } - UpdateBuffer(constantBuffers[CBTYPE_POINTLIGHT], lcb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_POINTLIGHT], lcb, threadID); - Draw(240, context); + wiRenderer::graphicsDevice->Draw(240, threadID); } else if(type==2) //spot { @@ -1989,11 +1776,11 @@ void wiRenderer::DrawLights(Camera* camera, DeviceContext context, unsigned int { (*lcb).mShM = l->shadowCam[0].getVP(); if(Light::shadowMaps_spotLight[l->shadowMap_index].depth) - BindTexturePS(Light::shadowMaps_spotLight[l->shadowMap_index].depth->shaderResource, TEXSLOT_SHADOW0, context); + wiRenderer::graphicsDevice->BindTexturePS(Light::shadowMaps_spotLight[l->shadowMap_index].depth->shaderResource, TEXSLOT_SHADOW0, threadID); } - UpdateBuffer(constantBuffers[CBTYPE_SPOTLIGHT], lcb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_SPOTLIGHT], lcb, threadID); - Draw(192, context); + wiRenderer::graphicsDevice->Draw(192, threadID); } } @@ -2002,7 +1789,7 @@ void wiRenderer::DrawLights(Camera* camera, DeviceContext context, unsigned int } } -void wiRenderer::DrawVolumeLights(Camera* camera, DeviceContext context) +void wiRenderer::DrawVolumeLights(Camera* camera, GRAPHICSTHREAD threadID) { static thread_local Frustum frustum = Frustum(); @@ -2016,29 +1803,29 @@ void wiRenderer::DrawVolumeLights(Camera* camera, DeviceContext context) if(!culledObjects.empty()) { - BindPrimitiveTopology(TRIANGLELIST,context); - BindVertexLayout(nullptr); - BindVertexBuffer(nullptr, 0, 0, context); - BindIndexBuffer(nullptr, context); - BindBlendState(blendStates[BSTYPE_ADDITIVE],context); - BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD],STENCILREF_DEFAULT,context); - BindRasterizerState(rasterizers[RSTYPE_DOUBLESIDED],context); + 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); - BindPS(pixelShaders[PSTYPE_VOLUMELIGHT],context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_VOLUMELIGHT],threadID); - BindConstantBufferPS(constantBuffers[CBTYPE_VOLUMELIGHT], CB_GETBINDSLOT(VolumeLightCB), context); - BindConstantBufferVS(constantBuffers[CBTYPE_VOLUMELIGHT], CB_GETBINDSLOT(VolumeLightCB), context); + wiRenderer::graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_VOLUMELIGHT], CB_GETBINDSLOT(VolumeLightCB), threadID); + wiRenderer::graphicsDevice->BindConstantBufferVS(constantBuffers[CBTYPE_VOLUMELIGHT], CB_GETBINDSLOT(VolumeLightCB), threadID); for(int type=1;type<3;++type){ if(type<=1){ - BindVS(vertexShaders[VSTYPE_VOLUMEPOINTLIGHT],context); + wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_VOLUMEPOINTLIGHT],threadID); } else{ - BindVS(vertexShaders[VSTYPE_VOLUMESPOTLIGHT],context); + wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_VOLUMESPOTLIGHT],threadID); } for(Cullable* c : culledObjects){ @@ -2078,12 +1865,12 @@ void wiRenderer::DrawVolumeLights(Camera* camera, DeviceContext context) (*lcb).enerdis=l->enerDis; (*lcb).enerdis.w=sca; - UpdateBuffer(constantBuffers[CBTYPE_VOLUMELIGHT],lcb,context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_VOLUMELIGHT],lcb,threadID); if(type<=1) - Draw(108,context); + wiRenderer::graphicsDevice->Draw(108,threadID); else - Draw(192,context); + wiRenderer::graphicsDevice->Draw(192,threadID); } } @@ -2093,7 +1880,7 @@ void wiRenderer::DrawVolumeLights(Camera* camera, DeviceContext context) } -void wiRenderer::DrawLensFlares(DeviceContext context){ +void wiRenderer::DrawLensFlares(GRAPHICSTHREAD threadID){ CulledList culledObjects; @@ -2122,26 +1909,26 @@ void wiRenderer::DrawLensFlares(DeviceContext context){ XMVECTOR flarePos = XMVector3Project(POS,0.f,0.f,(float)GetScreenWidth(),(float)GetScreenHeight(),0.1f,1.0f,getCamera()->GetProjection(),getCamera()->GetView(),XMMatrixIdentity()); if( XMVectorGetX(XMVector3Dot( XMVectorSubtract(POS,getCamera()->GetEye()),getCamera()->GetAt() ))>0 ) - wiLensFlare::Draw(context,flarePos,l->lensFlareRimTextures); + wiLensFlare::Draw(threadID,flarePos,l->lensFlareRimTextures); } } } -void wiRenderer::ClearShadowMaps(DeviceContext context){ +void wiRenderer::ClearShadowMaps(GRAPHICSTHREAD threadID){ if (GetGameSpeed()) { - UnbindTextures(TEXSLOT_SHADOW0, 1 + TEXSLOT_SHADOW_CUBE - TEXSLOT_SHADOW0, context); + wiRenderer::graphicsDevice->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(context); + Light::shadowMaps_pointLight[index].Activate(threadID); } for (unsigned int index = 0; index < Light::shadowMaps_spotLight.size(); ++index) { - Light::shadowMaps_spotLight[index].Activate(context); + Light::shadowMaps_spotLight[index].Activate(threadID); } } } -void wiRenderer::DrawForShadowMap(DeviceContext context) +void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) { if (GameSpeed) { @@ -2152,17 +1939,17 @@ void wiRenderer::DrawForShadowMap(DeviceContext context) if (culledLights.size() > 0) { - BindPrimitiveTopology(TRIANGLELIST, context); - BindVertexLayout(vertexLayouts[VLTYPE_EFFECT], context); + wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLELIST, threadID); + wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_EFFECT], threadID); - BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_DEFAULT, context); + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_DEFAULT, threadID); - BindBlendState(blendStates[BSTYPE_OPAQUE], context); + wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE], threadID); - BindPS(pixelShaders[PSTYPE_SHADOW], context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_SHADOW], threadID); - BindVS(vertexShaders[VSTYPE_SHADOW], context); + wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_SHADOW], threadID); set orderedSpotLights; @@ -2206,7 +1993,7 @@ void wiRenderer::DrawForShadowMap(DeviceContext context) l->shadowMaps_dirLight[index].Initialize(SHADOWMAPRES, SHADOWMAPRES, 0, true); } - l->shadowMaps_dirLight[index].Activate(context); + l->shadowMaps_dirLight[index].Activate(threadID); const float siz = l->shadowCam[index].size * 0.5f; const float f = l->shadowCam[index].farplane; @@ -2232,14 +2019,14 @@ void wiRenderer::DrawForShadowMap(DeviceContext context) if (visibleInstances.size() && !mesh->isBillboarded) { if (!mesh->doubleSided) - BindRasterizerState(rasterizers[RSTYPE_SHADOW], context); + wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_SHADOW], threadID); else - BindRasterizerState(rasterizers[RSTYPE_SHADOW_DOUBLESIDED], context); + wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_SHADOW_DOUBLESIDED], threadID); - //D3D11_MAPPED_SUBRESOURCE mappedResource; + //MAPPED_SUBRESOURCE mappedResource; static thread_local ShadowCB* cb = new ShadowCB; (*cb).mVP = l->shadowCam[index].getVP(); - UpdateBuffer(constantBuffers[CBTYPE_SHADOW], cb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_SHADOW], cb, threadID); int k = 0; @@ -2255,12 +2042,12 @@ void wiRenderer::DrawForShadowMap(DeviceContext context) if (k < 1) continue; - Mesh::UpdateRenderableInstances(visibleInstances.size(), context); + Mesh::UpdateRenderableInstances(visibleInstances.size(), threadID); - BindVertexBuffer((mesh->sOutBuffer ? mesh->sOutBuffer : mesh->meshVertBuff), 0, sizeof(Vertex), context); - BindVertexBuffer(mesh->meshInstanceBuffer, 1, sizeof(Instance), context); - BindIndexBuffer(mesh->meshIndexBuff, context); + 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); int matsiz = mesh->materialIndices.size(); @@ -2268,17 +2055,17 @@ void wiRenderer::DrawForShadowMap(DeviceContext context) for (Material* iMat : mesh->materials) { if (!wireRender && !iMat->isSky && !iMat->water && iMat->cast_shadow) { - BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0, context); + wiRenderer::graphicsDevice->BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0, threadID); static thread_local MaterialCB* mcb = new MaterialCB; (*mcb).Create(*iMat, m); - UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); - DrawIndexedInstanced(mesh->indices.size(), visibleInstances.size(), context); + wiRenderer::graphicsDevice->DrawIndexedInstanced(mesh->indices.size(), visibleInstances.size(), threadID); m++; } @@ -2308,7 +2095,7 @@ void wiRenderer::DrawForShadowMap(DeviceContext context) CulledList culledObjects; CulledCollection culledRenderer; - Light::shadowMaps_spotLight[i].Set(context); + Light::shadowMaps_spotLight[i].Set(threadID); static thread_local Frustum frustum = Frustum(); XMFLOAT4X4 proj, view; XMStoreFloat4x4(&proj, XMLoadFloat4x4(&l->shadowCam[0].Projection)); @@ -2333,14 +2120,14 @@ void wiRenderer::DrawForShadowMap(DeviceContext context) if (visibleInstances.size() && !mesh->isBillboarded) { if (!mesh->doubleSided) - BindRasterizerState(rasterizers[RSTYPE_SHADOW], context); + wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_SHADOW], threadID); else - BindRasterizerState(rasterizers[RSTYPE_SHADOW_DOUBLESIDED], context); + wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_SHADOW_DOUBLESIDED], threadID); - //D3D11_MAPPED_SUBRESOURCE mappedResource; + //MAPPED_SUBRESOURCE mappedResource; static thread_local ShadowCB* cb = new ShadowCB; (*cb).mVP = l->shadowCam[index].getVP(); - UpdateBuffer(constantBuffers[CBTYPE_SHADOW], cb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_SHADOW], cb, threadID); int k = 0; @@ -2356,12 +2143,12 @@ void wiRenderer::DrawForShadowMap(DeviceContext context) if (k < 1) continue; - Mesh::UpdateRenderableInstances(visibleInstances.size(), context); + Mesh::UpdateRenderableInstances(visibleInstances.size(), threadID); - BindVertexBuffer((mesh->sOutBuffer ? mesh->sOutBuffer : mesh->meshVertBuff), 0, sizeof(Vertex), context); - BindVertexBuffer(mesh->meshInstanceBuffer, 1, sizeof(Instance), context); - BindIndexBuffer(mesh->meshIndexBuff, context); + 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); int matsiz = mesh->materialIndices.size(); @@ -2369,17 +2156,17 @@ void wiRenderer::DrawForShadowMap(DeviceContext context) for (Material* iMat : mesh->materials) { if (!wireRender && !iMat->isSky && !iMat->water && iMat->cast_shadow) { - BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0, context); + wiRenderer::graphicsDevice->BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0, threadID); static thread_local MaterialCB* mcb = new MaterialCB; (*mcb).Create(*iMat, m); - UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); - DrawIndexedInstanced(mesh->indices.size(), visibleInstances.size(), context); + wiRenderer::graphicsDevice->DrawIndexedInstanced(mesh->indices.size(), visibleInstances.size(), threadID); m++; } @@ -2399,12 +2186,12 @@ void wiRenderer::DrawForShadowMap(DeviceContext context) //POINTLIGHTS if(!orderedPointLights.empty()) { - BindPS(pixelShaders[PSTYPE_SHADOWCUBEMAPRENDER], context); - BindVS(vertexShaders[VSTYPE_SHADOWCUBEMAPRENDER], context); - BindGS(geometryShaders[GSTYPE_SHADOWCUBEMAPRENDER], context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_SHADOWCUBEMAPRENDER], threadID); + wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_SHADOWCUBEMAPRENDER], threadID); + wiRenderer::graphicsDevice->BindGS(geometryShaders[GSTYPE_SHADOWCUBEMAPRENDER], threadID); - BindConstantBufferPS(constantBuffers[CBTYPE_POINTLIGHT], CB_GETBINDSLOT(PointLightCB), context); - BindConstantBufferGS(constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubeMapRenderCB), context); + wiRenderer::graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_POINTLIGHT], CB_GETBINDSLOT(PointLightCB), threadID); + wiRenderer::graphicsDevice->BindConstantBufferGS(constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubeMapRenderCB), threadID); int i = 0; for (Light* l : orderedPointLights) @@ -2414,19 +2201,19 @@ void wiRenderer::DrawForShadowMap(DeviceContext context) l->shadowMap_index = i; - Light::shadowMaps_pointLight[i].Set(context); + Light::shadowMaps_pointLight[i].Set(threadID); - //D3D11_MAPPED_SUBRESOURCE mappedResource; + //MAPPED_SUBRESOURCE mappedResource; static thread_local PointLightCB* lcb = new PointLightCB; (*lcb).enerdis = l->enerDis; (*lcb).pos = l->translation; - UpdateBuffer(constantBuffers[CBTYPE_POINTLIGHT], lcb, context); + wiRenderer::graphicsDevice->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(); - UpdateBuffer(constantBuffers[CBTYPE_CUBEMAPRENDER], cb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_CUBEMAPRENDER], cb, threadID); CulledList culledObjects; CulledCollection culledRenderer; @@ -2444,9 +2231,9 @@ void wiRenderer::DrawForShadowMap(DeviceContext context) if (!mesh->isBillboarded && !visibleInstances.empty()) { if (!mesh->doubleSided) - BindRasterizerState(rasterizers[RSTYPE_SHADOW], context); + wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_SHADOW], threadID); else - BindRasterizerState(rasterizers[RSTYPE_SHADOW_DOUBLESIDED], context); + wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_SHADOW_DOUBLESIDED], threadID); @@ -2463,26 +2250,26 @@ void wiRenderer::DrawForShadowMap(DeviceContext context) if (k < 1) continue; - Mesh::UpdateRenderableInstances(visibleInstances.size(), context); + Mesh::UpdateRenderableInstances(visibleInstances.size(), threadID); - BindVertexBuffer((mesh->sOutBuffer ? mesh->sOutBuffer : mesh->meshVertBuff), 0, sizeof(Vertex), context); - BindVertexBuffer(mesh->meshInstanceBuffer, 1, sizeof(Instance), context); - BindIndexBuffer(mesh->meshIndexBuff, context); + 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); int matsiz = mesh->materialIndices.size(); int m = 0; for (Material* iMat : mesh->materials) { if (!wireRender && !iMat->isSky && !iMat->water && iMat->cast_shadow) { - BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0, context); + wiRenderer::graphicsDevice->BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0, threadID); static thread_local MaterialCB* mcb = new MaterialCB; (*mcb).Create(*iMat, m); - UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); - DrawIndexedInstanced(mesh->indices.size(), visibleInstances.size(), context); + wiRenderer::graphicsDevice->DrawIndexedInstanced(mesh->indices.size(), visibleInstances.size(), threadID); } m++; } @@ -2493,7 +2280,7 @@ void wiRenderer::DrawForShadowMap(DeviceContext context) i++; } - BindGS(nullptr, context); + wiRenderer::graphicsDevice->BindGS(nullptr, threadID); } } } @@ -2529,7 +2316,7 @@ void wiRenderer::SetSpotLightShadowProps(int shadowMapCount, int resolution) } -void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, DeviceContext context +void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, GRAPHICSTHREAD threadID , bool BlackOut, bool isReflection, SHADERTYPE shaded , TextureView refRes, bool grass, GRAPHICSTHREAD thread) { @@ -2581,9 +2368,9 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, DeviceContex envProbeCB->mTransform.r[0] = XMLoadFloat3(&envMapPositions[0]); envProbeCB->mTransform.r[1] = XMLoadFloat3(&envMapPositions[1]); envProbeCB->mTransform = XMMatrixTranspose(envProbeCB->mTransform); - UpdateBuffer(constantBuffers[CBTYPE_MISC], envProbeCB, context); - BindTexturePS(envMaps[0], TEXSLOT_ENV0, context); - BindTexturePS(envMaps[1], TEXSLOT_ENV1, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MISC], envProbeCB, threadID); + wiRenderer::graphicsDevice->BindTexturePS(envMaps[0], TEXSLOT_ENV0, threadID); + wiRenderer::graphicsDevice->BindTexturePS(envMaps[1], TEXSLOT_ENV1, threadID); @@ -2591,67 +2378,67 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, DeviceContex culledRenderer[((Object*)object)->mesh].insert((Object*)object); if(grass){ for(wiHairParticle* hair : ((Object*)object)->hParticleSystems){ - hair->Draw(camera,context); + hair->Draw(camera,threadID); } } } if(DX11Eff && tessF) - BindPrimitiveTopology(PATCHLIST,context); + wiRenderer::graphicsDevice->BindPrimitiveTopology(PATCHLIST,threadID); else - BindPrimitiveTopology(TRIANGLELIST,context); - BindVertexLayout(vertexLayouts[VLTYPE_EFFECT],context); + wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLELIST,threadID); + wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_EFFECT],threadID); if(DX11Eff && tessF) - BindVS(vertexShaders[VSTYPE_OBJECT],context); + wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_OBJECT],threadID); else { if (isReflection) { - BindVS(vertexShaders[VSTYPE_OBJECT_REFLECTION], context); + wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_OBJECT_REFLECTION], threadID); } else { - BindVS(vertexShaders[VSTYPE_OBJECT10], context); + wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_OBJECT10], threadID); } } if(DX11Eff && tessF) - BindHS(hullShaders[HSTYPE_OBJECT],context); + wiRenderer::graphicsDevice->BindHS(hullShaders[HSTYPE_OBJECT],threadID); else - BindHS(nullptr,context); + wiRenderer::graphicsDevice->BindHS(nullptr,threadID); if(DX11Eff && tessF) - BindDS(domainShaders[DSTYPE_OBJECT],context); + wiRenderer::graphicsDevice->BindDS(domainShaders[DSTYPE_OBJECT],threadID); else - BindDS(nullptr,context); + wiRenderer::graphicsDevice->BindDS(nullptr,threadID); if (wireRender) - BindPS(pixelShaders[PSTYPE_SIMPLEST], context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_SIMPLEST], threadID); else if (BlackOut) - BindPS(pixelShaders[PSTYPE_BLACKOUT], context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_BLACKOUT], threadID); else if (shaded == SHADERTYPE_NONE) - BindPS(pixelShaders[PSTYPE_TEXTUREONLY], context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_TEXTUREONLY], threadID); else if (shaded == SHADERTYPE_DEFERRED) - BindPS(pixelShaders[PSTYPE_OBJECT], context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_OBJECT], threadID); else if (shaded == SHADERTYPE_FORWARD_SIMPLE) - BindPS(pixelShaders[PSTYPE_OBJECT_FORWARDSIMPLE], context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_OBJECT_FORWARDSIMPLE], threadID); else return; - BindBlendState(blendStates[BSTYPE_OPAQUE],context); + wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); if(!wireRender) { if (enviroMap != nullptr) { - BindTexturePS(enviroMap, TEXSLOT_ENV_GLOBAL, context); + wiRenderer::graphicsDevice->BindTexturePS(enviroMap, TEXSLOT_ENV_GLOBAL, threadID); } else { - UnbindTextures(TEXSLOT_ENV_GLOBAL, 1, context); + wiRenderer::graphicsDevice->UnbindTextures(TEXSLOT_ENV_GLOBAL, 1, threadID); } if(refRes != nullptr) - BindTexturePS(refRes,TEXSLOT_ONDEMAND5,context); + wiRenderer::graphicsDevice->BindTexturePS(refRes,TEXSLOT_ONDEMAND5,threadID); } @@ -2661,9 +2448,9 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, DeviceContex if(!mesh->doubleSided) - BindRasterizerState(wireRender?rasterizers[RSTYPE_WIRE]:rasterizers[RSTYPE_FRONT],context); + wiRenderer::graphicsDevice->BindRasterizerState(wireRender?rasterizers[RSTYPE_WIRE]:rasterizers[RSTYPE_FRONT],threadID); else - BindRasterizerState(wireRender?rasterizers[RSTYPE_WIRE]:rasterizers[RSTYPE_DOUBLESIDED],context); + wiRenderer::graphicsDevice->BindRasterizerState(wireRender?rasterizers[RSTYPE_WIRE]:rasterizers[RSTYPE_DOUBLESIDED],threadID); int matsiz = mesh->materialIndices.size(); @@ -2680,12 +2467,12 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, DeviceContex if(k<1) continue; - Mesh::UpdateRenderableInstances(visibleInstances.size(), context); + Mesh::UpdateRenderableInstances(visibleInstances.size(), threadID); - BindIndexBuffer(mesh->meshIndexBuff,context); - BindVertexBuffer((mesh->sOutBuffer?mesh->sOutBuffer:mesh->meshVertBuff),0,sizeof(Vertex),context); - BindVertexBuffer(mesh->meshInstanceBuffer,1,sizeof(Instance),context); + 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); int m=0; for(Material* iMat : mesh->materials){ @@ -2693,27 +2480,27 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, DeviceContex if(!iMat->IsTransparent() && !iMat->isSky && !iMat->water){ if(iMat->shadeless) - BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT],STENCILREF_SHADELESS,context); + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT],STENCILREF_SHADELESS,threadID); if(iMat->subsurface_scattering) - BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT],STENCILREF_SKIN,context); + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT],STENCILREF_SKIN,threadID); else - BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT],mesh->stencilRef,context); + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT],mesh->stencilRef,threadID); static thread_local MaterialCB* mcb = new MaterialCB; (*mcb).Create(*iMat, m); - UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); - if(!wireRender) BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0,context); - if(!wireRender) BindTexturePS(iMat->refMap, TEXSLOT_ONDEMAND1,context); - if(!wireRender) BindTexturePS(iMat->normalMap, TEXSLOT_ONDEMAND2,context); - if(!wireRender) BindTexturePS(iMat->specularMap, TEXSLOT_ONDEMAND3,context); + 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(DX11Eff) - BindTextureDS(iMat->displacementMap, TEXSLOT_ONDEMAND4,context); + wiRenderer::graphicsDevice->BindTextureDS(iMat->displacementMap, TEXSLOT_ONDEMAND4,threadID); - DrawIndexedInstanced(mesh->indices.size(),visibleInstances.size(),context); + wiRenderer::graphicsDevice->DrawIndexedInstanced(mesh->indices.size(),visibleInstances.size(),threadID); } m++; } @@ -2721,17 +2508,17 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, DeviceContex } - BindPS(nullptr,context); - BindVS(nullptr,context); - BindDS(nullptr,context); - BindHS(nullptr,context); + wiRenderer::graphicsDevice->BindPS(nullptr,threadID); + wiRenderer::graphicsDevice->BindVS(nullptr,threadID); + wiRenderer::graphicsDevice->BindDS(nullptr,threadID); + wiRenderer::graphicsDevice->BindHS(nullptr,threadID); } } void wiRenderer::DrawWorldTransparent(Camera* camera, TextureView refracRes, TextureView refRes - , TextureView waterRippleNormals, DeviceContext context) + , TextureView waterRippleNormals, GRAPHICSTHREAD threadID) { CulledCollection culledRenderer; CulledList culledObjects; @@ -2760,9 +2547,9 @@ void wiRenderer::DrawWorldTransparent(Camera* camera, TextureView refracRes, Tex for(Cullable* object : culledObjects) culledRenderer[((Object*)object)->mesh].insert((Object*)object); - BindPrimitiveTopology(TRIANGLELIST,context); - BindVertexLayout(vertexLayouts[VLTYPE_EFFECT],context); - BindVS(vertexShaders[VSTYPE_OBJECT10],context); + wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLELIST,threadID); + wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_EFFECT],threadID); + wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_OBJECT10],threadID); if (!wireRender) @@ -2770,20 +2557,20 @@ void wiRenderer::DrawWorldTransparent(Camera* camera, TextureView refracRes, Tex if (enviroMap != nullptr) { - BindTexturePS(enviroMap, TEXSLOT_ENV_GLOBAL, context); + wiRenderer::graphicsDevice->BindTexturePS(enviroMap, TEXSLOT_ENV_GLOBAL, threadID); } else { - UnbindTextures(TEXSLOT_ENV_GLOBAL, 1, context); + wiRenderer::graphicsDevice->UnbindTextures(TEXSLOT_ENV_GLOBAL, 1, threadID); } - BindTexturePS(refRes, TEXSLOT_ONDEMAND5,context); - BindTexturePS(refracRes, TEXSLOT_ONDEMAND6,context); - //BindTexturePS(depth,7,context); - BindTexturePS(waterRippleNormals, TEXSLOT_ONDEMAND7, context); + wiRenderer::graphicsDevice->BindTexturePS(refRes, TEXSLOT_ONDEMAND5,threadID); + wiRenderer::graphicsDevice->BindTexturePS(refracRes, TEXSLOT_ONDEMAND6,threadID); + //BindTexturePS(depth,7,threadID); + wiRenderer::graphicsDevice->BindTexturePS(waterRippleNormals, TEXSLOT_ONDEMAND7, threadID); } - BindBlendState(blendStates[BSTYPE_OPAQUE],context); + wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE],threadID); RENDERTYPE lastRenderType = RENDERTYPE_VOID; @@ -2804,9 +2591,9 @@ void wiRenderer::DrawWorldTransparent(Camera* camera, TextureView refracRes, Tex continue; if (!mesh->doubleSided) - BindRasterizerState(wireRender ? rasterizers[RSTYPE_WIRE] : rasterizers[RSTYPE_FRONT], context); + wiRenderer::graphicsDevice->BindRasterizerState(wireRender ? rasterizers[RSTYPE_WIRE] : rasterizers[RSTYPE_FRONT], threadID); else - BindRasterizerState(wireRender ? rasterizers[RSTYPE_WIRE] : rasterizers[RSTYPE_DOUBLESIDED], context); + wiRenderer::graphicsDevice->BindRasterizerState(wireRender ? rasterizers[RSTYPE_WIRE] : rasterizers[RSTYPE_DOUBLESIDED], threadID); int matsiz = mesh->materialIndices.size(); @@ -2826,12 +2613,12 @@ void wiRenderer::DrawWorldTransparent(Camera* camera, TextureView refracRes, Tex if (k<1) continue; - Mesh::UpdateRenderableInstances(visibleInstances.size(), context); + Mesh::UpdateRenderableInstances(visibleInstances.size(), threadID); - BindIndexBuffer(mesh->meshIndexBuff,context); - BindVertexBuffer((mesh->sOutBuffer?mesh->sOutBuffer:mesh->meshVertBuff),0,sizeof(Vertex),context); - BindVertexBuffer(mesh->meshInstanceBuffer,1,sizeof(Instance),context); + 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); int m=0; @@ -2844,30 +2631,30 @@ void wiRenderer::DrawWorldTransparent(Camera* camera, TextureView refracRes, Tex static thread_local MaterialCB* mcb = new MaterialCB; (*mcb).Create(*iMat, m); - UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); - if(!wireRender) BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0,context); - if(!wireRender) BindTexturePS(iMat->refMap, TEXSLOT_ONDEMAND1,context); - if(!wireRender) BindTexturePS(iMat->normalMap, TEXSLOT_ONDEMAND2,context); - if(!wireRender) BindTexturePS(iMat->specularMap, TEXSLOT_ONDEMAND3,context); + 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 (iMat->IsTransparent() && lastRenderType != RENDERTYPE_TRANSPARENT) { lastRenderType = RENDERTYPE_TRANSPARENT; - BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_TRANSPARENT, context); - BindPS(wireRender ? pixelShaders[PSTYPE_SIMPLEST] : pixelShaders[PSTYPE_OBJECT_TRANSPARENT], context); + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_TRANSPARENT, threadID); + wiRenderer::graphicsDevice->BindPS(wireRender ? pixelShaders[PSTYPE_SIMPLEST] : pixelShaders[PSTYPE_OBJECT_TRANSPARENT], threadID); } if (iMat->IsWater() && lastRenderType != RENDERTYPE_WATER) { lastRenderType = RENDERTYPE_WATER; - BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD], STENCILREF_EMPTY, context); - BindPS(wireRender ? pixelShaders[PSTYPE_SIMPLEST] : pixelShaders[PSTYPE_WATER], context); - BindRasterizerState(wireRender ? rasterizers[RSTYPE_WIRE] : rasterizers[RSTYPE_DOUBLESIDED], context); + 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); } - DrawIndexedInstanced(mesh->indices.size(),visibleInstances.size(),context); + wiRenderer::graphicsDevice->DrawIndexedInstanced(mesh->indices.size(),visibleInstances.size(),threadID); } m++; } @@ -2877,49 +2664,49 @@ void wiRenderer::DrawWorldTransparent(Camera* camera, TextureView refracRes, Tex } -void wiRenderer::DrawSky(DeviceContext context, bool isReflection) +void wiRenderer::DrawSky(GRAPHICSTHREAD threadID, bool isReflection) { if (enviroMap == nullptr) return; - BindPrimitiveTopology(TRIANGLELIST,context); - BindRasterizerState(rasterizers[RSTYPE_BACK],context); - BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD],STENCILREF_SKY,context); - BindBlendState(blendStates[BSTYPE_OPAQUE],context); + 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); if (!isReflection) { - BindVS(vertexShaders[VSTYPE_SKY], context); - BindPS(pixelShaders[PSTYPE_SKY], context); + wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_SKY], threadID); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_SKY], threadID); } else { - BindVS(vertexShaders[VSTYPE_SKY_REFLECTION], context); - BindPS(pixelShaders[PSTYPE_SKY_REFLECTION], context); + wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_SKY_REFLECTION], threadID); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_SKY_REFLECTION], threadID); } - BindTexturePS(enviroMap, TEXSLOT_ENV_GLOBAL, context); + wiRenderer::graphicsDevice->BindTexturePS(enviroMap, TEXSLOT_ENV_GLOBAL, threadID); - BindVertexBuffer(nullptr,0,0,context); - BindVertexLayout(nullptr, context); - Draw(240,context); + wiRenderer::graphicsDevice->BindVertexBuffer(nullptr,0,0,threadID); + wiRenderer::graphicsDevice->BindVertexLayout(nullptr, threadID); + wiRenderer::graphicsDevice->Draw(240,threadID); } -void wiRenderer::DrawSun(DeviceContext context) +void wiRenderer::DrawSun(GRAPHICSTHREAD threadID) { - BindPrimitiveTopology(TRIANGLELIST, context); - BindRasterizerState(rasterizers[RSTYPE_BACK], context); - BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD], STENCILREF_SKY, context); - BindBlendState(blendStates[BSTYPE_ADDITIVE], context); + 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); - BindVS(vertexShaders[VSTYPE_SKY], context); - BindPS(pixelShaders[PSTYPE_SUN], context); + wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_SKY], threadID); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_SUN], threadID); - BindVertexBuffer(nullptr, 0, 0, context); - BindVertexLayout(nullptr, context); - Draw(240, context); + wiRenderer::graphicsDevice->BindVertexBuffer(nullptr, 0, 0, threadID); + wiRenderer::graphicsDevice->BindVertexLayout(nullptr, threadID); + wiRenderer::graphicsDevice->Draw(240, threadID); } -void wiRenderer::DrawDecals(Camera* camera, DeviceContext context) +void wiRenderer::DrawDecals(Camera* camera, GRAPHICSTHREAD threadID) { bool boundCB = false; for (Model* model : GetScene().models) @@ -2930,28 +2717,28 @@ void wiRenderer::DrawDecals(Camera* camera, DeviceContext context) if (!boundCB) { boundCB = true; - BindConstantBufferPS(constantBuffers[CBTYPE_DECAL], CB_GETBINDSLOT(DecalCB),context); + wiRenderer::graphicsDevice->BindConstantBufferPS(constantBuffers[CBTYPE_DECAL], CB_GETBINDSLOT(DecalCB),threadID); } - //BindTexturePS(depth, 1, context); - BindVS(vertexShaders[VSTYPE_DECAL], context); - BindPS(pixelShaders[PSTYPE_DECAL], context); - BindRasterizerState(rasterizers[RSTYPE_BACK], context); - BindBlendState(blendStates[BSTYPE_TRANSPARENT], context); - BindDepthStencilState(depthStencils[DSSTYPE_STENCILREAD_MATCH], STENCILREF::STENCILREF_DEFAULT, context); - BindVertexLayout(nullptr, context); - BindPrimitiveTopology(PRIMITIVETOPOLOGY::TRIANGLELIST, context); + //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); for (Decal* decal : model->decals) { if ((decal->texture || decal->normal) && camera->frustum.CheckBox(decal->bounds.corners)) { - BindTexturePS(decal->texture, TEXSLOT_ONDEMAND0, context); - BindTexturePS(decal->normal, TEXSLOT_ONDEMAND1, context); + wiRenderer::graphicsDevice->BindTexturePS(decal->texture, TEXSLOT_ONDEMAND0, threadID); + wiRenderer::graphicsDevice->BindTexturePS(decal->normal, TEXSLOT_ONDEMAND1, threadID); static thread_local MiscCB* dcbvs = new MiscCB; (*dcbvs).mTransform =XMMatrixTranspose(XMLoadFloat4x4(&decal->world)*camera->GetViewProjection()); - UpdateBuffer(constantBuffers[CBTYPE_MISC], dcbvs, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MISC], dcbvs, threadID); static thread_local DecalCB* dcbps = new DecalCB; dcbps->mDecalVP = @@ -2966,9 +2753,9 @@ void wiRenderer::DrawDecals(Camera* camera, DeviceContext context) 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; - UpdateBuffer(constantBuffers[CBTYPE_DECAL], dcbps, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_DECAL], dcbps, threadID); - Draw(36, context); + wiRenderer::graphicsDevice->Draw(36, threadID); } @@ -2976,7 +2763,7 @@ void wiRenderer::DrawDecals(Camera* camera, DeviceContext context) } } -void wiRenderer::UpdateWorldCB(DeviceContext context) +void wiRenderer::UpdateWorldCB(GRAPHICSTHREAD threadID) { static thread_local WorldCB* cb = new WorldCB; @@ -2989,9 +2776,9 @@ void wiRenderer::UpdateWorldCB(DeviceContext context) XMStoreFloat4(&(*cb).mSun, GetSunPosition()); (*cb).mSunColor = GetSunColor(); - UpdateBuffer(constantBuffers[CBTYPE_WORLD], cb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_WORLD], cb, threadID); } -void wiRenderer::UpdateFrameCB(DeviceContext context) +void wiRenderer::UpdateFrameCB(GRAPHICSTHREAD threadID) { static thread_local FrameCB* cb = new FrameCB; @@ -3001,9 +2788,9 @@ void wiRenderer::UpdateFrameCB(DeviceContext context) (*cb).mWindWaveSize = wind.waveSize; (*cb).mWindDirection = wind.direction; - UpdateBuffer(constantBuffers[CBTYPE_FRAME], cb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_FRAME], cb, threadID); } -void wiRenderer::UpdateCameraCB(DeviceContext context) +void wiRenderer::UpdateCameraCB(GRAPHICSTHREAD threadID) { static thread_local CameraCB* cb = new CameraCB; @@ -3025,28 +2812,28 @@ void wiRenderer::UpdateCameraCB(DeviceContext context) (*cb).mZNearP = camera->zNearP; (*cb).mZFarP = camera->zFarP; - UpdateBuffer(constantBuffers[CBTYPE_CAMERA], cb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_CAMERA], cb, threadID); } -void wiRenderer::SetClipPlane(XMFLOAT4 clipPlane, DeviceContext context) +void wiRenderer::SetClipPlane(XMFLOAT4 clipPlane, GRAPHICSTHREAD threadID) { - UpdateBuffer(constantBuffers[CBTYPE_CLIPPLANE], &clipPlane, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_CLIPPLANE], &clipPlane, threadID); } -void wiRenderer::UpdateGBuffer(vector gbuffer, DeviceContext context) +void wiRenderer::UpdateGBuffer(vector gbuffer, GRAPHICSTHREAD threadID) { for (unsigned int i = 0; i < gbuffer.size(); ++i) { - BindTexturePS(gbuffer[i], TEXSLOT_GBUFFER0 + i, context); + wiRenderer::graphicsDevice->BindTexturePS(gbuffer[i], TEXSLOT_GBUFFER0 + i, threadID); } } -void wiRenderer::UpdateDepthBuffer(TextureView depth, TextureView linearDepth, DeviceContext context) +void wiRenderer::UpdateDepthBuffer(TextureView depth, TextureView linearDepth, GRAPHICSTHREAD threadID) { - BindTexturePS(depth, TEXSLOT_DEPTH, context); - BindTextureVS(depth, TEXSLOT_DEPTH, context); - BindTextureGS(depth, TEXSLOT_DEPTH, context); + wiRenderer::graphicsDevice->BindTexturePS(depth, TEXSLOT_DEPTH, threadID); + wiRenderer::graphicsDevice->BindTextureVS(depth, TEXSLOT_DEPTH, threadID); + wiRenderer::graphicsDevice->BindTextureGS(depth, TEXSLOT_DEPTH, threadID); - BindTexturePS(linearDepth, TEXSLOT_LINEARDEPTH, context); - BindTextureVS(linearDepth, TEXSLOT_LINEARDEPTH, context); - BindTextureGS(linearDepth, TEXSLOT_LINEARDEPTH, context); + wiRenderer::graphicsDevice->BindTexturePS(linearDepth, TEXSLOT_LINEARDEPTH, threadID); + wiRenderer::graphicsDevice->BindTextureVS(linearDepth, TEXSLOT_LINEARDEPTH, threadID); + wiRenderer::graphicsDevice->BindTextureGS(linearDepth, TEXSLOT_LINEARDEPTH, threadID); } void wiRenderer::FinishLoading() @@ -3264,8 +3051,8 @@ Model* wiRenderer::LoadModel(const string& dir, const string& name, const XMMATR physicsEngine->registerObject(o); } } - - Lock(); + + wiRenderer::graphicsDevice->LOCK(); Update(); @@ -3293,7 +3080,7 @@ Model* wiRenderer::LoadModel(const string& dir, const string& name, const XMMATR SetUpCubes(); SetUpBoneLines(); - Unlock(); + wiRenderer::graphicsDevice->UNLOCK(); LoadWorldInfo(dir, name); @@ -3305,9 +3092,9 @@ void wiRenderer::LoadWorldInfo(const string& dir, const string& name) { LoadWiWorldInfo(dir, name+".wiw", GetScene().worldInfo, GetScene().wind); - Lock(); - UpdateWorldCB(getImmediateContext()); - Unlock(); + wiRenderer::graphicsDevice->LOCK(); + UpdateWorldCB(GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::graphicsDevice->UNLOCK(); } Scene& wiRenderer::GetScene() { @@ -3395,21 +3182,21 @@ void wiRenderer::PutEnvProbe(const XMFLOAT3& position, int resolution) probe->transform(position); probe->cubeMap.InitializeCube(resolution, 1, true, DXGI_FORMAT_R16G16B16A16_FLOAT, 0); - Lock(); + wiRenderer::graphicsDevice->LOCK(); - DeviceContext context = getImmediateContext(); + GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE; - probe->cubeMap.Activate(context, 0, 0, 0, 1); + probe->cubeMap.Activate(threadID, 0, 0, 0, 1); - BindVertexLayout(vertexLayouts[VLTYPE_EFFECT], context); - BindPrimitiveTopology(TRIANGLELIST, context); - BindBlendState(blendStates[BSTYPE_OPAQUE], context); + wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_EFFECT], threadID); + wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLELIST, threadID); + wiRenderer::graphicsDevice->BindBlendState(blendStates[BSTYPE_OPAQUE], threadID); - BindPS(pixelShaders[PSTYPE_ENVMAP], context); - BindVS(vertexShaders[VSTYPE_ENVMAP], context); - BindGS(geometryShaders[GSTYPE_ENVMAP], context); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_ENVMAP], threadID); + wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_ENVMAP], threadID); + wiRenderer::graphicsDevice->BindGS(geometryShaders[GSTYPE_ENVMAP], threadID); - BindConstantBufferGS(constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubeMapRenderCB), context); + wiRenderer::graphicsDevice->BindConstantBufferGS(constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubeMapRenderCB), threadID); vector cameras; @@ -3434,7 +3221,7 @@ void wiRenderer::PutEnvProbe(const XMFLOAT3& position, int resolution) (*cb).mViewProjection[i] = cameras[i].getVP(); } - UpdateBuffer(constantBuffers[CBTYPE_CUBEMAPRENDER], cb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_CUBEMAPRENDER], cb, threadID); CulledList culledObjects; @@ -3455,9 +3242,9 @@ void wiRenderer::PutEnvProbe(const XMFLOAT3& position, int resolution) if (!mesh->isBillboarded && !visibleInstances.empty()) { if (!mesh->doubleSided) - BindRasterizerState(rasterizers[RSTYPE_FRONT], context); + wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_FRONT], threadID); else - BindRasterizerState(rasterizers[RSTYPE_DOUBLESIDED], context); + wiRenderer::graphicsDevice->BindRasterizerState(rasterizers[RSTYPE_DOUBLESIDED], threadID); @@ -3474,12 +3261,12 @@ void wiRenderer::PutEnvProbe(const XMFLOAT3& position, int resolution) if (k < 1) continue; - Mesh::UpdateRenderableInstances(visibleInstances.size(), context); + Mesh::UpdateRenderableInstances(visibleInstances.size(), threadID); - BindVertexBuffer((mesh->sOutBuffer ? mesh->sOutBuffer : mesh->meshVertBuff), 0, sizeof(Vertex), context); - BindVertexBuffer(mesh->meshInstanceBuffer, 1, sizeof(Instance), context); - BindIndexBuffer(mesh->meshIndexBuff, context); + 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); int matsiz = mesh->materialIndices.size(); @@ -3488,20 +3275,20 @@ void wiRenderer::PutEnvProbe(const XMFLOAT3& position, int resolution) if (!wireRender && !iMat->isSky && !iMat->water && iMat->cast_shadow) { if (iMat->shadeless) - BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_SHADELESS, context); + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_SHADELESS, threadID); if (iMat->subsurface_scattering) - BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_SKIN, context); + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_SKIN, threadID); else - BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], mesh->stencilRef, context); + wiRenderer::graphicsDevice->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], mesh->stencilRef, threadID); - BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0, context); + wiRenderer::graphicsDevice->BindTexturePS(iMat->texture, TEXSLOT_ONDEMAND0, threadID); static thread_local MaterialCB* mcb = new MaterialCB; (*mcb).Create(*iMat, m); - UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, context); + wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_MATERIAL], mcb, threadID); - DrawIndexedInstanced(mesh->indices.size(), visibleInstances.size(), context); + wiRenderer::graphicsDevice->DrawIndexedInstanced(mesh->indices.size(), visibleInstances.size(), threadID); } m++; } @@ -3513,35 +3300,35 @@ void wiRenderer::PutEnvProbe(const XMFLOAT3& position, int resolution) // sky { - BindPrimitiveTopology(TRIANGLELIST, context); - BindRasterizerState(rasterizers[RSTYPE_BACK], context); - BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD], STENCILREF_SKY, context); - BindBlendState(blendStates[BSTYPE_OPAQUE], context); + 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); - BindVS(vertexShaders[VSTYPE_ENVMAP_SKY], context); - BindPS(pixelShaders[PSTYPE_ENVMAP_SKY], context); - BindGS(geometryShaders[GSTYPE_ENVMAP_SKY], context); + wiRenderer::graphicsDevice->BindVS(vertexShaders[VSTYPE_ENVMAP_SKY], threadID); + wiRenderer::graphicsDevice->BindPS(pixelShaders[PSTYPE_ENVMAP_SKY], threadID); + wiRenderer::graphicsDevice->BindGS(geometryShaders[GSTYPE_ENVMAP_SKY], threadID); - BindTexturePS(enviroMap, TEXSLOT_ENV_GLOBAL, context); + wiRenderer::graphicsDevice->BindTexturePS(enviroMap, TEXSLOT_ENV_GLOBAL, threadID); - BindVertexBuffer(nullptr, 0, 0, context); - BindVertexLayout(nullptr, context); - Draw(240, context); + wiRenderer::graphicsDevice->BindVertexBuffer(nullptr, 0, 0, threadID); + wiRenderer::graphicsDevice->BindVertexLayout(nullptr, threadID); + wiRenderer::graphicsDevice->Draw(240, threadID); } - BindGS(nullptr, context); + wiRenderer::graphicsDevice->BindGS(nullptr, threadID); - probe->cubeMap.Deactivate(context); + probe->cubeMap.Deactivate(threadID); - GenerateMips(probe->cubeMap.shaderResource[0], context); + wiRenderer::graphicsDevice->GenerateMips(probe->cubeMap.shaderResource[0], threadID); enviroMap = probe->cubeMap.shaderResource.front(); scene->environmentProbes.push_back(probe); - Unlock(); + wiRenderer::graphicsDevice->UNLOCK(); } void wiRenderer::MaterialCB::Create(const Material& mat,UINT materialIndex){ diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index a2a871e7a..94084fc7a 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -49,17 +49,7 @@ class wiRenderer { public: - static D3D_DRIVER_TYPE driverType; - static D3D_FEATURE_LEVEL featureLevel; - static SwapChain swapChain; - static RenderTargetView renderTargetView; - static ViewPort viewPort; - static GraphicsDevice graphicsDevice; - static DeviceContext immediateContext; - static bool DX11,VSYNC,DEFERREDCONTEXT_SUPPORT; - static DeviceContext deferredContexts[GRAPHICSTHREAD_COUNT]; - static CommandList commandLists[GRAPHICSTHREAD_COUNT]; - static mutex graphicsMutex; + static GraphicsDevice* graphicsDevice; #ifndef WINSTORE_SUPPORT static HRESULT InitDevice(HWND window, int screenW, int screenH, bool windowed); #else @@ -67,18 +57,7 @@ public: #endif static void DestroyDevice(); static void Present(function drawToScreen1=nullptr,function drawToScreen2=nullptr,function drawToScreen3=nullptr); - static void ExecuteDeferredContexts(); - static void FinishCommandList(GRAPHICSTHREAD thread); - static map drawCalls; - static long getDrawCallCount(); - static bool getMultithreadingSupport(){ return DEFERREDCONTEXT_SUPPORT; } - - inline static DeviceContext getImmediateContext(){ return immediateContext; } - inline static DeviceContext getDeferredContext(GRAPHICSTHREAD thread){ return deferredContexts[thread]; } - - inline static void Lock(){ graphicsMutex.lock(); } - inline static void Unlock(){ graphicsMutex.unlock(); } static Sampler samplers[SSLOT_COUNT]; @@ -329,7 +308,7 @@ public: static void Update(); // Render data that needs to be updated on the main thread! static void UpdatePerFrameData(); - static void UpdateRenderData(DeviceContext context); + static void UpdateRenderData(GRAPHICSTHREAD threadID); //static void UpdateSoftBodyPinning(); static void UpdateSPTree(wiSPTree*& tree); static void UpdateImages(); @@ -337,7 +316,7 @@ public: static void PutDecal(Decal* decal); static void PutWaterRipple(const string& image, const XMFLOAT3& pos, const wiWaterPlane& waterPlane); static void ManageWaterRipples(); - static void DrawWaterRipples(DeviceContext context); + static void DrawWaterRipples(GRAPHICSTHREAD threadID); static void SetGameSpeed(float value){GameSpeed=value; if(GameSpeed<0) GameSpeed=0;}; static float GetGameSpeed(); static void ChangeRasterizer(){wireRender=!wireRender;}; @@ -364,338 +343,46 @@ public: static Light* getLightByName(const string& name); static void ReloadShaders(const string& path = ""); - static void BindPersistentState(DeviceContext context); - static void RebindPersistentState(DeviceContext context); + static void BindPersistentState(GRAPHICSTHREAD threadID); + static void RebindPersistentState(GRAPHICSTHREAD threadID); static Vertex TransformVertex(const Mesh* mesh, int vertexI, const XMMATRIX& mat = XMMatrixIdentity()); static Vertex TransformVertex(const Mesh* mesh, const SkinnedVertex& vertex, const XMMATRIX& mat = XMMatrixIdentity()); static XMFLOAT3 VertexVelocity(const Mesh* mesh, const int& vertexI); public: - inline static void BindTexturePS(TextureView texture, int slot, DeviceContext context = immediateContext) { - if (context != nullptr && texture != nullptr) { - context->PSSetShaderResources(slot, 1, &texture); - } - } - inline static void BindTexturesPS(TextureView textures[], int slot, int num, DeviceContext context = immediateContext) { - if (context != nullptr && textures != nullptr) { - context->PSSetShaderResources(slot, num, textures); - } - } - inline static void BindTextureVS(TextureView texture, int slot, DeviceContext context = immediateContext) { - if (context != nullptr && texture != nullptr) { - context->VSSetShaderResources(slot, 1, &texture); - } - } - inline static void BindTexturesVS(TextureView textures[], int slot, int num, DeviceContext context = immediateContext) { - if (context != nullptr && textures != nullptr) { - context->VSSetShaderResources(slot, num, textures); - } - } - inline static void BindTextureGS(TextureView texture, int slot, DeviceContext context = immediateContext) { - if (context != nullptr && texture != nullptr) { - context->GSSetShaderResources(slot, 1, &texture); - } - } - inline static void BindTexturesGS(TextureView textures[], int slot, int num, DeviceContext context = immediateContext) { - if (context != nullptr && textures != nullptr) { - context->GSSetShaderResources(slot, num, textures); - } - } - inline static void BindTextureDS(TextureView texture, int slot, DeviceContext context = immediateContext) { - if (context != nullptr && texture != nullptr) { - context->DSSetShaderResources(slot, 1, &texture); - } - } - inline static void BindTexturesDS(TextureView textures[], int slot, int num, DeviceContext context = immediateContext) { - if (context != nullptr && textures != nullptr) { - context->DSSetShaderResources(slot, num, textures); - } - } - inline static void BindTextureHS(TextureView texture, int slot, DeviceContext context = immediateContext) { - if (context != nullptr && texture != nullptr) { - context->HSSetShaderResources(slot, 1, &texture); - } - } - inline static void BindTexturesHS(TextureView textures[], int slot, int num, DeviceContext context = immediateContext) { - if (context != nullptr && textures != nullptr) { - context->HSSetShaderResources(slot, num, textures); - } - } - inline static void UnbindTextures(int slot, int num, DeviceContext context = immediateContext) - { - assert(num <= 32 && "UnbindTextures limit of 32 reached!"); - if (context != nullptr) - { - static TextureView empties[32] = { - nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, - nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, - nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, - nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr, - }; - context->PSSetShaderResources(slot, num, empties); - context->VSSetShaderResources(slot, num, empties); - context->GSSetShaderResources(slot, num, empties); - context->HSSetShaderResources(slot, num, empties); - context->DSSetShaderResources(slot, num, empties); - } - } - inline static void BindSamplerPS(Sampler sampler, int slot, DeviceContext context = immediateContext) { - if (context != nullptr && sampler != nullptr) { - context->PSSetSamplers(slot, 1, &sampler); - } - } - inline static void BindSamplersPS(Sampler samplers[], int slot, int num, DeviceContext context = immediateContext) { - if (context != nullptr && samplers != nullptr) { - context->PSSetSamplers(slot, num, samplers); - } - } - inline static void BindSamplerVS(Sampler sampler, int slot, DeviceContext context = immediateContext) { - if (context != nullptr && sampler != nullptr) { - context->VSSetSamplers(slot, 1, &sampler); - } - } - inline static void BindSamplersVS(Sampler samplers[], int slot, int num, DeviceContext context = immediateContext) { - if (context != nullptr && samplers != nullptr) { - context->VSSetSamplers(slot, num, samplers); - } - } - inline static void BindSamplerGS(Sampler sampler, int slot, DeviceContext context = immediateContext) { - if (context != nullptr && sampler != nullptr) { - context->GSSetSamplers(slot, 1, &sampler); - } - } - inline static void BindSamplersGS(Sampler samplers[], int slot, int num, DeviceContext context = immediateContext) { - if (context != nullptr && samplers != nullptr) { - context->GSSetSamplers(slot, num, samplers); - } - } - inline static void BindSamplerHS(Sampler sampler, int slot, DeviceContext context = immediateContext) { - if (context != nullptr && sampler != nullptr) { - context->HSSetSamplers(slot, 1, &sampler); - } - } - inline static void BindSamplersHS(Sampler samplers[], int slot, int num, DeviceContext context = immediateContext) { - if (context != nullptr && samplers != nullptr) { - context->HSSetSamplers(slot, num, samplers); - } - } - inline static void BindSamplerDS(Sampler sampler, int slot, DeviceContext context = immediateContext) { - if (context != nullptr && sampler != nullptr) { - context->DSSetSamplers(slot, 1, &sampler); - } - } - inline static void BindSamplersDS(Sampler samplers[], int slot, int num, DeviceContext context = immediateContext) { - if (context != nullptr && samplers != nullptr) { - context->DSSetSamplers(slot, num, samplers); - } - } - inline static void BindConstantBufferPS(BufferResource buffer, int slot, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->PSSetConstantBuffers(slot, 1, &buffer); - } - } - inline static void BindConstantBufferVS(BufferResource buffer, int slot, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->VSSetConstantBuffers(slot, 1, &buffer); - - } - } - inline static void BindConstantBufferGS(BufferResource buffer, int slot, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->GSSetConstantBuffers(slot, 1, &buffer); - } - } - inline static void BindConstantBufferDS(BufferResource buffer, int slot, DeviceContext context = immediateContext) { - if (context != nullptr) { - - context->DSSetConstantBuffers(slot, 1, &buffer); - } - } - inline static void BindConstantBufferHS(BufferResource buffer, int slot, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->HSSetConstantBuffers(slot, 1, &buffer); - } - } - inline static void BindVertexBuffer(BufferResource vertexBuffer, int slot, UINT stride, DeviceContext context = immediateContext) { - if (context != nullptr) { - UINT offset = 0; - context->IASetVertexBuffers(slot, 1, &vertexBuffer, &stride, &offset); - } - } - inline static void BindIndexBuffer(BufferResource indexBuffer, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->IASetIndexBuffer(indexBuffer, DXGI_FORMAT_R32_UINT, 0); - } - } - inline static void BindPrimitiveTopology(PRIMITIVETOPOLOGY type, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->IASetPrimitiveTopology((D3D11_PRIMITIVE_TOPOLOGY)type); - } - } - inline static void BindVertexLayout(VertexLayout layout, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->IASetInputLayout(layout); - } - } - inline static void BindBlendState(BlendState state, DeviceContext context = immediateContext) { - if (context != nullptr) { - static float blendFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; - static UINT sampleMask = 0xffffffff; - context->OMSetBlendState(state, blendFactor, sampleMask); - } - } - inline static void BindBlendStateEx(BlendState state, const XMFLOAT4& blendFactor = XMFLOAT4(1, 1, 1, 1), UINT sampleMask = 0xffffffff, - DeviceContext context = immediateContext) { - if (context != nullptr) { - float fblendFactor[4] = { blendFactor.x, blendFactor.y, blendFactor.z, blendFactor.w }; - } - } - inline static void BindDepthStencilState(DepthStencilState state, UINT stencilRef, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->OMSetDepthStencilState(state, stencilRef); - } - } - inline static void BindRasterizerState(RasterizerState state, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->RSSetState(state); - } - } - inline static void BindStreamOutTarget(BufferResource buffer, DeviceContext context = immediateContext) { - if (context != nullptr) { - UINT offsetSO[1] = { 0 }; - context->SOSetTargets(1, &buffer, offsetSO); - } - } - inline static void BindPS(PixelShader shader, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->PSSetShader(shader, nullptr, 0); - } - } - inline static void BindVS(VertexShader shader, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->VSSetShader(shader, nullptr, 0); - } - } - inline static void BindGS(GeometryShader shader, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->GSSetShader(shader, nullptr, 0); - } - } - inline static void BindHS(HullShader shader, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->HSSetShader(shader, nullptr, 0); - } - } - inline static void BindDS(DomainShader shader, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->DSSetShader(shader, nullptr, 0); - } - } - inline static void Draw(int vertexCount, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->Draw(vertexCount, 0); - ++drawCalls[context]; - } - } - inline static void DrawIndexed(int indexCount, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->DrawIndexed(indexCount, 0, 0); - ++drawCalls[context]; - } - } - inline static void DrawIndexedInstanced(int indexCount, int instanceCount, DeviceContext context = immediateContext) { - if (context != nullptr) { - context->DrawIndexedInstanced(indexCount, instanceCount, 0, 0, 0); - ++drawCalls[context]; - } - } - inline static void GenerateMips(TextureView texture, DeviceContext context = immediateContext) - { - context->GenerateMips(texture); - } - //Comment: specify dataSize param if you are uploading multiple instances of data (eg. sizeof(Vertex)*vertices.count()) - template - inline static void ResizeBuffer(BufferResource& buffer, int dataCount) { - if (buffer != nullptr) { - static thread_local D3D11_BUFFER_DESC desc; - buffer->GetDesc(&desc); - int dataSize = sizeof(T)*dataCount; - if ((int)desc.ByteWidthRelease(); - desc.ByteWidth = dataSize; - graphicsDevice->CreateBuffer(&desc, nullptr, &buffer); - } - } - } - template - inline static void UpdateBuffer(BufferResource& buffer, const T* data, DeviceContext context = immediateContext, int dataSize = -1) - { - if (buffer != nullptr && data != nullptr && context != nullptr) { - static thread_local D3D11_BUFFER_DESC desc; - buffer->GetDesc(&desc); - HRESULT hr; - if (dataSize>(int)desc.ByteWidth) { //recreate the buffer if new datasize exceeds buffer size - buffer->Release(); - desc.ByteWidth = dataSize * 2; - hr = graphicsDevice->CreateBuffer(&desc, nullptr, &buffer); - } - if (desc.Usage == D3D11_USAGE_DYNAMIC) { - static thread_local D3D11_MAPPED_SUBRESOURCE mappedResource; - void* dataPtr; - context->Map(buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - dataPtr = (void*)mappedResource.pData; - memcpy(dataPtr, data, (dataSize >= 0 ? dataSize : desc.ByteWidth)); - context->Unmap(buffer, 0); - } - else { - context->UpdateSubresource(buffer, 0, nullptr, data, 0, 0); - } - } - } - template - inline static void SafeRelease(T& resource) { - if (resource != nullptr) { - resource->Release(); - resource = nullptr; - } - } - template - inline static void SafeInit(T& resource) - { - resource = nullptr; - } - - static void UpdateWorldCB(DeviceContext context); - static void UpdateFrameCB(DeviceContext context); - static void UpdateCameraCB(DeviceContext context); - static void SetClipPlane(XMFLOAT4 clipPlane, DeviceContext context); - static void UpdateGBuffer(vector gbuffer, DeviceContext context = immediateContext); - static void UpdateDepthBuffer(TextureView depth, TextureView linearDepth, DeviceContext context = immediateContext); - static void DrawSky(DeviceContext context, bool isReflection = false); - static void DrawSun(DeviceContext context); - static void DrawWorld(Camera* camera, bool DX11Eff, int tessF, DeviceContext context + + static void UpdateWorldCB(GRAPHICSTHREAD threadID); + static void UpdateFrameCB(GRAPHICSTHREAD threadID); + static void UpdateCameraCB(GRAPHICSTHREAD threadID); + static void SetClipPlane(XMFLOAT4 clipPlane, GRAPHICSTHREAD threadID); + static void UpdateGBuffer(vector gbuffer, GRAPHICSTHREAD threadID); + static void UpdateDepthBuffer(TextureView depth, TextureView linearDepth, GRAPHICSTHREAD threadID); + + static void DrawSky(GRAPHICSTHREAD threadID, bool isReflection = false); + static void DrawSun(GRAPHICSTHREAD threadID); + static void DrawWorld(Camera* camera, bool DX11Eff, int tessF, GRAPHICSTHREAD threadID , bool BlackOut, bool isReflection, SHADERTYPE shaded, TextureView refRes, bool grass, GRAPHICSTHREAD thread); - static void ClearShadowMaps(DeviceContext context); - static void DrawForShadowMap(DeviceContext context); + static void ClearShadowMaps(GRAPHICSTHREAD threadID); + static void DrawForShadowMap(GRAPHICSTHREAD threadID); static void DrawWorldTransparent(Camera* camera, TextureView refracRes, TextureView refRes - , TextureView waterRippleNormals, DeviceContext context); - void DrawDebugSpheres(Camera* camera, DeviceContext context); - static void DrawDebugBoneLines(Camera* camera, DeviceContext context); - static void DrawDebugLines(Camera* camera, DeviceContext context); - static void DrawDebugBoxes(Camera* camera, DeviceContext context); - static void DrawSoftParticles(Camera* camera, ID3D11DeviceContext *context, bool dark = false); - static void DrawSoftPremulParticles(Camera* camera, ID3D11DeviceContext *context, bool dark = false); - static void DrawTrails(DeviceContext context, TextureView refracRes); - static void DrawImagesAdd(DeviceContext context, TextureView refracRes); + , TextureView waterRippleNormals, GRAPHICSTHREAD threadID); + void DrawDebugSpheres(Camera* camera, GRAPHICSTHREAD threadID); + static void DrawDebugBoneLines(Camera* camera, GRAPHICSTHREAD threadID); + static void DrawDebugLines(Camera* camera, GRAPHICSTHREAD threadID); + static void DrawDebugBoxes(Camera* camera, GRAPHICSTHREAD threadID); + static void DrawSoftParticles(Camera* camera, GRAPHICSTHREAD threadID, bool dark = false); + static void DrawSoftPremulParticles(Camera* camera, GRAPHICSTHREAD threadID, bool dark = false); + static void DrawTrails(GRAPHICSTHREAD threadID, TextureView refracRes); + static void DrawImagesAdd(GRAPHICSTHREAD threadID, TextureView refracRes); //alpha-opaque - static void DrawImages(DeviceContext context, TextureView refracRes); - static void DrawImagesNormals(DeviceContext context, TextureView refracRes); - static void DrawLights(Camera* camera, DeviceContext context, unsigned int stencilRef = 2); - static void DrawVolumeLights(Camera* camera, DeviceContext context); - static void DrawLensFlares(DeviceContext context); - static void DrawDecals(Camera* camera, DeviceContext context); + static void DrawImages(GRAPHICSTHREAD threadID, TextureView refracRes); + static void DrawImagesNormals(GRAPHICSTHREAD threadID, TextureView refracRes); + static void DrawLights(Camera* camera, GRAPHICSTHREAD threadID, unsigned int stencilRef = 2); + static void DrawVolumeLights(Camera* camera, GRAPHICSTHREAD threadID); + static void DrawLensFlares(GRAPHICSTHREAD threadID); + static void DrawDecals(Camera* camera, GRAPHICSTHREAD threadID); static XMVECTOR GetSunPosition(); static XMFLOAT4 GetSunColor(); diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp index 5a26c4106..760b015ec 100644 --- a/WickedEngine/wiRenderer_BindLua.cpp +++ b/WickedEngine/wiRenderer_BindLua.cpp @@ -425,7 +425,7 @@ namespace wiRenderer_BindLua int argc = wiLua::SGetArgCount(L); if (argc > 0) { - wiRenderer::VSYNC = wiLua::SGetBool(L, 1); + wiRenderer::graphicsDevice->SetVSyncEnabled(wiLua::SGetBool(L, 1)); } return 0; } diff --git a/WickedEngine/wiResourceManager.cpp b/WickedEngine/wiResourceManager.cpp index 3a6dd6f1f..253ddc752 100644 --- a/WickedEngine/wiResourceManager.cpp +++ b/WickedEngine/wiResourceManager.cpp @@ -2,8 +2,6 @@ #include "wiRenderer.h" #include "wiSound.h" #include "wiHelper.h" -#include "Utility/WicTextureLoader.h" -#include "Utility/DDSTextureLoader.h" wiResourceManager::filetypes wiResourceManager::types; wiResourceManager* wiResourceManager::globalResources = nullptr; @@ -92,20 +90,21 @@ void* wiResourceManager::add(const string& name, Data_Type newType case Data_Type::IMAGE: { TextureView image=nullptr; - if( - !ext.compare("jpg") - || !ext.compare("JPG") - || !ext.compare("png") - || !ext.compare("PNG") - ) + //if( + // !ext.compare("jpg") + // || !ext.compare("JPG") + // || !ext.compare("png") + // || !ext.compare("PNG") + // ) { - wiRenderer::Lock(); - CreateWICTextureFromFile(true,wiRenderer::graphicsDevice,wiRenderer::getImmediateContext(),(wchar_t*)(wstring(name.begin(),name.end()).c_str()),nullptr,&image); - wiRenderer::Unlock(); - } - else if(!ext.compare("dds")){ - CreateDDSTextureFromFile(wiRenderer::graphicsDevice,(wchar_t*)(wstring(name.begin(),name.end()).c_str()),nullptr,&image); + //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(); } + //else if(!ext.compare("dds")){ + // CreateDDSTextureFromFile(wiRenderer::graphicsDevice,(wchar_t*)(wstring(name.begin(),name.end()).c_str()),nullptr,&image); + //} if(image) success=image; @@ -114,11 +113,12 @@ void* wiResourceManager::add(const string& name, Data_Type newType case Data_Type::IMAGE_STAGING: { APIResource image=nullptr; - if(!ext.compare("dds")){ - CreateDDSTextureFromFileEx(wiRenderer::graphicsDevice,(wchar_t*)(wstring(name.begin(),name.end()).c_str()),0 - ,D3D11_USAGE_STAGING,0,D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE,0,false - ,&image,nullptr); - } + //if(!ext.compare("dds")){ + // CreateDDSTextureFromFileEx(wiRenderer::graphicsDevice,(wchar_t*)(wstring(name.begin(),name.end()).c_str()),0 + // ,USAGE_STAGING,0,CPU_ACCESS_READ | CPU_ACCESS_WRITE,0,false + // ,&image,nullptr); + //} + wiHelper::messageBox("IMAGE_STAGING texture loading not implemented in ResourceManager!", "Warning!"); if(image) success=image; @@ -176,7 +176,7 @@ void* wiResourceManager::add(const string& name, Data_Type newType wiRenderer::graphicsDevice->CreateGeometryShader(buffer, bufferSize, nullptr, &shader); if (streamOutDecl != nullptr && elementCount > 0){ wiRenderer::graphicsDevice->CreateGeometryShaderWithStreamOutput(buffer, bufferSize, streamOutDecl, - elementCount, NULL, 0, shader ? 0 : D3D11_SO_NO_RASTERIZED_STREAM, NULL, &shader); + elementCount, NULL, 0, shader ? 0 : SO_NO_RASTERIZED_STREAM, NULL, &shader); } delete[] buffer; success = shader; @@ -260,30 +260,30 @@ bool wiResourceManager::del(const string& name, bool forceDelete) switch(res->type){ case Data_Type::IMAGE: case Data_Type::IMAGE_STAGING: - wiRenderer::SafeRelease(reinterpret_cast(res->data)); + SAFE_RELEASE(reinterpret_cast(res->data)); break; case Data_Type::VERTEXSHADER: { VertexShaderInfo* vsinfo = (VertexShaderInfo*)res->data; - wiRenderer::SafeRelease(vsinfo->vertexLayout); - wiRenderer::SafeRelease(vsinfo->vertexShader); + SAFE_RELEASE(vsinfo->vertexLayout); + SAFE_RELEASE(vsinfo->vertexShader); delete vsinfo; } break; case Data_Type::PIXELSHADER: - wiRenderer::SafeRelease(reinterpret_cast(res->data)); + SAFE_RELEASE(reinterpret_cast(res->data)); break; case Data_Type::GEOMETRYSHADER: - wiRenderer::SafeRelease(reinterpret_cast(res->data)); + SAFE_RELEASE(reinterpret_cast(res->data)); break; case Data_Type::HULLSHADER: - wiRenderer::SafeRelease(reinterpret_cast(res->data)); + SAFE_RELEASE(reinterpret_cast(res->data)); break; case Data_Type::DOMAINSHADER: - wiRenderer::SafeRelease(reinterpret_cast(res->data)); + SAFE_RELEASE(reinterpret_cast(res->data)); break; case Data_Type::COMPUTESHADER: - wiRenderer::SafeRelease(reinterpret_cast(res->data)); + SAFE_RELEASE(reinterpret_cast(res->data)); break; case Data_Type::SOUND: case Data_Type::MUSIC: diff --git a/WickedEngine/wiSPTree.cpp b/WickedEngine/wiSPTree.cpp index 443c7a347..8599ddf84 100644 --- a/WickedEngine/wiSPTree.cpp +++ b/WickedEngine/wiSPTree.cpp @@ -19,8 +19,8 @@ wiSPTree::~wiSPTree() } void wiSPTree::initialize(const vector& objects){ - initialize(objects,XMFLOAT3(D3D11_FLOAT32_MAX,D3D11_FLOAT32_MAX,D3D11_FLOAT32_MAX) - ,XMFLOAT3(-D3D11_FLOAT32_MAX,-D3D11_FLOAT32_MAX,-D3D11_FLOAT32_MAX)); + initialize(objects,XMFLOAT3(FLOAT32_MAX,FLOAT32_MAX,FLOAT32_MAX) + ,XMFLOAT3(-FLOAT32_MAX,-FLOAT32_MAX,-FLOAT32_MAX)); } void wiSPTree::initialize(const vector& objects, const XMFLOAT3& newMin, const XMFLOAT3& newMax){ XMFLOAT3 min = newMin; diff --git a/WickedEngine/wiSprite.cpp b/WickedEngine/wiSprite.cpp index 60fe25312..17f784003 100644 --- a/WickedEngine/wiSprite.cpp +++ b/WickedEngine/wiSprite.cpp @@ -59,23 +59,23 @@ void wiSprite::CleanUp(){ ContentHolder->del(mask); } -void wiSprite::Draw(TextureView refracRes, DeviceContext context){ +void wiSprite::Draw(TextureView refracRes, GRAPHICSTHREAD threadID){ if(effects.opacity>0 && ((effects.blendFlag==BLENDMODE_ADDITIVE && effects.fade<1) || effects.blendFlag!=BLENDMODE_ADDITIVE) ){ effects.setRefractionSource(refracRes); - wiImage::Draw(texturePointer,effects,context); + wiImage::Draw(texturePointer,effects,threadID); } } void wiSprite::Draw(){ - wiSprite::Draw(NULL,wiRenderer::getImmediateContext()); + wiSprite::Draw(NULL,GRAPHICSTHREAD_IMMEDIATE); } -void wiSprite::DrawNormal(DeviceContext context){ +void wiSprite::DrawNormal(GRAPHICSTHREAD threadID){ if(normalPointer && effects.opacity>0 && ((effects.blendFlag==BLENDMODE_ADDITIVE && effects.fade<1) || effects.blendFlag!=BLENDMODE_ADDITIVE)){ //effects.setRefractionMap(refracRes); wiImageEffects effectsMod(effects); effectsMod.blendFlag=BLENDMODE_ADDITIVE; effectsMod.extractNormalMap=true; - wiImage::Draw(normalPointer,effectsMod,context); + wiImage::Draw(normalPointer,effectsMod,threadID); } } diff --git a/WickedEngine/wiSprite.h b/WickedEngine/wiSprite.h index 9b90b3513..f5d1a5cbe 100644 --- a/WickedEngine/wiSprite.h +++ b/WickedEngine/wiSprite.h @@ -22,9 +22,9 @@ public: void Update(float); void Update(); - void Draw(TextureView refracRes, DeviceContext context); + void Draw(TextureView refracRes, GRAPHICSTHREAD threadID); void Draw(); - void DrawNormal(DeviceContext context); + void DrawNormal(GRAPHICSTHREAD threadID); string name; diff --git a/WickedEngine/wiTextureHelper.cpp b/WickedEngine/wiTextureHelper.cpp index e8963a2ae..3d08150a7 100644 --- a/WickedEngine/wiTextureHelper.cpp +++ b/WickedEngine/wiTextureHelper.cpp @@ -14,12 +14,12 @@ wiTextureHelper::wiTextureHelperInstance::~wiTextureHelperInstance() { for (int i = 0; i < HELPERTEXTURE_COUNT; ++i) { - wiRenderer::SafeRelease(helperTextures[i]); + SAFE_RELEASE(helperTextures[i]); } for (auto& x : colorTextures) { - wiRenderer::SafeRelease(x.second); + SAFE_RELEASE(x.second); } } diff --git a/WickedEngine/wiTextureHelper.h b/WickedEngine/wiTextureHelper.h index 102b4e9e0..f9dc94167 100644 --- a/WickedEngine/wiTextureHelper.h +++ b/WickedEngine/wiTextureHelper.h @@ -62,18 +62,19 @@ public: textureDesc.Format = format; textureDesc.SampleDesc.Count = 1; textureDesc.SampleDesc.Quality = 0; - textureDesc.Usage = D3D11_USAGE_DEFAULT; - textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + textureDesc.Usage = USAGE_DEFAULT; + textureDesc.BindFlags = BIND_SHADER_RESOURCE; textureDesc.CPUAccessFlags = 0; textureDesc.MiscFlags = 0; - D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc; + ShaderResourceViewDesc shaderResourceViewDesc; shaderResourceViewDesc.Format = format; - shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; - shaderResourceViewDesc.Texture2D.MipLevels = 1; + shaderResourceViewDesc.ViewDimension = RESOURCE_DIMENSION_TEXTURE2D; + //shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; + //shaderResourceViewDesc.Texture2D.MipLevels = 1; + shaderResourceViewDesc.mipLevels = 1; - D3D11_SUBRESOURCE_DATA InitData; + SubresourceData InitData; ZeroMemory(&InitData, sizeof(InitData)); InitData.pSysMem = data; InitData.SysMemPitch = static_cast(width * channelCount); @@ -86,7 +87,7 @@ public: return hr; } hr = wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D, &shaderResourceViewDesc, &texture); - wiRenderer::SafeRelease(texture2D); + SAFE_RELEASE(texture2D); return hr; }