diff options
author | Fox Caminiti <fox@foxcam.net> | 2023-01-04 18:30:56 -0500 |
---|---|---|
committer | Fox Caminiti <fox@foxcam.net> | 2023-01-04 18:30:56 -0500 |
commit | eebbdd012b0d156e9e92369585c6ad82ed3de371 (patch) | |
tree | bbaeec7569de49f68bf853158a95c095878cf825 /src/gl_calls.cpp | |
parent | a37ea807e93886e6a6ebc22a878a5649e97f015a (diff) |
shapes; remove stencil buffer?
Diffstat (limited to 'src/gl_calls.cpp')
-rw-r--r-- | src/gl_calls.cpp | 60 |
1 files changed, 52 insertions, 8 deletions
diff --git a/src/gl_calls.cpp b/src/gl_calls.cpp index 5007148..dbc0784 100644 --- a/src/gl_calls.cpp +++ b/src/gl_calls.cpp @@ -30,13 +30,14 @@ const char *DefaultFragmentShaderSource = "#version 330 core\n" "in vec2 TexCoord;\n" "uniform sampler2D Texture;\n" "uniform int FragmentMode;\n" +"uniform vec3 InputCol;\n" "void main()\n" "{\n" "vec4 Col = texture(Texture, TexCoord);\n" " if (FragmentMode == 0) {\n" " FragColor = Col;\n" "} else {\n" -" FragColor = vec4(vec3(1.0f), Col.a);\n" +" FragColor = vec4(InputCol, Col.a);\n" "}\n" "}\0"; @@ -164,9 +165,9 @@ GL_DeleteHWBuffer(gl_effect_layer *Test) Test->Initialized = true; } -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) +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 Col, int RenderMode) { glBindTexture(GL_TEXTURE_2D, TestL->Texture); int ByteFlag = (BytesPerPixel == 4) ? GL_RGBA : GL_RGBA16; @@ -208,8 +209,18 @@ GL_RasterizeShape(gl_effect_layer *TestL, gl_effect_layer *TestM, void *PointDat Uniform = glGetUniformLocation(DefaultShaderProgram, "Scale"); glUniform1f(Uniform, T.scale); +#if 0 + void *PointData = NULL; + int PointCount = 0; + if (RenderMode == 0) { + PointData = FillData; + PointCount = FillCount; + } else { + PointData = StrokeData; + PointCount = StrokeCount; + } glBindBuffer(GL_ARRAY_BUFFER, ShapeVerts.VertexBufferObject); - glBufferData(GL_ARRAY_BUFFER, sizeof(real32) * 4 * GL_PointCount, PointData, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, sizeof(real32) * 4 * 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))); @@ -220,15 +231,50 @@ GL_RasterizeShape(gl_effect_layer *TestL, gl_effect_layer *TestM, void *PointDat glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR_WRAP); glDisable(GL_CULL_FACE); - glDrawArrays(GL_TRIANGLE_STRIP, 0, GL_PointCount); + if (RenderMode == 0) { + glDrawArrays(GL_TRIANGLE_FAN, 0, PointCount); + } else { + glDrawArrays(GL_TRIANGLE_STRIP, 0, PointCount); + } // stencil buffer glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); +#else + 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))); + + 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); + + 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))); + + 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, StrokeCount); + + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); +#endif // default verts glBindVertexArray(0); Uniform = glGetUniformLocation(DefaultShaderProgram, "VertexMode"); glUniform1i(Uniform, 0); + Uniform = glGetUniformLocation(DefaultShaderProgram, "FragmentMode"); + glUniform1i(Uniform, 1); + Uniform = glGetUniformLocation(DefaultShaderProgram, "InputCol"); + glUniform3f(Uniform, Col.r, Col.g, Col.b); 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); @@ -256,8 +302,6 @@ GL_RasterizeShape(gl_effect_layer *TestL, gl_effect_layer *TestM, void *PointDat glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, EffectBitmapAddress); glBindFramebuffer(GL_FRAMEBUFFER, 0); - // GL_DeleteHWBuffer(TestL); - // GL_DeleteHWBuffer(TestM); } void |