diff --git a/Documentation/ScriptingAPI-Documentation.md b/Documentation/ScriptingAPI-Documentation.md index f2bd07f18..1f93b418f 100644 --- a/Documentation/ScriptingAPI-Documentation.md +++ b/Documentation/ScriptingAPI-Documentation.md @@ -106,7 +106,7 @@ You can use the Renderer with the following functions, all of which are in the g - GetRenderHeight(): float result - GetCameras() : string result - GetCamera(opt String name) : Camera result -- If string is provided, it will search a camera by name, otherwise, returns the main camera -- LoadModel(string fileName, opt Matrix transform) -- Load Model from file +- LoadModel(string fileName, opt Matrix transform) : int rootEntity -- Load Model from file. returns a root entity that everything in this model is attached to - LoadWorldInfo(string fileName) -- Loads world information from file - DuplicateInstance(Object object) : Object result -- Copies the specified object in the scene as an instanced mesh - SetEnvironmentMap(Texture cubemap) diff --git a/Editor/AnimationWindow.cpp b/Editor/AnimationWindow.cpp index dd8409446..c120957f5 100644 --- a/Editor/AnimationWindow.cpp +++ b/Editor/AnimationWindow.cpp @@ -149,7 +149,7 @@ void AnimationWindow::Update() } int selected = animationsComboBox->GetSelected(); - if (selected >= 0 && selected < scene.animations.GetCount()) + if (selected >= 0 && selected < (int)scene.animations.GetCount()) { AnimationComponent& animation = scene.animations[selected]; diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 9d29b725e..dabe8245f 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -31,17 +31,6 @@ using namespace wiRectPacker; using namespace wiSceneSystem; using namespace wiECS; -Editor::Editor() -{ - SAFE_INIT(renderComponent); - SAFE_INIT(loader); -} - -Editor::~Editor() -{ - //SAFE_DELETE(renderComponent); - //SAFE_DELETE(loader); -} void Editor::Initialize() { @@ -60,9 +49,9 @@ void Editor::Initialize() wiRenderer::GetDevice()->SetVSyncEnabled(true); wiRenderer::SetOcclusionCullingEnabled(true); - wiInputManager::GetInstance()->addXInput(new wiXInput()); + wiInputManager::addXInput(new wiXInput()); - wiProfiler::GetInstance().ENABLED = true; + wiProfiler::SetEnabled(true); renderComponent = new EditorComponent; renderComponent->Initialize(); @@ -152,68 +141,23 @@ void EditorComponent::ChangeRenderPath(RENDERPATH path) renderPath->Initialize(); renderPath->Load(); - DeleteWindows(); - - materialWnd = new MaterialWindow(&GetGUI()); - postprocessWnd = new PostprocessWindow(&GetGUI(), renderPath); - weatherWnd = new WeatherWindow(&GetGUI()); - objectWnd = new ObjectWindow(&GetGUI()); - meshWnd = new MeshWindow(&GetGUI()); - cameraWnd = new CameraWindow(&GetGUI()); - rendererWnd = new RendererWindow(&GetGUI(), renderPath); - envProbeWnd = new EnvProbeWindow(&GetGUI()); - decalWnd = new DecalWindow(&GetGUI()); - lightWnd = new LightWindow(&GetGUI()); - animWnd = new AnimationWindow(&GetGUI()); - emitterWnd = new EmitterWindow(&GetGUI()); - hairWnd = new HairParticleWindow(&GetGUI()); - forceFieldWnd = new ForceFieldWindow(&GetGUI()); - oceanWnd = new OceanWindow(&GetGUI()); -} -void EditorComponent::DeleteWindows() -{ - SAFE_DELETE(materialWnd); - SAFE_DELETE(postprocessWnd); - SAFE_DELETE(weatherWnd); - SAFE_DELETE(objectWnd); - SAFE_DELETE(meshWnd); - SAFE_DELETE(cameraWnd); - SAFE_DELETE(rendererWnd); - SAFE_DELETE(envProbeWnd); - SAFE_DELETE(decalWnd); - SAFE_DELETE(lightWnd); - SAFE_DELETE(animWnd); - SAFE_DELETE(emitterWnd); - SAFE_DELETE(hairWnd); - SAFE_DELETE(forceFieldWnd); - SAFE_DELETE(oceanWnd); + materialWnd.reset(new MaterialWindow(&GetGUI())); + postprocessWnd.reset(new PostprocessWindow(&GetGUI(), renderPath)); + weatherWnd.reset(new WeatherWindow(&GetGUI())); + objectWnd.reset(new ObjectWindow(&GetGUI())); + meshWnd.reset(new MeshWindow(&GetGUI())); + cameraWnd.reset(new CameraWindow(&GetGUI())); + rendererWnd.reset(new RendererWindow(&GetGUI(), renderPath)); + envProbeWnd.reset(new EnvProbeWindow(&GetGUI())); + decalWnd.reset(new DecalWindow(&GetGUI())); + lightWnd.reset(new LightWindow(&GetGUI())); + animWnd.reset(new AnimationWindow(&GetGUI())); + emitterWnd.reset(new EmitterWindow(&GetGUI())); + hairWnd.reset(new HairParticleWindow(&GetGUI())); + forceFieldWnd.reset(new ForceFieldWindow(&GetGUI())); + oceanWnd.reset(new OceanWindow(&GetGUI())); } -void EditorComponent::Initialize() -{ - SAFE_INIT(materialWnd); - SAFE_INIT(postprocessWnd); - SAFE_INIT(weatherWnd); - SAFE_INIT(objectWnd); - SAFE_INIT(meshWnd); - SAFE_INIT(cameraWnd); - SAFE_INIT(rendererWnd); - SAFE_INIT(envProbeWnd); - SAFE_INIT(decalWnd); - SAFE_INIT(lightWnd); - SAFE_INIT(animWnd); - SAFE_INIT(emitterWnd); - SAFE_INIT(hairWnd); - SAFE_INIT(forceFieldWnd); - SAFE_INIT(oceanWnd); - - - SAFE_INIT(loader); - SAFE_INIT(renderPath); - - - __super::Initialize(); -} void EditorComponent::Load() { __super::Load(); @@ -694,7 +638,7 @@ void EditorComponent::Load() renderPath->GetGUI().SetVisible(false); } GetGUI().SetVisible(false); - wiProfiler::GetInstance().ENABLED = false; + wiProfiler::SetEnabled(false); main->infoDisplay.active = false; }); GetGUI().AddWidget(cinemaModeCheckBox); @@ -763,21 +707,20 @@ void EditorComponent::FixedUpdate() } void EditorComponent::Update(float dt) { - wiInputManager& input = *wiInputManager::GetInstance(); Scene& scene = wiRenderer::GetScene(); CameraComponent& camera = wiRenderer::GetCamera(); animWnd->Update(); // Exit cinema mode: - if (input.down(VK_ESCAPE)) + if (wiInputManager::down(VK_ESCAPE)) { if (renderPath != nullptr) { renderPath->GetGUI().SetVisible(true); } GetGUI().SetVisible(true); - wiProfiler::GetInstance().ENABLED = true; + wiProfiler::SetEnabled(true); main->infoDisplay.active = true; cinemaModeCheckBox->SetCheck(false); @@ -788,35 +731,35 @@ void EditorComponent::Update(float dt) // Camera control: static XMFLOAT4 originalMouse = XMFLOAT4(0, 0, 0, 0); - XMFLOAT4 currentMouse = input.getpointer(); + XMFLOAT4 currentMouse = wiInputManager::getpointer(); float xDif = 0, yDif = 0; - if (input.down(VK_MBUTTON)) + if (wiInputManager::down(VK_MBUTTON)) { xDif = currentMouse.x - originalMouse.x; yDif = currentMouse.y - originalMouse.y; xDif = 0.1f*xDif*(1.0f / 60.0f); yDif = 0.1f*yDif*(1.0f / 60.0f); - input.setpointer(originalMouse); + wiInputManager::setpointer(originalMouse); } else { - originalMouse = input.getpointer(); + originalMouse = wiInputManager::getpointer(); } const float buttonrotSpeed = 2.0f / 60.0f; - if (input.down(VK_LEFT)) + if (wiInputManager::down(VK_LEFT)) { xDif -= buttonrotSpeed; } - if (input.down(VK_RIGHT)) + if (wiInputManager::down(VK_RIGHT)) { xDif += buttonrotSpeed; } - if (input.down(VK_UP)) + if (wiInputManager::down(VK_UP)) { yDif -= buttonrotSpeed; } - if (input.down(VK_DOWN)) + if (wiInputManager::down(VK_DOWN)) { yDif += buttonrotSpeed; } @@ -830,20 +773,20 @@ void EditorComponent::Update(float dt) // FPS Camera const float clampedDT = min(dt, 0.1f); // if dt > 100 millisec, don't allow the camera to jump too far... - const float speed = (input.down(VK_SHIFT) ? 10.0f : 1.0f) * cameraWnd->movespeedSlider->GetValue() * clampedDT; + const float speed = (wiInputManager::down(VK_SHIFT) ? 10.0f : 1.0f) * cameraWnd->movespeedSlider->GetValue() * clampedDT; static XMVECTOR move = XMVectorSet(0, 0, 0, 0); XMVECTOR moveNew = XMVectorSet(0, 0, 0, 0); - if (!input.down(VK_CONTROL)) + if (!wiInputManager::down(VK_CONTROL)) { // Only move camera if control not pressed - if (input.down('A')) { moveNew += XMVectorSet(-1, 0, 0, 0); } - if (input.down('D')) { moveNew += XMVectorSet(1, 0, 0, 0); } - if (input.down('W')) { moveNew += XMVectorSet(0, 0, 1, 0); } - if (input.down('S')) { moveNew += XMVectorSet(0, 0, -1, 0); } - if (input.down('E')) { moveNew += XMVectorSet(0, 1, 0, 0); } - if (input.down('Q')) { moveNew += XMVectorSet(0, -1, 0, 0); } + if (wiInputManager::down('A')) { moveNew += XMVectorSet(-1, 0, 0, 0); } + if (wiInputManager::down('D')) { moveNew += XMVectorSet(1, 0, 0, 0); } + if (wiInputManager::down('W')) { moveNew += XMVectorSet(0, 0, 1, 0); } + if (wiInputManager::down('S')) { moveNew += XMVectorSet(0, 0, -1, 0); } + if (wiInputManager::down('E')) { moveNew += XMVectorSet(0, 1, 0, 0); } + if (wiInputManager::down('Q')) { moveNew += XMVectorSet(0, -1, 0, 0); } moveNew = XMVector3Normalize(moveNew) * speed; } @@ -872,14 +815,14 @@ void EditorComponent::Update(float dt) { // Orbital Camera - if (input.down(VK_LSHIFT)) + if (wiInputManager::down(VK_LSHIFT)) { XMVECTOR V = XMVectorAdd(camera.GetRight() * xDif, camera.GetUp() * yDif) * 10; XMFLOAT3 vec; XMStoreFloat3(&vec, V); cameraWnd->camera_target.Translate(vec); } - else if (input.down(VK_LCONTROL)) + else if (wiInputManager::down(VK_LCONTROL)) { cameraWnd->camera_transform.Translate(XMFLOAT3(0, 0, yDif * 4)); camera.SetDirty(); @@ -1058,7 +1001,7 @@ void EditorComponent::Update(float dt) { if (object->GetRenderTypes() & RENDERTYPE_WATER) { - if (input.down(VK_LBUTTON)) + if (wiInputManager::down(VK_LBUTTON)) { // if water, then put a water ripple onto it: wiRenderer::PutWaterRipple(wiHelper::GetOriginalWorkingDirectory() + "images/ripple.png", hovered.position); @@ -1066,10 +1009,10 @@ void EditorComponent::Update(float dt) } else { - if (input.press(VK_LBUTTON)) + if (wiInputManager::press(VK_LBUTTON)) { SoftBodyPhysicsComponent* softBody = scene.softbodies.GetComponent(object->meshID); - if (softBody != nullptr && input.down('P')) + if (softBody != nullptr && wiInputManager::down('P')) { MeshComponent* mesh = scene.meshes.GetComponent(object->meshID); @@ -1104,7 +1047,7 @@ void EditorComponent::Update(float dt) } // Visualize soft body pinning: - if (input.down('P')) + if (wiInputManager::down('P')) { for (size_t i = 0; i < scene.softbodies.GetCount(); ++i) { @@ -1137,7 +1080,7 @@ void EditorComponent::Update(float dt) // Select... static bool selectAll = false; - if (input.press(VK_RBUTTON) || selectAll) + if (wiInputManager::press(VK_RBUTTON) || selectAll) { wiArchive* archive = AdvanceHistory(); @@ -1175,7 +1118,7 @@ void EditorComponent::Update(float dt) { // Add the hovered item to the selection: - if (!selected.empty() && input.down(VK_LSHIFT)) + if (!selected.empty() && wiInputManager::down(VK_LSHIFT)) { // Union selection: list saved = selected; @@ -1253,7 +1196,7 @@ void EditorComponent::Update(float dt) meshWnd->SetEntity(object->meshID); const MeshComponent* mesh = scene.meshes.GetComponent(object->meshID); - if (mesh != nullptr && mesh->subsets.size() > picked.subsetIndex) + if (mesh != nullptr && (int)mesh->subsets.size() > picked.subsetIndex) { materialWnd->SetEntity(mesh->subsets[picked.subsetIndex].materialID); } @@ -1267,7 +1210,7 @@ void EditorComponent::Update(float dt) } // Delete - if (input.press(VK_DELETE)) + if (wiInputManager::press(VK_DELETE)) { wiArchive* archive = AdvanceHistory(); @@ -1292,15 +1235,15 @@ void EditorComponent::Update(float dt) } // Control operations... - if (input.down(VK_CONTROL)) + if (wiInputManager::down(VK_CONTROL)) { // Select All - if (input.press('A')) + if (wiInputManager::press('A')) { selectAll = true; } // Copy - if (input.press('C')) + if (wiInputManager::press('C')) { SAFE_DELETE(clipboard); clipboard = new wiArchive(); @@ -1311,7 +1254,7 @@ void EditorComponent::Update(float dt) } } // Paste - if (input.press('V')) + if (wiInputManager::press('V')) { auto prevSel = selected; EndTranslate(); @@ -1329,7 +1272,7 @@ void EditorComponent::Update(float dt) BeginTranslate(); } // Duplicate Instances - if (input.press('D')) + if (wiInputManager::press('D')) { auto prevSel = selected; EndTranslate(); @@ -1342,7 +1285,7 @@ void EditorComponent::Update(float dt) BeginTranslate(); } // Put Instances - if (clipboard != nullptr && hovered.subsetIndex >= 0 && input.down(VK_LSHIFT) && input.press(VK_LBUTTON)) + if (clipboard != nullptr && hovered.subsetIndex >= 0 && wiInputManager::down(VK_LSHIFT) && wiInputManager::press(VK_LBUTTON)) { XMMATRIX M = XMLoadFloat4x4(&hovered.orientation); @@ -1361,12 +1304,12 @@ void EditorComponent::Update(float dt) } } // Undo - if (input.press('Z')) + if (wiInputManager::press('Z')) { ConsumeHistoryOperation(true); } // Redo - if (input.press('Y')) + if (wiInputManager::press('Y')) { ConsumeHistoryOperation(false); } @@ -1799,8 +1742,6 @@ void EditorComponent::Unload() { renderPath->Unload(); - DeleteWindows(); - __super::Unload(); } diff --git a/Editor/Editor.h b/Editor/Editor.h index 5d052b0ac..90e510b45 100644 --- a/Editor/Editor.h +++ b/Editor/Editor.h @@ -35,28 +35,28 @@ class EditorComponent : public Renderable2DComponent private: wiGraphicsTypes::Texture2D pointLightTex, spotLightTex, dirLightTex, areaLightTex, decalTex, forceFieldTex, emitterTex, hairTex, cameraTex, armatureTex; public: - MaterialWindow* materialWnd; - PostprocessWindow* postprocessWnd; - WeatherWindow* weatherWnd; - ObjectWindow* objectWnd; - MeshWindow* meshWnd; - CameraWindow* cameraWnd; - RendererWindow* rendererWnd; - EnvProbeWindow* envProbeWnd; - DecalWindow* decalWnd; - LightWindow* lightWnd; - AnimationWindow* animWnd; - EmitterWindow* emitterWnd; - HairParticleWindow* hairWnd; - ForceFieldWindow* forceFieldWnd; - OceanWindow* oceanWnd; + std::unique_ptr materialWnd; + std::unique_ptr postprocessWnd; + std::unique_ptr weatherWnd; + std::unique_ptr objectWnd; + std::unique_ptr meshWnd; + std::unique_ptr cameraWnd; + std::unique_ptr rendererWnd; + std::unique_ptr envProbeWnd; + std::unique_ptr decalWnd; + std::unique_ptr lightWnd; + std::unique_ptr animWnd; + std::unique_ptr emitterWnd; + std::unique_ptr hairWnd; + std::unique_ptr forceFieldWnd; + std::unique_ptr oceanWnd; - Editor* main; + Editor* main = nullptr; - wiCheckBox* cinemaModeCheckBox; + wiCheckBox* cinemaModeCheckBox = nullptr; - EditorLoadingScreen* loader; - Renderable3DComponent* renderPath; + EditorLoadingScreen* loader = nullptr; + Renderable3DComponent* renderPath = nullptr; enum RENDERPATH { RENDERPATH_FORWARD, @@ -66,9 +66,7 @@ public: RENDERPATH_PATHTRACING, }; void ChangeRenderPath(RENDERPATH path); - void DeleteWindows(); - void Initialize() override; void Load() override; void Start() override; void FixedUpdate() override; @@ -117,12 +115,12 @@ public: class Editor : public MainComponent { public: - Editor(); - ~Editor(); + Editor() {} + ~Editor() {} - EditorComponent* renderComponent; - EditorLoadingScreen* loader; + EditorComponent* renderComponent = nullptr; + EditorLoadingScreen* loader = nullptr; - void Initialize(); + void Initialize() override; }; diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp index ba1e7dc5f..a0e7400f6 100644 --- a/Editor/MaterialWindow.cpp +++ b/Editor/MaterialWindow.cpp @@ -352,7 +352,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) ofn.Flags = 0; if (GetSaveFileNameA(&ofn) == TRUE) { string fileName = ofn.lpstrFile; - material->baseColorMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); + material->baseColorMap = (Texture2D*)wiResourceManager::GetGlobal().add(fileName); material->baseColorMapName = wiHelper::GetFileNameFromPath(fileName); texture_baseColor_Button->SetText(material->baseColorMapName); } @@ -404,7 +404,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) ofn.Flags = 0; if (GetSaveFileNameA(&ofn) == TRUE) { string fileName = ofn.lpstrFile; - material->normalMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); + material->normalMap = (Texture2D*)wiResourceManager::GetGlobal().add(fileName); material->normalMapName = wiHelper::GetFileNameFromPath(fileName); texture_normal_Button->SetText(material->normalMapName); } @@ -456,7 +456,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) ofn.Flags = 0; if (GetSaveFileNameA(&ofn) == TRUE) { string fileName = ofn.lpstrFile; - material->surfaceMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); + material->surfaceMap = (Texture2D*)wiResourceManager::GetGlobal().add(fileName); material->surfaceMapName = wiHelper::GetFileNameFromPath(fileName); texture_surface_Button->SetText(material->surfaceMapName); } @@ -508,7 +508,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) ofn.Flags = 0; if (GetSaveFileNameA(&ofn) == TRUE) { string fileName = ofn.lpstrFile; - material->displacementMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); + material->displacementMap = (Texture2D*)wiResourceManager::GetGlobal().add(fileName); material->displacementMapName = wiHelper::GetFileNameFromPath(fileName); texture_displacement_Button->SetText(material->displacementMapName); } diff --git a/Editor/ModelImporter_GLTF.cpp b/Editor/ModelImporter_GLTF.cpp index b5a86428d..79fac4bd5 100644 --- a/Editor/ModelImporter_GLTF.cpp +++ b/Editor/ModelImporter_GLTF.cpp @@ -140,7 +140,7 @@ void RegisterTexture2D(tinygltf::Image *image) } // We loaded the texture2d, so register to the resource manager to be retrieved later: - wiResourceManager::GetGlobal()->Register(image->uri, tex, wiResourceManager::IMAGE); + wiResourceManager::GetGlobal().Register(image->uri, tex, wiResourceManager::IMAGE); } } } @@ -172,7 +172,7 @@ void LoadNode(tinygltf::Node* node, Entity parent, LoaderState& state) entity = state.scene.Entity_CreateObject(node->name); ObjectComponent& object = *state.scene.objects.GetComponent(entity); - if (node->mesh < state.meshArray.size()) + if (node->mesh < (int)state.meshArray.size()) { object.meshID = state.meshArray[node->mesh]; @@ -485,11 +485,11 @@ void ImportModel_GLTF(const std::string& fileName) // Retrieve textures by name: if (!material.baseColorMapName.empty()) - material.baseColorMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material.baseColorMapName); + material.baseColorMap = (Texture2D*)wiResourceManager::GetGlobal().add(material.baseColorMapName); if (!material.normalMapName.empty()) - material.normalMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material.normalMapName); + material.normalMap = (Texture2D*)wiResourceManager::GetGlobal().add(material.normalMapName); if (!material.surfaceMapName.empty()) - material.surfaceMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material.surfaceMapName); + material.surfaceMap = (Texture2D*)wiResourceManager::GetGlobal().add(material.surfaceMapName); if (baseColorFactor != x.values.end()) { diff --git a/Editor/ModelImporter_OBJ.cpp b/Editor/ModelImporter_OBJ.cpp index 65d1e666b..810942b5a 100644 --- a/Editor/ModelImporter_OBJ.cpp +++ b/Editor/ModelImporter_OBJ.cpp @@ -65,19 +65,19 @@ void ImportModel_OBJ(const std::string& fileName) if (!material.surfaceMapName.empty()) { - material.surfaceMap = (Texture2D*)wiResourceManager::GetGlobal()->add(directory + material.surfaceMapName); + material.surfaceMap = (Texture2D*)wiResourceManager::GetGlobal().add(directory + material.surfaceMapName); } if (!material.baseColorMapName.empty()) { - material.baseColorMap = (Texture2D*)wiResourceManager::GetGlobal()->add(directory + material.baseColorMapName); + material.baseColorMap = (Texture2D*)wiResourceManager::GetGlobal().add(directory + material.baseColorMapName); } if (!material.normalMapName.empty()) { - material.normalMap = (Texture2D*)wiResourceManager::GetGlobal()->add(directory + material.normalMapName); + material.normalMap = (Texture2D*)wiResourceManager::GetGlobal().add(directory + material.normalMapName); } if (!material.displacementMapName.empty()) { - material.displacementMap = (Texture2D*)wiResourceManager::GetGlobal()->add(directory + material.displacementMapName); + material.displacementMap = (Texture2D*)wiResourceManager::GetGlobal().add(directory + material.displacementMapName); } materialLibrary.push_back(materialEntity); // for subset-indexing... diff --git a/Editor/PostprocessWindow.cpp b/Editor/PostprocessWindow.cpp index b62ab0952..4e8dd6b77 100644 --- a/Editor/PostprocessWindow.cpp +++ b/Editor/PostprocessWindow.cpp @@ -185,8 +185,8 @@ PostprocessWindow::PostprocessWindow(wiGUI* gui, Renderable3DComponent* comp) : ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if (GetOpenFileNameA(&ofn) == TRUE) { string fileName = ofn.lpstrFile; - //wiRenderer::SetColorGrading((Texture2D*)wiResourceManager::GetGlobal()->add(fileName)); - component->setColorGradingTexture((Texture2D*)wiResourceManager::GetGlobal()->add(fileName)); + //wiRenderer::SetColorGrading((Texture2D*)wiResourceManager::GetGlobal().add(fileName)); + component->setColorGradingTexture((Texture2D*)wiResourceManager::GetGlobal().add(fileName)); if (component->getColorGradingTexture() != nullptr) { colorGradingButton->SetText(fileName); diff --git a/Editor/Translator.cpp b/Editor/Translator.cpp index 63279e846..a86650b8a 100644 --- a/Editor/Translator.cpp +++ b/Editor/Translator.cpp @@ -210,7 +210,7 @@ void Translator::Update() dragStarted = false; dragEnded = false; - XMFLOAT4 pointer = wiInputManager::GetInstance()->getpointer(); + XMFLOAT4 pointer = wiInputManager::getpointer(); const CameraComponent& cam = wiRenderer::GetCamera(); XMVECTOR pos = transform.GetPositionV(); @@ -292,7 +292,7 @@ void Translator::Update() } } - if (dragging || (state != TRANSLATOR_IDLE && wiInputManager::GetInstance()->down(VK_LBUTTON))) + if (dragging || (state != TRANSLATOR_IDLE && wiInputManager::down(VK_LBUTTON))) { XMVECTOR plane, planeNormal; if (state == TRANSLATOR_X) @@ -410,7 +410,7 @@ void Translator::Update() dragging = true; } - if (!wiInputManager::GetInstance()->down(VK_LBUTTON)) + if (!wiInputManager::down(VK_LBUTTON)) { if (dragging) { diff --git a/Editor/WeatherWindow.cpp b/Editor/WeatherWindow.cpp index 976fc8ccf..ebb2e41c7 100644 --- a/Editor/WeatherWindow.cpp +++ b/Editor/WeatherWindow.cpp @@ -111,7 +111,7 @@ WeatherWindow::WeatherWindow(wiGUI* gui) : GUI(gui) ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if (GetOpenFileNameA(&ofn) == TRUE) { string fileName = ofn.lpstrFile; - wiRenderer::SetEnvironmentMap((Texture2D*)wiResourceManager::GetGlobal()->add(fileName)); + wiRenderer::SetEnvironmentMap((Texture2D*)wiResourceManager::GetGlobal().add(fileName)); skyButton->SetText(fileName); } } diff --git a/Editor/main.cpp b/Editor/main.cpp index 6214cbbe5..cf2190176 100644 --- a/Editor/main.cpp +++ b/Editor/main.cpp @@ -226,9 +226,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_MOUSEWHEEL: { - XMFLOAT4 pointer = wiInputManager::GetInstance()->getpointer(); + XMFLOAT4 pointer = wiInputManager::getpointer(); float delta = GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA; - wiInputManager::GetInstance()->setpointer(XMFLOAT4(pointer.x, pointer.y, delta, 0)); + wiInputManager::setpointer(XMFLOAT4(pointer.x, pointer.y, delta, 0)); } break; case WM_KEYDOWN: diff --git a/Tests/test_script.lua b/Tests/test_script.lua index 54ce89f20..277af14d1 100644 --- a/Tests/test_script.lua +++ b/Tests/test_script.lua @@ -4,7 +4,7 @@ debugout("Begin script: test_script.lua"); -- Load a model: -LoadModel("../models/teapot.wiscene"); +local parent = LoadModel("../models/teapot.wiscene"); LoadModel("../models/cameras.wiscene"); -- Load camera sample script: @@ -29,17 +29,17 @@ runProcess(function() -- This shows how to handle attachments: - -- Create parent transform, this will be rotated: - local parent = CreateEntity(); - scene.Component_CreateTransform(parent); - - -- Retrieve teapot base and lid entity IDs: - local teapot_base = scene.Entity_FindByName("Base"); - local teapot_top = scene.Entity_FindByName("Top"); - - -- Attach base to parent, lid to base: - scene.Component_Attach(teapot_base, parent); - scene.Component_Attach(teapot_top, teapot_base); + -- -- Create parent transform, this will be rotated: + -- local parent = CreateEntity(); + -- scene.Component_CreateTransform(parent); + -- + -- -- Retrieve teapot base and lid entity IDs: + -- local teapot_base = scene.Entity_FindByName("Base"); + -- local teapot_top = scene.Entity_FindByName("Top"); + -- + -- -- Attach base to parent, lid to base: + -- scene.Component_Attach(teapot_base, parent); + -- scene.Component_Attach(teapot_top, teapot_base); while(true) do diff --git a/WickedEngine/CommonInclude.h b/WickedEngine/CommonInclude.h index 42cef9297..99d68303e 100644 --- a/WickedEngine/CommonInclude.h +++ b/WickedEngine/CommonInclude.h @@ -27,7 +27,6 @@ using namespace DirectX; using namespace DirectX::PackedVector; #define ALIGN_16 void* operator new(size_t i){return _mm_malloc(i, 16);} void operator delete(void* p){_mm_free(p);} -#define SAFE_INIT(a) (a) = nullptr; #define SAFE_RELEASE(a) if((a)!=nullptr){(a)->Release();(a)=nullptr;} #define SAFE_DELETE(a) if((a)!=nullptr){delete (a);(a)=nullptr;} #define SAFE_DELETE_ARRAY(a) if((a)!=nullptr){delete[](a);(a)=nullptr;} diff --git a/WickedEngine/DeferredRenderableComponent.cpp b/WickedEngine/DeferredRenderableComponent.cpp index 0011dc4d2..1f6619880 100644 --- a/WickedEngine/DeferredRenderableComponent.cpp +++ b/WickedEngine/DeferredRenderableComponent.cpp @@ -97,7 +97,7 @@ void DeferredRenderableComponent::Render() void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) { - wiProfiler::GetInstance().BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID); wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID); @@ -108,7 +108,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) rtGBuffer.Activate(threadID, 0, 0, 0, 0); { - wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); + wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); wiRenderer::DrawWorld(wiRenderer::GetCamera(), getTessellationEnabled(), threadID, SHADERTYPE_DEFERRED, getHairParticlesEnabled(), true, getLayerMask()); } @@ -148,7 +148,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) rtLight.Activate(threadID, rtGBuffer.depth); { - wiRenderer::GetDevice()->BindResource(PS, getSSREnabled() ? rtSSR.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID); + wiRenderer::GetDevice()->BindResource(PS, getSSREnabled() ? rtSSR.GetTexture() : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID); wiRenderer::DrawLights(wiRenderer::GetCamera(), threadID); } @@ -160,7 +160,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) fx.stencilComp = STENCILMODE_LESS; rtSSAO[0].Activate(threadID); { fx.process.setSSAO(true); - fx.setMaskMap(wiTextureHelper::getInstance()->getRandom64x64()); + fx.setMaskMap(wiTextureHelper::getRandom64x64()); fx.quality = QUALITY_BILINEAR; fx.sampleFlag = SAMPLEMODE_MIRROR; wiImage::Draw(nullptr, fx, threadID); @@ -242,7 +242,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) rtDeferred.Activate(threadID, rtGBuffer.depth); { wiImage::DrawDeferred((getSSSEnabled() ? rtSSS[0].GetTexture(0) : rtLight.GetTexture(0)), rtLight.GetTexture(1) - , getSSAOEnabled() ? rtSSAO.back().GetTexture() : wiTextureHelper::getInstance()->getWhite() + , getSSAOEnabled() ? rtSSAO.back().GetTexture() : wiTextureHelper::getWhite() , threadID, STENCILREF_DEFAULT); wiRenderer::DrawSky(threadID); } @@ -262,7 +262,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) wiRenderer::GetDevice()->EventEnd(threadID); } - wiProfiler::GetInstance().EndRange(threadID); // Opaque Scene + wiProfiler::EndRange(threadID); // Opaque Scene } wiRenderTarget& DeferredRenderableComponent::GetFinalRT() diff --git a/WickedEngine/ForwardRenderableComponent.cpp b/WickedEngine/ForwardRenderableComponent.cpp index 69c0dc303..f4f63fdb0 100644 --- a/WickedEngine/ForwardRenderableComponent.cpp +++ b/WickedEngine/ForwardRenderableComponent.cpp @@ -79,7 +79,7 @@ void ForwardRenderableComponent::Render() void ForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) { - wiProfiler::GetInstance().BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID); wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID); @@ -90,9 +90,9 @@ void ForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) rtMain.Activate(threadID, 0, 0, 0, 0); { - wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); - wiRenderer::GetDevice()->BindResource(PS, getSSAOEnabled() ? rtSSAO.back().GetTexture() : wiTextureHelper::getInstance()->getWhite(), TEXSLOT_RENDERABLECOMPONENT_SSAO, threadID); - wiRenderer::GetDevice()->BindResource(PS, getSSREnabled() ? rtSSR.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID); + wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); + wiRenderer::GetDevice()->BindResource(PS, getSSAOEnabled() ? rtSSAO.back().GetTexture() : wiTextureHelper::getWhite(), TEXSLOT_RENDERABLECOMPONENT_SSAO, threadID); + wiRenderer::GetDevice()->BindResource(PS, getSSREnabled() ? rtSSR.GetTexture() : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID); wiRenderer::DrawWorld(wiRenderer::GetCamera(), getTessellationEnabled(), threadID, SHADERTYPE_FORWARD, getHairParticlesEnabled(), true, getLayerMask()); wiRenderer::DrawSky(threadID); } @@ -125,7 +125,7 @@ void ForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) fx.stencilComp = STENCILMODE_LESS; rtSSAO[0].Activate(threadID); { fx.process.setSSAO(true); - fx.setMaskMap(wiTextureHelper::getInstance()->getRandom64x64()); + fx.setMaskMap(wiTextureHelper::getRandom64x64()); fx.quality = QUALITY_BILINEAR; fx.sampleFlag = SAMPLEMODE_MIRROR; wiImage::Draw(nullptr, fx, threadID); @@ -163,7 +163,7 @@ void ForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) wiRenderer::GetDevice()->EventEnd(threadID); } - wiProfiler::GetInstance().EndRange(threadID); // Opaque Scene + wiProfiler::EndRange(threadID); // Opaque Scene } wiDepthTarget* ForwardRenderableComponent::GetDepthBuffer() diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index f7655e546..b0adff690 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -66,7 +66,9 @@ void MainComponent::Initialize() } wiRenderer::SetDevice(new GraphicsDevice_DX12(window, fullscreen, debugdevice)); } - else + + // default graphics device: + if (wiRenderer::GetDevice() == nullptr) { wiRenderer::SetDevice(new GraphicsDevice_DX11(window, fullscreen, debugdevice)); } @@ -109,58 +111,72 @@ void MainComponent::Run() return; } - wiProfiler::GetInstance().BeginFrame(); - wiProfiler::GetInstance().BeginRange("CPU Frame", wiProfiler::DOMAIN_CPU); + wiProfiler::BeginFrame(); + wiProfiler::BeginRange("CPU Frame", wiProfiler::DOMAIN_CPU); - wiInputManager::GetInstance()->Update(); + wiInputManager::Update(); - static wiTimer timer = wiTimer(); - static double accumulator = 0.0; - const double elapsedTime = max(0, timer.elapsed() / 1000.0); + deltaTime = float(max(0, timer.elapsed() / 1000.0)); timer.record(); - fadeManager.Update((float)elapsedTime); - - // Fixed time update: - wiProfiler::GetInstance().BeginRange("Fixed Update", wiProfiler::DOMAIN_CPU); - if (frameskip) + if (wiWindowRegistration::IsWindowActive()) { - accumulator += elapsedTime; - if (!wiWindowRegistration::GetInstance()->IsWindowActive() || accumulator > applicationControlLostThreshold) //application probably lost control - accumulator = 0; + // If the application is active, run Update loops: - while (accumulator >= targetFrameRateInv) + fadeManager.Update(deltaTime); + + // Fixed time update: + wiProfiler::BeginRange("Fixed Update", wiProfiler::DOMAIN_CPU); { - FixedUpdate(); - accumulator -= targetFrameRateInv; + if (frameskip) + { + deltaTimeAccumulator += deltaTime; + if (deltaTimeAccumulator > 10) + { + // application probably lost control, fixed update would be take long + deltaTimeAccumulator = 0; + } + + const float targetFrameRateInv = 1.0f / targetFrameRate; + while (deltaTimeAccumulator >= targetFrameRateInv) + { + FixedUpdate(); + deltaTimeAccumulator -= targetFrameRateInv; + } + } + else + { + FixedUpdate(); + } } + wiProfiler::EndRange(); // Fixed Update + + wiLua::GetGlobal()->SetDeltaTime(double(deltaTime)); + + // Variable-timed update: + wiProfiler::BeginRange("Update", wiProfiler::DOMAIN_CPU); + Update(deltaTime); + wiProfiler::EndRange(); // Update } else { - FixedUpdate(); + // If the application is not active, disable Update loops: + deltaTimeAccumulator = 0; + wiLua::GetGlobal()->SetDeltaTime(0); } - wiProfiler::GetInstance().EndRange(); // Fixed Update - wiLua::GetGlobal()->SetDeltaTime(elapsedTime); - - // Variable-timed update: - wiProfiler::GetInstance().BeginRange("Update", wiProfiler::DOMAIN_CPU); - Update((float)elapsedTime); - wiProfiler::GetInstance().EndRange(); // Update - - - wiProfiler::GetInstance().BeginRange("Render", wiProfiler::DOMAIN_CPU); + wiProfiler::BeginRange("Render", wiProfiler::DOMAIN_CPU); Render(); - wiProfiler::GetInstance().EndRange(); // Render + wiProfiler::EndRange(); // Render - wiProfiler::GetInstance().EndRange(); // CPU Frame + wiProfiler::EndRange(); // CPU Frame - wiProfiler::GetInstance().BeginRange("Compose", wiProfiler::DOMAIN_CPU); + wiProfiler::BeginRange("Compose", wiProfiler::DOMAIN_CPU); wiRenderer::GetDevice()->PresentBegin(); Compose(); wiRenderer::GetDevice()->PresentEnd(); - wiProfiler::GetInstance().EndRange(); // Compose + wiProfiler::EndRange(); // Compose wiRenderer::EndFrame(); @@ -170,7 +186,7 @@ void MainComponent::Run() startupScriptProcessed = true; } - wiProfiler::GetInstance().EndFrame(); + wiProfiler::EndFrame(); } void MainComponent::Update(float dt) @@ -193,12 +209,12 @@ void MainComponent::Render() { wiLua::GetGlobal()->Render(); - wiProfiler::GetInstance().BeginRange("GPU Frame", wiProfiler::DOMAIN_GPU, GRAPHICSTHREAD_IMMEDIATE); + wiProfiler::BeginRange("GPU Frame", wiProfiler::DOMAIN_GPU, GRAPHICSTHREAD_IMMEDIATE); wiRenderer::BindPersistentState(GRAPHICSTHREAD_IMMEDIATE); wiImage::BindPersistentState(GRAPHICSTHREAD_IMMEDIATE); wiFont::BindPersistentState(GRAPHICSTHREAD_IMMEDIATE); getActiveComponent()->Render(); - wiProfiler::GetInstance().EndRange(GRAPHICSTHREAD_IMMEDIATE); // GPU Frame + wiProfiler::EndRange(GRAPHICSTHREAD_IMMEDIATE); // GPU Frame } void MainComponent::Compose() @@ -212,7 +228,7 @@ void MainComponent::Compose() fx.siz.x = (float)wiRenderer::GetDevice()->GetScreenWidth(); fx.siz.y = (float)wiRenderer::GetDevice()->GetScreenHeight(); fx.opacity = fadeManager.opacity; - wiImage::Draw(wiTextureHelper::getInstance()->getColor(fadeManager.color), fx, GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(wiTextureHelper::getColor(fadeManager.color), fx, GRAPHICSTHREAD_IMMEDIATE); } // Draw the information display @@ -274,7 +290,7 @@ void MainComponent::Compose() wiFont(ss.str(), wiFontProps(4, 4, infoDisplay.size, WIFALIGN_LEFT, WIFALIGN_TOP, 0, 0, wiColor(255,255,255,255), wiColor(0,0,0,255))).Draw(GRAPHICSTHREAD_IMMEDIATE); } - wiProfiler::GetInstance().DrawData(4, 120, GRAPHICSTHREAD_IMMEDIATE); + wiProfiler::DrawData(4, 120, GRAPHICSTHREAD_IMMEDIATE); wiBackLog::Draw(); } @@ -293,7 +309,7 @@ bool MainComponent::SetWindow(wiWindowRegistration::window_type window, HINSTANC screenH = rect.bottom - rect.top; } - wiWindowRegistration::GetInstance()->RegisterWindow(window); + wiWindowRegistration::RegisterWindow(window); return true; } @@ -305,7 +321,7 @@ bool MainComponent::SetWindow(wiWindowRegistration::window_type window) this->window = window; - wiWindowRegistration::GetInstance()->RegisterWindow(window); + wiWindowRegistration::RegisterWindow(window); return true; } diff --git a/WickedEngine/MainComponent.h b/WickedEngine/MainComponent.h index 3b793251a..00bf76e67 100644 --- a/WickedEngine/MainComponent.h +++ b/WickedEngine/MainComponent.h @@ -11,13 +11,14 @@ class MainComponent { private: RenderableComponent* activeComponent = nullptr; + float targetFrameRate = 60; bool frameskip = true; - int targetFrameRate = 60; - double targetFrameRateInv = 1.0f / 60.0f; - int applicationControlLostThreshold = 10; - bool component_dirty = true; wiFadeManager fadeManager; + + float deltaTime = 0; + float deltaTimeAccumulator = 0; + wiTimer timer; public: MainComponent(); virtual ~MainComponent(); @@ -34,11 +35,14 @@ public: wiResourceManager Content; - void setFrameSkip(bool value){ frameskip = value; } - bool getFrameSkip(){ return frameskip; } - void setTargetFrameRate(int value){ targetFrameRate = value; targetFrameRateInv = 1.0 / (double)targetFrameRate; } - int getTargetFrameRate(){ return targetFrameRate; } - void setApplicationControlLostThreshold(int value){ applicationControlLostThreshold = value; } + // Set the desired target framerate for the FixedUpdate() loop (default = 60) + void setTargetFrameRate(float value) { targetFrameRate = value; } + // Get the desired target framerate for the FixedUpdate() loop + float getTargetFrameRate() const { return targetFrameRate; } + // Set the desired behaviour of the FixedUpdate() loop (default = true) + // enabled : the FixedUpdate() loop will run at targetFrameRate frequency + // disabled : the FixedUpdate() loop will run every frame only once. + void setFrameSkip(bool enabled) { frameskip = enabled; } // Initializes all engine components virtual void Initialize(); diff --git a/WickedEngine/MainComponent_BindLua.cpp b/WickedEngine/MainComponent_BindLua.cpp index fe1a3a945..e52a9c68d 100644 --- a/WickedEngine/MainComponent_BindLua.cpp +++ b/WickedEngine/MainComponent_BindLua.cpp @@ -323,7 +323,7 @@ int SetProfilerEnabled(lua_State* L) int argc = wiLua::SGetArgCount(L); if (argc > 0) { - wiProfiler::GetInstance().ENABLED = wiLua::SGetBool(L, 1); + wiProfiler::SetEnabled(wiLua::SGetBool(L, 1)); } else wiLua::SError(L, "SetProfilerEnabled(bool active) not enough arguments!"); diff --git a/WickedEngine/PathTracingRenderableComponent.cpp b/WickedEngine/PathTracingRenderableComponent.cpp index 684a04f25..81d230f7e 100644 --- a/WickedEngine/PathTracingRenderableComponent.cpp +++ b/WickedEngine/PathTracingRenderableComponent.cpp @@ -137,7 +137,7 @@ void PathTracingRenderableComponent::RenderFrameSetUp(GRAPHICSTHREAD threadID) void PathTracingRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) { - wiProfiler::GetInstance().BeginRange("Traced Scene", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Traced Scene", wiProfiler::DOMAIN_GPU, threadID); wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID); @@ -158,7 +158,7 @@ void PathTracingRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) wiImage::Draw(traceResult, fx, threadID); - wiProfiler::GetInstance().EndRange(threadID); // Traced Scene + wiProfiler::EndRange(threadID); // Traced Scene } void PathTracingRenderableComponent::Compose() @@ -170,8 +170,8 @@ void PathTracingRenderableComponent::Compose() fx.blendFlag = BLENDMODE_OPAQUE; fx.quality = QUALITY_BILINEAR; fx.process.setToneMap(true); - fx.setDistortionMap(wiTextureHelper::getInstance()->getBlack()); // tonemap shader uses signed distortion mask, so black = no distortion - fx.setMaskMap(wiTextureHelper::getInstance()->getColor(wiColor::Gray)); + fx.setDistortionMap(wiTextureHelper::getBlack()); // tonemap shader uses signed distortion mask, so black = no distortion + fx.setMaskMap(wiTextureHelper::getColor(wiColor::Gray)); wiImage::Draw(rtAccumulation.GetTexture(), fx, GRAPHICSTHREAD_IMMEDIATE); diff --git a/WickedEngine/Renderable3DComponent.cpp b/WickedEngine/Renderable3DComponent.cpp index a60e26650..10ab8d4a3 100644 --- a/WickedEngine/Renderable3DComponent.cpp +++ b/WickedEngine/Renderable3DComponent.cpp @@ -266,7 +266,7 @@ void Renderable3DComponent::RenderReflections(GRAPHICSTHREAD threadID) { return; } - wiProfiler::GetInstance().BeginRange("Reflection rendering", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Reflection rendering", wiProfiler::DOMAIN_GPU, threadID); if (wiRenderer::IsRequestedReflectionRendering()) { @@ -292,7 +292,7 @@ void Renderable3DComponent::RenderReflections(GRAPHICSTHREAD threadID) } } - wiProfiler::GetInstance().EndRange(); // Reflection Rendering + wiProfiler::EndRange(); // Reflection Rendering } void Renderable3DComponent::RenderShadows(GRAPHICSTHREAD threadID) { @@ -344,7 +344,7 @@ void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRende // We don't need the following for stereograms... return; } - wiProfiler::GetInstance().BeginRange("Secondary Scene", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Secondary Scene", wiProfiler::DOMAIN_GPU, threadID); XMVECTOR sunDirection = XMLoadFloat3(&wiRenderer::GetScene().weather.sunDirection); if (getLightShaftsEnabled() && XMVectorGetX(XMVector3Dot(sunDirection, wiRenderer::GetCamera().GetAt())) > 0) @@ -444,18 +444,18 @@ void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRende wiRenderer::DrawSoftParticles(wiRenderer::GetCamera(), true, threadID); } - wiProfiler::GetInstance().EndRange(threadID); // Secondary Scene + wiProfiler::EndRange(threadID); // Secondary Scene } void Renderable3DComponent::RenderTransparentScene(wiRenderTarget& refractionRT, GRAPHICSTHREAD threadID) { - wiProfiler::GetInstance().BeginRange("Transparent Scene", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Transparent Scene", wiProfiler::DOMAIN_GPU, threadID); - wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); + wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); wiRenderer::GetDevice()->BindResource(PS, refractionRT.GetTexture(), TEXSLOT_RENDERABLECOMPONENT_REFRACTION, threadID); wiRenderer::GetDevice()->BindResource(PS, rtWaterRipple.GetTexture(), TEXSLOT_RENDERABLECOMPONENT_WATERRIPPLES, threadID); wiRenderer::DrawWorldTransparent(wiRenderer::GetCamera(), SHADERTYPE_FORWARD, threadID, false, true, getLayerMask()); - wiProfiler::GetInstance().EndRange(threadID); // Transparent Scene + wiProfiler::EndRange(threadID); // Transparent Scene } void Renderable3DComponent::RenderComposition(wiRenderTarget& shadedSceneRT, wiRenderTarget& mainRT, GRAPHICSTHREAD threadID) { @@ -464,7 +464,7 @@ void Renderable3DComponent::RenderComposition(wiRenderTarget& shadedSceneRT, wiR // We don't need the following for stereograms... return; } - wiProfiler::GetInstance().BeginRange("Post Processing", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Post Processing", wiProfiler::DOMAIN_GPU, threadID); wiImageEffects fx((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y); fx.hdr = true; @@ -472,7 +472,7 @@ void Renderable3DComponent::RenderComposition(wiRenderTarget& shadedSceneRT, wiR if (wiRenderer::GetTemporalAAEnabled() && !wiRenderer::GetTemporalAADebugEnabled()) { wiRenderer::GetDevice()->EventBegin("Temporal AA Resolve", threadID); - wiProfiler::GetInstance().BeginRange("Temporal AA Resolve", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Temporal AA Resolve", wiProfiler::DOMAIN_GPU, threadID); fx.blendFlag = BLENDMODE_OPAQUE; int current = wiRenderer::GetDevice()->GetFrameCount() % 2 == 0 ? 0 : 1; int history = 1 - current; @@ -492,7 +492,7 @@ void Renderable3DComponent::RenderComposition(wiRenderTarget& shadedSceneRT, wiR wiImage::Draw(rtTemporalAA[current].GetTexture(), fx, threadID); fx.presentFullScreen = false; } - wiProfiler::GetInstance().EndRange(threadID); + wiProfiler::EndRange(threadID); wiRenderer::GetDevice()->EventEnd(threadID); } @@ -567,7 +567,7 @@ void Renderable3DComponent::RenderComposition(wiRenderTarget& shadedSceneRT, wiR } else { - fx.setMaskMap(wiTextureHelper::getInstance()->getColor(wiColor::Gray)); + fx.setMaskMap(wiTextureHelper::getColor(wiColor::Gray)); } if (getMotionBlurEnabled()) { @@ -641,7 +641,7 @@ void Renderable3DComponent::RenderComposition(wiRenderTarget& shadedSceneRT, wiR wiRenderer::GetDevice()->EventEnd(threadID); - wiProfiler::GetInstance().EndRange(threadID); // Post Processing 1 + wiProfiler::EndRange(threadID); // Post Processing 1 } void Renderable3DComponent::RenderColorGradedComposition() { @@ -655,7 +655,7 @@ void Renderable3DComponent::RenderColorGradedComposition() fx.presentFullScreen = false; fx.process.clear(); fx.process.setStereogram(true); - wiImage::Draw(wiTextureHelper::getInstance()->getRandom64x64(), fx, GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(wiTextureHelper::getRandom64x64(), fx, GRAPHICSTHREAD_IMMEDIATE); wiRenderer::GetDevice()->EventEnd(GRAPHICSTHREAD_IMMEDIATE); return; } @@ -670,7 +670,7 @@ void Renderable3DComponent::RenderColorGradedComposition() else { fx.process.setColorGrade(true); - fx.setMaskMap(wiTextureHelper::getInstance()->getColorGradeDefault()); + fx.setMaskMap(wiTextureHelper::getColorGradeDefault()); } } else diff --git a/WickedEngine/TiledDeferredRenderableComponent.cpp b/WickedEngine/TiledDeferredRenderableComponent.cpp index 87340b513..32b944794 100644 --- a/WickedEngine/TiledDeferredRenderableComponent.cpp +++ b/WickedEngine/TiledDeferredRenderableComponent.cpp @@ -25,7 +25,7 @@ TiledDeferredRenderableComponent::~TiledDeferredRenderableComponent() void TiledDeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) { - wiProfiler::GetInstance().BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID); wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID); @@ -36,7 +36,7 @@ void TiledDeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) rtGBuffer.Activate(threadID, 0, 0, 0, 0); { - wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); + wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); wiRenderer::DrawWorld(wiRenderer::GetCamera(), getTessellationEnabled(), threadID, SHADERTYPE_DEFERRED, getHairParticlesEnabled(), true, getLayerMask()); } @@ -76,7 +76,7 @@ void TiledDeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) wiRenderer::BindGBufferTextures(rtGBuffer.GetTexture(0), rtGBuffer.GetTexture(1), rtGBuffer.GetTexture(2), rtGBuffer.GetTexture(3), nullptr, threadID); - wiRenderer::GetDevice()->BindResource(CS, getSSREnabled() ? rtSSR.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID); + wiRenderer::GetDevice()->BindResource(CS, getSSREnabled() ? rtSSR.GetTexture() : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID); wiRenderer::ComputeTiledLightCulling(true, threadID); @@ -88,7 +88,7 @@ void TiledDeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) fx.stencilComp = STENCILMODE_LESS; rtSSAO[0].Activate(threadID); { fx.process.setSSAO(true); - fx.setMaskMap(wiTextureHelper::getInstance()->getRandom64x64()); + fx.setMaskMap(wiTextureHelper::getRandom64x64()); fx.quality = QUALITY_BILINEAR; fx.sampleFlag = SAMPLEMODE_MIRROR; wiImage::Draw(nullptr, fx, threadID); @@ -171,7 +171,7 @@ void TiledDeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) rtDeferred.Activate(threadID, rtGBuffer.depth); { wiImage::DrawDeferred((getSSSEnabled() ? rtSSS[0].GetTexture(0) : static_cast(wiRenderer::GetTexture(TEXTYPE_2D_TILEDDEFERRED_DIFFUSEUAV))), static_cast(wiRenderer::GetTexture(TEXTYPE_2D_TILEDDEFERRED_SPECULARUAV)) - , getSSAOEnabled() ? rtSSAO.back().GetTexture() : wiTextureHelper::getInstance()->getWhite() + , getSSAOEnabled() ? rtSSAO.back().GetTexture() : wiTextureHelper::getWhite() , threadID, STENCILREF_DEFAULT); wiRenderer::DrawSky(threadID); } @@ -191,16 +191,16 @@ void TiledDeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) } - wiProfiler::GetInstance().EndRange(threadID); // Opaque Scene + wiProfiler::EndRange(threadID); // Opaque Scene } void TiledDeferredRenderableComponent::RenderTransparentScene(wiRenderTarget& refractionRT, GRAPHICSTHREAD threadID) { - wiProfiler::GetInstance().BeginRange("Transparent Scene", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Transparent Scene", wiProfiler::DOMAIN_GPU, threadID); - wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); + wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); wiRenderer::GetDevice()->BindResource(PS, refractionRT.GetTexture(), TEXSLOT_RENDERABLECOMPONENT_REFRACTION, threadID); wiRenderer::GetDevice()->BindResource(PS, rtWaterRipple.GetTexture(), TEXSLOT_RENDERABLECOMPONENT_WATERRIPPLES, threadID); wiRenderer::DrawWorldTransparent(wiRenderer::GetCamera(), SHADERTYPE_TILEDFORWARD, threadID, getHairParticlesEnabled(), true, getLayerMask()); - wiProfiler::GetInstance().EndRange(); // Transparent Scene + wiProfiler::EndRange(); // Transparent Scene } diff --git a/WickedEngine/TiledForwardRenderableComponent.cpp b/WickedEngine/TiledForwardRenderableComponent.cpp index 13c1bf3f5..6868daf6b 100644 --- a/WickedEngine/TiledForwardRenderableComponent.cpp +++ b/WickedEngine/TiledForwardRenderableComponent.cpp @@ -25,12 +25,12 @@ void TiledForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) wiImageEffects fx((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y); - wiProfiler::GetInstance().BeginRange("Z-Prepass", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Z-Prepass", wiProfiler::DOMAIN_GPU, threadID); rtMain.Activate(threadID, 0, 0, 0, 0, true); // depth prepass { wiRenderer::DrawWorld(wiRenderer::GetCamera(), getTessellationEnabled(), threadID, SHADERTYPE_DEPTHONLY, getHairParticlesEnabled(), true, getLayerMask()); } - wiProfiler::GetInstance().EndRange(threadID); + wiProfiler::EndRange(threadID); wiRenderer::GetDevice()->TransitionBarrier(dsv, ARRAYSIZE(dsv), RESOURCE_STATE_DEPTH_WRITE, RESOURCE_STATE_COPY_SOURCE, threadID); @@ -54,12 +54,12 @@ void TiledForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) wiRenderer::GetDevice()->UnbindResources(TEXSLOT_ONDEMAND0, 1, threadID); - wiProfiler::GetInstance().BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID); rtMain.Set(threadID); { - wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); - wiRenderer::GetDevice()->BindResource(PS, getSSAOEnabled() ? rtSSAO.back().GetTexture() : wiTextureHelper::getInstance()->getWhite(), TEXSLOT_RENDERABLECOMPONENT_SSAO, threadID); - wiRenderer::GetDevice()->BindResource(PS, getSSREnabled() ? rtSSR.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID); + wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); + wiRenderer::GetDevice()->BindResource(PS, getSSAOEnabled() ? rtSSAO.back().GetTexture() : wiTextureHelper::getWhite(), TEXSLOT_RENDERABLECOMPONENT_SSAO, threadID); + wiRenderer::GetDevice()->BindResource(PS, getSSREnabled() ? rtSSR.GetTexture() : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID); wiRenderer::DrawWorld(wiRenderer::GetCamera(), getTessellationEnabled(), threadID, SHADERTYPE_TILEDFORWARD, true, true); wiRenderer::DrawSky(threadID); } @@ -75,7 +75,7 @@ void TiledForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) fx.stencilComp = STENCILMODE_LESS; rtSSAO[0].Activate(threadID); { fx.process.setSSAO(true); - fx.setMaskMap(wiTextureHelper::getInstance()->getRandom64x64()); + fx.setMaskMap(wiTextureHelper::getRandom64x64()); fx.quality = QUALITY_BILINEAR; fx.sampleFlag = SAMPLEMODE_MIRROR; wiImage::Draw(nullptr, fx, threadID); @@ -113,17 +113,17 @@ void TiledForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) wiRenderer::GetDevice()->EventEnd(threadID); } - wiProfiler::GetInstance().EndRange(threadID); // Opaque Scene + wiProfiler::EndRange(threadID); // Opaque Scene } void TiledForwardRenderableComponent::RenderTransparentScene(wiRenderTarget& refractionRT, GRAPHICSTHREAD threadID) { - wiProfiler::GetInstance().BeginRange("Transparent Scene", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Transparent Scene", wiProfiler::DOMAIN_GPU, threadID); - wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); + wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); wiRenderer::GetDevice()->BindResource(PS, refractionRT.GetTexture(), TEXSLOT_RENDERABLECOMPONENT_REFRACTION, threadID); wiRenderer::GetDevice()->BindResource(PS, rtWaterRipple.GetTexture(), TEXSLOT_RENDERABLECOMPONENT_WATERRIPPLES, threadID); wiRenderer::DrawWorldTransparent(wiRenderer::GetCamera(), SHADERTYPE_TILEDFORWARD, threadID, getHairParticlesEnabled(), true); - wiProfiler::GetInstance().EndRange(threadID); // Transparent Scene + wiProfiler::EndRange(threadID); // Transparent Scene } diff --git a/WickedEngine/WickedEngine_SHARED.vcxitems b/WickedEngine/WickedEngine_SHARED.vcxitems index 2f5fe94aa..fb61581b0 100644 --- a/WickedEngine/WickedEngine_SHARED.vcxitems +++ b/WickedEngine/WickedEngine_SHARED.vcxitems @@ -710,6 +710,7 @@ + diff --git a/WickedEngine/WickedEngine_SHARED.vcxitems.filters b/WickedEngine/WickedEngine_SHARED.vcxitems.filters index 187812b07..e100516c0 100644 --- a/WickedEngine/WickedEngine_SHARED.vcxitems.filters +++ b/WickedEngine/WickedEngine_SHARED.vcxitems.filters @@ -1943,6 +1943,9 @@ ENGINE\Graphics + + ENGINE\Helpers + diff --git a/WickedEngine/wiBackLog.cpp b/WickedEngine/wiBackLog.cpp index 321093417..df53465fd 100644 --- a/WickedEngine/wiBackLog.cpp +++ b/WickedEngine/wiBackLog.cpp @@ -88,7 +88,7 @@ namespace wiBackLog { if (backgroundTex == nullptr) { - const unsigned char colorData[] = { 0, 0, 43, 200, 43, 31, 141, 223 }; + const uint8_t colorData[] = { 0, 0, 43, 200, 43, 31, 141, 223 }; HRESULT hr = wiTextureHelper::CreateTexture(backgroundTex, colorData, 1, 2, 4); assert(SUCCEEDED(hr)); } diff --git a/WickedEngine/wiEmittedParticle.cpp b/WickedEngine/wiEmittedParticle.cpp index 4f3912871..286b4b701 100644 --- a/WickedEngine/wiEmittedParticle.cpp +++ b/WickedEngine/wiEmittedParticle.cpp @@ -337,7 +337,7 @@ void wiEmittedParticle::UpdateRenderData(const TransformComponent& transform, co if (IsSPHEnabled()) { - wiProfiler::GetInstance().BeginRange("SPH - Simulation", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("SPH - Simulation", wiProfiler::DOMAIN_GPU, threadID); // Smooth Particle Hydrodynamics: device->EventBegin("SPH - Simulation", threadID); @@ -436,7 +436,7 @@ void wiEmittedParticle::UpdateRenderData(const TransformComponent& transform, co device->EventEnd(threadID); - wiProfiler::GetInstance().EndRange(threadID); + wiProfiler::EndRange(threadID); } device->EventBegin("Simulate", threadID); @@ -617,25 +617,25 @@ void wiEmittedParticle::LoadShaders() { std::string path = wiRenderer::GetShaderPath(); - vertexShader = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticleVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShader = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticleVS.cso", wiResourceManager::VERTEXSHADER)); - pixelShader[SOFT] = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticlePS_soft.cso", wiResourceManager::PIXELSHADER)); - pixelShader[SOFT_DISTORTION] = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticlePS_soft_distortion.cso", wiResourceManager::PIXELSHADER)); - pixelShader[SIMPLEST] = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticlePS_simplest.cso", wiResourceManager::PIXELSHADER)); + pixelShader[SOFT] = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticlePS_soft.cso", wiResourceManager::PIXELSHADER)); + pixelShader[SOFT_DISTORTION] = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticlePS_soft_distortion.cso", wiResourceManager::PIXELSHADER)); + pixelShader[SIMPLEST] = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticlePS_simplest.cso", wiResourceManager::PIXELSHADER)); - kickoffUpdateCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_kickoffUpdateCS.cso", wiResourceManager::COMPUTESHADER)); - finishUpdateCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_finishUpdateCS.cso", wiResourceManager::COMPUTESHADER)); - emitCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_emitCS.cso", wiResourceManager::COMPUTESHADER)); - emitCS_FROMMESH = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_emitCS_FROMMESH.cso", wiResourceManager::COMPUTESHADER)); - sphpartitionCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_sphpartitionCS.cso", wiResourceManager::COMPUTESHADER)); - sphpartitionoffsetsCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_sphpartitionoffsetsCS.cso", wiResourceManager::COMPUTESHADER)); - sphpartitionoffsetsresetCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_sphpartitionoffsetsresetCS.cso", wiResourceManager::COMPUTESHADER)); - sphdensityCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_sphdensityCS.cso", wiResourceManager::COMPUTESHADER)); - sphforceCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_sphforceCS.cso", wiResourceManager::COMPUTESHADER)); - simulateCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_simulateCS.cso", wiResourceManager::COMPUTESHADER)); - simulateCS_SORTING = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_simulateCS_SORTING.cso", wiResourceManager::COMPUTESHADER)); - simulateCS_DEPTHCOLLISIONS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_simulateCS_DEPTHCOLLISIONS.cso", wiResourceManager::COMPUTESHADER)); - simulateCS_SORTING_DEPTHCOLLISIONS = static_cast(wiResourceManager::GetShaderManager()->add(path + "emittedparticle_simulateCS_SORTING_DEPTHCOLLISIONS.cso", wiResourceManager::COMPUTESHADER)); + kickoffUpdateCS = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticle_kickoffUpdateCS.cso", wiResourceManager::COMPUTESHADER)); + finishUpdateCS = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticle_finishUpdateCS.cso", wiResourceManager::COMPUTESHADER)); + emitCS = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticle_emitCS.cso", wiResourceManager::COMPUTESHADER)); + emitCS_FROMMESH = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticle_emitCS_FROMMESH.cso", wiResourceManager::COMPUTESHADER)); + sphpartitionCS = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticle_sphpartitionCS.cso", wiResourceManager::COMPUTESHADER)); + sphpartitionoffsetsCS = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticle_sphpartitionoffsetsCS.cso", wiResourceManager::COMPUTESHADER)); + sphpartitionoffsetsresetCS = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticle_sphpartitionoffsetsresetCS.cso", wiResourceManager::COMPUTESHADER)); + sphdensityCS = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticle_sphdensityCS.cso", wiResourceManager::COMPUTESHADER)); + sphforceCS = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticle_sphforceCS.cso", wiResourceManager::COMPUTESHADER)); + simulateCS = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticle_simulateCS.cso", wiResourceManager::COMPUTESHADER)); + simulateCS_SORTING = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticle_simulateCS_SORTING.cso", wiResourceManager::COMPUTESHADER)); + simulateCS_DEPTHCOLLISIONS = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticle_simulateCS_DEPTHCOLLISIONS.cso", wiResourceManager::COMPUTESHADER)); + simulateCS_SORTING_DEPTHCOLLISIONS = static_cast(wiResourceManager::GetShaderManager().add(path + "emittedparticle_simulateCS_SORTING_DEPTHCOLLISIONS.cso", wiResourceManager::COMPUTESHADER)); GraphicsDevice* device = wiRenderer::GetDevice(); diff --git a/WickedEngine/wiFFTGenerator.cpp b/WickedEngine/wiFFTGenerator.cpp index 9304a0c90..c252cc04c 100644 --- a/WickedEngine/wiFFTGenerator.cpp +++ b/WickedEngine/wiFFTGenerator.cpp @@ -231,8 +231,8 @@ void CSFFT_512x512_Data_t::LoadShaders() { std::string path = wiRenderer::GetShaderPath(); - pRadix008A_CS = static_cast(wiResourceManager::GetShaderManager()->add(path+ "fft_512x512_c2c_CS.cso", wiResourceManager::COMPUTESHADER)); - pRadix008A_CS2 = static_cast(wiResourceManager::GetShaderManager()->add(path + "fft_512x512_c2c_v2_CS.cso", wiResourceManager::COMPUTESHADER)); + pRadix008A_CS = static_cast(wiResourceManager::GetShaderManager().add(path+ "fft_512x512_c2c_CS.cso", wiResourceManager::COMPUTESHADER)); + pRadix008A_CS2 = static_cast(wiResourceManager::GetShaderManager().add(path + "fft_512x512_c2c_v2_CS.cso", wiResourceManager::COMPUTESHADER)); GraphicsDevice* device = wiRenderer::GetDevice(); diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp index b7f08dcea..fd10aac0d 100644 --- a/WickedEngine/wiFont.cpp +++ b/WickedEngine/wiFont.cpp @@ -22,7 +22,7 @@ using namespace wiGraphicsTypes; namespace wiFont_Internal { std::string FONTPATH = "fonts/"; - GPURingBuffer vertexBuffer; + GPURingBuffer vertexBuffers[GRAPHICSTHREAD_COUNT]; GPUBuffer indexBuffer; GPUBuffer constantBuffer; BlendState blendState; @@ -268,8 +268,11 @@ void wiFont::Initialize() bd.BindFlags = BIND_VERTEX_BUFFER; bd.CPUAccessFlags = CPU_ACCESS_WRITE; - HRESULT hr = device->CreateBuffer(&bd, nullptr, &vertexBuffer); - assert(SUCCEEDED(hr)); + for (int i = 0; i < GRAPHICSTHREAD_COUNT; ++i) + { + HRESULT hr = device->CreateBuffer(&bd, nullptr, &vertexBuffers[i]); + assert(SUCCEEDED(hr)); + } } { @@ -376,13 +379,13 @@ void wiFont::LoadShaders() { "POSITION", 0, FORMAT_R16G16_UINT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, FORMAT_R16G16_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, }; - vertexShader = static_cast(wiResourceManager::GetShaderManager()->add(path + "fontVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShader = static_cast(wiResourceManager::GetShaderManager().add(path + "fontVS.cso", wiResourceManager::VERTEXSHADER)); vertexLayout = new VertexLayout; wiRenderer::GetDevice()->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShader->code, vertexLayout); - pixelShader = static_cast(wiResourceManager::GetShaderManager()->add(path + "fontPS.cso", wiResourceManager::PIXELSHADER)); + pixelShader = static_cast(wiResourceManager::GetShaderManager().add(path + "fontPS.cso", wiResourceManager::PIXELSHADER)); GraphicsPSODesc desc; @@ -435,13 +438,13 @@ void wiFont::Draw(GRAPHICSTHREAD threadID) GraphicsDevice* device = wiRenderer::GetDevice(); UINT vboffset; - volatile FontVertex* textBuffer = (volatile FontVertex*)device->AllocateFromRingBuffer(&vertexBuffer, sizeof(FontVertex) * text.length() * 4, vboffset, threadID); + volatile FontVertex* textBuffer = (volatile FontVertex*)device->AllocateFromRingBuffer(&vertexBuffers[threadID], sizeof(FontVertex) * text.length() * 4, vboffset, threadID); if (textBuffer == nullptr) { return; } const int quadCount = ModifyGeo(textBuffer, text, newProps, style); - device->InvalidateBufferAccess(&vertexBuffer, threadID); + device->InvalidateBufferAccess(&vertexBuffers[threadID], threadID); device->EventBegin("Font", threadID); @@ -449,7 +452,7 @@ void wiFont::Draw(GRAPHICSTHREAD threadID) device->BindSampler(PS, &sampler, SSLOT_ONDEMAND1, threadID); GPUBuffer* vbs[] = { - &vertexBuffer, + &vertexBuffers[threadID], }; const UINT strides[] = { sizeof(FontVertex), diff --git a/WickedEngine/wiGPUBVH.cpp b/WickedEngine/wiGPUBVH.cpp index 47dd712aa..be60acd3f 100644 --- a/WickedEngine/wiGPUBVH.cpp +++ b/WickedEngine/wiGPUBVH.cpp @@ -220,7 +220,7 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) } - wiProfiler::GetInstance().BeginRange("BVH Rebuild", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("BVH Rebuild", wiProfiler::DOMAIN_GPU, threadID); device->EventBegin("BVH - Reset", threadID); { @@ -396,7 +396,7 @@ void wiGPUBVH::Build(const Scene& scene, GRAPHICSTHREAD threadID) } device->EventEnd(threadID); - wiProfiler::GetInstance().EndRange(threadID); // BVH rebuild + wiProfiler::EndRange(threadID); // BVH rebuild } void wiGPUBVH::Bind(GRAPHICSTHREAD threadID) { @@ -420,12 +420,12 @@ void wiGPUBVH::LoadShaders() GraphicsDevice* device = wiRenderer::GetDevice(); string SHADERPATH = wiRenderer::GetShaderPath(); - computeShaders[CSTYPE_BVH_RESET] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "bvh_resetCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_BVH_CLASSIFICATION] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "bvh_classificationCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_BVH_KICKJOBS] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "bvh_kickjobsCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_BVH_CLUSTERPROCESSOR] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "bvh_clusterprocessorCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_BVH_HIERARCHY] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "bvh_hierarchyCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_BVH_PROPAGATEAABB] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "bvh_propagateaabbCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_BVH_RESET] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "bvh_resetCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_BVH_CLASSIFICATION] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "bvh_classificationCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_BVH_KICKJOBS] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "bvh_kickjobsCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_BVH_CLUSTERPROCESSOR] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "bvh_clusterprocessorCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_BVH_HIERARCHY] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "bvh_hierarchyCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_BVH_PROPAGATEAABB] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "bvh_propagateaabbCS.cso", wiResourceManager::COMPUTESHADER)); for (int i = 0; i < CSTYPE_BVH_COUNT; ++i) diff --git a/WickedEngine/wiGPUSortLib.cpp b/WickedEngine/wiGPUSortLib.cpp index beb2a757f..dee954753 100644 --- a/WickedEngine/wiGPUSortLib.cpp +++ b/WickedEngine/wiGPUSortLib.cpp @@ -45,10 +45,10 @@ namespace wiGPUSortLib { std::string path = wiRenderer::GetShaderPath(); - kickoffSortCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "gpusortlib_kickoffSortCS.cso", wiResourceManager::COMPUTESHADER)); - sortCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "gpusortlib_sortCS.cso", wiResourceManager::COMPUTESHADER)); - sortInnerCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "gpusortlib_sortInnerCS.cso", wiResourceManager::COMPUTESHADER)); - sortStepCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "gpusortlib_sortStepCS.cso", wiResourceManager::COMPUTESHADER)); + kickoffSortCS = static_cast(wiResourceManager::GetShaderManager().add(path + "gpusortlib_kickoffSortCS.cso", wiResourceManager::COMPUTESHADER)); + sortCS = static_cast(wiResourceManager::GetShaderManager().add(path + "gpusortlib_sortCS.cso", wiResourceManager::COMPUTESHADER)); + sortInnerCS = static_cast(wiResourceManager::GetShaderManager().add(path + "gpusortlib_sortInnerCS.cso", wiResourceManager::COMPUTESHADER)); + sortStepCS = static_cast(wiResourceManager::GetShaderManager().add(path + "gpusortlib_sortStepCS.cso", wiResourceManager::COMPUTESHADER)); GraphicsDevice* device = wiRenderer::GetDevice(); diff --git a/WickedEngine/wiGUI.cpp b/WickedEngine/wiGUI.cpp index e7026ca5e..cc6edf972 100644 --- a/WickedEngine/wiGUI.cpp +++ b/WickedEngine/wiGUI.cpp @@ -35,7 +35,7 @@ void wiGUI::Update(float dt) UpdateTransform(); } - XMFLOAT4 _p = wiInputManager::GetInstance()->getpointer(); + XMFLOAT4 _p = wiInputManager::getpointer(); pointerpos.x = _p.x; pointerpos.y = _p.y; diff --git a/WickedEngine/wiGraphicsDevice.cpp b/WickedEngine/wiGraphicsDevice.cpp index 78c9285fd..5f34d6408 100644 --- a/WickedEngine/wiGraphicsDevice.cpp +++ b/WickedEngine/wiGraphicsDevice.cpp @@ -2,7 +2,7 @@ using namespace wiGraphicsTypes; -bool GraphicsDevice::CheckCapability(GRAPHICSDEVICE_CAPABILITY capability) +bool GraphicsDevice::CheckCapability(GRAPHICSDEVICE_CAPABILITY capability) const { switch (capability) { @@ -27,7 +27,7 @@ bool GraphicsDevice::CheckCapability(GRAPHICSDEVICE_CAPABILITY capability) return false; } -uint32_t GraphicsDevice::GetFormatStride(FORMAT value) +uint32_t GraphicsDevice::GetFormatStride(FORMAT value) const { switch (value) { diff --git a/WickedEngine/wiGraphicsDevice.h b/WickedEngine/wiGraphicsDevice.h index 6f69d441a..901027820 100644 --- a/WickedEngine/wiGraphicsDevice.h +++ b/WickedEngine/wiGraphicsDevice.h @@ -76,13 +76,15 @@ namespace wiGraphicsTypes virtual void ExecuteDeferredContexts() = 0; virtual void FinishCommandList(GRAPHICSTHREAD thread) = 0; - inline bool GetVSyncEnabled() { return VSYNC; } - inline void SetVSyncEnabled(bool value) { VSYNC = value; } - inline uint64_t GetFrameCount() { return FRAMECOUNT; } + virtual void WaitForGPU() = 0; - inline int GetScreenWidth() { return SCREENWIDTH; } - inline int GetScreenHeight() { return SCREENHEIGHT; } - inline bool ResolutionChanged() { return RESOLUTIONCHANGED; } + inline bool GetVSyncEnabled() const { return VSYNC; } + inline void SetVSyncEnabled(bool value) { VSYNC = value; } + inline uint64_t GetFrameCount() const { return FRAMECOUNT; } + + inline int GetScreenWidth() const { return SCREENWIDTH; } + inline int GetScreenHeight() const { return SCREENHEIGHT; } + inline bool ResolutionChanged() const { return RESOLUTIONCHANGED; } virtual void SetResolution(int width, int height) = 0; @@ -98,15 +100,15 @@ namespace wiGraphicsTypes GRAPHICSDEVICE_CAPABILITY_UNORDEREDACCESSTEXTURE_LOAD_FORMAT_EXT, GRAPHICSDEVICE_CAPABILITY_COUNT, }; - bool CheckCapability(GRAPHICSDEVICE_CAPABILITY capability); + bool CheckCapability(GRAPHICSDEVICE_CAPABILITY capability) const; - uint32_t GetFormatStride(FORMAT value); + uint32_t GetFormatStride(FORMAT value) const; - inline XMMATRIX GetScreenProjection() + inline XMMATRIX GetScreenProjection() const { return XMMatrixOrthographicOffCenterLH(0, (float)GetScreenWidth(), (float)GetScreenHeight(), 0, -1, 1); } - inline FORMAT GetBackBufferFormat() { return BACKBUFFER_FORMAT; } + inline FORMAT GetBackBufferFormat() const { return BACKBUFFER_FORMAT; } inline static UINT GetBackBufferCount() { return BACKBUFFER_COUNT; } @@ -151,9 +153,7 @@ namespace wiGraphicsTypes virtual bool QueryRead(GPUQuery *query, GRAPHICSTHREAD threadID) = 0; virtual void UAVBarrier(GPUResource *const* uavs, UINT NumBarriers, GRAPHICSTHREAD threadID) = 0; virtual void TransitionBarrier(GPUResource *const* resources, UINT NumBarriers, RESOURCE_STATES stateBefore, RESOURCE_STATES stateAfter, GRAPHICSTHREAD threadID) = 0; - - virtual void WaitForGPU() = 0; - + virtual void EventBegin(const std::string& name, GRAPHICSTHREAD threadID) = 0; virtual void EventEnd(GRAPHICSTHREAD threadID) = 0; virtual void SetMarker(const std::string& name, GRAPHICSTHREAD threadID) = 0; diff --git a/WickedEngine/wiGraphicsDevice_DX11.cpp b/WickedEngine/wiGraphicsDevice_DX11.cpp index e899c650b..8ff3ee89a 100644 --- a/WickedEngine/wiGraphicsDevice_DX11.cpp +++ b/WickedEngine/wiGraphicsDevice_DX11.cpp @@ -1395,8 +1395,6 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(wiWindowRegistration::window_type windo for (int i = 0; i < GRAPHICSTHREAD_COUNT; i++) { - SAFE_INIT(commandLists[i]); - SAFE_INIT(deviceContexts[i]); stencilRef[i] = 0; blendFactor[i] = XMFLOAT4(1, 1, 1, 1); } @@ -3119,6 +3117,10 @@ void GraphicsDevice_DX11::FinishCommandList(GRAPHICSTHREAD thread) deviceContexts[thread]->FinishCommandList(true, &commandLists[thread]); } +void GraphicsDevice_DX11::WaitForGPU() +{ +} + void GraphicsDevice_DX11::validate_raster_uavs(GRAPHICSTHREAD threadID) { @@ -3772,10 +3774,6 @@ bool GraphicsDevice_DX11::DownloadResource(GPUResource* resourceToDownload, GPUR return false; } -void GraphicsDevice_DX11::WaitForGPU() -{ -} - void GraphicsDevice_DX11::QueryBegin(GPUQuery *query, GRAPHICSTHREAD threadID) { deviceContexts[threadID]->Begin((ID3D11Query*)query->resource[query->async_frameshift]); diff --git a/WickedEngine/wiGraphicsDevice_DX11.h b/WickedEngine/wiGraphicsDevice_DX11.h index f44c8e9ad..a5921f30a 100644 --- a/WickedEngine/wiGraphicsDevice_DX11.h +++ b/WickedEngine/wiGraphicsDevice_DX11.h @@ -50,7 +50,6 @@ namespace wiGraphicsTypes public: GraphicsDevice_DX11(wiWindowRegistration::window_type window, bool fullscreen = false, bool debuglayer = false); - ~GraphicsDevice_DX11(); HRESULT CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *ppBuffer) override; @@ -99,6 +98,8 @@ namespace wiGraphicsTypes void PresentBegin() override; void PresentEnd() override; + void WaitForGPU() override; + void ExecuteDeferredContexts() override; void FinishCommandList(GRAPHICSTHREAD thread) override; @@ -148,8 +149,6 @@ namespace wiGraphicsTypes void UAVBarrier(GPUResource *const* uavs, UINT NumBarriers, GRAPHICSTHREAD threadID) override {}; void TransitionBarrier(GPUResource *const* resources, UINT NumBarriers, RESOURCE_STATES stateBefore, RESOURCE_STATES stateAfter, GRAPHICSTHREAD threadID) override {}; - void WaitForGPU() override; - void EventBegin(const std::string& name, GRAPHICSTHREAD threadID) override; void EventEnd(GRAPHICSTHREAD threadID) override; void SetMarker(const std::string& name, GRAPHICSTHREAD threadID) override; diff --git a/WickedEngine/wiGraphicsDevice_DX12.cpp b/WickedEngine/wiGraphicsDevice_DX12.cpp index bff7fd186..f14619cc6 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.cpp +++ b/WickedEngine/wiGraphicsDevice_DX12.cpp @@ -6,9 +6,6 @@ #include "Utility/d3dx12.h" -#include -#include - #pragma comment(lib,"d3d12.lib") #pragma comment(lib,"Dxgi.lib") #pragma comment(lib,"dxguid.lib") @@ -29,7 +26,7 @@ namespace wiGraphicsTypes inline D3D12_CPU_DESCRIPTOR_HANDLE ToNativeHandle(wiCPUHandle handle) { D3D12_CPU_DESCRIPTOR_HANDLE native; - native.ptr = handle; + native.ptr = (SIZE_T)handle; return native; } @@ -1650,32 +1647,28 @@ namespace wiGraphicsTypes sampler_desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP; sampler_desc.ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER; sampler_desc.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR; - nullSampler = new D3D12_CPU_DESCRIPTOR_HANDLE; - nullSampler->ptr = SamplerAllocator->allocate(); - device->CreateSampler(&sampler_desc, *nullSampler); + nullSampler.ptr = SamplerAllocator->allocate(); + device->CreateSampler(&sampler_desc, nullSampler); D3D12_CONSTANT_BUFFER_VIEW_DESC cbv_desc = {}; - nullCBV = new D3D12_CPU_DESCRIPTOR_HANDLE; - nullCBV->ptr = ResourceAllocator->allocate(); - device->CreateConstantBufferView(&cbv_desc, *nullCBV); + nullCBV.ptr = ResourceAllocator->allocate(); + device->CreateConstantBufferView(&cbv_desc, nullCBV); D3D12_SHADER_RESOURCE_VIEW_DESC srv_desc = {}; srv_desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; srv_desc.Format = DXGI_FORMAT_R32_UINT; srv_desc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER; - nullSRV = new D3D12_CPU_DESCRIPTOR_HANDLE; - nullSRV->ptr = ResourceAllocator->allocate(); - device->CreateShaderResourceView(nullptr, &srv_desc, *nullSRV); + nullSRV.ptr = ResourceAllocator->allocate(); + device->CreateShaderResourceView(nullptr, &srv_desc, nullSRV); D3D12_UNORDERED_ACCESS_VIEW_DESC uav_desc = {}; uav_desc.Format = DXGI_FORMAT_R32_UINT; uav_desc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER; - nullUAV = new D3D12_CPU_DESCRIPTOR_HANDLE; - nullUAV->ptr = ResourceAllocator->allocate(); - device->CreateUnorderedAccessView(nullptr, nullptr, &uav_desc, *nullUAV); + nullUAV.ptr = ResourceAllocator->allocate(); + device->CreateUnorderedAccessView(nullptr, nullptr, &uav_desc, nullUAV); } // Create resource upload buffer @@ -1687,9 +1680,8 @@ namespace wiGraphicsTypes for (UINT fr = 0; fr < BACKBUFFER_COUNT; ++fr) { hr = swapChain->GetBuffer(fr, __uuidof(ID3D12Resource), (void**)&frames[fr].backBuffer); - frames[fr].backBufferRTV = new D3D12_CPU_DESCRIPTOR_HANDLE; - frames[fr].backBufferRTV->ptr = RTAllocator->allocate(); - device->CreateRenderTargetView(frames[fr].backBuffer, nullptr, *frames[fr].backBufferRTV); + frames[fr].backBufferRTV.ptr = RTAllocator->allocate(); + device->CreateRenderTargetView(frames[fr].backBuffer, nullptr, frames[fr].backBufferRTV); for (int i = 0; i < GRAPHICSTHREAD_COUNT; ++i) { @@ -1745,8 +1737,6 @@ namespace wiGraphicsTypes // Generate default root signature: - SAFE_INIT(graphicsRootSig); - SAFE_INIT(computeRootSig); D3D12_DESCRIPTOR_RANGE samplerRange = {}; samplerRange.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER; @@ -1962,7 +1952,7 @@ namespace wiGraphicsTypes GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE)->SetComputeRootSignature(computeRootSig); D3D12_CPU_DESCRIPTOR_HANDLE nullDescriptors[] = { - *nullSampler,*nullCBV,*nullSRV,*nullUAV + nullSampler,nullCBV,nullSRV,nullUAV }; GetFrameResources().ResourceDescriptorsGPU[GRAPHICSTHREAD_IMMEDIATE]->reset(device, nullDescriptors); GetFrameResources().SamplerDescriptorsGPU[GRAPHICSTHREAD_IMMEDIATE]->reset(device, nullDescriptors); @@ -1989,7 +1979,6 @@ namespace wiGraphicsTypes for (UINT fr = 0; fr < BACKBUFFER_COUNT; ++fr) { SAFE_RELEASE(frames[fr].backBuffer); - SAFE_DELETE(frames[fr].backBufferRTV); for (int i = 0; i < GRAPHICSTHREAD_COUNT; i++) { @@ -2010,11 +1999,6 @@ namespace wiGraphicsTypes SAFE_RELEASE(copyFence); CloseHandle(copyFenceEvent); - SAFE_DELETE(nullSampler); - SAFE_DELETE(nullCBV); - SAFE_DELETE(nullSRV); - SAFE_DELETE(nullUAV); - SAFE_RELEASE(graphicsRootSig); SAFE_RELEASE(computeRootSig); @@ -2055,7 +2039,7 @@ namespace wiGraphicsTypes { hr = swapChain->GetBuffer(fr, __uuidof(ID3D12Resource), (void**)&frames[fr].backBuffer); assert(SUCCEEDED(hr)); - device->CreateRenderTargetView(frames[fr].backBuffer, nullptr, *frames[fr].backBufferRTV); + device->CreateRenderTargetView(frames[fr].backBuffer, nullptr, frames[fr].backBufferRTV); } RESOLUTIONCHANGED = true; @@ -3350,7 +3334,7 @@ namespace wiGraphicsTypes // Set the back buffer as the render target. - GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE)->OMSetRenderTargets(1, GetFrameResources().backBufferRTV, FALSE, NULL); + GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE)->OMSetRenderTargets(1, &GetFrameResources().backBufferRTV, FALSE, NULL); // Then set the color to clear the window to. @@ -3359,7 +3343,7 @@ namespace wiGraphicsTypes color[1] = 0.0; color[2] = 0.0; color[3] = 1.0; - GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE)->ClearRenderTargetView(*GetFrameResources().backBufferRTV, color, 0, NULL); + GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE)->ClearRenderTargetView(GetFrameResources().backBufferRTV, color, 0, NULL); } @@ -3427,7 +3411,7 @@ namespace wiGraphicsTypes GetDirectCommandList((GRAPHICSTHREAD)threadID)->SetComputeRootSignature(computeRootSig); D3D12_CPU_DESCRIPTOR_HANDLE nullDescriptors[] = { - *nullSampler,*nullCBV,*nullSRV,*nullUAV + nullSampler,nullCBV,nullSRV,nullUAV }; GetFrameResources().ResourceDescriptorsGPU[threadID]->reset(device, nullDescriptors); GetFrameResources().SamplerDescriptorsGPU[threadID]->reset(device, nullDescriptors); @@ -3461,6 +3445,15 @@ namespace wiGraphicsTypes assert(SUCCEEDED(hr)); } + void GraphicsDevice_DX12::WaitForGPU() + { + if (frameFence->GetCompletedValue() < FRAMECOUNT) + { + HRESULT result = frameFence->SetEventOnCompletion(FRAMECOUNT, frameFenceEvent); + WaitForSingleObject(frameFenceEvent, INFINITE); + } + } + void GraphicsDevice_DX12::BindScissorRects(UINT numRects, const Rect* rects, GRAPHICSTHREAD threadID) { assert(rects != nullptr); @@ -3629,7 +3622,7 @@ namespace wiGraphicsTypes for (int i = 0; i < num; ++i) { GetFrameResources().ResourceDescriptorsGPU[threadID]->update((SHADERSTAGE)stage, GPU_RESOURCE_HEAP_CBV_COUNT + slot + i, - nullSRV->ptr, device, GetDirectCommandList(threadID)); + nullSRV.ptr, device, GetDirectCommandList(threadID)); } } } @@ -3640,7 +3633,7 @@ namespace wiGraphicsTypes for (int i = 0; i < num; ++i) { GetFrameResources().ResourceDescriptorsGPU[threadID]->update(CS, GPU_RESOURCE_HEAP_CBV_COUNT + GPU_RESOURCE_HEAP_SRV_COUNT + slot + i, - nullUAV->ptr, device, GetDirectCommandList(threadID)); + nullUAV.ptr, device, GetDirectCommandList(threadID)); } } } @@ -3939,15 +3932,6 @@ namespace wiGraphicsTypes return false; } - void GraphicsDevice_DX12::WaitForGPU() - { - if (frameFence->GetCompletedValue() < FRAMECOUNT) - { - HRESULT result = frameFence->SetEventOnCompletion(FRAMECOUNT, frameFenceEvent); - WaitForSingleObject(frameFenceEvent, INFINITE); - } - } - void GraphicsDevice_DX12::QueryBegin(GPUQuery *query, GRAPHICSTHREAD threadID) { } diff --git a/WickedEngine/wiGraphicsDevice_DX12.h b/WickedEngine/wiGraphicsDevice_DX12.h index 1efc398e0..bbafefcaf 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.h +++ b/WickedEngine/wiGraphicsDevice_DX12.h @@ -5,23 +5,8 @@ #include "wiGraphicsDevice.h" #include "wiWindowRegistration.h" -struct IDXGISwapChain3; -enum D3D_DRIVER_TYPE; -enum D3D_FEATURE_LEVEL; -enum D3D12_DESCRIPTOR_HEAP_TYPE; - -struct ID3D12Device; -struct ID3D12CommandAllocator; -struct ID3D12CommandList; -struct ID3D12GraphicsCommandList; -struct ID3D12Fence; -struct ID3D12Resource; -struct ID3D12PipelineState; -struct ID3D12DescriptorHeap; -struct ID3D12CommandQueue; -struct ID3D12RootSignature; -struct ID3D12CommandSignature; -struct D3D12_CPU_DESCRIPTOR_HANDLE; +#include +#include namespace wiGraphicsTypes { @@ -29,34 +14,34 @@ namespace wiGraphicsTypes class GraphicsDevice_DX12 : public GraphicsDevice { private: - ID3D12Device* device; - ID3D12CommandQueue* directQueue; - ID3D12Fence* frameFence; + ID3D12Device* device = nullptr; + ID3D12CommandQueue* directQueue = nullptr; + ID3D12Fence* frameFence = nullptr; HANDLE frameFenceEvent; - ID3D12CommandQueue* copyQueue; - ID3D12CommandAllocator* copyAllocator; - ID3D12CommandList* copyCommandList; - ID3D12Fence* copyFence; + ID3D12CommandQueue* copyQueue = nullptr; + ID3D12CommandAllocator* copyAllocator = nullptr; + ID3D12CommandList* copyCommandList = nullptr; + ID3D12Fence* copyFence = nullptr; HANDLE copyFenceEvent; UINT64 copyFenceValue; wiSpinLock copyQueueLock; - ID3D12RootSignature* graphicsRootSig; - ID3D12RootSignature* computeRootSig; + ID3D12RootSignature* graphicsRootSig = nullptr; + ID3D12RootSignature* computeRootSig = nullptr; - ID3D12CommandSignature* dispatchIndirectCommandSignature; - ID3D12CommandSignature* drawInstancedIndirectCommandSignature; - ID3D12CommandSignature* drawIndexedInstancedIndirectCommandSignature; + ID3D12CommandSignature* dispatchIndirectCommandSignature = nullptr; + ID3D12CommandSignature* drawInstancedIndirectCommandSignature = nullptr; + ID3D12CommandSignature* drawIndexedInstancedIndirectCommandSignature = nullptr; struct DescriptorAllocator : public wiThreadSafeManager { - ID3D12DescriptorHeap* heap; + ID3D12DescriptorHeap* heap = nullptr; size_t heap_begin; uint32_t itemCount; UINT maxCount; UINT itemSize; - bool* itemsAlive; + bool* itemsAlive = nullptr; uint32_t lastAlloc; DescriptorAllocator(ID3D12Device* device, D3D12_DESCRIPTOR_HEAP_TYPE type, UINT maxCount); @@ -66,29 +51,29 @@ namespace wiGraphicsTypes void clear(); void free(wiCPUHandle descriptorHandle); }; - DescriptorAllocator* RTAllocator; - DescriptorAllocator* DSAllocator; - DescriptorAllocator* ResourceAllocator; - DescriptorAllocator* SamplerAllocator; + DescriptorAllocator* RTAllocator = nullptr; + DescriptorAllocator* DSAllocator = nullptr; + DescriptorAllocator* ResourceAllocator = nullptr; + DescriptorAllocator* SamplerAllocator = nullptr; struct FrameResources { - ID3D12Resource* backBuffer; - D3D12_CPU_DESCRIPTOR_HANDLE* backBufferRTV; - ID3D12CommandAllocator* commandAllocators[GRAPHICSTHREAD_COUNT]; - ID3D12CommandList* commandLists[GRAPHICSTHREAD_COUNT]; + ID3D12Resource* backBuffer = nullptr; + D3D12_CPU_DESCRIPTOR_HANDLE backBufferRTV = {}; + ID3D12CommandAllocator* commandAllocators[GRAPHICSTHREAD_COUNT] = {}; + ID3D12CommandList* commandLists[GRAPHICSTHREAD_COUNT] = {}; struct DescriptorTableFrameAllocator { - ID3D12DescriptorHeap* heap_CPU; - ID3D12DescriptorHeap* heap_GPU; + ID3D12DescriptorHeap* heap_CPU = nullptr; + ID3D12DescriptorHeap* heap_GPU = nullptr; UINT descriptorType; UINT itemSize; UINT itemCount; UINT ringOffset; bool dirty[SHADERSTAGE_COUNT]; - wiCPUHandle* boundDescriptors; + wiCPUHandle* boundDescriptors = nullptr; DescriptorTableFrameAllocator(ID3D12Device* device, D3D12_DESCRIPTOR_HEAP_TYPE type, UINT maxRenameCount); ~DescriptorTableFrameAllocator(); @@ -97,15 +82,15 @@ namespace wiGraphicsTypes void update(SHADERSTAGE stage, UINT slot, wiCPUHandle descriptor, ID3D12Device* device, ID3D12GraphicsCommandList* commandList); void validate(ID3D12Device* device, ID3D12GraphicsCommandList* commandList); }; - DescriptorTableFrameAllocator* ResourceDescriptorsGPU[GRAPHICSTHREAD_COUNT]; - DescriptorTableFrameAllocator* SamplerDescriptorsGPU[GRAPHICSTHREAD_COUNT]; + DescriptorTableFrameAllocator* ResourceDescriptorsGPU[GRAPHICSTHREAD_COUNT] = {}; + DescriptorTableFrameAllocator* SamplerDescriptorsGPU[GRAPHICSTHREAD_COUNT] = {}; struct ResourceFrameAllocator { - ID3D12Resource* resource; - uint8_t* dataBegin; - uint8_t* dataCur; - uint8_t* dataEnd; + ID3D12Resource* resource = nullptr; + uint8_t* dataBegin = nullptr; + uint8_t* dataCur = nullptr; + uint8_t* dataEnd = nullptr; ResourceFrameAllocator(ID3D12Device* device, size_t size); ~ResourceFrameAllocator(); @@ -114,24 +99,24 @@ namespace wiGraphicsTypes void clear(); uint64_t calculateOffset(uint8_t* address); }; - ResourceFrameAllocator* resourceBuffer[GRAPHICSTHREAD_COUNT]; + ResourceFrameAllocator* resourceBuffer[GRAPHICSTHREAD_COUNT] = {}; }; FrameResources frames[BACKBUFFER_COUNT]; FrameResources& GetFrameResources() { return frames[GetFrameCount() % BACKBUFFER_COUNT]; } ID3D12GraphicsCommandList* GetDirectCommandList(GRAPHICSTHREAD threadID); - D3D12_CPU_DESCRIPTOR_HANDLE* nullSampler; - D3D12_CPU_DESCRIPTOR_HANDLE* nullCBV; - D3D12_CPU_DESCRIPTOR_HANDLE* nullSRV; - D3D12_CPU_DESCRIPTOR_HANDLE* nullUAV; + D3D12_CPU_DESCRIPTOR_HANDLE nullSampler = {}; + D3D12_CPU_DESCRIPTOR_HANDLE nullCBV = {}; + D3D12_CPU_DESCRIPTOR_HANDLE nullSRV = {}; + D3D12_CPU_DESCRIPTOR_HANDLE nullUAV = {}; struct UploadBuffer : wiThreadSafeManager { - ID3D12Resource* resource; - uint8_t* dataBegin; - uint8_t* dataCur; - uint8_t* dataEnd; + ID3D12Resource* resource = nullptr; + uint8_t* dataBegin = nullptr; + uint8_t* dataCur = nullptr; + uint8_t* dataEnd = nullptr; UploadBuffer(ID3D12Device* device, size_t size); ~UploadBuffer(); @@ -140,17 +125,16 @@ namespace wiGraphicsTypes void clear(); uint64_t calculateOffset(uint8_t* address); }; - UploadBuffer* bufferUploader; - UploadBuffer* textureUploader; + UploadBuffer* bufferUploader = nullptr; + UploadBuffer* textureUploader = nullptr; - IDXGISwapChain3* swapChain; + IDXGISwapChain3* swapChain = nullptr; ViewPort viewPort; PRIMITIVETOPOLOGY prev_pt[GRAPHICSTHREAD_COUNT] = {}; public: GraphicsDevice_DX12(wiWindowRegistration::window_type window, bool fullscreen = false, bool debuglayer = false); - ~GraphicsDevice_DX12(); HRESULT CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *ppBuffer) override; @@ -201,6 +185,8 @@ namespace wiGraphicsTypes void ExecuteDeferredContexts() override; void FinishCommandList(GRAPHICSTHREAD thread) override; + void WaitForGPU() override; + void SetResolution(int width, int height) override; Texture2D GetBackBuffer() override; @@ -247,8 +233,6 @@ namespace wiGraphicsTypes void UAVBarrier(GPUResource *const* uavs, UINT NumBarriers, GRAPHICSTHREAD threadID) override; void TransitionBarrier(GPUResource *const* resources, UINT NumBarriers, RESOURCE_STATES stateBefore, RESOURCE_STATES stateAfter, GRAPHICSTHREAD threadID) override; - void WaitForGPU() override; - void EventBegin(const std::string& name, GRAPHICSTHREAD threadID) override; void EventEnd(GRAPHICSTHREAD threadID) override; void SetMarker(const std::string& name, GRAPHICSTHREAD threadID) override; diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.cpp b/WickedEngine/wiGraphicsDevice_Vulkan.cpp index ea0c99def..955e6deb3 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.cpp +++ b/WickedEngine/wiGraphicsDevice_Vulkan.cpp @@ -4408,6 +4408,11 @@ namespace wiGraphicsTypes } } + void GraphicsDevice_Vulkan::WaitForGPU() + { + vkQueueWaitIdle(graphicsQueue); + } + void GraphicsDevice_Vulkan::BindScissorRects(UINT numRects, const Rect* rects, GRAPHICSTHREAD threadID) { assert(rects != nullptr); @@ -5162,11 +5167,6 @@ namespace wiGraphicsTypes return false; } - void GraphicsDevice_Vulkan::WaitForGPU() - { - vkQueueWaitIdle(graphicsQueue); - } - void GraphicsDevice_Vulkan::QueryBegin(GPUQuery *query, GRAPHICSTHREAD threadID) { } diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.h b/WickedEngine/wiGraphicsDevice_Vulkan.h index 77b3d0db5..75b3e8edb 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.h +++ b/WickedEngine/wiGraphicsDevice_Vulkan.h @@ -198,7 +198,6 @@ namespace wiGraphicsTypes public: GraphicsDevice_Vulkan(wiWindowRegistration::window_type window, bool fullscreen = false, bool debuglayer = false); - ~GraphicsDevice_Vulkan(); HRESULT CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *ppBuffer) override; @@ -249,6 +248,8 @@ namespace wiGraphicsTypes void ExecuteDeferredContexts() override; void FinishCommandList(GRAPHICSTHREAD thread) override; + void WaitForGPU() override; + void SetResolution(int width, int height) override; Texture2D GetBackBuffer() override; @@ -295,8 +296,6 @@ namespace wiGraphicsTypes void UAVBarrier(GPUResource *const* uavs, UINT NumBarriers, GRAPHICSTHREAD threadID) override; void TransitionBarrier(GPUResource *const* resources, UINT NumBarriers, RESOURCE_STATES stateBefore, RESOURCE_STATES stateAfter, GRAPHICSTHREAD threadID) override; - void WaitForGPU() override; - void EventBegin(const std::string& name, GRAPHICSTHREAD threadID) override; void EventEnd(GRAPHICSTHREAD threadID) override; void SetMarker(const std::string& name, GRAPHICSTHREAD threadID) override; diff --git a/WickedEngine/wiHairParticle.cpp b/WickedEngine/wiHairParticle.cpp index cc1ebf2ec..f4af7ea10 100644 --- a/WickedEngine/wiHairParticle.cpp +++ b/WickedEngine/wiHairParticle.cpp @@ -132,7 +132,7 @@ void wiHairParticle::Draw(const CameraComponent& camera, const MaterialComponent return; } device->BindGraphicsPSO(&PSO_wire, threadID); - device->BindResource(VS, wiTextureHelper::getInstance()->getWhite(), TEXSLOT_ONDEMAND0, threadID); + device->BindResource(VS, wiTextureHelper::getWhite(), TEXSLOT_ONDEMAND0, threadID); } else { @@ -188,18 +188,12 @@ void wiHairParticle::LoadShaders() { std::string path = wiRenderer::GetShaderPath(); - vs = static_cast(wiResourceManager::GetShaderManager()->add(path + "hairparticleVS.cso", wiResourceManager::VERTEXSHADER)); + vs = static_cast(wiResourceManager::GetShaderManager().add(path + "hairparticleVS.cso", wiResourceManager::VERTEXSHADER)); - - for (int i = 0; i < SHADERTYPE_COUNT; ++i) - { - SAFE_INIT(ps[i]); - } - - ps[SHADERTYPE_DEPTHONLY] = static_cast(wiResourceManager::GetShaderManager()->add(path + "hairparticlePS_alphatestonly.cso", wiResourceManager::PIXELSHADER)); - ps[SHADERTYPE_DEFERRED] = static_cast(wiResourceManager::GetShaderManager()->add(path + "hairparticlePS_deferred.cso", wiResourceManager::PIXELSHADER)); - ps[SHADERTYPE_FORWARD] = static_cast(wiResourceManager::GetShaderManager()->add(path + "hairparticlePS_forward.cso", wiResourceManager::PIXELSHADER)); - ps[SHADERTYPE_TILEDFORWARD] = static_cast(wiResourceManager::GetShaderManager()->add(path + "hairparticlePS_tiledforward.cso", wiResourceManager::PIXELSHADER)); + ps[SHADERTYPE_DEPTHONLY] = static_cast(wiResourceManager::GetShaderManager().add(path + "hairparticlePS_alphatestonly.cso", wiResourceManager::PIXELSHADER)); + ps[SHADERTYPE_DEFERRED] = static_cast(wiResourceManager::GetShaderManager().add(path + "hairparticlePS_deferred.cso", wiResourceManager::PIXELSHADER)); + ps[SHADERTYPE_FORWARD] = static_cast(wiResourceManager::GetShaderManager().add(path + "hairparticlePS_forward.cso", wiResourceManager::PIXELSHADER)); + ps[SHADERTYPE_TILEDFORWARD] = static_cast(wiResourceManager::GetShaderManager().add(path + "hairparticlePS_tiledforward.cso", wiResourceManager::PIXELSHADER)); GraphicsDevice* device = wiRenderer::GetDevice(); @@ -264,8 +258,7 @@ void wiHairParticle::LoadShaders() } } - SAFE_INIT(ps_simplest); - ps_simplest = static_cast(wiResourceManager::GetShaderManager()->add(path + "hairparticlePS_simplest.cso", wiResourceManager::PIXELSHADER)); + ps_simplest = static_cast(wiResourceManager::GetShaderManager().add(path + "hairparticlePS_simplest.cso", wiResourceManager::PIXELSHADER)); { GraphicsPSODesc desc; @@ -280,8 +273,7 @@ void wiHairParticle::LoadShaders() device->CreateGraphicsPSO(&desc, &PSO_wire); } - SAFE_INIT(cs_simulate); - cs_simulate = static_cast(wiResourceManager::GetShaderManager()->add(path + "hairparticle_simulateCS.cso", wiResourceManager::COMPUTESHADER)); + cs_simulate = static_cast(wiResourceManager::GetShaderManager().add(path + "hairparticle_simulateCS.cso", wiResourceManager::COMPUTESHADER)); { ComputePSODesc desc; diff --git a/WickedEngine/wiHelper.cpp b/WickedEngine/wiHelper.cpp index 359e17ca9..3b75ba2d3 100644 --- a/WickedEngine/wiHelper.cpp +++ b/WickedEngine/wiHelper.cpp @@ -67,7 +67,7 @@ namespace wiHelper void messageBox(const std::string& msg, const std::string& caption){ #ifndef WINSTORE_SUPPORT - MessageBoxA(wiWindowRegistration::GetInstance()->GetRegisteredWindow(), msg.c_str(), caption.c_str(), 0); + MessageBoxA(wiWindowRegistration::GetRegisteredWindow(), msg.c_str(), caption.c_str(), 0); #else wstring wmsg(msg.begin(), msg.end()); wstring wcaption(caption.begin(), caption.end()); @@ -304,7 +304,11 @@ namespace wiHelper void Sleep(float milliseconds) { - //::Sleep((DWORD)milliseconds); + ::Sleep((DWORD)milliseconds); + } + + void Spin(float milliseconds) + { milliseconds /= 1000.0f; chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now(); double ms = 0; diff --git a/WickedEngine/wiHelper.h b/WickedEngine/wiHelper.h index 4b3180288..3298503d1 100644 --- a/WickedEngine/wiHelper.h +++ b/WickedEngine/wiHelper.h @@ -58,7 +58,11 @@ namespace wiHelper void RemoveExtensionFromFileName(std::string& filename); + // Puts the current thread to sleeping state for a given time (OS can overtake) void Sleep(float milliseconds); + + // Spins for the given time and does nothing (OS can not overtake) + void Spin(float milliseconds); }; #endif diff --git a/WickedEngine/wiImage.cpp b/WickedEngine/wiImage.cpp index 04354ebf9..1eb4aa2ad 100644 --- a/WickedEngine/wiImage.cpp +++ b/WickedEngine/wiImage.cpp @@ -419,37 +419,37 @@ namespace wiImage { std::string path = wiRenderer::GetShaderPath(); - vertexShader = static_cast(wiResourceManager::GetShaderManager()->add(path + "imageVS.cso", wiResourceManager::VERTEXSHADER)); - screenVS = static_cast(wiResourceManager::GetShaderManager()->add(path + "screenVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShader = static_cast(wiResourceManager::GetShaderManager().add(path + "imageVS.cso", wiResourceManager::VERTEXSHADER)); + screenVS = static_cast(wiResourceManager::GetShaderManager().add(path + "screenVS.cso", wiResourceManager::VERTEXSHADER)); - imagePS[IMAGE_SHADER_STANDARD] = static_cast(wiResourceManager::GetShaderManager()->add(path + "imagePS.cso", wiResourceManager::PIXELSHADER)); - imagePS[IMAGE_SHADER_SEPARATENORMALMAP] = static_cast(wiResourceManager::GetShaderManager()->add(path + "imagePS_separatenormalmap.cso", wiResourceManager::PIXELSHADER)); - imagePS[IMAGE_SHADER_DISTORTION] = static_cast(wiResourceManager::GetShaderManager()->add(path + "imagePS_distortion.cso", wiResourceManager::PIXELSHADER)); - imagePS[IMAGE_SHADER_DISTORTION_MASKED] = static_cast(wiResourceManager::GetShaderManager()->add(path + "imagePS_distortion_masked.cso", wiResourceManager::PIXELSHADER)); - imagePS[IMAGE_SHADER_MASKED] = static_cast(wiResourceManager::GetShaderManager()->add(path + "imagePS_masked.cso", wiResourceManager::PIXELSHADER)); - imagePS[IMAGE_SHADER_FULLSCREEN] = static_cast(wiResourceManager::GetShaderManager()->add(path + "screenPS.cso", wiResourceManager::PIXELSHADER)); + imagePS[IMAGE_SHADER_STANDARD] = static_cast(wiResourceManager::GetShaderManager().add(path + "imagePS.cso", wiResourceManager::PIXELSHADER)); + imagePS[IMAGE_SHADER_SEPARATENORMALMAP] = static_cast(wiResourceManager::GetShaderManager().add(path + "imagePS_separatenormalmap.cso", wiResourceManager::PIXELSHADER)); + imagePS[IMAGE_SHADER_DISTORTION] = static_cast(wiResourceManager::GetShaderManager().add(path + "imagePS_distortion.cso", wiResourceManager::PIXELSHADER)); + imagePS[IMAGE_SHADER_DISTORTION_MASKED] = static_cast(wiResourceManager::GetShaderManager().add(path + "imagePS_distortion_masked.cso", wiResourceManager::PIXELSHADER)); + imagePS[IMAGE_SHADER_MASKED] = static_cast(wiResourceManager::GetShaderManager().add(path + "imagePS_masked.cso", wiResourceManager::PIXELSHADER)); + imagePS[IMAGE_SHADER_FULLSCREEN] = static_cast(wiResourceManager::GetShaderManager().add(path + "screenPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_BLUR_H] = static_cast(wiResourceManager::GetShaderManager()->add(path + "horizontalBlurPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_BLUR_V] = static_cast(wiResourceManager::GetShaderManager()->add(path + "verticalBlurPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_LIGHTSHAFT] = static_cast(wiResourceManager::GetShaderManager()->add(path + "lightShaftPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_OUTLINE] = static_cast(wiResourceManager::GetShaderManager()->add(path + "outlinePS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_DEPTHOFFIELD] = static_cast(wiResourceManager::GetShaderManager()->add(path + "depthofFieldPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_MOTIONBLUR] = static_cast(wiResourceManager::GetShaderManager()->add(path + "motionBlurPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_BLOOMSEPARATE] = static_cast(wiResourceManager::GetShaderManager()->add(path + "bloomSeparatePS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_FXAA] = static_cast(wiResourceManager::GetShaderManager()->add(path + "fxaa.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_SSAO] = static_cast(wiResourceManager::GetShaderManager()->add(path + "ssao.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_SSSS] = static_cast(wiResourceManager::GetShaderManager()->add(path + "ssss.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_LINEARDEPTH] = static_cast(wiResourceManager::GetShaderManager()->add(path + "linDepthPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_COLORGRADE] = static_cast(wiResourceManager::GetShaderManager()->add(path + "colorGradePS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_SSR] = static_cast(wiResourceManager::GetShaderManager()->add(path + "ssr.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_STEREOGRAM] = static_cast(wiResourceManager::GetShaderManager()->add(path + "stereogramPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_TONEMAP] = static_cast(wiResourceManager::GetShaderManager()->add(path + "toneMapPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_REPROJECTDEPTHBUFFER] = static_cast(wiResourceManager::GetShaderManager()->add(path + "reprojectDepthBufferPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_DOWNSAMPLEDEPTHBUFFER] = static_cast(wiResourceManager::GetShaderManager()->add(path + "downsampleDepthBuffer4xPS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_TEMPORALAA] = static_cast(wiResourceManager::GetShaderManager()->add(path + "temporalAAResolvePS.cso", wiResourceManager::PIXELSHADER)); - postprocessPS[POSTPROCESS_SHARPEN] = static_cast(wiResourceManager::GetShaderManager()->add(path + "sharpenPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_BLUR_H] = static_cast(wiResourceManager::GetShaderManager().add(path + "horizontalBlurPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_BLUR_V] = static_cast(wiResourceManager::GetShaderManager().add(path + "verticalBlurPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_LIGHTSHAFT] = static_cast(wiResourceManager::GetShaderManager().add(path + "lightShaftPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_OUTLINE] = static_cast(wiResourceManager::GetShaderManager().add(path + "outlinePS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_DEPTHOFFIELD] = static_cast(wiResourceManager::GetShaderManager().add(path + "depthofFieldPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_MOTIONBLUR] = static_cast(wiResourceManager::GetShaderManager().add(path + "motionBlurPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_BLOOMSEPARATE] = static_cast(wiResourceManager::GetShaderManager().add(path + "bloomSeparatePS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_FXAA] = static_cast(wiResourceManager::GetShaderManager().add(path + "fxaa.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_SSAO] = static_cast(wiResourceManager::GetShaderManager().add(path + "ssao.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_SSSS] = static_cast(wiResourceManager::GetShaderManager().add(path + "ssss.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_LINEARDEPTH] = static_cast(wiResourceManager::GetShaderManager().add(path + "linDepthPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_COLORGRADE] = static_cast(wiResourceManager::GetShaderManager().add(path + "colorGradePS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_SSR] = static_cast(wiResourceManager::GetShaderManager().add(path + "ssr.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_STEREOGRAM] = static_cast(wiResourceManager::GetShaderManager().add(path + "stereogramPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_TONEMAP] = static_cast(wiResourceManager::GetShaderManager().add(path + "toneMapPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_REPROJECTDEPTHBUFFER] = static_cast(wiResourceManager::GetShaderManager().add(path + "reprojectDepthBufferPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_DOWNSAMPLEDEPTHBUFFER] = static_cast(wiResourceManager::GetShaderManager().add(path + "downsampleDepthBuffer4xPS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_TEMPORALAA] = static_cast(wiResourceManager::GetShaderManager().add(path + "temporalAAResolvePS.cso", wiResourceManager::PIXELSHADER)); + postprocessPS[POSTPROCESS_SHARPEN] = static_cast(wiResourceManager::GetShaderManager().add(path + "sharpenPS.cso", wiResourceManager::PIXELSHADER)); - deferredPS = static_cast(wiResourceManager::GetShaderManager()->add(path + "deferredPS.cso", wiResourceManager::PIXELSHADER)); + deferredPS = static_cast(wiResourceManager::GetShaderManager().add(path + "deferredPS.cso", wiResourceManager::PIXELSHADER)); GraphicsDevice* device = wiRenderer::GetDevice(); diff --git a/WickedEngine/wiInputManager.cpp b/WickedEngine/wiInputManager.cpp index 5334d7caa..226d89cc0 100644 --- a/WickedEngine/wiInputManager.cpp +++ b/WickedEngine/wiInputManager.cpp @@ -5,8 +5,13 @@ #include "wiWindowRegistration.h" #include "wiHelper.h" +#include + using namespace std; +namespace wiInputManager +{ + #ifndef WINSTORE_SUPPORT #define KEY_DOWN(vk_code) (GetAsyncKeyState(vk_code) < 0) #define KEY_TOGGLE(vk_code) ((GetAsyncKeyState(vk_code) & 1) != 0) @@ -15,270 +20,240 @@ using namespace std; #define KEY_TOGGLE(vk_code) (((int)Windows::UI::Core::CoreWindow::GetForCurrentThread()->GetAsyncKeyState((Windows::System::VirtualKey)vk_code) & 1) != 0) #endif //WINSTORE_SUPPORT #define KEY_UP(vk_code) (!KEY_DOWN(vk_code)) -static float mousewheel_scrolled = 0.0f; + static float mousewheel_scrolled = 0.0f; -wiInputManager::wiInputManager() -{ - xinput = nullptr; - dinput = nullptr; - rawinput = nullptr; -} -wiInputManager::~wiInputManager() -{ -} + wiSpinLock locker; -wiInputManager* wiInputManager::GetInstance() -{ - static wiInputManager instance; - return &instance; -} + std::map inputs; + std::vector touches; + wiXInput* xinput = nullptr; + wiDirectInput* dinput = nullptr; + wiRawInput* rawinput = nullptr; -void wiInputManager::addXInput(wiXInput* input){ - xinput=input; -} -void wiInputManager::addDirectInput(wiDirectInput* input){ - dinput = input; -} -void wiInputManager::addRawInput(wiRawInput* input){ - rawinput = input; -} + void addXInput(wiXInput* input) { xinput = input; } + void addDirectInput(wiDirectInput* input) { dinput = input; } + void addRawInput(wiRawInput* input) { rawinput = input; } -void wiInputManager::CleanUp(){ - SAFE_DELETE(xinput); - SAFE_DELETE(dinput); - SAFE_DELETE(rawinput); -} - -void wiInputManager::Update() -{ - LOCK(); - - if(dinput){ - dinput->Frame(); - } - if(xinput){ - xinput->UpdateControllerState(); - } - if (rawinput){ - //rawinput->RetrieveBufferedData(); - } - - for (InputCollection::iterator iter = inputs.begin(); iter != inputs.end();) + void Update() { - InputType type = iter->first.type; - DWORD button = iter->first.button; - short playerIndex = iter->first.playerIndex; + locker.lock(); - bool todelete = false; - - if (down(button, type, playerIndex)) - { - iter->second++; + if (dinput) { + dinput->Frame(); } - else - { - todelete = true; + if (xinput) { + xinput->UpdateControllerState(); + } + if (rawinput) { + //rawinput->RetrieveBufferedData(); } - if (todelete) + for (auto iter = inputs.begin(); iter != inputs.end();) { - inputs.erase(iter++); - } - else - { - ++iter; + InputType type = iter->first.type; + DWORD button = iter->first.button; + short playerIndex = iter->first.playerIndex; + + bool todelete = false; + + if (down(button, type, playerIndex)) + { + iter->second++; + } + else + { + todelete = true; + } + + if (todelete) + { + inputs.erase(iter++); + } + else + { + ++iter; + } } + + touches.clear(); + + mousewheel_scrolled = 0.0f; + + locker.unlock(); } - touches.clear(); - - mousewheel_scrolled = 0.0f; - - UNLOCK(); -} - -bool wiInputManager::down(DWORD button, InputType inputType, short playerindex) -{ - if (!wiWindowRegistration::GetInstance()->IsWindowActive()) + bool down(DWORD button, InputType inputType, short playerindex) { + if (!wiWindowRegistration::IsWindowActive()) + { + return false; + } + + + switch (inputType) + { + case KEYBOARD: + return KEY_DOWN(static_cast(button)) | KEY_TOGGLE(static_cast(button)); + break; + case XINPUT_JOYPAD: + if (xinput != nullptr && xinput->isButtonDown(playerindex, button)) + return true; + break; + case DIRECTINPUT_JOYPAD: + if (dinput != nullptr && (dinput->isButtonDown(playerindex, button) || dinput->getDirections(playerindex) == button)) { + return true; + } + break; + default:break; + } return false; } - - - switch (inputType) + bool press(DWORD button, InputType inputType, short playerindex) { - case KEYBOARD: - return KEY_DOWN(static_cast(button)) | KEY_TOGGLE(static_cast(button)); - break; - case XINPUT_JOYPAD: - if (xinput != nullptr && xinput->isButtonDown(playerindex, button)) - return true; - break; - case DIRECTINPUT_JOYPAD: - if (dinput != nullptr && ( dinput->isButtonDown(playerindex, button) || dinput->getDirections(playerindex)==button )){ + if (!down(button, inputType, playerindex)) + return false; + + Input input = Input(); + input.button = button; + input.type = inputType; + input.playerIndex = playerindex; + locker.lock(); + auto iter = inputs.find(input); + if (iter == inputs.end()) + { + inputs.insert(make_pair(input, 0)); + locker.unlock(); return true; } - break; - default:break; - } - return false; -} -bool wiInputManager::press(DWORD button, InputType inputType, short playerindex) -{ - if (!down(button, inputType, playerindex)) - return false; - - Input input = Input(); - input.button=button; - input.type=inputType; - input.playerIndex = playerindex; - LOCK(); - InputCollection::iterator iter = inputs.find(input); - if(iter==inputs.end()){ - inputs.insert(InputCollection::value_type(input,0)); - UNLOCK(); - return true; - } - if (iter->second <= 0) - { - UNLOCK(); - return true; - } - UNLOCK(); - return false; -} -bool wiInputManager::hold(DWORD button, DWORD frames, bool continuous, InputType inputType, short playerIndex) -{ - - if (!down(button, inputType, playerIndex)) - return false; - - Input input = Input(); - input.button = button; - input.type = inputType; - input.playerIndex = playerIndex; - LOCK(); - InputCollection::iterator iter = inputs.find(input); - if (iter == inputs.end()) - { - inputs.insert(pair(input, 0)); - UNLOCK(); + if (iter->second <= 0) + { + locker.unlock(); + return true; + } + locker.unlock(); return false; } - else if ((!continuous && iter->second == frames) || (continuous && iter->second >= frames)) + bool hold(DWORD button, DWORD frames, bool continuous, InputType inputType, short playerIndex) { - UNLOCK(); - return true; + + if (!down(button, inputType, playerIndex)) + return false; + + Input input = Input(); + input.button = button; + input.type = inputType; + input.playerIndex = playerIndex; + locker.lock(); + auto iter = inputs.find(input); + if (iter == inputs.end()) + { + inputs.insert(make_pair(input, 0)); + locker.unlock(); + return false; + } + else if ((!continuous && iter->second == frames) || (continuous && iter->second >= frames)) + { + locker.unlock(); + return true; + } + locker.unlock(); + return false; } - UNLOCK(); - return false; -} -XMFLOAT4 wiInputManager::getpointer() -{ + XMFLOAT4 getpointer() + { #ifndef WINSTORE_SUPPORT - POINT p; - GetCursorPos(&p); - ScreenToClient(wiWindowRegistration::GetInstance()->GetRegisteredWindow(), &p); - return XMFLOAT4((float)p.x, (float)p.y, mousewheel_scrolled, 0); + POINT p; + GetCursorPos(&p); + ScreenToClient(wiWindowRegistration::GetRegisteredWindow(), &p); + return XMFLOAT4((float)p.x, (float)p.y, mousewheel_scrolled, 0); #else - auto& p = Windows::UI::Core::CoreWindow::GetForCurrentThread()->PointerPosition; - return XMFLOAT4(p.X, p.Y, mousewheel_scrolled, 0); + auto& p = Windows::UI::Core::CoreWindow::GetForCurrentThread()->PointerPosition; + return XMFLOAT4(p.X, p.Y, mousewheel_scrolled, 0); #endif -} -void wiInputManager::setpointer(const XMFLOAT4& props) -{ + } + void setpointer(const XMFLOAT4& props) + { #ifndef WINSTORE_SUPPORT - POINT p; - p.x = (LONG)props.x; - p.y = (LONG)props.y; - ClientToScreen(wiWindowRegistration::GetInstance()->GetRegisteredWindow(), &p); - SetCursorPos(p.x, p.y); + POINT p; + p.x = (LONG)props.x; + p.y = (LONG)props.y; + ClientToScreen(wiWindowRegistration::GetRegisteredWindow(), &p); + SetCursorPos(p.x, p.y); #endif - mousewheel_scrolled = props.z; -} -void wiInputManager::hidepointer(bool value) -{ -#ifndef WINSTORE_SUPPORT - ShowCursor(!value); -#endif -} -char wiInputManager::getCharPressed() -{ - for (DWORD i = 1; i < 256; ++i) + mousewheel_scrolled = props.z; + } + void hidepointer(bool value) { - if (press(i, KEYBOARD)) +#ifndef WINSTORE_SUPPORT + ShowCursor(!value); +#endif + } + + + void AddTouch(const Touch& touch) + { + locker.lock(); + touches.push_back(touch); + locker.unlock(); + } + +#ifdef WINSTORE_SUPPORT + using namespace Windows::ApplicationModel; + using namespace Windows::ApplicationModel::Core; + using namespace Windows::ApplicationModel::Activation; + using namespace Windows::UI::Core; + using namespace Windows::UI::Input; + using namespace Windows::System; + using namespace Windows::Foundation; + + void _OnPointerPressed(CoreWindow^ window, PointerEventArgs^ pointer) + { + auto p = pointer->CurrentPoint; + + Touch touch; + touch.state = Touch::TOUCHSTATE_PRESSED; + touch.pos = XMFLOAT2(p->Position.X, p->Position.Y); + AddTouch(touch); + } + void _OnPointerReleased(CoreWindow^ window, PointerEventArgs^ pointer) + { + auto p = pointer->CurrentPoint; + + Touch touch; + touch.state = Touch::TOUCHSTATE_RELEASED; + touch.pos = XMFLOAT2(p->Position.X, p->Position.Y); + AddTouch(touch); + } + void _OnPointerMoved(CoreWindow^ window, PointerEventArgs^ pointer) + { + auto p = pointer->CurrentPoint; + + Touch touch; + touch.state = Touch::TOUCHSTATE_MOVED; + touch.pos = XMFLOAT2(p->Position.X, p->Position.Y); + AddTouch(touch); + } +#endif // WINSTORE_SUPPORT + + const std::vector& getTouches() + { + static bool isRegisteredTouch = false; + if (!isRegisteredTouch) { - return static_cast(i); +#ifdef WINSTORE_SUPPORT + auto window = CoreWindow::GetForCurrentThread(); + + window->PointerPressed += ref new TypedEventHandler(_OnPointerPressed); + window->PointerReleased += ref new TypedEventHandler(_OnPointerReleased); + window->PointerMoved += ref new TypedEventHandler(_OnPointerMoved); +#endif // WINSTORE_SUPPORT + + isRegisteredTouch = true; } + + return touches; } - return 0; } - - -void AddTouch(const wiInputManager::Touch& touch) -{ - wiInputManager::GetInstance()->LOCK(); - wiInputManager::GetInstance()->touches.push_back(touch); - wiInputManager::GetInstance()->UNLOCK(); -} - -#ifdef WINSTORE_SUPPORT -using namespace Windows::ApplicationModel; -using namespace Windows::ApplicationModel::Core; -using namespace Windows::ApplicationModel::Activation; -using namespace Windows::UI::Core; -using namespace Windows::UI::Input; -using namespace Windows::System; -using namespace Windows::Foundation; - -void _OnPointerPressed(CoreWindow^ window, PointerEventArgs^ pointer) -{ - auto p = pointer->CurrentPoint; - - wiInputManager::Touch touch; - touch.state = wiInputManager::Touch::TOUCHSTATE_PRESSED; - touch.pos = XMFLOAT2(p->Position.X, p->Position.Y); - AddTouch(touch); -} -void _OnPointerReleased(CoreWindow^ window, PointerEventArgs^ pointer) -{ - auto p = pointer->CurrentPoint; - - wiInputManager::Touch touch; - touch.state = wiInputManager::Touch::TOUCHSTATE_RELEASED; - touch.pos = XMFLOAT2(p->Position.X, p->Position.Y); - AddTouch(touch); -} -void _OnPointerMoved(CoreWindow^ window, PointerEventArgs^ pointer) -{ - auto p = pointer->CurrentPoint; - - wiInputManager::Touch touch; - touch.state = wiInputManager::Touch::TOUCHSTATE_MOVED; - touch.pos = XMFLOAT2(p->Position.X, p->Position.Y); - AddTouch(touch); -} -#endif // WINSTORE_SUPPORT - -std::vector wiInputManager::getTouches() -{ - static bool isRegisteredTouch = false; - if (!isRegisteredTouch) - { -#ifdef WINSTORE_SUPPORT - auto window = CoreWindow::GetForCurrentThread(); - - window->PointerPressed += ref new TypedEventHandler(_OnPointerPressed); - window->PointerReleased += ref new TypedEventHandler(_OnPointerReleased); - window->PointerMoved += ref new TypedEventHandler(_OnPointerMoved); -#endif // WINSTORE_SUPPORT - - isRegisteredTouch = true; - } - - return touches; -} - diff --git a/WickedEngine/wiInputManager.h b/WickedEngine/wiInputManager.h index 5dfbf7fe0..f1e795e09 100644 --- a/WickedEngine/wiInputManager.h +++ b/WickedEngine/wiInputManager.h @@ -3,30 +3,18 @@ #include "wiThreadSafeManager.h" #include -#include class wiXInput; class wiDirectInput; class wiRawInput; -class wiInputManager : public wiThreadSafeManager +namespace wiInputManager { -public: - wiInputManager(); - ~wiInputManager(); - - static wiInputManager* GetInstance(); - - wiXInput* xinput; - wiDirectInput* dinput; - wiRawInput* rawinput; - void addXInput(wiXInput* input); void addDirectInput(wiDirectInput* input); void addRawInput(wiRawInput* input); void Update(); - void CleanUp(); enum InputType{ DIRECTINPUT_JOYPAD, @@ -54,8 +42,6 @@ public: } }; }; - typedef std::map InputCollection; - InputCollection inputs; //check if a button is down bool down(DWORD button, InputType inputType = InputType::KEYBOARD, short playerindex = 0); @@ -69,8 +55,6 @@ public: void setpointer(const XMFLOAT4& props); //hide pointer void hidepointer(bool value); - //find out which character is pressed on keyboard (if any) - char getCharPressed(); struct Touch { @@ -84,12 +68,7 @@ public: // current position of touch XMFLOAT2 pos; }; - std::vector getTouches(); - -private: - std::vector touches; - - friend void AddTouch(const wiInputManager::Touch& touch); + const std::vector& getTouches(); }; diff --git a/WickedEngine/wiInputManager_BindLua.cpp b/WickedEngine/wiInputManager_BindLua.cpp index 7b088f893..fa8714676 100644 --- a/WickedEngine/wiInputManager_BindLua.cpp +++ b/WickedEngine/wiInputManager_BindLua.cpp @@ -28,7 +28,7 @@ int wiInputManager_BindLua::Down(lua_State* L) { type = (wiInputManager::InputType)wiLua::SGetInt(L, 2); } - wiLua::SSetBool(L, wiInputManager::GetInstance()->down((DWORD)code, type)); + wiLua::SSetBool(L, wiInputManager::down((DWORD)code, type)); return 1; } else @@ -46,7 +46,7 @@ int wiInputManager_BindLua::Press(lua_State* L) { type = (wiInputManager::InputType)wiLua::SGetInt(L, 2); } - wiLua::SSetBool(L, wiInputManager::GetInstance()->press((DWORD)code, type)); + wiLua::SSetBool(L, wiInputManager::press((DWORD)code, type)); return 1; } else @@ -74,7 +74,7 @@ int wiInputManager_BindLua::Hold(lua_State* L) { type = (wiInputManager::InputType)wiLua::SGetInt(L, 4); } - wiLua::SSetBool(L, wiInputManager::GetInstance()->hold((DWORD)code, (DWORD)duration, continuous, type)); + wiLua::SSetBool(L, wiInputManager::hold((DWORD)code, (DWORD)duration, continuous, type)); return 1; } else @@ -83,7 +83,7 @@ int wiInputManager_BindLua::Hold(lua_State* L) } int wiInputManager_BindLua::GetPointer(lua_State* L) { - Luna::push(L, new Vector_BindLua(XMLoadFloat4(&wiInputManager::GetInstance()->getpointer()))); + Luna::push(L, new Vector_BindLua(XMLoadFloat4(&wiInputManager::getpointer()))); return 1; } int wiInputManager_BindLua::SetPointer(lua_State* L) @@ -96,7 +96,7 @@ int wiInputManager_BindLua::SetPointer(lua_State* L) { XMFLOAT4 props; XMStoreFloat4(&props, vec->vector); - wiInputManager::GetInstance()->setpointer(props); + wiInputManager::setpointer(props); } else wiLua::SError(L, "SetPointer(Vector props) argument is not a Vector!"); @@ -110,7 +110,7 @@ int wiInputManager_BindLua::HidePointer(lua_State* L) int argc = wiLua::SGetArgCount(L); if (argc > 0) { - wiInputManager::GetInstance()->hidepointer(wiLua::SGetBool(L, 1)); + wiInputManager::hidepointer(wiLua::SGetBool(L, 1)); } else wiLua::SError(L, "HidePointer(bool value) not enough arguments!"); @@ -118,7 +118,7 @@ int wiInputManager_BindLua::HidePointer(lua_State* L) } int wiInputManager_BindLua::GetTouches(lua_State* L) { - auto& touches = wiInputManager::GetInstance()->getTouches(); + auto& touches = wiInputManager::getTouches(); for (auto& touch : touches) { Luna::push(L, new Touch_BindLua(touch)); diff --git a/WickedEngine/wiLensFlare.cpp b/WickedEngine/wiLensFlare.cpp index 2666588f8..f1d341116 100644 --- a/WickedEngine/wiLensFlare.cpp +++ b/WickedEngine/wiLensFlare.cpp @@ -61,11 +61,11 @@ namespace wiLensFlare { std::string path = wiRenderer::GetShaderPath(); - vertexShader = static_cast(wiResourceManager::GetShaderManager()->add(path + "lensFlareVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShader = static_cast(wiResourceManager::GetShaderManager().add(path + "lensFlareVS.cso", wiResourceManager::VERTEXSHADER)); - pixelShader = static_cast(wiResourceManager::GetShaderManager()->add(path + "lensFlarePS.cso", wiResourceManager::PIXELSHADER)); + pixelShader = static_cast(wiResourceManager::GetShaderManager().add(path + "lensFlarePS.cso", wiResourceManager::PIXELSHADER)); - geometryShader = static_cast(wiResourceManager::GetShaderManager()->add(path + "lensFlareGS.cso", wiResourceManager::GEOMETRYSHADER)); + geometryShader = static_cast(wiResourceManager::GetShaderManager().add(path + "lensFlareGS.cso", wiResourceManager::GEOMETRYSHADER)); GraphicsDevice* device = wiRenderer::GetDevice(); diff --git a/WickedEngine/wiOcean.cpp b/WickedEngine/wiOcean.cpp index 9b1e196ea..4eeb75741 100644 --- a/WickedEngine/wiOcean.cpp +++ b/WickedEngine/wiOcean.cpp @@ -386,15 +386,15 @@ void wiOcean::LoadShaders() std::string path = wiRenderer::GetShaderPath(); - m_pUpdateSpectrumCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "oceanSimulatorCS.cso", wiResourceManager::COMPUTESHADER)); - m_pUpdateDisplacementMapCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "oceanUpdateDisplacementMapCS.cso", wiResourceManager::COMPUTESHADER)); - m_pUpdateGradientFoldingCS = static_cast(wiResourceManager::GetShaderManager()->add(path + "oceanUpdateGradientFoldingCS.cso", wiResourceManager::COMPUTESHADER)); + m_pUpdateSpectrumCS = static_cast(wiResourceManager::GetShaderManager().add(path + "oceanSimulatorCS.cso", wiResourceManager::COMPUTESHADER)); + m_pUpdateDisplacementMapCS = static_cast(wiResourceManager::GetShaderManager().add(path + "oceanUpdateDisplacementMapCS.cso", wiResourceManager::COMPUTESHADER)); + m_pUpdateGradientFoldingCS = static_cast(wiResourceManager::GetShaderManager().add(path + "oceanUpdateGradientFoldingCS.cso", wiResourceManager::COMPUTESHADER)); - g_pOceanSurfVS = static_cast(wiResourceManager::GetShaderManager()->add(path + "oceanSurfaceVS.cso", wiResourceManager::VERTEXSHADER)); + g_pOceanSurfVS = static_cast(wiResourceManager::GetShaderManager().add(path + "oceanSurfaceVS.cso", wiResourceManager::VERTEXSHADER)); - g_pOceanSurfPS = static_cast(wiResourceManager::GetShaderManager()->add(path + "oceanSurfacePS.cso", wiResourceManager::PIXELSHADER)); - g_pWireframePS = static_cast(wiResourceManager::GetShaderManager()->add(path + "oceanSurfaceSimplePS.cso", wiResourceManager::PIXELSHADER)); + g_pOceanSurfPS = static_cast(wiResourceManager::GetShaderManager().add(path + "oceanSurfacePS.cso", wiResourceManager::PIXELSHADER)); + g_pWireframePS = static_cast(wiResourceManager::GetShaderManager().add(path + "oceanSurfaceSimplePS.cso", wiResourceManager::PIXELSHADER)); GraphicsDevice* device = wiRenderer::GetDevice(); diff --git a/WickedEngine/wiPhysicsEngine_Bullet.cpp b/WickedEngine/wiPhysicsEngine_Bullet.cpp index 08522b9e7..d6992dd67 100644 --- a/WickedEngine/wiPhysicsEngine_Bullet.cpp +++ b/WickedEngine/wiPhysicsEngine_Bullet.cpp @@ -309,7 +309,7 @@ namespace wiPhysicsEngine return; } - wiProfiler::GetInstance().BeginRange("Physics", wiProfiler::DOMAIN_CPU); + wiProfiler::BeginRange("Physics", wiProfiler::DOMAIN_CPU); btVector3 wind = btVector3(weather.windDirection.x, weather.windDirection.y, weather.windDirection.z); @@ -488,6 +488,6 @@ namespace wiPhysicsEngine } } - wiProfiler::GetInstance().EndRange(); // Physics + wiProfiler::EndRange(); // Physics } } diff --git a/WickedEngine/wiProfiler.cpp b/WickedEngine/wiProfiler.cpp index 99faab3c6..a1ce882f3 100644 --- a/WickedEngine/wiProfiler.cpp +++ b/WickedEngine/wiProfiler.cpp @@ -2,71 +2,109 @@ #include "wiGraphicsDevice.h" #include "wiRenderer.h" #include "wiFont.h" +#include "wiTimer.h" +#include "wiGraphicsResource.h" #include +#include +#include using namespace std; using namespace wiGraphicsTypes; -void wiProfiler::BeginFrame() +namespace wiProfiler { - if (!ENABLED) - return; + bool ENABLED = false; + bool initialized = false; - wiRenderer::GetDevice()->QueryBegin(&disjoint, GRAPHICSTHREAD_IMMEDIATE); -} -void wiProfiler::EndFrame() -{ - if (!ENABLED) - return; - - wiRenderer::GetDevice()->QueryEnd(&disjoint, GRAPHICSTHREAD_IMMEDIATE); - while(!wiRenderer::GetDevice()->QueryRead(&disjoint, GRAPHICSTHREAD_IMMEDIATE)); - - assert(rangeStack.empty() && "There was a range which was not ended!"); - - if (disjoint.result_disjoint == FALSE) + struct Range { - for (auto& x : ranges) + PROFILER_DOMAIN domain; + std::string name; + float time; + + wiTimer cpuBegin, cpuEnd; + wiGraphicsTypes::GPUQuery gpuBegin, gpuEnd; + + Range() :time(0), domain(DOMAIN_CPU) {} + ~Range() {} + }; + std::unordered_map ranges; + std::stack rangeStack; + wiGraphicsTypes::GPUQuery disjoint; + + void BeginFrame() + { + if (!ENABLED) + return; + + if (!initialized) { - x.second->time = 0; - switch (x.second->domain) + initialized = true; + + ranges.reserve(100); + + GPUQueryDesc desc; + desc.async_latency = 4; + desc.MiscFlags = 0; + desc.Type = GPU_QUERY_TYPE_TIMESTAMP_DISJOINT; + wiRenderer::GetDevice()->CreateQuery(&desc, &disjoint); + } + + wiRenderer::GetDevice()->QueryBegin(&disjoint, GRAPHICSTHREAD_IMMEDIATE); + } + void EndFrame() + { + if (!ENABLED || !initialized) + return; + + wiRenderer::GetDevice()->QueryEnd(&disjoint, GRAPHICSTHREAD_IMMEDIATE); + while (!wiRenderer::GetDevice()->QueryRead(&disjoint, GRAPHICSTHREAD_IMMEDIATE)); + + assert(rangeStack.empty() && "There was a range which was not ended!"); + + if (disjoint.result_disjoint == FALSE) + { + for (auto& x : ranges) { - case wiProfiler::DOMAIN_CPU: - x.second->time = (float)abs(x.second->cpuEnd.elapsed() - x.second->cpuBegin.elapsed()); - break; - case wiProfiler::DOMAIN_GPU: - while (!wiRenderer::GetDevice()->QueryRead(&x.second->gpuBegin, GRAPHICSTHREAD_IMMEDIATE)); - while (!wiRenderer::GetDevice()->QueryRead(&x.second->gpuEnd, GRAPHICSTHREAD_IMMEDIATE)); - x.second->time = abs((float)(x.second->gpuEnd.result_timestamp - x.second->gpuBegin.result_timestamp) / disjoint.result_timestamp_frequency * 1000.0f); - break; - default: - assert(0); - break; + x.second->time = 0; + switch (x.second->domain) + { + case wiProfiler::DOMAIN_CPU: + x.second->time = (float)abs(x.second->cpuEnd.elapsed() - x.second->cpuBegin.elapsed()); + break; + case wiProfiler::DOMAIN_GPU: + while (!wiRenderer::GetDevice()->QueryRead(&x.second->gpuBegin, GRAPHICSTHREAD_IMMEDIATE)); + while (!wiRenderer::GetDevice()->QueryRead(&x.second->gpuEnd, GRAPHICSTHREAD_IMMEDIATE)); + x.second->time = abs((float)(x.second->gpuEnd.result_timestamp - x.second->gpuBegin.result_timestamp) / disjoint.result_timestamp_frequency * 1000.0f); + break; + default: + assert(0); + break; + } } } } -} -void wiProfiler::BeginRange(const std::string& name, PROFILER_DOMAIN domain, GRAPHICSTHREAD threadID) -{ - if (!ENABLED) - return; - - if (ranges.find(name) == ranges.end()) + void BeginRange(const std::string& name, PROFILER_DOMAIN domain, GRAPHICSTHREAD threadID) { - Range* range = new Range; - range->name = name; - range->domain = domain; - range->time = 0; + if (!ENABLED || !initialized) + return; - switch (domain) + if (ranges.find(name) == ranges.end()) { - case wiProfiler::DOMAIN_CPU: - range->cpuBegin.Start(); - range->cpuEnd.Start(); - break; - case wiProfiler::DOMAIN_GPU: + Range* range = new Range; + range->name = name; + range->domain = domain; + range->time = 0; + + switch (domain) + { + case wiProfiler::DOMAIN_CPU: + range->cpuBegin.Start(); + range->cpuEnd.Start(); + break; + case wiProfiler::DOMAIN_GPU: { GPUQueryDesc desc; desc.async_latency = 4; @@ -76,103 +114,89 @@ void wiProfiler::BeginRange(const std::string& name, PROFILER_DOMAIN domain, GRA wiRenderer::GetDevice()->CreateQuery(&desc, &range->gpuEnd); } break; - default: - assert(0); - break; + default: + assert(0); + break; + } + + + ranges.insert(make_pair(name, range)); } - - ranges.insert(make_pair(name, range)); - } - - switch (domain) - { - case wiProfiler::DOMAIN_CPU: - ranges[name]->cpuBegin.record(); - break; - case wiProfiler::DOMAIN_GPU: - wiRenderer::GetDevice()->QueryEnd(&ranges[name]->gpuBegin, threadID); - break; - default: - assert(0); - break; - } - - rangeStack.push(name); -} -void wiProfiler::EndRange(GRAPHICSTHREAD threadID) -{ - if (!ENABLED) - return; - - assert(!rangeStack.empty() && "There is no range to end!"); - const std::string& top = rangeStack.top(); - - auto& it = ranges.find(top); - if (it != ranges.end()) - { - switch (it->second->domain) + switch (domain) { case wiProfiler::DOMAIN_CPU: - it->second->cpuEnd.record(); + ranges[name]->cpuBegin.record(); break; case wiProfiler::DOMAIN_GPU: - wiRenderer::GetDevice()->QueryEnd(&it->second->gpuEnd, threadID); + wiRenderer::GetDevice()->QueryEnd(&ranges[name]->gpuBegin, threadID); break; default: assert(0); break; } + + rangeStack.push(name); } - else + void EndRange(GRAPHICSTHREAD threadID) { - assert(0); - } + if (!ENABLED || !initialized) + return; - rangeStack.pop(); -} + assert(!rangeStack.empty() && "There is no range to end!"); + const std::string& top = rangeStack.top(); -void wiProfiler::DrawData(int x, int y, GRAPHICSTHREAD threadID) -{ - if (!ENABLED) - return; - - stringstream ss(""); - ss.precision(2); - ss << "Frame Profiler Ranges:" << endl << "----------------------------" << endl; - - for (int domain = DOMAIN_CPU; domain < DOMAIN_COUNT; ++domain) - { - for (auto& x : ranges) + auto& it = ranges.find(top); + if (it != ranges.end()) { - if (x.second->domain == domain) + switch (it->second->domain) { - ss << x.first << ": " << fixed << x.second->time << " ms" << endl; + case wiProfiler::DOMAIN_CPU: + it->second->cpuEnd.record(); + break; + case wiProfiler::DOMAIN_GPU: + wiRenderer::GetDevice()->QueryEnd(&it->second->gpuEnd, threadID); + break; + default: + assert(0); + break; } } - ss << endl; + else + { + assert(0); + } + + rangeStack.pop(); } - wiFont(ss.str(), wiFontProps(x, y, -1, WIFALIGN_LEFT, WIFALIGN_TOP, 0, 0, wiColor(255,255,255,255), wiColor(0,0,0,255))).Draw(threadID); -} - - -wiProfiler::wiProfiler() -{ - ranges.reserve(100); - - GPUQueryDesc desc; - desc.async_latency = 4; - desc.MiscFlags = 0; - desc.Type = GPU_QUERY_TYPE_TIMESTAMP_DISJOINT; - wiRenderer::GetDevice()->CreateQuery(&desc, &disjoint); - - ENABLED = false; -} -wiProfiler::~wiProfiler() -{ - for (auto& x : ranges) + void DrawData(int x, int y, GRAPHICSTHREAD threadID) { - SAFE_DELETE(x.second); + if (!ENABLED || !initialized) + return; + + stringstream ss(""); + ss.precision(2); + ss << "Frame Profiler Ranges:" << endl << "----------------------------" << endl; + + for (int domain = DOMAIN_CPU; domain < DOMAIN_COUNT; ++domain) + { + for (auto& x : ranges) + { + if (x.second->domain == domain) + { + ss << x.first << ": " << fixed << x.second->time << " ms" << endl; + } + } + ss << endl; + } + + wiFont(ss.str(), wiFontProps(x, y, -1, WIFALIGN_LEFT, WIFALIGN_TOP, 0, 0, wiColor(255, 255, 255, 255), wiColor(0, 0, 0, 255))).Draw(threadID); } + + void SetEnabled(bool value) + { + ENABLED = value; + } + } diff --git a/WickedEngine/wiProfiler.h b/WickedEngine/wiProfiler.h index a12a85347..50c4e61e5 100644 --- a/WickedEngine/wiProfiler.h +++ b/WickedEngine/wiProfiler.h @@ -1,55 +1,25 @@ #pragma once -#include -#include -#include - #include "wiEnums.h" -#include "wiTimer.h" -#include "wiGraphicsResource.h" -class wiProfiler +#include + +namespace wiProfiler { -public: - static wiProfiler& GetInstance() { static wiProfiler profiler; return profiler; } - enum PROFILER_DOMAIN { DOMAIN_CPU, DOMAIN_GPU, DOMAIN_COUNT }; - struct Range - { - PROFILER_DOMAIN domain; - std::string name; - float time; - - wiTimer cpuBegin, cpuEnd; - wiGraphicsTypes::GPUQuery gpuBegin, gpuEnd; - - Range() :time(0), domain(DOMAIN_CPU) {} - ~Range() {} - }; void BeginFrame(); void EndFrame(); void BeginRange(const std::string& name, PROFILER_DOMAIN domain, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); void EndRange(GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); - float GetRangeTime(const std::string& name) { return ranges[name]->time; } - const std::unordered_map& GetRanges() { return ranges; } - // Renders a basic text of the Profiling results to the (x,y) screen coordinate void DrawData(int x, int y, GRAPHICSTHREAD threadID); - bool ENABLED; - -private: - wiProfiler(); - ~wiProfiler(); - - std::unordered_map ranges; - std::stack rangeStack; - wiGraphicsTypes::GPUQuery disjoint; + void SetEnabled(bool value); }; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 8070b1616..f32f658c2 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -402,7 +402,7 @@ void ReloadShaders(const std::string& path) GetDevice()->WaitForGPU(); - wiResourceManager::GetShaderManager()->CleanUp(); + wiResourceManager::GetShaderManager().Clear(); LoadShaders(); wiHairParticle::LoadShaders(); wiEmittedParticle::LoadShaders(); @@ -444,63 +444,6 @@ void Initialize() frameAllocators[i].reserve(4 * 1024 * 1024); } - for (int i = 0; i < VSTYPE_LAST; ++i) - { - SAFE_INIT(vertexShaders[i]); - } - for (int i = 0; i < PSTYPE_LAST; ++i) - { - SAFE_INIT(pixelShaders[i]); - } - for (int i = 0; i < GSTYPE_LAST; ++i) - { - SAFE_INIT(geometryShaders[i]); - } - for (int i = 0; i < HSTYPE_LAST; ++i) - { - SAFE_INIT(hullShaders[i]); - } - for (int i = 0; i < DSTYPE_LAST; ++i) - { - SAFE_INIT(domainShaders[i]); - } - for (int i = 0; i < CSTYPE_LAST; ++i) - { - SAFE_INIT(computeShaders[i]); - } - for (int i = 0; i < VLTYPE_LAST; ++i) - { - SAFE_INIT(vertexLayouts[i]); - } - for (int i = 0; i < RSTYPE_LAST; ++i) - { - SAFE_INIT(rasterizers[i]); - } - for (int i = 0; i < DSSTYPE_LAST; ++i) - { - SAFE_INIT(depthStencils[i]); - } - for (int i = 0; i < CBTYPE_LAST; ++i) - { - SAFE_INIT(constantBuffers[i]); - } - for (int i = 0; i < RBTYPE_LAST; ++i) - { - SAFE_INIT(resourceBuffers[i]); - } - for (int i = 0; i < TEXTYPE_LAST; ++i) - { - SAFE_INIT(textures[i]); - } - for (int i = 0; i < SSLOT_COUNT_PERSISTENT; ++i) - { - SAFE_INIT(samplers[i]); - } - for (int i = 0; i < SSTYPE_LAST; ++i) - { - SAFE_INIT(customsamplers[i]); - } - GetCamera().CreatePerspective((float)GetInternalResolution().x, (float)GetInternalResolution().y, 0.1f, 800); SetUpStates(); @@ -1754,7 +1697,7 @@ void LoadShaders() { { "POSITION_NORMAL_SUBSETINDEX", 0, MeshComponent::Vertex_POS::FORMAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, }; - vertexShaders[VSTYPE_OBJECT_DEBUG] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS_debug.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_OBJECT_DEBUG] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectVS_debug.cso", wiResourceManager::VERTEXSHADER)); device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_OBJECT_DEBUG]->code, vertexLayouts[VLTYPE_OBJECT_DEBUG]); } { @@ -1772,7 +1715,7 @@ void LoadShaders() { "MATIPREV", 1, FORMAT_R32G32B32A32_FLOAT, 3, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, { "MATIPREV", 2, FORMAT_R32G32B32A32_FLOAT, 3, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, }; - vertexShaders[VSTYPE_OBJECT_COMMON] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS_common.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_OBJECT_COMMON] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectVS_common.cso", wiResourceManager::VERTEXSHADER)); device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_OBJECT_COMMON]->code, vertexLayouts[VLTYPE_OBJECT_ALL]); } @@ -1786,7 +1729,7 @@ void LoadShaders() { "MATI", 2, FORMAT_R32G32B32A32_FLOAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, { "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, }; - vertexShaders[VSTYPE_OBJECT_POSITIONSTREAM] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS_positionstream.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_OBJECT_POSITIONSTREAM] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectVS_positionstream.cso", wiResourceManager::VERTEXSHADER)); device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_OBJECT_POSITIONSTREAM]->code, vertexLayouts[VLTYPE_OBJECT_POS]); } @@ -1801,7 +1744,7 @@ void LoadShaders() { "MATI", 2, FORMAT_R32G32B32A32_FLOAT, 2, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, { "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 2, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, }; - vertexShaders[VSTYPE_OBJECT_SIMPLE] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS_simple.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_OBJECT_SIMPLE] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectVS_simple.cso", wiResourceManager::VERTEXSHADER)); device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_OBJECT_SIMPLE]->code, vertexLayouts[VLTYPE_OBJECT_POS_TEX]); } @@ -1815,7 +1758,7 @@ void LoadShaders() { "MATI", 2, FORMAT_R32G32B32A32_FLOAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, { "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 1, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, }; - vertexShaders[VSTYPE_SHADOW] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "shadowVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_SHADOW] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "shadowVS.cso", wiResourceManager::VERTEXSHADER)); device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_SHADOW]->code, vertexLayouts[VLTYPE_SHADOW_POS]); } @@ -1830,11 +1773,11 @@ void LoadShaders() { "MATI", 2, FORMAT_R32G32B32A32_FLOAT, 2, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, { "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 2, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, }; - vertexShaders[VSTYPE_SHADOW_ALPHATEST] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "shadowVS_alphatest.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_SHADOW_ALPHATEST] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "shadowVS_alphatest.cso", wiResourceManager::VERTEXSHADER)); device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_SHADOW_ALPHATEST]->code, vertexLayouts[VLTYPE_SHADOW_POS_TEX]); - vertexShaders[VSTYPE_SHADOW_TRANSPARENT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "shadowVS_transparent.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_SHADOW_TRANSPARENT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "shadowVS_transparent.cso", wiResourceManager::VERTEXSHADER)); } @@ -1844,7 +1787,7 @@ void LoadShaders() { "POSITION", 0, FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, }; - vertexShaders[VSTYPE_LINE] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "linesVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_LINE] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "linesVS.cso", wiResourceManager::VERTEXSHADER)); device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_LINE]->code, vertexLayouts[VLTYPE_LINE]); } @@ -1856,163 +1799,163 @@ void LoadShaders() { "TEXCOORD", 0, FORMAT_R32G32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 1, FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, }; - vertexShaders[VSTYPE_TRAIL] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "trailVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_TRAIL] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "trailVS.cso", wiResourceManager::VERTEXSHADER)); device->CreateInputLayout(layout, ARRAYSIZE(layout), &vertexShaders[VSTYPE_TRAIL]->code, vertexLayouts[VLTYPE_TRAIL]); } - vertexShaders[VSTYPE_OBJECT_COMMON_TESSELLATION] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS_common_tessellation.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_OBJECT_SIMPLE_TESSELLATION] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS_simple_tessellation.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_IMPOSTOR] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "impostorVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_DIRLIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "dirLightVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_POINTLIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "pointLightVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_SPOTLIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "spotLightVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_LIGHTVISUALIZER_SPOTLIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "vSpotLightVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_LIGHTVISUALIZER_POINTLIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "vPointLightVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_LIGHTVISUALIZER_SPHERELIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "vSphereLightVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_LIGHTVISUALIZER_DISCLIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "vDiscLightVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_LIGHTVISUALIZER_RECTANGLELIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "vRectangleLightVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_LIGHTVISUALIZER_TUBELIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "vTubeLightVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_DECAL] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "decalVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_ENVMAP] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "envMapVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_ENVMAP_SKY] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "envMap_skyVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_SPHERE] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "sphereVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_CUBE] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubeVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_SHADOWCUBEMAPRENDER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubeShadowVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_SHADOWCUBEMAPRENDER_ALPHATEST] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubeShadowVS_alphatest.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_SKY] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "skyVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_WATER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "waterVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_VOXELIZER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS_voxelizer.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_VOXEL] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "voxelVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_FORCEFIELDVISUALIZER_POINT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "forceFieldPointVisualizerVS.cso", wiResourceManager::VERTEXSHADER)); - vertexShaders[VSTYPE_FORCEFIELDVISUALIZER_PLANE] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "forceFieldPlaneVisualizerVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_OBJECT_COMMON_TESSELLATION] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectVS_common_tessellation.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_OBJECT_SIMPLE_TESSELLATION] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectVS_simple_tessellation.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_IMPOSTOR] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "impostorVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_DIRLIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "dirLightVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_POINTLIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "pointLightVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_SPOTLIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "spotLightVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_LIGHTVISUALIZER_SPOTLIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "vSpotLightVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_LIGHTVISUALIZER_POINTLIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "vPointLightVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_LIGHTVISUALIZER_SPHERELIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "vSphereLightVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_LIGHTVISUALIZER_DISCLIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "vDiscLightVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_LIGHTVISUALIZER_RECTANGLELIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "vRectangleLightVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_LIGHTVISUALIZER_TUBELIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "vTubeLightVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_DECAL] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "decalVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_ENVMAP] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "envMapVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_ENVMAP_SKY] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "envMap_skyVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_SPHERE] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "sphereVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_CUBE] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "cubeVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_SHADOWCUBEMAPRENDER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "cubeShadowVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_SHADOWCUBEMAPRENDER_ALPHATEST] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "cubeShadowVS_alphatest.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_SKY] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "skyVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_WATER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "waterVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_VOXELIZER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectVS_voxelizer.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_VOXEL] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "voxelVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_FORCEFIELDVISUALIZER_POINT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "forceFieldPointVisualizerVS.cso", wiResourceManager::VERTEXSHADER)); + vertexShaders[VSTYPE_FORCEFIELDVISUALIZER_PLANE] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "forceFieldPlaneVisualizerVS.cso", wiResourceManager::VERTEXSHADER)); - pixelShaders[PSTYPE_OBJECT_DEFERRED] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_deferred.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_DEFERRED_NORMALMAP] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_deferred_normalmap.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_DEFERRED_POM] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_deferred_pom.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_DEFERRED_NORMALMAP_POM] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_deferred_normalmap_pom.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_IMPOSTOR_DEFERRED] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "impostorPS_deferred.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_DEFERRED] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_deferred.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_DEFERRED_NORMALMAP] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_deferred_normalmap.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_DEFERRED_POM] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_deferred_pom.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_DEFERRED_NORMALMAP_POM] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_deferred_normalmap_pom.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_IMPOSTOR_DEFERRED] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "impostorPS_deferred.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_FORWARD] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_forward.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_FORWARD_NORMALMAP] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_forward_normalmap.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_forward_transparent.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT_NORMALMAP] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_forward_transparent_normalmap.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_FORWARD_PLANARREFLECTION] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_forward_planarreflection.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_FORWARD_NORMALMAP_PLANARREFLECTION] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_forward_normalmap_planarreflection.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT_PLANARREFLECTION] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_forward_transparent_planarreflection.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT_NORMALMAP_PLANARREFLECTION] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_forward_transparent_normalmap_planarreflection.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_FORWARD_POM] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_forward_pom.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_FORWARD_NORMALMAP_POM] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_forward_normalmap_pom.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT_POM] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_forward_transparent_pom.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT_NORMALMAP_POM] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_forward_transparent_normalmap_pom.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_FORWARD_WATER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_forward_water.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_IMPOSTOR_FORWARD] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "impostorPS_forward.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_FORWARD] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_forward.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_FORWARD_NORMALMAP] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_forward_normalmap.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_forward_transparent.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT_NORMALMAP] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_forward_transparent_normalmap.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_FORWARD_PLANARREFLECTION] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_forward_planarreflection.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_FORWARD_NORMALMAP_PLANARREFLECTION] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_forward_normalmap_planarreflection.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT_PLANARREFLECTION] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_forward_transparent_planarreflection.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT_NORMALMAP_PLANARREFLECTION] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_forward_transparent_normalmap_planarreflection.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_FORWARD_POM] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_forward_pom.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_FORWARD_NORMALMAP_POM] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_forward_normalmap_pom.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT_POM] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_forward_transparent_pom.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT_NORMALMAP_POM] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_forward_transparent_normalmap_pom.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_FORWARD_WATER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_forward_water.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_IMPOSTOR_FORWARD] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "impostorPS_forward.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_TILEDFORWARD] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_tiledforward.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_NORMALMAP] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_tiledforward_normalmap.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_tiledforward_transparent.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_NORMALMAP] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_tiledforward_transparent_normalmap.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_PLANARREFLECTION] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_tiledforward_planarreflection.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_NORMALMAP_PLANARREFLECTION] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_tiledforward_normalmap_planarreflection.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_PLANARREFLECTION] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_tiledforward_transparent_planarreflection.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_NORMALMAP_PLANARREFLECTION] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_tiledforward_transparent_normalmap_planarreflection.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_POM] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_tiledforward_pom.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_NORMALMAP_POM] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_tiledforward_normalmap_pom.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_POM] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_tiledforward_transparent_pom.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_NORMALMAP_POM] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_tiledforward_transparent_normalmap_pom.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_WATER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_tiledforward_water.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_IMPOSTOR_TILEDFORWARD] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "impostorPS_tiledforward.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_TILEDFORWARD] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_tiledforward.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_NORMALMAP] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_tiledforward_normalmap.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_tiledforward_transparent.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_NORMALMAP] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_tiledforward_transparent_normalmap.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_PLANARREFLECTION] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_tiledforward_planarreflection.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_NORMALMAP_PLANARREFLECTION] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_tiledforward_normalmap_planarreflection.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_PLANARREFLECTION] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_tiledforward_transparent_planarreflection.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_NORMALMAP_PLANARREFLECTION] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_tiledforward_transparent_normalmap_planarreflection.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_POM] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_tiledforward_pom.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_NORMALMAP_POM] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_tiledforward_normalmap_pom.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_POM] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_tiledforward_transparent_pom.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_NORMALMAP_POM] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_tiledforward_transparent_normalmap_pom.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_WATER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_tiledforward_water.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_IMPOSTOR_TILEDFORWARD] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "impostorPS_tiledforward.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_HOLOGRAM] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_hologram.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_HOLOGRAM] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_hologram.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_DEBUG] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_debug.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_SIMPLEST] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_simplest.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_BLACKOUT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_blackout.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_TEXTUREONLY] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_textureonly.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_OBJECT_ALPHATESTONLY] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_alphatestonly.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_IMPOSTOR_ALPHATESTONLY] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "impostorPS_alphatestonly.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_IMPOSTOR_SIMPLE] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "impostorPS_simple.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_ENVIRONMENTALLIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "environmentalLightPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_DIRLIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "dirLightPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_POINTLIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "pointLightPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_SPOTLIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "spotLightPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_SPHERELIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "sphereLightPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_DISCLIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "discLightPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_RECTANGLELIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "rectangleLightPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_TUBELIGHT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "tubeLightPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_LIGHTVISUALIZER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "lightVisualizerPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_VOLUMETRICLIGHT_DIRECTIONAL] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "volumetricLight_DirectionalPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_VOLUMETRICLIGHT_POINT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "volumetricLight_PointPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_VOLUMETRICLIGHT_SPOT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "volumetricLight_SpotPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_DECAL] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "decalPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_ENVMAP] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "envMapPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_ENVMAP_SKY_STATIC] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "envMap_skyPS_static.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_ENVMAP_SKY_DYNAMIC] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "envMap_skyPS_dynamic.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_CAPTUREIMPOSTOR_ALBEDO] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "captureImpostorPS_albedo.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_CAPTUREIMPOSTOR_NORMAL] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "captureImpostorPS_normal.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_CAPTUREIMPOSTOR_SURFACE] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "captureImpostorPS_surface.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_CUBEMAP] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubemapPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_LINE] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "linesPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_SKY_STATIC] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "skyPS_static.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_SKY_DYNAMIC] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "skyPS_dynamic.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_SUN] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "sunPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_SHADOW_ALPHATEST] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "shadowPS_alphatest.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_SHADOW_TRANSPARENT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "shadowPS_transparent.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_SHADOW_WATER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "shadowPS_water.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_SHADOWCUBEMAPRENDER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubeShadowPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_SHADOWCUBEMAPRENDER_ALPHATEST] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubeShadowPS_alphatest.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_TRAIL] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "trailPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_VOXELIZER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_voxelizer.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_VOXEL] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "voxelPS.cso", wiResourceManager::PIXELSHADER)); - pixelShaders[PSTYPE_FORCEFIELDVISUALIZER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "forceFieldVisualizerPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_DEBUG] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_debug.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_SIMPLEST] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_simplest.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_BLACKOUT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_blackout.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_TEXTUREONLY] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_textureonly.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_OBJECT_ALPHATESTONLY] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_alphatestonly.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_IMPOSTOR_ALPHATESTONLY] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "impostorPS_alphatestonly.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_IMPOSTOR_SIMPLE] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "impostorPS_simple.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_ENVIRONMENTALLIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "environmentalLightPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_DIRLIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "dirLightPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_POINTLIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "pointLightPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_SPOTLIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "spotLightPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_SPHERELIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "sphereLightPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_DISCLIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "discLightPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_RECTANGLELIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "rectangleLightPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_TUBELIGHT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "tubeLightPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_LIGHTVISUALIZER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "lightVisualizerPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_VOLUMETRICLIGHT_DIRECTIONAL] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "volumetricLight_DirectionalPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_VOLUMETRICLIGHT_POINT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "volumetricLight_PointPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_VOLUMETRICLIGHT_SPOT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "volumetricLight_SpotPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_DECAL] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "decalPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_ENVMAP] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "envMapPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_ENVMAP_SKY_STATIC] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "envMap_skyPS_static.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_ENVMAP_SKY_DYNAMIC] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "envMap_skyPS_dynamic.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_CAPTUREIMPOSTOR_ALBEDO] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "captureImpostorPS_albedo.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_CAPTUREIMPOSTOR_NORMAL] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "captureImpostorPS_normal.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_CAPTUREIMPOSTOR_SURFACE] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "captureImpostorPS_surface.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_CUBEMAP] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "cubemapPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_LINE] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "linesPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_SKY_STATIC] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "skyPS_static.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_SKY_DYNAMIC] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "skyPS_dynamic.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_SUN] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "sunPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_SHADOW_ALPHATEST] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "shadowPS_alphatest.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_SHADOW_TRANSPARENT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "shadowPS_transparent.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_SHADOW_WATER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "shadowPS_water.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_SHADOWCUBEMAPRENDER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "cubeShadowPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_SHADOWCUBEMAPRENDER_ALPHATEST] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "cubeShadowPS_alphatest.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_TRAIL] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "trailPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_VOXELIZER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectPS_voxelizer.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_VOXEL] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "voxelPS.cso", wiResourceManager::PIXELSHADER)); + pixelShaders[PSTYPE_FORCEFIELDVISUALIZER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "forceFieldVisualizerPS.cso", wiResourceManager::PIXELSHADER)); - geometryShaders[GSTYPE_ENVMAP] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "envMapGS.cso", wiResourceManager::GEOMETRYSHADER)); - geometryShaders[GSTYPE_ENVMAP_SKY] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "envMap_skyGS.cso", wiResourceManager::GEOMETRYSHADER)); - geometryShaders[GSTYPE_SHADOWCUBEMAPRENDER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubeShadowGS.cso", wiResourceManager::GEOMETRYSHADER)); - geometryShaders[GSTYPE_SHADOWCUBEMAPRENDER_ALPHATEST] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubeShadowGS_alphatest.cso", wiResourceManager::GEOMETRYSHADER)); - geometryShaders[GSTYPE_VOXELIZER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectGS_voxelizer.cso", wiResourceManager::GEOMETRYSHADER)); - geometryShaders[GSTYPE_VOXEL] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "voxelGS.cso", wiResourceManager::GEOMETRYSHADER)); + geometryShaders[GSTYPE_ENVMAP] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "envMapGS.cso", wiResourceManager::GEOMETRYSHADER)); + geometryShaders[GSTYPE_ENVMAP_SKY] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "envMap_skyGS.cso", wiResourceManager::GEOMETRYSHADER)); + geometryShaders[GSTYPE_SHADOWCUBEMAPRENDER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "cubeShadowGS.cso", wiResourceManager::GEOMETRYSHADER)); + geometryShaders[GSTYPE_SHADOWCUBEMAPRENDER_ALPHATEST] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "cubeShadowGS_alphatest.cso", wiResourceManager::GEOMETRYSHADER)); + geometryShaders[GSTYPE_VOXELIZER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectGS_voxelizer.cso", wiResourceManager::GEOMETRYSHADER)); + geometryShaders[GSTYPE_VOXEL] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "voxelGS.cso", wiResourceManager::GEOMETRYSHADER)); - computeShaders[CSTYPE_LUMINANCE_PASS1] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "luminancePass1CS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_LUMINANCE_PASS2] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "luminancePass2CS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_TILEFRUSTUMS] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "tileFrustumsCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_RESOLVEMSAADEPTHSTENCIL] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "resolveMSAADepthStencilCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_VOXELSCENECOPYCLEAR] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "voxelSceneCopyClearCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_VOXELSCENECOPYCLEAR_TEMPORALSMOOTHING] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "voxelSceneCopyClear_TemporalSmoothing.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_VOXELRADIANCESECONDARYBOUNCE] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "voxelRadianceSecondaryBounceCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_VOXELCLEARONLYNORMAL] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "voxelClearOnlyNormalCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_GENERATEMIPCHAIN2D_UNORM4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "generateMIPChain2D_unorm4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "generateMIPChain2D_float4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_GENERATEMIPCHAIN2D_UNORM4_GAUSSIAN] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "generateMIPChain2D_unorm4_GaussianCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_GAUSSIAN] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "generateMIPChain2D_float4_GaussianCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "generateMIPChain3D_unorm4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "generateMIPChain3D_float4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_GENERATEMIPCHAIN3D_UNORM4_GAUSSIAN] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "generateMIPChain3D_unorm4_GaussianCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_GAUSSIAN] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "generateMIPChain3D_float4_GaussianCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_GENERATEMIPCHAINCUBE_UNORM4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "generateMIPChainCube_unorm4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_GENERATEMIPCHAINCUBE_FLOAT4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "generateMIPChainCube_float4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_GENERATEMIPCHAINCUBEARRAY_UNORM4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "generateMIPChainCubeArray_unorm4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_GENERATEMIPCHAINCUBEARRAY_FLOAT4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "generateMIPChainCubeArray_float4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_FILTERENVMAP] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "filterEnvMapCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_COPYTEXTURE2D_UNORM4] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "copytexture2D_unorm4CS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_COPYTEXTURE2D_UNORM4_BORDEREXPAND] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "copytexture2D_unorm4_borderexpandCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_SKINNING] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "skinningCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_SKINNING_LDS] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "skinningCS_LDS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_CLOUDGENERATOR] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cloudGeneratorCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_RAYTRACE_CLEAR] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "raytrace_clearCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_RAYTRACE_LAUNCH] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "raytrace_launchCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_RAYTRACE_KICKJOBS] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "raytrace_kickjobsCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_RAYTRACE_PRIMARY] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "raytrace_primaryCS.cso", wiResourceManager::COMPUTESHADER)); - computeShaders[CSTYPE_RAYTRACE_LIGHTSAMPLING] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "raytrace_lightsamplingCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_LUMINANCE_PASS1] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "luminancePass1CS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_LUMINANCE_PASS2] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "luminancePass2CS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_TILEFRUSTUMS] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "tileFrustumsCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_RESOLVEMSAADEPTHSTENCIL] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "resolveMSAADepthStencilCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_VOXELSCENECOPYCLEAR] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "voxelSceneCopyClearCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_VOXELSCENECOPYCLEAR_TEMPORALSMOOTHING] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "voxelSceneCopyClear_TemporalSmoothing.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_VOXELRADIANCESECONDARYBOUNCE] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "voxelRadianceSecondaryBounceCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_VOXELCLEARONLYNORMAL] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "voxelClearOnlyNormalCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_GENERATEMIPCHAIN2D_UNORM4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain2D_unorm4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain2D_float4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_GENERATEMIPCHAIN2D_UNORM4_GAUSSIAN] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain2D_unorm4_GaussianCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_GAUSSIAN] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain2D_float4_GaussianCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain3D_unorm4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain3D_float4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_GENERATEMIPCHAIN3D_UNORM4_GAUSSIAN] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain3D_unorm4_GaussianCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_GAUSSIAN] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChain3D_float4_GaussianCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_GENERATEMIPCHAINCUBE_UNORM4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChainCube_unorm4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_GENERATEMIPCHAINCUBE_FLOAT4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChainCube_float4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_GENERATEMIPCHAINCUBEARRAY_UNORM4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChainCubeArray_unorm4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_GENERATEMIPCHAINCUBEARRAY_FLOAT4_SIMPLEFILTER] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "generateMIPChainCubeArray_float4_SimpleFilterCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_FILTERENVMAP] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "filterEnvMapCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_COPYTEXTURE2D_UNORM4] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "copytexture2D_unorm4CS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_COPYTEXTURE2D_UNORM4_BORDEREXPAND] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "copytexture2D_unorm4_borderexpandCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_SKINNING] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "skinningCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_SKINNING_LDS] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "skinningCS_LDS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_CLOUDGENERATOR] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "cloudGeneratorCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_RAYTRACE_CLEAR] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "raytrace_clearCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_RAYTRACE_LAUNCH] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "raytrace_launchCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_RAYTRACE_KICKJOBS] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "raytrace_kickjobsCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_RAYTRACE_PRIMARY] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "raytrace_primaryCS.cso", wiResourceManager::COMPUTESHADER)); + computeShaders[CSTYPE_RAYTRACE_LIGHTSAMPLING] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "raytrace_lightsamplingCS.cso", wiResourceManager::COMPUTESHADER)); - hullShaders[HSTYPE_OBJECT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectHS.cso", wiResourceManager::HULLSHADER)); + hullShaders[HSTYPE_OBJECT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectHS.cso", wiResourceManager::HULLSHADER)); - domainShaders[DSTYPE_OBJECT] = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectDS.cso", wiResourceManager::DOMAINSHADER)); + domainShaders[DSTYPE_OBJECT] = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + "objectDS.cso", wiResourceManager::DOMAINSHADER)); // default objectshaders: @@ -2706,7 +2649,7 @@ void LoadShaders() name += ".cso"; ComputePSODesc desc; - desc.cs = static_cast(wiResourceManager::GetShaderManager()->add(SHADERPATH + name, wiResourceManager::COMPUTESHADER)); + desc.cs = static_cast(wiResourceManager::GetShaderManager().add(SHADERPATH + name, wiResourceManager::COMPUTESHADER)); RECREATE(CPSO_tiledlighting[i][j][k]); device->CreateComputePSO(&desc, CPSO_tiledlighting[i][j][k]); } @@ -3407,7 +3350,7 @@ void UpdatePerFrameData(float dt) // Perform culling and obtain closest reflector: requestReflectionRendering = false; - wiProfiler::GetInstance().BeginRange("Frustum Culling", wiProfiler::DOMAIN_CPU); + wiProfiler::BeginRange("Frustum Culling", wiProfiler::DOMAIN_CPU); { for (auto& x : frameCullings) { @@ -3530,7 +3473,7 @@ void UpdatePerFrameData(float dt) } } - wiProfiler::GetInstance().EndRange(); // Frustum Culling + wiProfiler::EndRange(); // Frustum Culling // Ocean will override any current reflectors waterPlane = scene.waterPlane; @@ -3844,7 +3787,7 @@ void UpdateRenderData(GRAPHICSTHREAD threadID) ManageDecalAtlas(threadID); - wiProfiler::GetInstance().BeginRange("Skinning", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Skinning", wiProfiler::DOMAIN_GPU, threadID); device->EventBegin("Skinning", threadID); { bool streamOutSetUp = false; @@ -3932,7 +3875,7 @@ void UpdateRenderData(GRAPHICSTHREAD threadID) } device->EventEnd(threadID); - wiProfiler::GetInstance().EndRange(threadID); // skinning + wiProfiler::EndRange(threadID); // skinning // Update soft body vertex buffers: for (size_t i = 0; i < scene.softbodies.GetCount(); ++i) @@ -4036,7 +3979,7 @@ void OcclusionCulling_Render(GRAPHICSTHREAD threadID) const FrameCulling& culling = frameCullings[&GetCamera()]; - wiProfiler::GetInstance().BeginRange("Occlusion Culling Render", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Occlusion Culling Render", wiProfiler::DOMAIN_GPU, threadID); int queryID = 0; @@ -4100,7 +4043,7 @@ void OcclusionCulling_Render(GRAPHICSTHREAD threadID) GetDevice()->EventEnd(threadID); } - wiProfiler::GetInstance().EndRange(threadID); // Occlusion Culling Render + wiProfiler::EndRange(threadID); // Occlusion Culling Render } void OcclusionCulling_Read() { @@ -4109,7 +4052,7 @@ void OcclusionCulling_Read() return; } - wiProfiler::GetInstance().BeginRange("Occlusion Culling Read", wiProfiler::DOMAIN_CPU); + wiProfiler::BeginRange("Occlusion Culling Read", wiProfiler::DOMAIN_CPU); const FrameCulling& culling = frameCullings[&GetCamera()]; @@ -4155,7 +4098,7 @@ void OcclusionCulling_Read() GetDevice()->EventEnd(GRAPHICSTHREAD_IMMEDIATE); } - wiProfiler::GetInstance().EndRange(); // Occlusion Culling Read + wiProfiler::EndRange(); // Occlusion Culling Read } void EndFrame() { @@ -4247,7 +4190,7 @@ void DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) Scene& scene = GetScene(); GetDevice()->EventBegin("Light Render", threadID); - wiProfiler::GetInstance().BeginRange("Light Render", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Light Render", wiProfiler::DOMAIN_GPU, threadID); // Environmental light (envmap + voxelGI) is always drawn { @@ -4313,7 +4256,7 @@ void DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) } - wiProfiler::GetInstance().EndRange(threadID); + wiProfiler::EndRange(threadID); GetDevice()->EventEnd(threadID); } void DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHREAD threadID) @@ -4647,7 +4590,7 @@ void DrawForShadowMap(const CameraComponent& camera, GRAPHICSTHREAD threadID, ui if (!culling.culledLights.empty()) { GetDevice()->EventBegin("ShadowMap Render", threadID); - wiProfiler::GetInstance().BeginRange("Shadow Rendering", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Shadow Rendering", wiProfiler::DOMAIN_GPU, threadID); const bool all_layers = layerMask == 0xFFFFFFFF; @@ -4943,7 +4886,7 @@ void DrawForShadowMap(const CameraComponent& camera, GRAPHICSTHREAD threadID, ui GetDevice()->BindRenderTargets(0, nullptr, nullptr, threadID); - wiProfiler::GetInstance().EndRange(); // Shadow Rendering + wiProfiler::EndRange(); // Shadow Rendering GetDevice()->EventEnd(threadID); } @@ -5347,7 +5290,7 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) if (probe.textureIndex < 0) { - device->BindResource(PS, wiTextureHelper::getInstance()->getBlackCubeMap(), TEXSLOT_ONDEMAND0, threadID); + device->BindResource(PS, wiTextureHelper::getBlackCubeMap(), TEXSLOT_ONDEMAND0, threadID); } else { @@ -5616,7 +5559,7 @@ void DrawSky(GRAPHICSTHREAD threadID) } else { - GetDevice()->BindResource(PS, wiTextureHelper::getInstance()->getBlack(), TEXSLOT_ONDEMAND0, threadID); + GetDevice()->BindResource(PS, wiTextureHelper::getBlack(), TEXSLOT_ONDEMAND0, threadID); } } @@ -5632,7 +5575,7 @@ void DrawSun(GRAPHICSTHREAD threadID) if (enviroMap != nullptr) { - GetDevice()->BindResource(PS, wiTextureHelper::getInstance()->getBlack(), TEXSLOT_ONDEMAND0, threadID); + GetDevice()->BindResource(PS, wiTextureHelper::getBlack(), TEXSLOT_ONDEMAND0, threadID); } else { @@ -6133,7 +6076,7 @@ void VoxelRadiance(GRAPHICSTHREAD threadID) GraphicsDevice* device = GetDevice(); device->EventBegin("Voxel Radiance", threadID); - wiProfiler::GetInstance().BeginRange("Voxel Radiance", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Voxel Radiance", wiProfiler::DOMAIN_GPU, threadID); Scene& scene = GetScene(); @@ -6279,7 +6222,7 @@ void VoxelRadiance(GRAPHICSTHREAD threadID) device->BindResource(PS, result, TEXSLOT_VOXELRADIANCE, threadID); device->BindResource(CS, result, TEXSLOT_VOXELRADIANCE, threadID); - wiProfiler::GetInstance().EndRange(threadID); + wiProfiler::EndRange(threadID); device->EventEnd(threadID); } @@ -6294,7 +6237,7 @@ inline XMUINT3 GetEntityCullingTileCount() } void ComputeTiledLightCulling(bool deferred, GRAPHICSTHREAD threadID) { - wiProfiler::GetInstance().BeginRange("Tiled Entity Processing", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("Tiled Entity Processing", wiProfiler::DOMAIN_GPU, threadID); GraphicsDevice* device = GetDevice(); int _width = GetInternalResolution().x; @@ -6484,7 +6427,7 @@ void ComputeTiledLightCulling(bool deferred, GRAPHICSTHREAD threadID) device->EventEnd(threadID); } - wiProfiler::GetInstance().EndRange(threadID); + wiProfiler::EndRange(threadID); } void ResolveMSAADepthBuffer(Texture2D* dst, Texture2D* src, GRAPHICSTHREAD threadID) { @@ -6910,8 +6853,8 @@ void DrawTracedScene(const CameraComponent& camera, Texture2D* result, GRAPHICST static unordered_set sceneTextures; if (sceneTextures.empty()) { - sceneTextures.insert(wiTextureHelper::getInstance()->getWhite()); - sceneTextures.insert(wiTextureHelper::getInstance()->getNormalMapDefault()); + sceneTextures.insert(wiTextureHelper::getWhite()); + sceneTextures.insert(wiTextureHelper::getNormalMapDefault()); } for (size_t i = 0; i < scene.objects.GetCount(); ++i) @@ -7063,7 +7006,7 @@ void DrawTracedScene(const CameraComponent& camera, Texture2D* result, GRAPHICST } else { - rect = storedTextures[wiTextureHelper::getInstance()->getWhite()]; + rect = storedTextures[wiTextureHelper::getWhite()]; } // eliminate border expansion: rect.x += atlasWrapBorder; @@ -7081,7 +7024,7 @@ void DrawTracedScene(const CameraComponent& camera, Texture2D* result, GRAPHICST } else { - rect = storedTextures[wiTextureHelper::getInstance()->getWhite()]; + rect = storedTextures[wiTextureHelper::getWhite()]; } // eliminate border expansion: rect.x += atlasWrapBorder; @@ -7100,7 +7043,7 @@ void DrawTracedScene(const CameraComponent& camera, Texture2D* result, GRAPHICST else { - rect = storedTextures[wiTextureHelper::getInstance()->getNormalMapDefault()]; + rect = storedTextures[wiTextureHelper::getNormalMapDefault()]; } // eliminate border expansion: rect.x += atlasWrapBorder; @@ -7120,7 +7063,7 @@ void DrawTracedScene(const CameraComponent& camera, Texture2D* result, GRAPHICST // Begin raytrace - wiProfiler::GetInstance().BeginRange("RayTrace - ALL", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("RayTrace - ALL", wiProfiler::DOMAIN_GPU, threadID); const XMFLOAT4& halton = wiMath::GetHaltonSequence((int)GetDevice()->GetFrameCount()); TracedRenderingCB cb; @@ -7185,7 +7128,7 @@ void DrawTracedScene(const CameraComponent& camera, Texture2D* result, GRAPHICST } else { - device->BindResource(CS, wiTextureHelper::getInstance()->getWhite(), TEXSLOT_ONDEMAND8, threadID); + device->BindResource(CS, wiTextureHelper::getWhite(), TEXSLOT_ONDEMAND8, threadID); } for (int bounce = 0; bounce < 8; ++bounce) @@ -7225,7 +7168,7 @@ void DrawTracedScene(const CameraComponent& camera, Texture2D* result, GRAPHICST { if (bounce == 1) { - wiProfiler::GetInstance().BeginRange("RayTrace - First Light Sampling", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("RayTrace - First Light Sampling", wiProfiler::DOMAIN_GPU, threadID); } // 2.) Light sampling (any hit) <- only after first bounce has occured @@ -7253,13 +7196,13 @@ void DrawTracedScene(const CameraComponent& camera, Texture2D* result, GRAPHICST if (bounce == 1) { - wiProfiler::GetInstance().EndRange(threadID); // RayTrace - First Light Sampling + wiProfiler::EndRange(threadID); // RayTrace - First Light Sampling } } if (bounce == 0) { - wiProfiler::GetInstance().BeginRange("RayTrace - First Bounce", wiProfiler::DOMAIN_GPU, threadID); + wiProfiler::BeginRange("RayTrace - First Bounce", wiProfiler::DOMAIN_GPU, threadID); } // 3.) Compute Primary Trace (closest hit) @@ -7289,12 +7232,12 @@ void DrawTracedScene(const CameraComponent& camera, Texture2D* result, GRAPHICST if (bounce == 0) { - wiProfiler::GetInstance().EndRange(threadID); // RayTrace - First Bounce + wiProfiler::EndRange(threadID); // RayTrace - First Bounce } } - wiProfiler::GetInstance().EndRange(threadID); // RayTrace - ALL + wiProfiler::EndRange(threadID); // RayTrace - ALL @@ -7306,12 +7249,12 @@ void GenerateClouds(Texture2D* dst, UINT refinementCount, float randomness, GRAP { GetDevice()->EventBegin("Cloud Generator", threadID); - TextureDesc src_desc = wiTextureHelper::getInstance()->getRandom64x64()->GetDesc(); + TextureDesc src_desc = wiTextureHelper::getRandom64x64()->GetDesc(); TextureDesc dst_desc = dst->GetDesc(); assert(dst_desc.BindFlags & BIND_UNORDERED_ACCESS); - GetDevice()->BindResource(CS, wiTextureHelper::getInstance()->getRandom64x64(), TEXSLOT_ONDEMAND0, threadID); + GetDevice()->BindResource(CS, wiTextureHelper::getRandom64x64(), TEXSLOT_ONDEMAND0, threadID); GetDevice()->BindUAV(CS, dst, 0, threadID); CloudGeneratorCB cb; @@ -7920,7 +7863,7 @@ void AddDeferredMIPGen(Texture2D* tex) -void LoadModel(const std::string& fileName, const XMMATRIX& transformMatrix) +Entity LoadModel(const std::string& fileName, const XMMATRIX& transformMatrix, bool attached) { wiArchive archive(fileName, true); if (archive.IsOpen()) @@ -7931,14 +7874,14 @@ void LoadModel(const std::string& fileName, const XMMATRIX& transformMatrix) // Serialize it from file: scene.Serialize(archive); - if (!XMMatrixIsIdentity(transformMatrix)) + // First, create new root parent: + Entity parent = CreateEntity(); + scene.transforms.Create(parent); + scene.layers.Create(parent).layerMask = ~0; + { // Apply the optional transformation matrix to the new scene: - // First, create new root parent: - Entity parent = CreateEntity(); - scene.transforms.Create(parent); - // Then all unparented(root) transforms will be parented to "parent" for (size_t i = 0; i < scene.transforms.GetCount() - 1; ++i) // GetCount() - 1 because the last added was the "parent" { @@ -7952,13 +7895,23 @@ void LoadModel(const std::string& fileName, const XMMATRIX& transformMatrix) // The parent component is transformed, scene is updated, then parent is deleted: scene.transforms.GetComponent(parent)->MatrixTransform(transformMatrix); scene.Update(0); + } + + if (!attached) + { + // In this case, we don't care about the root anymore, so delete it. This will simplify overall hierarchy scene.Component_DetachChildren(parent); scene.Entity_Remove(parent); + parent = INVALID_ENTITY; } // Merge with the original scene: GetScene().Merge(scene); + + return parent; } + + return INVALID_ENTITY; } diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index a7339b856..8691ffea8 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -310,7 +310,11 @@ namespace wiRenderer void AddDeferredMIPGen(wiGraphicsTypes::Texture2D* tex); // Helper function to open a wiscene file and add the contents to the current scene - void LoadModel(const std::string& fileName, const XMMATRIX& transformMatrix = XMMatrixIdentity()); + // transformMatrix : everything will be transformed by this matrix (optional) + // attached : everything will be attached to a base entity + // + // returns INVALID_ENTITY if attached argument was false, else it returns the base entity handle + wiECS::Entity LoadModel(const std::string& fileName, const XMMATRIX& transformMatrix = XMMatrixIdentity(), bool attached = false); }; diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp index 6e29c64f9..9109e41a4 100644 --- a/WickedEngine/wiRenderer_BindLua.cpp +++ b/WickedEngine/wiRenderer_BindLua.cpp @@ -97,7 +97,8 @@ namespace wiRenderer_BindLua wiLua::SError(L, "LoadModel(string fileName, opt Matrix transform) argument is not a matrix!"); } } - wiRenderer::LoadModel(fileName, transform); + Entity root = wiRenderer::LoadModel(fileName, transform, true); + wiLua::SSetInt(L, int(root)); return 1; } else diff --git a/WickedEngine/wiResourceManager.cpp b/WickedEngine/wiResourceManager.cpp index 8fd7370e7..38f2e4c3f 100644 --- a/WickedEngine/wiResourceManager.cpp +++ b/WickedEngine/wiResourceManager.cpp @@ -18,31 +18,15 @@ static const std::unordered_map types make_pair("WAV", wiResourceManager::SOUND) }; -wiResourceManager* wiResourceManager::globalResources = nullptr; -wiResourceManager::wiResourceManager():wiThreadSafeManager() +wiResourceManager& wiResourceManager::GetGlobal() { -} -wiResourceManager::~wiResourceManager() -{ - CleanUp(); -} -wiResourceManager* wiResourceManager::GetGlobal() -{ - if (globalResources == nullptr) - { - LOCK_STATIC(); - if (globalResources == nullptr) - { - globalResources = new wiResourceManager(); - } - UNLOCK_STATIC(); - } + static wiResourceManager globalResources; return globalResources; } -wiResourceManager* wiResourceManager::GetShaderManager() +wiResourceManager& wiResourceManager::GetShaderManager() { - static wiResourceManager* shaderManager = new wiResourceManager; + static wiResourceManager shaderManager; return shaderManager; } @@ -441,11 +425,12 @@ bool wiResourceManager::Register(const wiHashString& name, void* resource, Data_ return false; } -bool wiResourceManager::CleanUp() +bool wiResourceManager::Clear() { wiRenderer::GetDevice()->WaitForGPU(); - std::vectorresNames(0); + std::vector resNames; + resNames.reserve(resources.size()); for (auto& x : resources) { resNames.push_back(x.first); diff --git a/WickedEngine/wiResourceManager.h b/WickedEngine/wiResourceManager.h index 099788d85..1e9396eb6 100644 --- a/WickedEngine/wiResourceManager.h +++ b/WickedEngine/wiResourceManager.h @@ -34,21 +34,17 @@ public: }; std::unordered_map resources; -protected: -static wiResourceManager* globalResources; - public: - wiResourceManager(); - ~wiResourceManager(); - static wiResourceManager* GetGlobal(); - static wiResourceManager* GetShaderManager(); + ~wiResourceManager() { Clear(); } + static wiResourceManager& GetGlobal(); + static wiResourceManager& GetShaderManager(); const Resource* get(const wiHashString& name, bool IncRefCount = false); //specify datatype for shaders void* add(const wiHashString& name, Data_Type newType = Data_Type::DYNAMIC); bool del(const wiHashString& name, bool forceDelete = false); bool Register(const wiHashString& name, void* resource, Data_Type newType); - bool CleanUp(); + bool Clear(); }; diff --git a/WickedEngine/wiResourceManager_BindLua.cpp b/WickedEngine/wiResourceManager_BindLua.cpp index b18496ef1..af32191e2 100644 --- a/WickedEngine/wiResourceManager_BindLua.cpp +++ b/WickedEngine/wiResourceManager_BindLua.cpp @@ -148,7 +148,7 @@ void wiResourceManager_BindLua::Bind() { Texture_BindLua::Bind(); Luna::Register(wiLua::GetGlobal()->GetLuaState()); - wiLua::GetGlobal()->RegisterObject(className, "globalResources", new wiResourceManager_BindLua(wiResourceManager::GetGlobal())); + wiLua::GetGlobal()->RegisterObject(className, "globalResources", new wiResourceManager_BindLua(&wiResourceManager::GetGlobal())); initialized = true; } } diff --git a/WickedEngine/wiSceneSystem.cpp b/WickedEngine/wiSceneSystem.cpp index 3672ebba8..665982a05 100644 --- a/WickedEngine/wiSceneSystem.cpp +++ b/WickedEngine/wiSceneSystem.cpp @@ -4,6 +4,7 @@ #include "wiResourceManager.h" #include "wiPhysicsEngine.h" #include "wiArchive.h" +#include "wiRenderer.h" #include #include @@ -227,7 +228,7 @@ namespace wiSceneSystem { return baseColorMap; } - return wiTextureHelper::getInstance()->getWhite(); + return wiTextureHelper::getWhite(); } Texture2D* MaterialComponent::GetNormalMap() const { @@ -236,7 +237,7 @@ namespace wiSceneSystem //{ // return normalMap; //} - //return wiTextureHelper::getInstance()->getNormalMapDefault(); + //return wiTextureHelper::getNormalMapDefault(); } Texture2D* MaterialComponent::GetSurfaceMap() const { @@ -244,7 +245,7 @@ namespace wiSceneSystem { return surfaceMap; } - return wiTextureHelper::getInstance()->getWhite(); + return wiTextureHelper::getWhite(); } Texture2D* MaterialComponent::GetDisplacementMap() const { @@ -252,7 +253,7 @@ namespace wiSceneSystem { return displacementMap; } - return wiTextureHelper::getInstance()->getWhite(); + return wiTextureHelper::getWhite(); } void MeshComponent::CreateRenderData() @@ -1172,12 +1173,12 @@ namespace wiSceneSystem if (!textureName.empty()) { material.baseColorMapName = textureName; - material.baseColorMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material.baseColorMapName); + material.baseColorMap = (Texture2D*)wiResourceManager::GetGlobal().add(material.baseColorMapName); } if (!normalMapName.empty()) { material.normalMapName = normalMapName; - material.normalMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material.normalMapName); + material.normalMap = (Texture2D*)wiResourceManager::GetGlobal().add(material.normalMapName); } return entity; diff --git a/WickedEngine/wiSceneSystem_Serializers.cpp b/WickedEngine/wiSceneSystem_Serializers.cpp index b51355c37..7388cfd10 100644 --- a/WickedEngine/wiSceneSystem_Serializers.cpp +++ b/WickedEngine/wiSceneSystem_Serializers.cpp @@ -107,19 +107,19 @@ namespace wiSceneSystem std::string texturesDir = archive.GetSourceDirectory(); if (!baseColorMapName.empty()) { - baseColorMap = (wiGraphicsTypes::Texture2D*)wiResourceManager::GetGlobal()->add(texturesDir + baseColorMapName); + baseColorMap = (wiGraphicsTypes::Texture2D*)wiResourceManager::GetGlobal().add(texturesDir + baseColorMapName); } if (!surfaceMapName.empty()) { - surfaceMap = (wiGraphicsTypes::Texture2D*)wiResourceManager::GetGlobal()->add(texturesDir + surfaceMapName); + surfaceMap = (wiGraphicsTypes::Texture2D*)wiResourceManager::GetGlobal().add(texturesDir + surfaceMapName); } if (!normalMapName.empty()) { - normalMap = (wiGraphicsTypes::Texture2D*)wiResourceManager::GetGlobal()->add(texturesDir + normalMapName); + normalMap = (wiGraphicsTypes::Texture2D*)wiResourceManager::GetGlobal().add(texturesDir + normalMapName); } if (!displacementMapName.empty()) { - displacementMap = (wiGraphicsTypes::Texture2D*)wiResourceManager::GetGlobal()->add(texturesDir + displacementMapName); + displacementMap = (wiGraphicsTypes::Texture2D*)wiResourceManager::GetGlobal().add(texturesDir + displacementMapName); } } diff --git a/WickedEngine/wiSprite.cpp b/WickedEngine/wiSprite.cpp index 2cc2222f6..cdc06be35 100644 --- a/WickedEngine/wiSprite.cpp +++ b/WickedEngine/wiSprite.cpp @@ -29,7 +29,7 @@ wiSprite::wiSprite(const std::string& newTexture, wiResourceManager* contentHold void wiSprite::Init(){ if (ContentHolder == nullptr) { - ContentHolder = wiResourceManager::GetGlobal(); + ContentHolder = &wiResourceManager::GetGlobal(); } texture=""; mask=""; diff --git a/WickedEngine/wiTextureHelper.cpp b/WickedEngine/wiTextureHelper.cpp index e138f52b1..5d8541c58 100644 --- a/WickedEngine/wiTextureHelper.cpp +++ b/WickedEngine/wiTextureHelper.cpp @@ -1,208 +1,239 @@ #include "wiTextureHelper.h" +#include "wiRenderer.h" #include "wiRandom.h" +#include "wiColor.h" + +#include using namespace wiGraphicsTypes; -wiTextureHelper::wiTextureHelperInstance::wiTextureHelperInstance() +namespace wiTextureHelper { - for (int i = 0; i < HELPERTEXTURE_COUNT; ++i) - { - helperTextures[i] = nullptr; - } -} -wiTextureHelper::wiTextureHelperInstance::~wiTextureHelperInstance() -{ - for (int i = 0; i < HELPERTEXTURE_COUNT; ++i) - { - SAFE_DELETE(helperTextures[i]); - } - for (auto& x : colorTextures) + enum HELPERTEXTURES { - SAFE_DELETE(x.second); - } -} + HELPERTEXTURE_RANDOM64X64, + HELPERTEXTURE_COLORGRADEDEFAULT, + HELPERTEXTURE_NORMALMAPDEFAULT, + HELPERTEXTURE_BLACKCUBEMAP, + HELPERTEXTURE_COUNT + }; + wiGraphicsTypes::Texture2D* helperTextures[HELPERTEXTURE_COUNT] = {}; + std::unordered_map colorTextures; - -Texture2D* wiTextureHelper::wiTextureHelperInstance::getRandom64x64() -{ - if (helperTextures[HELPERTEXTURE_RANDOM64X64] != nullptr) + Texture2D* getRandom64x64() { + if (helperTextures[HELPERTEXTURE_RANDOM64X64] != nullptr) + { + return helperTextures[HELPERTEXTURE_RANDOM64X64]; + } + + static const int dataLength = 64 * 64 * 4; + unsigned char* data = new unsigned char[dataLength]; + for (int i = 0; i < dataLength; i += 4) + { + data[i] = wiRandom::getRandom(0, 255); + data[i + 1] = wiRandom::getRandom(0, 255); + data[i + 2] = wiRandom::getRandom(0, 255); + data[i + 3] = 255; + } + + if (FAILED(CreateTexture(helperTextures[HELPERTEXTURE_RANDOM64X64], data, 64, 64, 4))) + { + delete[] data; + return nullptr; + } + delete[] data; + + return helperTextures[HELPERTEXTURE_RANDOM64X64]; } - static const int dataLength = 64 * 64 * 4; - unsigned char* data = new unsigned char[dataLength]; - for (int i = 0; i < dataLength; i += 4) + Texture2D* getColorGradeDefault() { - data[i] = wiRandom::getRandom(0, 255); - data[i + 1] = wiRandom::getRandom(0, 255); - data[i + 2] = wiRandom::getRandom(0, 255); - data[i + 3] = 255; - } + if (helperTextures[HELPERTEXTURE_COLORGRADEDEFAULT] != nullptr) + { + return helperTextures[HELPERTEXTURE_COLORGRADEDEFAULT]; + } - if (FAILED(CreateTexture(helperTextures[HELPERTEXTURE_RANDOM64X64], data, 64, 64, 4))) - { + static const int dataLength = 256 * 16 * 4; + unsigned char* data = new unsigned char[dataLength]; + for (int slice = 0; slice < 16; ++slice) + { + for (int x = 0; x < 16; ++x) + { + for (int y = 0; y < 16; ++y) + { + wiColor color; + color.r = x * 16 + x; + color.g = y * 16 + y; + color.b = slice * 16 + slice; + + int gridPos = (slice * 16 + y * 256 + x) * 4; + data[gridPos] = color.r; + data[gridPos + 1] = color.g; + data[gridPos + 2] = color.b; + data[gridPos + 3] = color.a; + } + } + } + + if (FAILED(CreateTexture(helperTextures[HELPERTEXTURE_COLORGRADEDEFAULT], data, 256, 16, 4))) + { + delete[] data; + return nullptr; + } delete[] data; - return nullptr; - } - delete[] data; - return helperTextures[HELPERTEXTURE_RANDOM64X64]; -} - -Texture2D* wiTextureHelper::wiTextureHelperInstance::getColorGradeDefault() -{ - if (helperTextures[HELPERTEXTURE_COLORGRADEDEFAULT] != nullptr) - { return helperTextures[HELPERTEXTURE_COLORGRADEDEFAULT]; } - static const int dataLength = 256 * 16 * 4; - unsigned char* data = new unsigned char[dataLength]; - for (int slice = 0; slice < 16; ++slice) + Texture2D* getNormalMapDefault() { - for (int x = 0; x < 16; ++x) + return getColor(wiColor(127, 127, 255, 255)); + } + + Texture2D* getBlackCubeMap() + { + if (helperTextures[HELPERTEXTURE_BLACKCUBEMAP] != nullptr) { - for (int y = 0; y < 16; ++y) - { - wiColor color; - color.r = x * 16 + x; - color.g = y * 16 + y; - color.b = slice * 16 + slice; - - int gridPos = (slice * 16 + y * 256 + x) * 4; - data[gridPos] = color.r; - data[gridPos + 1] = color.g; - data[gridPos + 2] = color.b; - data[gridPos + 3] = color.a; - } + return helperTextures[HELPERTEXTURE_BLACKCUBEMAP]; } - } - if (FAILED(CreateTexture(helperTextures[HELPERTEXTURE_COLORGRADEDEFAULT], data, 256, 16, 4))) - { - delete[] data; - return nullptr; - } - delete[] data; + int width = 1; + int height = 1; + struct vector4b + { + unsigned char r; + unsigned char g; + unsigned char b; + unsigned char a; - return helperTextures[HELPERTEXTURE_COLORGRADEDEFAULT]; -} + vector4b(unsigned char r = 0, unsigned char g = 0, unsigned char b = 0, unsigned char a = 0) :r(r), g(g), b(b), a(a) {} + }; -Texture2D* wiTextureHelper::wiTextureHelperInstance::getNormalMapDefault() -{ - return getColor(wiColor(127, 127, 255, 255)); -} + TextureDesc texDesc; + texDesc.Width = width; + texDesc.Height = height; + texDesc.MipLevels = 1; + texDesc.ArraySize = 6; + texDesc.Format = FORMAT_R8G8B8A8_UNORM; + texDesc.CPUAccessFlags = 0; + texDesc.SampleDesc.Count = 1; + texDesc.SampleDesc.Quality = 0; + texDesc.Usage = USAGE_DEFAULT; + texDesc.BindFlags = BIND_SHADER_RESOURCE; + texDesc.CPUAccessFlags = 0; + texDesc.MiscFlags = RESOURCE_MISC_TEXTURECUBE; + + SubresourceData pData[6]; + std::vector d[6]; // 6 images of type vector4b = 4 * unsigned char + + for (int cubeMapFaceIndex = 0; cubeMapFaceIndex < 6; cubeMapFaceIndex++) + { + d[cubeMapFaceIndex].resize(width * height); + + // fill with black color + std::fill( + d[cubeMapFaceIndex].begin(), + d[cubeMapFaceIndex].end(), + vector4b(0, 0, 0, 0)); + + pData[cubeMapFaceIndex].pSysMem = &d[cubeMapFaceIndex][0];// description.data; + pData[cubeMapFaceIndex].SysMemPitch = width * 4; + pData[cubeMapFaceIndex].SysMemSlicePitch = 0; + } + + HRESULT hr = wiRenderer::GetDevice()->CreateTexture2D(&texDesc, &pData[0], &helperTextures[HELPERTEXTURE_BLACKCUBEMAP]); + + if (FAILED(hr)) + { + return nullptr; + } -Texture2D* wiTextureHelper::wiTextureHelperInstance::getBlackCubeMap() -{ - if (helperTextures[HELPERTEXTURE_BLACKCUBEMAP] != nullptr) - { return helperTextures[HELPERTEXTURE_BLACKCUBEMAP]; } - int width = 1; - int height = 1; - - struct vector4b + Texture2D* getWhite() { - unsigned char r; - unsigned char g; - unsigned char b; - unsigned char a; - - vector4b(unsigned char r=0, unsigned char g=0, unsigned char b=0, unsigned char a=0) :r(r), g(g), b(b), a(a) {} - }; - - TextureDesc texDesc; - texDesc.Width = width; - texDesc.Height = height; - texDesc.MipLevels = 1; - texDesc.ArraySize = 6; - texDesc.Format = FORMAT_R8G8B8A8_UNORM; - texDesc.CPUAccessFlags = 0; - texDesc.SampleDesc.Count = 1; - texDesc.SampleDesc.Quality = 0; - texDesc.Usage = USAGE_DEFAULT; - texDesc.BindFlags = BIND_SHADER_RESOURCE; - texDesc.CPUAccessFlags = 0; - texDesc.MiscFlags = RESOURCE_MISC_TEXTURECUBE; - - SubresourceData pData[6]; - std::vector d[6]; // 6 images of type vector4b = 4 * unsigned char - - for (int cubeMapFaceIndex = 0; cubeMapFaceIndex < 6; cubeMapFaceIndex++) - { - d[cubeMapFaceIndex].resize(width * height); - - // fill with black color - std::fill( - d[cubeMapFaceIndex].begin(), - d[cubeMapFaceIndex].end(), - vector4b(0, 0, 0, 0)); - - pData[cubeMapFaceIndex].pSysMem = &d[cubeMapFaceIndex][0];// description.data; - pData[cubeMapFaceIndex].SysMemPitch = width * 4; - pData[cubeMapFaceIndex].SysMemSlicePitch = 0; + return getColor(wiColor(255, 255, 255, 255)); } - HRESULT hr = wiRenderer::GetDevice()->CreateTexture2D(&texDesc, &pData[0], &helperTextures[HELPERTEXTURE_BLACKCUBEMAP]); - - if (FAILED(hr)) + Texture2D* getBlack() { - return nullptr; + return getColor(wiColor(0, 0, 0, 255)); } - return helperTextures[HELPERTEXTURE_BLACKCUBEMAP]; -} - -Texture2D* wiTextureHelper::wiTextureHelperInstance::getWhite() -{ - return getColor(wiColor(255, 255, 255, 255)); -} - -Texture2D* wiTextureHelper::wiTextureHelperInstance::getBlack() -{ - return getColor(wiColor(0, 0, 0, 255)); -} - -Texture2D* wiTextureHelper::wiTextureHelperInstance::getTransparent() -{ - return getColor(wiColor(0, 0, 0, 0)); -} - -Texture2D* wiTextureHelper::wiTextureHelperInstance::getColor(const wiColor& color) -{ - if (colorTextures.find(color.rgba) != colorTextures.end()) + Texture2D* getTransparent() { - return colorTextures[color.rgba]; + return getColor(wiColor(0, 0, 0, 0)); } - static const int dim = 1; - static const int dataLength = dim * dim * 4; - unsigned char* data = new unsigned char[dataLength]; - for (int i = 0; i < dataLength; i += 4) + Texture2D* getColor(const wiColor& color) { - data[i] = color.r; - data[i + 1] = color.g; - data[i + 2] = color.b; - data[i + 3] = color.a; - } + if (colorTextures.find(color.rgba) != colorTextures.end()) + { + return colorTextures[color.rgba]; + } - Texture2D* texture = nullptr; - if (FAILED(CreateTexture(texture, data, dim, dim, 4))) - { + static const int dim = 1; + static const int dataLength = dim * dim * 4; + unsigned char* data = new unsigned char[dataLength]; + for (int i = 0; i < dataLength; i += 4) + { + data[i] = color.r; + data[i + 1] = color.g; + data[i + 2] = color.b; + data[i + 3] = color.a; + } + + Texture2D* texture = nullptr; + if (FAILED(CreateTexture(texture, data, dim, dim, 4))) + { + delete[] data; + return nullptr; + } delete[] data; - return nullptr; + + colorTextures[color.rgba] = texture; + + return texture; } - delete[] data; - colorTextures[color.rgba] = texture; - return texture; + HRESULT CreateTexture(wiGraphicsTypes::Texture2D*& texture, const uint8_t* data, UINT width, UINT height, UINT channelCount, FORMAT format) + { + if (data == nullptr) + { + return E_FAIL; + } + + TextureDesc textureDesc; + ZeroMemory(&textureDesc, sizeof(textureDesc)); + textureDesc.Width = width; + textureDesc.Height = height; + textureDesc.MipLevels = 1; + textureDesc.ArraySize = 1; + textureDesc.Format = format; + textureDesc.SampleDesc.Count = 1; + textureDesc.SampleDesc.Quality = 0; + textureDesc.Usage = USAGE_IMMUTABLE; + textureDesc.BindFlags = BIND_SHADER_RESOURCE; + textureDesc.CPUAccessFlags = 0; + textureDesc.MiscFlags = 0; + + SubresourceData InitData; + ZeroMemory(&InitData, sizeof(InitData)); + InitData.pSysMem = data; + InitData.SysMemPitch = static_cast(width * channelCount); + + HRESULT hr; + hr = wiRenderer::GetDevice()->CreateTexture2D(&textureDesc, &InitData, &texture); + + return hr; + } + } - diff --git a/WickedEngine/wiTextureHelper.h b/WickedEngine/wiTextureHelper.h index d76f39b59..29d3ca478 100644 --- a/WickedEngine/wiTextureHelper.h +++ b/WickedEngine/wiTextureHelper.h @@ -1,81 +1,20 @@ #pragma once -#include "wiRenderer.h" -#include "wiColor.h" #include "CommonInclude.h" +#include "wiGraphicsDevice.h" +#include "wiColor.h" - -class wiTextureHelper +namespace wiTextureHelper { -private: - class wiTextureHelperInstance - { - private: - enum HELPERTEXTURES - { - HELPERTEXTURE_RANDOM64X64, - HELPERTEXTURE_COLORGRADEDEFAULT, - HELPERTEXTURE_NORMALMAPDEFAULT, - HELPERTEXTURE_BLACKCUBEMAP, - HELPERTEXTURE_COUNT - }; - wiGraphicsTypes::Texture2D* helperTextures[HELPERTEXTURE_COUNT]; + wiGraphicsTypes::Texture2D* getRandom64x64(); + wiGraphicsTypes::Texture2D* getColorGradeDefault(); + wiGraphicsTypes::Texture2D* getNormalMapDefault(); + wiGraphicsTypes::Texture2D* getBlackCubeMap(); - std::unordered_map colorTextures; - public: - wiTextureHelperInstance(); - ~wiTextureHelperInstance(); + wiGraphicsTypes::Texture2D* getWhite(); + wiGraphicsTypes::Texture2D* getBlack(); + wiGraphicsTypes::Texture2D* getTransparent(); + wiGraphicsTypes::Texture2D* getColor(const wiColor& color); - wiGraphicsTypes::Texture2D* getRandom64x64(); - wiGraphicsTypes::Texture2D* getColorGradeDefault(); - wiGraphicsTypes::Texture2D* getNormalMapDefault(); - wiGraphicsTypes::Texture2D* getBlackCubeMap(); - - wiGraphicsTypes::Texture2D* getWhite(); - wiGraphicsTypes::Texture2D* getBlack(); - wiGraphicsTypes::Texture2D* getTransparent(); - wiGraphicsTypes::Texture2D* getColor(const wiColor& color); - }; - - -public: - static wiTextureHelperInstance* getInstance() - { - static wiTextureHelperInstance* instance = new wiTextureHelperInstance(); - return instance; - } - - template - static HRESULT CreateTexture(wiGraphicsTypes::Texture2D*& texture, T* data, UINT width, UINT height, UINT channelCount, wiGraphicsTypes::FORMAT format = wiGraphicsTypes::FORMAT_R8G8B8A8_UNORM) - { - if (data == nullptr) - { - return E_FAIL; - } - using namespace wiGraphicsTypes; - - TextureDesc textureDesc; - ZeroMemory(&textureDesc, sizeof(textureDesc)); - textureDesc.Width = width; - textureDesc.Height = height; - textureDesc.MipLevels = 1; - textureDesc.ArraySize = 1; - textureDesc.Format = format; - textureDesc.SampleDesc.Count = 1; - textureDesc.SampleDesc.Quality = 0; - textureDesc.Usage = USAGE_IMMUTABLE; - textureDesc.BindFlags = BIND_SHADER_RESOURCE; - textureDesc.CPUAccessFlags = 0; - textureDesc.MiscFlags = 0; - - SubresourceData InitData; - ZeroMemory(&InitData, sizeof(InitData)); - InitData.pSysMem = data; - InitData.SysMemPitch = static_cast(width * channelCount); - - HRESULT hr; - hr = wiRenderer::GetDevice()->CreateTexture2D(&textureDesc, &InitData, &texture); - - return hr; - } + HRESULT CreateTexture(wiGraphicsTypes::Texture2D*& texture, const uint8_t* data, UINT width, UINT height, UINT channelCount, wiGraphicsTypes::FORMAT format = wiGraphicsTypes::FORMAT_R8G8B8A8_UNORM); }; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 5735af99a..08ae07252 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 21; // minor bug fixes, alterations, refactors, updates - const int revision = 34; + const int revision = 35; long GetVersion() diff --git a/WickedEngine/wiWidget.cpp b/WickedEngine/wiWidget.cpp index 0adbb488c..7c1bcc7ea 100644 --- a/WickedEngine/wiWidget.cpp +++ b/WickedEngine/wiWidget.cpp @@ -6,6 +6,7 @@ #include "wiMath.h" #include "wiHelper.h" #include "wiInputManager.h" +#include "wiRenderer.h" #include "ShaderInterop_Renderer.h" #include @@ -120,7 +121,7 @@ void wiWidget::RenderTooltip(wiGUI* gui) static const float _border = 2; float fontWidth = (float)tooltipFont.textWidth() + _border * 2; float fontHeight = (float)tooltipFont.textHeight() + _border * 2; - wiImage::Draw(wiTextureHelper::getInstance()->getColor(wiColor(255, 234, 165)), wiImageEffects(tooltipPos.x - _border, tooltipPos.y - _border, fontWidth, fontHeight), gui->GetGraphicsThread()); + wiImage::Draw(wiTextureHelper::getColor(wiColor(255, 234, 165)), wiImageEffects(tooltipPos.x - _border, tooltipPos.y - _border, fontWidth, fontHeight), gui->GetGraphicsThread()); tooltipFont.SetText(tooltip); tooltipFont.Draw(gui->GetGraphicsThread()); if (!scriptTip.empty()) @@ -333,7 +334,7 @@ void wiButton::Update(wiGUI* gui, float dt) } } - if (wiInputManager::GetInstance()->press(VK_LBUTTON, wiInputManager::KEYBOARD)) + if (wiInputManager::press(VK_LBUTTON, wiInputManager::KEYBOARD)) { if (state == FOCUS) { @@ -342,7 +343,7 @@ void wiButton::Update(wiGUI* gui, float dt) } } - if (wiInputManager::GetInstance()->down(VK_LBUTTON, wiInputManager::KEYBOARD)) + if (wiInputManager::down(VK_LBUTTON, wiInputManager::KEYBOARD)) { if (state == DEACTIVATING) { @@ -387,7 +388,7 @@ void wiButton::Render(wiGUI* gui) gui->ResetScissor(); - wiImage::Draw(wiTextureHelper::getInstance()->getColor(color) + wiImage::Draw(wiTextureHelper::getColor(color) , wiImageEffects(translation.x, translation.y, scale.x, scale.y), gui->GetGraphicsThread()); @@ -458,7 +459,7 @@ void wiLabel::Render(wiGUI* gui) gui->ResetScissor(); - wiImage::Draw(wiTextureHelper::getInstance()->getColor(color) + wiImage::Draw(wiTextureHelper::getColor(color) , wiImageEffects(translation.x, translation.y, scale.x, scale.y), gui->GetGraphicsThread()); @@ -548,7 +549,7 @@ void wiTextInputField::Update(wiGUI* gui, float dt) } } - if (wiInputManager::GetInstance()->press(VK_LBUTTON, wiInputManager::KEYBOARD)) + if (wiInputManager::press(VK_LBUTTON, wiInputManager::KEYBOARD)) { if (state == FOCUS) { @@ -557,7 +558,7 @@ void wiTextInputField::Update(wiGUI* gui, float dt) } } - if (wiInputManager::GetInstance()->down(VK_LBUTTON, wiInputManager::KEYBOARD)) + if (wiInputManager::down(VK_LBUTTON, wiInputManager::KEYBOARD)) { if (state == DEACTIVATING) { @@ -575,7 +576,7 @@ void wiTextInputField::Update(wiGUI* gui, float dt) if (state == ACTIVE) { - if (wiInputManager::GetInstance()->press(VK_RETURN, wiInputManager::KEYBOARD)) + if (wiInputManager::press(VK_RETURN, wiInputManager::KEYBOARD)) { // accept input... @@ -590,8 +591,8 @@ void wiTextInputField::Update(wiGUI* gui, float dt) gui->DeactivateWidget(this); } - else if ((wiInputManager::GetInstance()->press(VK_LBUTTON, wiInputManager::KEYBOARD) && !intersectsPointer) || - wiInputManager::GetInstance()->press(VK_ESCAPE, wiInputManager::KEYBOARD)) + else if ((wiInputManager::press(VK_LBUTTON, wiInputManager::KEYBOARD) && !intersectsPointer) || + wiInputManager::press(VK_ESCAPE, wiInputManager::KEYBOARD)) { // cancel input value_new.clear(); @@ -614,7 +615,7 @@ void wiTextInputField::Render(wiGUI* gui) gui->ResetScissor(); - wiImage::Draw(wiTextureHelper::getInstance()->getColor(color) + wiImage::Draw(wiTextureHelper::getColor(color) , wiImageEffects(translation.x, translation.y, scale.x, scale.y), gui->GetGraphicsThread()); @@ -732,7 +733,7 @@ void wiSlider::Update(wiGUI* gui, float dt) } if (state == ACTIVE) { - if (wiInputManager::GetInstance()->down(VK_LBUTTON, wiInputManager::KEYBOARD)) + if (wiInputManager::down(VK_LBUTTON, wiInputManager::KEYBOARD)) { if (state == ACTIVE) { @@ -765,7 +766,7 @@ void wiSlider::Update(wiGUI* gui, float dt) } } - if (wiInputManager::GetInstance()->press(VK_LBUTTON, wiInputManager::KEYBOARD)) + if (wiInputManager::press(VK_LBUTTON, wiInputManager::KEYBOARD)) { if (state == FOCUS) { @@ -809,11 +810,11 @@ void wiSlider::Render(wiGUI* gui) gui->ResetScissor(); // trail - wiImage::Draw(wiTextureHelper::getInstance()->getColor(color) + wiImage::Draw(wiTextureHelper::getColor(color) , wiImageEffects(translation.x - headWidth * 0.5f, translation.y + scale.y * 0.5f - scale.y*0.1f, scale.x + headWidth, scale.y * 0.2f), gui->GetGraphicsThread()); // head float headPosX = wiMath::Lerp(translation.x, translation.x + scale.x, wiMath::Clamp(wiMath::InverseLerp(start, end, value), 0, 1)); - wiImage::Draw(wiTextureHelper::getInstance()->getColor(color) + wiImage::Draw(wiTextureHelper::getColor(color) , wiImageEffects(headPosX - headWidth * 0.5f, translation.y, headWidth, scale.y), gui->GetGraphicsThread()); if (parent != gui) @@ -899,7 +900,7 @@ void wiCheckBox::Update(wiGUI* gui, float dt) } } - if (wiInputManager::GetInstance()->press(VK_LBUTTON, wiInputManager::KEYBOARD)) + if (wiInputManager::press(VK_LBUTTON, wiInputManager::KEYBOARD)) { if (state == FOCUS) { @@ -908,7 +909,7 @@ void wiCheckBox::Update(wiGUI* gui, float dt) } } - if (wiInputManager::GetInstance()->down(VK_LBUTTON, wiInputManager::KEYBOARD)) + if (wiInputManager::down(VK_LBUTTON, wiInputManager::KEYBOARD)) { if (state == DEACTIVATING) { @@ -942,13 +943,13 @@ void wiCheckBox::Render(wiGUI* gui) gui->ResetScissor(); // control - wiImage::Draw(wiTextureHelper::getInstance()->getColor(color) + wiImage::Draw(wiTextureHelper::getColor(color) , wiImageEffects(translation.x, translation.y, scale.x, scale.y), gui->GetGraphicsThread()); // check if (GetCheck()) { - wiImage::Draw(wiTextureHelper::getInstance()->getColor(wiColor::lerp(color, wiColor::White, 0.8f)) + wiImage::Draw(wiTextureHelper::getColor(wiColor::lerp(color, wiColor::White, 0.8f)) , wiImageEffects(translation.x + scale.x*0.25f, translation.y + scale.y*0.25f, scale.x*0.5f, scale.y*0.5f) , gui->GetGraphicsThread()); } @@ -1041,13 +1042,13 @@ void wiComboBox::Update(wiGUI* gui, float dt) } } - if (wiInputManager::GetInstance()->press(VK_LBUTTON, wiInputManager::KEYBOARD)) + if (wiInputManager::press(VK_LBUTTON, wiInputManager::KEYBOARD)) { // activate clicked = true; } - if (wiInputManager::GetInstance()->down(VK_LBUTTON, wiInputManager::KEYBOARD)) + if (wiInputManager::down(VK_LBUTTON, wiInputManager::KEYBOARD)) { if (state == DEACTIVATING) { @@ -1076,7 +1077,7 @@ void wiComboBox::Update(wiGUI* gui, float dt) } else { - int scroll = (int)wiInputManager::GetInstance()->getpointer().z; + int scroll = (int)wiInputManager::getpointer().z; firstItemVisible -= scroll; firstItemVisible = max(0, min((int)items.size() - maxVisibleItemCount, firstItemVisible)); @@ -1132,10 +1133,10 @@ void wiComboBox::Render(wiGUI* gui) gui->ResetScissor(); // control-base - wiImage::Draw(wiTextureHelper::getInstance()->getColor(color) + wiImage::Draw(wiTextureHelper::getColor(color) , wiImageEffects(translation.x, translation.y, scale.x, scale.y), gui->GetGraphicsThread()); // control-arrow - wiImage::Draw(wiTextureHelper::getInstance()->getColor(color) + wiImage::Draw(wiTextureHelper::getColor(color) , wiImageEffects(translation.x + scale.x + 1, translation.y, scale.y, scale.y), gui->GetGraphicsThread()); wiFont("V", wiFontProps((int)(translation.x + scale.x + scale.y*0.5f), (int)(translation.y + scale.y*0.5f), -1, WIFALIGN_CENTER, WIFALIGN_CENTER, 0, 0, textColor, textShadowColor)).Draw(gui->GetGraphicsThread()); @@ -1181,7 +1182,7 @@ void wiComboBox::Render(wiGUI* gui) col = colors[ACTIVE]; } } - wiImage::Draw(wiTextureHelper::getInstance()->getColor(col) + wiImage::Draw(wiTextureHelper::getColor(col) , wiImageEffects(translation.x, translation.y + _GetItemOffset(i), scale.x, scale.y), gui->GetGraphicsThread()); wiFont(x, wiFontProps((int)(translation.x + scale.x*0.5f), (int)(translation.y + scale.y*0.5f + _GetItemOffset(i)), -1, WIFALIGN_CENTER, WIFALIGN_CENTER, 0, 0, textColor, textShadowColor)).Draw(gui->GetGraphicsThread()); @@ -1273,13 +1274,6 @@ wiWindow::wiWindow(wiGUI* gui, const std::string& name) :wiWidget() // Add controls - SAFE_INIT(closeButton); - SAFE_INIT(moveDragger); - SAFE_INIT(resizeDragger_BottomRight); - SAFE_INIT(resizeDragger_UpperLeft); - - - // Add a grabber onto the title bar moveDragger = new wiButton(name + "_move_dragger"); moveDragger->SetText(""); @@ -1461,7 +1455,7 @@ void wiWindow::Render(wiGUI* gui) // body if (!IsMinimized()) { - wiImage::Draw(wiTextureHelper::getInstance()->getColor(color) + wiImage::Draw(wiTextureHelper::getColor(color) , wiImageEffects(translation.x, translation.y, scale.x, scale.y), gui->GetGraphicsThread()); } @@ -1613,7 +1607,7 @@ void wiColorPicker::Update(wiGUI* gui, float dt) bool dragged = false; - if (wiInputManager::GetInstance()->press(VK_LBUTTON, wiInputManager::KEYBOARD)) + if (wiInputManager::press(VK_LBUTTON, wiInputManager::KEYBOARD)) { if (state == FOCUS) { @@ -1622,7 +1616,7 @@ void wiColorPicker::Update(wiGUI* gui, float dt) } } - if (wiInputManager::GetInstance()->down(VK_LBUTTON, wiInputManager::KEYBOARD)) + if (wiInputManager::down(VK_LBUTTON, wiInputManager::KEYBOARD)) { if (state == ACTIVE) { diff --git a/WickedEngine/wiWidget.h b/WickedEngine/wiWidget.h index 6fbc6b605..e548d733b 100644 --- a/WickedEngine/wiWidget.h +++ b/WickedEngine/wiWidget.h @@ -258,12 +258,12 @@ public: class wiWindow :public wiWidget { protected: - wiGUI* gui; - wiButton* closeButton; - wiButton* minimizeButton; - wiButton* resizeDragger_UpperLeft; - wiButton* resizeDragger_BottomRight; - wiButton* moveDragger; + wiGUI* gui = nullptr; + wiButton* closeButton = nullptr; + wiButton* minimizeButton = nullptr; + wiButton* resizeDragger_UpperLeft = nullptr; + wiButton* resizeDragger_BottomRight = nullptr; + wiButton* moveDragger = nullptr; std::list childrenWidgets; bool minimized; public: diff --git a/WickedEngine/wiWindowRegistration.cpp b/WickedEngine/wiWindowRegistration.cpp new file mode 100644 index 000000000..6304a2697 --- /dev/null +++ b/WickedEngine/wiWindowRegistration.cpp @@ -0,0 +1,21 @@ +#include "wiWindowRegistration.h" + +namespace wiWindowRegistration +{ + window_type window = nullptr; + + window_type GetRegisteredWindow() { + return window; + } + void RegisterWindow(window_type wnd) { + window = wnd; + } + bool IsWindowActive() { +#ifndef WINSTORE_SUPPORT + HWND fgw = GetForegroundWindow(); + return fgw == window; +#else + return true; +#endif + } +} diff --git a/WickedEngine/wiWindowRegistration.h b/WickedEngine/wiWindowRegistration.h index b0a547928..f3ee75e96 100644 --- a/WickedEngine/wiWindowRegistration.h +++ b/WickedEngine/wiWindowRegistration.h @@ -1,42 +1,15 @@ -#ifndef _WINDOWREGISTRATION_H_ -#define _WINDOWREGISTRATION_H_ +#pragma once #include "CommonInclude.h" - -class wiWindowRegistration +namespace wiWindowRegistration { -public: #ifndef WINSTORE_SUPPORT typedef HWND window_type; #else typedef Windows::UI::Core::CoreWindow^ window_type; #endif -private: - window_type window; - -public: - wiWindowRegistration() :window(nullptr) {} - - window_type GetRegisteredWindow() { - return window; - } - void RegisterWindow(window_type wnd) { - window = wnd; - } - bool IsWindowActive() { -#ifndef WINSTORE_SUPPORT - HWND fgw = GetForegroundWindow(); - return fgw == window; -#else - return true; -#endif - } - - static wiWindowRegistration* GetInstance() { - static wiWindowRegistration* reg = new wiWindowRegistration; - return reg; - } + window_type GetRegisteredWindow(); + void RegisterWindow(window_type wnd); + bool IsWindowActive(); }; - -#endif // _WINDOWREGISTRATION_H_