summaryrefslogtreecommitdiff
path: root/src/gl_calls.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gl_calls.cpp')
-rw-r--r--src/gl_calls.cpp121
1 files changed, 113 insertions, 8 deletions
diff --git a/src/gl_calls.cpp b/src/gl_calls.cpp
index 1cb408a..5007148 100644
--- a/src/gl_calls.cpp
+++ b/src/gl_calls.cpp
@@ -1,17 +1,27 @@
#include "gl_calls.h"
const char *DefaultVertexShaderSource = "#version 330 core\n"
-"layout (location = 0) in vec3 aPos;\n"
+"layout (location = 0) in vec3 Point;\n"
"layout (location = 1) in vec2 aTexCoord;\n"
"out vec2 TexCoord;\n"
"uniform int VertexMode;\n"
"uniform vec3 CompDimensions;\n"
+"uniform vec2 LayerDimensions;\n"
+"uniform vec2 Pos;\n"
+"uniform vec2 Anchor;\n"
+"uniform float Rad;\n"
+"uniform float Scale;\n"
"void main()\n"
"{\n"
" if (VertexMode == 0) {\n"
-" gl_Position = vec4(aPos, 1.0);\n"
+" gl_Position = vec4(Point, 1.0);\n"
"} else {\n"
-" gl_Position = vec4(vec2(aPos.x / CompDimensions.x, aPos.y / CompDimensions.y) * 2 - 1.0f, 0.0f, 1.0);\n"
+" vec2 XRotation = vec2(cos(Rad), sin(Rad));\n"
+" vec2 YRotation = vec2(sin(Rad), -cos(Rad));\n"
+" vec2 XAxis = (Point.x - (Anchor.x * LayerDimensions.x)) * Scale * XRotation;\n"
+" vec2 YAxis = (Point.y - (Anchor.y * LayerDimensions.y)) * -Scale * YRotation;\n"
+" vec2 LocalPoint = Pos + vec2(XAxis + YAxis);\n"
+" gl_Position = vec4(vec2(LocalPoint.x / CompDimensions.x, LocalPoint.y / CompDimensions.y) * 2 - 1.0f, 0.0f, 1.0);\n"
"}\n"
" TexCoord = aTexCoord;\n"
"}\0";
@@ -83,25 +93,24 @@ static void GL_InitDefaultVerts() {
1, 2, 3
};
- // Indices!
glGenVertexArrays(1, &DefaultVerts.VertexArrayObject);
-
glGenBuffers(1, &DefaultVerts.ElementBufferObject);
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, DefaultVerts.ElementBufferObject);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLIndices), GLIndices,
GL_STATIC_DRAW);
glGenBuffers(1, &DefaultVerts.VertexBufferObject);
- // Our vertices need to be stored in this buffer.
glBindBuffer(GL_ARRAY_BUFFER, DefaultVerts.VertexBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(GL_DefaultVertices), GL_DefaultVertices, GL_STATIC_DRAW);
- // position attribute
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
- // texture coordinate (note the last parameter's offset)
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
+
+ glGenVertexArrays(1, &ShapeVerts.VertexArrayObject);
+ glGenBuffers(1, &ShapeVerts.VertexBufferObject);
}
void
@@ -156,6 +165,102 @@ GL_DeleteHWBuffer(gl_effect_layer *Test)
}
void
+GL_RasterizeShape(gl_effect_layer *TestL, gl_effect_layer *TestM, void *PointData, uint32 GL_PointCount,
+ layer_transforms T, int Width, int Height, int BytesPerPixel, void *EffectBitmapAddress, int L_Width, int L_Height)
+{
+ glBindTexture(GL_TEXTURE_2D, TestL->Texture);
+ int ByteFlag = (BytesPerPixel == 4) ? GL_RGBA : GL_RGBA16;
+ int ByteFlag2 = (BytesPerPixel == 4) ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT;
+ glTexImage2D(GL_TEXTURE_2D, 0, ByteFlag, Width, Height, 0, GL_RGBA,
+ ByteFlag2, EffectBitmapAddress);
+
+ GL_UpdateTexture(TestL, EffectBitmapAddress, Width, Height, BytesPerPixel, 0);
+ GL_UpdateTexture(TestM, EffectBitmapAddress, Width, Height, BytesPerPixel, 1);
+
+ glBindFramebuffer(GL_FRAMEBUFFER, TestM->FramebufferObject);
+
+ // stencil buffer
+ glEnable(GL_STENCIL_TEST);
+ glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
+ glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+ glStencilFunc(GL_ALWAYS, 0, 0xFF);
+ glStencilMask(0xff);
+ glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+
+ glUseProgram(DefaultShaderProgram);
+
+ int Uniform = glGetUniformLocation(DefaultShaderProgram, "VertexMode");
+ glUniform1i(Uniform, 1);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "FragmentMode");
+ glUniform1i(Uniform, 1);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "CompDimensions");
+ glUniform3f(Uniform, Width, Height, 0);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "LayerDimensions");
+ glUniform2f(Uniform, L_Width, L_Height);
+ 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);
+
+ glBindBuffer(GL_ARRAY_BUFFER, ShapeVerts.VertexBufferObject);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(real32) * 4 * GL_PointCount, PointData, 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);
+
+ // 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_STRIP, 0, GL_PointCount);
+
+ // stencil buffer
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+
+ // default verts
+ glBindVertexArray(0);
+ Uniform = glGetUniformLocation(DefaultShaderProgram, "VertexMode");
+ glUniform1i(Uniform, 0);
+ 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);
+
+ // stencil buffer
+ glDisable(GL_STENCIL_TEST);
+ glStencilMask(0xFF);
+ glStencilFunc(GL_ALWAYS, 0, 0xFF);
+
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, TestM->FramebufferObject);
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, TestL->FramebufferObject);
+ glBlitFramebuffer(0, 0, Width, Height, 0, 0, Width, Height,
+ GL_COLOR_BUFFER_BIT, GL_NEAREST);
+ glBindFramebuffer(GL_FRAMEBUFFER, TestL->FramebufferObject);
+
+ glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, EffectBitmapAddress);
+
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ // GL_DeleteHWBuffer(TestL);
+ // GL_DeleteHWBuffer(TestM);
+}
+
+void
GL_UpdateTexture(gl_effect_layer *Test, void *Data, uint16 Width, uint16 Height, uint16 BytesPerPixel, bool32 Multisample)
{
glViewport(0, 0, Width, Height);