diff options
author | Fox Caminiti <fox@foxcam.net> | 2022-07-24 11:22:48 -0400 |
---|---|---|
committer | Fox Caminiti <fox@foxcam.net> | 2022-07-24 11:22:48 -0400 |
commit | 3e399d7f2f37feb10e120d7c5950615ffb350a84 (patch) | |
tree | 4cb8c876c176b5ccbdfcaefec8c97abc0b4f773a | |
parent | 4e37809ee8823dc1a9e1b044b9180840c8f5ca7f (diff) |
demo scene added; minor oversights fixed
-rwxr-xr-x | build.sh | 20 | ||||
-rw-r--r-- | createcalls.cpp | 117 | ||||
-rw-r--r-- | main.cpp | 68 | ||||
-rw-r--r-- | main.h | 15 | ||||
-rw-r--r-- | my_imgui_widgets.cpp | 24 |
5 files changed, 154 insertions, 90 deletions
@@ -1,26 +1,18 @@ #!/bin/bash -WINDOWS=0 +WINDOWS=1 - -if [[ "$WINDOWS" == 1 ]]; then -WARNING_FLAGS=" - -Wall -Wextra \ - -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable \ - -Wno-missing-field-initializers -Wno-sign-compare -Wno-write-strings -Wno-unused-but-set-parameter \ - -Wno-missing-braces -Wno-format-security - -fno-exceptions -Wno-strict-aliasing \ - -DDEBUG=1 -DARM=0 -DTHREADED=1 -DPACKEDRGB=1 -DWINDOWS=1 \ -" -else WARNING_FLAGS=" -Wall -Wextra \ -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable \ -Wno-missing-field-initializers -Wno-sign-compare -Wno-write-strings -Wno-unused-but-set-parameter \ -Wno-missing-braces -Wno-format-security -fno-exceptions -Wno-strict-aliasing \ - -DDEBUG=1 -DARM=0 -DTHREADED=1 -DPACKEDRGB=1 -DWINDOWS=0 \ + -DDEBUG=1 -DARM=0 -DTHREADED=1 -DPACKEDRGB=1 \ " + +if [[ "$WINDOWS" == 1 ]]; then +WARNING_FLAGS="$WARNING_FLAGS -DWINDOWS=1" fi @@ -76,7 +68,7 @@ fi # imgui if [[ "$WINDOWS" == 1 ]]; then -clang++ $WARNING_FLAGS -g -target x86_64-pc-windows-gnu -march=x86-64-v3 -I .. -Iimgui -Iimgui/backends \ +clang++ -g $WARNING_FLAGS -target x86_64-pc-windows-gnu -march=x86-64-v3 -I .. -Iimgui -Iimgui/backends \ main.cpp imgui/imgui*.cpp imgui/backends/imgui_impl_sdl.cpp imgui/backends/imgui_impl_opengl3.cpp \ -I/usr/x86_64-w64-mingw32/include/SDL2 -I/usr/x86_64-w64-mingw32/include/GL \ -lmingw32 -lopengl32 -lSDL2main -lSDL2 -llibavcodec -llibswscale -llibavformat -llibavutil \ diff --git a/createcalls.cpp b/createcalls.cpp index d85b271..e5ca18d 100644 --- a/createcalls.cpp +++ b/createcalls.cpp @@ -302,6 +302,36 @@ SSE_CopyToBuffer(pixel_buffer *Raster, uint16 Which) } } +internal void +DebugFillSolid(pixel_buffer *Raster, v4 Color) +{ + __m128i Col = _mm_set1_epi32(ColToUint32(Color)); + uint8 *Row = ((uint8 *)Raster->OriginalBuffer); + uint32 bytes = 0; + while (bytes <= Raster->Height*Raster->Width*4) { + uint8 *Pixel = (uint8 *)Row + bytes; + _mm_storeu_si128((__m128i *)Pixel, Col); + bytes += 16; + } +} + +internal void +BitmapPackRGB(pixel_buffer *Buffer) { +#if PACKEDRGB + Buffer->Pitch = Buffer->Width*Buffer->BytesPerPixel; +#else + Buffer->Pitch = Buffer->Width; // each row has only 1 byte, 8 bits, per pixel + Buffer->Channel = Buffer->Width*Buffer->Height; +#endif +#if PACKEDRGB + Store4x4Chunk(Buffer); + SSE_CopyToBuffer(Buffer, 1); + SSE_ClearBuffer(Buffer, 1); +#else + Libav_GBRAToRGBA(Buffer); +#endif +} + internal pixel_buffer LoadImage(memory *Memory, char *filename) { @@ -315,19 +345,21 @@ LoadImage(memory *Memory, char *filename) Buffer.Height = h; Buffer.Width = w; // printf("%s", stbi_failure_reason()); -#if PACKEDRGB - Buffer.Pitch = Buffer.Width*Buffer.BytesPerPixel; -#else - Buffer.Pitch = Buffer.Width; // each row has only 1 byte, 8 bits, per pixel - Buffer.Channel = Buffer.Width*Buffer.Height; -#endif -#if PACKEDRGB - Store4x4Chunk(&Buffer); - SSE_CopyToBuffer(&Buffer, 1); - SSE_ClearBuffer(&Buffer, 1); -#else - Libav_GBRAToRGBA(&Buffer); -#endif + BitmapPackRGB(&Buffer); + Buffer.ToUpdate = true; + return Buffer; +} + +internal pixel_buffer +CreateSolidBitmap(memory *Memory, uint16 Height, uint16 Width, v4 Color) { + pixel_buffer Buffer = {}; + Buffer.BytesPerPixel = 4; + Buffer.OriginalBuffer = AllocateMemory(Memory, Height * Width * Buffer.BytesPerPixel, B_Scratch); + Buffer.EffectBuffer = AllocateMemory(Memory, Height * Width * Buffer.BytesPerPixel, B_Scratch); + Buffer.Height = Height; + Buffer.Width = Width; + DebugFillSolid(&Buffer, Color); + BitmapPackRGB(&Buffer); Buffer.ToUpdate = true; return Buffer; } @@ -649,34 +681,51 @@ CreateLayerFromSource(project_data *File, project_state *State, memory *Memory, if (IsSupportedFile(&Type, filename)) { project_layer *Layer = CreateLayer(File, Memory); CreateRenderInfo(Layer, Memory, *File, Type, filename); - State->UpdateKeyframes = true; State->UpdateFrame = true; + State->DemoButton = true; } else { PostMsg(State, "File open fail..."); } } -internal void -CreateDebugLayer(struct project_data *File, memory *Memory, int16 Width, int16 Height) +internal project_layer * +CreateSolidLayer(project_data *File, memory *Memory, uint16 Width, uint16 Height, v4 Col) { - int16 a = File->NumberOfLayers++; - Assert(a < MAX_LAYERS); - - File->Layer[a] = (project_layer *)AllocateMemory(Memory, sizeof(project_layer), F_Layers); + project_layer *Layer = CreateLayer(File, Memory); + Layer->RenderInfo = AllocateMemory(Memory, sizeof(image_source), P_SourceData); + image_source *Source = (image_source *)Layer->RenderInfo; + Source->Raster = CreateSolidBitmap(Memory, Width, Height, Col); + Layer->SourceType = source_image; + return Layer; +} - File->Layer[a]->Name = (char *)AllocateMemory(Memory, 256, F_Strings); - sprintf(File->Layer[a]->Name, "Layer %i", a); - File->Layer[a]->x = InitFloatProperty("X Position", (real32)Width/2, 1.0f); - File->Layer[a]->y = InitFloatProperty("Y Position", (real32)Height/2, 1.0f); - File->Layer[a]->ax = InitFloatProperty("Anchor X", 0.5f, 0.005f); - File->Layer[a]->ay = InitFloatProperty("Anchor Y", 0.5f, 0.005f); - File->Layer[a]->scale = InitFloatProperty("Scale", 1.0f, 0.005f); - File->Layer[a]->rotation = InitFloatProperty("Rotation", 0.0f, 1.0f); - File->Layer[a]->opacity = InitFloatProperty("Opacity", 0.4f, 0.005f, 0.0f, 1.0f); - File->Layer[a]->time = InitFloatProperty("Frame Number", 0.0f, 1.0f, 0, 100000); - File->Layer[a]->RenderInfo = AllocateMemory(Memory, sizeof(image_source), P_SourceData); - image_source *Source = (image_source *)File->Layer[a]->RenderInfo; - Source->Raster = CreateDebugBitmap(Width, Height, Memory); - File->Layer[a]->SourceType = source_image; +internal void +CreateDemoScene(project_data *File, memory *Memory) +{ + project_layer *Layer1 = CreateSolidLayer(File, Memory, 720, 1280, V4(0.0, 0.0, 0.0, 1.0)); + Layer1->x.CurrentValue.f = 1280/2; + Layer1->y.CurrentValue.f = 720/2; + Layer1->StartFrame = 0; + Layer1->EndFrame = File->EndFrame; + project_layer *Layer2 = CreateSolidLayer(File, Memory, 500, 500, V4(0.0, 1.0, 0.4, 1.0)); + Layer2->x.CurrentValue.f = 1280/2; + Layer2->y.CurrentValue.f = 720/2; + Layer2->StartFrame = 0; + Layer2->EndFrame = File->EndFrame; + ManualKeyframeInsertF(&Layer2->rotation, Memory, 2, 0); + ManualKeyframeInsertF(&Layer2->rotation, Memory, 50, 360); + Layer2->rotation.IsToggled = true; + Layer2->scale.IsToggled = true; + project_layer *Layer3 = CreateSolidLayer(File, Memory, 160, 160, V4(1.0, 0.3, 0.2, 1.0)); + Layer3->x.CurrentValue.f = 1280/4; + Layer3->y.CurrentValue.f = 720/4; + Layer3->opacity.CurrentValue.f = 0.5f; + Layer3->StartFrame = 0; + Layer3->EndFrame = File->EndFrame; + ManualKeyframeInsertF(&Layer3->x, Memory, 2, Layer3->x.CurrentValue.f); + ManualKeyframeInsertF(&Layer3->x, Memory, 30, Layer3->x.CurrentValue.f+(1280/2)); + ManualKeyframeInsertF(&Layer3->x, Memory, 60, Layer3->x.CurrentValue.f+(1280/3)); + Layer3->x.IsToggled = true; + Layer3->y.IsToggled = true; } @@ -118,40 +118,40 @@ MainFunction(main_sdl *Main, memory *Memory, cache_pool *Cache, pixel_buffer *CompBuffer) { SSE_ClearBuffer(CompBuffer); - for (int i = 0; i < File->NumberOfLayers; i++) { - project_layer *Layer = File->Layer[i]; - if (Layer->RenderInfo) { - // Keyframe updating - if (State->UpdateKeyframes) { - for (int p = 0; p < Layer->NumberOfEffects; p++) { - for (int o = 0; o < Layer->Effect[p]->NumberOfProperties; o++) { - CalculateKeyframesLinearly(File->CurrentFrame, &Layer->Effect[p]->Property[o]); - } - } - for (int r = 0; r < AmountOf(Layer->Property); r++) { - CalculateKeyframesLinearly(File->CurrentFrame, &Layer->Property[r]); - } - State->UpdateKeyframes = false; + for (int i = 0; i < File->NumberOfLayers; i++) { + project_layer *Layer = File->Layer[i]; + if (Layer->RenderInfo) { + // Keyframe updating + if (State->UpdateKeyframes) { + for (int p = 0; p < Layer->NumberOfEffects; p++) { + for (int o = 0; o < Layer->Effect[p]->NumberOfProperties; o++) { + CalculateKeyframesLinearly(File->CurrentFrame, &Layer->Effect[p]->Property[o]); + } } - - // Video updating - if (Layer->SourceType == source_video) { // && Layer->VideoCurrentFrame != File->CurrentFrame - Layer->VideoFrameOffset) { - video_source *Source = (video_source *)Layer->RenderInfo; - LoadVideoFrame(Source, Memory, File->CurrentFrame); // TODO(fox): Make above check work! - UpdateEffects(Layer, Memory); - Source->Raster.ToUpdate = true; + for (int r = 0; r < AmountOf(Layer->Property); r++) { + CalculateKeyframesLinearly(File->CurrentFrame, &Layer->Property[r]); } + } - // Effect updating - if (Layer->SourceType == source_image) { - image_source *Source = (image_source *)Layer->RenderInfo; - if (Source->Raster.ToUpdate) { - UpdateEffects(Layer, Memory); - Source->Raster.ToUpdate = false; - } + // Video updating + if (Layer->SourceType == source_video) { // && Layer->VideoCurrentFrame != File->CurrentFrame - Layer->VideoFrameOffset) { + video_source *Source = (video_source *)Layer->RenderInfo; + LoadVideoFrame(Source, Memory, File->CurrentFrame); // TODO(fox): Make above check work! + UpdateEffects(Layer, Memory); + Source->Raster.ToUpdate = true; + } + + // Effect updating + if (Layer->SourceType == source_image) { + image_source *Source = (image_source *)Layer->RenderInfo; + if (Source->Raster.ToUpdate) { + UpdateEffects(Layer, Memory); + Source->Raster.ToUpdate = false; } } } + } + State->UpdateKeyframes = false; QueueCurrentFrame(File, CompBuffer, State); } @@ -458,7 +458,17 @@ int main(int argc, char *argv[]) { SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); // uint32 ScreenSize[2] = {2560/1.2, 1600/1.2}; - real32 ScreenSize[2] = {3840/1.2, 2160/1.2}; + // real32 ScreenSize[2] = {3840/1.2, 2160/1.2}; + real32 ScreenSize[2]; + SDL_DisplayMode current; + int windowtest = SDL_GetCurrentDisplayMode(0, ¤t); + if (windowtest == 0) { + ScreenSize[0] = current.w; + ScreenSize[1] = current.h; + } else { + ScreenSize[0] = 1920; + ScreenSize[1] = 1080; + } SDL_Window* window = SDL_CreateWindow("Event Tester", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, ScreenSize[0], ScreenSize[1], window_flags); SDL_GLContext gl_context = SDL_GL_CreateContext(window); SDL_GL_MakeCurrent(window, gl_context); @@ -158,7 +158,7 @@ union val { struct keyframe { val Value; - uint16 FrameNumber; + int32 FrameNumber; keyframe_type Type; bool32 IsSelected; // The X coordinate for the tangent is in keyframes, and the Y is in units. @@ -283,8 +283,8 @@ struct project_layer { effect *Effect[MAX_EFFECTS]; uint16 NumberOfEffects; - uint16 StartFrame; - uint16 EndFrame; + int32 StartFrame; + int32 EndFrame; uint32 LayerColor; @@ -312,10 +312,10 @@ struct project_data uint16 Width; uint16 Height; uint16 FPS; - uint16 NumberOfFrames; - uint16 StartFrame; - uint16 EndFrame; - int16 CurrentFrame; + uint32 NumberOfFrames; + int32 StartFrame; + int32 EndFrame; + int32 CurrentFrame; // NOTE(fox): Currently I'm handling layer sorting by just saying that // their order in memory is the order of the index and manually moving @@ -375,6 +375,7 @@ struct project_state bool32 IsRunning = 1; bool32 IsPlaying; + bool32 DemoButton = 1; uint16 NumberOfSelectedLayers; int16 MostRecentlySelectedLayer = -1; // convenience for the properties panel diff --git a/my_imgui_widgets.cpp b/my_imgui_widgets.cpp index 5a0ab55..c199aa4 100644 --- a/my_imgui_widgets.cpp +++ b/my_imgui_widgets.cpp @@ -275,6 +275,15 @@ ImGui_File(project_data *File, project_state *State, memory *Memory, ui *UI, ImG if (ImGui::Button("Add source")) { AddSource(File, Memory); } + if (State->DemoButton) { + ImGui::SameLine(); + if (ImGui::Button("Generate demo scene")) { + CreateDemoScene(File, Memory); + State->UpdateKeyframes = true; + State->UpdateFrame = true; + State->DemoButton = false; + } + } for (int16 i = 0; i < File->NumberOfSources; i++) { ImGui::PushID(i); ImGui::InputText("##source", File->Source[i], STRING_SIZE); @@ -552,6 +561,9 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, } ImGui_SlidingLayer(Layer, &UI->DraggingKeyframeThreshold, io.MouseDelta.x, UI->TimelineZoom, 1); + // TODO(fox): Investigate why this button doesn't get lined up with + // leftbound in certain cases. (i.e. rotation property expanded with keyframes) + ImGui::Button("##layer", ImVec2((LayerTLSpan * UI->TimelineZoom), 0)); ImGui::SameLine(); if (ImGui::IsItemClicked()) { if (!io.KeyShift) DeselectAllLayers(File, State); @@ -778,12 +790,12 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, draw_list->PopClipRect(); - ImGui::SetCursorScreenPos(ImVec2(MinPos.x, MinPos.y)); - ImGui::Button("##SplitMove", ImVec2(TimelineBorderPadding.x, SidebarSizeWithBorder.y)); - if (ImGui::IsItemActive() && ImGui::IsMouseDragging(ImGuiMouseButton_Left, -1)) - { - UI->TimelineSplit += io.MouseDelta.x; - } + // ImGui::SetCursorScreenPos(ImVec2(MinPos.x, MinPos.y)); + // ImGui::Button("##SplitMove", ImVec2(TimelineBorderPadding.x, SidebarSizeWithBorder.y)); + // if (ImGui::IsItemActive() && ImGui::IsMouseDragging(ImGuiMouseButton_Left, -1)) + // { + // UI->TimelineSplit += io.MouseDelta.x; + // } ImGui::SetCursorScreenPos(ImVec2(MinPos.x, MinPos.y)); ImGui::InvisibleButton("AnimationCurves", ImVec2(TimelineSize.x - 20, GraphWindowHeight), ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight); |