summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorFox Caminiti <fox@foxcam.net>2023-01-20 10:10:54 -0500
committerFox Caminiti <fox@foxcam.net>2023-01-20 10:10:54 -0500
commit2f164ae23bcd8a857081529189b484a1515f2834 (patch)
treec7f5b163f7e1585a8fbdb3b8fb7fb012761ae239 /src/include
parent1d0d8549411e23394059f420f053cc3ee28dacfb (diff)
youarelazy
Diffstat (limited to 'src/include')
-rw-r--r--src/include/all.h612
-rw-r--r--src/include/defines.h2
-rw-r--r--src/include/functions.h21
-rw-r--r--src/include/imgui_ops.h2
-rw-r--r--src/include/layer.h2
-rw-r--r--src/include/main.h93
-rw-r--r--src/include/memory.h11
-rw-r--r--src/include/my_math.h16
8 files changed, 731 insertions, 28 deletions
diff --git a/src/include/all.h b/src/include/all.h
new file mode 100644
index 0000000..8bafd30
--- /dev/null
+++ b/src/include/all.h
@@ -0,0 +1,612 @@
+// TODO(fox);: Incorporate sorting for non-continuous shapes.
+static uint32
+Bezier_Shape_Sort(memory *Memory, shape_layer *Shape, bezier_point *PointData,
+ project_state *State, layer_transforms T, int Width, int Height,
+ int CompWidth, int CompHeight, bool32 Interact);
+
+static bezier_point *
+Bezier_LookupAddress(memory *Memory, uint16 *Block_Bezier_Index, uint16 Index, bool32 AssertExists = 1);
+
+static bezier_point *
+Bezier_LookupAddress(memory *Memory, property_channel *Property, uint16 Index, bool32 AssertExists = 1);
+
+static void
+Bezier_Interact_Evaluate(project_state *State, bezier_point *PointAddress, v2 *Pos, real32 GraphZoomHeight = 1, real32 Y_Increment = 1);
+
+static void
+Bezier_Add(memory *Memory, memory_table_list TableName, uint16 *Block_Bezier_Index, uint16 *Block_Bezier_Count,
+ uint16 *PointCount, bezier_point PointData);
+
+static void
+Bezier_Add(memory *Memory, memory_table_list TableName, property_channel *Property, bezier_point PointData, uint16 *ArrayLocation);
+
+// return all points
+static void Bezier_CubicCalcPointsCasteljauStep(void *Data, uint32 Size, uint32 *Increment, real32 x1, real32 y1, real32 x2, real32 y2, real32 x3, real32 y3, real32 x4, real32 y4, real32 tess_tol, int level);
+
+void * Bezier_CubicCalcPoints(v2 p1, v2 p2, v2 p3, v2 p4, void *Data, uint32 Size);
+
+v2 Bezier_LineDist(v2 a, v2 b, v2 p);
+
+v2 Bezier_LineClosestPoint(v2 a, v2 b, v2 p);
+
+// The ratio here is just the dot product divided by the squared length.
+v2 Bezier_LineClosestPointR(v2 a, v2 b, v2 p, real32 *ratio);
+
+static void Bezier_CubicBoxCasteljauStep(v2 Min, v2 Max, v2 *p_closest, v2 *p_last, real32 *p_closest_dist2,
+ real32 x1, real32 y1, real32 x2, real32 y2, real32 x3, real32 y3, real32 x4, real32 y4, real32 tess_tol, int level);
+
+static void
+Bezier_BoxTest(v2 p1, v2 p2, v2 p3, v2 p4, v2 Min, v2 Max, v2 *p_closest);
+
+real32 Bezier_CubicRatioOfPoint(v2 p1, v2 p2, v2 p3, v2 p4, v2 p);
+
+// finds the min/max bounds of the curve
+static void Bezier_CubicMinMaxCasteljauStep(v2 *p_min, v2 *p_max, real32 x1, real32 y1, real32 x2, real32 y2, real32 x3, real32 y3, real32 x4, real32 y4, real32 tess_tol, int level);
+
+real32 Bezier_CubicRatioOfPoint(v2 p1, v2 p2, v2 p3, v2 p4, v2 p);
+
+static bool32
+File_Open(project_data *File, project_state *State, memory *Memory, char *Filename);
+
+static bool32
+IO_Save(project_data *File, project_state *State, memory *Memory, char *Filename);
+
+static void
+File_SaveAs(project_data *File, project_state *State, memory *Memory, char *Filename);
+
+static void
+Playhead_Increment(int32 *Frame_Current, int32 Frame_Start, int32 Frame_End, int32 Increment);
+
+static uint16
+Source_Generate_Blank(project_data *File, project_state *State, memory *Memory, uint16 Width, uint16 Height, uint16 BytesPerPixel);
+
+static void
+Source_Delete(project_data *File, memory *Memory, uint32 Index);
+
+static int16
+Source_Generate(project_data *File, project_state *State, memory *Memory, void *TempString);
+
+
+static void
+Property_AddKeyframe(memory *Memory, memory_table_list TableName, property_channel *Property, int Frame, uint16 *ArrayLocation);
+
+static block_composition *
+Precomp_Init(project_data *File, memory *Memory);
+
+static uint32
+Effect_Init(project_state *State, memory *Memory, uint32 EffectEntryIndex, int EffectCount);
+
+static void
+Effect_Add(project_data *File, project_state *State, memory *Memory, uint32 EffectEntryIndex);
+
+void Source_DeselectAll(project_data *File, memory *Memory);
+
+// NOTE(fox);: This won't work with precomps!
+
+void Clipboard_Paste(project_data *File, project_state *State, memory *Memory, sorted_comp_array *SortedCompStart, sorted_layer_array *SortedLayerStart, uint16 *SortedKeyframeArray);
+
+void Clipboard_Store(project_data *File, project_state *State, memory *Memory, sorted_comp_array *SortedCompStart, sorted_layer_array *SortedLayerStart, sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray);
+
+void Property_MinMax_X(memory *Memory, project_state *State, property_channel *Property,
+ uint16 *ArrayLocation, real32 *Min, real32 *Max);
+void Property_MinMax_Y(memory *Memory, project_state *State, property_channel *Property,
+ sorted_property_array *PropertyStart, real32 *Min, real32 *Max, bool32 Evaluate = 1);
+
+inline property_channel *
+Effect_Property(memory *Memory, block_effect *Effect, int Offset);
+
+inline v2 Effect_V2(memory *Memory, block_effect *Effect, int Offset);
+
+// TODO(fox);: Merge with other sorting code.
+void Effect_Curves_Sort(memory *Memory, block_effect *Effect, uint16 *SortedPointStart, uint16 Which);
+
+static void
+Interact_Evaluate_Layer(memory *Memory, project_state *State, uint16 Layer_Index_Physical, sorted_comp_array SortedCompStart, sorted_layer_array *SortedLayerStart,
+ int32 *Frame_Start, int32 *Frame_End, int *Frame_Offset);
+
+void File_DeselectAllKeyframes(project_data *File, project_state *State, memory *Memory,
+ sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray,
+ sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray);
+
+
+static void
+Project_Layer_Delete(project_data *File, project_state *State, memory *Memory);
+
+static bool32
+Property_IsGraphSelected(memory *Memory, property_channel *Property, uint16 *ArrayLocation);
+
+static void
+Project_Layer_Duplicate(project_data *File, project_state *State, memory *Memory,
+ sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, v2 Offset, bool32 FakeOnly);
+
+static void
+Project_ShapeLayer_New(project_data *File, project_state *State, memory *Memory);
+
+static void
+Project_PaintLayer_New(project_data *File, project_state *State, memory *Memory);
+
+void Source_UICreateButton(project_data *File, project_state *State, memory *Memory);
+
+void Precomp_UIDuplicate(project_data *File, project_state *State, memory *Memory, uint16 CompIndex,
+ sorted_comp_array SortedCompStart, sorted_layer_array *SortedLayerStart);
+
+void Precomp_UIDelete(project_data *File, project_state *State, memory *Memory, uint16 CompIndex,
+ sorted_comp_array SortedCompStart, sorted_layer_array *SortedLayerStart);
+
+void Precomp_UICreateButton(project_data *File, project_state *State, memory *Memory, uint16 CompIndex,
+ sorted_comp_array SortedCompStart, sorted_layer_array *SortedLayerStart);
+
+// TODO(fox);: Make separate full-size bitmap that gets scaled on the GPU instead of this
+static void
+State_BindBrushTexture(memory *Memory, brush_state *Brush, uint32 BytesPerPixel);
+
+static void
+Brush_CalcBitmapAlphaFromSize(memory *Memory, brush_state *Brush, uint32 BytesPerPixel);
+
+// Imported bitmaps are stored in linear, and all ops are also done in linear.
+static void
+Bitmap_SRGBToLinear(void *Buffer, uint16 Width, uint16 Height, uint16 BytesPerPixel, bool32 ToLinear);
+
+static void
+Brush_Info(brush_info *B, brush_state *Brush, block_source *Source, void *SourceBuffer, v2 LayerPos, v4 Color);
+
+void Bitmap_SwapData(uint8 *Address_0, uint8 *Address_1, uint64 Size, uint16 BytesPerPixel);
+
+static void
+PaintTest(brush_info B, void *CacheBuffer, rectangle RenderRegion);
+
+static void
+RenderQueue_AddBrush(project_state *State, v2 LayerPos);
+
+static void
+RenderQueue_AddBlit(project_state *State);
+
+static void
+Effect_GaussianBlur(real32 *Data, int Width, int Height, int BytesPerPixel, void *EffectBitmapAddress, uint16 ShaderProgram);
+
+static void
+Effect_Curves_Init(block_effect *Effect, property_channel *Property);
+
+static void
+Effect_Levels(real32 *Data, int Width, int Height, int BytesPerPixel, void *EffectBitmapAddress, uint16 ShaderProgram);
+
+static void
+Effect_Curves(real32 *Data, int Width, int Height, int BytesPerPixel, void *EffectBitmapAddress, uint16 ShaderProgram);
+
+static void
+Effect_EndEntry(project_state *State);
+
+static void
+Effect_AddProperty_Real(project_state *State, char *Name, real32 DefaultValue, real32 MinVal = -999999, real32 MaxVal = 999999, property_display_type DisplayType = property_display_type_standard);
+
+static void
+Effect_AddProperty_Col(project_state *State, char *Name, v4 DefaultValue);
+
+static void
+Effect_AddProperty_Blendmode(project_state *State, char *Name, blend_mode DefaultValue);
+
+static header_effect*
+Effect_EntryFromID(project_state *State, char *ID);
+
+static void
+Effect_InitEntries(project_state *State);
+
+void Effect_GL_DrawColor(int Width, int Height, int BytesPerPixel, void *EffectBitmapAddress,
+ uint16 ShaderProgram, v4 Color);
+
+void Effect_GL_GaussianBlur(int Width, int Height, int BytesPerPixel, void *EffectBitmapAddress,
+ uint16 ShaderProgram, real32 Radius);
+
+void Effect_GL_Levels(int Width, int Height, int BytesPerPixel, void *EffectBitmapAddress,
+ uint16 ShaderProgram, real32 Min, real32 Mid, real32 Max, v4 ColMin, v4 ColMid, v4 ColMax);
+static void
+CurvesSolver(real32 *LUT, v2 Point_P1, v2 Point_P2, v2 m1, v2 m2, int i);
+
+static void
+Effect_Software_Curves(int Width, int Height, int BytesPerPixel, void *EffectBitmapAddress, v2 *PointData, real32 PointCount, v4 PointCount_Col);
+
+bool32 AV_TryFrame(av_info *AV, AVCodecContext *CodecContext, int32 *err, bool32 *EndOfFile, int StreamIndex = -1);
+
+// Widgets not involving drawing UI.
+
+static v2 ImGui_ScreenPointToCompUV(ImVec2 ViewportMin, ImVec2 CompPos, ImVec2 CompZoom, ImVec2 MousePos);
+static void ImGui_WarpMouseFinish(project_state *State, ImVec2 MousePos);
+static ImVec2 ImGui_Brush_CalcMousePos(project_state *State, ImGuiIO &io, ImVec2 MouseDelta, int32 i, real32 DeltaDistance, real32 DeltaSlope);
+static bool32 ImGui_TestBoxSelection_Point(ImVec2 Pos, ImGuiIO &io, bool32 *Test);
+
+static void
+Layer_TestBoxSelect(memory *Memory, project_state *State, ui *UI, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray,
+ uint16 PrincipalIndex, v2 MinPos, v2 MaxPos);
+
+void AV_IsFileSupported(char *filename, bool32 *IsVideo, bool32 *HasAudio);
+
+void AV_Dealloc(av_info *AV);
+
+void AV_InitStream(av_stream_info *Stream);
+
+// The duration isn't always reported in AVStream, but seeking towards the end
+// and advancing until we hit EOF seems to be accurate.
+void AV_GetDuration(av_info *AV, av_stream_info *Stream, uint64 *Duration, real32 *SecondCount);
+
+
+void AV_Init(block_source *Source, av_info *AV, memory *Memory);
+
+uint32 AV_AudioTest(av_info *AV, void *Data, uint32 Size, real32 FPS, int32 InitialFrameToSeek);
+
+void AV_SeekAudio(av_info *AV, real32 FPS, int32 FrameToSeek);
+
+
+void AV_LoadVideoFrame(memory *Memory, block_source *Source, av_info *AV, int32 FrameToSeek, void *Buffer);
+
+void
+GL_GenAndBindTexture(GLuint *GLTexture, int Width, int Height, int BytesPerPixel, void *BufferAddress);
+
+static void
+GL_BindDefaultVertexArrays();
+
+void
+GL_InitHWBuffer(gl_effect_layer *Test);
+
+void
+GL_DeleteHWBuffer(gl_effect_layer *Test);
+
+void
+GL_UpdateTexture(gl_effect_layer *Test, void *Data, uint16 Width, uint16 Height, uint16 BytesPerPixel, bool32 Multisample);
+
+static uint16
+Effect_GL_InitShader(const char *FragmentShaderEffectSource);
+
+static void
+ImGui_WarpMouse(project_state *State, ImVec2 MousePos, ImVec2 Min, ImVec2 Max, int Direction = 3);
+
+static bool32
+ImGui_TestBoxSelection_Point(ImVec2 Pos, ImGuiIO &io, bool32 *Test);
+
+static void
+ImGui_ColorPanel(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io);
+
+static void
+ImGui_KeybindUI(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io);
+
+static void
+ImGui_Popups(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io);
+
+static void
+ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io, sorted_file Sorted);
+
+static void
+ImGui_Menu(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io);
+
+static void
+ImGui_EffectsPanel(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO io);
+
+static void
+ImGui_DebugRenderQueue(project_state *State);
+
+static void
+ImGui_DebugUndoTree(memory *Memory, project_state *State);
+
+static void
+ImGui_Properties_Slider(project_state *State, memory *Memory, property_channel *Property, ImGuiIO &io, ImVec2 WindowMinAbs, ImVec2 WindowMaxAbs, memory_table_list Table);
+
+
+static void
+ImGui_Properties_CurvesUI(project_state *State, memory *Memory, ImGuiIO io, block_effect *Effect, property_channel *PropertyStart, uint16 *SortedPointStart);
+
+static void
+ImGui_SD_Prompt(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io,
+ sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray);
+
+static void
+ImGui_Timeline_HorizontalIncrementDraw(project_state *State, ui *UI, ImDrawList *draw_list, ImVec2 TimelineSizeWithBorder, ImVec2 TimelineAbsolutePos, block_composition MainComp,
+ ImVec2 TimelineZoomSize, ImVec2 TimelineMoveSize);
+
+static void
+ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO io,
+ sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray);
+
+static void
+ImGui_Viewport_ShapeUI(project_state *State, memory *Memory, ui *UI, ImGuiIO &io, block_layer *Layer, int Width, int Height, shape_layer *Shape, block_composition *MainComp, ImDrawList *draw_list);
+
+
+static void
+ImGui_Viewport_BrushUI(project_state *State, memory *Memory, ImVec2 ViewportMin, ImVec2 ViewportMax, ImVec2 CompZoom, ImGuiIO io, uint16 Width, uint16 Height);
+
+static void
+ImGui_Viewport_TransformUI(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO &io, ImDrawList *draw_list,
+ interact_transform *Interact, ImVec2 ViewportMin, uint32 CompWidth, uint32 CompHeight, uint16 *SortedKeyframeArray);
+
+static void
+ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImGuiIO &io, ImDrawList *draw_list, block_composition *MainComp, uint32 CompIndex, block_layer *ParentLayer[4], uint32 Recursions,
+ sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray);
+
+static void
+ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io, GLuint textureID,
+ sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray);
+
+static void
+IO_ReadFromStream(void *Address, uint64 SizeToRead, SDL_RWops *File);
+
+// lots of cleanup...
+static void
+Layer_Delete(project_data *File, project_state *State, memory *Memory, uint32 Index);
+
+static int
+Layer_GetTopOffset(project_data *File, memory *Memory);
+
+static void
+Layer_ToggleChannel(project_data *File, memory *Memory, int32 a);
+
+static void
+Layer_Select(memory *Memory, project_state *State, int32 i);
+
+static void
+Layer_Select_RecurseUp(memory *Memory, project_state *State, int32 i, int16 RecursionIdx[MAX_PRECOMP_RECURSIONS], uint32 Recursions);
+
+static void
+Layer_Select_Traverse(uint16 PrincipalCompIndex, memory *Memory, project_state *State, int32 IndexToFind, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray,
+ int16 RecursionIdx[MAX_PRECOMP_RECURSIONS], int32 *Recursions);
+
+static void
+Layer_GetDimensions(memory *Memory, block_layer *Layer, int *Width, int *Height);
+
+static v2
+Layer_TraverseForPoint(project_data *File, project_state *State, memory *Memory, v2 PrincipalCompUV, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray);
+
+// TODO(fox);: Precomps?
+static int32
+Layer_TestSelection(memory *Memory, project_state *State, ui *UI, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, uint16 PrincipalIndex);
+
+static bool32
+Shape_TestBoxSelect(v2 Min, v2 Max, bezier_point *BezierPointData, uint32 BezierCount);
+
+static bool32
+Transform_TestBox(block_layer *Layer, uint32 Width, uint32 Height, v2 Min, v2 Max);
+
+static void
+Interact_Transform_Begin(project_data *File, memory *Memory, project_state *State, ImVec2 OGPos,
+ sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray);
+
+static void
+Layer_RecursiveDeselect(memory *Memory, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, uint16 TargetIndex, uint16 PrincipalIndex);
+
+static void
+Main_InputTest(project_data *File, project_state *State, memory *Memory, sorted_file Sorted, ui *UI, SDL_Window *window, GLuint textureID);
+
+static void
+Render_Main(project_data *File, project_state *State, memory *Memory, sorted_file Sorted, ui *UI, SDL_Window *window, GLuint textureID,
+ void *Data, void *OutputBuffer, render_type RenderType, rectangle RenderRegion);
+
+static void
+Layer_UpdateAllKeyframes(project_data *File, project_state *State, memory *Memory, block_layer *Layer, uint16 Index_Physical,
+ sorted_property_array *SortedProperty, uint16 *SortedKeyframe, uint16 Frame_Current);
+
+static av_info *
+AV_Retrieve(project_state *State, memory *Memory, uint32 SourceIndex);
+
+struct gl_data;
+struct gl_viewport_data;
+
+static void
+GL_Test(const ImDrawList* parent_list, const ImDrawCmd* cmd);
+
+static void
+Render_Paint(project_data *File, project_state *State, memory *Memory, sorted_file Sorted, ui *UI, SDL_Window *window, GLuint textureID, ImGuiIO io, v2 LayerPos);
+
+static void
+Render_Blit(project_data *File, project_state *State, memory *Memory, sorted_file Sorted, ui *UI, SDL_Window *window, GLuint textureID, ImGuiIO io, v2 LayerPos);
+
+static void
+Main_Renderer(project_data *File, project_state *State, memory *Memory, sorted_file Sorted, ui *UI, SDL_Window *window, GLuint textureID, ImGuiIO io);
+
+static uint32
+Memory_Block_AllocateNew(memory *Memory, memory_table_list TableName);
+
+static void *
+Memory_Block_AddressAtIndex(memory *Memory, memory_table_list TableName, uint32 Index, bool32 AssertExists = 1);
+
+static uint16
+Memory_Block_LazyIndexAtAddress(memory *Memory, memory_table_list TableName, void *Address);
+
+
+static void *
+Memory_Block_AllocateAddress(memory *Memory, memory_table_list TableName);
+
+// IMPORTANT(fox);: All block data structs have to start with a uint8 Occupied variable!
+static bool32
+Block_Loop(memory *Memory, memory_table_list TableName, uint32 TotalCount, int *HasIncremented, int *CurrentCount, int *Index);
+
+static bool32
+Block_Loop(memory *Memory, property_channel *Property, uint32 TotalCount, int *HasIncremented, int *CurrentCount, int *Index);
+
+static uint32
+Memory_Block_PrincipalBitmap_AllocateNew(project_data *File, project_state *State, memory *Memory);
+
+static uint32
+Memory_Block_Bitmap_AllocateNew(project_state *State, memory *Memory, cache_entry Entry, uint64 NewSize);
+static void
+Memory_Cache_Purge(project_data *File, project_state *State, memory *Memory, int32 SingleFrame = -1);
+
+static cache_entry *
+Memory_Cache_Search(project_state *State, memory *Memory, cache_entry_type Type, uint32 TypeInfo, uint32 TypeInfo_Sub);
+
+static void *
+Memory_Block_Bitmap_AddressAtIndex(memory *Memory, uint32 Index);
+
+static void *
+Memory_AddressAtOffset(memory *Memory, memory_table_list TableName, uint64 Offset);
+
+void Memory_Copy(uint8 *Address_Write, uint8 *Address_Read, uint64 Size);
+
+void Memory_Fill(uint8 *Address_Write, uint8 *Address_Read, uint64 WriteSize, uint64 ReadSize);
+
+void Arbitrary_Zero(uint8 *Address_Write, uint64 Size);
+
+void Arbitrary_SwapData(memory *Memory, uint8 *Address_0, uint8 *Address_1, uint64 Size);
+
+
+static void
+Arbitrary_ShiftData(uint8 *Address_Start, uint8 *Address_End, uint64 ShiftAmount, int32 Direction);
+
+static uint64
+Data_Compress(memory *Memory, void *DataSource, uint64 DataSize, void *DataBuffer, uint64 DataBufferSize, int CompressionLevel);
+
+static void
+Data_Decompress(memory *Memory, void *CompressedLocation, uint64 CompressedSize, void *BitmapLocation, uint64 ExpectedSize);
+
+static real32 *
+NVG_Point(real32 *StrokeData, real32 x, real32 y, real32 u, real32 v);
+
+static void NVG_ChooseBevel(int bevel, nvg_point *p0, nvg_point *p1, float w,
+ float* x0, float* y0, float* x1, float* y1);
+
+static real32 * NVG_RoundCap(nvg_point * Point, real32 *StrokeData,
+ float dx, float dy, float w, int ncap,
+ float u0, float u1, int Mode);
+
+static real32 * NVG_ButtCap(nvg_point *Point, real32 *StrokeData,
+ float dx, float dy, float w, float d,
+ float u0, float u1, int Mode);
+
+static void
+NVG_ExpandFill(void *Memory, int NumberOfVerts, nvg_point *PointData, real32 *FillData);
+
+static v2
+T_CompUVToLayerUV(layer_transforms T, uint32 FileWidth, uint32 FileHeight, uint32 SourceWidth, uint32 SourceHeight, v2 CompUV);
+
+static v2
+T_CompPosToLayerPos(layer_transforms T, uint32 FileWidth, uint32 FileHeight, uint32 SourceWidth, uint32 SourceHeight, real32 X, real32 Y);
+
+static void
+Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDrawList *draw_list,
+ sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray,
+ sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray, uint32 CompIndex, int32 Frame_Current);
+
+static v2
+Transform_ScreenSpaceToLocal(layer_transforms T, uint32 FileWidth, uint32 FileHeight, uint32 SourceWidth, uint32 SourceHeight,
+ ImVec2 CompPos, ImVec2 CompZoom, ImVec2 ViewportMin, ImVec2 Point);
+
+// Transform given data based on state's Interact data.
+static void
+Transform_ApplyInteractive(interact_transform Interact, real32 *OutputX, real32 *OutputY, real32 *OutputRotation, real32 *OutputScale);
+
+static void
+Transform_IterateOuterBounds(block_layer *Layer, uint32 Width, uint32 Height, real32 *MinX, real32 *MinY, real32 *MaxX, real32 *MaxY);
+static void
+Transform_Recurse(project_state *State, memory *Memory, block_composition *MainComp, uint32 CompIndex, block_layer *ParentLayer[4], uint32 Recursions,
+ sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray,
+ real32 *MinX, real32 *MinY, real32 *MaxX, real32 *MaxY);
+
+
+static v2
+TransformPoint(layer_transforms T, real32 Width, real32 Height, v2 Point);
+
+static layer_transforms
+Transform_Inverse(layer_transforms T);
+
+static ImVec2
+Layer_LocalToScreenSpace(project_state *State, memory *Memory, block_layer *Layer, ui *UI, uint32 PrincipalCompIndex, v2 Point);
+
+static void
+Renderer_Start(void *Data, void *OutputBuffer, render_type RenderType, rectangle RenderRegion);
+
+static void
+Renderer_Check(bool32 *Test, render_type RenderType);
+
+static void
+Fallback_RenderLayer(transform_info T, void *OutputBuffer, rectangle RenderRegion);
+
+inline uint16 *
+Property_GetSortedArray(uint16 *SortedKeyframeArray, int i, int h);
+
+static sorted_layer_array *
+Sorted_GetLayerStart(sorted_layer_array *LayerArrayStart, sorted_comp_array *SortedCompStart, uint32 TargetComp);
+
+static void
+Layer_Sort_CheckPrev(memory *Memory, int i, int Direction, sorted_layer_array *SortedLayerStart, sorted_comp_array SortedCompStart, int *EntriesPassed, sorted_layer_array *LayerEntry, bool32 AltMethod);
+
+void LayerProperty_SortAll(project_data *File, project_state *State, memory *Memory, sorted_layer_array *LayerArrayStart,
+ sorted_comp_array *CompStart, sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray,
+ uint32 CompCount);
+
+static void
+TempSource_SortAll(project_data *File, project_state *State, memory *Memory, uint16 *SourceArrayStart, uint16 *TempSourceCount);
+
+
+static sorted_file
+File_Sort_Push(project_data *File, project_state *State, memory *Memory);
+
+static void
+File_Sort_Pop(memory *Memory, uint64 Layer_SortSize, uint64 Property_SortSize, uint64 Source_SortSize);
+
+#if STABLE
+struct curl_data;
+
+static size_t dumbcurlcallback(void *data, size_t size, size_t nmemb, void *userp);
+
+static void
+SD_JSONToSource(project_data *File, project_state *State, memory *Memory, void *JSONResponse, int Height, int Width);
+
+static void
+SD_ParseProgress(project_state *State, char *JSONInfo);
+
+static void
+SD_AssembleJSON(sd_state *SD, char *JSONPayload, void *Base64Bitmap = NULL);
+
+struct curl_state;
+
+static void
+Curl_Free(curl_state *Handle);
+
+static void
+Curl_StopAll(project_state *State, curl_state *ProgHandle, curl_state *MainHandle);
+
+static int
+Curl_Check(curl_state *Handle);
+
+static void
+Curl_Prog_Init(curl_state *C, void *OutputData);
+
+static void
+Curl_Main(project_data *File, project_state *State, memory *Memory, curl_state *MainHandle, curl_state *ProgHandle);
+#endif
+
+static void
+CopyStrings(void *Dest, void *Data);
+
+static uint16
+String_AddToFile(memory *Memory, char *Char);
+
+static bool32
+String_Compare(char *String1, char *String2, uint32 Length);
+
+static uint32
+String_Length(char *Char);
+
+static void
+String_Copy(char *String1, char *String2, uint32 Length);
+
+static void
+String_Append(char *String1, char *String2, uint32 Length);
+
+static void
+String_PathToLayerName(char *Path, char *Dest);
+
+static int
+TestThread(void *ptr);
+
+static bool32
+Threading_IsActive(render_type RenderType);
+
+static void
+Threading_BitmapOp(void *Data, void *OutputBuffer, render_type RenderType, rectangle InitialRenderRegion);
+
+static uint64
+History_GetActionSize(history_entry_list *History, int i);
+
+void History_Entry_Commit(memory *Memory, char *Name);
+void History_Entry_End(memory *Memory);
+static void History_Action_Shift(memory *Memory, memory_table_list TableName,
+ void *Address0, void *Address1, uint64 Amount, int16 Direction);
+static void History_Action_Block_Swap(memory *Memory, memory_table_list TableName, void *Address_Data);
+static void History_Action_Swap(memory *Memory, memory_table_list TableName, uint64 Size, void *Address_Data);
diff --git a/src/include/defines.h b/src/include/defines.h
index 1d4e147..2100c07 100644
--- a/src/include/defines.h
+++ b/src/include/defines.h
@@ -31,6 +31,8 @@ typedef uint64 ptrsize; // is there a compiler variable for 32 vs 64 bit like
#define MAX_LAYERS 2048
#define MAX_EFFECTS 32
#define MAX_SOURCES 1024
+#define MAX_HISTORY_ENTRIES 1024
+#define MAX_HISTORY_ACTIONS 4096
#define MAX_COMPS 1024
#define MAX_PRECOMP_RECURSIONS 4
#define MAX_MASKS 8
diff --git a/src/include/functions.h b/src/include/functions.h
index 2c18f85..4ded552 100644
--- a/src/include/functions.h
+++ b/src/include/functions.h
@@ -6,6 +6,7 @@ static void Arbitrary_Zero(uint8 *Address_Write, uint64 Size);
static void Arbitrary_SwapData(memory *Memory, uint8 *Address_0, uint8 *Address_1, uint64 Size);
static void Arbitrary_ShiftData(uint8 *Address_Start, uint8 *Address_End, uint64 ShiftAmount, int32 Direction);
+void AV_Init(block_source *Source, av_info *AV, memory *Memory);
// Rudimentary guess-until-correct solver for bezier curves, used to evaluate
// the keyframe graph. Similar to the Catmull-Rom solver in CurvesSolver().
@@ -18,6 +19,19 @@ static void Bezier_Interact_Evaluate(project_state *State, bezier_poin
static void Bezier_Add(memory *Memory, memory_table_list TableName, property_channel *Property, bezier_point PointData, uint16 *ArrayLocation);
static void Bezier_Add(memory *Memory, memory_table_list TableName, uint16 *Block_Bezier_Index, uint16 *Block_Bezier_Count, uint16 *PointCount, bezier_point PointData);
+static void
+Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDrawList *draw_list,
+ sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray,
+ sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray, uint32 CompIndex, int32 Frame_Current);
+
+static void *
+Memory_Block_AddressAtIndex(memory *Memory, memory_table_list TableName, uint32 Index, bool32 AssertExists = 1);
+
+static bool32
+Block_Loop(memory *Memory, memory_table_list TableName, uint32 TotalCount, int *HasIncremented, int *CurrentCount, int *Index);
+
+static void
+File_SaveAs(project_data *File, project_state *State, memory *Memory, char *Filename);
static uint32
Bezier_Shape_Sort(memory *Memory, shape_layer *Shape, bezier_point *PointData,
@@ -31,12 +45,11 @@ static layer_transforms Transform_Inverse(layer_transforms T);
static v2 T_CompPosToLayerPos(layer_transforms T, uint32 FileWidth, uint32 FileHeight, uint32 SourceWidth, uint32 SourceHeight, real32 X, real32 Y);
-static void GL_RasterizeShape(gl_effect_layer *TestL, gl_effect_layer *TestM, void *StrokeData, void *FillData, uint32 StrokeCount, uint32 FillCount,
- layer_transforms T, int Width, int Height, int BytesPerPixel, void *EffectBitmapAddress, int L_Width, int L_Height, v4 FillCol, v4 StrokeCol, int RenderMode);
-
static void ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io, sorted_file Sorted);
static void ImGui_PropertiesPanel(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray);
-static void ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io, GLuint textureID, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, uint16 *SortedKeyframeArray);
+static void
+ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io, GLuint textureID,
+ sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray);
static void ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO io, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray);
static void ImGui_File(project_data *File, project_state *State, memory *Memory, ImGuiIO io, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray);
diff --git a/src/include/imgui_ops.h b/src/include/imgui_ops.h
index 6089f94..2d1c1bc 100644
--- a/src/include/imgui_ops.h
+++ b/src/include/imgui_ops.h
@@ -1,5 +1,3 @@
-
-
ImVec2 operator+(ImVec2 A, ImVec2 B)
{
ImVec2 Result;
diff --git a/src/include/layer.h b/src/include/layer.h
index bf32aca..2b83a79 100644
--- a/src/include/layer.h
+++ b/src/include/layer.h
@@ -28,7 +28,7 @@ Layer_DeselectAll(project_data *File, project_state *State, memory *Memory);
static bool32
Layer_LoopChannels(project_state *State, memory *Memory, sorted_property_array **SortedProperty, uint16 **SortedKeyframe, block_layer *Layer,
- property_channel **Property, block_effect **EffectOut, int *h, int *c, int *p);
+ property_channel **Property, block_effect **EffectOut, int *h, int *c, int *p, int LoopNumber = 8);
static void
Layer_ToggleAllChannels(project_state *State, memory *Memory, block_layer *Layer,
diff --git a/src/include/main.h b/src/include/main.h
index 7d3299e..6c9caca 100644
--- a/src/include/main.h
+++ b/src/include/main.h
@@ -1,3 +1,62 @@
+#include <glad.h>
+
+#include <stdio.h>
+#if WINDOWS
+#include <windows.h>
+#else
+#include <sys/mman.h>
+#include <unistd.h>
+#endif
+
+#if ARM
+#include <arm_neon.h>
+#include <arm_sve.h>
+#else
+#include <smmintrin.h>
+#endif
+
+#include "imgui.h"
+#include "imgui_impl_sdl.h"
+#include "imgui_impl_opengl3.h"
+#include <SDL.h>
+#if defined(IMGUI_IMPL_OPENGL_ES2)
+#include <SDL_opengles2.h>
+#else
+#include <SDL_opengl.h>
+#endif
+
+#define STB_IMAGE_IMPLEMENTATION
+#define STBI_FAILURE_USERMSG
+#include "stb_image.h"
+
+#define STB_IMAGE_WRITE_IMPLEMENTATION
+#include "stb_image_write.h"
+
+// TODO(fox): Used for thumbnails. The renderer could be expanded to do this
+// much more efficiently.
+#define STB_IMAGE_RESIZE_IMPLEMENTATION
+#include "stb_image_resize.h"
+
+extern "C" {
+#include <libavcodec/avcodec.h>
+#include <libavformat/avformat.h>
+#include <libavformat/avio.h>
+#include <libavutil/avutil.h>
+#include <libswscale/swscale.h>
+#include <libswresample/swresample.h>
+}
+
+
+
+#include "defines.h"
+#include "my_math.h"
+#include "structs.h"
+#if STABLE
+#include "stable_diffusion.h"
+#endif
+#include "memory.h"
+#include "nanovg.h"
+
enum instruction_mode {
instruction_mode_scalar,
#if ARM
@@ -156,6 +215,7 @@ struct sorted_property_array
struct sorted_comp_array
{
uint32 LayerCount;
+ uint32 FakeLayerCount;
uint32 CurrentSortIndex; // Used intermediately in the sorting algorithm
real32 DisplaySize;
};
@@ -163,6 +223,7 @@ struct sorted_comp_array
struct sorted_layer_array
{
uint16 Block_Layer_Index;
+ bool32 IsFake;
real32 SortedOffset;
real32 DisplayOffset;
uint16 Sorted_Effect_Index[MAX_EFFECTS];
@@ -187,8 +248,8 @@ struct sorted_file
struct shape_options {
int Visibility;
v4 FillCol = {1, 1, 1, 1};
- v4 StrokeCol = {0, 1, 0, 1};
- float StrokeWidth = 25;
+ v4 StrokeCol = {1, 0, 0, 1};
+ float StrokeWidth = 10;
nvg_line_cap LineJoinType = NVG_ROUND;
nvg_line_cap LineCapType = NVG_ROUND;
real32 Roundness;
@@ -200,10 +261,10 @@ struct shape_layer {
uint16 Point_Count;
bool32 IsClosed;
bool32 Contiguous = 1; // No points have been deleted/added, so sorting isn't needed.
- // NOTE(fox): This is kinda lazily done atm, there may be situations where
- // this isn't the correct value.
- int Width;
- int Height;
+ // NOTE(fox): Point vals are normalized based on whatever these values are!
+ // They get set once the shape becomes a shape layer!
+ real32 Width;
+ real32 Height;
shape_options Opt;
};
@@ -239,6 +300,8 @@ enum interact_type
interact_type_layer_move,
interact_type_layer_timeadjust,
interact_type_viewport_transform,
+ interact_type_viewport_duplicate,
+ interact_type_viewport_slide,
interact_type_keyframe_move,
interact_type_keyframe_scale,
interact_type_keyframe_rotate,
@@ -249,16 +312,18 @@ char *ToolName[] {
"Move",
"Crop",
"Brush",
+ "Slide",
"Pen",
- "Square"
+ "Rectangle"
};
enum tool {
tool_default,
tool_crop,
tool_brush,
+ tool_slide,
tool_pen,
- tool_square,
+ tool_rectangle,
tool_count
};
@@ -413,6 +478,7 @@ struct project_state
interact_type Interact_Active;
int32 Interact_Modifier;
real32 Interact_Offset[12];
+ real32 Interact_Dup_Previous[2];
void *Interact_Address;
// NOTE(fox): We need to keep track of when the user changes the CurrentValue of a
@@ -459,6 +525,8 @@ struct ui
ImVec2 CompZoom; // In screen pixels, not percentage.
ImVec2 CompPos;
+ int Mode = 1;
+
// Under 1 is zoomed in!
ImVec2 TimelinePercentZoomed;
ImVec2 TimelinePercentOffset;
@@ -730,3 +798,12 @@ struct render_entry {
rectangle RenderRegion;
};
+
+#include "ffmpeg_backend.h"
+#include "layer.h"
+#include "debug.h"
+#include "all.h"
+
+#include "imgui_internal_widgets.h"
+
+#include "imgui_ops.h"
diff --git a/src/include/memory.h b/src/include/memory.h
index dab6ed4..e6b7676 100644
--- a/src/include/memory.h
+++ b/src/include/memory.h
@@ -15,9 +15,12 @@ enum memory_table_list {
F_PrincipalBitmaps,
B_Thumbnails,
+ B_PointData,
B_ScratchSpace,
B_CacheEntries,
B_CachedBitmaps,
+
+ M_Count
};
struct memory_table {
@@ -53,15 +56,17 @@ struct history_entry {
uint16 NumberOfActions;
};
+
+
struct history_entry_list {
- history_entry Entry[256];
- history_action Action[1024];
+ history_entry Entry[MAX_HISTORY_ENTRIES];
+ history_action Action[MAX_HISTORY_ACTIONS];
uint16 NumberOfEntries;
uint16 EntryPlayhead;
};
struct memory {
- memory_table Slot[16];
+ memory_table Slot[M_Count];
history_entry_list History;
uint64 ScratchPos;
uint32 EntryCount;
diff --git a/src/include/my_math.h b/src/include/my_math.h
index 72c6b99..2a54f4d 100644
--- a/src/include/my_math.h
+++ b/src/include/my_math.h
@@ -361,16 +361,6 @@ v2i operator-(v2i A, int16 B)
return(Result);
}
-v2i operator+(v2i A, int16 B)
-{
- v2i Result;
-
- Result.x = A.x + B;
- Result.y = A.y + B;
-
- return(Result);
-}
-
v2 operator*(real32 A, v2 B)
{
v2 Result;
@@ -580,6 +570,12 @@ LengthSq(v2 A)
return Result;
}
+inline real32
+Length(v2 A)
+{
+ return sqrt(Inner(A, A));
+}
+
inline uint32
Floor(uint32 A, uint32 B)
{