summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFox Caminiti <fox@foxcam.net>2023-02-11 17:37:49 -0500
committerFox Caminiti <fox@foxcam.net>2023-02-11 17:37:49 -0500
commitbd25daeae033e4f905ae0145831a7d8fdd92e471 (patch)
tree7e602f31449d8eb58212a028e91e7eb32e4bbf84 /src
parent52c6ad3f2686cb66a8954ca5dac7f3eba4676cc3 (diff)
v4.0
Diffstat (limited to 'src')
-rw-r--r--src/createcalls.cpp4
-rw-r--r--src/gl_calls.cpp37
-rw-r--r--src/imgui_ui.cpp2
-rw-r--r--src/imgui_ui_timeline.cpp9
-rw-r--r--src/imgui_ui_viewport.cpp2
-rw-r--r--src/include/defines.h4
-rw-r--r--src/include/main.h2
-rw-r--r--src/include/memory.h8
-rw-r--r--src/main.cpp43
-rw-r--r--src/undo.cpp14
10 files changed, 80 insertions, 45 deletions
diff --git a/src/createcalls.cpp b/src/createcalls.cpp
index fc50b6e..56cf4d8 100644
--- a/src/createcalls.cpp
+++ b/src/createcalls.cpp
@@ -690,6 +690,10 @@ Property_IsGraphSelected(memory *Memory, property_channel *Property, uint16 *Arr
return 0;
}
+// TODO(fox): It seems like duping many layers at once causes this to take up
+// exponentially more data on the undo tree than it should. Rewrite the loop to
+// change the offsets before duping, taking into account all dupes, like what
+// the sorting code does.
// TODO(fox): Add different modes (all dupes on top, each dupe above its layer, two for bottom)
static void
Sort_OffsetDupes(memory *Memory, sorted_layer_array *SortedLayerStart, block_layer *StartLayer,
diff --git a/src/gl_calls.cpp b/src/gl_calls.cpp
index 8d5ef8c..5d65100 100644
--- a/src/gl_calls.cpp
+++ b/src/gl_calls.cpp
@@ -116,11 +116,6 @@ static void GL_InitDefaultVerts() {
glBindBuffer(GL_ARRAY_BUFFER, DefaultVerts.VertexBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(GL_DefaultVertices), GL_DefaultVertices, GL_STATIC_DRAW);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
- glEnableVertexAttribArray(1);
-
glGenVertexArrays(1, &ShapeVerts.VertexArrayObject);
glGenBuffers(1, &ShapeVerts.VertexBufferObject);
}
@@ -212,20 +207,17 @@ GL_BlitStencil(gl_effect_layer *TestM, void *StrokeData, void *FillData, uint32
glUniform3f(Uniform, 0, 0, 0);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
- glBindVertexArray(0);
+ glBindVertexArray(ShapeVerts.VertexArrayObject);
glStencilFunc(GL_EQUAL, StencilLayer, 0xFF);
glStencilOp(GL_KEEP, GL_KEEP, Mode);
- // fill
- // vertices
- glBindBuffer(GL_ARRAY_BUFFER, ShapeVerts.VertexBufferObject);
- glBufferData(GL_ARRAY_BUFFER, sizeof(real32) * 4 * FillCount, FillData, GL_STATIC_DRAW);
- glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
+ glBindBuffer(GL_ARRAY_BUFFER, ShapeVerts.VertexBufferObject);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(real32) * 4 * FillCount, FillData, GL_STATIC_DRAW);
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
- glDrawElements(GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_INT, 0);
- //
+ glDrawArrays(GL_TRIANGLE_FAN, 0, FillCount);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glBindVertexArray(0);
@@ -264,11 +256,11 @@ GL_RasterizeShape2(gl_effect_layer *TestM, void *StrokeData, void *FillData, uin
// the stencil buffer, but since we also are using it to mask out precomps,
// every shape has to be drawn a second time to "clean up" the buffer.
- if (RenderMode & gl_renderflag_fill && RenderMode & gl_renderflag_concave)
+ if (RenderMode & gl_renderflag_fill && !(RenderMode & gl_renderflag_convex))
{
// disable color component writing and allow stencil writing using the shape layer's vertices
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
- glBindVertexArray(0);
+ glBindVertexArray(ShapeVerts.VertexArrayObject);
glStencilFunc(GL_ALWAYS, 0, 0xFF);
glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR_WRAP);
@@ -279,6 +271,8 @@ GL_RasterizeShape2(gl_effect_layer *TestM, void *StrokeData, void *FillData, uin
Uniform = glGetUniformLocation(DefaultShaderProgram, "FragmentMode");
glUniform1i(Uniform, 1);
+ glBindVertexArray(ShapeVerts.VertexArrayObject);
+
glBindBuffer(GL_ARRAY_BUFFER, ShapeVerts.VertexBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(real32) * 4 * FillCount, FillData, GL_STATIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
@@ -291,7 +285,7 @@ GL_RasterizeShape2(gl_effect_layer *TestM, void *StrokeData, void *FillData, uin
// allow color component writing
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glBindVertexArray(0);
+ glBindVertexArray(DefaultVerts.VertexArrayObject);
glStencilFunc(GL_EQUAL, StencilLayer + 1, 0xFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
@@ -318,7 +312,7 @@ GL_RasterizeShape2(gl_effect_layer *TestM, void *StrokeData, void *FillData, uin
// get cleaned by setting StencilOp to GL_DECR.
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
- glBindVertexArray(0);
+ glBindVertexArray(DefaultVerts.VertexArrayObject);
glStencilFunc(GL_ALWAYS, 0, 0xFF);
glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_DECR_WRAP);
@@ -329,6 +323,8 @@ GL_RasterizeShape2(gl_effect_layer *TestM, void *StrokeData, void *FillData, uin
Uniform = glGetUniformLocation(DefaultShaderProgram, "FragmentMode");
glUniform1i(Uniform, 1);
+ glBindVertexArray(ShapeVerts.VertexArrayObject);
+
glBindBuffer(GL_ARRAY_BUFFER, ShapeVerts.VertexBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(real32) * 4 * FillCount, FillData, GL_STATIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
@@ -341,7 +337,7 @@ GL_RasterizeShape2(gl_effect_layer *TestM, void *StrokeData, void *FillData, uin
else if (RenderMode & gl_renderflag_fill)
{
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glBindVertexArray(0);
+ glBindVertexArray(ShapeVerts.VertexArrayObject);
glStencilFunc(GL_EQUAL, StencilLayer, 0xFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
@@ -370,6 +366,7 @@ GL_RasterizeShape2(gl_effect_layer *TestM, void *StrokeData, void *FillData, uin
// stroke component
if (RenderMode & gl_renderflag_stroke)
{
+ glBindVertexArray(ShapeVerts.VertexArrayObject);
Uniform = glGetUniformLocation(DefaultShaderProgram, "VertexMode");
glUniform1i(Uniform, 1);
Uniform = glGetUniformLocation(DefaultShaderProgram, "FragmentMode");
diff --git a/src/imgui_ui.cpp b/src/imgui_ui.cpp
index 5d8b319..62fcb2a 100644
--- a/src/imgui_ui.cpp
+++ b/src/imgui_ui.cpp
@@ -721,8 +721,8 @@ ImGui_Menu(project_data *File, project_state *State, ui *UI, memory *Memory, ImG
#if STABLE
if (ImGui::Selectable("Stable Diffusion tools", UI->StableEnabled))
UI->StableEnabled ^= 1;
- ImGui::EndMenu();
#endif
+ ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
diff --git a/src/imgui_ui_timeline.cpp b/src/imgui_ui_timeline.cpp
index aa4d0cd..964f7c5 100644
--- a/src/imgui_ui_timeline.cpp
+++ b/src/imgui_ui_timeline.cpp
@@ -653,12 +653,21 @@ ImGui_Timeline_DrawPrecomp(project_data *File, project_state *State, memory *Mem
ImVec2 ColSize(Size, Size);
if (ImGui::Button("##test", ColSize)) {
int h = 0, z = 0, i = 0;
+ bool32 Commit = false;
while (Block_Loop(Memory, F_Layers, File->Layer_Count, &h, &z, &i)) {
block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i);
if (Layer->IsSelected & 0x01) {
+ if (!Commit) {
+ History_Entry_Commit(Memory, "Change layer colors");
+ Commit = true;
+ }
+ History_Action_Swap(Memory, F_Layers, sizeof(Layer->ColIndex), &Layer->ColIndex);
Layer->ColIndex = c;
}
}
+ if (Commit) {
+ History_Entry_End(Memory);
+ }
}
if ((c+1) % 4) { ImGui::SameLine(); }
ImGui::PopStyleColor();
diff --git a/src/imgui_ui_viewport.cpp b/src/imgui_ui_viewport.cpp
index 103d325..4b6f6ce 100644
--- a/src/imgui_ui_viewport.cpp
+++ b/src/imgui_ui_viewport.cpp
@@ -619,7 +619,7 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
}
ImGui::SetCursorScreenPos(io.MousePos - ScaleHandleSize/2);
- ImGui::Button("##mover", ScaleHandleSize);
+ ImGui::InvisibleButton("##mover", ScaleHandleSize);
if (!State->InteractTransformMode && ImGui::IsItemActivated() && !OtherActions) {
State->Interact_Active = interact_type_viewport_transform_gizmo;
State->InteractTransformMode = 3;
diff --git a/src/include/defines.h b/src/include/defines.h
index 2100c07..884ab46 100644
--- a/src/include/defines.h
+++ b/src/include/defines.h
@@ -31,8 +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_HISTORY_ENTRIES 2048
+#define MAX_HISTORY_ACTIONS 8192
#define MAX_COMPS 1024
#define MAX_PRECOMP_RECURSIONS 4
#define MAX_MASKS 8
diff --git a/src/include/main.h b/src/include/main.h
index da037dc..10604cb 100644
--- a/src/include/main.h
+++ b/src/include/main.h
@@ -402,7 +402,7 @@ enum gl_shape_renderflags
{
gl_renderflag_fill = 1 << 0,
gl_renderflag_stroke = 1 << 1,
- gl_renderflag_concave = 1 << 2
+ gl_renderflag_convex = 1 << 2
};
struct gl_data
diff --git a/src/include/memory.h b/src/include/memory.h
index ae3fd61..c312c8f 100644
--- a/src/include/memory.h
+++ b/src/include/memory.h
@@ -46,12 +46,12 @@ struct history_action {
uint64 Size;
uint64 ByteOffset;
uint64 ShiftAmount; // Only for type_shift
- int16 Direction; // Only for type_shift
+ int32 Direction; // Only for type_shift
};
struct history_entry {
char *Name;
- uint16 NumberOfActions;
+ uint32 NumberOfActions;
};
@@ -59,8 +59,8 @@ struct history_entry {
struct history_entry_list {
history_entry Entry[MAX_HISTORY_ENTRIES];
history_action Action[MAX_HISTORY_ACTIONS];
- uint16 NumberOfEntries;
- uint16 EntryPlayhead;
+ uint32 NumberOfEntries;
+ uint32 EntryPlayhead;
};
struct memory {
diff --git a/src/main.cpp b/src/main.cpp
index 0b57e99..0bac544 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -300,6 +300,8 @@ GL_Test(const ImDrawList* parent_list, const ImDrawCmd* cmd)
gl_viewport_data *RenderData = (gl_viewport_data *)cmd->UserCallbackData;
gl_effect_layer MSBuffer = {};
+ int err = 0;
+
int A[4] = {};
glGetIntegerv(GL_VIEWPORT, A);
@@ -321,6 +323,8 @@ GL_Test(const ImDrawList* parent_list, const ImDrawCmd* cmd)
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
+ // printf("%i\n", RenderData->LayerCount);
+
for (int i = 0; i < RenderData->LayerCount; i++) {
gl_data *Data = RenderData->LayerEntry[i];
@@ -619,14 +623,32 @@ Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDr
}
T = Transform_TestInteracts(State, Layer, SortEntry, T);
+ int Width = 0, Height = 0;
+ Layer_GetDimensions(Memory, Layer, &Width, &Height);
+
+ // quick test to see if layer is outside viewport
+ if (CompIndex == File->PrincipalCompIndex) {
+ int MaxDist = (Width > Height) ? Width : Height;
+ v2 Pos = V2(T.x, T.y);
+ v2 Min = Pos - V2(MaxDist / 2);
+ v2 Max = Pos + V2(MaxDist / 2);
+ ImVec2 ScreenMin = UI->CompPos + (IV2(Min) / ImVec2(Comp->Width, Comp->Height)) * UI->CompZoom;
+ ImVec2 ScreenMax = UI->CompPos + (IV2(Max) / ImVec2(Comp->Width, Comp->Height)) * UI->CompZoom;
+ if (ScreenMax.x < RenderData->ViewportMin.x ||
+ ScreenMin.x > RenderData->ViewportMax.x ||
+ ScreenMin.y > RenderData->ViewportMax.y ||
+ ScreenMax.y < RenderData->ViewportMin.y)
+ continue;
+ }
+
if (Layer->IsShapeLayer) {
void *Data = PointBuffer;
shape_layer *Shape = &Layer->Shape;
shape_options ShapeOpt = Layer->ShapeOpt;
if (ShapeOpt.StrokeWidth == 0.0f) {
if (ShapeOpt.Visibility == 0)
- ShapeOpt.Visibility = 2;
- if (ShapeOpt.Visibility == 1)
+ ShapeOpt.Visibility = 1;
+ if (ShapeOpt.Visibility == 2)
continue;
}
bool32 IsConvex = 0;
@@ -639,21 +661,21 @@ Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDr
uint32 StrokeCount = 0;
int RenderFlags = 0;
- if (ShapeOpt.Visibility == 1 || ShapeOpt.Visibility == 2) {
+ if (ShapeOpt.Visibility == 0 || ShapeOpt.Visibility == 2) {
RenderFlags |= gl_renderflag_stroke;
StrokeCount = NVG_ExpandStroke(Memory, NumberOfVerts, ShapeOpt.StrokeWidth, ShapeOpt.LineCapType, ShapeOpt.LineJoinType, Shape->IsClosed, (nvg_point *)Data, (real32 *)Data_Stroke, &IsConvex);
PointBuffer += StrokeCount * sizeof(real32) * 4;
Data_Fill = PointBuffer;
}
- if (ShapeOpt.Visibility == 0 || ShapeOpt.Visibility == 2) {
+ if (ShapeOpt.Visibility == 0 || ShapeOpt.Visibility == 1) {
RenderFlags |= gl_renderflag_fill;
NVG_ExpandFill(Memory, NumberOfVerts, (nvg_point *)Data, (real32 *)Data_Fill);
PointBuffer += NumberOfVerts * sizeof(real32) * 4;
}
if (!IsConvex)
- RenderFlags |= gl_renderflag_concave;
+ RenderFlags |= gl_renderflag_convex;
// zero to set the framebuffer to main
gl_effect_layer TestL = {};
@@ -674,11 +696,10 @@ Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDr
if (ExtraT.scale != 0) {
NewExtraT = Transform_Add(NewExtraT, ExtraT, Comp->Width, Comp->Height);
}
+
gl_data *GL_Data = RenderData->LayerEntry[RenderData->LayerCount] = (gl_data *)PointBuffer;
RenderData->LayerCount++;
PointBuffer += sizeof(gl_data);
- int Width = 0, Height = 0;
- Layer_GetDimensions(Memory, Layer, &Width, &Height);
GL_Data->Type = 1;
GL_Data->T = NewExtraT;
GL_Data->Width = Width;
@@ -713,9 +734,6 @@ Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDr
GL_Data->FillCount = 4;
} else {
Assert(0);
- int Width = 0, Height = 0;
- Layer_GetDimensions(Memory, Layer, &Width, &Height);
-
gl_data *GL_Data = RenderData->LayerEntry[RenderData->LayerCount] = (gl_data *)PointBuffer;
RenderData->LayerCount++;
PointBuffer += sizeof(gl_data);
@@ -1142,16 +1160,17 @@ int main(int argc, char *argv[]) {
ScreenSize[1] = 1080;
}
#endif
- SDL_Window* window = SDL_CreateWindow("Event Tester", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, ScreenSize[0], ScreenSize[1], window_flags);
+ SDL_Window* window = SDL_CreateWindow("Event Tester", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, ScreenSize[0], ScreenSize[1] - 80, window_flags);
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync
- if (!gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress))
+ if (!gladLoadGL((GLADloadfunc)SDL_GL_GetProcAddress))
{
printf("Failed to initialize GLAD");
return -1;
}
+ gladInstallGLDebug();
GL_InitDefaultShader();
GL_InitDefaultVerts();
diff --git a/src/undo.cpp b/src/undo.cpp
index c26ab1b..627a0d5 100644
--- a/src/undo.cpp
+++ b/src/undo.cpp
@@ -231,20 +231,24 @@ void History_Entry_End(memory *Memory)
}
static void
-History_Purge(memory *Memory, history_entry_list *History, uint64 ActionCount_Total, uint64 ActionOffset_Total, uint64 PurgeSize)
+History_Purge(memory *Memory, history_entry_list *History, uint64 ActionCount_Total, uint64 ActionOffset_Total, uint64 PurgeSize, uint16 PurgeCount = 0)
{
int Size = 0;
int EntryIndex = 0;
int ActionIndex = 0;
int ActionCount = 0;
- while (Size < PurgeSize) {
+ bool32 Test = 1;
+ while (Test) {
history_entry *Entry = &History->Entry[EntryIndex];
ActionCount += Entry->NumberOfActions;
+ if (ActionCount >= 4060)
+ int b = 0;
while (ActionIndex < ActionCount) {
Size += History_GetActionSize(History, ActionIndex);
ActionIndex++;
}
EntryIndex++;
+ Test = (PurgeCount == 0) ? (Size < PurgeSize) : (EntryIndex < PurgeCount);
}
int EntryCount = (EntryIndex + 1);
{
@@ -282,8 +286,10 @@ static void History_Action_Add(memory *Memory, history_action ActionData, void *
Entry = &History->Entry[History->EntryPlayhead - 1];
Info = History_GetTreeInfo(History, History->EntryPlayhead - 1);
}
- if (Info.ActionCount_Total > MAX_HISTORY_ACTIONS) {
- Assert(0);
+ if (Info.ActionCount_Total >= MAX_HISTORY_ACTIONS) {
+ History_Purge(Memory, History, Info.ActionCount_Total, Info.ActionOffset_Total, ActionData.Size * 4, History->NumberOfEntries / 4);
+ Entry = &History->Entry[History->EntryPlayhead - 1];
+ Info = History_GetTreeInfo(History, History->EntryPlayhead - 1);
}
history_action *Action = &History->Action[Info.ActionCount_Total];