summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorFox Caminiti <fox@foxcam.net>2023-02-17 17:20:18 -0500
committerFox Caminiti <fox@foxcam.net>2023-02-17 17:20:18 -0500
commit02870398a99fab6351182fba407d7d733affa5a1 (patch)
treefb5f4744f46e9d7816072e4d01547034bca04bb2 /src/main.cpp
parentfffb3474ee0321d73a47db01dbc4b6b19670ddc5 (diff)
blend mode rendering halfway implemented
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp193
1 files changed, 165 insertions, 28 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 3152156..b144942 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -120,7 +120,7 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, sorted_
if (State->FirstFrame) {
ImGui::MyWindowSetup(&State->RightDock, DockID);
}
- ImGui::MyDockWindow("Timeline", State->RightDock);
+ // ImGui::MyDockWindow("Timeline", State->RightDock);
if (State->Warp_WantSetPos) {
ImGui_WarpMouseFinish(State, io.MousePos);
@@ -155,7 +155,7 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, sorted_
} else {
}
ImGui_PropertiesPanel(File, State, UI, Memory, io, Sorted.CompArray, Sorted.LayerArray, Sorted.PropertyStart, Sorted.PropertyArray);
- // ImGui_File(File, State, Memory, io, Sorted.CompArray, Sorted.LayerArray);
+ ImGui_File(File, State, Memory, io, Sorted.CompArray, Sorted.LayerArray);
ImGui_ColorPanel(File, State, UI, Memory, io);
#if STABLE
@@ -218,10 +218,10 @@ Layer_UpdateAllKeyframes(project_data *File, project_state *State, memory *Memor
Property_MinMax_Y(Memory, State, Property, SortedProperty, &MinY, &MaxY);
real32 Y_Increment = 1 / (MaxY - MinY);
v2 FirstPointPos[3];
- bezier_point *FirstPointAddress = Bezier_LookupAddress(Memory, Property, SortedKeyframe[0]);
+ bezier_point *FirstPointAddress = Bezier_LookupAddress(Memory, Property->Block_Bezier_Index, SortedKeyframe[0]);
Bezier_Interact_Evaluate(State, FirstPointAddress, FirstPointPos);
v2 LastPointPos[3];
- bezier_point *LastPointAddress = Bezier_LookupAddress(Memory, Property, SortedKeyframe[Property->Keyframe_Count - 1]);
+ bezier_point *LastPointAddress = Bezier_LookupAddress(Memory, Property->Block_Bezier_Index, SortedKeyframe[Property->Keyframe_Count - 1]);
Bezier_Interact_Evaluate(State, LastPointAddress, LastPointPos);
if (FirstPointPos[0].x >= Frame_Current) {
Property->CurrentValue = FirstPointPos[0].y;
@@ -231,17 +231,17 @@ Layer_UpdateAllKeyframes(project_data *File, project_state *State, memory *Memor
int KeyframeIndex = 0;
for (;;) {
v2 PointPos[3];
- bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, SortedKeyframe[KeyframeIndex + 1]);
+ bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property->Block_Bezier_Index, SortedKeyframe[KeyframeIndex + 1]);
Bezier_Interact_Evaluate(State, PointAddress, PointPos, 1, Y_Increment);
if (PointPos[0].x >= Frame_Current)
break;
KeyframeIndex++;
}
v2 PointPos[3];
- bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, SortedKeyframe[KeyframeIndex]);
+ bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property->Block_Bezier_Index, SortedKeyframe[KeyframeIndex]);
Bezier_Interact_Evaluate(State, PointAddress, PointPos, 1, Y_Increment);
v2 NextPointPos[3];
- bezier_point *NextPointAddress = Bezier_LookupAddress(Memory, Property, SortedKeyframe[KeyframeIndex + 1]);
+ bezier_point *NextPointAddress = Bezier_LookupAddress(Memory, Property->Block_Bezier_Index, SortedKeyframe[KeyframeIndex + 1]);
Bezier_Interact_Evaluate(State, NextPointAddress, NextPointPos, 1, Y_Increment);
if (PointAddress->Type == interpolation_type_hold) {
Property->CurrentValue = PointPos[0].y;
@@ -291,10 +291,19 @@ Render_SortKeyframes(project_data *File, project_state *State, memory *Memory,
int32 Frame_End_Abs = Frame_End + Frame_Offset;
int FrameToSeek = State->Frame_Current - Frame_Start_Abs;
+ if (Layer->x.Keyframe_Count == 2)
+ int b = 0;
+ if (State->UpdateKeyframes) {
+ if (Layer->x.Keyframe_Count == 2)
+ int b = 0;
+ }
+
if (Frame_Start_Abs <= Frame_Current &&
Frame_End_Abs > Frame_Current && Layer->IsVisible)
{
if (State->UpdateKeyframes) {
+ if (Layer->x.Keyframe_Count == 2)
+ int b = 0;
sorted_property_array *SortedLayerProperties = SortedPropertyStart + SortEntry.SortedPropertyStart;
uint16 *SortedLayerKeyframes = SortedKeyframeArray + SortEntry.SortedKeyframeStart;
Layer_UpdateAllKeyframes(File, State, Memory, Layer, Index_Physical, SortedLayerProperties, SortedLayerKeyframes, Frame_Current);
@@ -309,6 +318,7 @@ GL_Test(const ImDrawList* parent_list, const ImDrawCmd* cmd)
uint64 PerfStart = SDL_GetPerformanceCounter();
gl_viewport_data *RenderData = (gl_viewport_data *)cmd->UserCallbackData;
gl_effect_layer MSBuffer = {};
+ gl_effect_layer MSBuffer2 = {};
int err = 0;
@@ -316,6 +326,7 @@ GL_Test(const ImDrawList* parent_list, const ImDrawCmd* cmd)
glGetIntegerv(GL_VIEWPORT, A);
GL_UpdateTexture(&MSBuffer, NULL, A[2], A[3], RenderData->BytesPerPixel, 1);
+ GL_UpdateTexture2(&MSBuffer2, NULL, A[2], A[3], RenderData->BytesPerPixel, 0);
glBindFramebuffer(GL_FRAMEBUFFER, MSBuffer.FramebufferObject);
glBindTexture(GL_TEXTURE_2D, 0);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
@@ -340,10 +351,10 @@ GL_Test(const ImDrawList* parent_list, const ImDrawCmd* cmd)
if (Data->Type == 0) {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- GL_RasterizeShape2(&MSBuffer, Data->StrokeData, Data->FillData, Data->StrokeCount, Data->FillCount,
- Data->T, RenderData->Width, RenderData->Height, RenderData->BytesPerPixel,
+ GL_RasterizeShape2(&MSBuffer, &MSBuffer2, Data->StrokeData, Data->FillData, Data->StrokeCount, Data->FillCount,
+ Data->T, RenderData->Width, RenderData->Height, RenderData->BytesPerPixel, Data->BitmapData,
Data->Width, Data->Height, Data->StrokeCol, Data->FillCol, Data->RenderMode, 0,
- RenderData->ViewportSize, RenderData->UIPos, RenderData->UIZoom, StencilLayer);
+ RenderData->ViewportSize, RenderData->UIPos, RenderData->UIZoom, Data->BlendMin, Data->BlendMax, StencilLayer);
} else if (Data->Type == 1) {
GL_BlitStencil(&MSBuffer, Data->StrokeData, Data->FillData, Data->StrokeCount, Data->FillCount,
Data->T, RenderData->Width, RenderData->Height, RenderData->BytesPerPixel,
@@ -352,7 +363,7 @@ GL_Test(const ImDrawList* parent_list, const ImDrawCmd* cmd)
StencilLayer++;
} else if (Data->Type == 2) {
GL_BlitStencil(&MSBuffer, Data->StrokeData, Data->FillData, Data->StrokeCount, Data->FillCount,
- Data->T, RenderData->Width, RenderData->Height, RenderData->BytesPerPixel,
+ Data->T, RenderData->Width, RenderData->Height, RenderData->BytesPerPixel,
Data->Width, Data->Height, Data->StrokeCol, Data->FillCol, Data->RenderMode, 0,
RenderData->ViewportSize, RenderData->UIPos, RenderData->UIZoom, StencilLayer, GL_DECR);
StencilLayer--;
@@ -377,13 +388,15 @@ GL_Test(const ImDrawList* parent_list, const ImDrawCmd* cmd)
MinPos.x, MinPos.y, MaxPos.x, MaxPos.y,
GL_COLOR_BUFFER_BIT, GL_LINEAR);
} else {
- // TODO(fox): fix this?
- glBlitFramebuffer(RenderData->ViewportMin.x, RenderData->ViewportMin.y - 50, RenderData->ViewportMax.x, RenderData->ViewportMax.y,
- RenderData->ViewportMin.x, RenderData->ViewportMin.y - 50, RenderData->ViewportMax.x, RenderData->ViewportMax.y,
+ real32 FlipY = A[3] - RenderData->ViewportMax.y;
+ real32 FlipY2 = A[3] - RenderData->ViewportMin.y;
+ glBlitFramebuffer(RenderData->ViewportMin.x, FlipY, RenderData->ViewportMax.x, FlipY2,
+ RenderData->ViewportMin.x, FlipY, RenderData->ViewportMax.x, FlipY2,
GL_COLOR_BUFFER_BIT, GL_LINEAR);
}
GL_DeleteHWBuffer(&MSBuffer);
+ GL_DeleteHWBuffer(&MSBuffer2);
uint64 PerfEnd = SDL_GetPerformanceCounter() - PerfStart;
// printf("OPENGL: %.2lu\n", PerfEnd);
}
@@ -601,7 +614,6 @@ Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDr
sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray, 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, Frame_Current);
uint64 Size = Comp->Width * Comp->Height * Comp->BytesPerPixel;
sorted_comp_array *SortedCompStart = &SortedCompArray[CompIndex];
@@ -622,7 +634,7 @@ Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDr
Interact_Evaluate_Layer(Memory, State, Index_Physical, *SortedCompStart, SortedLayerStart, &Frame_Start, &Frame_End, &Frame_Offset);
int32 Frame_Start_Abs = Frame_Start + Frame_Offset;
int32 Frame_End_Abs = Frame_End + Frame_Offset;
- int FrameToSeek = State->Frame_Current - Frame_Start_Abs;
+ int FrameToSeek = State->Frame_Current - Frame_Offset;
if (Frame_Start_Abs <= Frame_Current &&
Frame_End_Abs > Frame_Current && Layer->IsVisible)
@@ -697,7 +709,7 @@ Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDr
*GL_Data = { 0, Data_Stroke, StrokeCount, ShapeOpt.StrokeCol,
Data_Fill, NumberOfVerts, ShapeOpt.FillCol,
- T, Shape->Width, Shape->Height, RenderFlags };
+ T, Shape->Width, Shape->Height, NULL, RenderFlags };
} else if (Layer->IsPrecomp) {
layer_transforms NewExtraT = Layer_GetTransforms(Layer);
@@ -715,10 +727,10 @@ Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDr
GL_Data->Width = Width;
GL_Data->Height = Height;
GL_Data->FillData = PointBuffer;
- real32 CompVerts[16] = { 0.f, 0.f, 0.f, 0.f,
- 0.f, (real32)Height, 0.f, 0.f,
- (real32)Width, (real32)Height, 0.f, 0.f,
- (real32)Width, 0.f, 0.f, 0.f };
+ real32 CompVerts[16] = { 0.f, 0.f, 0.0f, 0.0f,
+ 0.f, (real32)Height, 0.0f, 1.0f,
+ (real32)Width, (real32)Height, 1.0f, 1.0f,
+ (real32)Width, 0.f, 1.0f, 0.0f };
for (int a = 0; a < 16; a++) {
*(real32 *)PointBuffer = CompVerts[a];
PointBuffer += sizeof(real32);
@@ -743,15 +755,133 @@ Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDr
}
GL_Data->FillCount = 4;
} else {
- Assert(0);
+
+ // gl_data *GL_Data = RenderData->LayerEntry[RenderData->LayerCount] = (gl_data *)PointBuffer;
+ // GL_Data->Type = 3;
+ // RenderData->LayerCount++;
+
gl_data *GL_Data = RenderData->LayerEntry[RenderData->LayerCount] = (gl_data *)PointBuffer;
RenderData->LayerCount++;
PointBuffer += sizeof(gl_data);
+ void *BitmapAddress;
- GL_Data->Type = 1;
+ block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index);
+ av_info *AV = NULL;
+ if (Source->Type == source_type_file) {
+ AV = AV_Retrieve(State, Memory, Layer->Block_Source_Index);
+ if (!AV) {
+ AV = (av_info *)Memory_Block_AllocateAddress(Memory, P_AVInfo);
+ AV->Occupied = 1;
+ AV->Block_Source_Index = Layer->Block_Source_Index;
+ AV_Init(Source, AV, Memory);
+ State->AVCount++;
+ }
+ }
+
+ if (Source->Type == source_type_principal || Source->Type == source_type_principal_temp) {
+ BitmapAddress = Memory_Block_AddressAtIndex(Memory, F_PrincipalBitmaps, Source->Bitmap_Index, 0);
+ } else {
+ cache_entry *CacheEntry = Memory_Cache_Search(State, Memory, cache_entry_type_source, Layer->Block_Source_Index, FrameToSeek);
+ BitmapAddress = Memory_Block_Bitmap_AddressAtIndex(Memory, CacheEntry->Block_StartIndex);
+ if (!CacheEntry->IsCached) {
+ AV_LoadVideoFrame(Memory, Source, AV, FrameToSeek, BitmapAddress);
+ CacheEntry->IsCached = true;
+ }
+ }
+
+ Assert(BitmapAddress);
+
+ GL_Data->FillData = PointBuffer;
+ GL_Data->FillCount = 4;
+ int Blend = (Layer->BlendMode != blend_normal) ? gl_renderflag_blend : 0;
+ v2 Min = V2(10000, 10000), Max = V2(-10000, -10000);
+ if (Blend) {
+ real32 CompVerts[24] = { 0.f, 0.f, 0.0f, 0.0f, -0.5f, 0.5f,
+ 0.f, (real32)Height, 0.0f, 1.0f, -0.5f, 0.5f,
+ (real32)Width, (real32)Height, 1.0f, 1.0f, -0.5f, 0.5f,
+ (real32)Width, 0.f, 1.0f, 0.0f, -0.5f, 0.5f };
+#if 1
+ real32 Rad = (T.rotation * (PI / 180));
+ v2 UIOffset = V2(RenderData->UIPos);
+ v2 UIZoom = V2(RenderData->UIZoom);
+ v2 ScreenDimensions = V2(RenderData->ViewportSize);
+ v2 LayerDimensions = V2(Width, Height);
+ v2 CompDimensions = V2(Comp->Width, Comp->Height);
+ v2 Anchor = V2(T.ax, T.ay);
+ v2 Pos = V2(T.x, T.y);
+ real32 Scale = T.scale;
+
+ for (int a = 0; a < 4; a++) {
+
+ real32 *PointX = &CompVerts[(a*6)];
+ real32 *PointY = &CompVerts[(a*6)+1];
+ v2 Point = V2(*PointX, *PointY);
+
+ v2 XRotation = V2(cos(Rad), sin(Rad));
+ v2 YRotation = V2(sin(Rad), -cos(Rad));
+ v2 XAxis = (Point.x - (Anchor.x * LayerDimensions.x)) * Scale * XRotation;
+ v2 YAxis = (Point.y - (Anchor.y * LayerDimensions.y)) * -Scale * YRotation;
+ v2 CompPoint = Pos + v2(XAxis + YAxis);
+ v2 CompUV = CompPoint / CompDimensions;
+ v2 ScreenPoint = UIOffset + (CompUV * UIZoom);
+ v2 ScreenUV = ScreenPoint / ScreenDimensions;
+
+ *PointX = ScreenUV.x;
+ *PointY = ScreenUV.y;
+ // if (ScreenPoint.x > Max.x)
+ // Max.x = ScreenPoint.x;
+ // if (ScreenPoint.x < Min.x)
+ // Min.x = ScreenPoint.x;
+ // if (ScreenPoint.y > Max.y)
+ // Max.y = ScreenPoint.y;
+ // if (ScreenPoint.y < Min.y)
+ // Min.y = ScreenPoint.y;
+ }
+
+#if 0
+ Rad = -Rad;
+ for (int a = 0; a < 4; a++) {
+
+ real32 *PointX = &CompVerts[(a*6)+2];
+ real32 *PointY = &CompVerts[(a*6)+3];
+ v2 Point = V2(*PointX, *PointY);
+
+ v2 XRotation = V2(cos(Rad), sin(Rad));
+ v2 YRotation = V2(sin(Rad), -cos(Rad));
+ v2 XAxis = (Point.x - 0.5) * XRotation;
+ v2 YAxis = (Point.y - 0.5) * YRotation;
+ v2 CompPoint = V2(0.5, 0.5) + v2(XAxis + YAxis);
+
+ *PointX = CompPoint.x;
+ *PointY = CompPoint.y;
+ }
+#endif
+#endif
+ for (int a = 0; a < 24; a++) {
+ *(real32 *)PointBuffer = CompVerts[a];
+ PointBuffer += sizeof(real32);
+ }
+ } else {
+ real32 CompVerts[16] = { 0.f, 0.f, 0.0f, 0.0f,
+ 0.f, (real32)Height, 0.0f, 1.0f,
+ (real32)Width, (real32)Height, 1.0f, 1.0f,
+ (real32)Width, 0.f, 1.0f, 0.0f };
+ for (int a = 0; a < 16; a++) {
+ *(real32 *)PointBuffer = CompVerts[a];
+ PointBuffer += sizeof(real32);
+ }
+ }
+
+ GL_Data->Type = 0;
GL_Data->Width = Width;
GL_Data->Height = Height;
+ if (Blend) {
+ GL_Data->BlendMin = Min;
+ GL_Data->BlendMax = Max;
+ }
+ GL_Data->BitmapData = BitmapAddress;
GL_Data->T = T;
+ GL_Data->RenderMode = gl_renderflag_convex | gl_renderflag_fill | gl_renderflag_texture | Blend;
}
}
}
@@ -800,7 +930,7 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, sorted_fil
Interact_Evaluate_Layer(Memory, State, Index_Physical, *SortedCompStart, SortedLayerStart, &Frame_Start, &Frame_End, &Frame_Offset);
int32 Frame_Start_Abs = Frame_Start + Frame_Offset;
int32 Frame_End_Abs = Frame_End + Frame_Offset;
- int FrameToSeek = State->Frame_Current - Frame_Start_Abs;
+ int FrameToSeek = State->Frame_Current - Frame_Offset;
if (Frame_Start_Abs <= Frame_Current &&
Frame_End_Abs > Frame_Current && Layer->IsVisible)
@@ -1002,7 +1132,7 @@ int main(int argc, char *argv[]) {
global_memory GlobalMemory = {};
- GlobalMemory.Size = ((uint64)1 * 1024 * 1024 * 1024);
+ GlobalMemory.Size = ((uint64)8 * 1024 * 1024 * 1024);
GlobalMemory.CurrentPosition = 0;
#if WINDOWS
@@ -1037,7 +1167,7 @@ int main(int argc, char *argv[]) {
Memory_InitTable(&GlobalMemory, &Memory, (uint64)5 * 1024 * 1024, B_Thumbnails, "Thumbnails");
Memory_InitTable(&GlobalMemory, &Memory, (uint64)5 * 1024 * 1024, B_PointData, "Point data");
Memory_InitTable(&GlobalMemory, &Memory, (uint64)128 * 1024 * 1024, B_ScratchSpace, "Scratch");
- Memory_InitTable(&GlobalMemory, &Memory, (uint64)700 * 1024 * 1024, B_CachedBitmaps, "Cached bitmap buffer");
+ Memory_InitTable(&GlobalMemory, &Memory, (uint64)5400 * 1024 * 1024, B_CachedBitmaps, "Cached bitmap buffer");
uint8 *Test = (uint8 *)Memory.Slot[B_ScratchSpace].Address + Memory.Slot[B_ScratchSpace].Size + 2;
*Test = 30;
@@ -1088,7 +1218,7 @@ int main(int argc, char *argv[]) {
block_composition *MainComp = (block_composition *)Memory_Block_AllocateAddress(&Memory, F_Precomps);
MainComp->Width = 1280;
- MainComp->Height = 1280;
+ MainComp->Height = 720;
MainComp->FPS = 60;
MainComp->BytesPerPixel = 4;
MainComp->Frame_Count = 80;
@@ -1182,7 +1312,12 @@ int main(int argc, char *argv[]) {
}
gladInstallGLDebug();
- GL_InitDefaultShader();
+ GL_InitDefaultShader(&DefaultVertexShader, DefaultVertexShaderSource,
+ &DefaultFragmentShader, DefaultFragmentShaderSource,
+ &DefaultShaderProgram);
+ GL_InitDefaultShader(&BlendVertexShader, BlendVertexShaderSource,
+ &BlendFragmentShader, BlendFragmentShaderSource,
+ &BlendShaderProgram);
GL_InitDefaultVerts();
Effect_InitEntries(State);
@@ -1402,7 +1537,9 @@ int main(int argc, char *argv[]) {
block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(&Memory, F_Precomps, File->PrincipalCompIndex);
Playhead_Increment(&State->Frame_Current, MainComp->Frame_Start, MainComp->Frame_End, 1);
State->UpdateFrame = true;
+ State->Interact_Transform = {};
State->UpdateKeyframes = true;
+ State->UpdateScreen += 1;
}
bool32 FullyCached = (State->CachedFrameCount == (MainComp->Frame_End - MainComp->Frame_Start + 1));