Whatever I was doing last time + made leds always be camera facing. Probably could use some speed up later on.

This commit is contained in:
Peter Slattery 2020-06-27 11:23:50 -07:00
parent e3d7a90a13
commit 266f42c4f6
17 changed files with 105 additions and 94 deletions

View File

@ -135,7 +135,7 @@ RemoveAnimationBlock(gs_list_handle AnimationBlockHandle, animation_system* Anim
internal u32
AddLayer (string Name, animation_system* AnimationSystem, blend_mode BlendMode = BlendMode_Overwrite)
{
// TODO(Peter): If this assert fires its time to make the layer buffer system
// NOTE(Peter): If this assert fires its time to make the layer buffer system
// resizable.
Assert(AnimationSystem->LayersCount < AnimationSystem->LayersMax);

View File

@ -500,6 +500,8 @@ UPDATE_AND_RENDER(UpdateAndRender)
}
#endif
PushRenderOrthographic(RenderBuffer, 0, 0, gs_Width(State->WindowBounds), gs_Height(State->WindowBounds));
PushRenderClearScreen(RenderBuffer);

View File

@ -221,8 +221,7 @@ typedef PANEL_INIT_PROC(panel_init_proc);
#define PANEL_CLEANUP_PROC(name) void name(panel* Panel, app_state* State)
typedef PANEL_CLEANUP_PROC(panel_cleanup_proc);
// TODO(Peter): Should be able to take the mouse out of this
#define PANEL_RENDER_PROC(name) void name(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context, mouse_state Mouse)
#define PANEL_RENDER_PROC(name) void name(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context)
typedef PANEL_RENDER_PROC(panel_render_proc);
// NOTE(Peter): This is used by the meta system to generate panel type info

View File

@ -114,9 +114,9 @@ internal void
LoadAssembly (assembly_array* Assemblies, led_system* LedSystem, memory_arena* Scratch, context Context, string Path, event_log* GlobalLog)
{
platform_memory_result AssemblyFile = ReadEntireFile(Context, Path);
if (AssemblyFile.Error == PlatformMemory_NoError && AssemblyFile.Size > 0)
if (AssemblyFile.Error == PlatformMemory_NoError && AssemblyFile.Data.Size > 0)
{
string AssemblyFileText = MakeString((char*)AssemblyFile.Base);
string AssemblyFileText = MakeString((char*)AssemblyFile.Data.Base);
Assert(Assemblies->Count < Assemblies->CountMax);
assembly* NewAssembly = &Assemblies->Values[Assemblies->Count++];
@ -129,7 +129,7 @@ LoadAssembly (assembly_array* Assemblies, led_system* LedSystem, memory_arena* S
{
v4 Offset = TempAssemblyOffsets[Assemblies->Count % TempAssemblyOffsetsCount];
ConstructAssemblyFromDefinition(NewAssembly, FileName, Offset, LedSystem);
PlatformFree(Context.PlatformMemory, AssemblyFile.Base, AssemblyFile.Size);
PlatformFree(Context.PlatformMemory, AssemblyFile.Data.Base, AssemblyFile.Data.Size);
}
else
{

View File

@ -454,7 +454,7 @@ RenderPanel(panel* Panel, rect PanelBounds, rect WindowBounds, render_command_bu
};
panel_definition Definition = GlobalPanelDefs[Panel->PanelDefinitionIndex];
Definition.Render(*Panel, PanelViewBounds, RenderBuffer, State, Context, Mouse);
Definition.Render(*Panel, PanelViewBounds, RenderBuffer, State, Context);
PushRenderOrthographic(RenderBuffer, WindowBounds.Min.x, WindowBounds.Min.y, WindowBounds.Max.x, WindowBounds.Max.y);
DrawPanelFooter(Panel, RenderBuffer, FooterBounds, Mouse, State);

View File

@ -63,12 +63,15 @@ enum platform_memory_error
PlatformMemory_UnknownError, // You should implement handling this when you see it
};
// TODO(Peter): Change this to just be data
// - Base, and Size
struct platform_memory_result
struct data
{
u8* Base;
s32 Size;
u64 Size;
};
struct platform_memory_result
{
data Data;
platform_memory_error Error;
};
@ -132,15 +135,6 @@ typedef PLATFORM_SEND_TO(platform_send_to);
#define PLATFORM_CLOSE_SOCKET(name) void name(platform_socket_handle SocketHandle)
typedef PLATFORM_CLOSE_SOCKET(platform_close_socket);
// File IO
// TODO(Peter):
struct directory_listing
{
string Path;
directory_listing* Next;
};
// Font
struct platform_font_info
{
@ -285,7 +279,6 @@ ReadEntireFile(context Context, string Path)
internal b32
WriteEntireFile(platform_file_handler FileHandler, string Path, u8* Contents, u32 Size)
{
// TODO(Peter): Overload to take a data struct instead of Contents And Size
b32 Result = FileHandler.WriteEntireFile(Path, Contents, Size);
return Result;
}

View File

@ -342,6 +342,7 @@ SetTri3DInBatch (render_quad_batch_constructor* Constructor, s32 TriIndex,
Constructor->ColorsV[BATCH_3D_COLOR_INDEX(TriIndex, 2)] = C2;
}
inline void
PushTri3DOnBatch (render_quad_batch_constructor* Constructor,
v4 P0, v4 P1, v4 P2,

View File

@ -59,6 +59,10 @@ static gsm_struct_member_type_info StructMembers_v4[] = {
{ "g", 1, (u64)&((v4*)0)->g, {}, 0},
{ "b", 1, (u64)&((v4*)0)->b, {}, 0},
{ "a", 1, (u64)&((v4*)0)->a, {}, 0},
{ "xy", 2, (u64)&((v4*)0)->xy, {}, 0},
{ "yz", 2, (u64)&((v4*)0)->yz, {}, 0},
{ "xyz", 3, (u64)&((v4*)0)->xyz, {}, 0},
{ "z", 1, (u64)&((v4*)0)->z, {}, 0},
{ "E", 1, (u64)&((v4*)0)->E, {}, 0},
};
static gsm_struct_member_type_info StructMembers_pixel[] = {
@ -107,7 +111,7 @@ static gsm_struct_member_type_info StructMembers_multiply_patterns_data[] = {
static gsm_struct_type_info StructTypes[] = {
{ gsm_StructType_solid_color_data, "solid_color_data", 16, 36, 0, 0, StructMembers_solid_color_data, 2 },
{ gsm_StructType_v4, "v4", 2, 16, 0, 0, StructMembers_v4, 3 },
{ gsm_StructType_v4, "v4", 2, 16, 0, 0, StructMembers_v4, 5 },
{ gsm_StructType_float, "float", 5, 4, 0, 0, 0, 0 },
{ gsm_StructType_color_buffer, "color_buffer", 12, 20, 0, 0, StructMembers_color_buffer, 3 },
{ gsm_StructType_pixel, "pixel", 5, 3, 0, 0, StructMembers_pixel, 2 },

View File

@ -572,7 +572,7 @@ DrawAnimationClipsList(rect PanelBounds, ui_interface* Interface, u32 SelectedAn
GSMetaTag(panel_render);
GSMetaTag(panel_type_animation_timeline);
internal void
AnimationTimeline_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context, mouse_state Mouse)
AnimationTimeline_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context)
{
animation_timeline_state* TimelineState = (animation_timeline_state*)Panel.PanelStateMemory;
gs_list_handle SelectedBlockHandle = State->SelectedAnimationBlockHandle;

View File

@ -74,7 +74,7 @@ DrawSACNUniversePixels (render_command_buffer* RenderBuffer, sacn_universe* ToDr
GSMetaTag(panel_render);
GSMetaTag(panel_type_dmx_view);
internal void
DMXView_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context, mouse_state Mouse)
DMXView_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context)
{
#if 0
// :NoLongerFunctionalSACNCodeButThatsOk

View File

@ -36,7 +36,7 @@ FileView_Cleanup(panel* Panel, app_state* State)
GSMetaTag(panel_render);
GSMetaTag(panel_type_file_view);
internal void
FileView_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context, mouse_state Mouse)
FileView_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context)
{
rect HeaderBounds = {0};
HeaderBounds.Min = {PanelBounds.Min.x, PanelBounds.Max.y - 32};

View File

@ -27,7 +27,7 @@ HierarchyView_Cleanup(panel* Panel, app_state* State)
GSMetaTag(panel_render);
GSMetaTag(panel_type_hierarchy);
internal void
HierarchyView_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context, mouse_state Mouse)
HierarchyView_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context)
{
ui_layout Layout = ui_CreateLayout(State->Interface, PanelBounds);
string TempString = PushString(&State->Transient, 256);

View File

@ -420,7 +420,7 @@ ArrangeNodes(pattern_node_workspace Workspace, r32 NodeWidth, r32 LayerDistance,
GSMetaTag(panel_render);
GSMetaTag(panel_type_node_graph);
internal void
NodeGraph_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context, mouse_state Mouse)
NodeGraph_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context)
{
node_graph_state* GraphState = (node_graph_state*)Panel.PanelStateMemory;
b32 MouseHandled = false;
@ -477,7 +477,7 @@ NodeGraph_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuf
{
visual_node VisualNode = GraphState->Layout.VisualNodes[i];
gs_list_handle NodeHandle = State->NodeWorkspace.SortedNodeHandles[i];
DrawNode(VisualNode.Position + GraphState->ViewOffset, VisualNode.Spec, NodeHandle, NodeWidth, LineHeight, State->Interface.Style, RenderBuffer, Mouse, &State->Transient);
DrawNode(VisualNode.Position + GraphState->ViewOffset, VisualNode.Spec, NodeHandle, NodeWidth, LineHeight, State->Interface.Style, RenderBuffer, Context.Mouse, &State->Transient);
}
for (u32 p = 0; p < GraphState->Layout.VisualPortsCount; p++)
@ -487,12 +487,12 @@ NodeGraph_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuf
VisualPort.PortBounds.Max += GraphState->ViewOffset;
v4 PortColor = WhiteV4;
if (PointIsInRange(Mouse.Pos, VisualPort.PortBounds.Min, VisualPort.PortBounds.Max))
if (PointIsInRange(Context.Mouse.Pos, VisualPort.PortBounds.Min, VisualPort.PortBounds.Max))
{
PortColor = PinkV4;
if (MouseButtonTransitionedDown(Mouse.LeftButtonState))
if (MouseButtonTransitionedDown(Context.Mouse.LeftButtonState))
{
BeginConnectNodesOperation(VisualPort, p, Mouse, State);
BeginConnectNodesOperation(VisualPort, p, Context.Mouse, State);
MouseHandled = true;
}
}
@ -519,15 +519,15 @@ NodeGraph_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuf
List.ElementLabelIndent = v2{10, 4};
string TitleString = MakeStringLiteral("Available Nodes");
DrawListElement(TitleString, &List, Mouse, RenderBuffer, State->Interface.Style);
DrawListElement(TitleString, &List, Context.Mouse, RenderBuffer, State->Interface.Style);
for (u32 i = 0; i < NodeType_Count; i++)
{
node_specification_ Spec = NodeSpecifications[i];
rect ElementBounds = DrawListElement(Spec.Identifier, &List, Mouse, RenderBuffer, State->Interface.Style);
rect ElementBounds = DrawListElement(Spec.Identifier, &List, Context.Mouse, RenderBuffer, State->Interface.Style);
if (MouseButtonTransitionedDown(Mouse.LeftButtonState)
&& gs_PointIsInRect(Mouse.DownPos, ElementBounds))
if (MouseButtonTransitionedDown(Context.Mouse.LeftButtonState)
&& gs_PointIsInRect(Context.Mouse.DownPos, ElementBounds))
{
PushNodeOnWorkspace(i, &State->NodeWorkspace, &State->Transient);
GraphState->LayoutIsDirty = true;
@ -535,9 +535,9 @@ NodeGraph_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuf
}
}
if (!MouseHandled && MouseButtonTransitionedDown(Mouse.LeftButtonState))
if (!MouseHandled && MouseButtonTransitionedDown(Context.Mouse.LeftButtonState))
{
BeginPanNodeGraph(State, {}, Mouse);
BeginPanNodeGraph(State, {}, Context.Mouse);
}
}

View File

@ -133,7 +133,7 @@ RenderProfiler_ListVisualization(ui_interface* Interface, ui_layout Layout, debu
GSMetaTag(panel_render);
GSMetaTag(panel_type_profiler);
internal void
ProfilerView_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context, mouse_state Mouse)
ProfilerView_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context)
{
memory_arena* Memory = &State->Transient;
string String = InitializeEmptyString(PushArray(Memory, char, 256), 256);
@ -149,9 +149,9 @@ ProfilerView_Render(panel Panel, rect PanelBounds, render_command_buffer* Render
r32 SingleFrameWidth = (r32)((s32)SingleFrameStep - 2);
ui_OutlineRect(&State->Interface, FrameListBounds, 2, WhiteV4);
if (gs_PointIsInRect(Mouse.Pos, FrameListBounds) && MouseButtonHeldDown(Mouse.LeftButtonState))
if (gs_PointIsInRect(Context.Mouse.Pos, FrameListBounds) && MouseButtonHeldDown(Context.Mouse.LeftButtonState))
{
v2 LocalMouse = gs_TransformPointIntoRectSpace(Mouse.Pos, FrameListBounds);
v2 LocalMouse = gs_TransformPointIntoRectSpace(Context.Mouse.Pos, FrameListBounds);
s32 ClosestFrameIndex = (LocalMouse.x / SingleFrameStep);
if (ClosestFrameIndex >= 0 && ClosestFrameIndex < DEBUG_FRAME_COUNT)
{

View File

@ -71,6 +71,7 @@ SculptureView_Cleanup(panel* Panel, app_state* State)
struct draw_leds_job_data
{
v4 CameraPosition;
v4* Positions;
pixel* Colors;
s32 StartIndex;
@ -107,18 +108,19 @@ DrawLEDsInBufferRangeJob (s32 ThreadID, void* JobData)
v2 UV2 = v2{1, 1};
v2 UV3 = v2{0, 1};
for (s32 LedIndex = 0; LedIndex < LEDCount; LedIndex++)
{
pixel PixelColor = Data->Colors[LedIndex];
v4 Color = v4{PixelColor.R / 255.f, PixelColor.G / 255.f, PixelColor.B / 255.f, 1.0f};
v4 V4Position = Data->Positions[Data->StartIndex + LedIndex];
V4Position.w = 0;
v4 P0 = P0_In + V4Position;
v4 P1 = P1_In + V4Position;
v4 P2 = P2_In + V4Position;
v4 P3 = P3_In + V4Position;
v4 Position = Data->Positions[Data->StartIndex + LedIndex];
m44 FaceCameraMatrix = GetLookAtMatrix(Position, Data->CameraPosition);
v4 PositionOffset = V4(Position.xyz, 0); // Ensure PositionOffset is a vector, not a point
v4 P0 = (FaceCameraMatrix * P0_In) + PositionOffset;
v4 P1 = (FaceCameraMatrix * P1_In) + PositionOffset;
v4 P2 = (FaceCameraMatrix * P2_In) + PositionOffset;
v4 P3 = (FaceCameraMatrix * P3_In) + PositionOffset;
SetTri3DInBatch(Data->Batch, BatchReservedRange.Start + TrisUsed++,
P0, P1, P2, UV0, UV1, UV2, Color, Color, Color);
@ -130,7 +132,7 @@ DrawLEDsInBufferRangeJob (s32 ThreadID, void* JobData)
GSMetaTag(panel_render);
GSMetaTag(panel_type_sculpture_view);
internal void
SculptureView_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context, mouse_state Mouse)
SculptureView_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context)
{
DEBUG_TRACK_SCOPE(RenderSculpture);
@ -145,9 +147,7 @@ SculptureView_Render(panel Panel, rect PanelBounds, render_command_buffer* Rende
PushRenderPerspective(RenderBuffer, PanelBounds.Min.x, PanelBounds.Min.y, PanelWidth, PanelHeight, State->Camera);
// TODO(Peter): Pretty sure this isn't working right now
m44 FaceCameraMatrix = GetLookAtMatrix(v4{0, 0, 0, 1}, V4(State->Camera.Position, 1));
FaceCameraMatrix = FaceCameraMatrix;
u32 MaxLEDsPerJob = 2048;
render_quad_batch_constructor RenderLEDsBatch = PushRenderQuad3DBatch(RenderBuffer, State->LedSystem.LedsCountTotal);
@ -166,13 +166,19 @@ SculptureView_Render(panel Panel, rect PanelBounds, render_command_buffer* Rende
JobData->StartIndex = Job * MaxLEDsPerJob;
JobData->OnePastLastIndex = GSMin(JobData->StartIndex + MaxLEDsPerJob, LedBuffer->LedCount);
JobData->Batch = &RenderLEDsBatch;
JobData->FaceCameraMatrix;
//JobData->FaceCameraMatrix = FaceCameraMatrix;
JobData->ModelViewMatrix = ModelViewMatrix;
JobData->LEDHalfWidth = LEDHalfWidth;
JobData->CameraPosition = V4(State->Camera.Position, 1);
Context.GeneralWorkQueue->PushWorkOnQueue(Context.GeneralWorkQueue, DrawLEDsInBufferRangeJob, JobData, "Sculpture Draw LEDS");
}
}
Context.GeneralWorkQueue->DoQueueWorkUntilDone(Context.GeneralWorkQueue, 0);
}

View File

@ -19,30 +19,33 @@ PLATFORM_READ_ENTIRE_FILE(Win32ReadEntireFile)
if (FileHandle != INVALID_HANDLE_VALUE)
{
DWORD FileSize = GetFileSize(FileHandle, NULL);
Result.Base = (u8*)VirtualAlloc(NULL, FileSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (Result.Base)
Result.Data.Base = (u8*)VirtualAlloc(NULL, FileSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (Result.Data.Base)
{
Result.Size = FileSize;
Result.Data.Size = FileSize;
s32 BytesRead = 0;
if (ReadFile(FileHandle, (LPVOID)Result.Base, FileSize, (LPDWORD)(&BytesRead), NULL))
if (ReadFile(FileHandle, (LPVOID)Result.Data.Base, FileSize, (LPDWORD)(&BytesRead), NULL))
{
}
else
{
u32 Error = GetLastError();
// TODO(Peter): :ErrorLogging
Result.Size = 0;
VirtualFree(Result.Data.Base, 0, MEM_RELEASE);
Result.Data.Size = 0;
Result.Error = PlatformMemory_UnknownError;
}
}
else
{
Result.Error = PlatformMemory_UnknownError;
}
CloseHandle(FileHandle);
}
else
{
Result.Error = PlatformMemory_FileNotFound;
// TODO(Peter): :ErrorLogging
}
return Result;
@ -138,13 +141,5 @@ PLATFORM_GET_FILE_PATH(Win32SystemDialogueOpenFile)
return Result;
}
internal directory_listing
EnumerateDirectory(char* Path, memory_arena* Storage)
{
directory_listing Result = {};
// TODO(Peter):
return Result;
}
#define WIN32_FOLDHAUS_FILEIO_H
#endif // WIN32_FOLDHAUS_FILEIO_H

View File

@ -75,6 +75,18 @@ union v4
float a;
};
struct
{
v2 xy;
v2 yz;
};
struct
{
v3 xyz;
float z;
};
float E[4];
};
@ -1271,11 +1283,10 @@ GetLookAtMatrix (v4 Position, v4 Target)
v4 Up = Normalize(Cross(Forward, Right));
m44 RotationMatrix = M44(
Right.x, Up.x, Forward.x, 0,
Right.y, Up.y, Forward.y, 0,
Right.z, Up.z, Forward.z, 0,
Right.x, Right.y, Right.z, 0,
Up.x, Up.y, Up.z, 0,
Forward.x, Forward.y, Forward.z, 0,
0, 0, 0, 1);
return RotationMatrix;
}