diff --git a/WickedEngine/DeferredRenderableComponent.cpp b/WickedEngine/DeferredRenderableComponent.cpp index 6a6ca0be1..c6ae43186 100644 --- a/WickedEngine/DeferredRenderableComponent.cpp +++ b/WickedEngine/DeferredRenderableComponent.cpp @@ -97,7 +97,6 @@ void DeferredRenderableComponent::RenderScene(wiRenderer::DeviceContext context) rtLinearDepth.Activate(context); { - wiImage::BatchBegin(context); fx.blendFlag = BLENDMODE_OPAQUE; fx.sampleFlag = SAMPLEMODE_CLAMP; fx.quality = QUALITY_NEAREST; @@ -119,7 +118,9 @@ void DeferredRenderableComponent::RenderScene(wiRenderer::DeviceContext context) if (getSSAOEnabled()){ - wiImage::BatchBegin(context, STENCILREF_DEFAULT); + //wiImage::BatchBegin(context, STENCILREF_DEFAULT); + fx.stencilRef = STENCILREF_DEFAULT; + fx.stencilComp = D3D11_COMPARISON_LESS; rtSSAO[0].Activate(context); { fx.process.setSSAO(true); fx.setDepthMap(rtLinearDepth.shaderResource.back()); @@ -145,6 +146,8 @@ void DeferredRenderableComponent::RenderScene(wiRenderer::DeviceContext context) wiImage::Draw(rtSSAO[1].shaderResource.back(), fx, context); fx.blur = 0; } + fx.stencilRef = 0; + fx.stencilComp = 0; } @@ -160,7 +163,9 @@ void DeferredRenderableComponent::RenderScene(wiRenderer::DeviceContext context) if (getSSSEnabled()) { - wiImage::BatchBegin(context, STENCILREF_SKIN); + //wiImage::BatchBegin(context, STENCILREF_SKIN); + fx.stencilRef = STENCILREF_SKIN; + fx.stencilComp = D3D11_COMPARISON_LESS; fx.quality = QUALITY_BILINEAR; fx.sampleFlag = SAMPLEMODE_CLAMP; fx.setDepthMap(rtLinearDepth.shaderResource.back()); @@ -180,19 +185,26 @@ void DeferredRenderableComponent::RenderScene(wiRenderer::DeviceContext context) } fx.process.clear(); rtSSS.back().Activate(context, rtGBuffer.depth); { - wiImage::BatchBegin(context); + //wiImage::BatchBegin(context); fx.quality = QUALITY_NEAREST; fx.sampleFlag = SAMPLEMODE_CLAMP; fx.blendFlag = BLENDMODE_OPAQUE; + fx.stencilRef = 0; + fx.stencilComp = 0; wiImage::Draw(rtDeferred.shaderResource.front(), fx, context); - wiImage::BatchBegin(context, STENCILREF_SKIN); + //wiImage::BatchBegin(context, STENCILREF_SKIN); + fx.stencilRef = STENCILREF_SKIN; + fx.stencilComp = D3D11_COMPARISON_LESS; wiImage::Draw(rtSSS[rtSSS.size() - 2].shaderResource.back(), fx, context); } + + fx.stencilRef = 0; + fx.stencilComp = 0; } if (getSSREnabled()){ rtSSR.Activate(context); { - wiImage::BatchBegin(context); + //wiImage::BatchBegin(context); context->GenerateMips(rtDeferred.shaderResource[0]); fx.process.setSSR(true); fx.setDepthMap(dtDepthCopy.shaderResource); @@ -208,7 +220,7 @@ void DeferredRenderableComponent::RenderScene(wiRenderer::DeviceContext context) } if (getMotionBlurEnabled()){ //MOTIONBLUR - wiImage::BatchBegin(context); + //wiImage::BatchBegin(context); rtMotionBlur.Activate(context); fx.process.setMotionBlur(true); fx.setVelocityMap(rtGBuffer.shaderResource.back()); diff --git a/WickedEngine/DeferredRenderableComponent_BindLua.cpp b/WickedEngine/DeferredRenderableComponent_BindLua.cpp index 481bf2d39..edacd8902 100644 --- a/WickedEngine/DeferredRenderableComponent_BindLua.cpp +++ b/WickedEngine/DeferredRenderableComponent_BindLua.cpp @@ -10,6 +10,12 @@ Luna::FunctionType DeferredRenderableCompon lunamethod(Renderable2DComponent_BindLua, ClearSprites), lunamethod(Renderable2DComponent_BindLua, ClearFonts), + lunamethod(Renderable2DComponent_BindLua, AddLayer), + lunamethod(Renderable2DComponent_BindLua, GetLayers), + lunamethod(Renderable2DComponent_BindLua, SetLayerOrder), + lunamethod(Renderable2DComponent_BindLua, SetSpriteOrder), + lunamethod(Renderable2DComponent_BindLua, SetFontOrder), + lunamethod(DeferredRenderableComponent_BindLua, GetContent), lunamethod(DeferredRenderableComponent_BindLua, Initialize), lunamethod(DeferredRenderableComponent_BindLua, Load), diff --git a/WickedEngine/ForwardRenderableComponent.cpp b/WickedEngine/ForwardRenderableComponent.cpp index 0f2799aef..f3b1f3438 100644 --- a/WickedEngine/ForwardRenderableComponent.cpp +++ b/WickedEngine/ForwardRenderableComponent.cpp @@ -88,7 +88,7 @@ void ForwardRenderableComponent::RenderScene(wiRenderer::DeviceContext context) fx.sampleFlag = SAMPLEMODE_CLAMP; fx.quality = QUALITY_NEAREST; fx.process.setLinDepth(true); - wiImage::BatchBegin(context); + //wiImage::BatchBegin(context); wiImage::Draw(rtMain.depth->shaderResource, fx, context); } diff --git a/WickedEngine/ForwardRenderableComponent_BindLua.cpp b/WickedEngine/ForwardRenderableComponent_BindLua.cpp index 14af25a5c..911e61ae4 100644 --- a/WickedEngine/ForwardRenderableComponent_BindLua.cpp +++ b/WickedEngine/ForwardRenderableComponent_BindLua.cpp @@ -10,6 +10,12 @@ Luna::FunctionType ForwardRenderableComponen lunamethod(Renderable2DComponent_BindLua, ClearSprites), lunamethod(Renderable2DComponent_BindLua, ClearFonts), + lunamethod(Renderable2DComponent_BindLua, AddLayer), + lunamethod(Renderable2DComponent_BindLua, GetLayers), + lunamethod(Renderable2DComponent_BindLua, SetLayerOrder), + lunamethod(Renderable2DComponent_BindLua, SetSpriteOrder), + lunamethod(Renderable2DComponent_BindLua, SetFontOrder), + lunamethod(ForwardRenderableComponent_BindLua, GetContent), lunamethod(ForwardRenderableComponent_BindLua, Initialize), lunamethod(ForwardRenderableComponent_BindLua, Load), diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index bd645db93..7c5a90ae0 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -135,7 +135,7 @@ void MainComponent::Compose() // Draw the color grading palette if (colorGradingPaletteDisplayEnabled) { - wiImage::BatchBegin(); + //wiImage::BatchBegin(); wiImage::Draw(wiTextureHelper::getInstance()->getColorGradeDefault(), wiImageEffects(0, 0, 256, 16)); wiImage::Draw(wiRenderer::GetColorGrading(), wiImageEffects(screenW-256.f, 0, 256, 16)); } diff --git a/WickedEngine/Renderable2DComponent.cpp b/WickedEngine/Renderable2DComponent.cpp index 03d84b961..529c28190 100644 --- a/WickedEngine/Renderable2DComponent.cpp +++ b/WickedEngine/Renderable2DComponent.cpp @@ -7,8 +7,7 @@ Renderable2DComponent::Renderable2DComponent() { setSpriteSpeed(1.f); - m_sprites.clear(); - m_fonts.clear(); + addLayer(DEFAULT_RENDERLAYER); } @@ -30,21 +29,22 @@ void Renderable2DComponent::Load() } void Renderable2DComponent::Unload() { - for (wiSprite* x : m_sprites) + for (auto& x : layers) { - if (x != nullptr) - x->CleanUp(); - SAFE_DELETE(x); + for (auto& y : x.entities) + { + if (y.sprite != nullptr) + { + y.sprite->CleanUp(); + delete y.sprite; + } + if (y.font != nullptr) + { + y.font->CleanUp(); + delete y.font; + } + } } - m_sprites.clear(); - - for (wiFont* x : m_fonts) - { - if (x != nullptr) - x->CleanUp(); - SAFE_DELETE(x); - } - m_fonts.clear(); } void Renderable2DComponent::Start() { @@ -52,78 +52,249 @@ void Renderable2DComponent::Start() } void Renderable2DComponent::Update() { - vector spritesToDelete(0); - vector fontsToDelete(0); + //vector spritesToDelete(0); + //vector fontsToDelete(0); - for (wiSprite* x : m_sprites) - { - if (x != nullptr) - x->Update(getSpriteSpeed()); - else - spritesToDelete.push_back(x); - } - for (wiFont* x : m_fonts) - { - if (x == nullptr) - fontsToDelete.push_back(x); - } + //for (wiSprite* x : m_sprites) + //{ + // if (x != nullptr) + // x->Update(getSpriteSpeed()); + // else + // spritesToDelete.push_back(x); + //} + //for (wiFont* x : m_fonts) + //{ + // if (x == nullptr) + // fontsToDelete.push_back(x); + //} - for (wiSprite* x : spritesToDelete) + //for (wiSprite* x : spritesToDelete) + //{ + // m_sprites.remove(x); + //} + //for (wiFont* x : fontsToDelete) + //{ + // m_fonts.remove(x); + //} + + for (auto& x : layers) { - m_sprites.remove(x); - } - for (wiFont* x : fontsToDelete) - { - m_fonts.remove(x); + for (auto& y : x.entities) + { + if (y.sprite != nullptr) + { + y.sprite->Update(getSpriteSpeed()); + } + if (y.font != nullptr) + { + // this is intentianally left blank + } + } } } void Renderable2DComponent::Render() { rtFinal.Activate(wiRenderer::getImmediateContext(), 0, 0, 0, 0); - wiImage::BatchBegin(); + //wiImage::BatchBegin(); - for (wiSprite* x : m_sprites) + + for (auto& x : layers) { - if(x != nullptr) - x->Draw(); + for (auto& y : x.entities) + { + if (y.sprite != nullptr) + { + y.sprite->Draw(); + } + if (y.font != nullptr) + { + y.font->Draw(); + } + } } - for (wiFont* x : m_fonts) - { - if (x != nullptr) - x->Draw(); - } + //for (wiSprite* x : m_sprites) + //{ + // if(x != nullptr) + // x->Draw(); + //} + + //for (wiFont* x : m_fonts) + //{ + // if (x != nullptr) + // x->Draw(); + //} } void Renderable2DComponent::Compose() { - wiImage::BatchBegin(); + //wiImage::BatchBegin(); wiImage::Draw(rtFinal.shaderResource.back(), wiImageEffects((float)wiRenderer::GetScreenWidth(),(float)wiRenderer::GetScreenHeight())); } -void Renderable2DComponent::addSprite(wiSprite* sprite) +void Renderable2DComponent::addSprite(wiSprite* sprite, const string& layer) { - m_sprites.push_back(sprite); + for (auto& x : layers) + { + if (!x.name.compare(layer)) + { + LayeredRenderEntity entity = LayeredRenderEntity(); + entity.type = LayeredRenderEntity::SPRITE; + entity.sprite = sprite; + x.entities.push_back(entity); + } + } + SortLayers(); } void Renderable2DComponent::removeSprite(wiSprite* sprite) { - m_sprites.remove(sprite); + for (auto& x : layers) + { + for (auto& y : x.entities) + { + if (y.sprite == sprite) + { + + } + } + } } void Renderable2DComponent::clearSprites() { - m_sprites.clear(); + for (auto& x : layers) + { + for (auto& y : x.entities) + { + + } + } } -void Renderable2DComponent::addFont(wiFont* font) +void Renderable2DComponent::addFont(wiFont* font, const string& layer) { - m_fonts.push_back(font); + for (auto& x : layers) + { + if (!x.name.compare(layer)) + { + LayeredRenderEntity entity = LayeredRenderEntity(); + entity.type = LayeredRenderEntity::FONT; + entity.font = font; + x.entities.push_back(entity); + } + } + SortLayers(); } void Renderable2DComponent::removeFont(wiFont* font) { - m_fonts.remove(font); + for (auto& x : layers) + { + for (auto& y : x.entities) + { + + } + } } void Renderable2DComponent::clearFonts() { - m_fonts.clear(); + for (auto& x : layers) + { + for (auto& y : x.entities) + { + + } + } +} + + +void Renderable2DComponent::addLayer(const string& name) +{ + for (auto& x : layers) + { + if (!x.name.compare(name)) + return; + } + RenderLayer layer = RenderLayer(name); + layer.order = layers.size(); + layers.push_back(layer); + layers.back().entities.clear(); +} +void Renderable2DComponent::setLayerOrder(const string& name, int order) +{ + for (auto& x : layers) + { + if (!x.name.compare(name)) + { + x.order = order; + break; + } + } + SortLayers(); +} +void Renderable2DComponent::SetSpriteOrder(wiSprite* sprite, int order) +{ + for (auto& x : layers) + { + for (auto& y : x.entities) + { + if (y.type == LayeredRenderEntity::SPRITE && y.sprite == sprite) + { + y.order = order; + } + } + } + SortLayers(); +} +void Renderable2DComponent::SetFontOrder(wiFont* font, int order) +{ + for (auto& x : layers) + { + for (auto& y : x.entities) + { + if (y.type == LayeredRenderEntity::FONT && y.font == font) + { + y.order = order; + } + } + } + SortLayers(); +} +void Renderable2DComponent::SortLayers() +{ + if (layers.empty()) + { + return; + } + + for (size_t i = 0; i < layers.size() - 1; ++i) + { + for (size_t j = i + 1; j < layers.size(); ++j) + { + if (layers[i].order > layers[j].order) + { + RenderLayer swap = layers[i]; + layers[i] = layers[j]; + layers[j] = swap; + } + } + } + for (auto& x : layers) + { + if (x.entities.empty()) + { + continue; + } + for (size_t i = 0; i < x.entities.size() - 1; ++i) + { + for (size_t j = i + 1; j < x.entities.size(); ++j) + { + if (x.entities[i].order > x.entities[j].order) + { + LayeredRenderEntity swap = x.entities[i]; + x.entities[i] = x.entities[j]; + x.entities[j] = swap; + } + } + } + } } diff --git a/WickedEngine/Renderable2DComponent.h b/WickedEngine/Renderable2DComponent.h index 48034b75a..33868745d 100644 --- a/WickedEngine/Renderable2DComponent.h +++ b/WickedEngine/Renderable2DComponent.h @@ -4,15 +4,46 @@ class wiSprite; class wiFont; +#define DEFAULT_RENDERLAYER "default" + +struct LayeredRenderEntity +{ + enum TYPE + { + SPRITE, + FONT, + } type; + wiSprite* sprite; + wiFont* font; + int order; + + LayeredRenderEntity() + { + type = SPRITE; + sprite = nullptr; + font = nullptr; + order = 0; + } +}; +struct RenderLayer +{ + vector entities; + string name; + int order; + + RenderLayer(const string& newName) + { + name = newName; + order = 0; + } +}; + class Renderable2DComponent : public RenderableComponent { private: float m_spriteSpeed; wiRenderTarget rtFinal; -protected: - list m_sprites; - list m_fonts; public: Renderable2DComponent(); ~Renderable2DComponent(); @@ -25,14 +56,21 @@ public: virtual void Render(); virtual void Compose(); - void addSprite(wiSprite* sprite); + void addSprite(wiSprite* sprite, const string& layer = DEFAULT_RENDERLAYER); void removeSprite(wiSprite* sprite); void clearSprites(); void setSpriteSpeed(float value){ m_spriteSpeed = value; } float getSpriteSpeed(){ return m_spriteSpeed; } - void addFont(wiFont* font); + void addFont(wiFont* font, const string& layer = DEFAULT_RENDERLAYER); void removeFont(wiFont* font); void clearFonts(); + + vector layers; + void addLayer(const string& name); + void setLayerOrder(const string& name, int order); + void SetSpriteOrder(wiSprite* sprite, int order); + void SetFontOrder(wiFont* font, int order); + void SortLayers(); }; diff --git a/WickedEngine/Renderable2DComponent_BindLua.cpp b/WickedEngine/Renderable2DComponent_BindLua.cpp index 9de390986..b302f49a0 100644 --- a/WickedEngine/Renderable2DComponent_BindLua.cpp +++ b/WickedEngine/Renderable2DComponent_BindLua.cpp @@ -13,7 +13,11 @@ Luna::FunctionType Renderable2DComponent_BindLua: lunamethod(Renderable2DComponent_BindLua, RemoveFont), lunamethod(Renderable2DComponent_BindLua, ClearSprites), lunamethod(Renderable2DComponent_BindLua, ClearFonts), - lunamethod(Renderable2DComponent_BindLua, AddFont), + lunamethod(Renderable2DComponent_BindLua, AddLayer), + lunamethod(Renderable2DComponent_BindLua, GetLayers), + lunamethod(Renderable2DComponent_BindLua, SetLayerOrder), + lunamethod(Renderable2DComponent_BindLua, SetSpriteOrder), + lunamethod(Renderable2DComponent_BindLua, SetFontOrder), lunamethod(Renderable2DComponent_BindLua, Initialize), lunamethod(Renderable2DComponent_BindLua, Load), lunamethod(Renderable2DComponent_BindLua, Unload), @@ -59,19 +63,22 @@ int Renderable2DComponent_BindLua::AddSprite(lua_State *L) Renderable2DComponent* ccomp = dynamic_cast(component); if (ccomp != nullptr) { - ccomp->addSprite(sprite->sprite); + if(argc>1) + ccomp->addSprite(sprite->sprite, wiLua::SGetString(L,2)); + else + ccomp->addSprite(sprite->sprite); } else { - wiLua::SError(L, "AddSprite(Sprite sprite) not a Renderable2DComponent!"); + wiLua::SError(L, "AddSprite(Sprite sprite, opt string layer) not a Renderable2DComponent!"); } } else - wiLua::SError(L, "AddSprite(Sprite sprite) argument is not a Sprite!"); + wiLua::SError(L, "AddSprite(Sprite sprite, opt string layer) argument is not a Sprite!"); } else { - wiLua::SError(L, "AddSprite(Sprite sprite) not enough arguments!"); + wiLua::SError(L, "AddSprite(Sprite sprite, opt string layer) not enough arguments!"); } return 0; } @@ -91,19 +98,22 @@ int Renderable2DComponent_BindLua::AddFont(lua_State* L) Renderable2DComponent* ccomp = dynamic_cast(component); if (ccomp != nullptr) { - ccomp->addFont(font->font); + if (argc > 1) + ccomp->addFont(font->font, wiLua::SGetString(L, 2)); + else + ccomp->addFont(font->font); } else { - wiLua::SError(L, "AddFont(Font font) not a Renderable2DComponent!"); + wiLua::SError(L, "AddFont(Font font, opt string layer) not a Renderable2DComponent!"); } } else - wiLua::SError(L, "AddFont(Font font) argument is not a Font!"); + wiLua::SError(L, "AddFont(Font font, opt string layer) argument is not a Font!"); } else { - wiLua::SError(L, "AddFont(Font font) not enough arguments!"); + wiLua::SError(L, "AddFont(Font font, opt string layer) not enough arguments!"); } return 0; } @@ -208,6 +218,153 @@ int Renderable2DComponent_BindLua::ClearFonts(lua_State* L) return 0; } +int Renderable2DComponent_BindLua::AddLayer(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "AddLayer() component is empty!"); + return 0; + } + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Renderable2DComponent* ccomp = dynamic_cast(component); + if (ccomp != nullptr) + { + ccomp->addLayer(wiLua::SGetString(L, 1)); + } + else + { + wiLua::SError(L, "AddLayer(string name) not a Renderable2DComponent!"); + } + } + else + { + wiLua::SError(L, "AddLayer(string name) not enough arguments!"); + } + return 0; +} +int Renderable2DComponent_BindLua::GetLayers(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "GetLayers() component is empty!"); + return 0; + } + + Renderable2DComponent* ccomp = dynamic_cast(component); + if (ccomp != nullptr) + { + stringstream ss(""); + for (auto& x : ccomp->layers) + { + ss << x.name << endl; + } + wiLua::SSetString(L, ss.str()); + return 1; + } + else + { + wiLua::SError(L, "GetLayers() not a Renderable2DComponent!"); + } + + return 0; +} +int Renderable2DComponent_BindLua::SetLayerOrder(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetLayerOrder() component is empty!"); + return 0; + } + int argc = wiLua::SGetArgCount(L); + if (argc > 1) + { + Renderable2DComponent* ccomp = dynamic_cast(component); + if (ccomp != nullptr) + { + ccomp->setLayerOrder(wiLua::SGetString(L, 1),wiLua::SGetInt(L,2)); + } + else + { + wiLua::SError(L, "SetLayerOrder(string name, int order) not a Renderable2DComponent!"); + } + } + else + { + wiLua::SError(L, "SetLayerOrder(string name, int order) not enough arguments!"); + } + return 0; +} +int Renderable2DComponent_BindLua::SetSpriteOrder(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetSpriteOrder() component is empty!"); + return 0; + } + int argc = wiLua::SGetArgCount(L); + if (argc > 1) + { + Renderable2DComponent* ccomp = dynamic_cast(component); + if (ccomp != nullptr) + { + wiSprite_BindLua* sprite = Luna::lightcheck(L, 1); + if (sprite != nullptr) + { + ccomp->SetSpriteOrder(sprite->sprite, wiLua::SGetInt(L, 2)); + } + else + { + wiLua::SError(L, "SetSpriteOrder(Sprite sprite, int order) argument is not a Sprite!"); + } + } + else + { + wiLua::SError(L, "SetSpriteOrder(Sprite sprite, int order) not a Renderable2DComponent!"); + } + } + else + { + wiLua::SError(L, "SetSpriteOrder(Sprite sprite, int order) not enough arguments!"); + } + return 0; +} +int Renderable2DComponent_BindLua::SetFontOrder(lua_State* L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetFontOrder() component is empty!"); + return 0; + } + int argc = wiLua::SGetArgCount(L); + if (argc > 1) + { + Renderable2DComponent* ccomp = dynamic_cast(component); + if (ccomp != nullptr) + { + wiFont_BindLua* font = Luna::lightcheck(L, 1); + if (font != nullptr) + { + ccomp->SetFontOrder(font->font, wiLua::SGetInt(L, 2)); + } + else + { + wiLua::SError(L, "SetFontOrder(Font font, int order) argument is not a Font!"); + } + } + else + { + wiLua::SError(L, "SetFontOrder(Font font, int order) not a Renderable2DComponent!"); + } + } + else + { + wiLua::SError(L, "SetFontOrder(Font font, int order) not enough arguments!"); + } + return 0; +} + void Renderable2DComponent_BindLua::Bind() { static bool initialized = false; diff --git a/WickedEngine/Renderable2DComponent_BindLua.h b/WickedEngine/Renderable2DComponent_BindLua.h index 080fe27e2..d5254968a 100644 --- a/WickedEngine/Renderable2DComponent_BindLua.h +++ b/WickedEngine/Renderable2DComponent_BindLua.h @@ -22,6 +22,12 @@ public: int ClearSprites(lua_State *L); int ClearFonts(lua_State* L); + int AddLayer(lua_State* L); + int GetLayers(lua_State* L); + int SetLayerOrder(lua_State* L); + int SetSpriteOrder(lua_State* L); + int SetFontOrder(lua_State* L); + static void Bind(); }; diff --git a/WickedEngine/Renderable3DComponent.cpp b/WickedEngine/Renderable3DComponent.cpp index c02851888..c1498f0f6 100644 --- a/WickedEngine/Renderable3DComponent.cpp +++ b/WickedEngine/Renderable3DComponent.cpp @@ -267,7 +267,7 @@ void Renderable3DComponent::RenderBloom(wiRenderer::DeviceContext context){ wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); - wiImage::BatchBegin(context); + //wiImage::BatchBegin(context); rtBloom[0].Activate(context); { @@ -312,7 +312,7 @@ void Renderable3DComponent::RenderLightShafts(wiRenderTarget& mainRT, wiRenderer wiRenderer::DrawSky(context); } - wiImage::BatchBegin(context); + //wiImage::BatchBegin(context); rtSun[1].Activate(context); { wiImageEffects fxs = fx; fxs.blendFlag = BLENDMODE_ADDITIVE; @@ -325,7 +325,7 @@ void Renderable3DComponent::RenderLightShafts(wiRenderTarget& mainRT, wiRenderer } void Renderable3DComponent::RenderComposition1(wiRenderTarget& shadedSceneRT, wiRenderer::DeviceContext context){ wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); - wiImage::BatchBegin(context); + //wiImage::BatchBegin(context); rtFinal[0].Activate(context); @@ -355,7 +355,7 @@ void Renderable3DComponent::RenderComposition1(wiRenderTarget& shadedSceneRT, wi void Renderable3DComponent::RenderComposition2(wiRenderer::DeviceContext context){ wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); fx.blendFlag = BLENDMODE_OPAQUE; - wiImage::BatchBegin(context); + //wiImage::BatchBegin(context); if (getDepthOfFieldEnabled()) { @@ -400,7 +400,7 @@ void Renderable3DComponent::RenderComposition2(wiRenderer::DeviceContext context void Renderable3DComponent::RenderColorGradedComposition(){ wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight()); - wiImage::BatchBegin(); + //wiImage::BatchBegin(); fx.blendFlag = BLENDMODE_OPAQUE; fx.quality = QUALITY_NEAREST; diff --git a/WickedEngine/Renderable3DComponent_BindLua.cpp b/WickedEngine/Renderable3DComponent_BindLua.cpp index 213d25b1d..481e9dd3d 100644 --- a/WickedEngine/Renderable3DComponent_BindLua.cpp +++ b/WickedEngine/Renderable3DComponent_BindLua.cpp @@ -11,6 +11,12 @@ Luna::FunctionType Renderable3DComponent_BindLua: lunamethod(Renderable2DComponent_BindLua, ClearSprites), lunamethod(Renderable2DComponent_BindLua, ClearFonts), + lunamethod(Renderable2DComponent_BindLua, AddLayer), + lunamethod(Renderable2DComponent_BindLua, GetLayers), + lunamethod(Renderable2DComponent_BindLua, SetLayerOrder), + lunamethod(Renderable2DComponent_BindLua, SetSpriteOrder), + lunamethod(Renderable2DComponent_BindLua, SetFontOrder), + lunamethod(Renderable3DComponent_BindLua, GetContent), lunamethod(Renderable3DComponent_BindLua, Initialize), lunamethod(Renderable3DComponent_BindLua, Load), diff --git a/WickedEngine/wiBackLog.cpp b/WickedEngine/wiBackLog.cpp index 434137eb9..e20185605 100644 --- a/WickedEngine/wiBackLog.cpp +++ b/WickedEngine/wiBackLog.cpp @@ -63,7 +63,7 @@ void wiBackLog::Update(){ } void wiBackLog::Draw(){ if(state!=DISABLED){ - wiImage::BatchBegin(); + //wiImage::BatchBegin(); wiImageEffects fx = wiImageEffects((float)wiRenderer::RENDERWIDTH, (float)wiRenderer::RENDERHEIGHT); fx.pos=XMFLOAT3(0,pos,0); fx.opacity = wiMath::Lerp(0, 1, pos / wiRenderer::RENDERHEIGHT); diff --git a/WickedEngine/wiFont_BindLua.cpp b/WickedEngine/wiFont_BindLua.cpp index 46804081b..120bbcdc4 100644 --- a/WickedEngine/wiFont_BindLua.cpp +++ b/WickedEngine/wiFont_BindLua.cpp @@ -78,10 +78,10 @@ int wiFont_BindLua::SetPos(lua_State* L) font->props.posY = XMVectorGetY(param->vector); } else - wiLua::SError(L, "SetSize(Vector size) argument is not a vector!"); + wiLua::SError(L, "SetSize(Vector pos) argument is not a vector!"); } else - wiLua::SError(L, "SetPos(Vector size) not enough arguments!"); + wiLua::SError(L, "SetPos(Vector pos) not enough arguments!"); return 0; } int wiFont_BindLua::SetSpacing(lua_State* L) @@ -96,10 +96,10 @@ int wiFont_BindLua::SetSpacing(lua_State* L) font->props.spacingY = XMVectorGetY(param->vector); } else - wiLua::SError(L, "SetSpacing(Vector size) argument is not a vector!"); + wiLua::SError(L, "SetSpacing(Vector spacing) argument is not a vector!"); } else - wiLua::SError(L, "SetSpacing(Vector size) not enough arguments!"); + wiLua::SError(L, "SetSpacing(Vector spacing) not enough arguments!"); return 0; } int wiFont_BindLua::SetAlign(lua_State* L) diff --git a/WickedEngine/wiImage.cpp b/WickedEngine/wiImage.cpp index c5c57a075..9aac80e4d 100644 --- a/WickedEngine/wiImage.cpp +++ b/WickedEngine/wiImage.cpp @@ -292,6 +292,28 @@ void wiImage::Draw(wiRenderer::TextureView texture, const wiImageEffects& effect void wiImage::Draw(wiRenderer::TextureView texture, const wiImageEffects& effects,ID3D11DeviceContext* context){ if(!context) return; + + { + // This equals the old BatchBegin + wiRenderer::BindPrimitiveTopology(wiRenderer::PRIMITIVETOPOLOGY::TRIANGLESTRIP, context); + wiRenderer::BindRasterizerState(rasterizerState, context); + switch (effects.stencilComp) + { + case D3D11_COMPARISON_LESS: + wiRenderer::BindDepthStencilState(depthStencilStateLess, effects.stencilRef, context); + break; + case D3D11_COMPARISON_GREATER: + wiRenderer::BindDepthStencilState(depthStencilStateGreater, effects.stencilRef, context); + break; + default: + wiRenderer::BindDepthStencilState(depthNoStencilState, effects.stencilRef, context); + break; + } + wiRenderer::BindBlendState(blendState, context); + wiRenderer::BindVS(vertexShader, context); + wiRenderer::BindPS(pixelShader, context); + } + if(!effects.blur){ if(!effects.process.active && !effects.bloom.separate && !effects.sunPos.x && !effects.sunPos.y){ ConstantBuffer cb; @@ -604,56 +626,56 @@ void wiImage::DrawDeferred(wiRenderer::TextureView texture wiRenderer::Draw(4,context); } - -void wiImage::BatchBegin() -{ - BatchBegin(wiRenderer::getImmediateContext()); -} -void wiImage::BatchBegin(ID3D11DeviceContext* context) -{ - //context->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP ); - - //context->RSSetState(rasterizerState); - //context->OMSetDepthStencilState(depthNoStencilState, 0); - - - wiRenderer::BindPrimitiveTopology(wiRenderer::PRIMITIVETOPOLOGY::TRIANGLESTRIP,context); - wiRenderer::BindRasterizerState(rasterizerState,context); - wiRenderer::BindDepthStencilState(depthNoStencilState, 0, context); - - - //float blendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - //UINT sampleMask = 0xffffffff; - //context->OMSetBlendState(blendState,blendFactor,sampleMask); - wiRenderer::BindBlendState(blendState,context); - - //context->VSSetShader( vertexShader, NULL, 0 ); - //context->PSSetShader( pixelShader, NULL, 0 ); - wiRenderer::BindVS(vertexShader,context); - wiRenderer::BindPS(pixelShader,context); -} -void wiImage::BatchBegin(ID3D11DeviceContext* context, unsigned int stencilref, bool stencilOpLess) -{ - //context->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP ); - - //context->RSSetState(rasterizerState); - //context->OMSetDepthStencilState(stencilOpLess?depthStencilStateLess:depthStencilStateGreater, stencilref); - - wiRenderer::BindPrimitiveTopology(wiRenderer::PRIMITIVETOPOLOGY::TRIANGLESTRIP,context); - wiRenderer::BindRasterizerState(rasterizerState,context); - wiRenderer::BindDepthStencilState(stencilOpLess?depthStencilStateLess:depthStencilStateGreater, stencilref, context); - - - //float blendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - //UINT sampleMask = 0xffffffff; - //context->OMSetBlendState(blendState,blendFactor,sampleMask); - wiRenderer::BindBlendState(blendState,context); - - //context->VSSetShader( vertexShader, NULL, 0 ); - //context->PSSetShader( pixelShader, NULL, 0 ); - wiRenderer::BindVS(vertexShader,context); - wiRenderer::BindPS(pixelShader,context); -} +// +//void wiImage::BatchBegin() +//{ +// BatchBegin(wiRenderer::getImmediateContext()); +//} +//void wiImage::BatchBegin(ID3D11DeviceContext* context) +//{ +// //context->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP ); +// +// //context->RSSetState(rasterizerState); +// //context->OMSetDepthStencilState(depthNoStencilState, 0); +// +// +// wiRenderer::BindPrimitiveTopology(wiRenderer::PRIMITIVETOPOLOGY::TRIANGLESTRIP,context); +// wiRenderer::BindRasterizerState(rasterizerState,context); +// wiRenderer::BindDepthStencilState(depthNoStencilState, 0, context); +// +// +// //float blendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; +// //UINT sampleMask = 0xffffffff; +// //context->OMSetBlendState(blendState,blendFactor,sampleMask); +// wiRenderer::BindBlendState(blendState,context); +// +// //context->VSSetShader( vertexShader, NULL, 0 ); +// //context->PSSetShader( pixelShader, NULL, 0 ); +// wiRenderer::BindVS(vertexShader,context); +// wiRenderer::BindPS(pixelShader,context); +//} +//void wiImage::BatchBegin(ID3D11DeviceContext* context, unsigned int stencilref, bool stencilOpLess) +//{ +// //context->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP ); +// +// //context->RSSetState(rasterizerState); +// //context->OMSetDepthStencilState(stencilOpLess?depthStencilStateLess:depthStencilStateGreater, stencilref); +// +// wiRenderer::BindPrimitiveTopology(wiRenderer::PRIMITIVETOPOLOGY::TRIANGLESTRIP,context); +// wiRenderer::BindRasterizerState(rasterizerState,context); +// wiRenderer::BindDepthStencilState(stencilOpLess?depthStencilStateLess:depthStencilStateGreater, stencilref, context); +// +// +// //float blendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; +// //UINT sampleMask = 0xffffffff; +// //context->OMSetBlendState(blendState,blendFactor,sampleMask); +// wiRenderer::BindBlendState(blendState,context); +// +// //context->VSSetShader( vertexShader, NULL, 0 ); +// //context->PSSetShader( pixelShader, NULL, 0 ); +// wiRenderer::BindVS(vertexShader,context); +// wiRenderer::BindPS(pixelShader,context); +//} void wiImage::Load(){ diff --git a/WickedEngine/wiImage.h b/WickedEngine/wiImage.h index cf5a25aa2..fdbd9ddf1 100644 --- a/WickedEngine/wiImage.h +++ b/WickedEngine/wiImage.h @@ -76,9 +76,13 @@ public: , ID3D11ShaderResourceView* depth, ID3D11ShaderResourceView* lightmap, ID3D11ShaderResourceView* normal , ID3D11ShaderResourceView* ao, ID3D11DeviceContext* context, int stencilref = 0); - static void BatchBegin(); - static void BatchBegin(ID3D11DeviceContext* context); - static void BatchBegin(ID3D11DeviceContext* context, unsigned int stencilref, bool stencilOpLess=true); + + //// DEPRECATED + //static void BatchBegin(); + //// DEPRECATED + //static void BatchBegin(ID3D11DeviceContext* context); + //// DEPRECATED + //static void BatchBegin(ID3D11DeviceContext* context, unsigned int stencilref, bool stencilOpLess=true); static void Load(); static void CleanUp(); diff --git a/WickedEngine/wiImageEffects.h b/WickedEngine/wiImageEffects.h index 798442dc7..228aeda18 100644 --- a/WickedEngine/wiImageEffects.h +++ b/WickedEngine/wiImageEffects.h @@ -26,7 +26,7 @@ enum Pivot{ CENTER, }; -class wiImageEffects{ +class wiImageEffects { public: XMFLOAT3 pos; XMFLOAT2 siz; @@ -37,29 +37,31 @@ public: XMFLOAT2 sunPos; XMFLOAT4 lookAt; //.w is for enabled float mirror; - float blur,blurDir; + float blur, blurDir; float fade; float opacity; float rotation; bool extractNormalMap; float mipLevel; - + unsigned int stencilRef; + int stencilComp; + BLENDMODE blendFlag; ImageType typeFlag; SAMPLEMODE sampleFlag; QUALITY quality; Pivot pivotFlag; - struct Bloom{ + struct Bloom { bool separate; float threshold; float saturation; - void clear(){separate=false;threshold=saturation=0;} - Bloom(){clear();} + void clear() { separate = false; threshold = saturation = 0; } + Bloom() { clear(); } }; Bloom bloom; - struct Processing{ + struct Processing { bool active; bool motionBlur; bool outline; @@ -70,70 +72,72 @@ public: bool ssr; bool linDepth; bool colorGrade; - - void clear(){active=motionBlur=outline=fxaa=ssao=linDepth=colorGrade=ssr=false;dofStrength=0;ssss=XMFLOAT2(0,0);} - void setDOF(float value){dofStrength=value;active=value>FLT_EPSILON;} - void setMotionBlur(bool value){motionBlur=value;active=value;} - void setOutline(bool value){outline=value;active=value;} - void setFXAA(bool value){fxaa=value;active=value;} - void setSSAO(bool value){ssao=value;active=value;} - void setLinDepth(bool value){linDepth=value;active=value;} - void setColorGrade(bool value){colorGrade=value;active=value;} + + void clear() { active = motionBlur = outline = fxaa = ssao = linDepth = colorGrade = ssr = false; dofStrength = 0; ssss = XMFLOAT2(0, 0); } + void setDOF(float value) { dofStrength = value; active = value > FLT_EPSILON; } + void setMotionBlur(bool value) { motionBlur = value; active = value; } + void setOutline(bool value) { outline = value; active = value; } + void setFXAA(bool value) { fxaa = value; active = value; } + void setSSAO(bool value) { ssao = value; active = value; } + void setLinDepth(bool value) { linDepth = value; active = value; } + void setColorGrade(bool value) { colorGrade = value; active = value; } //direction*Properties - void setSSSS(const XMFLOAT2& value){ssss=value;active=value.x||value.y;} - void setSSR(bool value){ ssr = value; active = value; } - Processing(){clear();} + void setSSSS(const XMFLOAT2& value) { ssss = value; active = value.x || value.y; } + void setSSR(bool value) { ssr = value; active = value; } + Processing() { clear(); } }; Processing process; bool deferred; - ID3D11ShaderResourceView *normalMap,*depthMap,*velocityMap,*refractionMap,*maskMap; - void setMaskMap(ID3D11ShaderResourceView*view){maskMap=view;} - void setRefractionMap(ID3D11ShaderResourceView*view){refractionMap=view;} - void setVelocityMap(ID3D11ShaderResourceView*view){velocityMap=view;} - void setDepthMap(ID3D11ShaderResourceView*view){depthMap=view;} - void setNormalMap(ID3D11ShaderResourceView*view){normalMap=view;} + ID3D11ShaderResourceView *normalMap, *depthMap, *velocityMap, *refractionMap, *maskMap; + void setMaskMap(ID3D11ShaderResourceView*view) { maskMap = view; } + void setRefractionMap(ID3D11ShaderResourceView*view) { refractionMap = view; } + void setVelocityMap(ID3D11ShaderResourceView*view) { velocityMap = view; } + void setDepthMap(ID3D11ShaderResourceView*view) { depthMap = view; } + void setNormalMap(ID3D11ShaderResourceView*view) { normalMap = view; } - void init(){ - pos=XMFLOAT3(0,0,0); - siz=XMFLOAT2(1,1); - scale=XMFLOAT2(1,1); - drawRec=XMFLOAT4(0,0,0,0); - texOffset=XMFLOAT2(0,0); - offset=XMFLOAT2(0,0); - sunPos=XMFLOAT2(0,0); - lookAt=XMFLOAT4(0,0,0,0); - mirror=1.0f; - blur=blurDir=fade=opacity=rotation=0.0f; - extractNormalMap=false; - mipLevel=0.f; - blendFlag=BLENDMODE_ALPHA; - typeFlag=SCREEN; - sampleFlag=SAMPLEMODE_MIRROR; - quality=QUALITY_BILINEAR; - pivotFlag=UPPERLEFT; - bloom=Bloom(); - process=Processing(); - deferred=false; - normalMap=nullptr; - depthMap=nullptr; - velocityMap=nullptr; - refractionMap=nullptr; - maskMap=nullptr; + void init() { + pos = XMFLOAT3(0, 0, 0); + siz = XMFLOAT2(1, 1); + scale = XMFLOAT2(1, 1); + drawRec = XMFLOAT4(0, 0, 0, 0); + texOffset = XMFLOAT2(0, 0); + offset = XMFLOAT2(0, 0); + sunPos = XMFLOAT2(0, 0); + lookAt = XMFLOAT4(0, 0, 0, 0); + mirror = 1.0f; + blur = blurDir = fade = opacity = rotation = 0.0f; + extractNormalMap = false; + mipLevel = 0.f; + stencilRef = 0; + stencilComp = 0; + blendFlag = BLENDMODE_ALPHA; + typeFlag = SCREEN; + sampleFlag = SAMPLEMODE_MIRROR; + quality = QUALITY_BILINEAR; + pivotFlag = UPPERLEFT; + bloom = Bloom(); + process = Processing(); + deferred = false; + normalMap = nullptr; + depthMap = nullptr; + velocityMap = nullptr; + refractionMap = nullptr; + maskMap = nullptr; } - wiImageEffects(){ + wiImageEffects() { init(); } - wiImageEffects(float width, float height){ + wiImageEffects(float width, float height) { init(); - siz=XMFLOAT2(width,height); + siz = XMFLOAT2(width, height); } - wiImageEffects(float posX, float posY, float width, float height){ + wiImageEffects(float posX, float posY, float width, float height) { init(); - pos.x=posX; - pos.y=posY; - siz=XMFLOAT2(width,height); + pos.x = posX; + pos.y = posY; + siz = XMFLOAT2(width, height); } }; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 79866001c..4ecae425c 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -391,6 +391,14 @@ void wiRenderer::SetUpStaticComponents() hullShader=NULL; domainShader=NULL; + thread t1(wiRenderer::LoadBasicShaders); + thread t2(wiRenderer::LoadShadowShaders); + thread t3(wiRenderer::LoadSkyShaders); + thread t4(wiRenderer::LoadLineShaders); + thread t5(wiRenderer::LoadTrailShaders); + thread t6(wiRenderer::LoadWaterShaders); + thread t7(wiRenderer::LoadTessShaders); + //cam = new Camera(SCREENWIDTH, SCREENHEIGHT, 0.1f, 800, XMVectorSet(0, 4, -4, 1)); cam = new Camera(); cam->SetUp(SCREENWIDTH, SCREENHEIGHT, 0.1f, 800); @@ -405,13 +413,7 @@ void wiRenderer::SetUpStaticComponents() debugSpheres=false; - wiRenderer::LoadBasicShaders(); - wiRenderer::LoadShadowShaders(); - wiRenderer::LoadSkyShaders(); - wiRenderer::LoadLineShaders(); - wiRenderer::LoadTrailShaders(); - wiRenderer::LoadWaterShaders(); - wiRenderer::LoadTessShaders(); + wiRenderer::SetUpStates(); wiRenderer::LoadBuffers(); @@ -459,6 +461,13 @@ void wiRenderer::SetUpStaticComponents() SetPointLightShadowProps(2, 512); SetSpotLightShadowProps(2, 512); + t1.join(); + t2.join(); + t3.join(); + t4.join(); + t5.join(); + t6.join(); + t7.join(); } void wiRenderer::CleanUpStatic() { @@ -1126,19 +1135,37 @@ void wiRenderer::LoadTrailShaders(){ void wiRenderer::ReloadShaders() { - // TODO + //// TODO : Also delete shaders from resourcemanager! + //wiResourceManager::GetGlobal()->del("shaders/effectVS10.cso"); + //wiResourceManager::GetGlobal()->del("shaders/sOVS.cso"); + //wiResourceManager::GetGlobal()->del("shaders/sOGS.cso"); + //wiResourceManager::GetGlobal()->del("shaders/effectVS.cso"); + //wiResourceManager::GetGlobal()->del("shaders/dirLightVS.cso"); + //wiResourceManager::GetGlobal()->del("shaders/pointLightVS.cso"); + //wiResourceManager::GetGlobal()->del("shaders/spotLightVS.cso"); + //wiResourceManager::GetGlobal()->del("shaders/vSpotLightVS.cso"); + //wiResourceManager::GetGlobal()->del("shaders/vPointLightVS.cso"); + //wiResourceManager::GetGlobal()->del("shaders/decalVS.cso"); + //wiResourceManager::GetGlobal()->del("shaders/effectPS.cso"); + //wiResourceManager::GetGlobal()->del("shaders/effectPS_transparent.cso"); + //wiResourceManager::GetGlobal()->del("shaders/effectPS_simplest.cso"); + //wiResourceManager::GetGlobal()->del("shaders/effectPS_forwardSimple.cso"); + //wiResourceManager::GetGlobal()->del("shaders/effectPS_blackout.cso"); + //wiResourceManager::GetGlobal()->del("shaders/effectPS_textureonly.cso"); + //wiResourceManager::GetGlobal()->del("shaders/dirLightPS.cso"); + //wiResourceManager::GetGlobal()->del("shaders/pointLightPS.cso"); + //wiResourceManager::GetGlobal()->del("shaders/spotLightPS.cso"); + //wiResourceManager::GetGlobal()->del("shaders/volumeLightPS.cso"); + //wiResourceManager::GetGlobal()->del("shaders/decalPS.cso"); + - //graphicsMutex.lock(); //LoadBasicShaders(); - //LoadLineShaders(); - //LoadTessShaders(); - //LoadSkyShaders(); - //LoadShadowShaders(); - //LoadWaterShaders(); - //LoadTrailShaders(); - //graphicsMutex.unlock(); - - //wiResourceManager::GetGlobal()->ReloadResources(wiResourceManager::Data_Type::PIXELSHADER); + ////LoadLineShaders(); + ////LoadTessShaders(); + ////LoadSkyShaders(); + ////LoadShadowShaders(); + ////LoadWaterShaders(); + ////LoadTrailShaders(); } @@ -2105,7 +2132,7 @@ void wiRenderer::ManageWaterRipples(){ waterRipples.pop_front(); } void wiRenderer::DrawWaterRipples(ID3D11DeviceContext* context){ - wiImage::BatchBegin(context); + //wiImage::BatchBegin(context); for(wiSprite* i:waterRipples){ i->DrawNormal(context); } @@ -2466,7 +2493,7 @@ void wiRenderer::DrawTrails(ID3D11DeviceContext* context, ID3D11ShaderResourceVi } void wiRenderer::DrawImagesAdd(ID3D11DeviceContext* context, ID3D11ShaderResourceView* refracRes){ imagesRTAdd.Activate(context,0,0,0,1); - wiImage::BatchBegin(context); + //wiImage::BatchBegin(context); for(wiSprite* x : images){ if(x->effects.blendFlag==BLENDMODE_ADDITIVE){ /*ID3D11ShaderResourceView* nor = x->effects.normalMap; @@ -2485,7 +2512,7 @@ void wiRenderer::DrawImagesAdd(ID3D11DeviceContext* context, ID3D11ShaderResourc } void wiRenderer::DrawImages(ID3D11DeviceContext* context, ID3D11ShaderResourceView* refracRes){ imagesRT.Activate(context,0,0,0,0); - wiImage::BatchBegin(context); + //wiImage::BatchBegin(context); for(wiSprite* x : images){ if(x->effects.blendFlag==BLENDMODE_ALPHA || x->effects.blendFlag==BLENDMODE_OPAQUE){ /*ID3D11ShaderResourceView* nor = x->effects.normalMap; @@ -2504,7 +2531,7 @@ void wiRenderer::DrawImages(ID3D11DeviceContext* context, ID3D11ShaderResourceVi } void wiRenderer::DrawImagesNormals(ID3D11DeviceContext* context, ID3D11ShaderResourceView* refracRes){ normalMapRT.Activate(context,0,0,0,0); - wiImage::BatchBegin(context); + //wiImage::BatchBegin(context); for(wiSprite* x : images){ x->DrawNormal(context); } diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 941ffbe0f..2afbc2340 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -836,8 +836,8 @@ public: context->OMGetBlendState(&b,nullptr,nullptr); if(b!=state){ #endif - float blendFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; - UINT sampleMask = 0xffffffff; + static float blendFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + static UINT sampleMask = 0xffffffff; context->OMSetBlendState(state,blendFactor,sampleMask); #ifdef API_CALL_STRICTNESS } @@ -845,6 +845,22 @@ public: #endif } } + inline static void BindBlendStateEx(BlendState state, const XMFLOAT4& blendFactor = XMFLOAT4(1,1,1,1), UINT sampleMask = 0xffffffff, + DeviceContext context = immediateContext) { + if (context != nullptr) { +#ifdef API_CALL_STRICTNESS + BlendState b; + context->OMGetBlendState(&b, nullptr, nullptr); + if (b != state) { +#endif + float fblendFactor[4] = { blendFactor.x, blendFactor.y, blendFactor.z, blendFactor.w }; + context->OMSetBlendState(state, fblendFactor, sampleMask); +#ifdef API_CALL_STRICTNESS + } + if (b != nullptr) b->Release(); +#endif + } + } inline static void BindDepthStencilState(DepthStencilState state, UINT stencilRef, DeviceContext context=immediateContext){ if(context!=nullptr){ #ifdef API_CALL_STRICTNESS diff --git a/WickedEngine/wiResourceManager.cpp b/WickedEngine/wiResourceManager.cpp index 6aa5c1718..e61978c81 100644 --- a/WickedEngine/wiResourceManager.cpp +++ b/WickedEngine/wiResourceManager.cpp @@ -276,27 +276,3 @@ bool wiResourceManager::CleanUp() MUTEX.unlock(); return true; } - -void wiResourceManager::ReloadResources(Data_Type type) -{ - //TODO - - vector reloadableNames(0); - vector reloadableTypes(0); - - - for (container::iterator it = resources.begin(); it != resources.end(); ++it) - { - if (it->second->type == type) - { - reloadableNames.push_back(it->first); - reloadableTypes.push_back(it->second->type); - } - } - - for (unsigned int i = 0; i < reloadableNames.size(); ++i) - { - del(reloadableNames[i]); - add(reloadableNames[i], reloadableTypes[i]); - } -} \ No newline at end of file diff --git a/WickedEngine/wiResourceManager.h b/WickedEngine/wiResourceManager.h index 65d7fbf7e..f3b353ead 100644 --- a/WickedEngine/wiResourceManager.h +++ b/WickedEngine/wiResourceManager.h @@ -41,8 +41,6 @@ public: ~wiResourceManager(); static wiResourceManager* GetGlobal(); - void ReloadResources(Data_Type type); - const Resource* get(const string& name); //specify datatype for shaders void* add(const string& name, Data_Type newType = Data_Type::DYNAMIC