summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gl_calls.cpp78
-rw-r--r--src/imgui_ui.cpp7
-rw-r--r--src/include/main.h1
-rw-r--r--src/main.cpp7
-rw-r--r--src/memory.cpp5
5 files changed, 81 insertions, 17 deletions
diff --git a/src/gl_calls.cpp b/src/gl_calls.cpp
index 82e8be2..68380aa 100644
--- a/src/gl_calls.cpp
+++ b/src/gl_calls.cpp
@@ -4,6 +4,9 @@
#include "gl_calls.h"
+
+// TODO(fox): Combine into one after fixing Mac/Windows blend mode slowdown.
+
const char *DefaultVertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 Point;\n"
"layout (location = 1) in vec2 aTexCoord;\n"
@@ -52,11 +55,6 @@ const char *DefaultFragmentShaderSource = "#version 330 core\n"
" FragColor = vec4(InputCol, Col.a);\n"
"} else if (FragmentMode == 2) {\n"
" FragColor = Col;\n"
-"} else {\n"
-" vec4 Dest = texture(Texture1, TexCoord);\n"
-" FragColor = Dest + Col;\n"
-" FragColor = ((1.0f - Dest * 2) * Col * Col) + (Dest * 2 * Col);\n"
-" FragColor.a = Col.a;\n"
"}\n"
"}\0";
@@ -111,12 +109,15 @@ const char *BlendVertexShaderSource = "#version 330 core\n"
"}\0";
#endif
+// NOTE(fox): Is this slower than using multiple fragment shaders with less source code?
+// TODO(fox): Multiply and add can be optimized without the texture copy.
const char *BlendFragmentShaderSource = "#version 330 core\n"
"out vec4 FragColor;\n"
"in vec2 TexCoord;\n"
"in vec2 TexCoordBlend;\n"
"uniform sampler2D Texture;\n"
"uniform sampler2D Texture1;\n"
+"uniform int BlendMode;\n"
"uniform vec3 InputCol;\n"
"uniform vec2 ScreenDimensions;\n"
"void main()\n"
@@ -124,12 +125,68 @@ const char *BlendFragmentShaderSource = "#version 330 core\n"
" vec2 NewCoord = gl_FragCoord.xy / ScreenDimensions;\n"
" vec4 Col = texture(Texture, TexCoord);\n"
" vec4 Dest = texture(Texture1, NewCoord);\n"
-" FragColor = Dest + Col;\n"
-" FragColor = ((1.0f - Dest * 2) * Col * Col) + (Dest * 2 * Col);\n"
+" vec4 Blend = Dest;\n"
+" FragColor.a = Dest.a;\n"
+" switch (BlendMode)\n"
+" {\n"
+" case 0:\n"
+" {\n"
+" FragColor.a = Col.a;\n"
+" } break;\n"
+" case 1:\n"
+" {\n"
+" Blend = Dest * Col;\n"
+" } break;\n"
+" case 2:\n"
+" {\n"
+" Blend = 1.0f - ((1.0f - Dest) / Col);\n"
+" } break;\n"
+" case 3:\n"
+" {\n"
+" Blend = (Dest + Col) - 1.0f;\n"
+" } break;\n"
+" case 4:\n"
+" {\n"
+" Blend = Dest + Col;\n"
+" } break;\n"
+" case 5:\n"
+" {\n"
+" Blend = 1.0f - ((1.0f - Dest) * (1.0f - Col));\n"
+" } break;\n"
+" case 6:\n"
+" {\n"
+" Blend = 2.0f * Dest * Col;\n"
+" vec4 BlendSecond = 1.0f - (2.0f * (1.0f - Dest) * (1.0f - Col));\n"
+" Blend = mix(BlendSecond, Blend, lessThan(Dest, vec4(0.5)));\n"
+" } break;\n"
+" case 7:\n"
+" {\n"
+" Blend = ((1.0f - Col * 2) * Dest * Dest) + (Col * 2 * Dest);\n"
+" } break;\n"
+" case 8:\n"
+" {\n"
+" Blend = 2.0f * Dest * Col;\n"
+" vec4 BlendSecond = 1.0f - (2.0f * (1.0f - Dest) * (1.0f - Col));\n"
+" Blend = mix(BlendSecond, Blend, greaterThan(Dest, vec4(0.5)));\n"
+" } break;\n"
+" case 9:\n"
+" {\n"
+" Blend = Dest - Col;\n"
+" } break;\n"
+" case 10:\n"
+" {\n"
+" Blend = Dest / (Col + 0.001f);\n"
+" } break;\n"
+" case 11:\n"
+" {\n"
+" Blend = Col - Dest;\n"
+" vec4 BlendSecond = Dest - Col;\n"
+" Blend = mix(BlendSecond, Blend, greaterThan(Col - Dest, vec4(0.0f)));\n"
+" } break;\n"
+" }\n"
+" FragColor.rgb = Blend.rgb ;\n"
"}\0";
-// " vec2 NewCoord = vec2(0.5, 0.5) + vec2(XAxis + YAxis);\n"
-
static void GL_InitDefaultShader(uint32 *VertexShader, const char *VertexShaderSource,
uint32 *FragmentShader, const char *FragmentShaderSource,
uint32 *ShaderProgram)
@@ -305,7 +362,7 @@ GL_BlitStencil(gl_effect_layer *TestM, void *StrokeData, void *FillData, uint32
static void
GL_RasterizeShape2(gl_effect_layer *TestM, gl_effect_layer *TestM2, void *StrokeData, void *FillData, uint32 StrokeCount, uint32 FillCount,
layer_transforms T, int Width, int Height, int BytesPerPixel, void *Bitmap,
- int L_Width, int L_Height,v4 StrokeCol, v4 FillCol, int RenderMode, int Vector,
+ int L_Width, int L_Height,v4 StrokeCol, v4 FillCol, blend_mode BlendMode, int RenderMode, int Vector,
ImVec2 ViewportSize, ImVec2 UIPos, ImVec2 UIZoom, v2 BlendMin, v2 BlendMax, int StencilLayer)
{
int Uniform = 0;
@@ -444,6 +501,7 @@ GL_RasterizeShape2(gl_effect_layer *TestM, gl_effect_layer *TestM2, void *Stroke
glBindTexture(GL_TEXTURE_2D, TestM2->Texture);
glUniform1i(glGetUniformLocation(BlendShaderProgram, "Texture"), 0);
glUniform1i(glGetUniformLocation(BlendShaderProgram, "Texture1"), 1);
+ glUniform1i(glGetUniformLocation(BlendShaderProgram, "BlendMode"), BlendMode);
} else {
glGenTextures(1, &Texture);
glBindTexture(GL_TEXTURE_2D, Texture);
diff --git a/src/imgui_ui.cpp b/src/imgui_ui.cpp
index 57d3f79..546392a 100644
--- a/src/imgui_ui.cpp
+++ b/src/imgui_ui.cpp
@@ -596,11 +596,12 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me
if (ImGui::IsKeyPressed(ImGuiKey_Delete))
{
- Bezier_Delete_Selected(File, State, Memory,
- Sorted.LayerArray, Sorted.CompArray,
- Sorted.PropertyStart, Sorted.PropertyArray);
+ State->HotkeyInput = hotkey_deletelayer;
#if 0
if (State->FocusedWindow == focus_timeline) {
+ Bezier_Delete_Selected(File, State, Memory,
+ Sorted.LayerArray, Sorted.CompArray,
+ Sorted.PropertyStart, Sorted.PropertyArray);
} else {
State->HotkeyInput = hotkey_deletelayer;
}
diff --git a/src/include/main.h b/src/include/main.h
index 46aed98..68df39d 100644
--- a/src/include/main.h
+++ b/src/include/main.h
@@ -422,6 +422,7 @@ struct gl_data
real32 Width;
real32 Height;
void *BitmapData;
+ blend_mode BlendMode;
int RenderMode;
v2 BlendMin;
diff --git a/src/main.cpp b/src/main.cpp
index 91a8ef2..894238a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -353,7 +353,7 @@ GL_Test(const ImDrawList* parent_list, const ImDrawCmd* cmd)
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
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,
+ Data->Width, Data->Height, Data->StrokeCol, Data->FillCol, Data->BlendMode, Data->RenderMode, 0,
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,
@@ -709,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, NULL, RenderFlags };
+ T, Shape->Width, Shape->Height, NULL, Layer->BlendMode, RenderFlags };
} else if (Layer->IsPrecomp) {
layer_transforms NewExtraT = Layer_GetTransforms(Layer);
@@ -892,6 +892,7 @@ Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDr
GL_Data->BlendMin = Min;
GL_Data->BlendMax = Max;
}
+ GL_Data->BlendMode = Layer->BlendMode;
GL_Data->BitmapData = BitmapAddress;
GL_Data->T = T;
GL_Data->RenderMode = gl_renderflag_convex | gl_renderflag_fill | gl_renderflag_texture | Blend;
@@ -1691,7 +1692,7 @@ int main(int argc, char *argv[]) {
uint64 TotalTime = GetCPUTime() - StartTime;
// printf("TOTAL: %.2lu, (%.2f ms) - INPUTS: %.2lu - RENDERING: %.2lu\n", PerfTime, FrameMS, InputTime, RenderTime);
#if DEBUG
- printf("TOTAL: %.2lu (%.2f ms) - INPUTS: %.2lu (%.2f) - RENDERING: %.2lu (%.2f)\n", TotalTime, FrameMS, InputTime, (real64)InputTime / TotalTime, RenderTime, (real64)RenderTime / TotalTime);
+ // printf("TOTAL: %.2lu (%.2f ms) - INPUTS: %.2lu (%.2f) - RENDERING: %.2lu (%.2f)\n", TotalTime, FrameMS, InputTime, (real64)InputTime / TotalTime, RenderTime, (real64)RenderTime / TotalTime);
#endif
// printf("TOTAL: %.2lu, (%.2f ms) - RENDERING: %.2lu\n", PerfTime, FrameMS, PerfTime);
}
diff --git a/src/memory.cpp b/src/memory.cpp
index fc82a13..9503b00 100644
--- a/src/memory.cpp
+++ b/src/memory.cpp
@@ -291,8 +291,10 @@ void Memory_Fill(uint8 *Address_Write, uint8 *Address_Read, uint64 WriteSize, ui
void Arbitrary_Zero(uint8 *Address_Write, uint64 Size)
{
- __m256i Zero256 = _mm256_setzero_si256();
uint64 i = 0;
+#if ARM
+#else
+ __m256i Zero256 = _mm256_setzero_si256();
if (Size > 64 && InstructionMode == instruction_mode_avx) {
uint64 Size_Lane = Size - (Size % 64);
while (i < Size_Lane) {
@@ -301,6 +303,7 @@ void Arbitrary_Zero(uint8 *Address_Write, uint64 Size)
i += 64;
}
}
+#endif
while (i < Size) {
*(Address_Write + i) = 0;
i++;