diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 235 |
1 files changed, 158 insertions, 77 deletions
@@ -33,11 +33,13 @@ #define STBI_FAILURE_USERMSG #include "lib/stb_image.h" + #include "defines.h" #include "my_math.h" #include "structs.h" #include "memory.h" +#include "stable_diffusion.h" #include "main.h" #include "debug.h" @@ -57,7 +59,7 @@ static uint64 BitmapBlockSize; static instruction_mode InstructionMode = instruction_mode_scalar; static uint32 RandomGlobalIncrement = 0; -// render_entry Entries[256]; +#include "lib/base64.c" #include "memory.cpp" #include "undo.cpp" @@ -67,6 +69,7 @@ static uint32 RandomGlobalIncrement = 0; #endif #include "createcalls.cpp" // #include "ffmpeg_backend.cpp" +#include "stable_diffusion.cpp" #include "my_imgui_widgets.cpp" #include "prenderer.cpp" #include "gl_calls.cpp" @@ -136,6 +139,16 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, Interact_Transform_Begin(File, Memory, State, io.MousePos, Sorted.CompArray, Sorted.LayerArray); } + bool32 mod_key = io.ConfigMacOSXBehaviors ? io.KeySuper : io.KeyCtrl; + if (mod_key) { + if (ImGui::IsKeyPressed(ImGuiKey_C)) { + Clipboard_Store(File, State, Memory, Sorted.PropertyInfo, Sorted.PropertyArray); + } + if (ImGui::IsKeyPressed(ImGuiKey_V)) { + Clipboard_Paste(File, State, Memory, Sorted.LayerArray); + } + } + ImGui::DockSpaceOverViewport(); if (Debug.ToggleWindow) { @@ -146,58 +159,90 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, if (State->Initializing == 3) { Source_UICreateButton(File, State, Memory, Sorted.CompArray, Sorted.LayerArray); - block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 0); + /* + block_layer *Layera = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 2); + Layera->x.IsToggled = true; + Layera->y.IsToggled = true; + block_layer *Layerb = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 1); + Layerb->x.IsToggled = true; + Layerb->y.IsToggled = true; + block_layer *Layerc = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 0); + Layerc->x.IsToggled = true; + Layerc->y.IsToggled = true; + */ + /* + Layer_Select(Memory, State, 0); + Layer_Select(Memory, State, 1); + Layer_Select(Memory, State, 2); + } + if (State->Initializing == 2) { + block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, File->PrincipalCompIndex); + Precomp_UICreateButton(File, State, Memory, MainComp, *Sorted.CompArray, Sorted.LayerArray); + Layer_DeselectAll(Memory, State, File->Layer_Count); + */ + // block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 0); + Layer_Select(Memory, State, 0); + /* History_Entry_Commit(Memory, "Add keyframe"); property_channel *Property = &Layer->x; { - bezier_point Point = { 1, {0, 800, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + bezier_point Point = { 1, {1, 0, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; Bezier_Add(Memory, Property, Point); } { - bezier_point Point = { 1, {20, 300, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + bezier_point Point = { 1, {10, 300, -3, 0, 3, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; Bezier_Add(Memory, Property, Point); } { - bezier_point Point = { 1, {10, 200, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + bezier_point Point = { 1, {20, 300, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; Bezier_Add(Memory, Property, Point); } + Property = &Layer->y; { - bezier_point Point = { 1, {15, 200, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + bezier_point Point = { 1, {10, 50, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; Bezier_Add(Memory, Property, Point); } - History_Entry_End(Memory); - - /* - History_Entry_Commit(Memory, "Add keyframe"); - Property = &Layer->y; { - bezier_point Point = { 1, {0, 400, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + bezier_point Point = { 1, {0, -800, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; Bezier_Add(Memory, Property, Point); } { bezier_point Point = { 1, {20, 400, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; Bezier_Add(Memory, Property, Point); } + Property = &Layer->rotation; + { + bezier_point Point = { 1, {0, 0, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + Bezier_Add(Memory, Property, Point); + } + { + bezier_point Point = { 1, {20, -360, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + Bezier_Add(Memory, Property, Point); + } + { + bezier_point Point = { 1, {40, 360, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + Bezier_Add(Memory, Property, Point); + } Property = &Layer->opacity; { bezier_point Point = { 1, {0, 1, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; Bezier_Add(Memory, Property, Point); } { - bezier_point Point = { 1, {20, 0, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; + bezier_point Point = { 1, {35, 0, -5, 0, 5, 0}, interpolation_type_bezier, 0, {0, 0, 0}, 0 }; Bezier_Add(Memory, Property, Point); } - */ - History_Entry_End(Memory); + */ } ImGui_Viewport(File, State, UI, Memory, io, textureID, Sorted.CompArray, Sorted.LayerArray); - ImGui_Timeline(File, State, Memory, UI, io, Sorted.CompArray, Sorted.LayerArray, Sorted.PropertyArray); + ImGui_Timeline(File, State, Memory, UI, io, Sorted.CompArray, Sorted.LayerArray, Sorted.PropertyInfo, Sorted.PropertyArray); ImGui_File(File, State, Memory, io, Sorted.CompArray, Sorted.LayerArray); ImGui_PropertiesPanel(File, State, UI, Memory, io); ImGui_ColorPanel(File, State, UI, Memory, io); + ImGui_StableDiffusion(File, State, UI, Memory, io); ImGui_Menu(File, State, UI, Memory, io); File_Sort_Pop(Memory, Sorted.Layer_SortSize, Sorted.Property_SortSize); @@ -209,11 +254,26 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, ImGui::EndFrame(); } +static void +Render_Main(void *Data, void *OutputBuffer, render_type RenderType, rectangle RenderRegion) +{ + bool32 IsRendering = true; + Renderer_Start(Data, OutputBuffer, RenderType, RenderRegion); + while (IsRendering) { + // SDL_Delay(1); + // Main_InputTest(File, State, &Memory, &UI); + Renderer_Check(&IsRendering, RenderType); + // TODO(fox): Make interruptable if the render time gets too long. + } +} + static void * -Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io, sorted_comp_info *SortedCompArray, sorted_layer *SortedLayerArray, uint16 *SortedPropertyArray, uint32 CompIndex) +Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io, + sorted_comp_info *SortedCompArray, sorted_layer *SortedLayerArray, + sorted_property_info *SortedPropertyInfo, uint16 *SortedPropertyArray, uint32 CompIndex, int32 Frame_Current) { block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, CompIndex); - cache_entry *Entry_Main = Memory_Cache_Search(State, Memory, cache_entry_type_comp, CompIndex, State->Frame_Current); + cache_entry *Entry_Main = Memory_Cache_Search(State, Memory, cache_entry_type_comp, CompIndex, 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); @@ -230,16 +290,69 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io sorted_layer SortEntry = SortedLayerInfo[i]; uint32 Index_Physical = SortEntry.Block_Layer_Index; block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical); - if (Layer->Frame_Start <= State->Frame_Current && - Layer->Frame_End > State->Frame_Current && Layer->IsVisible) + if (Layer->Frame_Start <= Frame_Current && + Layer->Frame_End > Frame_Current && Layer->IsVisible) { + int32 Offset = (State->Interact_Active == interact_type_keyframe_move) ? (int32)State->Interact_Offset[0] : 0; + for (int h = 0; h < AmountOf(Layer->Property); h++) { + property_channel *Property = &Layer->Property[h]; + sorted_property_info *InfoLocation = SortedPropertyInfo + (Index_Physical * 7) + h; + uint16 *ArrayLocation = SortedPropertyArray + (Index_Physical * 7 * MAX_KEYFRAMES_PER_BLOCK) + (h * MAX_KEYFRAMES_PER_BLOCK); + if (Property->Block_Bezier_Count) { + real32 MinY, MaxY; + Property_MinMax_Y(Memory, State, Property, InfoLocation, &MinY, &MaxY); + real32 Y_Increment = 1 / (MaxY - MinY); + v2 FirstPointPos[3]; + bezier_point *FirstPointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[0]); + Bezier_EvaluateValue(State, FirstPointAddress, FirstPointPos); + v2 LastPointPos[3]; + bezier_point *LastPointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[Property->Keyframe_Count - 1]); + Bezier_EvaluateValue(State, LastPointAddress, LastPointPos); + if (FirstPointPos[0].x >= Frame_Current) { + Property->CurrentValue = FirstPointPos[0].y; + } else if (LastPointPos[0].x <= Frame_Current) { + Property->CurrentValue = LastPointPos[0].y; + } else { + int KeyframeIndex = 0; + for (;;) { + v2 PointPos[3]; + bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[KeyframeIndex + 1]); + Bezier_EvaluateValue(State, PointAddress, PointPos, 1, Y_Increment); + if (PointPos[0].x >= Frame_Current) + break; + KeyframeIndex++; + } + v2 PointPos[3]; + bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[KeyframeIndex]); + Bezier_EvaluateValue(State, PointAddress, PointPos, 1, Y_Increment); + v2 NextPointPos[3]; + bezier_point *NextPointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[KeyframeIndex + 1]); + Bezier_EvaluateValue(State, NextPointAddress, NextPointPos, 1, Y_Increment); + if (PointAddress->Type == interpolation_type_hold) { + Property->CurrentValue = PointPos[0].y; + } else if (PointAddress->Type == interpolation_type_linear && NextPointAddress->Type == interpolation_type_linear) { + real32 Ratio = (Frame_Current - PointPos[0].x) / (NextPointPos[0].x - PointPos[0].x); + Property->CurrentValue = PointPos[0].y + ((NextPointPos[0].y - PointPos[0].y) * Ratio); + } else { + Property->CurrentValue = Bezier_SolveYForX(PointPos[0], PointPos[0] + PointPos[2], NextPointPos[0] + NextPointPos[1], NextPointPos[0], Frame_Current); + } + } + } + } + layer_bitmap_state *BitmapState = &State->Render.Bitmap[Index_Physical]; void *BitmapAddress = NULL; if (!Layer->IsPrecomp) { block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); if (Source->Type == source_type_principal) { - BitmapAddress = Memory_Block_AddressAtIndex(Memory, F_PrincipalBitmaps, Source->Bitmap_Index); + if (State->Interact_Active == interact_type_brush && State->Brush.LayerToPaint_Index == Index_Physical) { + // Assert(0); + // Render_Main((void *)T, , RenderRegion); + BitmapAddress = Memory_Block_AddressAtIndex(Memory, F_PrincipalBitmaps, Source->Bitmap_Index); + } else { + 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) { @@ -266,13 +379,8 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io } else { block_composition *Precomp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, Layer->Block_Source_Index); - 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, SortedPropertyArray, Layer->Block_Source_Index); - Entry->CycleTime = GetTime() - Src_TimeStart; - // } - BitmapAddress = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry->Block_StartIndex); + BitmapAddress = Render_Comp(File, State, Memory, io, SortedCompArray, SortedLayerArray, + SortedPropertyInfo, SortedPropertyArray, Layer->Block_Source_Index, (int32)Layer->time.CurrentValue); } Assert(BitmapAddress); @@ -281,38 +389,6 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io // for (int a = 0; a < Layer->Block_Effect_Count; a++) { // } - int32 Offset = (State->Interact_Active == interact_type_keyframe_move) ? (int32)State->Interact_Offset[0] : 0; - for (int h = 0; h < AmountOf(Layer->Property); h++) { - property_channel *Property = &Layer->Property[h]; - uint16 *ArrayLocation = SortedPropertyArray + (i * 7 * MAX_KEYFRAMES_PER_BLOCK) + (h * MAX_KEYFRAMES_PER_BLOCK); - if (Property->Block_Bezier_Count) { - v2 Min, Max; - Property_MinMax(Memory, State, Property, ArrayLocation, &Min, &Max); - if (Min.x >= State->Frame_Current) { - Property->CurrentValue = Min.y; - } else if (Max.x <= State->Frame_Current) { - Property->CurrentValue = Max.y; - } else { - int KeyframeIndex = 0; - for (;;) { - v2 PointPos[3]; - bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[KeyframeIndex + 1]); - Bezier_EvaluateValue(State, PointAddress, PointPos); - if (PointPos[0].x >= State->Frame_Current) - break; - KeyframeIndex++; - } - v2 PointPos[3]; - bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[KeyframeIndex]); - Bezier_EvaluateValue(State, PointAddress, PointPos); - v2 NextPointPos[3]; - bezier_point *NextPointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[KeyframeIndex + 1]); - Bezier_EvaluateValue(State, NextPointAddress, NextPointPos); - Property->CurrentValue = Bezier_SolveYForX(PointPos[0], PointPos[0] + PointPos[2], NextPointPos[0] + NextPointPos[1], NextPointPos[0], State->Frame_Current); - } - } - } - /* for (int h = 0; h < AmountOf(Layer->Property); h++) { property_channel *Property = &Layer->Property[h]; @@ -326,13 +402,7 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io T.SourceBuffer = BitmapAddress; rectangle RenderRegion = {0, 0, Comp->Width, Comp->Height}; - bool32 IsRendering = true; - Renderer_Start((void *)&T, CompBuffer, RenderRegion); - while (IsRendering) { - SDL_Delay(1); - Renderer_Check(&IsRendering); - // TODO(fox): Make interruptable if the render time gets too long. - } + Render_Main((void *)&T, CompBuffer, render_type_main, RenderRegion); } } Entry_Main->CycleTime = GetTime() - Comp_TimeStart; @@ -349,7 +419,8 @@ Main_Renderer(project_data *File, project_state *State, memory *Memory, SDL_Wind sorted_file Sorted = File_Sort_Push(File, State, Memory); - void *MainCompBuffer = Render_Comp(File, State, Memory, io, Sorted.CompArray, Sorted.LayerArray, Sorted.PropertyArray, File->PrincipalCompIndex); + void *MainCompBuffer = Render_Comp(File, State, Memory, io, Sorted.CompArray, Sorted.LayerArray, + Sorted.PropertyInfo, Sorted.PropertyArray, File->PrincipalCompIndex, State->Frame_Current); File_Sort_Pop(Memory, Sorted.Layer_SortSize, Sorted.Property_SortSize); @@ -402,7 +473,7 @@ int main(int argc, char *argv[]) { 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"); + Memory_InitTable(&GlobalMemory, &Memory, (uint64)50 * 1024 * 1024, B_CachedBitmaps, "Cached bitmap buffer"); #if ARM @@ -416,16 +487,26 @@ int main(int argc, char *argv[]) { } #endif - - project_state *State = (project_state *)Memory.Slot[P_MiscCache].Address; - *State = {}; + project_state State_ = {}; + project_state *State = &State_; project_data *File = (project_data *)Memory_Block_AllocateAddress(&Memory, F_File); *File = {}; File->Occupied = 1; - State->Brush.PaintBuffer = Memory.Slot[B_ScratchSpace].Address; + // NOTE(fox): Right now I'm just gonna throw all dynamic allocs that can't + // be simplified to the push/pop model here; will worry about how to best + // use RAM later. + + State->Brush.PaintBuffer = (void *)((uint8 *)Memory.Slot[B_ScratchSpace].Address + Memory.ScratchPos); uint64 ScratchPaintSize = 2048*2048*4; Memory.ScratchPos += ScratchPaintSize; + State->Brush.TransientBitmap = (void *)((uint8 *)Memory.Slot[B_ScratchSpace].Address + Memory.ScratchPos); + ScratchPaintSize = 2048*2048*4; + Memory.ScratchPos += ScratchPaintSize; + + State->ClipboardBuffer = (void *)((uint8 *)Memory.Slot[B_ScratchSpace].Address + Memory.ScratchPos); + State->ClipboardSize = 1024*1024; + Memory.ScratchPos += State->ClipboardSize; ui UI = {}; UI.Test = ImDrawListSplitter(); @@ -438,8 +519,8 @@ int main(int argc, char *argv[]) { block_composition *MainComp = (block_composition *)Memory_Block_AllocateAddress(&Memory, F_Precomps); - MainComp->Width = 1024; - MainComp->Height = 512; + MainComp->Width = 1280; + MainComp->Height = 720; MainComp->FPS = 24; MainComp->BytesPerPixel = 4; MainComp->Frame_Count = 48; @@ -763,8 +844,8 @@ int main(int argc, char *argv[]) { GLuint textureID; glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D, textureID); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); |