summaryrefslogtreecommitdiff
path: root/gl_calls.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gl_calls.cpp')
-rw-r--r--gl_calls.cpp111
1 files changed, 55 insertions, 56 deletions
diff --git a/gl_calls.cpp b/gl_calls.cpp
index 68c2882..fcb7fd9 100644
--- a/gl_calls.cpp
+++ b/gl_calls.cpp
@@ -2,30 +2,30 @@ const char *DefaultVertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"layout (location = 1) in vec2 aTexCoord;\n"
"out vec2 TexCoord;\n"
-"void main()\n"
-"{\n"
-" gl_Position = vec4(aPos, 1.0);\n"
-" TexCoord = aTexCoord;\n"
-"}\0";
-const char *MaskVertexShaderSource = "#version 330 core\n"
-"layout (location = 0) in vec3 aPos;\n"
-"layout (location = 1) in vec2 aTexCoord;\n"
-"out vec2 TexCoord;\n"
+"uniform int VertexMode;\n"
"uniform vec3 CompDimensions;\n"
"void main()\n"
"{\n"
-" gl_Position = vec4(vec2(aPos.x / CompDimensions.x, aPos.y / CompDimensions.y) * 2 - 1.0f, 0.0f, 1.0);\n"
+" if (VertexMode == 0) {\n"
+" gl_Position = vec4(aPos, 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"
+"}\n"
" TexCoord = aTexCoord;\n"
"}\0";
const char *DefaultFragmentShaderSource = "#version 330 core\n"
"out vec4 FragColor;\n"
"in vec2 TexCoord;\n"
"uniform sampler2D Texture;\n"
+"uniform int FragmentMode;\n"
"void main()\n"
"{\n"
-"vec4 ColTest = texture(Texture, TexCoord);\n"
-"ColTest.r += 0.5f;\n"
-"FragColor = ColTest;\n"
+"vec4 Col = texture(Texture, TexCoord);\n"
+" if (FragmentMode == 0) {\n"
+" FragColor = Col;\n"
+"} else {\n"
+" FragColor = vec4(vec3(1.0f), Col.a);\n"
+"}\n"
"}\0";
#if 0
const char *fragmentShaderSource = "#version 330 core\n"
@@ -117,32 +117,8 @@ static void TestGL_InitDefaultShader() {
printf("Shader linkage fail:\n %s", infoLog);
}
- uint32 MaskVertexShader = glCreateShader(GL_VERTEX_SHADER);
-
- glShaderSource(MaskVertexShader, 1, &MaskVertexShaderSource, NULL);
- glCompileShader(MaskVertexShader);
-
- glGetShaderiv(MaskVertexShader, GL_COMPILE_STATUS, &success);
- if(!success) {
- glGetProgramInfoLog(DefaultShaderProgram, 512, NULL, infoLog);
- printf("Shader linkage fail:\n %s", infoLog);
- }
-
- MaskShaderProgram = glCreateProgram();
-
- glAttachShader(MaskShaderProgram, MaskVertexShader);
- glAttachShader(MaskShaderProgram, DefaultFragmentShader);
- glLinkProgram(MaskShaderProgram);
-
- glGetProgramiv(MaskShaderProgram, GL_LINK_STATUS, &success);
- if(!success) {
- glGetProgramInfoLog(MaskShaderProgram, 512, NULL, infoLog);
- printf("Shader linkage fail:\n %s", infoLog);
- }
-
// Default vertex shader is still needed to link to other effects.
glDeleteShader(DefaultFragmentShader);
- glDeleteShader(MaskVertexShader);
}
static void TestGL_InitDefaultVerts() {
@@ -152,8 +128,6 @@ static void TestGL_InitDefaultVerts() {
1, 2, 3
};
- glEnable(GL_MULTISAMPLE);
-
// Indices!
glGenVertexArrays(1, &DefaultVerts.VertexArrayObject);
@@ -176,32 +150,57 @@ static void TestGL_InitDefaultVerts() {
}
void
-TestGL_InitTexture(gl_effect_layer *Test, void *Data, uint16 Width, uint16 Height)
+TestGL_InitTexture(gl_effect_layer *Test)
{
+ glGenFramebuffers(1, &Test->FramebufferObject);
glGenTextures(1, &Test->Texture);
- glBindTexture(GL_TEXTURE_2D, Test->Texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glGenRenderbuffers(1, &Test->Color_Renderbuffer);
+ glGenRenderbuffers(1, &Test->Stencil_Renderbuffer);
+ Test->Initialized = true;
+}
+void
+TestGL_UpdateTexture(gl_effect_layer *Test, void *Data, uint16 Width, uint16 Height, bool32 Multisample)
+{
glViewport(0, 0, Width, Height);
- glGenFramebuffers(1, &Test->FramebufferObject);
+ if (!Test->Initialized) {
+ TestGL_InitTexture(Test);
+ }
- glGenRenderbuffers(1, &Test->Color_Renderbuffer);
- glBindRenderbuffer(GL_RENDERBUFFER, Test->Color_Renderbuffer);
- glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, Width, Height);
+ GLenum Target = GL_TEXTURE_2D;
+ if (Multisample)
+ Target = GL_TEXTURE_2D_MULTISAMPLE;
+
+ glBindTexture(Target, Test->Texture);
+ glTexParameteri(Target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(Target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(Target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(Target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ if (Multisample) {
+ glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGB, Width, Height, GL_TRUE);
+ glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
- GLuint Stencil_Renderbuffer = 0;
- glGenRenderbuffers(1, &Stencil_Renderbuffer);
- glBindRenderbuffer( GL_RENDERBUFFER, (GLuint)Stencil_Renderbuffer );
- glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, Width, Height );
+ glBindRenderbuffer(GL_RENDERBUFFER, Test->Color_Renderbuffer);
+ glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_RGBA8, Width, Height);
+
+ glBindRenderbuffer(GL_RENDERBUFFER, (GLuint)Test->Stencil_Renderbuffer );
+ glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_STENCIL_INDEX8, Width, Height );
+ } else {
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ glBindRenderbuffer(GL_RENDERBUFFER, Test->Color_Renderbuffer);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, Width, Height);
+
+ glBindRenderbuffer(GL_RENDERBUFFER, (GLuint)Test->Stencil_Renderbuffer );
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, Width, Height );
+ }
glBindFramebuffer(GL_FRAMEBUFFER, Test->FramebufferObject);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, Test->Color_Renderbuffer);
- glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, Stencil_Renderbuffer);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, Test->Stencil_Renderbuffer);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
@@ -209,8 +208,8 @@ TestGL_InitTexture(gl_effect_layer *Test, void *Data, uint16 Width, uint16 Heigh
Assert(0);
}
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA,
- GL_UNSIGNED_BYTE, Data);
+ // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA,
+ // GL_UNSIGNED_BYTE, Data);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}