diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 101 |
1 files changed, 53 insertions, 48 deletions
@@ -128,7 +128,7 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, ImGui::DockSpaceOverViewport(); if (!io.WantCaptureKeyboard) - ImGui_ProcessInputs(File, State, Memory, io); + ImGui_ProcessInputs(File, State, UI, Memory, io); #if 0 @@ -154,7 +154,7 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, if (Debug.ToggleWindow) { ImGui::ShowDemoWindow(); - ImGui_DebugMemoryViewer(State); + ImGui_DebugMemoryViewer(Memory, State); } // ImGui::ShowDemoWindow(); @@ -165,12 +165,18 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, ImGui::EndFrame(); } -static void +static void * Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io, sorted_comp_info *SortedCompArray, sorted_layer *SortedLayerArray, uint32 CompIndex) { block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, CompIndex); cache_entry *Entry_Main = Memory_Cache_Search(State, Memory, State->Render.Entry, cache_entry_type_comp, CompIndex, State->Frame_Current); void *CompBuffer = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry_Main->Block_StartIndex); + + if (Entry_Main->IsCached) + return CompBuffer; + + uint64 Comp_TimeStart = GetTime(); + sorted_comp_info *SortedCompInfo = &SortedCompArray[CompIndex]; sorted_layer *SortedLayerInfo = Layer_GetSortedArray(SortedLayerArray, SortedCompArray, CompIndex); for (int i = 0; i < SortedCompInfo->LayerCount; i++) { @@ -205,6 +211,7 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io Entry->CycleTime = GetTime() - Src_TimeStart; Layer->x.CurrentValue = (Layer->Block_Source_Index == 0) ? 200 : Comp->Width/2; Layer->y.CurrentValue = Comp->Height/2; + Entry->IsCached = true; } BitmapAddress = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry->Block_StartIndex); } else { @@ -228,9 +235,16 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io property_channel *Property = &Layer->x; - if (Property->Keyframe_Count) { + if (Property->Block_Bezier_Count) { bezier_point *FirstPoint = Bezier_Lookup(Memory, Property, 0); - bezier_point *LastPoint = Bezier_Lookup(Memory, Property, Property->Keyframe_Count - 1); + int k = 0; + for (;;) { + bezier_point *Point = Bezier_Lookup(Memory, Property, k); + if (!Point->Occupied) + break; + k++; + } + bezier_point *LastPoint = Bezier_Lookup(Memory, Property, k - 1); if (FirstPoint->Pos[0].x >= State->Frame_Current) { Property->CurrentValue = FirstPoint->Pos[0].y; } else if (LastPoint->Pos[0].x <= State->Frame_Current) { @@ -245,7 +259,11 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io } bezier_point *Point = Bezier_Lookup(Memory, Property, KeyframeIndex); bezier_point *NextPoint = Bezier_Lookup(Memory, Property, KeyframeIndex + 1); - Property->CurrentValue = Bezier_SolveYForX(Point->Pos[0], Point->Pos[0] + Point->Pos[2], NextPoint->Pos[0] + NextPoint->Pos[1], NextPoint->Pos[0], State->Frame_Current); + v2 Pos_New[3] = { Point->Pos[0], Point->Pos[1], Point->Pos[2] }; + v2 NextPos_New[3] = { NextPoint->Pos[0], NextPoint->Pos[1], NextPoint->Pos[2] }; + Keyframe_Interact_Evaluate(Memory, State, Point->IsSelected, Point->Pos, Pos_New); + Keyframe_Interact_Evaluate(Memory, State, NextPoint->IsSelected, NextPoint->Pos, NextPos_New); + Property->CurrentValue = Bezier_SolveYForX(Pos_New[0], Pos_New[0] + Pos_New[2], NextPos_New[0] + NextPos_New[1], NextPos_New[0], State->Frame_Current); } } @@ -271,6 +289,9 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io } } } + Entry_Main->CycleTime = GetTime() - Comp_TimeStart; + Entry_Main->IsCached = true; + return CompBuffer; } static void @@ -278,11 +299,7 @@ Main_Renderer(project_data *File, project_state *State, memory *Memory, SDL_Wind { State->UpdateFrame = false; - uint64 Comp_TimeStart = GetTime(); - block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, File->PrincipalCompIndex); - cache_entry *Entry_Main = Memory_Cache_Search(State, Memory, State->Render.Entry, cache_entry_type_comp, File->PrincipalCompIndex, State->Frame_Current); - void *MainCompBuffer = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry_Main->Block_StartIndex); // NOTE(fox): All layers are given a slot here uint64 SortSize = (sizeof(sorted_comp_info) * File->Comp_Count) + (sizeof(sorted_layer) * File->Layer_Count); @@ -292,19 +309,19 @@ Main_Renderer(project_data *File, project_state *State, memory *Memory, SDL_Wind sorted_layer *SortedLayerArray = (sorted_layer *)((uint8 *)SortedArray + (sizeof(sorted_comp_info) * File->Comp_Count)); Layer_SortAll(Memory, SortedLayerArray, SortedCompArray, File->Layer_Count, File->Comp_Count); - Render_Comp(File, State, Memory, io, SortedCompArray, SortedLayerArray, File->PrincipalCompIndex); + void *MainCompBuffer = Render_Comp(File, State, Memory, io, SortedCompArray, SortedLayerArray, File->PrincipalCompIndex); Memory_PopScratch(Memory, SortSize); glBindTexture(GL_TEXTURE_2D, textureID); int ByteFlag2 = (MainComp->BytesPerPixel == 4) ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT; - if (!Entry_Main->CycleTime) + if (State->FirstFrame) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, MainComp->Width, MainComp->Height, 0, GL_RGBA, ByteFlag2, MainCompBuffer); + State->FirstFrame = false; + } glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, MainComp->Width, MainComp->Height, GL_RGBA, ByteFlag2, MainCompBuffer); - Entry_Main->CycleTime = GetTime() - Comp_TimeStart; - // TODO(fox): garbage collect AV state! } @@ -340,7 +357,7 @@ int main(int argc, char *argv[]) { Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Strings, "Strings", sizeof(block_string)); Memory_InitTable(&GlobalMemory, &Memory, (uint64)64 * 1024 * 1024, B_ScratchSpace, "Scratch"); - Memory_InitTable(&GlobalMemory, &Memory, (uint64)50 * 1024 * 1024, B_CachedBitmaps, "Cached bitmap buffer"); + Memory_InitTable(&GlobalMemory, &Memory, (uint64)200 * 1024 * 1024, B_CachedBitmaps, "Cached bitmap buffer"); #if ARM InstructionMode = instruction_mode_neon; @@ -412,8 +429,8 @@ int main(int argc, char *argv[]) { Bezier->Occupied = 1; Bezier->Point[0].Pos[0] = V2(0, 0); - Bezier->Point[1].Pos[0] = V2(10, 50); - Bezier->Point[2].Pos[0] = V2(20, -50); + Bezier->Point[1].Pos[0] = V2(20, 50); + Bezier->Point[2].Pos[0] = V2(40, -50); Bezier->Point[0].Pos[1] = V2(-4, 0); Bezier->Point[1].Pos[1] = V2(-4, 0); Bezier->Point[2].Pos[1] = V2(-4, 0); @@ -423,8 +440,10 @@ int main(int argc, char *argv[]) { Bezier->Point[0].Type = interpolation_type_bezier; Bezier->Point[1].Type = interpolation_type_bezier; Bezier->Point[2].Type = interpolation_type_bezier; - Bezier->Point[1].IsSelected = true; - Property->Keyframe_Count = 3; + Bezier->Point[1].IsSelected = false; + Bezier->Point[0].Occupied = true; + Bezier->Point[1].Occupied = true; + Bezier->Point[2].Occupied = true; property_channel *Property2 = &Layer->opacity; Property2->Block_Bezier_Index[0] = Memory_Block_AllocateNew(&Memory, F_Bezier); @@ -435,7 +454,8 @@ int main(int argc, char *argv[]) { Bezier2->Point[0].Pos[0] = V2(0, 0); Bezier2->Point[1].Pos[0] = V2(20, 1); - Property2->Keyframe_Count = 2; + Bezier2->Point[0].Occupied = true; + Bezier2->Point[1].Occupied = true; property_channel *Property3 = &Layer->y; Property3->Block_Bezier_Index[0] = Memory_Block_AllocateNew(&Memory, F_Bezier); @@ -445,8 +465,8 @@ int main(int argc, char *argv[]) { Bezier3->Occupied = 1; Bezier3->Point[0].Pos[0] = V2(0, -20); - Bezier3->Point[1].Pos[0] = V2(10, 300); - Bezier3->Point[2].Pos[0] = V2(20, 100); + Bezier3->Point[1].Pos[0] = V2(20, 300); + Bezier3->Point[2].Pos[0] = V2(40, 100); Bezier3->Point[0].Pos[1] = V2(-4, 0); Bezier3->Point[1].Pos[1] = V2(-4, 0); Bezier3->Point[2].Pos[1] = V2(-4, 0); @@ -456,7 +476,9 @@ int main(int argc, char *argv[]) { Bezier3->Point[0].Type = interpolation_type_bezier; Bezier3->Point[1].Type = interpolation_type_bezier; Bezier3->Point[2].Type = interpolation_type_bezier; - Property3->Keyframe_Count = 3; + Bezier3->Point[0].Occupied = true; + Bezier3->Point[1].Occupied = true; + Bezier3->Point[2].Occupied = true; } // { // Layer_CreateFromSource(File, State, &Memory, SourceIndex, MainComp->Frame_End); @@ -472,6 +494,7 @@ int main(int argc, char *argv[]) { { uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/b.jpg"); block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, 1); +#if 0 { Layer_CreateFromSource(File, State, &Memory, SourceIndex, MainComp->Frame_End); block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(&Memory, F_Layers, File->Layer_Count - 1); @@ -505,7 +528,10 @@ int main(int argc, char *argv[]) { Bezier->Point[1].Type = interpolation_type_bezier; Bezier->Point[2].Type = interpolation_type_bezier; Bezier->Point[3].Type = interpolation_type_bezier; - Property->Keyframe_Count = 4; + Bezier->Point[0].Occupied = true; + Bezier->Point[1].Occupied = true; + Bezier->Point[2].Occupied = true; + Bezier->Point[3].Occupied = true; property_channel *Property2 = &Layer->opacity; Property2->Block_Bezier_Index[0] = Memory_Block_AllocateNew(&Memory, F_Bezier); @@ -516,31 +542,10 @@ int main(int argc, char *argv[]) { Bezier2->Point[0].Pos[0] = V2(25, 1); Bezier2->Point[1].Pos[0] = V2(40, 0); - Property2->Keyframe_Count = 2; - - /* - property_channel *Property3 = &Layer->y; - Property3->Block_Bezier_Index[0] = Memory_Block_AllocateNew(&Memory, F_Bezier); - Property3->Block_Bezier_Count = 1; - - block_bezier *Bezier3 = (block_bezier *)Memory_Block_AddressAtIndex(&Memory, F_Bezier, Property3->Block_Bezier_Index[0]); - Bezier3->Occupied = 1; - - Bezier3->Point[0].Pos[0] = V2(0, -20); - Bezier3->Point[1].Pos[0] = V2(10, 300); - Bezier3->Point[2].Pos[0] = V2(20, 100); - Bezier3->Point[0].Pos[1] = V2(-4, 0); - Bezier3->Point[1].Pos[1] = V2(-4, 0); - Bezier3->Point[2].Pos[1] = V2(-4, 0); - Bezier3->Point[0].Pos[2] = V2(4, 0); - Bezier3->Point[1].Pos[2] = V2(4, 0); - Bezier3->Point[2].Pos[2] = V2(4, 0); - Bezier3->Point[0].Type = interpolation_type_bezier; - Bezier3->Point[1].Type = interpolation_type_bezier; - Bezier3->Point[2].Type = interpolation_type_bezier; - Property3->Keyframe_Count = 3; - */ + Bezier2->Point[0].Occupied = true; + Bezier2->Point[1].Occupied = true; } +#endif } { |