5#include "Headers/Utils.h"
35#include <IconsForkAwesome.h>
36#include <imgui_memory_editor/imgui_memory_editor.h>
37#include <imgui_internal.h>
54 bool _windowOwned =
false;
67 if ( state._hoveredNodePreview != state._focusedNodePreview )
69 state._focusedNodePreview = state._hoveredNodePreview;
72 if ( state._hoveredScenePreview != state._focusedScenePreview )
74 state._focusedScenePreview = state._hoveredScenePreview;
83 return state._hoveredNodePreview || state._hoveredScenePreview;
88 return state._focusedNodePreview || state._focusedScenePreview;
102 return mi_new( size );
119 return ImTextureID(intptr_t(texData));
124 const intptr_t texData = intptr_t(texID);
130 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
131 io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors;
132 io.SetClipboardTextFn = [](
void* user_data,
const char* text)
134 if ( user_data !=
nullptr )
140 io.GetClipboardTextFn = [](
void* user_data )
142 if ( user_data !=
nullptr)
150 static bool enable_clipboard =
true;
151 io.ClipboardUserData = &enable_clipboard;
173 pushConstants.data[0]._vec[1].w =
to_F32( data.
_mip );
174 pushConstants.data[0]._vec[2].x = isArrayTexture ? 1.f : 0.f;
176 pushConstants.data[0]._vec[2].z = data.
_flip ? 1.f : 0.f;
177 pushConstants.data[0]._vec[2].w = data.
_srgb ? 1.f : 0.f;
178 return pushConstants;
183 ,
FrameListener(
"Editor", context.kernel().frameListenerMgr(), 9999 )
184 , _editorUpdateTimer( Time::ADD_TIMER(
"Editor Update Timer" ) )
185 , _editorRenderTimer( Time::ADD_TIMER(
"Editor Render Timer" ) )
186 , _currentTheme( theme )
201 _nodePreviewBGColour = { 0.35f, 0.32f, 0.45f };
207 g_windowManager =
nullptr;
217 constexpr F32 fontSize = 13.f;
218 constexpr F32 fontSizeBold = 16.f;
219 constexpr F32 iconSize = 16.f;
233 U8* pPixels =
nullptr;
236 const string textFontPath = ( Paths::g_fontsPath / g_editorFontFile ).
string();
237 const string textFontBoldPath = ( Paths::g_fontsPath / g_editorFontFileBold ).
string();
238 const string iconFontPath = ( Paths::g_fontsPath / g_editorIconFile ).
string();
240 ImFontConfig font_cfg;
241 font_cfg.OversampleH = font_cfg.OversampleV = 1;
242 font_cfg.PixelSnapH =
true;
243 font_cfg.SizePixels = fontSize * DPIScaleFactor;
244 font_cfg.EllipsisChar = (ImWchar)0x0085;
245 font_cfg.GlyphOffset.y = 1.0f * IM_TRUNC( font_cfg.SizePixels / fontSize );
249 g_editorFontFile.c_str(),
250 (
int)font_cfg.SizePixels );
253 io.Fonts->AddFontFromFileTTF( textFontPath.c_str(), fontSize * DPIScaleFactor, &font_cfg );
255 font_cfg.MergeMode =
true;
256 font_cfg.SizePixels = iconSize * DPIScaleFactor;
257 font_cfg.GlyphOffset.y = 1.0f * IM_TRUNC( font_cfg.SizePixels / iconSize );
259 static const ImWchar icons_ranges[] = { ICON_MIN_FK, ICON_MAX_FK, 0 };
260 io.Fonts->AddFontFromFileTTF( iconFontPath.c_str(), iconSize * DPIScaleFactor, &font_cfg, icons_ranges );
262 font_cfg.MergeMode =
false;
263 font_cfg.SizePixels = fontSizeBold * DPIScaleFactor;
264 font_cfg.GlyphOffset.y = 0.f;
266 io.Fonts->AddFontFromFileTTF( textFontBoldPath.c_str(), fontSizeBold * DPIScaleFactor, &font_cfg );
268 io.Fonts->GetTexDataAsRGBA32( &pPixels, &iWidth, &iHeight );
281 if (
createDirectory( Paths::g_saveLocation / Paths::Editor::g_saveLocation ) != FileError::NONE )
290 _editorCamera->setFixedYawAxis(
true );
291 _editorCamera->setEye( 60.f, 45.f, 60.f );
292 _editorCamera->setEuler( -15.f, 40.f, 0.f );
293 _editorCamera->speedFactor().turn = 45.f;
297 _nodePreviewCamera->setFixedYawAxis(
true );
298 _nodePreviewCamera->speedFactor().turn = 125.f;
299 _nodePreviewCamera->speedFactor().zoom = 175.f;
301 IMGUI_CHECKVERSION();
325 shaderDescriptor.
_modules.push_back( vertModule );
326 shaderDescriptor.
_modules.push_back( fragModule );
327 shaderDescriptor.
_globalDefines.emplace_back(
"toggleChannel ivec4(PushData0[0])");
328 shaderDescriptor.
_globalDefines.emplace_back(
"depthRange PushData0[1].xy");
329 shaderDescriptor.
_globalDefines.emplace_back(
"layer uint(PushData0[1].z)");
330 shaderDescriptor.
_globalDefines.emplace_back(
"mip uint(PushData0[1].w)");
331 shaderDescriptor.
_globalDefines.emplace_back(
"textureType uint(PushData0[2].x)");
332 shaderDescriptor.
_globalDefines.emplace_back(
"depthTexture uint(PushData0[2].y)");
333 shaderDescriptor.
_globalDefines.emplace_back(
"flip uint(PushData0[2].z)");
334 shaderDescriptor.
_globalDefines.emplace_back(
"convertToSRGB (uint(PushData0[2].w) == 1)");
350 fragModule.
_defines.emplace_back(
"axisWidth PushData0[0].x" );
351 fragModule.
_defines.emplace_back(
"gridScale PushData0[0].y" );
356 shaderDescriptor.
_modules.push_back( vertModule );
357 shaderDescriptor.
_modules.push_back( fragModule );
362 blend.enabled(
true );
411 blend.enabled(
true );
419 io.ConfigViewportsNoDecoration =
true;
420 io.ConfigViewportsNoTaskBarIcon =
true;
421 io.ConfigDockingTransparentPayload =
true;
422 io.ConfigViewportsNoAutoMerge =
false;
424 io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
425 io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
427 io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport;
428 io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset;
429 io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports;
430 io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos;
431 io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports;
435 io.ConfigWindowsMoveFromTitleBarOnly =
true;
443 io.DisplayFramebufferScale.
x = io.DisplaySize.x > 0 ? (
F32)display_size.
width / io.DisplaySize.x : 0.f;
444 io.DisplayFramebufferScale.y = io.DisplaySize.y > 0 ? (
F32)display_size.
height / io.DisplaySize.y : 0.f;
446 ImGuiViewport* main_viewport = ImGui::GetMainViewport();
450 platform_io.Platform_CreateWindow = []( ImGuiViewport* viewport )
452 if ( g_windowManager !=
nullptr )
456 winDescriptor.
title =
"No Title Yet";
457 winDescriptor.
parentWindow = g_windowManager->mainWindow();
461 winDescriptor.
flags |= viewport->Flags & ImGuiViewportFlags_NoDecoration
464 winDescriptor.
flags |= viewport->Flags & ImGuiViewportFlags_NoDecoration
467 winDescriptor.
flags |= viewport->Flags & ImGuiViewportFlags_TopMost
470 winDescriptor.
flags |= viewport->Flags & ImGuiViewportFlags_NoTaskBarIcon
474 winDescriptor.
dimensions.
set( viewport->Size.x, viewport->Size.y );
475 winDescriptor.
position.
set( viewport->Pos.x, viewport->Pos.y );
485 newWindow->
hidden(
false );
493 viewport->PlatformRequestClose =
true;
502 viewport->PlatformRequestMove =
true;
511 viewport->PlatformRequestResize =
true;
515 viewport->PlatformHandle = (
void*)newWindow;
516 viewport->PlatformUserData = IM_NEW( ImGuiViewportData )
529 platform_io.Platform_DestroyWindow = []( ImGuiViewport* viewport )
531 if ( g_windowManager !=
nullptr )
533 if ( ImGuiViewportData* data = (ImGuiViewportData*)viewport->PlatformUserData )
535 if ( data->_window && data->_windowOwned )
539 data->_window =
nullptr;
542 viewport->PlatformUserData = viewport->PlatformHandle =
nullptr;
546 platform_io.Platform_ShowWindow = []( ImGuiViewport* viewport )
548 if ( ImGuiViewportData* data = (ImGuiViewportData*)viewport->PlatformUserData )
550 data->_window->hidden(
false );
554 platform_io.Platform_SetWindowPos = []( ImGuiViewport* viewport,
557 if ( ImGuiViewportData* data = (ImGuiViewportData*)viewport->PlatformUserData )
559 data->_window->setPosition( (
I32)pos.x, (
I32)pos.y );
563 platform_io.Platform_GetWindowPos = []( ImGuiViewport* viewport ) -> ImVec2
565 if (
const ImGuiViewportData* data = (ImGuiViewportData*)viewport->PlatformUserData )
567 const vec2<I32> pos = data->_window->getPosition();
568 return ImVec2( (
F32)pos.
x, (
F32)pos.
y );
574 platform_io.Platform_GetWindowSize = []( ImGuiViewport* viewport ) -> ImVec2
576 if (
const ImGuiViewportData* data = (ImGuiViewportData*)viewport->PlatformUserData )
578 const vec2<U16> dim = data->_window->getDimensions();
585 platform_io.Platform_GetWindowFocus = []( ImGuiViewport* viewport ) ->
bool
587 if (
const ImGuiViewportData* data = (ImGuiViewportData*)viewport->PlatformUserData )
589 return data->_window->hasFocus();
595 platform_io.Platform_SetWindowAlpha = []( ImGuiViewport* viewport,
598 if ( ImGuiViewportData* data = (ImGuiViewportData*)viewport->PlatformUserData )
600 data->_window->opacity(
to_U8( alpha * 255 ) );
604 platform_io.Platform_SetWindowSize = []( ImGuiViewport* viewport,
607 if ( ImGuiViewportData* data = (ImGuiViewportData*)viewport->PlatformUserData )
613 platform_io.Platform_SetWindowFocus = []( ImGuiViewport* viewport )
615 if (
const ImGuiViewportData* data = (ImGuiViewportData*)viewport->PlatformUserData )
617 data->_window->bringToFront();
621 platform_io.Platform_SetWindowTitle = []( ImGuiViewport* viewport,
624 if (
const ImGuiViewportData* data = (ImGuiViewportData*)viewport->PlatformUserData )
626 data->_window->title( title );
630 platform_io.Platform_RenderWindow = []( ImGuiViewport* viewport,
631 void* platformContext )
643 platform_io.Renderer_RenderWindow = []( ImGuiViewport* viewport,
644 void* platformContext )
656 ImDrawData* pDrawData = viewport->DrawData;
657 const I32 fb_width =
to_I32( pDrawData->DisplaySize.x * ImGui::GetIO().DisplayFramebufferScale.x );
658 const I32 fb_height =
to_I32( pDrawData->DisplaySize.y * ImGui::GetIO().DisplayFramebufferScale.y );
659 const Rect<I32> targetViewport{0, 0, fb_width, fb_height};
678 platform_io.Platform_SwapBuffers = []( ImGuiViewport* viewport,
679 void* platformContext )
681 if ( g_windowManager !=
nullptr )
692 platform_io.Platform_OnChangedViewport = []( ImGuiViewport* viewport )
694 static F32 previousDPIScale = 1.f;
695 if ( ImGuiViewportData* data = (ImGuiViewportData*)viewport->PlatformUserData )
697 if ( viewport->DpiScale != previousDPIScale )
699 previousDPIScale = viewport->DpiScale;
700 ImGui::GetStyle().ScaleAllSizes( previousDPIScale );
701 data->_window->context().editor()._queuedDPIValue = previousDPIScale;
706 const I32 monitorCount =
to_I32( monitors.size() );
708 platform_io.Monitors.resize( monitorCount );
710 for (
I32 i = 0; i < monitorCount; ++i )
713 ImGuiPlatformMonitor& imguiMonitor = platform_io.Monitors[i];
725 ImGuiViewportData* data = IM_NEW( ImGuiViewportData )();
727 data->_windowOwned =
false;
728 main_viewport->PlatformUserData = data;
731 gizmoContext = ImGui::CreateContext( io.Fonts );
733 gizmoContext->Viewports[0]->PlatformHandle =
_mainWindow;
734 _gizmo = std::make_unique<Gizmo>( *
this, gizmoContext );
736 SDL_SetHint( SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH,
"1" );
739 descriptor.
position = ImVec2( 0, 0 );
740 descriptor.
size = ImVec2( 300, 550 );
741 descriptor.
minSize = ImVec2( 200, 200 );
742 descriptor.
name = ICON_FK_HUBZILLA
" Solution Explorer";
746 descriptor.
position = ImVec2( 0, 0 );
747 descriptor.
minSize = ImVec2( 200, 200 );
748 descriptor.
name = ICON_FK_PICTURE_O
" PostFX Settings";
753 descriptor.
name = ICON_FK_PENCIL_SQUARE_O
" Property Explorer";
756 descriptor.
position = ImVec2( 0, 550.0f );
759 descriptor.
name = ICON_FK_FOLDER_OPEN
" Content Explorer";
760 descriptor.
flags |= ImGuiWindowFlags_NoTitleBar;
766 descriptor.
name = ICON_FK_PRINT
" Application Output";
769 descriptor.
position = ImVec2( 150, 150 );
770 descriptor.
size = ImVec2( 640, 480 );
771 descriptor.
name = ICON_FK_EYE
" Node Preview";
772 descriptor.
minSize = ImVec2( 100, 100 );
773 descriptor.
flags = 0;
776 descriptor.
name =
"Scene View ###AnimatedTitlePlayState";
797 editorDesc.
_name =
"Node_Preview";
845 ImGui::SetCurrentContext(
context );
846 ImGui::DestroyPlatformWindows();
847 ImGui::DestroyContext(
context );
867 const bool editorHasFocus =
hasFocus();
869 ImGuiIO& io = ImGui::GetIO();
870 if ( editorHasFocus )
872 io.ConfigFlags &= ~ImGuiConfigFlags_NavNoCaptureKeyboard;
876 io.ConfigFlags |= ImGuiConfigFlags_NavNoCaptureKeyboard;
879 _context.
kernel().projectManager()->onChangeFocus( !editorHasFocus );
885 if ( running() == state )
891 Scene* activeScene = sMgr->activeProject()->getActiveScene();
894 Reset( _windowFocusState );
897 SceneStatePerPlayer& playerState = activeScene->state()->playerState( sMgr->playerPass() );
901 playerState.overrideCamera(
nullptr );
902 sceneGizmoEnabled(
false );
905 if ( !
_context.
kernel().projectManager()->resetSelection( 0,
true ) )
913 playerState.overrideCamera( editorCamera() );
914 sceneGizmoEnabled(
true );
929 const auto addValAnd10Percent = [](
const F32 val )
931 return val + ((val * 10) / 100.f);
933 const auto addValMinus20Percent = [](
const F32 val )
935 return val - ((val * 20) / 100.f);
938 std::array<IM::ConeDescriptor, 6> descriptors;
941 descriptor.slices = 4u;
942 descriptor.noCull =
true;
950 descriptors[0].
length = 2.0f;
951 descriptors[1].length = 1.5f;
952 descriptors[2].length = 2.0f;
954 descriptors[0].root =
VECTOR3_ZERO +
vec3<F32>( addValAnd10Percent( descriptors[0].length ), 0.f, 0.f );
955 descriptors[1].root =
VECTOR3_ZERO +
vec3<F32>( 0.f, addValAnd10Percent( descriptors[1].length ), 0.f );
956 descriptors[2].root =
VECTOR3_ZERO +
vec3<F32>( 0.f, 0.f, addValAnd10Percent( descriptors[2].length ) );
958 descriptors[0].radius = 0.05f;
959 descriptors[1].radius = 0.05f;
960 descriptors[2].radius = 0.05f;
962 descriptors[0].colour =
UColour4( 255, 0, 0, 255 );
963 descriptors[1].colour =
UColour4( 0, 255, 0, 255 );
964 descriptors[2].colour =
UColour4( 0, 0, 255, 255 );
971 descriptors[3].
length = 0.5f;
972 descriptors[4].length = 0.5f;
973 descriptors[5].length = 0.5f;
975 descriptors[3].root =
VECTOR3_ZERO +
vec3<F32>( addValMinus20Percent( descriptors[0].length ) + 0.50f, 0.f, 0.f );
976 descriptors[4].root =
VECTOR3_ZERO +
vec3<F32>( 0.f, addValMinus20Percent( descriptors[1].length ) + 0.50f, 0.f );
977 descriptors[5].root =
VECTOR3_ZERO +
vec3<F32>( 0.f, 0.f, addValMinus20Percent( descriptors[2].length ) + 0.50f );
979 descriptors[3].radius = 0.15f;
980 descriptors[4].radius = 0.15f;
981 descriptors[5].radius = 0.15f;
983 descriptors[3].colour =
UColour4( 255, 0, 0, 255 );
984 descriptors[4].colour =
UColour4( 0, 255, 0, 255 );
985 descriptors[5].colour =
UColour4( 0, 0, 255, 255 );
995 static bool allGizmosEnabled =
false;
1001 ImGui::SetCurrentContext(
context );
1004 io.DeltaTime = Time::MicrosecondsToSeconds<F32>( deltaTimeUS );
1007 if ( io.MouseDrawCursor || ImGui::GetMouseCursor() == ImGuiMouseCursor_None )
1011 else if ( !
COMPARE( io.MousePos.x, -1.f ) && !
COMPARE( io.MousePos.y, -1.f ) )
1013 switch ( ImGui::GetCurrentContext()->MouseCursor )
1016 case ImGuiMouseCursor_Arrow:
1019 case ImGuiMouseCursor_TextInput:
1022 case ImGuiMouseCursor_ResizeAll:
1025 case ImGuiMouseCursor_ResizeNS:
1028 case ImGuiMouseCursor_ResizeEW:
1031 case ImGuiMouseCursor_ResizeNESW:
1034 case ImGuiMouseCursor_ResizeNWSE:
1038 case ImGuiMouseCursor_Hand:
1045 nodePreviewWindowVisible(
false);
1060 Scene* activeScene = sMgr->activeProject()->getActiveScene();
1072 if ( !sMgr->resetSelection( 0,
true ) )
1079 if ( allGizmosEnabled )
1083 sceneGizmoEnabled(
true );
1090 sceneGizmoEnabled(
false );
1094 static bool movedToNode =
false;
1098 playerState.overrideCamera(
nullptr );
1099 nodePreviewCamera()->setTarget(
nullptr );
1100 movedToNode =
false;
1104 if ( nodePreviewWindowVisible() )
1106 playerState.overrideCamera( nodePreviewCamera() );
1113 nodePreviewCamera()->minRadius( radius * 0.75f );
1114 nodePreviewCamera()->maxRadius( radius * 10.f );
1115 nodePreviewCamera()->curRadius( radius );
1121 playerState.overrideCamera( editorCamera() );
1123 nodePreviewCamera()->setTarget(
nullptr );
1124 movedToNode =
false;
1142 const ImGuiViewport* viewport = ImGui::GetMainViewport();
1143 ImGui::SetNextWindowPos( viewport->WorkPos );
1144 ImGui::SetNextWindowSize( viewport->WorkSize );
1145 ImGui::SetNextWindowViewport( viewport->ID );
1146 ImGui::PushStyleVar( ImGuiStyleVar_WindowRounding, 0.0f );
1147 ImGui::PushStyleVar( ImGuiStyleVar_WindowBorderSize, 0.0f );
1148 ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 0.0f, 0.0f ) );
1150 constexpr ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
1151 ImGui::Begin(
"Editor",
nullptr, windowFlags );
1152 ImGui::PopStyleVar( 3 );
1154 ImGuiStyle& style = ImGui::GetStyle();
1155 const F32 originalSize = style.WindowMinSize.x;
1156 style.WindowMinSize.x = 300.f;
1157 const ImGuiID dockspace_id = ImGui::GetID(
"EditorDockspace" );
1158 ImGui::DockSpace( dockspace_id, ImVec2( 0.0f, 0.0f ), ImGuiDockNodeFlags_PassthruCentralNode );
1159 style.WindowMinSize.x = originalSize;
1182 static MemoryEditor memEditor;
1184 if ( !memEditor.Open )
1194 ImGui::SetNextWindowPos( ImVec2( 650, 20 ), ImGuiCond_FirstUseEver );
1207 _infiniteGridAxisWidth = value;
1208 _gridSettingsDirty =
true;
1213 _infiniteGridScale = value;
1214 _gridSettingsDirty =
true;
1221 const I64 targetGUID = node.getGUID();
1223 const auto& visibleNodes = _context.kernel().projectManager()->getRenderedNodeList();
1224 const size_t nodeCount = visibleNodes.size();
1225 for (
size_t i = 0u; i < nodeCount; ++i )
1227 if ( visibleNodes.node( i )._node->getGUID() == targetGUID )
1245 ? infiniteGridEnabledNode()
1246 : infiniteGridEnabledScene();
1248 if ( !sceneGizmoEnabled() && !infiniteGridEnabled )
1274 constexpr I32 viewportDim = 256;
1275 constexpr I32 viewportPadding = 6;
1277 GFX::EnqueueCommand<GFX::SetViewportCommand>( bufferInOut)->_viewport =
1279 windowWidth - (viewportDim - viewportPadding),
1306 window->backgroundUpdate();
1317 const ImGuiIO& io = ImGui::GetIO();
1318 if ( io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable ) [[likely]]
1321 ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
1322 for (
I32 n = 0; n < platform_io.Viewports.Size; n++ )
1324 const ImGuiViewport* viewport = platform_io.Viewports[n];
1326 if ( window !=
nullptr && window->
isHovered() && !(viewport->Flags & ImGuiViewportFlags_NoInputs) )
1328 ImGui::GetIO().AddMouseViewportEvent( viewport->ID );
1334 ImGui::GetIO().AddMouseViewportEvent( 0 );
1346 if (
render() ) [[likely]]
1350 ImDrawData* pDrawData = ImGui::GetDrawData();
1351 const I32 fb_width =
to_I32( pDrawData->DisplaySize.x * ImGui::GetIO().DisplayFramebufferScale.x );
1352 const I32 fb_height =
to_I32( pDrawData->DisplaySize.y * ImGui::GetIO().DisplayFramebufferScale.y );
1353 const Rect<I32> targetViewport{0, 0, fb_width, fb_height};
1355 pDrawData->ScaleClipRects( ImGui::GetIO().DisplayFramebufferScale );
1364 if ( io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable ) [[likely]]
1366 ImGui::UpdatePlatformWindows();
1374 if ( running() && _stepQueue > 0 )
1389 const WindowType type = _windowFocusState._focusedNodePreview ? WindowType::NodePreview : WindowType::SceneView;
1391 return viewWindow->
sceneRect( globalCoords );
1398 if (
id == bufferGUID)
1406 auto& newBuffer =
_imguiBuffers.emplace_back(std::make_pair(bufferGUID,
nullptr)).second;
1412 idxBuff.dynamic =
true;
1413 idxBuff.count = maxVertices * 3;
1426 memCmdInOut.
_bufferLocks.push_back( newBuffer->setBuffer( params ));
1427 memCmdInOut.
_bufferLocks.push_back( newBuffer->setIndexBuffer( idxBuff ));
1429 return newBuffer.get();
1436 const bool editorPass,
1442 constexpr U32 MaxVertices = (1 << 16);
1443 constexpr U32 MaxIndices = MaxVertices * 3u;
1444 static ImDrawVert vertices[MaxVertices];
1445 static ImDrawIdx indices[MaxIndices];
1449 const I32 fb_width = targetViewport.
sizeX;
1450 const I32 fb_height = targetViewport.
sizeY;
1453 if ( pDrawData->CmdListsCount == 0 || fb_width <= 0 || fb_height <= 0 )
1459 assert( buffer !=
nullptr );
1462 U32 numVertices = 0, numIndices = 0;
1463 for (
I32 n = 0; n < pDrawData->CmdListsCount; ++n )
1465 const ImDrawList* cl = pDrawData->CmdLists[n];
1466 const U32 clNumVertices =
to_U32(cl->VtxBuffer.size());
1467 const U32 clNumIndices =
to_U32(cl->IdxBuffer.size());
1469 if ( (numVertices + clNumVertices) > MaxVertices || (numIndices + clNumIndices) > MaxIndices )
1474 memcpy( &vertices[numVertices], cl->VtxBuffer.Data, clNumVertices *
sizeof( ImDrawVert ) );
1475 memcpy( &indices[numIndices], cl->IdxBuffer.Data, clNumIndices *
sizeof( ImDrawIdx ) );
1477 numVertices += clNumVertices;
1478 numIndices += clNumIndices;
1485 idxBuffer.dynamic =
true;
1486 idxBuffer.count = numIndices;
1487 idxBuffer.data = indices;
1492 const ImVec4 windowBGColour = ImGui::GetStyle().Colors[ImGuiCol_WindowBg];
1494 auto beginRenderPassCmd = GFX::EnqueueCommand<GFX::BeginRenderPassCommand>( bufferInOut );
1496 beginRenderPassCmd->_name =
"Render IMGUI [ External ]";
1502 auto scopeCmd = GFX::EnqueueCommand<GFX::BeginDebugScopeCommand>( bufferInOut );
1503 scopeCmd->_scopeName =
"Render IMGUI [ Internal ]";
1504 scopeCmd->_scopeId = numVertices;
1507 GFX::EnqueueCommand<GFX::BindPipelineCommand>( bufferInOut)->_pipeline =
_editorPipeline;
1514 GFX::EnqueueCommand<GFX::SetViewportCommand>( bufferInOut)->_viewport = targetViewport;
1516 const F32 scale[] = {
1517 2.f / pDrawData->DisplaySize.
x,
1518 2.f / pDrawData->DisplaySize.y
1521 const F32 translate[] = {
1522 -1.f - pDrawData->DisplayPos.x * scale[0],
1523 1.f + pDrawData->DisplayPos.y * scale[1]
1526 CameraSnapshot& snapshot = GFX::EnqueueCommand<GFX::SetCameraCommand>( bufferInOut)->_cameraSnapshot;
1530 projection.
m[0][0] = scale[0];
1531 projection.
m[1][1] = -scale[1];
1532 projection.
m[2][2] = -1.f;
1533 projection.
m[3][0] = translate[0];
1534 projection.
m[3][1] = translate[1];
1536 const ImVec2 clip_off = pDrawData->DisplayPos;
1537 const ImVec2 clip_scale = pDrawData->FramebufferScale;
1541 ImTextureID crtImguiTexID =
nullptr;
1543 U32 baseVertex = 0u;
1544 U32 indexOffset = 0u;
1549 bool newCommand =
true;
1550 for (
I32 n = 0; n < pDrawData->CmdListsCount; ++n )
1552 const ImDrawList* cmd_list = pDrawData->CmdLists[n];
1553 for (
const ImDrawCmd& pcmd : cmd_list->CmdBuffer )
1555 if ( pcmd.UserCallback )
1557 static_cast<IMGUICallbackData*
>(pcmd.UserCallbackData)->_cmdBuffer = &bufferInOut;
1558 pcmd.UserCallback( cmd_list, &pcmd );
1563 ImVec2 clip_min( (pcmd.ClipRect.x - clip_off.x)* clip_scale.x, (pcmd.ClipRect.y - clip_off.y)* clip_scale.y );
1564 ImVec2 clip_max( (pcmd.ClipRect.z - clip_off.x)* clip_scale.x, (pcmd.ClipRect.w - clip_off.y)* clip_scale.y );
1567 if (clip_min.x < 0.f) { clip_min.x = 0.f; }
1568 if (clip_min.y < 0.f) { clip_min.y = 0.f; }
1569 if (clip_max.x > fb_width) { clip_max.x =
to_F32(fb_width); }
1570 if (clip_max.y > fb_height) { clip_max.y =
to_F32(fb_height); }
1571 if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
1577 clipRect.
sizeX =
to_I32( clip_max.x - clip_min.x );
1578 clipRect.
sizeY =
to_I32( clip_max.y - clip_min.y );
1582 if ( prevClipRect != clipRect )
1584 prevClipRect = clipRect;
1585 GFX::EnqueueCommand<GFX::SetScissorCommand>( bufferInOut )->_rect = clipRect;
1593 ImTextureID imguiTexID = pcmd.GetTexID();
1595 if ( imguiTexID != crtImguiTexID )
1599 auto cmd = GFX::EnqueueCommand<GFX::BindShaderResourcesCommand>( bufferInOut );
1610 crtImguiTexID = imguiTexID;
1616 drawCommand = GFX::EnqueueCommand<GFX::DrawCommand>( bufferInOut );
1621 drawCmd->_sourceBuffer = buffer->handle();
1622 drawCmd->_cmd.indexCount = pcmd.ElemCount;
1623 drawCmd->_cmd.firstIndex = indexOffset + pcmd.IdxOffset;
1624 drawCmd->_cmd.baseVertex = baseVertex + pcmd.VtxOffset;
1629 indexOffset += cmd_list->IdxBuffer.size();
1630 baseVertex += cmd_list->VtxBuffer.size();
1635 GFX::EnqueueCommand<GFX::EndRenderPassCommand>( bufferInOut );
1639 GFX::EnqueueCommand<GFX::EndDebugScopeCommand>( bufferInOut );
1662 _editorCamera->lookAt( eye, fwd, up );
1667 _editorCamera->speedFactor( speed );
1676 Time::SecondsToMilliseconds<F32>( 2.0f ),
1681 showStatusMessage(
"Nothing to Undo", Time::SecondsToMilliseconds<F32>( 2.0f ),
true );
1691 Time::SecondsToMilliseconds<F32>( 2.0f ),
1696 showStatusMessage(
"Nothing to Redo", Time::SecondsToMilliseconds<F32>( 2.0f ),
true );
1708 if (
_gizmo->onKey(
true, key ) )
1717 io.AddKeyEvent( ImGuiMod_Ctrl,
true );
1721 io.AddKeyEvent( ImGuiMod_Shift,
true );
1725 io.AddKeyEvent( ImGuiMod_Alt,
true );
1729 io.AddKeyEvent( ImGuiMod_Super,
true );
1732 io.AddKeyEvent( imguiKey,
true );
1746 if (
_gizmo->onKey(
false, key ) )
1774 io.AddKeyEvent( ImGuiMod_Ctrl,
false );
1778 io.AddKeyEvent( ImGuiMod_Shift,
false );
1782 io.AddKeyEvent( ImGuiMod_Alt,
false );
1786 io.AddKeyEvent( ImGuiMod_Super,
false );
1789 io.AddKeyEvent( imguiKey,
false );
1797 if ( window !=
nullptr )
1799 for (
I32 i = 0; i !=
context->Viewports.Size; i++ )
1816 if ( focusedWindow ==
nullptr )
1818 focusedWindow = g_windowManager->mainWindow();
1819 assert( focusedWindow !=
nullptr );
1825 if ( viewport ==
nullptr )
1847 _windowFocusState._hoveredScenePreview = sceneView->hovered() && sceneView->
sceneRect(
true ).
contains( mousePos.x, mousePos.y );
1850 _windowFocusState._hoveredNodePreview = nodeView->hovered() && nodeView->
sceneRect(
true ).
contains( mousePos.x, mousePos.y );
1852 _windowFocusState._globalMousePos = mousePos;
1856 Rect<I32>( 0, 0, viewportSize.
z, viewportSize.
w ) );
1857 _windowFocusState._scaledMousePos = ImVec2( tempMousePos.
x, tempMousePos.
y );
1863 if ( !
isInit() || !running() )
1876 ImVec2 tempCoords{};
1878 bool positionOverride =
false;
1881 if ( ctx->IO.WantSetMousePos )
1884 assert( !positionOverride );
1886 positionOverride =
true;
1887 tempCoords = ctx->IO.MousePos;
1889 to_I32( tempCoords.y ) );
1893 if ( !positionOverride )
1897 tempCoords = {
to_F32( posGlobal.x ),
to_F32( posGlobal.y ) };
1904 ImGuiContext* ctx =
nullptr;
1907 if ( !ctx->IO.WantSetMousePos )
1909 ImGui::SetCurrentContext( ctx );
1910 ctx->IO.AddMousePosEvent( _windowFocusState._globalMousePos.x,
1911 _windowFocusState._globalMousePos.y );
1916 if ( !ctx->IO.WantSetMousePos )
1918 ImGui::SetCurrentContext( ctx );
1919 ctx->IO.AddMousePosEvent( _windowFocusState._scaledMousePos.x,
1920 _windowFocusState._scaledMousePos.y );
1928 ImGui::SetCurrentContext( ctx );
1931 ctx->IO.AddMouseWheelEvent( ctx->IO.MouseWheelH + 1, ctx->IO.MouseWheel );
1935 ctx->IO.AddMouseWheelEvent( ctx->IO.MouseWheelH - 1, ctx->IO.MouseWheel );
1939 ctx->IO.AddMouseWheelEvent( ctx->IO.MouseWheelH, ctx->IO.MouseWheel + 1 );
1943 ctx->IO.AddMouseWheelEvent( ctx->IO.MouseWheelH, ctx->IO.MouseWheel - 1 );
1950 if ( _windowFocusState._focusedNodePreview )
1973 ImGui::SetCurrentContext( ctx );
1978 ctx->IO.AddMouseButtonEvent(
to_I32( i ),
true );
1986 _gizmo->onMouseButton(
true );
2011 if ( SetFocus( _windowFocusState ) )
2018 ImGui::SetCurrentContext( ctx );
2023 ctx->IO.AddMouseButtonEvent(
to_I32( i ),
false );
2029 _gizmo->onMouseButton(
false );
2042 return wantsJoystick();
2047 return wantsJoystick();
2052 return wantsJoystick();
2057 return wantsJoystick();
2062 return wantsJoystick();
2067 return wantsJoystick();
2072 return wantsJoystick();
2077 if ( !
isInit() || !running() )
2091 if ( ctx->IO.WantCaptureMouseUnlessPopupClose )
2100 return _gizmo->needsMouse();
2112 if ( ctx->IO.WantCaptureKeyboard )
2119 return _windowFocusState._focusedNodePreview;
2124 return isInit() && running() && !Focused( _windowFocusState );
2129 return isInit() && running() && !Hovered( _windowFocusState );
2139 bool wantsCapture =
false;
2142 ImGui::SetCurrentContext( ctx );
2143 ctx->IO.AddInputCharactersUTF8( arg.
_text.c_str() );
2144 wantsCapture = ctx->IO.WantCaptureKeyboard || wantsCapture;
2148 return wantsCapture;
2174 ctx->IO.DisplayFramebufferScale = ImVec2(
2191 if ( w < 1 || h < 1 || _nodePreviewRTHandle._rt->getResolution() ==
vec2<U16>( w, h ) )
2202 if (
_context.
kernel().projectManager()->saveActiveScene(
false,
true, msgCallback, finishCallback ) )
2233 ._unloadPreviousScene =
true,
2234 ._loadInSeparateThread =
true,
2235 ._deferToStartOfFrame =
true,
2236 ._createIfNotExist = createIfNotExists
2239 if ( !
_context.
kernel().projectManager()->activeProject()->switchScene( target ) )
2243 Time::SecondsToMilliseconds<F32>( 3.f ),
2252 if ( crtEntry != scene )
2254 tempBuffer.
put( crtEntry );
2257 tempBuffer.
put( scene );
2259 size_t i = tempBuffer.
size();
2277 const auto& graph =
_context.
kernel().projectManager()->activeProject()->getActiveScene()->sceneGraph();
2278 ret +=
to_U32( graph->getTotalNodeCount() );
2285 Scene* activeScene =
_context.
kernel().projectManager()->activeProject()->getActiveScene();
2292 const bool preserveAspect,
2293 const bool useModal )
const
2295 if ( tex == INVALID_HANDLE<Texture> )
2302 static std::array<bool, 4> state = {
true,
true,
true,
true };
2304 const ImDrawCallback toggleColours = []( [[maybe_unused]]
const ImDrawList* parent_list,
const ImDrawCmd* imCmd ) ->
void
2313 bool isArrayTexture =
false;
2314 if ( data->
_texture != INVALID_HANDLE<Texture> )
2318 const TextureType texType = tex->descriptor()._texType;
2322 if ( isTextureArray || isTextureCube )
2324 isArrayTexture =
true;
2326 auto cmd = GFX::EnqueueCommand<GFX::BindShaderResourcesCommand>( buffer );
2338 if ( isTextureCube )
2341 { 0u, tex->mipCount() },
2342 { 0u,
to_U16( tex->depth() * 6u) });
2344 Set( binding.
_data, texView, defaultSampler );
2357 bool closed =
false;
2358 bool opened =
false;
2365 opened = ImGui::BeginPopupModal( modalName.data(),
nullptr, ImGuiWindowFlags_AlwaysAutoResize );
2370 opened = ImGui::Begin( modalName.data(),
nullptr, ImGuiWindowFlags_AlwaysAutoResize );
2375 assert( tex != INVALID_HANDLE<Texture> );
2386 const U8 numChannels =
NumChannels( texPtr->descriptor()._baseFormat );
2388 assert( numChannels > 0 );
2390 bool isArray =
false;
2393 ImGui::Text(
"Depth: " );
2397 ImGui::Text(
"Range: " );
2399 ImGui::DragFloatRange2(
"",
2408 ImGui::Text(
"R: " );
2412 if ( numChannels > 1 )
2415 ImGui::Text(
"G: " );
2419 if ( numChannels > 2 )
2422 ImGui::Text(
"B: " );
2427 if ( numChannels > 3 )
2430 ImGui::Text(
"A: " );
2437 ImGui::Text(
"Flip: " );
2443 U32 maxLayers = texPtr->depth();
2450 ImGui::Text(
"Layer: " );
2452 ImGui::SliderScalar(
"##modalTextureLayerSelect",
2458 U16 maxMip = texPtr->mipCount();
2463 ImGui::Text(
"Mip: " );
2465 ImGui::SliderScalar(
"##modalTextureMipSelect",
2467 &g_modalTextureData.
_mip,
2472 const bool nonDefaultColours = g_modalTextureData.
_isDepthTexture || !state[0] || !state[1] || !state[2] || !state[3] || g_modalTextureData.
_flip || isArray;
2473 g_modalTextureData.
_colourData.
set( state[0] ? 1 : 0, state[1] ? 1 : 0, state[2] ? 1 : 0, state[3] ? 1 : 0 );
2475 if ( nonDefaultColours )
2477 ImGui::GetWindowDrawList()->AddCallback( toggleColours, &g_modalTextureData );
2481 if ( preserveAspect )
2483 const U16 w = texPtr->width();
2484 const U16 h = texPtr->height();
2485 aspect = w /
to_F32( h );
2488 static F32 zoom = 1.0f;
2489 static ImVec2 zoomCenter( 0.5f, 0.5f );
2491 ImVec2( dimensions.
width, dimensions.
height / aspect ),
2497 ImVec2( 16.f, 1.025f ) );
2499 if ( nonDefaultColours )
2502 ImGui::GetWindowDrawList()->AddCallback( toggleColours, &defaultData );
2505 ImGui::Text(
"Mouse: Wheel = scroll | CTRL + Wheel = zoom | Hold Wheel "
2508 if ( ImGui::Button(
"Close" ) )
2511 zoomCenter = ImVec2( 0.5f, 0.5f );
2514 ImGui::CloseCurrentPopup();
2516 g_modalTextureData.
_texture = INVALID_HANDLE<Texture>;
2529 else if ( !useModal )
2542 if ( mesh == INVALID_HANDLE<Mesh> )
2556 Get(mesh)->resourceName().c_str() ) )
2583 static bool wasClosed =
false;
2586 using ReturnTypeOfName = std::remove_cvref_t<std::invoke_result_t<
decltype(&Resource::resourceName),
Resource>>;
2587 static char inputBuf[ReturnTypeOfName::kMaxSize + 2] = {};
2590 if ( ImGui::BeginPopupModal(
"Spawn Entity",
nullptr, ImGuiWindowFlags_AlwaysAutoResize ) )
2602 ImGui::Text(
"Spawn [ %s ]?", inputBuf );
2605 ImGui::Text(
"Scale:" ); ImGui::SameLine();
2609 ImGui::Text(
"Position:" ); ImGui::SameLine();
2613 ImGui::Text(
"Rotation (euler):" ); ImGui::SameLine();
2614 if ( ImGui::InputFloat3(
"##Rotation (euler):", rotation.
_v ) )
2617 ImGui::Text(
"Name:" ); ImGui::SameLine();
2618 if ( ImGui::InputText(
"##Name:",
2621 ImGuiInputTextFlags_EnterReturnsTrue ) )
2626 if ( ImGui::Button(
"Cancel", ImVec2( 120, 0 ) ) )
2628 ImGui::CloseCurrentPopup();
2630 rotation.
set( 0.f );
2634 ImGui::SetItemDefaultFocus();
2636 if ( ImGui::Button(
"Yes", ImVec2( 120, 0 ) ) )
2638 ImGui::CloseCurrentPopup();
2648 rotation.
set( 0.f );
2660 const F32 durationMS,
2663 _statusBar->showMessage( message, durationMS, error );
2670 const std::string_view name)
const
2675 nodeDescriptor.
_name = name;
2679 Scene* activeScene =
_context.
kernel().projectManager()->activeProject()->getActiveScene();
2680 const SceneGraphNode* node = activeScene->sceneGraph()->getRoot()->addChildNode( nodeDescriptor );
2681 if ( node !=
nullptr )
2685 tComp->
rotate( rotation );
2701 return _context.
kernel().projectManager()->activeProject()->getSceneEntries();
2706 Scene* activeScene =
_context.
kernel().projectManager()->activeProject()->getActiveScene();
2707 return *activeScene->lightPool();
2724 window->onRemoveComponent( comp );
2732 bool savedParent =
false, savedScene =
false;
2735 if ( sgn->parent() !=
nullptr && sgn->parent()->parent() !=
nullptr )
2739 if ( unsavedSceneChanges() )
2746 "Saved node [ {} ] to file! (Saved parent: {}) (Saved scene: {})",
2747 sgn->name().c_str(),
2748 savedParent ?
"Yes" :
"No",
2749 savedScene ?
"Yes" :
"No" ),
2750 Time::SecondsToMilliseconds<F32>( 3 ),
2760 sgn->name().c_str() ),
2761 Time::SecondsToMilliseconds<F32>( 3 ),
2768 Scene* activeScene =
_context.
kernel().projectManager()->activeProject()->getActiveScene();
2769 activeScene->sceneGraph()->removeNode( nodeGUID );
2770 unsavedSceneChanges(
true );
2779 return selection->componentMask() &
to_U32( newComponentType );
2791 Scene* activeScene =
context().
kernel().projectManager()->activeProject()->getActiveScene();
2809 return !( selection->componentMask() &
to_U32( newComponentType ) );
2821 Scene* activeScene =
context().
kernel().projectManager()->activeProject()->getActiveScene();
2835 boost::property_tree::ptree pt;
2836 const ResourcePath editorPath = Paths::g_xmlDataLocation / Paths::Editor::g_saveLocation;
2843 pt.put(
"editor.grid.<xmlattr>.enabled_scene", infiniteGridEnabledScene() );
2844 pt.put(
"editor.grid.<xmlattr>.enabled_node", infiniteGridEnabledNode() );
2847 pt.put(
"editor.nodeBGColour.<xmlattr>.r", nodePreviewBGColour().r );
2848 pt.put(
"editor.nodeBGColour.<xmlattr>.g", nodePreviewBGColour().g );
2849 pt.put(
"editor.nodeBGColour.<xmlattr>.b", nodePreviewBGColour().b );
2851 if ( _editorCamera )
2853 _editorCamera->saveToXML( pt,
"editor" );
2855 if ( _nodePreviewCamera )
2857 _nodePreviewCamera->saveToXML( pt,
"editor" );
2861 pt.add(
"editor.recentScene.entry",
_recentSceneList.get( i )._name.c_str() );
2869 g_editorSaveFileBak,
2871 == FileError::NONE )
2883 static boost::property_tree::ptree g_emptyPtree;
2885 boost::property_tree::ptree pt;
2886 const ResourcePath editorPath = Paths::g_xmlDataLocation / Paths::Editor::g_saveLocation;
2887 if ( !
fileExists( editorPath / g_editorSaveFile ) )
2889 if (
fileExists( editorPath / g_editorSaveFileBak ) )
2892 g_editorSaveFileBak,
2896 != FileError::NONE )
2903 if (
fileExists( editorPath / g_editorSaveFile ) )
2919 for (
const auto& [tag, data] :
2920 pt.get_child(
"editor.recentScene", g_emptyPtree ) )
2922 if ( tag ==
"<xmlcomment>" )
2926 const std::string name = data.get_value<std::string>();
2927 if ( !name.empty() )
2933 if ( _editorCamera )
2935 _editorCamera->loadFromXML( pt,
"editor" );
2937 if ( _nodePreviewCamera )
2939 _nodePreviewCamera->loadFromXML( pt,
"editor" );
2941 infiniteGridEnabledScene( pt.get(
"editor.grid.<xmlattr>.enabled_scene",
2942 infiniteGridEnabledScene() ) );
2943 infiniteGridEnabledNode( pt.get(
"editor.grid.<xmlattr>.enabled_node", infiniteGridEnabledNode() ) );
2946 _nodePreviewBGColour.set(
2947 pt.get(
"editor.nodeBGColour.<xmlattr>.r", nodePreviewBGColour().r ),
2948 pt.get(
"editor.nodeBGColour.<xmlattr>.g", nodePreviewBGColour().g ),
2949 pt.get(
"editor.nodeBGColour.<xmlattr>.b", nodePreviewBGColour().b ) );
2956 namespace Util::detail
2963 ImGui::PushItemFlag( ImGuiItemFlags_Disabled,
true );
2966 ImGui::PushStyleVar( ImGuiStyleVar_Alpha, std::max(0.5f, ImGui::GetStyle().Alpha - 0.35f) );
2975 ImGui::PopStyleVar();
2977 ImGui::PopItemFlag();
#define WAIT_FOR_CONDITION(...)
#define PROFILE_SCOPE_AUTO(CATEGORY)
#define PROFILE_SCOPE(NAME, CATEGORY)
WindowManager & windowManager() noexcept
static void updateSelection(Gizmo *gizmo, const vector< SceneGraphNode * > &nodes)
static void render(Gizmo *gizmo, const Camera *camera, const Rect< I32 > &targetViewport, GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
static void onSceneFocus(Gizmo *gizmo, const bool state) noexcept
static void update(Gizmo *gizmo, const U64 deltaTimeUS)
static BoundingSphere moveCameraToNode(const Divide::ProjectManager *mgr, Camera *camera, const SceneGraphNode *targetNode)
static Camera * playerCamera(const Divide::ProjectManager *mgr, const bool skipOverride=false) noexcept
static bool saveNode(const Divide::ProjectManager *mgr, const SceneGraphNode *targetNode)
static bool loadNode(const Divide::ProjectManager *mgr, SceneGraphNode *targetNode)
static void editorPreviewNode(Divide::ProjectManager *mgr, const I64 editorPreviewNode)
static Camera * playerCamera(const Divide::ProjectManager *mgr, bool skipOverride=false) noexcept
static SceneEnvironmentProbePool * getEnvProbes(const Divide::ProjectManager *manager) noexcept
F32 getRadius() const noexcept
static Camera * GetUtilityCamera(const UtilityCamera type)
static Camera * CreateCamera(const Str< 256 > &cameraName, Mode cameraMode)
const CameraSnapshot & snapshot() const noexcept
Returns the internal camera snapshot data (eye, orientation, etc)
static mat4< F32 > LookAt(const vec3< F32 > &eye, const vec3< F32 > &target, const vec3< F32 > &up) noexcept
static bool DestroyCamera(Camera *&camera)
size_t size() const noexcept
const T & get(const size_t idx) const
void bringToFront() const noexcept
vec2< U16 > getDrawableSize() const noexcept
bool hidden() const noexcept
bool isHovered() const noexcept
I32 currentDisplayIndex() const noexcept
vec2< U16 > getDimensions() const noexcept
void addEventListener(WindowEvent windowEvent, const EventListener &listener)
void selectionChangeCallback(PlayerIndex idx, const vector< SceneGraphNode * > &nodes) const
bool joystickAxisMoved(const Input::JoystickEvent &arg) noexcept override
Handle< ShaderProgram > _infiniteGridProgram
void createFontTexture(F32 DPIScaleFactor)
Destroys the old font, if any, before loading the new one.
PipelineDescriptor _axisGizmoPipelineDesc
DisplayWindow * _mainWindow
void showStatusMessage(const string &message, F32 durationMS, bool error) const
void updateFocusState(ImVec2 mousePos)
bool mouseButtonReleased(const Input::MouseButtonEvent &arg) override
Mouse button released: return true if input was consumed.
EditorOptionsWindow_uptr _optionsWindow
UndoManager_uptr _undoManager
static ImGuiViewport * FindViewportByPlatformHandle(ImGuiContext *context, const DisplayWindow *window)
SceneGraphNode * _previewNode
bool mouseMoved(const Input::MouseMoveEvent &arg) override
Mouse moved: return true if input was consumed.
bool onKeyDown(const Input::KeyEvent &key) override
Key pressed: return true if input was consumed.
bool wantsKeyboard() const noexcept
std::pair< bufferPtr, size_t > _memoryEditorData
eastl::fixed_vector< std::pair< I64, GenericVertexData_ptr >, 5, true > _imguiBuffers
RenderTargetHandle _nodePreviewRTHandle
bool addComponent(SceneGraphNode *selection, ComponentType newComponentType) const
bool joystickButtonPressed(const Input::JoystickEvent &arg) noexcept override
Joystick or Gamepad: return true if input was consumed.
bool joystickRemap(const Input::JoystickEvent &arg) noexcept override
void onChangeScene(Scene *newScene)
bool modalModelSpawn(Handle< Mesh > mesh, bool quick, const vec3< F32 > &scale=VECTOR3_UNIT, const vec3< F32 > &position=VECTOR3_ZERO)
Returns true if the model was queued.
U32 stepQueue() const noexcept
void onWindowSizeChange(const SizeChangeParams ¶ms)
bool init(const vec2< U16 > renderResolution)
bool modalTextureView(std::string_view modalName, Handle< Texture > tex, vec2< F32 > dimensions, bool preserveAspect, bool useModal) const
Returns true if the window was closed.
std::array< ImGuiContext *, to_base(ImGuiContextType::COUNT)> _imguiContexts
void drawScreenOverlay(const Camera *camera, const Rect< I32 > &targetViewport, GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut) const
Render any editor specific element that needs to be part of the scene (e.g. Control Gizmo)
bool mouseButtonPressed(const Input::MouseButtonEvent &arg) override
Mouse button pressed: return true if input was consumed.
void renderModelSpawnModal()
void renderDrawList(ImDrawData *pDrawData, I64 bufferGUID, const Rect< I32 > &targetViewport, bool editorPass, GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
LightPool & getActiveLightPool() const
bool joystickAddRemove(const Input::JoystickEvent &arg) noexcept override
Time::ProfileTimer & _editorUpdateTimer
U32 saveItemCount() const noexcept
StatusBar_uptr _statusBar
void postRender(RenderStage stage, const CameraSnapshot &cameraSnapshot, RenderTargetID target, GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
bool spawnGeometry(Handle< Mesh > mesh, const vec3< F32 > &scale, const vec3< F32 > &position, const vec3< Angle::DEGREES< F32 > > &rotation, std::string_view name) const
Return true if the model was spawned as a scene node.
bool isInit() const noexcept
Pipeline * _editorPipeline
const ProjectIDs & getProjectList() const noexcept
void infiniteGridScale(const F32 value) noexcept
bool joystickBallMoved(const Input::JoystickEvent &arg) noexcept override
void copyPlayerCamToEditorCam() noexcept
ImGuiStyleEnum _currentTheme
void update(U64 deltaTimeUS)
std::array< std::unique_ptr< DockedWindow >, to_base(WindowType::COUNT)> _dockedWindows
struct Divide::Editor::QueueModelSpawn _queuedModelSpawn
IMPrimitive * _infiniteGridPrimitive
static std::array< Input::MouseButton, 5 > g_oisButtons
SamplerDescriptor _editorSampler
bool removeComponent(SceneGraphNode *selection, ComponentType newComponentType) const
bool isNodeInView(const SceneGraphNode &node) const noexcept
Return true if the specified node passed frustum culling during the main render pass.
CircularBuffer< SceneEntry, 10 > _recentSceneList
static std::array< const char *, 3 > g_supportedExportPlatforms
void loadNode(SceneGraphNode *sgn) const
void onRemoveComponent(const EditorComponent &comp) const
bool onTextEvent(const Input::TextEvent &arg) override
bool wantsJoystick() const noexcept
BoundingSphere teleportToNode(Camera *camera, const SceneGraphNode *sgn) const
bool onKeyUp(const Input::KeyEvent &key) override
Key released: return true if input was consumed.
void setEditorCamLookAt(const vec3< F32 > &eye, const vec3< F32 > &fwd, const vec3< F32 > &up)
void saveNode(const SceneGraphNode *sgn) const
bool switchScene(const SceneEntry &scene, bool createIfNotExists=false)
bool frameEnded(const FrameEvent &evt) noexcept override
frameEnded is called after the buffers have been swapped
bool framePostRender(const FrameEvent &evt) override
const SceneEntries & getSceneList() const noexcept
ResourcePath _externalTextEditorPath
GenericVertexData * getOrCreateIMGUIBuffer(I64 bufferGUID, U32 maxVertices, GFX::MemoryBarrierCommand &memCmdInOut)
bool simulationPaused() const noexcept
void getCommandBuffer(GFX::CommandBuffer &bufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
SceneEnvironmentProbePool * getActiveEnvProbePool() const noexcept
bool joystickButtonReleased(const Input::JoystickEvent &arg) noexcept override
void setEditorCameraSpeed(const vec3< F32 > &speed) noexcept
bool saveSceneChanges(const DELEGATE< void, std::string_view > &msgCallback, const DELEGATE< void, bool > &finishCallback) const
Saves all new changes to the current scene and uses the provided callbacks to return progress message...
void onResolutionChange(const SizeChangeParams ¶ms)
Handle< Texture > _fontTexture
bool joystickPovMoved(const Input::JoystickEvent &arg) noexcept override
Time::ProfileTimer & _editorRenderTimer
void queueRemoveNode(I64 nodeGUID)
CameraSnapshot _render2DSnapshot
bool isDefaultScene() const noexcept
bool openProject(const ProjectID &projectID)
void infiniteGridAxisWidth(const F32 value) noexcept
string _lastOpenSceneName
PipelineDescriptor _infiniteGridPipelineDesc
Handle< ShaderProgram > _imguiProgram
Rect< I32 > scenePreviewRect(bool globalCoords) const noexcept
IMPrimitive * newIMP(std::string_view name)
Create and return a new immediate mode emulation primitive.
GFXRTPool & renderTargetPool() noexcept
const RenderStateBlock & getNoDepthTestBlock() const noexcept
returns the standard state block
bool destroyIMP(IMPrimitive *&primitive)
Pipeline * newPipeline(const PipelineDescriptor &descriptor)
Create and return a new graphics pipeline. This is only used for caching and doesn't use the object a...
GenericVertexData_ptr newGVD(U32 ringBufferLength, std::string_view name)
void flushCommandBuffer(Handle< GFX::CommandBuffer > &&commandBuffer)
RenderTarget * getRenderTarget(const RenderTargetID target) const
RenderTargetHandle allocateRT(const RenderTargetDescriptor &descriptor)
bool deallocateRT(RenderTargetHandle &handle)
FORCE_INLINE I64 getGUID() const noexcept
virtual BufferLock updateBuffer(U32 buffer, U32 elementCountOffset, U32 elementCountRange, bufferPtr data)=0
virtual BufferLock setIndexBuffer(const IndexBuffer &indices)=0
void getCommandBuffer(GFX::CommandBuffer &commandBufferInOut, GFX::MemoryBarrierCommand &memCmdInOut)
void beginBatch(bool reserveBuffers, U32 vertexCount, U32 attributeCount)
void vertex(F32 x, F32 y, F32 z)
void fromCones(const IM::ConeDescriptor *cones, size_t count)
void setPipelineDescriptor(const PipelineDescriptor &descriptor)
void setPushConstants(const PushConstantsStruct &fastData)
void begin(PrimitiveTopology type)
const Rect< I32 > & sceneRect(bool globalCoords) const noexcept
PlatformContext & context() noexcept
PlatformContext & _context
Application & app() noexcept
Kernel & kernel() noexcept
Editor & editor() noexcept
GFXDevice & gfx() noexcept
Configuration & config() noexcept
bool contains(U xIn, U yIn) const noexcept
bool resize(U16 width, U16 height)
Resize all attachments.
U16 getWidth() const noexcept
static BoundingSphere GetBounds(const SceneGraphNode *sgn)
void RemoveComponents(U32 componentMask)
FORCE_INLINE T * get() const
Returns a pointer to a specific component. Returns null if the SGN does not have the component reques...
void AddComponents(U32 componentMask, bool allowDuplicates)
static I64 DEFAULT_SCENE_GUID
An API-independent representation of a texture.
static Handle< Texture > DefaultTexture2DArray() noexcept
static const SamplerDescriptor DefaultSampler() noexcept
static Handle< Texture > DefaultTexture2D() noexcept
ImageView getView() const noexcept
static bool IsRelativeMouseMode() noexcept
static U32 GetMouseState(vec2< I32 > &pos, bool global) noexcept
DisplayWindow * getFocusedWindow() noexcept
static void SetCaptureMouse(bool state) noexcept
DisplayWindow * createWindow(const WindowDescriptor &descriptor, ErrorCode &err)
const vector< MonitorData > & monitorData() const noexcept
static void SetCursorStyle(CursorStyle style)
bool destroyWindow(DisplayWindow *&window)
static bool SetGlobalCursorPosition(I32 x, I32 y) noexcept
DisplayWindow & getWindow(I64 guid)
void drawToWindow(DisplayWindow &window)
vec3< T > getForwardVec() const noexcept
Alias for -getCol(2). Assumes -Z fwd.
vec3< T > getUpVec() const noexcept
Alias for getCol(1)
void set(const T *v) noexcept
set the 2 components of the vector manually using a source pointer to a (large enough) array
T length() const noexcept
return the vector's length
vec3 direction(const vec3 &u) const noexcept
get the direction vector to the specified point
void set(const T *v) noexcept
set the 3 components of the vector manually using a source pointer to a (large enough) array
void set(const T *v) noexcept
set the 4 components of the vector manually using a source pointer to a (large enough) array
static size_t ImFormatString(char *buf, size_t buf_size, const char *fmt,...)
#define IM_ARRAYSIZE(_ARR)
constexpr U8 MAX_FRAMES_IN_FLIGHT
Maximum number of active frames until we start waiting on a fence/sync.
constexpr char ENGINE_NAME[]
CommandBuffer * Get(Handle< CommandBuffer > handle)
FORCE_INLINE T * EnqueueCommand(CommandBuffer &buffer)
Handle< CommandBuffer > AllocateCommandBuffer(const char *name, const size_t reservedCmdCount)
FORCE_INLINE void FreeWrapper(void *ptr, void *user_data) noexcept
static ImGuiAllocatorUserData g_ImAllocatorUserData
FORCE_INLINE void * MallocWrapper(const size_t size, void *user_data) noexcept
static ImGuiMemAllocFunc g_ImAllocatorAllocFunc
static ImGuiMemFreeFunc g_ImAllocatorFreeFunc
constexpr Optick::Category::Type GUI
static std::stack< bool > g_readOnlyFaded
Str StringFormat(const char *fmt, Args &&...args)
bool IsEmptyOrNull(const char *str) noexcept
void OpenCenteredPopup(const char *name, ImGui::ImGuiPopupFlags popup_flags=0)
void writeXML(const ResourcePath &path, const boost::property_tree::ptree &tree)
void readXML(const ResourcePath &path, boost::property_tree::ptree &tree)
void Reset(Editor::FocusedWindowState &state) noexcept
const string g_editorFontFileBold
WindowManager * g_windowManager
bool Hovered(const Editor::FocusedWindowState &state) noexcept
const string g_editorSaveFileBak
const string g_editorSaveFile
const string g_editorIconFile
bool Focused(const Editor::FocusedWindowState &state) noexcept
const string g_editorFontFile
IMGUICallbackData g_modalTextureData
bool SetFocus(Editor::FocusedWindowState &state) noexcept
Handle console commands that start with a forward slash.
ImTextureID to_TexID(Handle< Texture > handle)
void SetClipboardText(const char *text) noexcept
void InitBasicImGUIState(ImGuiIO &io) noexcept
DELEGATE_STD< Ret, Args... > DELEGATE
F32 PlatformDefaultDPI() noexcept
constexpr U32 to_U32(const T value)
FORCE_INLINE void DestroyResource(Handle< T > &handle, const bool immediate=false)
vector< SceneEntry > SceneEntries
static const vec3< F32 > WORLD_X_NEG_AXIS
PushConstantsStruct IMGUICallbackToPushConstants(const IMGUICallbackData &data, const bool isArrayTexture)
constexpr U16 to_U16(const T value)
constexpr RenderTargetID SCREEN_TARGET_ID
void PushReadOnly(const bool fade)
vector< ProjectID > ProjectIDs
ImGuiKey DivideKeyToImGuiKey(const Input::KeyCode key) noexcept
bool DebugBreak(const bool condition) noexcept
static const vec3< F32 > WORLD_Y_NEG_AXIS
constexpr F32 to_F32(const T value)
const char * GetClipboardText() noexcept
bool IsCubeTexture(TextureType texType) noexcept
bool IsArrayTexture(TextureType texType) noexcept
FileError createDirectory(const ResourcePath &path)
eastl::vector< Type > vector
bool IsDepthTexture(GFXImagePacking packing) noexcept
FileError copyFile(const ResourcePath &sourcePath, const std::string_view sourceName, const ResourcePath &targetPath, const std::string_view targetName, const bool overwrite)
void Set(DescriptorSetBindingData &dataInOut, ShaderBuffer *buffer, const BufferRange range) noexcept
DescriptorSetBinding & AddBinding(DescriptorSet &setInOut, U8 slot, U16 stageVisibilityMask)
vec2< T > COORD_REMAP(vec2< T > input, const Rect< T > &in_rect, const Rect< T > &out_rect) noexcept
FORCE_INLINE Handle< T > CreateResource(const ResourceDescriptor< T > &descriptor, bool &wasInCache, std::atomic_uint &taskCounter)
@ Vulkan
not supported yet
constexpr U8 to_U8(const T value)
static const vec3< F32 > WORLD_Z_NEG_AXIS
SceneNodeHandle FromHandle(const Handle< T > handle)
Handle< Texture > from_TexID(ImTextureID texID)
bool COMPARE(T X, U Y) noexcept
void ToggleCursor(bool state) noexcept
bool fileExists(const ResourcePath &filePathAndName)
constexpr I32 to_I32(const T value)
static const vec3< F32 > VECTOR3_ZERO
U8 NumChannels(GFXImageFormat format) noexcept
FORCE_INLINE T * Get(const Handle< T > handle)
constexpr auto to_base(const Type value) -> Type
bool ImageZoomAndPan(ImTextureID user_texture_id, const ImVec2 &size, float aspectRatio, float &zoom, ImVec2 &zoomCenter, int panMouseButtonDrag, int resetZoomAndPanMouseButton, const ImVec2 &zoomMaxAndZoomStep)
bool ToggleButton(const char *str_id, bool *v)
bool ResetStyle(int styleEnum, ImGuiStyle &style)
VertexBindings _vertexBindings
BufferUpdateUsage _updateUsage
BufferUpdateFrequency _updateFrequency
size_t _elementSize
Buffer primitive size in bytes.
mat4< F32 > _invViewMatrix
mat4< F32 > _projectionMatrix
static NO_INLINE void errorfn(const char *format, T &&... args)
DescriptorSetBindingData _data
GenericDrawCommandContainer _drawCommands
static constexpr RTColourAttachmentSlot ALBEDO
std::pair< bufferPtr, size_t > _initialData
BufferBindConfig _bindConfig
BufferParams _bufferParams
Handle< Texture > _texture
GFX::CommandBuffer * _cmdBuffer
PlatformContext * _context
PrimitiveTopology _primitiveTopology
AttributeMap _vertexFormat
Handle< ShaderProgram > _shaderProgramHandle
RTBlendStates _blendStates
RenderStateBlock _stateBlock
vector< ShaderModuleDescriptor > _modules
ModuleDefines _globalDefines
MipMappingState _mipMappingState
std::array< BlendingSettings, to_base(RTColourAttachmentSlot::COUNT)> _settings
InternalRTAttachmentDescriptors _attachments
PropertyDescriptor< T > _propertyDescriptor
StringReturnType< N > string() const noexcept
TextureWrap _wrapU
Texture wrap mode (Or S-R-T)
U8 _anisotropyLevel
The value must be in the range [0...255] and is automatically clamped by the max HW supported level.
SceneNodeHandle _nodeHandle
std::array< I64, MAX_SELECTIONS > _selections
U16 width
The new width and height.
DisplayWindow * parentWindow
static ImGuiWindowFlags ExtraWindowFlags