summaryrefslogtreecommitdiff
path: root/src/gl_calls.cpp
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/gl_calls.cpp
parent1d0d8549411e23394059f420f053cc3ee28dacfb (diff)
youarelazy
Diffstat (limited to 'src/gl_calls.cpp')
-rw-r--r--src/gl_calls.cpp149
1 files changed, 145 insertions, 4 deletions
diff --git a/src/gl_calls.cpp b/src/gl_calls.cpp
index 3db9e6a..0fe2a31 100644
--- a/src/gl_calls.cpp
+++ b/src/gl_calls.cpp
@@ -1,3 +1,7 @@
+#if SPECIAL
+#include "main.h"
+#endif
+
#include "gl_calls.h"
const char *DefaultVertexShaderSource = "#version 330 core\n"
@@ -5,9 +9,12 @@ const char *DefaultVertexShaderSource = "#version 330 core\n"
"layout (location = 1) in vec2 aTexCoord;\n"
"out vec2 TexCoord;\n"
"uniform int VertexMode;\n"
-"uniform vec3 CompDimensions;\n"
+"uniform vec2 CompDimensions;\n"
"uniform vec2 LayerDimensions;\n"
+"uniform vec2 ScreenDimensions;\n"
"uniform vec2 Pos;\n"
+"uniform vec2 UIOffset;\n"
+"uniform vec2 UIZoom;\n"
"uniform vec2 Anchor;\n"
"uniform float Rad;\n"
"uniform float Scale;\n"
@@ -21,7 +28,11 @@ const char *DefaultVertexShaderSource = "#version 330 core\n"
" vec2 XAxis = (Point.x - (Anchor.x * LayerDimensions.x)) * Scale * XRotation;\n"
" vec2 YAxis = (Point.y - (Anchor.y * LayerDimensions.y)) * -Scale * YRotation;\n"
" vec2 CompPoint = Pos + vec2(XAxis + YAxis);\n"
-" gl_Position = vec4(vec2(CompPoint.x / CompDimensions.x, CompPoint.y / CompDimensions.y) * 2 - 1.0f, 0.0f, 1.0);\n"
+" vec2 CompUV = CompPoint / CompDimensions;\n"
+" vec2 ScreenPoint = UIOffset + (CompUV * UIZoom);\n"
+" vec2 ScreenUV = ScreenPoint / ScreenDimensions;\n"
+" vec2 GL_Space = ScreenUV * 2 - vec2(1.0f, 1.0f);\n"
+" gl_Position = vec4(vec2(GL_Space.x, -GL_Space.y), 0.0f, 1.0);\n"
"}\n"
" TexCoord = aTexCoord;\n"
"}\0";
@@ -166,9 +177,131 @@ GL_DeleteHWBuffer(gl_effect_layer *Test)
}
static void
+GL_RasterizeShape2(gl_effect_layer *TestM, void *StrokeData, void *FillData, uint32 StrokeCount, uint32 FillCount,
+ layer_transforms T, int Width, int Height, int BytesPerPixel,
+ int L_Width, int L_Height,v4 StrokeCol, v4 FillCol, int RenderMode, int Vector,
+ ImVec2 ViewportSize, ImVec2 UIPos, ImVec2 UIZoom)
+{
+ int Uniform = 0;
+
+ // stencil buffer
+ glEnable(GL_STENCIL_TEST);
+ glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
+ glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ glClear(GL_STENCIL_BUFFER_BIT);
+ glStencilFunc(GL_ALWAYS, 0, 0xFF);
+ glStencilMask(0xff);
+ glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "CompDimensions");
+ glUniform2f(Uniform, Width, Height);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "LayerDimensions");
+ glUniform2f(Uniform, L_Width, L_Height);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "ScreenDimensions");
+ glUniform2f(Uniform, ViewportSize.x, ViewportSize.y);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "UIOffset");
+ glUniform2f(Uniform, UIPos.x, UIPos.y);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "UIZoom");
+ glUniform2f(Uniform, UIZoom.x, UIZoom.y);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "Pos");
+ glUniform2f(Uniform, T.x, T.y);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "Anchor");
+ glUniform2f(Uniform, T.ax, T.ay);
+ real32 Rad = (T.rotation * (PI / 180));
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "Rad");
+ glUniform1f(Uniform, Rad);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "Scale");
+ glUniform1f(Uniform, T.scale);
+
+ if (RenderMode == 0 || RenderMode == 1)
+ {
+
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "VertexMode");
+ glUniform1i(Uniform, 1);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "FragmentMode");
+ glUniform1i(Uniform, 1);
+
+ // 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)));
+
+ // stencil buffer
+ glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR_WRAP);
+ glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR_WRAP);
+ glDisable(GL_CULL_FACE);
+
+ glDrawArrays(GL_TRIANGLE_FAN, 0, FillCount);
+ //
+
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ glBindVertexArray(0);
+
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "VertexMode");
+ glUniform1i(Uniform, 0);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "FragmentMode");
+ glUniform1i(Uniform, 1);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "InputCol");
+ glUniform3f(Uniform, FillCol.r, FillCol.g, FillCol.b);
+
+ // stencil for fill
+ //
+ // vertices
+ 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);
+
+ // stencil buffer
+ glStencilFunc(GL_NOTEQUAL, 0, 0xFF);
+ glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
+
+ glDrawElements(GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_INT, 0);
+ //
+ } else {
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ }
+
+ // stencil buffer not needed
+ glDisable(GL_STENCIL_TEST);
+ glStencilMask(0xFF);
+ glStencilFunc(GL_ALWAYS, 0, 0xFF);
+
+ glBindVertexArray(0);
+
+ if (RenderMode == 0 || RenderMode == 2) {
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "VertexMode");
+ glUniform1i(Uniform, 1);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "FragmentMode");
+ glUniform1i(Uniform, 1);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "InputCol");
+ glUniform3f(Uniform, StrokeCol.r, StrokeCol.g, StrokeCol.b);
+
+ // stroke
+ //
+ glBindBuffer(GL_ARRAY_BUFFER, ShapeVerts.VertexBufferObject);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(real32) * 4 * StrokeCount, StrokeData, 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)));
+ glEnableVertexAttribArray(1);
+
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, StrokeCount);
+ //
+ }
+}
+
+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 StrokeCol, v4 FillCol, int RenderMode)
+ layer_transforms T, int Width, int Height, int BytesPerPixel, void *EffectBitmapAddress, int L_Width, int L_Height, v4 StrokeCol, v4 FillCol, int RenderMode, int Vector,
+ ImVec2 ViewportSize, ImVec2 UIZoom, ImVec2 UIPos)
{
+#if 0
int Uniform = 0;
glBindTexture(GL_TEXTURE_2D, TestL->Texture);
int ByteFlag = (BytesPerPixel == 4) ? GL_RGBA : GL_RGBA16;
@@ -176,7 +309,8 @@ GL_RasterizeShape(gl_effect_layer *TestL, gl_effect_layer *TestM, void *StrokeDa
glTexImage2D(GL_TEXTURE_2D, 0, ByteFlag, Width, Height, 0, GL_RGBA,
ByteFlag2, EffectBitmapAddress);
- GL_UpdateTexture(TestL, EffectBitmapAddress, Width, Height, BytesPerPixel, 0);
+ if (!Vector)
+ GL_UpdateTexture(TestL, EffectBitmapAddress, Width, Height, BytesPerPixel, 0);
GL_UpdateTexture(TestM, EffectBitmapAddress, Width, Height, BytesPerPixel, 1);
glBindFramebuffer(GL_FRAMEBUFFER, TestM->FramebufferObject);
@@ -196,8 +330,14 @@ GL_RasterizeShape(gl_effect_layer *TestL, gl_effect_layer *TestM, void *StrokeDa
glUniform3f(Uniform, Width, Height, 0);
Uniform = glGetUniformLocation(DefaultShaderProgram, "LayerDimensions");
glUniform2f(Uniform, L_Width, L_Height);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "ScreenDimensions");
+ glUniform2f(Uniform, ViewportSize.x, ViewportSize.y);
Uniform = glGetUniformLocation(DefaultShaderProgram, "Pos");
glUniform2f(Uniform, T.x, T.y);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "CompOffset");
+ glUniform2f(Uniform, UIPos.x, UIPos.y);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "CompZoom");
+ glUniform2f(Uniform, UIZoom.x, UIZoom.y);
Uniform = glGetUniformLocation(DefaultShaderProgram, "Anchor");
glUniform2f(Uniform, T.ax, T.ay);
real32 Rad = (T.rotation * (PI / 180));
@@ -297,6 +437,7 @@ GL_RasterizeShape(gl_effect_layer *TestL, gl_effect_layer *TestM, void *StrokeDa
glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, EffectBitmapAddress);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
+#endif
}
void