From b39c7374009d03d448e47e08ddabc30abeee5247 Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Thu, 25 Aug 2022 18:55:59 -0400 Subject: minor fixes --- bitmap_calls.cpp | 33 ++++++++++++++++++++++++++++----- build.sh | 4 ++-- createcalls.cpp | 33 +++++++++++++++++++-------------- effects_software.cpp | 3 +++ functions.h | 2 +- gl_calls.cpp | 1 + main.cpp | 10 ++++------ my_imgui_widgets.cpp | 43 +++++++++++++++++++++---------------------- undo.cpp | 4 ++-- 9 files changed, 81 insertions(+), 52 deletions(-) diff --git a/bitmap_calls.cpp b/bitmap_calls.cpp index 46f0c31..0e76039 100644 --- a/bitmap_calls.cpp +++ b/bitmap_calls.cpp @@ -248,16 +248,25 @@ Bitmap_StencilAlpha(void *Input, void *Output, uint16 BytesPerPixel, uint64 Tota uint16 ByteOffset = Bitmap_CalcByteOffset(BytesPerPixel); uint64 RemainderBytes = TotalBytes % ByteOffset; +#if ARM +#else __m256i AlphaBytes = _mm256_set1_epi32(0x00FFFFFF); __m256i Zeroi = _mm256_set1_epi32(0); +#endif while (bytes <= TotalBytes - RemainderBytes) { uint8 *Pixel = (uint8 *)Row + bytes; uint8 *Pixel2 = (uint8 *)Row2 + bytes; #if ARM if (InstructionMode == instruction_mode_neon) { - uint32x2x4_t OutputPixel = vld4_u32((uint32 *)Pixel); - vst4_u32((uint32 *)Pixel2, OutputPixel); + // TODO(fox): Optimize and write NEON! + uint8 *DestAlpha = Pixel2 + (BytesPerPixel/4)*3; + uint8 Alpha = *DestAlpha; + uint32 *DestPixel = (uint32 *)Pixel2; + uint32 *SrcPixel = (uint32 *)Pixel; + *DestPixel = *SrcPixel; + *DestAlpha = Alpha; + bytes += BytesPerPixel; #else if (InstructionMode == instruction_mode_avx) { __m256i InputPixel = _mm256_loadu_si256((__m256i *)Pixel); @@ -266,19 +275,33 @@ Bitmap_StencilAlpha(void *Input, void *Output, uint16 BytesPerPixel, uint64 Tota OutputPixel = _mm256_blendv_epi8(OutputPixel, InputPixel, AlphaBytes); _mm256_storeu_si256((__m256i *)Pixel2, OutputPixel); } + bytes += ByteOffset; } else if (InstructionMode == instruction_mode_sse) { __m128i OutputPixel = _mm_loadu_si128((__m128i *)Pixel); _mm_storeu_si128((__m128i *)Pixel2, OutputPixel); + bytes += ByteOffset; #endif } else { - *(uint32 *)Pixel2 = *(uint32 *)Pixel; + // TODO(fox): Optimize and write NEON! + uint8 *DestAlpha = Pixel2 + (BytesPerPixel/4)*3; + uint8 Alpha = *DestAlpha; + uint32 *DestPixel = (uint32 *)Pixel2; + uint32 *SrcPixel = (uint32 *)Pixel; + *DestPixel = *SrcPixel; + *DestAlpha = Alpha; + bytes += BytesPerPixel; } - bytes += ByteOffset; } while (bytes <= TotalBytes) { uint8 *Pixel = (uint8 *)Row + bytes; uint8 *Pixel2 = (uint8 *)Row2 + bytes; - *(uint32 *)Pixel2 = *(uint32 *)Pixel; + // TODO(fox): Optimize and write NEON! + uint8 *DestAlpha = Pixel2 + (BytesPerPixel/4)*3; + uint8 Alpha = *DestAlpha; + uint32 *DestPixel = (uint32 *)Pixel2; + uint32 *SrcPixel = (uint32 *)Pixel; + *DestPixel = *SrcPixel; + *DestAlpha = Alpha; bytes += BytesPerPixel; } } diff --git a/build.sh b/build.sh index 61109c7..6ae9de1 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ #!/bin/bash -OPTIMIZATION="-g" # Enable optimization. -DEBUG=1 # Compile with debug UI. +OPTIMIZATION="-O2" # Enable optimization. +DEBUG=0 # Compile with debug UI. IMGUI=0 # Compile ImGui libs. Our custom ImGui functions still compile on zero. THREADED=1 # Compile with threading. Useful to disable when stepping through the renderer. WINDOWS=0 # Compile for Windows with Mingw. diff --git a/createcalls.cpp b/createcalls.cpp index b5be361..5467f18 100644 --- a/createcalls.cpp +++ b/createcalls.cpp @@ -7,13 +7,22 @@ IncrementFrame(project_data *File, int16 Amount) { } } +static void +PostMsg(project_state *State, char *msg) +{ + State->MsgTime = 120; + State->Msg = msg; +} + static bool32 -Source_Generate(project_data *File, memory *Memory, void *Path) +Source_Generate(project_data *File, project_state *State, memory *Memory, void *TempString) { Assert(File->NumberOfSources < MAX_SOURCES); source *Source = &File->Source[File->NumberOfSources]; bool32 IsVideo = 0; + void *Path = String_GenerateFromChar(Memory, (char *)TempString); + if (AV_IsFileSupported((char *)Path, &IsVideo)) { if (IsVideo) Source->SourceType = source_type_video; @@ -26,7 +35,8 @@ Source_Generate(project_data *File, memory *Memory, void *Path) History_Entry_End(Memory); return 1; } else { - // PostMsg(State, "File open fail..."); + void *Address = Memory_Rewind(Memory, STRING_SIZE, F_Strings); + PostMsg(State, "File open fail..."); } return 0; @@ -53,13 +63,6 @@ CreateKeyframeBlock(property_channel *Property, memory *Memory) Property->KeyframeBlock[a] = (keyframe_block *)AllocateMemory(Memory, sizeof(keyframe_block), F_Keyframes); } -static void -PostMsg(project_state *State, char *msg) -{ - State->MsgTime = 120; - State->Msg = msg; -} - // Note we use total bytes here so we can use this memory for both packed and unpacked bitmaps. void * Layer_AllocateBitmap(memory *Memory, uint16 Width, uint16 Height, uint16 BytesPerPixel) { @@ -280,15 +283,15 @@ static void LoadTestFootage(project_data *File, project_state *State, memory *Memory) { void *SourceString = String_GenerateFromChar(Memory, "../asset/a.jpg"); - Source_Generate(File, Memory, SourceString); + Source_Generate(File, State, Memory, SourceString); SourceString = String_GenerateFromChar(Memory, "../asset/24.mp4"); - Source_Generate(File, Memory, SourceString); + Source_Generate(File, State, Memory, SourceString); SourceString = String_GenerateFromChar(Memory, "../asset/b.jpg"); - Source_Generate(File, Memory, SourceString); + Source_Generate(File, State, Memory, SourceString); SourceString = String_GenerateFromChar(Memory, "../asset/c.jpg"); - Source_Generate(File, Memory, SourceString); + Source_Generate(File, State, Memory, SourceString); SourceString = String_GenerateFromChar(Memory, "../asset/p.mp4"); - Source_Generate(File, Memory, SourceString); + Source_Generate(File, State, Memory, SourceString); Layer_CreateFromSource(File, State, Memory, &File->Source[0]); SelectLayer(File->Layer[0], State, 0); @@ -337,7 +340,9 @@ LoadTestFootage(project_data *File, project_state *State, memory *Memory) Mask->NumberOfPoints = 5; Mask->IsClosed = true; + */ + /* Mask_DeletePoint(Memory, Mask, 1); History_Undo(Memory); diff --git a/effects_software.cpp b/effects_software.cpp index 8451f6d..06e8543 100644 --- a/effects_software.cpp +++ b/effects_software.cpp @@ -1,6 +1,8 @@ static void Effect_Software_DrawColor(source *Source, layer_bitmap_info *BitmapInfo, memory *Memory, property_channel Property[]) { +#if ARM +#else v4 FloatColor = Property[0].CurrentValue.col; blend_mode BlendMode = Property[1].CurrentValue.blendmode; @@ -171,4 +173,5 @@ Effect_Software_DrawColor(source *Source, layer_bitmap_info *BitmapInfo, memory _mm256_storeu_si256((__m256i *)Pixel, OutputPixel); } } +#endif } diff --git a/functions.h b/functions.h index 044d877..1e044d1 100644 --- a/functions.h +++ b/functions.h @@ -12,7 +12,7 @@ static uint16 Bitmap_CalcByteOffset(uint16 BytesPerPixel); // Returns the amount static uint64 Bitmap_CalcTotalBytes(uint16 Width, uint16 Height, uint16 BytesPerPixel); // Returns the total amount of bytes a bitmap takes up. static uint64 Bitmap_CalcUnpackedBytes(uint16 Width, uint16 Height, uint16 BytesPerPixel); -static bool32 Source_Generate(project_data *File, memory *Memory, void *Path); // Fills out source info if the source is a supported file. +static bool32 Source_Generate(project_data *File, project_state *State, memory *Memory, void *Path); // Fills out source info if the source is a supported file. // Libav (ffmpeg) backend for decoding video diff --git a/gl_calls.cpp b/gl_calls.cpp index 277b15b..ba63fda 100644 --- a/gl_calls.cpp +++ b/gl_calls.cpp @@ -222,6 +222,7 @@ GL_UpdateTexture(gl_effect_layer *Test, void *Data, uint16 Width, uint16 Height, static void GL_BindDefaultVertexArrays() { + glBindVertexArray(DefaultVerts.VertexArrayObject); // Switch to main buffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, DefaultVerts.ElementBufferObject); glBindBuffer(GL_ARRAY_BUFFER, DefaultVerts.VertexBufferObject); diff --git a/main.cpp b/main.cpp index 52cfae6..866ef24 100644 --- a/main.cpp +++ b/main.cpp @@ -158,10 +158,10 @@ int main(int argc, char *argv[]) { File.StartFrame = 0; File.EndFrame = 65; - LoadTestFootage(&File, &State, &Memory); +#if DEBUG + LoadTestFootage(&File, &State, &Memory); -#if DEBUG // GDB and LLDB say this plain struct that's literally under 30 bytes is // incomplete in the layers unless I do this... layer_bitmap_info BitmapInfo; @@ -272,7 +272,7 @@ int main(int argc, char *argv[]) { ScreenSize[1] = 1080; } #endif - SDL_Window* window = SDL_CreateWindow("Event Tester", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, ScreenSize[0], ScreenSize[1], window_flags); + SDL_Window* window = SDL_CreateWindow("Event Tester", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, ScreenSize[0], ScreenSize[1], window_flags); SDL_GLContext gl_context = SDL_GL_CreateContext(window); SDL_GL_MakeCurrent(window, gl_context); SDL_GL_SetSwapInterval(1); // Enable vsync @@ -332,9 +332,7 @@ int main(int argc, char *argv[]) { ImGui_ImplSDL2_ProcessEvent(&event); if (event.type == SDL_DROPFILE) { char *DropFile = event.drop.file; - // TODO(fox): Free failed strings if too many get created! - void *SourceString = String_GenerateFromChar(Memory, DropFile); - Source_Generate(File, Memory, SourceString); + Source_Generate(&File, &State, &Memory, DropFile); SDL_free(DropFile); } if (event.type == SDL_QUIT) diff --git a/my_imgui_widgets.cpp b/my_imgui_widgets.cpp index 1ef4d31..d2fa7c0 100644 --- a/my_imgui_widgets.cpp +++ b/my_imgui_widgets.cpp @@ -425,7 +425,7 @@ ImGui_Viewport(project_data File, project_state *State, ui *UI, memory *Memory, ImVec2 ViewportMin = ImGui::GetCursorScreenPos(); ImVec2 ViewportScale = ImGui::GetContentRegionAvail(); - ViewportScale.y -= ImGui::GetFontSize(); + ViewportScale.y -= ImGui::GetFontSize()*0.5; if (ViewportScale.x < 50.0f) ViewportScale.x = 50.0f; if (ViewportScale.y < 50.0f) ViewportScale.y = 50.0f; ImVec2 ViewportMax = ImVec2(ViewportMin.x + ViewportScale.x, ViewportMin.y + ViewportScale.y); @@ -705,36 +705,32 @@ ImGui_Viewport(project_data File, project_state *State, ui *UI, memory *Memory, } IsDeactivated = false; // just in case escape and mouse release happen simultaneously } + mask *Mask = &Layer->Mask[Layer->NumberOfMasks-1]; if (IsDeactivated) { mask *Mask = &Layer->Mask[Layer->NumberOfMasks-1]; if (Mask->NumberOfPoints == 1) { + // NOTE(fox): We have to use this slightly janky way of writing to + // the history tree since we can only create entries/actions once we + // know the user is committed to them. Might write an escapable + // entry mode if we do this often. uint16 PreviousNumberOfMasks = Layer->NumberOfMasks - 1; uint16 PreviousNumberOfPoints = Mask->NumberOfPoints - 1; + bool32 NotActive = false; History_Entry_Commit(Memory, action_entry_default, "Create mask"); + History_Action_Change(Memory, &State->Pen.IsActive, &NotActive, + &State->Pen.IsActive, action_type_change_u32); History_Action_Change(Memory, &Layer->NumberOfMasks, &PreviousNumberOfMasks, - &Layer->NumberOfMasks, action_type_change_u16); + &Layer->NumberOfMasks, action_type_change_u16); History_Action_Change(Memory, &Mask->NumberOfPoints, &PreviousNumberOfPoints, - &Mask->NumberOfPoints, action_type_change_u16); + &Mask->NumberOfPoints, action_type_change_u16); History_Entry_End(Memory); } else { uint16 PreviousNumberOfPoints = Mask->NumberOfPoints - 1; - uint16 Empty = 0; mask_point *CurrentPoint = &Mask->Point[Mask->NumberOfPoints-1]; History_Entry_Commit(Memory, action_entry_default, "Add point"); History_Action_Change(Memory, &Mask->NumberOfPoints, &PreviousNumberOfPoints, &Mask->NumberOfPoints, action_type_change_u16); - History_Action_Change(Memory, &CurrentPoint->Pos.x, &Empty, - &CurrentPoint->Pos.x, action_type_change_r32); - History_Action_Change(Memory, &CurrentPoint->Pos.y, &Empty, - &CurrentPoint->Pos.y, action_type_change_r32); - History_Action_Change(Memory, &CurrentPoint->TangentLeft.x, &Empty, - &CurrentPoint->TangentLeft.x, action_type_change_r32); - History_Action_Change(Memory, &CurrentPoint->TangentLeft.y, &Empty, - &CurrentPoint->TangentLeft.y, action_type_change_r32); - History_Action_Change(Memory, &CurrentPoint->TangentRight.x, &Empty, - &CurrentPoint->TangentRight.x, action_type_change_r32); - History_Action_Change(Memory, &CurrentPoint->TangentRight.y, &Empty, - &CurrentPoint->TangentRight.y, action_type_change_r32); + History_Action_StoreData(Memory, &CurrentPoint, sizeof(mask_point)); History_Entry_End(Memory); } } @@ -791,6 +787,8 @@ ImGui_Viewport(project_data File, project_state *State, ui *UI, memory *Memory, UI->CompPos.y -= Distance*UI->TempZoomRatio.y; } + ImGui::SetCursorScreenPos(ImVec2(ViewportMin.x, ViewportMin.y + ViewportScale.y - ImGui::GetFontSize()*1.5)); + ImGui::Text("%.1f", 100.0f * (UI->CompZoom.x / CompBuffer.Width)); if (State->MsgTime > 0) { ImGui::SameLine(); @@ -846,6 +844,7 @@ ImGui_File(project_data *File, project_state *State, memory *Memory, ui *UI, ImG { ImGui::Begin("Files"); ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); +#if DEBUG if (State->DemoButton) { if (ImGui::Button("Generate demo scene")) { CreateDemoScene(File, State, Memory); @@ -863,6 +862,7 @@ ImGui_File(project_data *File, project_state *State, memory *Memory, ui *UI, ImG State->GridButton = false; } } +#endif ImGui::Text("Sources:"); for (int i = 0; i < File->NumberOfSources; i++) { bool32 Test = false; @@ -881,12 +881,11 @@ ImGui_File(project_data *File, project_state *State, memory *Memory, ui *UI, ImG } ImGui::EndPopup(); } - // static char Input[1024]; - // ImGui::InputText("##sourceinput", Input, STRING_SIZE); - // ImGui::SameLine(); - // if (ImGui::Button("Create Layer")) { - // // AddSource(File, State, Memory, Input); - // } + static char Input[1024]; + ImGui::InputTextWithHint("##sourceinput", "Input file path of source...", Input, STRING_SIZE); + if (ImGui::IsItemDeactivated() && ImGui::IsKeyPressed(ImGuiKey_Enter)) { + Source_Generate(File, State, Memory, Input); + } #if DEBUG for (int i = 0; i < Debug.Temp.WatchedProperties; i++) { if (Debug.Temp.DebugPropertyType[i] == d_float) { diff --git a/undo.cpp b/undo.cpp index 2306db9..bb49772 100644 --- a/undo.cpp +++ b/undo.cpp @@ -282,8 +282,8 @@ void History_Action_Shift(memory *Memory, action_type ActionChange, void *DataAd *(action_type *)Data = ActionChange; } -// Overwrite area with arbitrary-sized memory. Only use for creation/deletion, -// not for value changes of things that already exist. +// Overwrite area with arbitrary-sized memory. Only use if the previous data +// doesn't need to be recorded, like pushing to the end of a stack. void History_Action_StoreData(memory *Memory, void *DataAddress, uint64 ByteSize) { Memory->Action.Entry[Memory->Action.Index].NumberOfActions++; -- cgit v1.2.3