From 17bee519ece8fc2bc356956841fed97286d24139 Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Thu, 24 Nov 2022 01:16:54 -0500 Subject: legwork --- main.cpp | 95 +++++++++++++++++++++++++++++----------------------------------- 1 file changed, 43 insertions(+), 52 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index ddf1560..950d548 100644 --- a/main.cpp +++ b/main.cpp @@ -184,13 +184,13 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, ImGui_DebugUndoTree(Memory, State); } +#if 0 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); Layer->Block_Effect_Index[0] = Effect_Init(State, Memory, 0, Layer->Block_Effect_Count); Layer->Block_Effect_Count = 1; } -#if 0 // Layera->x.IsToggled = true; // Layera->y.IsToggled = true; // block_layer *Layerb = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 1); @@ -388,33 +388,18 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io layer_bitmap_state *BitmapState = &State->Render.Bitmap[Index_Physical]; void *BitmapAddress = NULL; - void *SecondSourceBitmap = NULL; // If there are effects or we're in interact_type_brush, we need to redirect to another scratch bitmap. + void *RenderAddress = NULL; // result of masking, effects, and intermediate paint stroke int Width = 0, Height = 0, BytesPerPixel = 0; - uint64 ScratchActive = 0; + if (!Layer->IsPrecomp) { - block_source *Source; + block_source *Source = NULL; if ((State->PreviewSource != -1) && Layer->IsSelected) { Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, State->PreviewSource); } else { Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); } if (Source->Type == source_type_principal || Source->Type == source_type_principal_temp) { - if (State->Interact_Active == interact_type_brush && State->Brush.LayerToPaint_Index == Index_Physical) { - Assert(Source->Type == source_type_principal); - void *SourceBitmapAddress = Memory_Block_AddressAtIndex(Memory, F_PrincipalBitmaps, Source->Bitmap_Index, 0); - ScratchActive = Source->Width * Source->Height * Source->BytesPerPixel; - SecondSourceBitmap = Memory_PushScratch(Memory, ScratchActive); - Memory_Copy((uint8 *)SecondSourceBitmap, (uint8 *)SourceBitmapAddress, ScratchActive); - // TODO(fox): Do all these extra precomputes really make a difference in the renderer? - rectangle RenderRegion = { 0, 0, Source->Width, Source->Height }; - direct_info Info = { (real32)Source->Width, (real32)Source->Height, (real32)Source->BytesPerPixel, (real32)Source->Width * Source->BytesPerPixel, - Bitmap_ByteInfo(Source->BytesPerPixel), blend_normal, - RenderRegion, State->Brush.TransientBitmap}; - Render_Main((void *)&Info, SecondSourceBitmap, render_type_notransform, State->Brush.CacheBounds); - BitmapAddress = SecondSourceBitmap; - } else { - BitmapAddress = Memory_Block_AddressAtIndex(Memory, F_PrincipalBitmaps, Source->Bitmap_Index, 0); - } + BitmapAddress = Memory_Block_AddressAtIndex(Memory, F_PrincipalBitmaps, Source->Bitmap_Index, 0); } else { cache_entry *Entry = Memory_Cache_Search(State, Memory, cache_entry_type_source, Layer->Block_Source_Index, 0); if (!Entry->IsCached) { @@ -449,24 +434,24 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io Height = Precomp->Height; BytesPerPixel = Precomp->BytesPerPixel; } + Assert(BitmapAddress); - if (Layer->Block_Effect_Count && !SecondSourceBitmap) { - block_source *Source; - if ((State->PreviewSource != -1) && Layer->IsSelected) { - Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, State->PreviewSource); - } else { - Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); - } - void *SourceBitmapAddress = Memory_Block_AddressAtIndex(Memory, F_PrincipalBitmaps, Source->Bitmap_Index, 0); - ScratchActive = Source->Width * Source->Height * Source->BytesPerPixel; - SecondSourceBitmap = Memory_PushScratch(Memory, ScratchActive); - Memory_Copy((uint8 *)SecondSourceBitmap, (uint8 *)SourceBitmapAddress, ScratchActive); - BitmapAddress = SecondSourceBitmap; + uint64 ScratchSize = Width * Height * BytesPerPixel; + RenderAddress = Memory_PushScratch(Memory, ScratchSize); + // Memory_Copy((uint8 *)RenderAddress, (uint8 *)BitmapAddress, ScratchSize); + + if (State->Interact_Active == interact_type_brush && State->Brush.LayerToPaint_Index == Index_Physical) { + // TODO(fox): Do all these extra precomputes really make a difference in the renderer? + rectangle RenderRegion = { 0, 0, Width, Height }; + direct_info Info = { (real32)Width, (real32)Height, (real32)BytesPerPixel, (real32)Width * BytesPerPixel, + Bitmap_ByteInfo(BytesPerPixel), blend_normal, + RenderRegion, State->Brush.TransientBitmap}; + Render_Main((void *)&Info, RenderAddress, render_type_notransform, State->Brush.CacheBounds); + } else if (Layer->Block_Effect_Count || Layer->Block_Mask_Count) { + Layer_UpdateMasksEffects(State, Layer, Memory, RenderAddress, Width, Height, BytesPerPixel); } - Layer_UpdateMasksEffects(State, Layer, Memory, BitmapAddress, Width, Height, BytesPerPixel); - Assert(Width); Assert(Height); transform_info T = Transform_Calculate(State, Memory, File, Layer, Comp, Width, Height, BytesPerPixel); @@ -474,8 +459,7 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io rectangle RenderRegion = {0, 0, Comp->Width, Comp->Height}; Render_Main((void *)&T, CompBuffer, render_type_main, RenderRegion); - if (ScratchActive) - Memory_PopScratch(Memory, ScratchActive); + Memory_PopScratch(Memory, ScratchSize); } } Entry_Main->CycleTime = GetCPUTime() - Comp_TimeStart; @@ -545,11 +529,11 @@ int main(int argc, char *argv[]) { Memory_InitTable(&GlobalMemory, &Memory, 2 * 1024 * 1024, F_Properties, "Properties", sizeof(property_channel)); Memory_InitTable(&GlobalMemory, &Memory, 4 * 1024 * 1024, F_Bezier, "Bezier paths (keyframes, masks)", sizeof(block_bezier)); Memory_InitTable(&GlobalMemory, &Memory, 4 * 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)100 * 1024 * 1024, F_PrincipalBitmaps, "Principal bitmap data", BitmapBlockSize); Memory_InitTable(&GlobalMemory, &Memory, (uint64)5 * 1024 * 1024, B_Thumbnails, "Thumbnails"); 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 @@ -603,27 +587,25 @@ int main(int argc, char *argv[]) { 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; - } #if 0 - { - uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/hand/b.jpg"); - block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, 1); + const char *myb[] = { "../asset/hand/IMG_4239.jpg", "../asset/hand/IMG_4242.jpg", "../asset/hand/IMG_4243.jpg", + "../asset/hand/IMG_4244.jpg", "../asset/hand/IMG_4248.jpg", "../asset/hand/IMG_4249.jpg" }; + + for (int i = 0; i < 6; i++) { + uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)myb[i]); + block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, File->Source_Count - 1); Source->IsSelected = true; } - { - uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/hand/c.png"); - block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, 2); + uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/hand/a.png"); + block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, File->Source_Count - 1); Source->IsSelected = true; } + { - uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/hand/d.png"); - block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, 2); + uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/hand/c.png"); + block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, File->Source_Count - 1); Source->IsSelected = true; } #endif @@ -735,7 +717,16 @@ int main(int argc, char *argv[]) { Brush_CalcBitmapAlphaFromSize(&Memory, &State->Brush, 4); State_BindBrushTexture(&Memory, &State->Brush, 4); - // File_Open(File, State, &Memory, "test"); + File_Open(File, State, &Memory, "test"); + int h = 0, c = 0, i = 0; + int Count = File->Source_Count; + while (Block_Loop(&Memory, F_Sources, Count, &h, &c, &i)) { + block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, i); + if (Source->Type == source_type_principal_temp) { + Source->Occupied = 0; + File->Source_Count--; + } + } #if STABLE curl_global_init(CURL_GLOBAL_ALL); -- cgit v1.2.3