diff --git a/WickedEngine/DeferredRenderableComponent.cpp b/WickedEngine/DeferredRenderableComponent.cpp index 576838edb..03eb09e3f 100644 --- a/WickedEngine/DeferredRenderableComponent.cpp +++ b/WickedEngine/DeferredRenderableComponent.cpp @@ -89,7 +89,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID){ wiRenderer::SetClipPlane(XMFLOAT4(0, 0, 0, 0), threadID); wiRenderer::DrawWorld(wiRenderer::getCamera(), false, tessellationQuality, threadID, false, false - , SHADERTYPE_DEFERRED, rtReflection.shaderResource.front(), true, GRAPHICSTHREAD_SCENE); + , SHADERTYPE_DEFERRED, rtReflection.GetTexture(), true, GRAPHICSTHREAD_SCENE); wiRenderer::DrawSky(threadID); @@ -101,7 +101,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID){ fx.sampleFlag = SAMPLEMODE_CLAMP; fx.quality = QUALITY_NEAREST; fx.process.setLinDepth(true); - wiImage::Draw(rtGBuffer.depth->shaderResource, fx, threadID); + wiImage::Draw(rtGBuffer.depth->GetTexture(), fx, threadID); fx.process.clear(); } rtLinearDepth.Deactivate(threadID); @@ -110,7 +110,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID){ wiRenderer::graphicsDevice->UnbindTextures(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID); - wiRenderer::UpdateDepthBuffer(dtDepthCopy.shaderResource, rtLinearDepth.shaderResource.front(), threadID); + wiRenderer::UpdateDepthBuffer(dtDepthCopy.GetTexture(), rtLinearDepth.GetTexture(), threadID); if (getStereogramEnabled()) { @@ -124,7 +124,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID){ } rtGBuffer.Deactivate(threadID); - wiRenderer::UpdateGBuffer(rtGBuffer.shaderResource, threadID); + wiRenderer::UpdateGBuffer(rtGBuffer.GetTexture(0), rtGBuffer.GetTexture(1), rtGBuffer.GetTexture(2), nullptr, nullptr, threadID); rtLight.Activate(threadID, rtGBuffer.depth); { wiRenderer::DrawLights(wiRenderer::getCamera(), threadID); @@ -149,13 +149,13 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID){ fx.blur = getSSAOBlur(); fx.blurDir = 0; fx.blendFlag = BLENDMODE_OPAQUE; - wiImage::Draw(rtSSAO[0].shaderResource.back(), fx, threadID); + wiImage::Draw(rtSSAO[0].GetTexture(), fx, threadID); } rtSSAO[2].Activate(threadID); { fx.blur = getSSAOBlur(); fx.blurDir = 1; fx.blendFlag = BLENDMODE_OPAQUE; - wiImage::Draw(rtSSAO[1].shaderResource.back(), fx, threadID); + wiImage::Draw(rtSSAO[1].GetTexture(), fx, threadID); fx.blur = 0; } fx.stencilRef = 0; @@ -164,9 +164,9 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID){ 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() + wiImage::DrawDeferred(rtGBuffer.GetTexture(0) + , rtLinearDepth.GetTexture(), rtLight.GetTexture(), rtGBuffer.GetTexture(1) + , getSSAOEnabled() ? rtSSAO.back().GetTexture() : wiTextureHelper::getInstance()->getWhite() , threadID, 0); wiRenderer::DrawDebugBoneLines(wiRenderer::getCamera(), threadID); wiRenderer::DrawDebugLines(wiRenderer::getCamera(), threadID); @@ -191,9 +191,9 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID){ dir.y = stren; fx.process.setSSSS(dir); if (i == 0) - wiImage::Draw(rtDeferred.shaderResource.back(), fx, threadID); + wiImage::Draw(rtDeferred.GetTexture(), fx, threadID); else - wiImage::Draw(rtSSS[i - 1].shaderResource.back(), fx, threadID); + wiImage::Draw(rtSSS[i - 1].GetTexture(), fx, threadID); } fx.process.clear(); rtSSS.back().Activate(threadID, rtGBuffer.depth); { @@ -204,10 +204,10 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID){ fx.blendFlag = BLENDMODE_OPAQUE; fx.stencilRef = 0; fx.stencilComp = 0; - wiImage::Draw(rtDeferred.shaderResource.front(), fx, threadID); + wiImage::Draw(rtDeferred.GetTexture(), fx, threadID); fx.stencilRef = STENCILREF_SKIN; fx.stencilComp = COMPARISON_LESS; - wiImage::Draw(rtSSS[rtSSS.size() - 2].shaderResource.back(), fx, threadID); + wiImage::Draw(rtSSS[rtSSS.size() - 2].GetTexture(), fx, threadID); } fx.stencilRef = 0; @@ -216,16 +216,16 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID){ if (getSSREnabled()){ rtSSR.Activate(threadID); { - wiRenderer::graphicsDevice->GenerateMips(rtDeferred.shaderResource[0], threadID); + wiRenderer::graphicsDevice->GenerateMips(rtDeferred.GetTexture(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()); + fx.setMaskMap(rtLinearDepth.GetTexture()); if (getSSSEnabled()) - wiImage::Draw(rtSSS.back().shaderResource.front(), fx, threadID); + wiImage::Draw(rtSSS.back().GetTexture(), fx, threadID); else - wiImage::Draw(rtDeferred.shaderResource.front(), fx, threadID); + wiImage::Draw(rtDeferred.GetTexture(), fx, threadID); fx.process.clear(); } } @@ -237,14 +237,14 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID){ //fx.setDepthMap(rtLinearDepth.shaderResource.back()); fx.blendFlag = BLENDMODE_OPAQUE; if (getSSREnabled()){ - wiImage::Draw(rtSSR.shaderResource.front(), fx, threadID); + wiImage::Draw(rtSSR.GetTexture(), fx, threadID); } else if (getSSSEnabled()) { - wiImage::Draw(rtSSS.back().shaderResource.front(), fx, threadID); + wiImage::Draw(rtSSS.back().GetTexture(), fx, threadID); } else{ - wiImage::Draw(rtDeferred.shaderResource.front(), fx, threadID); + wiImage::Draw(rtDeferred.GetTexture(), fx, threadID); } fx.process.clear(); } diff --git a/WickedEngine/ForwardRenderableComponent.cpp b/WickedEngine/ForwardRenderableComponent.cpp index 4e2df4c41..2a8a3591a 100644 --- a/WickedEngine/ForwardRenderableComponent.cpp +++ b/WickedEngine/ForwardRenderableComponent.cpp @@ -91,12 +91,12 @@ void ForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) fx.quality = QUALITY_NEAREST; fx.process.setLinDepth(true); //wiImage::BatchBegin(threadID); - wiImage::Draw(rtMain.depth->shaderResource, fx, threadID); + wiImage::Draw(rtMain.depth->GetTexture(), fx, threadID); } rtLinearDepth.Deactivate(threadID); dtDepthCopy.CopyFrom(*rtMain.depth, threadID); - wiRenderer::UpdateDepthBuffer(dtDepthCopy.shaderResource, rtLinearDepth.shaderResource.front(), threadID); + wiRenderer::UpdateDepthBuffer(dtDepthCopy.GetTexture(), rtLinearDepth.GetTexture(), threadID); } diff --git a/WickedEngine/Renderable2DComponent.cpp b/WickedEngine/Renderable2DComponent.cpp index ef66d0130..ee090e2bf 100644 --- a/WickedEngine/Renderable2DComponent.cpp +++ b/WickedEngine/Renderable2DComponent.cpp @@ -103,7 +103,7 @@ void Renderable2DComponent::Compose() wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); fx.presentFullScreen = true; - wiImage::Draw(rtFinal.shaderResource.back(), fx); + wiImage::Draw(rtFinal.GetTexture(), fx); RenderableComponent::Compose(); } diff --git a/WickedEngine/Renderable3DComponent.cpp b/WickedEngine/Renderable3DComponent.cpp index d1bafb820..e2009851f 100644 --- a/WickedEngine/Renderable3DComponent.cpp +++ b/WickedEngine/Renderable3DComponent.cpp @@ -286,9 +286,9 @@ void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRende //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(), threadID); - wiRenderer::DrawTrails(threadID, shadedSceneRT.shaderResource.front()); + wiRenderer::DrawWorldTransparent(wiRenderer::getCamera(), shadedSceneRT.GetTexture(), rtReflection.GetTexture() + , rtWaterRipple.GetTexture(), threadID); + wiRenderer::DrawTrails(threadID, shadedSceneRT.GetTexture()); } } @@ -310,26 +310,26 @@ void Renderable3DComponent::RenderBloom(GRAPHICSTHREAD threadID) fx.bloom.threshold = getBloomThreshold(); fx.blendFlag = BLENDMODE_OPAQUE; fx.sampleFlag = SAMPLEMODE_CLAMP; - wiImage::Draw(rtFinal[0].shaderResource.front(), fx, threadID); + wiImage::Draw(rtFinal[0].GetTexture(), fx, threadID); } rtBloom[1].Activate(threadID); //horizontal { - wiRenderer::graphicsDevice->GenerateMips(rtBloom[0].shaderResource[0], threadID); + wiRenderer::graphicsDevice->GenerateMips(rtBloom[0].GetTexture(), 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, threadID); + wiImage::Draw(rtBloom[0].GetTexture(), fx, threadID); } rtBloom[2].Activate(threadID); //vertical { fx.blur = getBloomStrength(); fx.blurDir = 1; fx.blendFlag = BLENDMODE_OPAQUE; - wiImage::Draw(rtBloom[1].shaderResource.back(), fx, threadID); + wiImage::Draw(rtBloom[1].GetTexture(), fx, threadID); } } void Renderable3DComponent::RenderLightShafts(wiRenderTarget& mainRT, GRAPHICSTHREAD threadID) @@ -363,7 +363,7 @@ void Renderable3DComponent::RenderLightShafts(wiRenderTarget& mainRT, GRAPHICSTH 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, threadID); + wiImage::Draw(rtSun[0].GetTexture(), fxs, threadID); } } } @@ -381,27 +381,27 @@ void Renderable3DComponent::RenderComposition1(wiRenderTarget& shadedSceneRT, GR rtFinal[0].Activate(threadID); fx.blendFlag = BLENDMODE_OPAQUE; - wiImage::Draw(shadedSceneRT.shaderResource.front(), fx, threadID); + wiImage::Draw(shadedSceneRT.GetTexture(), fx, threadID); fx.blendFlag = BLENDMODE_ALPHA; - wiImage::Draw(rtTransparent.shaderResource.back(), fx, threadID); + wiImage::Draw(rtTransparent.GetTexture(), fx, threadID); if (getEmittedParticlesEnabled()){ - wiImage::Draw(rtParticle.shaderResource.back(), fx, threadID); + wiImage::Draw(rtParticle.GetTexture(), fx, threadID); } fx.blendFlag = BLENDMODE_ADDITIVE; if (getVolumeLightsEnabled()){ - wiImage::Draw(rtVolumeLight.shaderResource.back(), fx, threadID); + wiImage::Draw(rtVolumeLight.GetTexture(), fx, threadID); } if (getEmittedParticlesEnabled()){ - wiImage::Draw(rtParticleAdditive.shaderResource.back(), fx, threadID); + wiImage::Draw(rtParticleAdditive.GetTexture(), fx, threadID); } if (getLightShaftsEnabled()){ - wiImage::Draw(rtSun.back().shaderResource.back(), fx, threadID); + wiImage::Draw(rtSun.back().GetTexture(), fx, threadID); } if (getLensFlareEnabled()){ - wiImage::Draw(rtLensFlare.shaderResource.back(), fx, threadID); + wiImage::Draw(rtLensFlare.GetTexture(), fx, threadID); } } void Renderable3DComponent::RenderComposition2(GRAPHICSTHREAD threadID){ @@ -420,20 +420,20 @@ void Renderable3DComponent::RenderComposition2(GRAPHICSTHREAD threadID){ rtDof[0].Activate(threadID); fx.blur = getDepthOfFieldStrength(); fx.blurDir = 0; - wiImage::Draw(rtFinal[0].shaderResource.back(), fx, threadID); + wiImage::Draw(rtFinal[0].GetTexture(), fx, threadID); rtDof[1].Activate(threadID); fx.blurDir = 1; - wiImage::Draw(rtDof[0].shaderResource.back(), fx, threadID); + wiImage::Draw(rtDof[0].GetTexture(), fx, threadID); fx.blur = 0; fx.process.clear(); // depth of field compose pass rtDof[2].Activate(threadID); fx.process.setDOF(getDepthOfFieldFocus()); - fx.setMaskMap(rtDof[1].shaderResource.back()); + fx.setMaskMap(rtDof[1].GetTexture()); //fx.setDepthMap(rtLinearDepth.shaderResource.back()); - wiImage::Draw(rtFinal[0].shaderResource.back(), fx, threadID); + wiImage::Draw(rtFinal[0].GetTexture(), fx, threadID); fx.setMaskMap(nullptr); //fx.setDepthMap(nullptr); fx.process.clear(); @@ -443,16 +443,16 @@ void Renderable3DComponent::RenderComposition2(GRAPHICSTHREAD threadID){ fx.process.setFXAA(getFXAAEnabled()); if (getDepthOfFieldEnabled()) - wiImage::Draw(rtDof[2].shaderResource.back(), fx, threadID); + wiImage::Draw(rtDof[2].GetTexture(), fx, threadID); else - wiImage::Draw(rtFinal[0].shaderResource.back(), fx, threadID); + wiImage::Draw(rtFinal[0].GetTexture(), fx, threadID); fx.process.clear(); if (getBloomEnabled()) { fx.blendFlag = BLENDMODE_ADDITIVE; fx.presentFullScreen = true; - wiImage::Draw(rtBloom.back().shaderResource.back(), fx, threadID); + wiImage::Draw(rtBloom.back().GetTexture(), fx, threadID); } } void Renderable3DComponent::RenderColorGradedComposition(){ @@ -488,7 +488,7 @@ void Renderable3DComponent::RenderColorGradedComposition(){ fx.presentFullScreen = true; } - wiImage::Draw(rtFinal[1].shaderResource.back(), fx); + wiImage::Draw(rtFinal[1].GetTexture(), fx); } diff --git a/WickedEngine/Texture_BindLua.cpp b/WickedEngine/Texture_BindLua.cpp index 8b85e38b5..0fd5130cf 100644 --- a/WickedEngine/Texture_BindLua.cpp +++ b/WickedEngine/Texture_BindLua.cpp @@ -9,7 +9,7 @@ Luna::PropertyType Texture_BindLua::properties[] = { { NULL, NULL } }; -Texture_BindLua::Texture_BindLua(TextureView texture) :texture(texture) +Texture_BindLua::Texture_BindLua(Texture2D* texture) :texture(texture) { } Texture_BindLua::Texture_BindLua(lua_State *L) diff --git a/WickedEngine/Texture_BindLua.h b/WickedEngine/Texture_BindLua.h index 63cd651f9..2b81aa603 100644 --- a/WickedEngine/Texture_BindLua.h +++ b/WickedEngine/Texture_BindLua.h @@ -6,13 +6,13 @@ class Texture_BindLua { public: - TextureView texture; + Texture2D* texture; static const char className[]; static Luna::FunctionType methods[]; static Luna::PropertyType properties[]; - Texture_BindLua(TextureView texture = nullptr); + Texture_BindLua(Texture2D* texture = nullptr); Texture_BindLua(lua_State *L); ~Texture_BindLua(); diff --git a/WickedEngine/wiBackLog.cpp b/WickedEngine/wiBackLog.cpp index 44293d0e2..f66b2108f 100644 --- a/WickedEngine/wiBackLog.cpp +++ b/WickedEngine/wiBackLog.cpp @@ -15,7 +15,7 @@ float wiBackLog::pos; int wiBackLog::scroll; stringstream wiBackLog::inputArea; int wiBackLog::historyPos=0; -TextureView wiBackLog::backgroundTex = nullptr; +Texture2D* wiBackLog::backgroundTex = nullptr; wiFont wiBackLog::font; void wiBackLog::Initialize(){ @@ -144,7 +144,7 @@ void wiBackLog::historyNext(){ } } -void wiBackLog::setBackground(TextureView texture) +void wiBackLog::setBackground(Texture2D* texture) { backgroundTex = texture; } diff --git a/WickedEngine/wiBackLog.h b/WickedEngine/wiBackLog.h index c39586590..18ffcba67 100644 --- a/WickedEngine/wiBackLog.h +++ b/WickedEngine/wiBackLog.h @@ -45,9 +45,9 @@ public: static bool isActive(){return state==IDLE;} - static void setBackground(TextureView texture); + static void setBackground(Texture2D* texture); - static TextureView backgroundTex; + static Texture2D* backgroundTex; static wiFont font; }; diff --git a/WickedEngine/wiDepthTarget.cpp b/WickedEngine/wiDepthTarget.cpp index 7d9ab7e9b..04f696c75 100644 --- a/WickedEngine/wiDepthTarget.cpp +++ b/WickedEngine/wiDepthTarget.cpp @@ -4,21 +4,26 @@ wiDepthTarget::wiDepthTarget() { - texture2D = NULL; - depthTarget = NULL; - shaderResource = NULL; + //texture2D = NULL; + //depthTarget = NULL; + //shaderResource = NULL; + texture = nullptr; + isCube = false; } wiDepthTarget::~wiDepthTarget() { - if(texture2D) texture2D->Release(); texture2D = NULL; - if(depthTarget) depthTarget->Release(); depthTarget = NULL; - if(shaderResource) shaderResource->Release(); shaderResource = NULL; + //if(texture2D) texture2D->Release(); texture2D = NULL; + //if(depthTarget) depthTarget->Release(); depthTarget = NULL; + //if(shaderResource) shaderResource->Release(); shaderResource = NULL; + SAFE_DELETE(texture); } void wiDepthTarget::Initialize(int width, int height, UINT MSAAC, UINT MSAAQ) { + isCube = false; + Texture2DDesc depthBufferDesc; ZeroMemory(&depthBufferDesc, sizeof(depthBufferDesc)); @@ -35,33 +40,37 @@ void wiDepthTarget::Initialize(int width, int height, UINT MSAAC, UINT MSAAQ) depthBufferDesc.CPUAccessFlags = 0; depthBufferDesc.MiscFlags = 0; - HRESULT hr; - // Create the texture for the depth buffer using the filled out description. - hr=wiRenderer::graphicsDevice->CreateTexture2D(&depthBufferDesc, nullptr, &texture2D); + wiRenderer::graphicsDevice->CreateTexture2D(&depthBufferDesc, nullptr, &texture); - DepthStencilViewDesc depthStencilViewDesc; - ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc)); - depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; - depthStencilViewDesc.ViewDimension = (MSAAQ==0 ? RESOURCE_DIMENSION_TEXTURE2D : RESOURCE_DIMENSION_TEXTURE2DMS); - //depthStencilViewDesc.Texture2D.MipSlice = 0; - depthStencilViewDesc.Flags = 0; + //HRESULT hr; + //// Create the texture for the depth buffer using the filled out description. + //hr=wiRenderer::graphicsDevice->CreateTexture2D(&depthBufferDesc, nullptr, &texture2D); - // Create the depth stencil view. - hr=wiRenderer::graphicsDevice->CreateDepthStencilView(texture2D, &depthStencilViewDesc, &depthTarget); + //DepthStencilViewDesc depthStencilViewDesc; + //ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc)); + //depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; + //depthStencilViewDesc.ViewDimension = (MSAAQ==0 ? RESOURCE_DIMENSION_TEXTURE2D : RESOURCE_DIMENSION_TEXTURE2DMS); + ////depthStencilViewDesc.Texture2D.MipSlice = 0; + //depthStencilViewDesc.Flags = 0; - //Create Depth ShaderResource - //ShaderResourceViewDesc shaderResourceViewDesc; - ZeroMemory(&shaderResourceViewDesc, sizeof(shaderResourceViewDesc)); - shaderResourceViewDesc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS; - shaderResourceViewDesc.ViewDimension = (MSAAQ==0 ? RESOURCE_DIMENSION_TEXTURE2D : RESOURCE_DIMENSION_TEXTURE2DMS); - //shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; - //shaderResourceViewDesc.Texture2D.MipLevels = 1; - shaderResourceViewDesc.mipLevels = 1; + //// Create the depth stencil view. + //hr=wiRenderer::graphicsDevice->CreateDepthStencilView(texture2D, &depthStencilViewDesc, &depthTarget); - wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D, &shaderResourceViewDesc, &shaderResource); + ////Create Depth ShaderResource + ////ShaderResourceViewDesc shaderResourceViewDesc; + //ZeroMemory(&shaderResourceViewDesc, sizeof(shaderResourceViewDesc)); + //shaderResourceViewDesc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS; + //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); } void wiDepthTarget::InitializeCube(int size) { + isCube = true; + Texture2DDesc depthBufferDesc; ZeroMemory(&depthBufferDesc, sizeof(depthBufferDesc)); @@ -78,45 +87,49 @@ void wiDepthTarget::InitializeCube(int size) depthBufferDesc.CPUAccessFlags = 0; 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); + wiRenderer::graphicsDevice->CreateTextureCube(&depthBufferDesc, nullptr, &textureCube); - DepthStencilViewDesc depthStencilViewDesc; - ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc)); - depthStencilViewDesc.Format = DXGI_FORMAT_D32_FLOAT; - depthStencilViewDesc.ViewDimension = RESOURCE_DIMENSION_TEXTURE2DARRAY; - // depthStencilViewDesc.Texture2DArray.FirstArraySlice = 0; - //depthStencilViewDesc.Texture2DArray.ArraySize = 6; - // depthStencilViewDesc.Texture2DArray.MipSlice = 0; - depthStencilViewDesc.ArraySize = 6; - depthStencilViewDesc.Flags = 0; + //HRESULT hr; + //// Create the texture for the depth buffer using the filled out description. + //hr=wiRenderer::graphicsDevice->CreateTexture2D(&depthBufferDesc, NULL, &texture2D); - // Create the depth stencil view. - hr=wiRenderer::graphicsDevice->CreateDepthStencilView(texture2D, &depthStencilViewDesc, &depthTarget); + //DepthStencilViewDesc depthStencilViewDesc; + //ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc)); + //depthStencilViewDesc.Format = DXGI_FORMAT_D32_FLOAT; + //depthStencilViewDesc.ViewDimension = RESOURCE_DIMENSION_TEXTURE2DARRAY; + //// depthStencilViewDesc.Texture2DArray.FirstArraySlice = 0; + ////depthStencilViewDesc.Texture2DArray.ArraySize = 6; + //// depthStencilViewDesc.Texture2DArray.MipSlice = 0; + //depthStencilViewDesc.ArraySize = 6; + //depthStencilViewDesc.Flags = 0; - //Create Depth ShaderResource - //ShaderResourceViewDesc shaderResourceViewDesc; - ZeroMemory(&shaderResourceViewDesc, sizeof(shaderResourceViewDesc)); - shaderResourceViewDesc.Format = DXGI_FORMAT_R32_FLOAT; - shaderResourceViewDesc.ViewDimension = RESOURCE_DIMENSION_TEXTURECUBE; - //shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; - //shaderResourceViewDesc.Texture2D.MipLevels = 1; - shaderResourceViewDesc.mipLevels = 1; + //// Create the depth stencil view. + //hr=wiRenderer::graphicsDevice->CreateDepthStencilView(texture2D, &depthStencilViewDesc, &depthTarget); - wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D, &shaderResourceViewDesc, &shaderResource); + ////Create Depth ShaderResource + ////ShaderResourceViewDesc shaderResourceViewDesc; + //ZeroMemory(&shaderResourceViewDesc, sizeof(shaderResourceViewDesc)); + //shaderResourceViewDesc.Format = DXGI_FORMAT_R32_FLOAT; + //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(GRAPHICSTHREAD threadID) { - wiRenderer::graphicsDevice->ClearDepthStencil( depthTarget, CLEAR_DEPTH | CLEAR_STENCIL, 1.0f, 0); + wiRenderer::graphicsDevice->ClearDepthStencil( texture, CLEAR_DEPTH | CLEAR_STENCIL, 1.0f, 0); } void wiDepthTarget::CopyFrom(const wiDepthTarget& from, GRAPHICSTHREAD threadID) { - if(shaderResource) shaderResource->Release(); - //static ShaderResourceViewDesc desc; - //from.shaderResource->GetDesc(&desc); - wiRenderer::graphicsDevice->CopyResource(texture2D,from.texture2D); - HRESULT r = wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D,&from.shaderResourceViewDesc,&shaderResource); + //if(shaderResource) shaderResource->Release(); + ////static ShaderResourceViewDesc desc; + ////from.shaderResource->GetDesc(&desc); + //wiRenderer::graphicsDevice->CopyResource(texture2D,from.texture2D); + //HRESULT r = wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D,&from.shaderResourceViewDesc,&shaderResource); + + wiRenderer::graphicsDevice->CopyTexture2D(GetTexture(), from.GetTexture(), threadID); } diff --git a/WickedEngine/wiDepthTarget.h b/WickedEngine/wiDepthTarget.h index 441401967..fc4d8be08 100644 --- a/WickedEngine/wiDepthTarget.h +++ b/WickedEngine/wiDepthTarget.h @@ -4,12 +4,17 @@ class wiDepthTarget { +private: + Texture2D* texture; + TextureCube* textureCube; + bool isCube; public: - Texture2D texture2D; - DepthStencilView depthTarget; - TextureView shaderResource; + //Texture2D texture2D; + //DepthStencilView depthTarget; + //Texture2D* shaderResource; + + //ShaderResourceViewDesc shaderResourceViewDesc; - ShaderResourceViewDesc shaderResourceViewDesc; wiDepthTarget(); ~wiDepthTarget(); @@ -18,5 +23,7 @@ public: void InitializeCube(int size); void Clear(GRAPHICSTHREAD threadID); void CopyFrom(const wiDepthTarget&, GRAPHICSTHREAD threadID); + + Texture2D* GetTexture() const { return(isCube ? textureCube : texture); } }; diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp index f6366aadc..b9ee1be86 100644 --- a/WickedEngine/wiFont.cpp +++ b/WickedEngine/wiFont.cpp @@ -362,7 +362,7 @@ wiFont::wiFontStyle::wiFontStyle(const string& newName){ ss1<<"fonts/"<add(ss1.str()); + texture = (Texture2D*)wiResourceManager::GetGlobal()->add(ss1.str()); file>>texWidth>>texHeight>>recSize>>charSize; int i=0; while(!file.eof()){ @@ -381,7 +381,7 @@ wiFont::wiFontStyle::wiFontStyle(const string& newName){ wiRenderer::graphicsDevice->UNLOCK(); } void wiFont::wiFontStyle::CleanUp(){ - SAFE_RELEASE(texture); + SAFE_DELETE(texture); } void wiFont::addFontStyle( const string& toAdd ){ for (auto& x : fontStyles) diff --git a/WickedEngine/wiFont.h b/WickedEngine/wiFont.h index 2cf76436a..7a36b11e9 100644 --- a/WickedEngine/wiFont.h +++ b/WickedEngine/wiFont.h @@ -76,7 +76,7 @@ private: struct wiFontStyle{ string name; - ID3D11ShaderResourceView *texture; + Texture2D* texture; struct LookUp{ int code; diff --git a/WickedEngine/wiGraphicsAPI.h b/WickedEngine/wiGraphicsAPI.h index 8888e3bf1..363bd376b 100644 --- a/WickedEngine/wiGraphicsAPI.h +++ b/WickedEngine/wiGraphicsAPI.h @@ -19,8 +19,8 @@ typedef ID3D11DeviceContext* DeviceContext; //typedef ID3D11Device* GraphicsDevice; typedef ID3D11CommandList* CommandList; typedef ID3D11RenderTargetView* RenderTargetView; -typedef ID3D11ShaderResourceView* TextureView; -typedef ID3D11Texture2D* Texture2D; +typedef ID3D11ShaderResourceView* ShaderResourceView; +typedef ID3D11Texture2D* APITexture2D; typedef ID3D11SamplerState* Sampler; typedef ID3D11Resource* APIResource; typedef ID3D11Buffer* BufferResource; @@ -164,21 +164,6 @@ enum TEXTURE_ADDRESS_MODE 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, @@ -284,25 +269,6 @@ struct Texture2DDesc 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; @@ -390,17 +356,51 @@ struct VertexShaderInfo { } }; +class Texture +{ +public: + ShaderResourceView shaderResourceView; + RenderTargetView renderTargetView; + DepthStencilView depthStencilView; + + Texture() :shaderResourceView(nullptr), renderTargetView(nullptr), depthStencilView(nullptr) {} + virtual ~Texture() + { + SAFE_RELEASE(shaderResourceView); + SAFE_RELEASE(renderTargetView); + SAFE_RELEASE(depthStencilView); + } +}; +class Texture2D : public Texture +{ +public: + APITexture2D texture2D; + Texture2DDesc desc; + + Texture2D() :Texture(), texture2D(nullptr) {} + virtual ~Texture2D() + { + SAFE_RELEASE(texture2D); + } +}; +class TextureCube : public Texture2D +{ +public: + TextureCube():Texture2D() {} + virtual ~TextureCube(){} +}; + 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 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 CreateTextureCube(const Texture2DDesc* pDesc, const SubresourceData *pInitialData, TextureCube **ppTextureCube) = 0; + virtual HRESULT CreateShaderResourceView(Texture2D* pTexture) = 0; + virtual HRESULT CreateRenderTargetView(Texture2D* pTexture) = 0; + virtual HRESULT CreateDepthStencilView(Texture2D* pTexture) = 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; @@ -411,26 +411,10 @@ public: 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; @@ -439,7 +423,6 @@ public: 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; @@ -447,19 +430,14 @@ public: ///////////////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 BindRenderTargets(UINT NumViews, Texture2D* const *ppRenderTargetViews, Texture2D* depthStencilTexture, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void ClearRenderTarget(Texture2D* pTexture, const FLOAT ColorRGBA[4], GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void ClearDepthStencil(Texture2D* pTexture, UINT ClearFlags, FLOAT Depth, UINT8 Stencil, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindTexturePS(const Texture* texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindTextureVS(const Texture* texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindTextureGS(const Texture* texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindTextureDS(const Texture* texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void BindTextureHS(const Texture* texture, int slot, 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; @@ -494,11 +472,12 @@ public: 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 GenerateMips(Texture* texture, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void CopyResource(APIResource pDstResource, const APIResource pSrcResource, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; + virtual void CopyTexture2D(Texture2D* pDst, const Texture2D* pSrc, 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; + virtual HRESULT CreateTextureFromFile(const wstring& fileName, Texture2D **ppTexture, bool mipMaps = true, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) = 0; }; diff --git a/WickedEngine/wiGraphicsAPI_DX11.cpp b/WickedEngine/wiGraphicsAPI_DX11.cpp index b20636185..1714584f2 100644 --- a/WickedEngine/wiGraphicsAPI_DX11.cpp +++ b/WickedEngine/wiGraphicsAPI_DX11.cpp @@ -12,7 +12,7 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(HWND window, int screenW, int screenH, UINT createDeviceFlags = 0; #ifdef _DEBUG - createDeviceFlags |= CREATE_DEVICE_DEBUG; + createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; #endif D3D_DRIVER_TYPE driverTypes[] = @@ -114,33 +114,23 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(HWND window, int screenW, int screenH, for (int i = 0; iCreateDeferredContext(0, &deviceContexts[i]); } -#ifdef BACKLOG - stringstream ss(""); - ss << NUM_DCONTEXT << " defferred contexts created!"; - wiBackLog::post(ss.str().c_str()); -#endif } else { - //MessageBox(window,L"Deferred Context not supported!",L"Error!",0); -#ifdef BACKLOG - wiBackLog::post("Deferred context not supported!"); -#endif DEFERREDCONTEXT_SUPPORT = false; - //exit(0); } // Create a render target view - Texture2D pBackBuffer = NULL; + APITexture2D pBackBuffer = NULL; hr = swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); if (FAILED(hr)) { wiHelper::messageBox("BackBuffer creation Failed!", "Error!", nullptr); exit(0); } - hr = CreateRenderTargetView(pBackBuffer, NULL, &renderTargetView); + hr = device->CreateRenderTargetView(pBackBuffer, NULL, &renderTargetView); //pBackBuffer->Release(); if (FAILED(hr)) { wiHelper::messageBox("Main Rendertarget creation Failed!", "Error!", nullptr); @@ -170,93 +160,402 @@ GraphicsDevice_DX11::~GraphicsDevice_DX11() } +// TODO! +inline D3D11_FILTER _ConvertFilter(FILTER value) +{ + return (D3D11_FILTER)value; +} +inline D3D11_TEXTURE_ADDRESS_MODE _ConvertTextureAddressMode(TEXTURE_ADDRESS_MODE value) +{ + return (D3D11_TEXTURE_ADDRESS_MODE)value; +} +inline D3D11_COMPARISON_FUNC _ConvertComparisonFunc(COMPARISON_FUNC value) +{ + return (D3D11_COMPARISON_FUNC)value; +} +inline D3D11_FILL_MODE _ConvertFillMode(FILL_MODE value) +{ + return (D3D11_FILL_MODE)value; +} +inline D3D11_CULL_MODE _ConvertCullMode(CULL_MODE value) +{ + return (D3D11_CULL_MODE)value; +} +inline D3D11_DEPTH_WRITE_MASK _ConvertDepthWriteMask(DEPTH_WRITE_MASK value) +{ + return (D3D11_DEPTH_WRITE_MASK)value; +} +inline D3D11_STENCIL_OP _ConvertStencilOp(STENCIL_OP value) +{ + return (D3D11_STENCIL_OP)value; +} +inline D3D11_BLEND _ConvertBlend(BLEND value) +{ + return (D3D11_BLEND)value; +} +inline D3D11_BLEND_OP _ConvertBlendOp(BLEND_OP value) +{ + return (D3D11_BLEND_OP)value; +} +inline D3D11_USAGE _ConvertUsage(USAGE value) +{ + return (D3D11_USAGE)value; +} +inline D3D11_INPUT_CLASSIFICATION _ConvertInputClassification(INPUT_CLASSIFICATION value) +{ + return (D3D11_INPUT_CLASSIFICATION)value; +} +inline DXGI_FORMAT _ConvertFormat(DXGI_FORMAT value) +{ + return value; +} +inline DXGI_SAMPLE_DESC _ConvertSampleDesc(DXGI_SAMPLE_DESC value) +{ + return value; +} + +inline D3D11_TEXTURE2D_DESC _ConvertTexture2DDesc(const Texture2DDesc* pDesc) +{ + D3D11_TEXTURE2D_DESC desc; + desc.Width = pDesc->Width; + desc.Height = pDesc->Height; + desc.MipLevels = pDesc->MipLevels; + desc.ArraySize = pDesc->ArraySize; + desc.Format = _ConvertFormat(pDesc->Format); + desc.SampleDesc = _ConvertSampleDesc(pDesc->SampleDesc); + desc.Usage = _ConvertUsage(pDesc->Usage); + desc.BindFlags = pDesc->BindFlags; + desc.CPUAccessFlags = pDesc->CPUAccessFlags; + desc.MiscFlags = pDesc->MiscFlags; + + return desc; +} +inline D3D11_SUBRESOURCE_DATA* _ConvertSubresourceData(const SubresourceData* pInitialData) +{ + if (pInitialData == nullptr) + return nullptr; + + D3D11_SUBRESOURCE_DATA* data = new D3D11_SUBRESOURCE_DATA; + data->pSysMem = pInitialData->pSysMem; + data->SysMemPitch = pInitialData->SysMemPitch; + data->SysMemSlicePitch = pInitialData->SysMemSlicePitch; + + return data; +} + + HRESULT GraphicsDevice_DX11::CreateBuffer(const BufferDesc *pDesc, const SubresourceData* pInitialData, BufferResource *ppBuffer) { + D3D11_BUFFER_DESC desc; + desc.ByteWidth = pDesc->ByteWidth; + desc.Usage = _ConvertUsage(pDesc->Usage); + desc.BindFlags = pDesc->BindFlags; + desc.CPUAccessFlags = pDesc->CPUAccessFlags; + desc.MiscFlags = pDesc->MiscFlags; + desc.StructureByteStride = pDesc->StructureByteStride; + + D3D11_SUBRESOURCE_DATA* data = _ConvertSubresourceData(pInitialData); + + return device->CreateBuffer(&desc, data, ppBuffer); +} +HRESULT GraphicsDevice_DX11::CreateTexture1D() +{ + // TODO return E_FAIL; } -HRESULT GraphicsDevice_DX11::CreateTexture2D(const Texture2DDesc* pDesc, const SubresourceData *pInitialData, Texture2D *ppTexture2D) +HRESULT GraphicsDevice_DX11::CreateTexture2D(const Texture2DDesc* pDesc, const SubresourceData *pInitialData, Texture2D **ppTexture2D) { + D3D11_TEXTURE2D_DESC desc = _ConvertTexture2DDesc(pDesc); + + D3D11_SUBRESOURCE_DATA* data = _ConvertSubresourceData(pInitialData); + + (*ppTexture2D) = new Texture2D; + (*ppTexture2D)->desc = *pDesc; + + HRESULT hr = S_OK; + + hr = device->CreateTexture2D(&desc, data, &((*ppTexture2D)->texture2D)); + if (FAILED(hr)) + return hr; + + hr = CreateRenderTargetView(*ppTexture2D); + if (FAILED(hr)) + return hr; + hr = CreateShaderResourceView(*ppTexture2D); + if (FAILED(hr)) + return hr; + hr = CreateDepthStencilView(*ppTexture2D); + if (FAILED(hr)) + return hr; + + return hr; +} +HRESULT GraphicsDevice_DX11::CreateTexture3D() +{ + // TODO return E_FAIL; } -HRESULT GraphicsDevice_DX11::CreateShaderResourceView(APIResource pResource, const ShaderResourceViewDesc* pDesc, TextureView *ppSRView) +HRESULT GraphicsDevice_DX11::CreateTextureCube(const Texture2DDesc* pDesc, const SubresourceData *pInitialData, TextureCube **ppTextureCube) { - return E_FAIL; + D3D11_TEXTURE2D_DESC desc = _ConvertTexture2DDesc(pDesc); + + D3D11_SUBRESOURCE_DATA* data = _ConvertSubresourceData(pInitialData); + + (*ppTextureCube) = new TextureCube; + (*ppTextureCube)->desc = *pDesc; + + HRESULT hr = S_OK; + + if (!(desc.MiscFlags & RESOURCE_MISC_TEXTURECUBE)) + { + desc.MiscFlags |= RESOURCE_MISC_TEXTURECUBE; + } + + hr = device->CreateTexture2D(&desc, data, &((*ppTextureCube)->texture2D)); + if (FAILED(hr)) + return hr; + + hr = CreateRenderTargetView(*ppTextureCube); + if (FAILED(hr)) + return hr; + hr = CreateShaderResourceView(*ppTextureCube); + if (FAILED(hr)) + return hr; + hr = CreateDepthStencilView(*ppTextureCube); + if (FAILED(hr)) + return hr; + + return hr; } -HRESULT GraphicsDevice_DX11::CreateRenderTargetView(APIResource pResource, const RenderTargetViewDesc* pDesc, RenderTargetView *ppRTView) +HRESULT GraphicsDevice_DX11::CreateShaderResourceView(Texture2D* pTexture) { - return E_FAIL; + HRESULT hr = E_FAIL; + if (pTexture->desc.BindFlags & D3D11_BIND_SHADER_RESOURCE) + { + D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc; + if (pTexture->desc.MiscFlags & RESOURCE_MISC_TEXTURECUBE) + { + shaderResourceViewDesc.Format = pTexture->desc.Format; + shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; + shaderResourceViewDesc.TextureCube.MostDetailedMip = 0; //from most detailed... + shaderResourceViewDesc.TextureCube.MipLevels = -1; //...to least detailed + } + else + { + shaderResourceViewDesc.Format = pTexture->desc.Format; + shaderResourceViewDesc.ViewDimension = (pTexture->desc.SampleDesc.Quality == 0 ? D3D11_SRV_DIMENSION_TEXTURE2D : D3D11_SRV_DIMENSION_TEXTURE2DMS); + shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; //from most detailed... + shaderResourceViewDesc.Texture2D.MipLevels = -1; //...to least detailed + } + + hr = device->CreateShaderResourceView(pTexture->texture2D, &shaderResourceViewDesc, &pTexture->shaderResourceView); + } + return hr; } -HRESULT GraphicsDevice_DX11::CreateDepthStencilView(APIResource pResource, const DepthStencilViewDesc* pDesc, DepthStencilView *ppDepthStencilView) +HRESULT GraphicsDevice_DX11::CreateRenderTargetView(Texture2D* pTexture) { - return E_FAIL; + HRESULT hr = E_FAIL; + if (pTexture->desc.BindFlags & D3D11_BIND_RENDER_TARGET) + { + D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc; + if (pTexture->desc.MiscFlags & RESOURCE_MISC_TEXTURECUBE) + { + renderTargetViewDesc.Format = pTexture->desc.Format; + renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; + renderTargetViewDesc.Texture2DArray.FirstArraySlice = 0; + renderTargetViewDesc.Texture2DArray.ArraySize = 6; + renderTargetViewDesc.Texture2DArray.MipSlice = 0; + } + else + { + renderTargetViewDesc.Format = pTexture->desc.Format; + renderTargetViewDesc.ViewDimension = (pTexture->desc.SampleDesc.Quality == 0 ? D3D11_RTV_DIMENSION_TEXTURE2D : D3D11_RTV_DIMENSION_TEXTURE2DMS); + renderTargetViewDesc.Texture2D.MipSlice = 0; + } + + hr = device->CreateRenderTargetView(pTexture->texture2D, &renderTargetViewDesc, &pTexture->renderTargetView); + } + return hr; +} +HRESULT GraphicsDevice_DX11::CreateDepthStencilView(Texture2D* pTexture) +{ + HRESULT hr = E_FAIL; + if (pTexture->desc.BindFlags & D3D11_BIND_DEPTH_STENCIL) + { + D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc; + if (pTexture->desc.MiscFlags & RESOURCE_MISC_TEXTURECUBE) + { + 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.Flags = 0; + } + else + { + ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc)); + depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; + depthStencilViewDesc.ViewDimension = (pTexture->desc.SampleDesc.Quality == 0 ? D3D11_DSV_DIMENSION_TEXTURE2D : D3D11_DSV_DIMENSION_TEXTURE2DMS); + depthStencilViewDesc.Texture2D.MipSlice = 0; + depthStencilViewDesc.Flags = 0; + } + + hr = device->CreateDepthStencilView(pTexture->texture2D, &depthStencilViewDesc, &pTexture->depthStencilView); + } + return hr; } HRESULT GraphicsDevice_DX11::CreateInputLayout(const VertexLayoutDesc *pInputElementDescs, UINT NumElements, const void *pShaderBytecodeWithInputSignature, SIZE_T BytecodeLength, VertexLayout *ppInputLayout) { + D3D11_INPUT_ELEMENT_DESC* desc = new D3D11_INPUT_ELEMENT_DESC[NumElements]; + for (UINT i = 0; i < NumElements; ++i) + { + desc[i].SemanticName = pInputElementDescs[i].SemanticName; + desc[i].SemanticIndex = pInputElementDescs[i].SemanticIndex; + desc[i].Format = _ConvertFormat(pInputElementDescs[i].Format); + desc[i].InputSlot = pInputElementDescs[i].InputSlot; + desc[i].AlignedByteOffset = pInputElementDescs[i].AlignedByteOffset; + desc[i].InputSlotClass = _ConvertInputClassification(pInputElementDescs[i].InputSlotClass); + desc[i].InstanceDataStepRate = pInputElementDescs[i].InstanceDataStepRate; + } + HRESULT hr = device->CreateInputLayout(desc, NumElements, pShaderBytecodeWithInputSignature, BytecodeLength, ppInputLayout); + + SAFE_DELETE_ARRAY(desc); + + return hr; } HRESULT GraphicsDevice_DX11::CreateVertexShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, VertexShader *ppVertexShader) { - return E_FAIL; + return device->CreateVertexShader(pShaderBytecode, BytecodeLength, pClassLinkage, ppVertexShader); } HRESULT GraphicsDevice_DX11::CreatePixelShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, PixelShader *ppPixelShader) { - return E_FAIL; + return device->CreatePixelShader(pShaderBytecode, BytecodeLength, pClassLinkage, ppPixelShader); } HRESULT GraphicsDevice_DX11::CreateGeometryShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, GeometryShader *ppGeometryShader) { - return E_FAIL; + return device->CreateGeometryShader(pShaderBytecode, BytecodeLength, pClassLinkage, ppGeometryShader); } HRESULT GraphicsDevice_DX11::CreateGeometryShaderWithStreamOutput(const void *pShaderBytecode, SIZE_T BytecodeLength, const StreamOutDeclaration *pSODeclaration, UINT NumEntries, const UINT *pBufferStrides, UINT NumStrides, UINT RasterizedStream, ClassLinkage pClassLinkage, GeometryShader *ppGeometryShader) { - return E_FAIL; + D3D11_SO_DECLARATION_ENTRY* decl = new D3D11_SO_DECLARATION_ENTRY[NumEntries]; + for (UINT i = 0; i < NumEntries; ++i) + { + decl[i].Stream = pSODeclaration[i].Stream; + decl[i].SemanticName = pSODeclaration[i].SemanticName; + decl[i].SemanticIndex = pSODeclaration[i].SemanticIndex; + decl[i].StartComponent = pSODeclaration[i].StartComponent; + decl[i].ComponentCount = pSODeclaration[i].ComponentCount; + decl[i].OutputSlot = pSODeclaration[i].OutputSlot; + } + + HRESULT hr = device->CreateGeometryShaderWithStreamOutput(pShaderBytecode, BytecodeLength, decl, NumEntries, pBufferStrides, + NumStrides, RasterizedStream, pClassLinkage, ppGeometryShader); + + SAFE_DELETE_ARRAY(decl); + + return hr; } HRESULT GraphicsDevice_DX11::CreateHullShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, HullShader *ppHullShader) { - return E_FAIL; + return device->CreateHullShader(pShaderBytecode, BytecodeLength, pClassLinkage, ppHullShader); } HRESULT GraphicsDevice_DX11::CreateDomainShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, DomainShader *ppDomainShader) { - return E_FAIL; + return device->CreateDomainShader(pShaderBytecode, BytecodeLength, pClassLinkage, ppDomainShader); } HRESULT GraphicsDevice_DX11::CreateComputeShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ClassLinkage pClassLinkage, ComputeShader *ppComputeShader) { - return E_FAIL; + return device->CreateComputeShader(pShaderBytecode, BytecodeLength, pClassLinkage, ppComputeShader); } HRESULT GraphicsDevice_DX11::CreateBlendState(const BlendDesc *pBlendStateDesc, BlendState *ppBlendState) { - return E_FAIL; + D3D11_BLEND_DESC desc; + desc.AlphaToCoverageEnable = pBlendStateDesc->AlphaToCoverageEnable; + desc.IndependentBlendEnable = pBlendStateDesc->IndependentBlendEnable; + for (int i = 0; i < 8; ++i) + { + desc.RenderTarget[i].BlendEnable = pBlendStateDesc->RenderTarget[i].BlendEnable; + desc.RenderTarget[i].SrcBlend = _ConvertBlend(pBlendStateDesc->RenderTarget[i].SrcBlend); + desc.RenderTarget[i].DestBlend = _ConvertBlend(pBlendStateDesc->RenderTarget[i].DestBlend); + desc.RenderTarget[i].BlendOp = _ConvertBlendOp(pBlendStateDesc->RenderTarget[i].BlendOp); + desc.RenderTarget[i].SrcBlendAlpha = _ConvertBlend(pBlendStateDesc->RenderTarget[i].SrcBlendAlpha); + desc.RenderTarget[i].DestBlendAlpha = _ConvertBlend(pBlendStateDesc->RenderTarget[i].DestBlendAlpha); + desc.RenderTarget[i].BlendOpAlpha = _ConvertBlendOp(pBlendStateDesc->RenderTarget[i].BlendOpAlpha); + desc.RenderTarget[i].RenderTargetWriteMask = pBlendStateDesc->RenderTarget[i].RenderTargetWriteMask; + } + + return device->CreateBlendState(&desc, ppBlendState); } HRESULT GraphicsDevice_DX11::CreateDepthStencilState(const DepthStencilDesc *pDepthStencilDesc, DepthStencilState *ppDepthStencilState) { - return E_FAIL; + D3D11_DEPTH_STENCIL_DESC desc; + desc.DepthEnable = pDepthStencilDesc->DepthEnable; + desc.DepthWriteMask = _ConvertDepthWriteMask(pDepthStencilDesc->DepthWriteMask); + desc.DepthFunc = _ConvertComparisonFunc(pDepthStencilDesc->DepthFunc); + desc.StencilEnable = pDepthStencilDesc->StencilEnable; + desc.StencilReadMask = pDepthStencilDesc->StencilReadMask; + desc.StencilWriteMask = pDepthStencilDesc->StencilWriteMask; + desc.FrontFace.StencilDepthFailOp = _ConvertStencilOp(pDepthStencilDesc->FrontFace.StencilDepthFailOp); + desc.FrontFace.StencilFailOp = _ConvertStencilOp(pDepthStencilDesc->FrontFace.StencilFailOp); + desc.FrontFace.StencilFunc = _ConvertComparisonFunc(pDepthStencilDesc->FrontFace.StencilFunc); + desc.FrontFace.StencilPassOp = _ConvertStencilOp(pDepthStencilDesc->FrontFace.StencilPassOp); + desc.BackFace.StencilDepthFailOp = _ConvertStencilOp(pDepthStencilDesc->BackFace.StencilDepthFailOp); + desc.BackFace.StencilFailOp = _ConvertStencilOp(pDepthStencilDesc->BackFace.StencilFailOp); + desc.BackFace.StencilFunc = _ConvertComparisonFunc(pDepthStencilDesc->BackFace.StencilFunc); + desc.BackFace.StencilPassOp = _ConvertStencilOp(pDepthStencilDesc->BackFace.StencilPassOp); + + return device->CreateDepthStencilState(&desc, ppDepthStencilState); } HRESULT GraphicsDevice_DX11::CreateRasterizerState(const RasterizerDesc *pRasterizerDesc, RasterizerState *ppRasterizerState) { - return E_FAIL; + D3D11_RASTERIZER_DESC desc; + desc.FillMode = _ConvertFillMode(pRasterizerDesc->FillMode); + desc.CullMode = _ConvertCullMode(pRasterizerDesc->CullMode); + desc.FrontCounterClockwise = pRasterizerDesc->FrontCounterClockwise; + desc.DepthBias = pRasterizerDesc->DepthBias; + desc.DepthBiasClamp = pRasterizerDesc->DepthBiasClamp; + desc.SlopeScaledDepthBias = pRasterizerDesc->SlopeScaledDepthBias; + desc.DepthClipEnable = pRasterizerDesc->DepthClipEnable; + desc.ScissorEnable = pRasterizerDesc->ScissorEnable; + desc.MultisampleEnable = pRasterizerDesc->MultisampleEnable; + desc.AntialiasedLineEnable = pRasterizerDesc->AntialiasedLineEnable; + + return device->CreateRasterizerState(&desc, ppRasterizerState); } HRESULT GraphicsDevice_DX11::CreateSamplerState(const SamplerDesc *pSamplerDesc, Sampler *ppSamplerState) { - return E_FAIL; -} -HRESULT GraphicsDevice_DX11::CreateDeferredContext(UINT ContextFlags, DeviceContext *ppDeferredContext) -{ - return E_FAIL; -} -DeviceContext GraphicsDevice_DX11::GetImmediateContext() -{ - return deviceContexts[GRAPHICSTHREAD_IMMEDIATE]; + D3D11_SAMPLER_DESC desc; + desc.Filter = _ConvertFilter(pSamplerDesc->Filter); + desc.AddressU = _ConvertTextureAddressMode(pSamplerDesc->AddressU); + desc.AddressV = _ConvertTextureAddressMode(pSamplerDesc->AddressV); + desc.AddressW = _ConvertTextureAddressMode(pSamplerDesc->AddressW); + desc.MipLODBias = pSamplerDesc->MipLODBias; + desc.MaxAnisotropy = pSamplerDesc->MaxAnisotropy; + desc.ComparisonFunc = _ConvertComparisonFunc(pSamplerDesc->ComparisonFunc); + desc.BorderColor[0] = pSamplerDesc->BorderColor[0]; + desc.BorderColor[1] = pSamplerDesc->BorderColor[1]; + desc.BorderColor[2] = pSamplerDesc->BorderColor[2]; + desc.BorderColor[3] = pSamplerDesc->BorderColor[3]; + desc.MinLOD = pSamplerDesc->MinLOD; + desc.MaxLOD = pSamplerDesc->MaxLOD; + + return device->CreateSamplerState(&desc, ppSamplerState); } + void GraphicsDevice_DX11::PresentBegin() { LOCK(); BindViewports(1, &viewPort); - GetImmediateContext()->OMSetRenderTargets(1, &renderTargetView, 0); + deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->OMSetRenderTargets(1, &renderTargetView, 0); float ClearColor[4] = { 0, 0, 0, 1.0f }; // red,green,blue,alpha - GetImmediateContext()->ClearRenderTargetView(renderTargetView, ClearColor); + deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->ClearRenderTargetView(renderTargetView, ClearColor); } void GraphicsDevice_DX11::PresentEnd() @@ -264,7 +563,7 @@ void GraphicsDevice_DX11::PresentEnd() swapChain->Present(VSYNC, 0); - GetImmediateContext()->OMSetRenderTargets(0, nullptr, nullptr); + deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->OMSetRenderTargets(0, nullptr, nullptr); UnbindTextures(0, TEXSLOT_COUNT, GRAPHICSTHREAD_IMMEDIATE); @@ -277,7 +576,7 @@ void GraphicsDevice_DX11::ExecuteDeferredContexts() { if (i != (GRAPHICSTHREAD)GRAPHICSTHREAD_IMMEDIATE &&commandLists[i]) { - GetImmediateContext()->ExecuteCommandList(commandLists[i], true); + deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->ExecuteCommandList(commandLists[i], true); commandLists[i]->Release(); commandLists[i] = nullptr; @@ -293,21 +592,28 @@ void GraphicsDevice_DX11::FinishCommandList(GRAPHICSTHREAD thread) } - -HRESULT GraphicsDevice_DX11::CreateTextureFromFile(const wstring& fileName, TextureView *ppShaderResourceView, bool mipMaps, GRAPHICSTHREAD threadID) +HRESULT GraphicsDevice_DX11::CreateTextureFromFile(const wstring& fileName, Texture2D **ppTexture, bool mipMaps, GRAPHICSTHREAD threadID) { + HRESULT hr = E_FAIL; + (*ppTexture) = new Texture2D(); + if (!fileName.substr(fileName.length() - 4).compare(wstring(L".dds"))) { // Load dds - CreateDDSTextureFromFile(device, fileName.c_str(), nullptr, ppShaderResourceView); + hr = CreateDDSTextureFromFile(device, fileName.c_str(), nullptr, &(*ppTexture)->shaderResourceView); } else { // Load WIC if (mipMaps && threadID == GRAPHICSTHREAD_IMMEDIATE) LOCK(); - CreateWICTextureFromFile(mipMaps, device, deviceContexts[threadID], fileName.c_str(), nullptr, ppShaderResourceView); + hr = CreateWICTextureFromFile(mipMaps, device, deviceContexts[threadID], fileName.c_str(), nullptr, &(*ppTexture)->shaderResourceView); if (mipMaps && threadID == GRAPHICSTHREAD_IMMEDIATE) UNLOCK(); } + + if (FAILED(hr)) + SAFE_DELETE(*ppTexture); + + return hr; } diff --git a/WickedEngine/wiGraphicsAPI_DX11.h b/WickedEngine/wiGraphicsAPI_DX11.h index 7a834b83c..b78408b63 100644 --- a/WickedEngine/wiGraphicsAPI_DX11.h +++ b/WickedEngine/wiGraphicsAPI_DX11.h @@ -20,12 +20,12 @@ public: 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 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 CreateTextureCube(const Texture2DDesc* pDesc, const SubresourceData *pInitialData, TextureCube **ppTextureCube); + virtual HRESULT CreateShaderResourceView(Texture2D* pTexture); + virtual HRESULT CreateRenderTargetView(Texture2D* pTexture); + virtual HRESULT CreateDepthStencilView(Texture2D* pTexture); 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); @@ -36,26 +36,10 @@ public: 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(); @@ -63,8 +47,7 @@ public: virtual void ExecuteDeferredContexts(); virtual void FinishCommandList(GRAPHICSTHREAD thread); - virtual bool GetMultithreadingSupport(); - virtual DeviceContext GetDeferredContext(GRAPHICSTHREAD thread); + virtual bool GetMultithreadingSupport() { return DEFERREDCONTEXT_SUPPORT; } virtual bool GetVSyncEnabled() { return VSYNC; } virtual void SetVSyncEnabled(bool value) { VSYNC = value; } @@ -87,69 +70,50 @@ public: SAFE_DELETE_ARRAY(pd3dViewPorts); } } - virtual void BindRenderTargets(UINT NumViews, RenderTargetView const *ppRenderTargetViews, DepthStencilView pDepthStencilView, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + virtual void BindRenderTargets(UINT NumViews, Texture2D* const *ppRenderTargetViews, Texture2D* depthStencilTexture, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { if (deviceContexts[threadID] != nullptr) { - deviceContexts[threadID]->OMSetRenderTargets(NumViews, ppRenderTargetViews, pDepthStencilView); + static thread_local RenderTargetView renderTargetViews[8]; + for (UINT i = 0; i < min(NumViews, 8); ++i) + { + renderTargetViews[i] = ppRenderTargetViews[i]->renderTargetView; + } + deviceContexts[threadID]->OMSetRenderTargets(NumViews, renderTargetViews, + (depthStencilTexture == nullptr ? nullptr : depthStencilTexture->depthStencilView)); } } - virtual void ClearRenderTarget(RenderTargetView pRenderTargetView, const FLOAT ColorRGBA[4], GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { - if (deviceContexts[threadID] != nullptr) { - deviceContexts[threadID]->ClearRenderTargetView(pRenderTargetView, ColorRGBA); + virtual void ClearRenderTarget(Texture2D* pTexture, const FLOAT ColorRGBA[4], GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && pTexture != nullptr && pTexture->renderTargetView != nullptr) { + deviceContexts[threadID]->ClearRenderTargetView(pTexture->renderTargetView, 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 ClearDepthStencil(Texture2D* pTexture, UINT ClearFlags, FLOAT Depth, UINT8 Stencil, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr && pTexture != nullptr && pTexture->depthStencilView != nullptr) { + deviceContexts[threadID]->ClearDepthStencilView(pTexture->depthStencilView, ClearFlags, Depth, Stencil); } } - virtual void BindTexturePS(TextureView texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + virtual void BindTexturePS(const Texture* texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { if (deviceContexts[threadID] != nullptr && texture != nullptr) { - deviceContexts[threadID]->PSSetShaderResources(slot, 1, &texture); + deviceContexts[threadID]->PSSetShaderResources(slot, 1, &texture->shaderResourceView); } } - 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) { + virtual void BindTextureVS(const Texture* texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { if (deviceContexts[threadID] != nullptr && texture != nullptr) { - deviceContexts[threadID]->VSSetShaderResources(slot, 1, &texture); + deviceContexts[threadID]->VSSetShaderResources(slot, 1, &texture->shaderResourceView); } } - 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) { + virtual void BindTextureGS(const Texture* texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { if (deviceContexts[threadID] != nullptr && texture != nullptr) { - deviceContexts[threadID]->GSSetShaderResources(slot, 1, &texture); + deviceContexts[threadID]->GSSetShaderResources(slot, 1, &texture->shaderResourceView); } } - 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) { + virtual void BindTextureDS(const Texture* texture, int slot, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { if (deviceContexts[threadID] != nullptr && texture != nullptr) { - deviceContexts[threadID]->DSSetShaderResources(slot, 1, &texture); + deviceContexts[threadID]->DSSetShaderResources(slot, 1, &texture->shaderResourceView); } } - 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) { + virtual void BindTextureHS(const Texture* 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); + deviceContexts[threadID]->HSSetShaderResources(slot, 1, &texture->shaderResourceView); } } virtual void UnbindTextures(int slot, int num, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) @@ -157,7 +121,7 @@ public: assert(num <= 32 && "UnbindTextures limit of 32 reached!"); if (deviceContexts[threadID] != nullptr) { - static TextureView empties[32] = { + static ID3D11ShaderResourceView* 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, @@ -358,15 +322,22 @@ public: deviceContexts[threadID]->DrawIndexedInstanced(indexCount, instanceCount, 0, 0, 0); } } - virtual void GenerateMips(TextureView texture, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) + virtual void GenerateMips(Texture* texture, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { - deviceContexts[threadID]->GenerateMips(texture); + deviceContexts[threadID]->GenerateMips(texture->shaderResourceView); } - virtual void CopyResource(APIResource pDstResource, APIResource pSrcResource, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + virtual void CopyResource(APIResource pDstResource, const APIResource pSrcResource, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { if (deviceContexts[threadID] != nullptr) { deviceContexts[threadID]->CopyResource(pDstResource, pSrcResource); } } + virtual void CopyTexture2D(Texture2D* pDst, const Texture2D* pSrc, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE) { + if (deviceContexts[threadID] != nullptr) { + SAFE_RELEASE(pDst->shaderResourceView); + deviceContexts[threadID]->CopyResource(pDst->texture2D, pSrc->texture2D); + CreateShaderResourceView(pDst); + } + } virtual void UpdateBuffer(BufferResource& buffer, const void* data, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE, int dataSize = -1) { if (buffer != nullptr && data != nullptr && deviceContexts[threadID] != nullptr) { @@ -379,7 +350,7 @@ public: BufferDesc desc; desc.ByteWidth = d3dDesc.ByteWidth; - switch (desc.Usage) + switch (d3dDesc.Usage) { case D3D11_USAGE_DEFAULT: desc.Usage = USAGE_DEFAULT; @@ -415,7 +386,6 @@ public: } } - - virtual HRESULT CreateTextureFromFile(const wstring& fileName, TextureView *ppShaderResourceView, bool mipMaps = true, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); + virtual HRESULT CreateTextureFromFile(const wstring& fileName, Texture2D **ppTexture, bool mipMaps = true, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); }; diff --git a/WickedEngine/wiHairParticle.cpp b/WickedEngine/wiHairParticle.cpp index 009fd583f..c4fe2614b 100644 --- a/WickedEngine/wiHairParticle.cpp +++ b/WickedEngine/wiHairParticle.cpp @@ -387,7 +387,7 @@ void wiHairParticle::Draw(Camera* camera, GRAPHICSTHREAD threadID) if(!culledPatches.empty()) { - TextureView texture = material->texture; + Texture2D* texture = material->texture; wiRenderer::graphicsDevice->BindPrimitiveTopology(PRIMITIVETOPOLOGY::POINTLIST,threadID); wiRenderer::graphicsDevice->BindVertexLayout(il,threadID); diff --git a/WickedEngine/wiImage.cpp b/WickedEngine/wiImage.cpp index 9cad2084a..2472c4a18 100644 --- a/WickedEngine/wiImage.cpp +++ b/WickedEngine/wiImage.cpp @@ -193,13 +193,13 @@ void wiImage::BindPersistentState(GRAPHICSTHREAD threadID) wiRenderer::graphicsDevice->BindConstantBufferPS(processCb, CB_GETBINDSLOT(PostProcessCB), threadID); - wiRenderer::graphicsDevice->LOCK(); + wiRenderer::graphicsDevice->UNLOCK(); } -void wiImage::Draw(TextureView texture, const wiImageEffects& effects){ +void wiImage::Draw(Texture2D* texture, const wiImageEffects& effects){ Draw(texture,effects,GRAPHICSTHREAD_IMMEDIATE); } -void wiImage::Draw(TextureView texture, const wiImageEffects& effects,GRAPHICSTHREAD threadID) +void wiImage::Draw(Texture2D* texture, const wiImageEffects& effects,GRAPHICSTHREAD threadID) { bool fullScreenEffect = false; @@ -426,9 +426,9 @@ void wiImage::Draw(TextureView texture, const wiImageEffects& effects,GRAPHICSTH wiRenderer::graphicsDevice->Draw((fullScreenEffect ? 3 : 4), threadID); } -void wiImage::DrawDeferred(TextureView texture - , TextureView depth, TextureView lightmap, TextureView normal - , TextureView ao, GRAPHICSTHREAD threadID, int stencilRef){ +void wiImage::DrawDeferred(Texture2D* texture + , Texture2D* depth, Texture2D* lightmap, Texture2D* normal + , Texture2D* ao, GRAPHICSTHREAD threadID, int stencilRef){ wiRenderer::graphicsDevice->BindPrimitiveTopology(PRIMITIVETOPOLOGY::TRIANGLELIST,threadID); wiRenderer::graphicsDevice->BindRasterizerState(rasterizerState,threadID); diff --git a/WickedEngine/wiImage.h b/WickedEngine/wiImage.h index 4065fbfca..389c493d8 100644 --- a/WickedEngine/wiImage.h +++ b/WickedEngine/wiImage.h @@ -65,12 +65,12 @@ private: public: wiImage(); - static void Draw(TextureView texture, const wiImageEffects& effects); - static void Draw(TextureView texture, const wiImageEffects& effects,GRAPHICSTHREAD threadID); + static void Draw(Texture2D* texture, const wiImageEffects& effects); + static void Draw(Texture2D* texture, const wiImageEffects& effects,GRAPHICSTHREAD threadID); - static void DrawDeferred(TextureView texture - , TextureView depth, TextureView lightmap, TextureView normal - , TextureView ao, GRAPHICSTHREAD threadID, int stencilref = 0); + static void DrawDeferred(Texture2D* texture + , Texture2D* depth, Texture2D* lightmap, Texture2D* normal + , Texture2D* ao, GRAPHICSTHREAD threadID, int stencilref = 0); static void Load(); static void CleanUp(); diff --git a/WickedEngine/wiImageEffects.h b/WickedEngine/wiImageEffects.h index c55133de5..51649a2b1 100644 --- a/WickedEngine/wiImageEffects.h +++ b/WickedEngine/wiImageEffects.h @@ -94,13 +94,13 @@ public: }; Processing process; bool deferred; - TextureView maskMap, distortionMap, refractionSource; + Texture2D* maskMap, *distortionMap, *refractionSource; // Generic texture - void setMaskMap(TextureView view) { maskMap = view; } + void setMaskMap(Texture2D* view) { maskMap = view; } // The normalmap texture which should distort the refraction source - void setDistortionMap(TextureView view) { distortionMap = view; } + void setDistortionMap(Texture2D* view) { distortionMap = view; } // The texture which should be distorted - void setRefractionSource(TextureView view) { refractionSource = view; } + void setRefractionSource(Texture2D* view) { refractionSource = view; } void init() { pos = XMFLOAT3(0, 0, 0); diff --git a/WickedEngine/wiLensFlare.cpp b/WickedEngine/wiLensFlare.cpp index 8de72cc1a..e230b1080 100644 --- a/WickedEngine/wiLensFlare.cpp +++ b/WickedEngine/wiLensFlare.cpp @@ -30,7 +30,7 @@ void wiLensFlare::CleanUp(){ if(blendState) blendState->Release(); blendState = NULL; if(depthStencilState) depthStencilState->Release(); depthStencilState = NULL; } -void wiLensFlare::Draw(GRAPHICSTHREAD threadID, const XMVECTOR& lightPos, vector& rims){ +void wiLensFlare::Draw(GRAPHICSTHREAD threadID, const XMVECTOR& lightPos, vector& rims){ if(!rims.empty()){ @@ -55,7 +55,7 @@ void wiLensFlare::Draw(GRAPHICSTHREAD threadID, const XMVECTOR& lightPos, vector //wiRenderer::graphicsDevice->BindTextureGS(depthMap,0,threadID); int i=0; - for(TextureView x : rims){ + for(Texture2D* x : rims){ if(x!=nullptr){ wiRenderer::graphicsDevice->BindTexturePS(x, TEXSLOT_ONDEMAND0 + i, threadID); wiRenderer::graphicsDevice->BindTextureGS(x, TEXSLOT_ONDEMAND0 + i, threadID); diff --git a/WickedEngine/wiLensFlare.h b/WickedEngine/wiLensFlare.h index 1bc0df17e..9d0c52d93 100644 --- a/WickedEngine/wiLensFlare.h +++ b/WickedEngine/wiLensFlare.h @@ -33,7 +33,7 @@ private: public: static void Initialize(); static void CleanUp(); - static void Draw(GRAPHICSTHREAD threadID, const XMVECTOR& lightPos, vector& rims); + static void Draw(GRAPHICSTHREAD threadID, const XMVECTOR& lightPos, vector& rims); }; #endif diff --git a/WickedEngine/wiLoader.cpp b/WickedEngine/wiLoader.cpp index 94c7545c5..7eca6f6d2 100644 --- a/WickedEngine/wiLoader.cpp +++ b/WickedEngine/wiLoader.cpp @@ -187,7 +187,7 @@ void LoadWiMaterialLibrary(const string& directory, const string& name, const st stringstream ss(""); ss<refMapName=ss.str(); - currentMat->refMap = (TextureView)wiResourceManager::GetGlobal()->add(ss.str()); + currentMat->refMap = (Texture2D*)wiResourceManager::GetGlobal()->add(ss.str()); } if(currentMat->refMap!=0) currentMat->hasRefMap = true; @@ -199,7 +199,7 @@ void LoadWiMaterialLibrary(const string& directory, const string& name, const st stringstream ss(""); ss<normalMapName=ss.str(); - currentMat->normalMap = (TextureView)wiResourceManager::GetGlobal()->add(ss.str()); + currentMat->normalMap = (Texture2D*)wiResourceManager::GetGlobal()->add(ss.str()); } if(currentMat->normalMap!=0) currentMat->hasNormalMap = true; @@ -211,7 +211,7 @@ void LoadWiMaterialLibrary(const string& directory, const string& name, const st stringstream ss(""); ss<textureName=ss.str(); - currentMat->texture = (TextureView)wiResourceManager::GetGlobal()->add(ss.str()); + currentMat->texture = (Texture2D*)wiResourceManager::GetGlobal()->add(ss.str()); } if(currentMat->texture!=0) currentMat->hasTexture=true; @@ -224,7 +224,7 @@ void LoadWiMaterialLibrary(const string& directory, const string& name, const st stringstream ss(""); ss<displacementMapName=ss.str(); - currentMat->displacementMap = (TextureView)wiResourceManager::GetGlobal()->add(ss.str()); + currentMat->displacementMap = (Texture2D*)wiResourceManager::GetGlobal()->add(ss.str()); } if(currentMat->displacementMap!=0) currentMat->hasDisplacementMap=true; @@ -236,7 +236,7 @@ void LoadWiMaterialLibrary(const string& directory, const string& name, const st stringstream ss(""); ss<specularMapName=ss.str(); - currentMat->specularMap = (TextureView)wiResourceManager::GetGlobal()->add(ss.str()); + currentMat->specularMap = (Texture2D*)wiResourceManager::GetGlobal()->add(ss.str()); } if(currentMat->specularMap!=0) currentMat->hasSpecularMap=true; @@ -932,8 +932,8 @@ void LoadWiLights(const string& directory, const string& name, const string& ide file>>t; stringstream rim(""); rim<add(rim.str())) != nullptr){ + Texture2D* tex=nullptr; + if ((tex = (Texture2D*)wiResourceManager::GetGlobal()->add(rim.str())) != nullptr){ lights.back()->lensFlareRimTextures.push_back(tex); lights.back()->lensFlareNames.push_back(rim.str()); } @@ -2832,13 +2832,13 @@ Decal::~Decal() { void Decal::addTexture(const string& tex){ texName=tex; if(!tex.empty()){ - texture = (TextureView)wiResourceManager::GetGlobal()->add(tex); + texture = (Texture2D*)wiResourceManager::GetGlobal()->add(tex); } } void Decal::addNormal(const string& nor){ norName=nor; if(!nor.empty()){ - normal = (TextureView)wiResourceManager::GetGlobal()->add(nor); + normal = (Texture2D*)wiResourceManager::GetGlobal()->add(nor); } } void Decal::UpdateTransform() diff --git a/WickedEngine/wiLoader.h b/WickedEngine/wiLoader.h index a69ad08f6..3558aa8be 100644 --- a/WickedEngine/wiLoader.h +++ b/WickedEngine/wiLoader.h @@ -99,25 +99,25 @@ struct Material bool hasRefMap; string refMapName; - TextureView refMap; + Texture2D* refMap; bool hasTexture; string textureName; - TextureView texture; + Texture2D* texture; bool premultipliedTexture; BLENDMODE blendFlag; bool hasNormalMap; string normalMapName; - TextureView normalMap; + Texture2D* normalMap; bool hasDisplacementMap; string displacementMapName; - TextureView displacementMap; + Texture2D* displacementMap; bool hasSpecularMap; string specularMapName; - TextureView specularMap; + Texture2D* specularMap; bool subsurface_scattering; bool toonshading; @@ -503,8 +503,8 @@ struct Object : public Streamable, public Transform //RIBBON TRAIL deque trail; BufferResource trailBuff; - TextureView trailDistortTex; - TextureView trailTex; + Texture2D* trailDistortTex; + Texture2D* trailTex; int physicsObjectI; @@ -785,7 +785,7 @@ struct Light : public Cullable , public Transform XMFLOAT4 enerDis; bool noHalo; bool shadow; - vector lensFlareRimTextures; + vector lensFlareRimTextures; vector lensFlareNames; //vector shadowMap; @@ -826,7 +826,7 @@ struct Light : public Cullable , public Transform struct Decal : public Cullable, public Transform { string texName,norName; - TextureView texture,normal; + Texture2D* texture,*normal; XMFLOAT4X4 view,projection; XMFLOAT3 front; float life,fadeStart; diff --git a/WickedEngine/wiRenderTarget.cpp b/WickedEngine/wiRenderTarget.cpp index ce13e76b1..a088cc379 100644 --- a/WickedEngine/wiRenderTarget.cpp +++ b/WickedEngine/wiRenderTarget.cpp @@ -4,11 +4,12 @@ void wiRenderTarget::clear(){ - textureDesc = { 0 }; + //textureDesc = { 0 }; numViews = 0; viewPort = ViewPort(); - depth = NULL; - retargetted = false; + depth = nullptr; + //retargetted = false; + isCube = false; } wiRenderTarget::wiRenderTarget() @@ -25,27 +26,39 @@ wiRenderTarget::wiRenderTarget(UINT width, UINT height, int numViews, bool hasDe wiRenderTarget::~wiRenderTarget() { - for(int i=0;iRelease(); texture2D[i] = NULL; - if(renderTarget[i]) renderTarget[i]->Release(); renderTarget[i] = NULL; - if(SAVEDshaderResource[i]) SAVEDshaderResource[i]->Release(); SAVEDshaderResource[i]=NULL; - if(shaderResource[i] && !retargetted) shaderResource[i]->Release(); shaderResource[i] = NULL; + //for(int i=0;iRelease(); texture2D[i] = NULL; + // if(renderTarget[i]) renderTarget[i]->Release(); renderTarget[i] = NULL; + // if(SAVEDshaderResource[i]) SAVEDshaderResource[i]->Release(); SAVEDshaderResource[i]=NULL; + // if(shaderResource[i] && !retargetted) shaderResource[i]->Release(); shaderResource[i] = NULL; + //} + //texture2D.clear(); + //renderTarget.clear(); + //shaderResource.clear(); + for (unsigned int i = 0; i < renderTargets.size(); ++i) + { + SAFE_DELETE(renderTargets[i]); } - texture2D.clear(); - renderTarget.clear(); - shaderResource.clear(); - if(depth) depth->~wiDepthTarget(); depth=NULL; + for (unsigned int i = 0; i < renderTargets_Cube.size(); ++i) + { + SAFE_DELETE(renderTargets_Cube[i]); + } + SAFE_DELETE(depth); } void wiRenderTarget::Initialize(UINT width, UINT height, int numViews, bool hasDepth, UINT MSAAC, UINT MSAAQ , DXGI_FORMAT format, UINT mipMapLevelCount) { + isCube = false; + this->numViews = numViews; - texture2D.resize(numViews); - renderTarget.resize(numViews); - shaderResource.resize(numViews); - SAVEDshaderResource.resize(numViews); - + //texture2D.resize(numViews); + //renderTarget.resize(numViews); + //shaderResource.resize(numViews); + //SAVEDshaderResource.resize(numViews); + renderTargets.resize(numViews); + + Texture2DDesc textureDesc; ZeroMemory(&textureDesc, sizeof(textureDesc)); textureDesc.Width = width; textureDesc.Height = height; @@ -63,23 +76,27 @@ void wiRenderTarget::Initialize(UINT width, UINT height, int numViews, bool hasD textureDesc.MiscFlags = RESOURCE_MISC_GENERATE_MIPS; } - RenderTargetViewDesc renderTargetViewDesc; - renderTargetViewDesc.Format = format; - renderTargetViewDesc.ViewDimension = (MSAAQ==0 ? RESOURCE_DIMENSION_TEXTURE2D : RESOURCE_DIMENSION_TEXTURE2DMS); - //renderTargetViewDesc.Texture2D.MipSlice = 0; + //RenderTargetViewDesc renderTargetViewDesc; + //renderTargetViewDesc.Format = format; + //renderTargetViewDesc.ViewDimension = (MSAAQ==0 ? RESOURCE_DIMENSION_TEXTURE2D : RESOURCE_DIMENSION_TEXTURE2DMS); + ////renderTargetViewDesc.Texture2D.MipSlice = 0; - - ShaderResourceViewDesc shaderResourceViewDesc; - shaderResourceViewDesc.Format = format; - 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; + // + //ShaderResourceViewDesc shaderResourceViewDesc; + //shaderResourceViewDesc.Format = format; + //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]); - wiRenderer::graphicsDevice->CreateRenderTargetView(texture2D[i], &renderTargetViewDesc, &renderTarget[i]); - wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D[i], &shaderResourceViewDesc, &shaderResource[i]); + //for(int i=0;iCreateTexture2D(&textureDesc, nullptr, &texture2D[i]); + // wiRenderer::graphicsDevice->CreateRenderTargetView(texture2D[i], &renderTargetViewDesc, &renderTarget[i]); + // wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D[i], &shaderResourceViewDesc, &shaderResource[i]); + //} + for (int i = 0; i < numViews; ++i) + { + wiRenderer::graphicsDevice->CreateTexture2D(&textureDesc, nullptr, &renderTargets[i]); } viewPort.Width = (FLOAT)width; @@ -96,12 +113,16 @@ void wiRenderTarget::Initialize(UINT width, UINT height, int numViews, bool hasD } void wiRenderTarget::InitializeCube(UINT size, int numViews, bool hasDepth, DXGI_FORMAT format, UINT mipMapLevelCount) { + isCube = true; + this->numViews = numViews; - texture2D.resize(numViews); - renderTarget.resize(numViews); - shaderResource.resize(numViews); - SAVEDshaderResource.resize(numViews); + //texture2D.resize(numViews); + //renderTarget.resize(numViews); + //shaderResource.resize(numViews); + //SAVEDshaderResource.resize(numViews); + renderTargets_Cube.resize(numViews); + Texture2DDesc textureDesc; ZeroMemory(&textureDesc, sizeof(textureDesc)); textureDesc.Width = size; textureDesc.Height = size; @@ -120,25 +141,30 @@ void wiRenderTarget::InitializeCube(UINT size, int numViews, bool hasDepth, DXGI } - RenderTargetViewDesc renderTargetViewDesc; - renderTargetViewDesc.Format = format; - renderTargetViewDesc.ViewDimension = RESOURCE_DIMENSION_TEXTURE2DARRAY; - // renderTargetViewDesc.Texture2DArray.FirstArraySlice = 0; - //renderTargetViewDesc.Texture2DArray.ArraySize = 6; - // renderTargetViewDesc.Texture2DArray.MipSlice = 0; - renderTargetViewDesc.ArraySize = 6; - - ShaderResourceViewDesc shaderResourceViewDesc; - shaderResourceViewDesc.Format = format; - shaderResourceViewDesc.ViewDimension = RESOURCE_DIMENSION_TEXTURECUBE; - //shaderResourceViewDesc.TextureCube.MostDetailedMip = 0; //from most detailed... - //shaderResourceViewDesc.TextureCube.MipLevels = -1; //...to least detailed - shaderResourceViewDesc.mipLevels = -1; + //RenderTargetViewDesc renderTargetViewDesc; + //renderTargetViewDesc.Format = format; + //renderTargetViewDesc.ViewDimension = RESOURCE_DIMENSION_TEXTURE2DARRAY; + //// renderTargetViewDesc.Texture2DArray.FirstArraySlice = 0; + ////renderTargetViewDesc.Texture2DArray.ArraySize = 6; + //// renderTargetViewDesc.Texture2DArray.MipSlice = 0; + //renderTargetViewDesc.ArraySize = 6; + // + //ShaderResourceViewDesc shaderResourceViewDesc; + //shaderResourceViewDesc.Format = format; + //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]); - wiRenderer::graphicsDevice->CreateRenderTargetView(texture2D[i], &renderTargetViewDesc, &renderTarget[i]); - wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D[i], &shaderResourceViewDesc, &shaderResource[0]); + //for(int i=0;iCreateTexture2D(&textureDesc, NULL, &texture2D[i]); + // wiRenderer::graphicsDevice->CreateRenderTargetView(texture2D[i], &renderTargetViewDesc, &renderTarget[i]); + // wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D[i], &shaderResourceViewDesc, &shaderResource[0]); + //} + + for (int i = 0; i < numViews; ++i) + { + wiRenderer::graphicsDevice->CreateTextureCube(&textureDesc, nullptr, &renderTargets_Cube[i]); } viewPort.Width = (FLOAT)size; @@ -167,7 +193,7 @@ void wiRenderTarget::Activate(GRAPHICSTHREAD threadID, float r, float g, float b Set(threadID); float ClearColor[4] = { r, g, b, a }; for(int i=0;iClearRenderTarget(renderTarget[i], ClearColor); + wiRenderer::graphicsDevice->ClearRenderTarget(GetTexture(i), ClearColor); if(depth) depth->Clear(threadID); } void wiRenderTarget::Activate(GRAPHICSTHREAD threadID, wiDepthTarget* getDepth, float r, float g, float b, float a) @@ -175,7 +201,7 @@ void wiRenderTarget::Activate(GRAPHICSTHREAD threadID, wiDepthTarget* getDepth, Set(threadID,getDepth); float ClearColor[4] = { r, g, b, a }; for(int i=0;iClearRenderTarget(renderTarget[i], ClearColor); + wiRenderer::graphicsDevice->ClearRenderTarget(GetTexture(i), ClearColor); } void wiRenderTarget::Activate(GRAPHICSTHREAD threadID, wiDepthTarget* getDepth) { @@ -188,40 +214,41 @@ void wiRenderTarget::Deactivate(GRAPHICSTHREAD threadID) void wiRenderTarget::Set(GRAPHICSTHREAD threadID) { wiRenderer::graphicsDevice->BindViewports(1, &viewPort); - wiRenderer::graphicsDevice->BindRenderTargets(numViews, renderTarget.data(),(depth?depth->depthTarget:nullptr)); + wiRenderer::graphicsDevice->BindRenderTargets(numViews, (isCube ? (Texture2D**)renderTargets_Cube.data() : renderTargets.data()), (depth ? depth->GetTexture() : nullptr)); } void wiRenderTarget::Set(GRAPHICSTHREAD threadID, wiDepthTarget* getDepth) { depth = getDepth; wiRenderer::graphicsDevice->BindViewports(1, &viewPort); - wiRenderer::graphicsDevice->BindRenderTargets(numViews, renderTarget.data(),(depth?depth->depthTarget:nullptr)); -} -void wiRenderTarget::Retarget(TextureView resource) -{ - retargetted=true; - for(unsigned int i=0;iBindRenderTargets(numViews, (isCube ? (Texture2D**)renderTargets_Cube.data() : renderTargets.data()), (depth ? depth->GetTexture() : nullptr)); } +//void wiRenderTarget::Retarget(Texture2D* resource) +//{ +// retargetted=true; +// for(unsigned int i=0;i0) - return textureDesc.MipLevels; + if (desc.MipLevels>0) + return desc.MipLevels; - UINT maxDim = max(textureDesc.Width, textureDesc.Height); + UINT maxDim = max(desc.Width, desc.Height); return static_cast( log2(static_cast(maxDim)) ); } diff --git a/WickedEngine/wiRenderTarget.h b/WickedEngine/wiRenderTarget.h index 609f5efe6..ffcb8e568 100644 --- a/WickedEngine/wiRenderTarget.h +++ b/WickedEngine/wiRenderTarget.h @@ -8,16 +8,19 @@ class wiRenderTarget { private: int numViews; - bool retargetted; - vector SAVEDshaderResource; + //bool retargetted; + //vector SAVEDshaderResource; void clear(); - Texture2DDesc textureDesc; + //Texture2DDesc textureDesc; + vector renderTargets; + vector renderTargets_Cube; + bool isCube; public: - ViewPort viewPort; - vector texture2D; - vector renderTarget; - vector shaderResource; - wiDepthTarget* depth; + //vector texture2D; + //vector renderTarget; + //vector shaderResource; + ViewPort viewPort; + wiDepthTarget* depth; wiRenderTarget(); wiRenderTarget(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); @@ -33,10 +36,11 @@ public: void Deactivate(GRAPHICSTHREAD threadID); void Set(GRAPHICSTHREAD threadID); void Set(GRAPHICSTHREAD threadID, wiDepthTarget*); - void Retarget(TextureView resource); - void Restore(); + //void Retarget(Texture2D* resource); + //void Restore(); - Texture2DDesc GetDesc() const{ return textureDesc; } + Texture2D* GetTexture(int viewID = 0) const{ return (isCube ? renderTargets_Cube[viewID] : renderTargets[viewID]); } + Texture2DDesc GetDesc(int viewID = 0) const{ return GetTexture(viewID)->desc; } UINT GetMipCount(); }; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 608bfd6a0..3c23caa97 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -24,6 +24,8 @@ #include "wiGraphicsAPI_DX11.h" #pragma region STATICS +GraphicsDevice* wiRenderer::graphicsDevice = nullptr; + Sampler wiRenderer::samplers[SSLOT_COUNT]; BufferResource wiRenderer::constantBuffers[CBTYPE_LAST]; @@ -42,7 +44,7 @@ int wiRenderer::SCREENWIDTH=1280,wiRenderer::SCREENHEIGHT=720,wiRenderer::SHADOW bool wiRenderer::HAIRPARTICLEENABLED=true,wiRenderer::EMITTERSENABLED=true; bool wiRenderer::wireRender = false, wiRenderer::debugSpheres = false, wiRenderer::debugBoneLines = false, wiRenderer::debugBoxes = false; -TextureView wiRenderer::enviroMap,wiRenderer::colorGrading; +Texture2D* wiRenderer::enviroMap,*wiRenderer::colorGrading; float wiRenderer::GameSpeed=1,wiRenderer::overrideGameSpeed=1; int wiRenderer::visibleCount; wiRenderTarget wiRenderer::normalMapRT, wiRenderer::imagesRT, wiRenderer::imagesRTAdd; @@ -1533,7 +1535,7 @@ void wiRenderer::DrawSoftPremulParticles(Camera* camera, GRAPHICSTHREAD threadID e->DrawPremul(camera, threadID, dark); } } -void wiRenderer::DrawTrails(GRAPHICSTHREAD threadID, TextureView refracRes){ +void wiRenderer::DrawTrails(GRAPHICSTHREAD threadID, Texture2D* refracRes){ wiRenderer::graphicsDevice->BindPrimitiveTopology(TRIANGLESTRIP,threadID); wiRenderer::graphicsDevice->BindVertexLayout(vertexLayouts[VLTYPE_TRAIL],threadID); @@ -1603,12 +1605,12 @@ void wiRenderer::DrawTrails(GRAPHICSTHREAD threadID, TextureView refracRes){ } } } -void wiRenderer::DrawImagesAdd(GRAPHICSTHREAD threadID, TextureView refracRes){ +void wiRenderer::DrawImagesAdd(GRAPHICSTHREAD threadID, Texture2D* 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; + /*Texture2D* nor = x->effects.normalMap; x->effects.setNormalMap(nullptr); bool changedBlend=false; if(x->effects.blendFlag==BLENDMODE_OPAQUE && nor){ @@ -1622,12 +1624,12 @@ void wiRenderer::DrawImagesAdd(GRAPHICSTHREAD threadID, TextureView refracRes){ } } } -void wiRenderer::DrawImages(GRAPHICSTHREAD threadID, TextureView refracRes){ +void wiRenderer::DrawImages(GRAPHICSTHREAD threadID, Texture2D* 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; + /*Texture2D* nor = x->effects.normalMap; x->effects.setNormalMap(nullptr); bool changedBlend=false; if(x->effects.blendFlag==BLENDMODE_OPAQUE && nor){ @@ -1641,7 +1643,7 @@ void wiRenderer::DrawImages(GRAPHICSTHREAD threadID, TextureView refracRes){ } } } -void wiRenderer::DrawImagesNormals(GRAPHICSTHREAD threadID, TextureView refracRes){ +void wiRenderer::DrawImagesNormals(GRAPHICSTHREAD threadID, Texture2D* refracRes){ normalMapRT.Activate(threadID,0,0,0,0); //wiImage::BatchBegin(threadID); for(wiSprite* x : images){ @@ -1727,7 +1729,7 @@ void wiRenderer::DrawLights(Camera* camera, GRAPHICSTHREAD threadID, unsigned in for (unsigned int shmap = 0; shmap < l->shadowMaps_dirLight.size(); ++shmap){ (*lcb).mShM[shmap]=l->shadowCam[shmap].getVP(); if(l->shadowMaps_dirLight[shmap].depth) - wiRenderer::graphicsDevice->BindTexturePS(l->shadowMaps_dirLight[shmap].depth->shaderResource,TEXSLOT_SHADOW0+shmap,threadID); + wiRenderer::graphicsDevice->BindTexturePS(l->shadowMaps_dirLight[shmap].depth->GetTexture(),TEXSLOT_SHADOW0+shmap,threadID); } wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_DIRLIGHT],lcb,threadID); @@ -1745,7 +1747,7 @@ void wiRenderer::DrawLights(Camera* camera, GRAPHICSTHREAD threadID, unsigned in { (*lcb).enerdis.w = 1.f; if(Light::shadowMaps_pointLight[l->shadowMap_index].depth) - wiRenderer::graphicsDevice->BindTexturePS(Light::shadowMaps_pointLight[l->shadowMap_index].depth->shaderResource, TEXSLOT_SHADOW_CUBE, threadID); + wiRenderer::graphicsDevice->BindTexturePS(Light::shadowMaps_pointLight[l->shadowMap_index].depth->GetTexture(), TEXSLOT_SHADOW_CUBE, threadID); } wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_POINTLIGHT], lcb, threadID); @@ -1776,7 +1778,7 @@ void wiRenderer::DrawLights(Camera* camera, GRAPHICSTHREAD threadID, unsigned in { (*lcb).mShM = l->shadowCam[0].getVP(); if(Light::shadowMaps_spotLight[l->shadowMap_index].depth) - wiRenderer::graphicsDevice->BindTexturePS(Light::shadowMaps_spotLight[l->shadowMap_index].depth->shaderResource, TEXSLOT_SHADOW0, threadID); + wiRenderer::graphicsDevice->BindTexturePS(Light::shadowMaps_spotLight[l->shadowMap_index].depth->GetTexture(), TEXSLOT_SHADOW0, threadID); } wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_SPOTLIGHT], lcb, threadID); @@ -2318,7 +2320,7 @@ void wiRenderer::SetSpotLightShadowProps(int shadowMapCount, int resolution) void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, GRAPHICSTHREAD threadID , bool BlackOut, bool isReflection, SHADERTYPE shaded - , TextureView refRes, bool grass, GRAPHICSTHREAD thread) + , Texture2D* refRes, bool grass, GRAPHICSTHREAD thread) { CulledCollection culledRenderer; CulledList culledObjects; @@ -2329,7 +2331,7 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, GRAPHICSTHRE if(!culledObjects.empty()) { - TextureView envMaps[] = { enviroMap, enviroMap }; + Texture2D* envMaps[] = { enviroMap, enviroMap }; XMFLOAT3 envMapPositions[] = { XMFLOAT3(0,0,0),XMFLOAT3(0,0,0) }; if (!GetScene().environmentProbes.empty()) { @@ -2360,7 +2362,7 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, GRAPHICSTHRE } for (unsigned int i = 0; i < min(sortedEnvProbes.size(), 2); ++i) { - envMaps[i] = sortedEnvProbes[i]->cubeMap.shaderResource.front(); + envMaps[i] = sortedEnvProbes[i]->cubeMap.GetTexture(); envMapPositions[i] = sortedEnvProbes[i]->translation; } } @@ -2517,8 +2519,8 @@ void wiRenderer::DrawWorld(Camera* camera, bool DX11Eff, int tessF, GRAPHICSTHRE } -void wiRenderer::DrawWorldTransparent(Camera* camera, TextureView refracRes, TextureView refRes - , TextureView waterRippleNormals, GRAPHICSTHREAD threadID) +void wiRenderer::DrawWorldTransparent(Camera* camera, Texture2D* refracRes, Texture2D* refRes + , Texture2D* waterRippleNormals, GRAPHICSTHREAD threadID) { CulledCollection culledRenderer; CulledList culledObjects; @@ -2818,14 +2820,15 @@ void wiRenderer::SetClipPlane(XMFLOAT4 clipPlane, GRAPHICSTHREAD threadID) { wiRenderer::graphicsDevice->UpdateBuffer(constantBuffers[CBTYPE_CLIPPLANE], &clipPlane, threadID); } -void wiRenderer::UpdateGBuffer(vector gbuffer, GRAPHICSTHREAD threadID) +void wiRenderer::UpdateGBuffer(Texture2D* slot0, Texture2D* slot1, Texture2D* slot2, Texture2D* slot3, Texture2D* slot4, GRAPHICSTHREAD threadID) { - for (unsigned int i = 0; i < gbuffer.size(); ++i) - { - wiRenderer::graphicsDevice->BindTexturePS(gbuffer[i], TEXSLOT_GBUFFER0 + i, threadID); - } + wiRenderer::graphicsDevice->BindTexturePS(slot0, TEXSLOT_GBUFFER0, threadID); + wiRenderer::graphicsDevice->BindTexturePS(slot1, TEXSLOT_GBUFFER1, threadID); + wiRenderer::graphicsDevice->BindTexturePS(slot2, TEXSLOT_GBUFFER2, threadID); + wiRenderer::graphicsDevice->BindTexturePS(slot3, TEXSLOT_GBUFFER3, threadID); + wiRenderer::graphicsDevice->BindTexturePS(slot4, TEXSLOT_GBUFFER4, threadID); } -void wiRenderer::UpdateDepthBuffer(TextureView depth, TextureView linearDepth, GRAPHICSTHREAD threadID) +void wiRenderer::UpdateDepthBuffer(Texture2D* depth, Texture2D* linearDepth, GRAPHICSTHREAD threadID) { wiRenderer::graphicsDevice->BindTexturePS(depth, TEXSLOT_DEPTH, threadID); wiRenderer::graphicsDevice->BindTextureVS(depth, TEXSLOT_DEPTH, threadID); @@ -3322,9 +3325,9 @@ void wiRenderer::PutEnvProbe(const XMFLOAT3& position, int resolution) probe->cubeMap.Deactivate(threadID); - wiRenderer::graphicsDevice->GenerateMips(probe->cubeMap.shaderResource[0], threadID); + wiRenderer::graphicsDevice->GenerateMips(probe->cubeMap.GetTexture(), threadID); - enviroMap = probe->cubeMap.shaderResource.front(); + enviroMap = probe->cubeMap.GetTexture(); scene->environmentProbes.push_back(probe); diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 94084fc7a..daa259f9d 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -276,7 +276,7 @@ protected: static bool wireRender, debugSpheres, debugBoneLines, debugBoxes; - static TextureView enviroMap,colorGrading; + static Texture2D* enviroMap,*colorGrading; static void LoadBuffers(); static void LoadBasicShaders(); static void LoadLineShaders(); @@ -327,10 +327,10 @@ public: static void SetToDrawDebugBoxes(bool param){debugBoxes=param;} static bool GetToDrawDebugSpheres(){return debugSpheres;}; static bool GetToDrawDebugBoxes(){return debugBoxes;}; - static TextureView GetColorGrading(){return colorGrading;}; - static void SetColorGrading(TextureView tex){colorGrading=tex;}; - static void SetEnviromentMap(TextureView tex){ enviroMap = tex; } - static TextureView GetEnviromentMap(){ return enviroMap; } + static Texture2D* GetColorGrading(){return colorGrading;}; + static void SetColorGrading(Texture2D* tex){colorGrading=tex;}; + static void SetEnviromentMap(Texture2D* tex){ enviroMap = tex; } + static Texture2D* GetEnviromentMap(){ return enviroMap; } static Transform* getTransformByName(const string& name); @@ -357,28 +357,28 @@ public: 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 UpdateGBuffer(Texture2D* slot0, Texture2D* slot1, Texture2D* slot2, Texture2D* slot3, Texture2D* slot4, GRAPHICSTHREAD threadID); + static void UpdateDepthBuffer(Texture2D* depth, Texture2D* 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); + , bool BlackOut, bool isReflection, SHADERTYPE shaded, Texture2D* refRes, bool grass, GRAPHICSTHREAD thread); static void ClearShadowMaps(GRAPHICSTHREAD threadID); static void DrawForShadowMap(GRAPHICSTHREAD threadID); - static void DrawWorldTransparent(Camera* camera, TextureView refracRes, TextureView refRes - , TextureView waterRippleNormals, GRAPHICSTHREAD threadID); + static void DrawWorldTransparent(Camera* camera, Texture2D* refracRes, Texture2D* refRes + , Texture2D* 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); + static void DrawTrails(GRAPHICSTHREAD threadID, Texture2D* refracRes); + static void DrawImagesAdd(GRAPHICSTHREAD threadID, Texture2D* refracRes); //alpha-opaque - static void DrawImages(GRAPHICSTHREAD threadID, TextureView refracRes); - static void DrawImagesNormals(GRAPHICSTHREAD threadID, TextureView refracRes); + static void DrawImages(GRAPHICSTHREAD threadID, Texture2D* refracRes); + static void DrawImagesNormals(GRAPHICSTHREAD threadID, Texture2D* refracRes); static void DrawLights(Camera* camera, GRAPHICSTHREAD threadID, unsigned int stencilRef = 2); static void DrawVolumeLights(Camera* camera, GRAPHICSTHREAD threadID); static void DrawLensFlares(GRAPHICSTHREAD threadID); diff --git a/WickedEngine/wiResourceManager.cpp b/WickedEngine/wiResourceManager.cpp index 253ddc752..6630d629b 100644 --- a/WickedEngine/wiResourceManager.cpp +++ b/WickedEngine/wiResourceManager.cpp @@ -89,7 +89,7 @@ void* wiResourceManager::add(const string& name, Data_Type newType switch(type){ case Data_Type::IMAGE: { - TextureView image=nullptr; + Texture2D* image=nullptr; //if( // !ext.compare("jpg") // || !ext.compare("JPG") @@ -260,7 +260,7 @@ bool wiResourceManager::del(const string& name, bool forceDelete) switch(res->type){ case Data_Type::IMAGE: case Data_Type::IMAGE_STAGING: - SAFE_RELEASE(reinterpret_cast(res->data)); + SAFE_DELETE(reinterpret_cast(res->data)); break; case Data_Type::VERTEXSHADER: { diff --git a/WickedEngine/wiResourceManager_BindLua.cpp b/WickedEngine/wiResourceManager_BindLua.cpp index ab6d4f379..01309b5ad 100644 --- a/WickedEngine/wiResourceManager_BindLua.cpp +++ b/WickedEngine/wiResourceManager_BindLua.cpp @@ -46,7 +46,7 @@ int wiResourceManager_BindLua::Get(lua_State *L) switch (data->type) { case wiResourceManager::Data_Type::IMAGE: - Luna::push(L, new Texture_BindLua((TextureView)data->data)); + Luna::push(L, new Texture_BindLua((Texture2D*)data->data)); return 1; break; case wiResourceManager::Data_Type::MUSIC: diff --git a/WickedEngine/wiSprite.cpp b/WickedEngine/wiSprite.cpp index 17f784003..596303653 100644 --- a/WickedEngine/wiSprite.cpp +++ b/WickedEngine/wiSprite.cpp @@ -40,15 +40,15 @@ void wiSprite::Init(){ void wiSprite::CreateReference(const string& newTexture, const string& newMask, const string& newNormal){ if(newTexture.length()) { texture = newTexture; - texturePointer = (TextureView)ContentHolder->add(newTexture); + texturePointer = (Texture2D*)ContentHolder->add(newTexture); } if(newMask.length()) { - maskPointer = (TextureView)ContentHolder->add(newMask); + maskPointer = (Texture2D*)ContentHolder->add(newMask); effects.setMaskMap( maskPointer ); mask = newMask; } if(newNormal.length()) { - normalPointer = (TextureView)ContentHolder->add(newNormal); + normalPointer = (Texture2D*)ContentHolder->add(newNormal); //effects.setNormalMap( normalPointer ); normal = newNormal; } @@ -59,7 +59,7 @@ void wiSprite::CleanUp(){ ContentHolder->del(mask); } -void wiSprite::Draw(TextureView refracRes, GRAPHICSTHREAD threadID){ +void wiSprite::Draw(Texture2D* 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,threadID); diff --git a/WickedEngine/wiSprite.h b/WickedEngine/wiSprite.h index f5d1a5cbe..0850b290a 100644 --- a/WickedEngine/wiSprite.h +++ b/WickedEngine/wiSprite.h @@ -9,7 +9,7 @@ class wiSprite : public wiImage { private: string texture, mask, normal; - TextureView texturePointer,normalPointer,maskPointer; + Texture2D* texturePointer,*normalPointer,*maskPointer; wiResourceManager* ContentHolder; public: wiSprite(wiResourceManager* contentHolder = nullptr); @@ -22,7 +22,7 @@ public: void Update(float); void Update(); - void Draw(TextureView refracRes, GRAPHICSTHREAD threadID); + void Draw(Texture2D* refracRes, GRAPHICSTHREAD threadID); void Draw(); void DrawNormal(GRAPHICSTHREAD threadID); @@ -66,7 +66,7 @@ public: }; Anim anim; - TextureView getTexture(){return texturePointer;} - void setTexture(TextureView value){texturePointer=value;} + Texture2D* getTexture(){return texturePointer;} + void setTexture(Texture2D* value){texturePointer=value;} }; diff --git a/WickedEngine/wiTextureHelper.cpp b/WickedEngine/wiTextureHelper.cpp index 3d08150a7..fec853d87 100644 --- a/WickedEngine/wiTextureHelper.cpp +++ b/WickedEngine/wiTextureHelper.cpp @@ -14,18 +14,18 @@ wiTextureHelper::wiTextureHelperInstance::~wiTextureHelperInstance() { for (int i = 0; i < HELPERTEXTURE_COUNT; ++i) { - SAFE_RELEASE(helperTextures[i]); + SAFE_DELETE(helperTextures[i]); } for (auto& x : colorTextures) { - SAFE_RELEASE(x.second); + SAFE_DELETE(x.second); } } -TextureView wiTextureHelper::wiTextureHelperInstance::getRandom64x64() +Texture2D* wiTextureHelper::wiTextureHelperInstance::getRandom64x64() { if (helperTextures[HELPERTEXTURE_RANDOM64X64] != nullptr) { @@ -53,7 +53,7 @@ TextureView wiTextureHelper::wiTextureHelperInstance::getRandom64x64() return helperTextures[HELPERTEXTURE_RANDOM64X64]; } -TextureView wiTextureHelper::wiTextureHelperInstance::getColorGradeDefault() +Texture2D* wiTextureHelper::wiTextureHelperInstance::getColorGradeDefault() { if (helperTextures[HELPERTEXTURE_COLORGRADEDEFAULT] != nullptr) { @@ -93,27 +93,27 @@ TextureView wiTextureHelper::wiTextureHelperInstance::getColorGradeDefault() return helperTextures[HELPERTEXTURE_COLORGRADEDEFAULT]; } -TextureView wiTextureHelper::wiTextureHelperInstance::getNormalMapDefault() +Texture2D* wiTextureHelper::wiTextureHelperInstance::getNormalMapDefault() { return getColor(wiColor(127, 127, 255, 255)); } -TextureView wiTextureHelper::wiTextureHelperInstance::getWhite() +Texture2D* wiTextureHelper::wiTextureHelperInstance::getWhite() { return getColor(wiColor(255, 255, 255, 255)); } -TextureView wiTextureHelper::wiTextureHelperInstance::getBlack() +Texture2D* wiTextureHelper::wiTextureHelperInstance::getBlack() { return getColor(wiColor(0, 0, 0, 255)); } -TextureView wiTextureHelper::wiTextureHelperInstance::getTransparent() +Texture2D* wiTextureHelper::wiTextureHelperInstance::getTransparent() { return getColor(wiColor(0, 0, 0, 0)); } -TextureView wiTextureHelper::wiTextureHelperInstance::getColor(const wiColor& color) +Texture2D* wiTextureHelper::wiTextureHelperInstance::getColor(const wiColor& color) { if (colorTextures.find(color.rgba) != colorTextures.end()) { @@ -130,7 +130,7 @@ TextureView wiTextureHelper::wiTextureHelperInstance::getColor(const wiColor& co data[i + 3] = color.a; } - TextureView texture; + Texture2D* texture; if (FAILED(CreateTexture(texture, data, 2, 2, 4))) { delete[] data; diff --git a/WickedEngine/wiTextureHelper.h b/WickedEngine/wiTextureHelper.h index f9dc94167..c3123d66a 100644 --- a/WickedEngine/wiTextureHelper.h +++ b/WickedEngine/wiTextureHelper.h @@ -17,21 +17,21 @@ private: HELPERTEXTURE_NORMALMAPDEFAULT, HELPERTEXTURE_COUNT }; - TextureView helperTextures[HELPERTEXTURE_COUNT]; + Texture2D* helperTextures[HELPERTEXTURE_COUNT]; - unordered_map colorTextures; + unordered_map colorTextures; public: wiTextureHelperInstance(); ~wiTextureHelperInstance(); - TextureView getRandom64x64(); - TextureView getColorGradeDefault(); - TextureView getNormalMapDefault(); + Texture2D* getRandom64x64(); + Texture2D* getColorGradeDefault(); + Texture2D* getNormalMapDefault(); - TextureView getWhite(); - TextureView getBlack(); - TextureView getTransparent(); - TextureView getColor(const wiColor& color); + Texture2D* getWhite(); + Texture2D* getBlack(); + Texture2D* getTransparent(); + Texture2D* getColor(const wiColor& color); }; static wiTextureHelperInstance* instance; @@ -46,7 +46,7 @@ public: } template - static HRESULT CreateTexture(TextureView& texture, T* data, UINT width, UINT height, UINT channelCount, DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM) + static HRESULT CreateTexture(Texture2D*& texture, T* data, UINT width, UINT height, UINT channelCount, DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM) { if (data == nullptr) { @@ -67,27 +67,27 @@ public: textureDesc.CPUAccessFlags = 0; textureDesc.MiscFlags = 0; - ShaderResourceViewDesc shaderResourceViewDesc; - shaderResourceViewDesc.Format = format; - shaderResourceViewDesc.ViewDimension = RESOURCE_DIMENSION_TEXTURE2D; - //shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; - //shaderResourceViewDesc.Texture2D.MipLevels = 1; - shaderResourceViewDesc.mipLevels = 1; + //ShaderResourceViewDesc shaderResourceViewDesc; + //shaderResourceViewDesc.Format = format; + //shaderResourceViewDesc.ViewDimension = RESOURCE_DIMENSION_TEXTURE2D; + ////shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; + ////shaderResourceViewDesc.Texture2D.MipLevels = 1; + //shaderResourceViewDesc.mipLevels = 1; SubresourceData InitData; ZeroMemory(&InitData, sizeof(InitData)); InitData.pSysMem = data; InitData.SysMemPitch = static_cast(width * channelCount); - Texture2D texture2D = nullptr; + //Texture2D* texture2D = nullptr; HRESULT hr; - hr = wiRenderer::graphicsDevice->CreateTexture2D(&textureDesc, &InitData, &texture2D); - if (FAILED(hr)) - { - return hr; - } - hr = wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D, &shaderResourceViewDesc, &texture); - SAFE_RELEASE(texture2D); + hr = wiRenderer::graphicsDevice->CreateTexture2D(&textureDesc, &InitData, &texture); + //if (FAILED(hr)) + //{ + // return hr; + //} + //hr = wiRenderer::graphicsDevice->CreateShaderResourceView(texture2D, &shaderResourceViewDesc, &texture); + //SAFE_RELEASE(texture2D); return hr; }