diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 211 |
1 files changed, 126 insertions, 85 deletions
@@ -66,7 +66,7 @@ static uint32 RandomGlobalIncrement = 0; #include "threading.cpp" #endif #include "createcalls.cpp" -#include "ffmpeg_backend.cpp" +// #include "ffmpeg_backend.cpp" #include "my_imgui_widgets.cpp" #include "prenderer.cpp" #include "gl_calls.cpp" @@ -125,39 +125,36 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, UI->Warp_WantSetPos = false; } - ImGui::DockSpaceOverViewport(); - if (!io.WantCaptureKeyboard) ImGui_ProcessInputs(File, State, UI, Memory, io); -#if 0 - - ImGui_Viewport(File, &State, &UI, &Memory, CompBuffer, io, textureID); - - ImGui_File(&File, &State, &Memory, &UI, io); - - ImGui_EffectsPanel(&File, &State, &Memory, &UI, io); - - ImGui_PropertiesPanel(&File, &State, &UI, &Memory, io); - - // ImGui_Graph(&File, &State, &Memory, &UI, io); - -#if DEBUG - ImGui_DebugUndoTree(&File, &Memory); -#endif - -#endif + uint64 SortSize = (sizeof(sorted_comp_info) * File->Comp_Count) + (sizeof(sorted_layer) * File->Layer_Count); + void *SortedArray = Memory_PushScratch(Memory, SortSize); + Arbitrary_Zero((uint8 *)SortedArray, SortSize); + sorted_comp_info *SortedCompArray = (sorted_comp_info *)SortedArray; + sorted_layer *SortedLayerArray = (sorted_layer *)((uint8 *)SortedArray + (sizeof(sorted_comp_info) * File->Comp_Count)); + Layer_SortAll(File, State, Memory, SortedLayerArray, SortedCompArray, File->Layer_Count, File->Comp_Count); - ImGui_Viewport(File, State, UI, Memory, io, textureID); - ImGui_Timeline(File, State, Memory, UI, io); - ImGui_File(File, State, Memory, io); + ImGui::DockSpaceOverViewport(); if (Debug.ToggleWindow) { ImGui::ShowDemoWindow(); ImGui_DebugMemoryViewer(Memory, State); + ImGui_DebugUndoTree(Memory, State); } - // ImGui::ShowDemoWindow(); + // if (State->Initializing == 3) + // Source_UICreateButton(File, State, Memory, SortedCompArray, SortedLayerArray); + + + ImGui_Viewport(File, State, UI, Memory, io, textureID, SortedCompArray, SortedLayerArray); + ImGui_Timeline(File, State, Memory, UI, io, SortedCompArray, SortedLayerArray); + ImGui_File(File, State, Memory, io, SortedCompArray, SortedLayerArray); + ImGui_PropertiesPanel(File, State, UI, Memory, io); + ImGui_ColorPanel(File, State, UI, Memory, io); + ImGui_Menu(File, State, UI, Memory, io); + + Memory_PopScratch(Memory, SortSize); #if DEBUG Debug.Temp = {}; #endif @@ -165,20 +162,28 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, ImGui::EndFrame(); } +static layer_transforms +Layer_GetTransforms(block_layer *Layer) { + return { Layer->x.CurrentValue, Layer->y.CurrentValue, Layer->ax.CurrentValue, Layer->ay.CurrentValue, Layer->rotation.CurrentValue, Layer->scale.CurrentValue }; +} + 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); + cache_entry *Entry_Main = Memory_Cache_Search(State, Memory, cache_entry_type_comp, CompIndex, State->Frame_Current); void *CompBuffer = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry_Main->Block_StartIndex); + uint64 Size = Comp->Width * Comp->Height * Comp->BytesPerPixel; + Arbitrary_Zero((uint8 *)CompBuffer, Size); - if (Entry_Main->IsCached) - return CompBuffer; + // 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++) { sorted_layer SortEntry = SortedLayerInfo[i]; uint32 Index_Physical = SortEntry.Block_Layer_Index; @@ -190,33 +195,36 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io void *BitmapAddress = NULL; if (!Layer->IsPrecomp) { block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); - cache_entry *Entry = Memory_Cache_Search(State, Memory, State->Render.Entry, cache_entry_type_source, Layer->Block_Source_Index, 0); - - Assert(Source->Type == source_type_image); - if (!Entry->IsCached) { - uint64 Src_TimeStart = GetTime(); - block_string *Name = (block_string *)Memory_Block_AddressAtIndex(Memory, F_Strings, Source->Path_String_Index); - int w = 0, h = 0; - void *temp = stbi_load(Name->Char, &w, &h, NULL, 4); - Source->Width = w; - Source->Height = h; - Source->BytesPerPixel = 4; - uint64 Size = Source->Width * Source->Height * Source->BytesPerPixel; - void *Source_Address = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry->Block_StartIndex); - Arbitrary_WriteInto((uint8 *)temp, (uint8 *)Source_Address, Size); - stbi_image_free(temp); - BitmapState->ToUpdate = false; - BitmapState->CurrentFrame = 0; - 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; + if (Source->Type == source_type_principal) { + BitmapAddress = Memory_Block_AddressAtIndex(Memory, F_PrincipalBitmaps, Source->Bitmap_Index); + } else { + cache_entry *Entry = Memory_Cache_Search(State, Memory, cache_entry_type_source, Layer->Block_Source_Index, 0); + if (!Entry->IsCached) { + uint64 Src_TimeStart = GetTime(); + block_string *Name = (block_string *)Memory_Block_AddressAtIndex(Memory, F_Strings, Source->Path_String_Index); + int w = 0, h = 0; + void *temp = stbi_load(Name->Char, &w, &h, NULL, 4); + Source->Width = w; + Source->Height = h; + Source->BytesPerPixel = 4; + uint64 Size = Source->Width * Source->Height * Source->BytesPerPixel; + void *Source_Address = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry->Block_StartIndex); + Arbitrary_WriteInto((uint8 *)temp, (uint8 *)Source_Address, Size); + stbi_image_free(temp); + BitmapState->ToUpdate = false; + BitmapState->CurrentFrame = 0; + Entry->CycleTime = GetTime() - Src_TimeStart; + Layer->x.CurrentValue = Comp->Width/2; + Layer->y.CurrentValue = Comp->Height/2; + Entry->IsCached = true; + } + BitmapAddress = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry->Block_StartIndex); } - BitmapAddress = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry->Block_StartIndex); + } else { block_composition *Precomp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, Layer->Block_Source_Index); - cache_entry *Entry = Memory_Cache_Search(State, Memory, State->Render.Entry, cache_entry_type_comp, Layer->Block_Source_Index, State->Frame_Current); + cache_entry *Entry = Memory_Cache_Search(State, Memory, cache_entry_type_comp, Layer->Block_Source_Index, State->Frame_Current); if (!Entry->IsCached) { uint64 Src_TimeStart = GetTime(); Render_Comp(File, State, Memory, io, SortedCompArray, SortedLayerArray, Layer->Block_Source_Index); @@ -307,7 +315,7 @@ Main_Renderer(project_data *File, project_state *State, memory *Memory, SDL_Wind Arbitrary_Zero((uint8 *)SortedArray, SortSize); sorted_comp_info *SortedCompArray = (sorted_comp_info *)SortedArray; 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); + Layer_SortAll(File, State, Memory, SortedLayerArray, SortedCompArray, File->Layer_Count, File->Comp_Count); void *MainCompBuffer = Render_Comp(File, State, Memory, io, SortedCompArray, SortedLayerArray, File->PrincipalCompIndex); @@ -343,6 +351,9 @@ int main(int argc, char *argv[]) { 0); #endif + // 1 meg per block + BitmapBlockSize = 1024 * 1024; + memory Memory = {}; Memory_InitTable(&GlobalMemory, &Memory, 1 * 1024 * 1024, P_AVInfo, "Image/video headers"); @@ -355,10 +366,12 @@ int main(int argc, char *argv[]) { Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Sources, "Sources", sizeof(block_source)); Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Bezier, "Bezier paths (keyframes, masks)", sizeof(block_bezier)); Memory_InitTable(&GlobalMemory, &Memory, 10 * 1024 * 1024, F_Strings, "Strings", sizeof(block_string)); + Memory_InitTable(&GlobalMemory, &Memory, (uint64)50 * 1024 * 1024, F_PrincipalBitmaps, "Principal bitmap data", BitmapBlockSize); Memory_InitTable(&GlobalMemory, &Memory, (uint64)64 * 1024 * 1024, B_ScratchSpace, "Scratch"); Memory_InitTable(&GlobalMemory, &Memory, (uint64)200 * 1024 * 1024, B_CachedBitmaps, "Cached bitmap buffer"); + #if ARM InstructionMode = instruction_mode_neon; #else @@ -370,21 +383,30 @@ int main(int argc, char *argv[]) { } #endif + project_state *State = (project_state *)Memory.Slot[P_MiscCache].Address; *State = {}; project_data *File = (project_data *)Memory_Block_AllocateAddress(&Memory, F_File); *File = {}; File->Occupied = 1; + State->Brush.PaintBuffer = Memory.Slot[B_ScratchSpace].Address; + uint64 ScratchPaintSize = 2048*2048*4; + Memory.ScratchPos += ScratchPaintSize; + ui UI = {}; UI.Test = ImDrawListSplitter(); + // int ToolCount = (int)tool_count; + // for (int i = 0; i < ToolCount; i++) { + // glBindTexture(GL_TEXTURE_2D, textureID); + // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, MainComp->Width, MainComp->Height, 0, GL_RGBA, ByteFlag2, MainCompBuffer); + // } + block_composition *MainComp = (block_composition *)Memory_Block_AllocateAddress(&Memory, F_Precomps); - // MainComp->Width = 3840; - // MainComp->Height = 2160; - MainComp->Width = 1280; - MainComp->Height = 720; + MainComp->Width = 1024; + MainComp->Height = 512; MainComp->FPS = 24; MainComp->BytesPerPixel = 4; MainComp->Frame_Count = 48; @@ -392,6 +414,9 @@ int main(int argc, char *argv[]) { MainComp->Occupied = 1; MainComp->Name_String_Index = String_AddToFile(&Memory, "Main comp"); + File->Comp_Count = 1; + + /* block_composition *Comp2 = (block_composition *)Memory_Block_AllocateAddress(&Memory, F_Precomps); Comp2->Width = 500; Comp2->Height = 500; @@ -401,16 +426,16 @@ int main(int argc, char *argv[]) { Comp2->Frame_End = 48; Comp2->Occupied = 1; Comp2->Name_String_Index = String_AddToFile(&Memory, "Another comp"); + */ - File->Comp_Count = 2; - - // 1 MB for 4, 2 MB for 8 - BitmapBlockSize = (MainComp->BytesPerPixel / 4) * 1024 * 1024; + File->Comp_Count = 1; { uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/a.jpg"); block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, 0); + Source->IsSelected = true; + /* { Layer_CreateFromSource(File, State, &Memory, SourceIndex, MainComp->Frame_End); block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(&Memory, F_Layers, File->Layer_Count - 1); @@ -480,30 +505,39 @@ int main(int argc, char *argv[]) { Bezier3->Point[1].Occupied = true; Bezier3->Point[2].Occupied = true; } - // { - // Layer_CreateFromSource(File, State, &Memory, SourceIndex, MainComp->Frame_End); - // block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(&Memory, F_Layers, File->Layer_Count - 1); - // Layer->Vertical_Offset = 1; - // Layer->Col[0] = 1; - // Layer->Col[1] = 0; - // Layer->Col[2] = 0; - // Layer->Block_Composition_Index = 1; - // } + */ + /* + { + Layer_CreateFromSource(File, State, &Memory, SourceIndex, MainComp->Frame_End); + block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(&Memory, F_Layers, File->Layer_Count - 1); + Layer->Vertical_Offset = 2; + Layer->IsSelected = true; + Layer->ColIndex = 2; + Layer->Block_Composition_Index = 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); + Layer->Vertical_Offset = 5; + Layer->ColIndex = 0; + Layer->Block_Composition_Index = 0; + } + */ } { 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 + Source->IsSelected = true; + /* { Layer_CreateFromSource(File, State, &Memory, SourceIndex, MainComp->Frame_End); block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(&Memory, F_Layers, File->Layer_Count - 1); - Layer->Vertical_Offset = 5; - Layer->Col[0] = 0; - Layer->Col[1] = 0; - Layer->Col[2] = 1; - Layer->Block_Composition_Index = 0; Layer->IsSelected = true; + Layer->Vertical_Offset = 3; + Layer->ColIndex = 1; + Layer->Block_Composition_Index = 0; + // Layer->IsSelected = true; property_channel *Property = &Layer->x; Property->Block_Bezier_Index[0] = Memory_Block_AllocateNew(&Memory, F_Bezier); @@ -545,21 +579,22 @@ int main(int argc, char *argv[]) { Bezier2->Point[0].Occupied = true; Bezier2->Point[1].Occupied = true; } -#endif + */ } { uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/c.jpg"); block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, 2); - // { - // Layer_CreateFromSource(File, State, &Memory, SourceIndex, MainComp->Frame_End); - // block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(&Memory, F_Layers, File->Layer_Count - 1); - // Layer->Vertical_Offset = 0; - // Layer->Col[0] = 0; - // Layer->Col[1] = 1; - // Layer->Col[2] = 0; - // Layer->Block_Composition_Index = 1; - // } + Source->IsSelected = true; + /* + { + Layer_CreateFromSource(File, State, &Memory, SourceIndex, MainComp->Frame_End); + block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(&Memory, F_Layers, File->Layer_Count - 1); + Layer->Vertical_Offset = 1; + Layer->ColIndex = 3; + Layer->Block_Composition_Index = 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); @@ -600,7 +635,6 @@ int main(int argc, char *argv[]) { SDL_Init(SDL_INIT_VIDEO); - Semaphore = SDL_CreateSemaphore(0); #if THREADED @@ -703,8 +737,15 @@ int main(int argc, char *argv[]) { ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + Brush_CalcBitmapAlphaFromSize(&Memory, &State->Brush, 4); + State_BindBrushTexture(&Memory, &State->Brush, 4); + + while (State->IsRunning) { + // State->Interact_Active = interact_type_layer_move; + // State->Interact_Offset[1] = -3.0f; + Main_InputTest(File, State, &Memory, &UI, window, textureID); if (State->IsPlaying) { |