Skip to content

Commit

Permalink
GPU Video Decoding (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij authored Apr 29, 2023
1 parent bde4e61 commit e02ca53
Show file tree
Hide file tree
Showing 99 changed files with 14,470 additions and 1,041 deletions.
1 change: 1 addition & 0 deletions Editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ set (SOURCE_FILES
PaintToolWindow.cpp
GraphicsWindow.cpp
SoundWindow.cpp
VideoWindow.cpp
SpringWindow.cpp
ScriptWindow.cpp
stdafx.cpp
Expand Down
24 changes: 24 additions & 0 deletions Editor/ComponentsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void ComponentsWindow::Create(EditorComponent* _editor)
meshWnd.Create(editor);
envProbeWnd.Create(editor);
soundWnd.Create(editor);
videoWnd.Create(editor);
decalWnd.Create(editor);
lightWnd.Create(editor);
animWnd.Create(editor);
Expand Down Expand Up @@ -71,6 +72,7 @@ void ComponentsWindow::Create(EditorComponent* _editor)
newComponentCombo.AddItem("Collider " ICON_COLLIDER, 18);
newComponentCombo.AddItem("Camera " ICON_CAMERA, 20);
newComponentCombo.AddItem("Object " ICON_OBJECT, 21);
newComponentCombo.AddItem("Video " ICON_VIDEO, 22);
newComponentCombo.OnSelect([=](wi::gui::EventArgs args) {
newComponentCombo.SetSelectedWithoutCallback(-1);
if (editor->translator.selected.empty())
Expand Down Expand Up @@ -183,6 +185,10 @@ void ComponentsWindow::Create(EditorComponent* _editor)
if (scene.objects.Contains(entity))
return;
break;
case 22:
if (scene.videos.Contains(entity))
return;
break;
default:
return;
}
Expand Down Expand Up @@ -279,6 +285,9 @@ void ComponentsWindow::Create(EditorComponent* _editor)
case 21:
scene.objects.Create(entity);
break;
case 22:
scene.videos.Create(entity);
break;
default:
break;
}
Expand All @@ -297,6 +306,7 @@ void ComponentsWindow::Create(EditorComponent* _editor)
AddWidget(&meshWnd);
AddWidget(&envProbeWnd);
AddWidget(&soundWnd);
AddWidget(&videoWnd);
AddWidget(&decalWnd);
AddWidget(&lightWnd);
AddWidget(&animWnd);
Expand Down Expand Up @@ -325,6 +335,7 @@ void ComponentsWindow::Create(EditorComponent* _editor)
meshWnd.SetVisible(false);
envProbeWnd.SetVisible(false);
soundWnd.SetVisible(false);
videoWnd.SetVisible(false);
decalWnd.SetVisible(false);
lightWnd.SetVisible(false);
animWnd.SetVisible(false);
Expand Down Expand Up @@ -543,6 +554,19 @@ void ComponentsWindow::ResizeLayout()
soundWnd.SetVisible(false);
}

if (scene.videos.Contains(videoWnd.entity))
{
videoWnd.SetVisible(true);
videoWnd.SetPos(pos);
videoWnd.SetSize(XMFLOAT2(width, videoWnd.GetScale().y));
pos.y += videoWnd.GetSize().y;
pos.y += padding;
}
else
{
videoWnd.SetVisible(false);
}

if (scene.decals.Contains(decalWnd.entity))
{
decalWnd.SetVisible(true);
Expand Down
2 changes: 2 additions & 0 deletions Editor/ComponentsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "HairParticleWindow.h"
#include "ForceFieldWindow.h"
#include "SoundWindow.h"
#include "VideoWindow.h"
#include "SpringWindow.h"
#include "IKWindow.h"
#include "TransformWindow.h"
Expand Down Expand Up @@ -51,6 +52,7 @@ class ComponentsWindow : public wi::gui::Window
HairParticleWindow hairWnd;
ForceFieldWindow forceFieldWnd;
SoundWindow soundWnd;
VideoWindow videoWnd;
SpringWindow springWnd;
IKWindow ikWnd;
TransformWindow transformWnd;
Expand Down
52 changes: 52 additions & 0 deletions Editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,25 @@ void EditorComponent::Update(float dt)
}
}
}
if (has_flag(optionsWnd.filter, OptionsWindow::Filter::Video))
{
for (size_t i = 0; i < scene.videos.GetCount(); ++i)
{
Entity entity = scene.videos.GetEntity(i);
if (!scene.transforms.Contains(entity))
continue;
const TransformComponent& transform = *scene.transforms.GetComponent(entity);

XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), transform.GetPositionV());
float dis = XMVectorGetX(disV);
if (dis > 0.01f && dis < wi::math::Distance(transform.GetPosition(), pickRay.origin) * 0.05f && dis < hovered.distance)
{
hovered = wi::scene::PickResult();
hovered.entity = entity;
hovered.distance = dis;
}
}
}
if (bone_picking)
{
for (size_t i = 0; i < scene.armatures.GetCount(); ++i)
Expand Down Expand Up @@ -1471,6 +1490,7 @@ void EditorComponent::Update(float dt)
componentsWnd.meshWnd.SetEntity(INVALID_ENTITY, -1);
componentsWnd.materialWnd.SetEntity(INVALID_ENTITY);
componentsWnd.soundWnd.SetEntity(INVALID_ENTITY);
componentsWnd.videoWnd.SetEntity(INVALID_ENTITY);
componentsWnd.decalWnd.SetEntity(INVALID_ENTITY);
componentsWnd.envProbeWnd.SetEntity(INVALID_ENTITY);
componentsWnd.forceFieldWnd.SetEntity(INVALID_ENTITY);
Expand Down Expand Up @@ -1513,6 +1533,7 @@ void EditorComponent::Update(float dt)
componentsWnd.hairWnd.SetEntity(picked.entity);
componentsWnd.lightWnd.SetEntity(picked.entity);
componentsWnd.soundWnd.SetEntity(picked.entity);
componentsWnd.videoWnd.SetEntity(picked.entity);
componentsWnd.decalWnd.SetEntity(picked.entity);
componentsWnd.envProbeWnd.SetEntity(picked.entity);
componentsWnd.forceFieldWnd.SetEntity(picked.entity);
Expand Down Expand Up @@ -2244,6 +2265,36 @@ void EditorComponent::Render() const
wi::font::Draw(ICON_SOUND, fp, cmd);
}
}
if (has_flag(optionsWnd.filter, OptionsWindow::Filter::Video))
{
for (size_t i = 0; i < scene.videos.GetCount(); ++i)
{
Entity entity = scene.videos.GetEntity(i);
if (!scene.transforms.Contains(entity))
continue;
const TransformComponent& transform = *scene.transforms.GetComponent(entity);

fp.position = transform.GetPosition();
fp.scaling = scaling * wi::math::Distance(transform.GetPosition(), camera.Eye);
fp.color = inactiveEntityColor;

if (hovered.entity == entity)
{
fp.color = hoveredEntityColor;
}
for (auto& picked : translator.selected)
{
if (picked.entity == entity)
{
fp.color = selectedEntityColor;
break;
}
}


wi::font::Draw(ICON_VIDEO, fp, cmd);
}
}
if (bone_picking)
{
static PipelineState pso;
Expand Down Expand Up @@ -3317,6 +3368,7 @@ void EditorComponent::RefreshSceneList()
componentsWnd.meshWnd.SetEntity(wi::ecs::INVALID_ENTITY, -1);
componentsWnd.lightWnd.SetEntity(wi::ecs::INVALID_ENTITY);
componentsWnd.soundWnd.SetEntity(wi::ecs::INVALID_ENTITY);
componentsWnd.videoWnd.SetEntity(wi::ecs::INVALID_ENTITY);
componentsWnd.decalWnd.SetEntity(wi::ecs::INVALID_ENTITY);
componentsWnd.envProbeWnd.SetEntity(wi::ecs::INVALID_ENTITY);
componentsWnd.materialWnd.SetEntity(wi::ecs::INVALID_ENTITY);
Expand Down
2 changes: 2 additions & 0 deletions Editor/Editor_SOURCE.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<ClCompile Include="$(MSBuildThisFileDirectory)TerrainWindow.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)TransformWindow.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)Translator.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)VideoWindow.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)WeatherWindow.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)xatlas.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
Expand Down Expand Up @@ -181,6 +182,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)tiny_obj_loader.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)TransformWindow.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)Translator.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)VideoWindow.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)WeatherWindow.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)xatlas.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)yumin.h" />
Expand Down
2 changes: 2 additions & 0 deletions Editor/Editor_SOURCE.vcxitems.filters
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<ClCompile Include="$(MSBuildThisFileDirectory)GeneralWindow.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)ProfilerWindow.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)EmbeddedResources.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)VideoWindow.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)AnimationWindow.h" />
Expand Down Expand Up @@ -140,6 +141,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)GeneralWindow.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ProfilerWindow.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)yumin.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)VideoWindow.h" />
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)startup.lua" />
Expand Down
1 change: 1 addition & 0 deletions Editor/IconDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define ICON_HAIR ICON_FA_SEEDLING
#define ICON_FORCE ICON_FA_WIND
#define ICON_SOUND ICON_FA_VOLUME_HIGH
#define ICON_VIDEO ICON_FA_FILM
#define ICON_DECAL ICON_FA_NOTE_STICKY
#define ICON_CAMERA ICON_FA_VIDEO
#define ICON_ENVIRONMENTPROBE ICON_FA_EARTH_ASIA
Expand Down
41 changes: 41 additions & 0 deletions Editor/OptionsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void OptionsWindow::Create(EditorComponent* _editor)
newCombo.AddItem("Force " ICON_FORCE, 6);
newCombo.AddItem("Decal " ICON_DECAL, 7);
newCombo.AddItem("Sound " ICON_SOUND, 8);
newCombo.AddItem("Video " ICON_VIDEO, 19);
newCombo.AddItem("Weather " ICON_WEATHER, 9);
newCombo.AddItem("Emitter " ICON_EMITTER, 10);
newCombo.AddItem("HairParticle " ICON_HAIR, 11);
Expand Down Expand Up @@ -111,6 +112,33 @@ void OptionsWindow::Create(EditorComponent* _editor)
return;
}
break;
case 19:
{
wi::helper::FileDialogParams params;
params.type = wi::helper::FileDialogParams::OPEN;
params.description = "Video";
params.extensions = wi::resourcemanager::GetSupportedVideoExtensions();
wi::helper::FileDialog(params, [=](std::string fileName) {
wi::eventhandler::Subscribe_Once(wi::eventhandler::EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) {
Entity entity = editor->GetCurrentScene().Entity_CreateVideo(wi::helper::GetFileNameFromPath(fileName), fileName);

wi::Archive& archive = editor->AdvanceHistory();
archive << EditorComponent::HISTORYOP_ADD;
editor->RecordSelection(archive);

editor->ClearSelected();
editor->AddSelected(entity);

editor->RecordSelection(archive);
editor->RecordEntity(archive, entity);

RefreshEntityTree();
editor->componentsWnd.videoWnd.SetEntity(entity);
});
});
return;
}
break;
case 9:
pick.entity = CreateEntity();
scene.weathers.Create(pick.entity);
Expand Down Expand Up @@ -191,6 +219,7 @@ void OptionsWindow::Create(EditorComponent* _editor)
filterCombo.AddItem(ICON_ENVIRONMENTPROBE, (uint64_t)Filter::EnvironmentProbe);
filterCombo.AddItem(ICON_DECAL, (uint64_t)Filter::Decal);
filterCombo.AddItem(ICON_SOUND, (uint64_t)Filter::Sound);
filterCombo.AddItem(ICON_VIDEO, (uint64_t)Filter::Video);
filterCombo.AddItem(ICON_WEATHER, (uint64_t)Filter::Weather);
filterCombo.AddItem(ICON_POINTLIGHT, (uint64_t)Filter::Light);
filterCombo.AddItem(ICON_ANIMATION, (uint64_t)Filter::Animation);
Expand Down Expand Up @@ -463,6 +492,10 @@ void OptionsWindow::PushToEntityTree(wi::ecs::Entity entity, int level)
{
item.name += ICON_SOUND " ";
}
if (scene.videos.Contains(entity))
{
item.name += ICON_VIDEO " ";
}
if (scene.decals.Contains(entity))
{
item.name += ICON_DECAL " ";
Expand Down Expand Up @@ -683,6 +716,14 @@ void OptionsWindow::RefreshEntityTree()
}
}

if (has_flag(filter, Filter::Video))
{
for (size_t i = 0; i < scene.videos.GetCount(); ++i)
{
PushToEntityTree(scene.videos.GetEntity(i), 0);
}
}

if (has_flag(filter, Filter::Hairparticle))
{
for (size_t i = 0; i < scene.hairs.GetCount(); ++i)
Expand Down
1 change: 1 addition & 0 deletions Editor/OptionsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class OptionsWindow : public wi::gui::Window
Terrain = 1 << 19,
Spring = 1 << 20,
Humanoid = 1 << 21,
Video = 1 << 22,

All = ~0ull,
} filter = Filter::All;
Expand Down
1 change: 0 additions & 1 deletion Editor/SoundWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "stdafx.h"
#include "SoundWindow.h"
#include "wiAudio.h"

using namespace wi::graphics;
using namespace wi::ecs;
Expand Down
Loading

0 comments on commit e02ca53

Please sign in to comment.