diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 129 |
1 files changed, 103 insertions, 26 deletions
diff --git a/src/main.cpp b/src/main.cpp index 88bc3ef..9856143 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -85,6 +85,7 @@ uint32 BitmapFill = 0x00000001; #include "undo.cpp" #include "io.cpp" #include "sorted.cpp" +#include "nanovg.cpp" #include "layer.cpp" #include "strings.cpp" #include "threading.cpp" @@ -352,7 +353,16 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, sorted_fil void *RenderAddress = NULL; // result of masking, effects, and intermediate paint stroke int Width = 0, Height = 0, BytesPerPixel = 0; - if (!Layer->IsPrecomp) { + if (Layer->IsPrecomp) { + block_composition *Precomp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, Layer->Block_Source_Index); + BitmapAddress = Render_Comp(File, State, Memory, Sorted, UI, window, textureID, io, SortedCompArray, SortedLayerArray, + SortedPropertyStart, SortedKeyframeArray, Layer->Block_Source_Index, (int32)Layer->time.CurrentValue); + Width = Precomp->Width; + Height = Precomp->Height; + BytesPerPixel = Precomp->BytesPerPixel; + } else if (Layer->IsShapeLayer) { + BytesPerPixel = 4; + } else { 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) { @@ -413,20 +423,13 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, sorted_fil Width = Source->Width; Height = Source->Height; BytesPerPixel = Source->BytesPerPixel; - } else { - block_composition *Precomp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, Layer->Block_Source_Index); - BitmapAddress = Render_Comp(File, State, Memory, Sorted, UI, window, textureID, io, SortedCompArray, SortedLayerArray, - SortedPropertyStart, SortedKeyframeArray, Layer->Block_Source_Index, (int32)Layer->time.CurrentValue); - Width = Precomp->Width; - Height = Precomp->Height; - BytesPerPixel = Precomp->BytesPerPixel; } - Assert(BitmapAddress); - uint64 ScratchSize = Width * Height * BytesPerPixel; RenderAddress = Memory_PushScratch(Memory, ScratchSize); - Memory_Copy((uint8 *)RenderAddress, (uint8 *)BitmapAddress, ScratchSize); + if (BitmapAddress) { + 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? @@ -436,18 +439,28 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, sorted_fil RenderRegion, State->Brush.TransientBitmap, 0, 0}; Render_Main(File, State, Memory, Sorted, UI, window, textureID, (void *)&Info, RenderAddress, render_type_notransform, State->Brush.CacheBounds); } - if (Layer->Block_Effect_Count || Layer->Block_Mask_Count) { - Layer_UpdateMasksEffects(State, Layer, Memory, RenderAddress, Width, Height, BytesPerPixel); - } - Assert(Width && Width <= 2048); - Assert(Height && Height <= 2048); - transform_info T = Transform_Calculate(State, Memory, File, Layer, Comp, Width, Height, BytesPerPixel); - T.SourceBuffer = RenderAddress; - rectangle RenderRegion = {0, 0, Comp->Width, Comp->Height}; + if (Layer->IsShapeLayer) { + Layer_UpdateMasksEffects(State, Layer, Memory, RenderAddress, Comp->Width, Comp->Height, Comp->BytesPerPixel, &Width, &Height); + rectangle RenderRegion = { 0, 0, Comp->Width, Comp->Height }; + direct_info Info = { (real32)Comp->Width, (real32)Comp->Height, (real32)Comp->BytesPerPixel, (real32)Comp->Width * Comp->BytesPerPixel, + Bitmap_ByteInfo(Comp->BytesPerPixel), UI->Color.a, blend_normal, + RenderRegion, RenderAddress, 0, 0}; + Render_Main(File, State, Memory, Sorted, UI, window, textureID, (void *)&Info, CompBuffer, render_type_notransform, RenderRegion); + } else { + Assert(Width && Width <= 2048); + Assert(Height && Height <= 2048); + transform_info T = Transform_Calculate(State, Memory, File, Layer, Comp, Width, Height, BytesPerPixel); + T.SourceBuffer = RenderAddress; + rectangle RenderRegion = {0, 0, Comp->Width, Comp->Height}; - Render_Main(File, State, Memory, Sorted, UI, window, textureID, (void *)&T, CompBuffer, render_type_main, RenderRegion); + Render_Main(File, State, Memory, Sorted, UI, window, textureID, (void *)&T, CompBuffer, render_type_main, RenderRegion); + } Memory_PopScratch(Memory, ScratchSize); + // if (Layer->Block_Effect_Count) { // || Layer->Block_Bezier_Count) { + // Layer_UpdateMasksEffects(State, Layer, Memory, RenderAddress, Width, Height, BytesPerPixel); + // } + } } @@ -750,8 +763,13 @@ int main(int argc, char *argv[]) { GLuint textureID; glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D, textureID); +#if DEBUG glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); +#else + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +#endif ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); @@ -771,10 +789,55 @@ int main(int argc, char *argv[]) { State->UpdateFrame = true; // State->MostRecentlySelectedLayer = 0; #else - uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/yu.webm"); - block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, SourceIndex); - Source->IsSelected = true; - Source_UICreateButton(File, State, &Memory); + // uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/yu.webm"); + // block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, SourceIndex); + // Source->IsSelected = true; + // Source_UICreateButton(File, State, &Memory); + + /* + { + block_layer *Layer = Layer_Init(File, &Memory); + Layer->IsShapeLayer = true; + Layer->Shape.Point_Count = 2; + Layer->Shape.Block_Bezier_Index[0] = Memory_Block_AllocateNew(&Memory, F_Bezier); + block_bezier *Bezier = (block_bezier *)Memory_Block_AddressAtIndex(&Memory, F_Bezier, Layer->Shape.Block_Bezier_Index[0], 0); + Bezier->Occupied = true; + Bezier->Point[0] = { 1, { V2(001, 001), V2(000, 000), V2(000, 000) }, interpolation_type_linear, 0 }; + Bezier->Point[1] = { 1, { V2(300, 300), V2(-150, 000), V2(150, 000) }, interpolation_type_bezier, 0 }; + // Bezier->Point[0] = { 1, { V2(200, 250), V2(000, 000), V2(000, 000) }, interpolation_type_linear, 0 }; + // Bezier->Point[1] = { 1, { V2(300, 300), V2(-150, 000), V2(150, 000) }, interpolation_type_linear, 0 }; + // Bezier->Point[2] = { 1, { V2(400, 250), V2(-150, 000), V2(150, 000) }, interpolation_type_linear, 0 }; + Layer->x.CurrentValue = MainComp->Width/2; + Layer->y.CurrentValue = MainComp->Height/2; + // Layer->ax.CurrentValue = 0; + // Layer->ay.CurrentValue = 0; + Layer->Vertical_Offset = 10; + Layer->Frame_Start = MainComp->Frame_Start; + Layer->Frame_End = MainComp->Frame_End; + } + { + block_layer *Layer = Layer_Init(File, &Memory); + Layer->IsShapeLayer = true; + Layer->Shape.Point_Count = 2; + Layer->Shape.Block_Bezier_Index[0] = Memory_Block_AllocateNew(&Memory, F_Bezier); + block_bezier *Bezier = (block_bezier *)Memory_Block_AddressAtIndex(&Memory, F_Bezier, Layer->Shape.Block_Bezier_Index[0], 0); + Bezier->Occupied = true; + Bezier->Point[0] = { 1, { V2(00, 000), V2(000, 000), V2(000, 000) }, interpolation_type_linear, 0 }; + Bezier->Point[1] = { 1, { V2(500, 300), V2(-150, 000), V2(150, 000) }, interpolation_type_bezier, 0 }; + // Bezier->Point[0] = { 1, { V2(200, 250), V2(000, 000), V2(000, 000) }, interpolation_type_linear, 0 }; + // Bezier->Point[1] = { 1, { V2(300, 300), V2(-150, 000), V2(150, 000) }, interpolation_type_linear, 0 }; + // Bezier->Point[2] = { 1, { V2(400, 250), V2(-150, 000), V2(150, 000) }, interpolation_type_linear, 0 }; + Layer->x.CurrentValue = MainComp->Width/2; + Layer->y.CurrentValue = MainComp->Height/2; + // Layer->ax.CurrentValue = 0; + // Layer->ay.CurrentValue = 0; + Layer->Vertical_Offset = 11; + Layer->IsSelected = true; + State->MostRecentlySelectedLayer = 1; + Layer->Frame_Start = MainComp->Frame_Start; + Layer->Frame_End = MainComp->Frame_End; + } + */ #endif #endif @@ -809,8 +872,22 @@ int main(int argc, char *argv[]) { // NextEffect->Index -= 1; // History_Entry_End(Memory); // } break; - case hotkey_newpaintlayer: { Project_PaintLayer_New(File, State, &Memory); } break; - case hotkey_newlayerfromsource: + case hotkey_newlayer_paint: { + Project_PaintLayer_New(File, State, &Memory); + } break; + case hotkey_newlayer_shape: + { + block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(&Memory, F_Precomps, File->PrincipalCompIndex); + v2 Point = State->TempZoomRatio * V2(MainComp->Width, MainComp->Height); + v2 Vector = V2(0, 0); + if (State->HotkeyExtra[0] != 0) { + Vector = V2(State->HotkeyExtra[0], State->HotkeyExtra[1]); + State->HotkeyExtra[0] = 0; + State->HotkeyExtra[1] = 0; + } + Project_ShapeLayer_New(File, State, &Memory, Point, Vector); + } break; + case hotkey_newlayer_source: { Source_UICreateButton(File, State, &Memory); State->UpdateKeyframes = true; |