diff options
author | Fox Caminiti <fox@foxcam.net> | 2023-02-01 13:11:05 -0500 |
---|---|---|
committer | Fox Caminiti <fox@foxcam.net> | 2023-02-01 13:11:05 -0500 |
commit | a2c1ceedc6c6b3756f8d9b3b9c29798b5d925447 (patch) | |
tree | 8c7e2cb9a6534bf12b5544053ac608ec0dec8dbe /src/gl_calls.cpp | |
parent | c40fb7c82be088db4166e92f131865f72b975f56 (diff) |
sorting and shape updates
Diffstat (limited to 'src/gl_calls.cpp')
-rw-r--r-- | src/gl_calls.cpp | 172 |
1 files changed, 48 insertions, 124 deletions
diff --git a/src/gl_calls.cpp b/src/gl_calls.cpp index 0fe2a31..91dba4f 100644 --- a/src/gl_calls.cpp +++ b/src/gl_calls.cpp @@ -177,21 +177,21 @@ GL_DeleteHWBuffer(gl_effect_layer *Test) } static void -GL_RasterizeShape2(gl_effect_layer *TestM, void *StrokeData, void *FillData, uint32 StrokeCount, uint32 FillCount, +GL_BlitStencil(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); + 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); + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + + int Uniform = 0; Uniform = glGetUniformLocation(DefaultShaderProgram, "CompDimensions"); glUniform2f(Uniform, Width, Height); @@ -213,131 +213,63 @@ GL_RasterizeShape2(gl_effect_layer *TestM, void *StrokeData, void *FillData, uin 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); - + Uniform = glGetUniformLocation(DefaultShaderProgram, "VertexMode"); + glUniform1i(Uniform, 1); + Uniform = glGetUniformLocation(DefaultShaderProgram, "FragmentMode"); + glUniform1i(Uniform, 1); + Uniform = glGetUniformLocation(DefaultShaderProgram, "InputCol"); + glUniform3f(Uniform, 0, 0, 0); + + // 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); + + glDrawElements(GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_INT, 0); + // + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 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, int Vector, - ImVec2 ViewportSize, ImVec2 UIZoom, ImVec2 UIPos) +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, bool32 KeepStencil) { -#if 0 - int Uniform = 0; - 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); - - if (!Vector) - 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); + 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); + if (!KeepStencil) + glClear(GL_STENCIL_BUFFER_BIT); glStencilFunc(GL_ALWAYS, 0, 0xFF); glStencilMask(0xff); - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - glUseProgram(DefaultShaderProgram); + int Uniform = 0; Uniform = glGetUniformLocation(DefaultShaderProgram, "CompDimensions"); - glUniform3f(Uniform, Width, Height, 0); + 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, "Pos"); - glUniform2f(Uniform, T.x, T.y); - Uniform = glGetUniformLocation(DefaultShaderProgram, "CompOffset"); + Uniform = glGetUniformLocation(DefaultShaderProgram, "UIOffset"); glUniform2f(Uniform, UIPos.x, UIPos.y); - Uniform = glGetUniformLocation(DefaultShaderProgram, "CompZoom"); + 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)); @@ -364,7 +296,7 @@ GL_RasterizeShape(gl_effect_layer *TestL, gl_effect_layer *TestM, void *StrokeDa // stencil buffer glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR_WRAP); - glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR_WRAP); + glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR_WRAP); glDisable(GL_CULL_FACE); glDrawArrays(GL_TRIANGLE_FAN, 0, FillCount); @@ -427,17 +359,6 @@ GL_RasterizeShape(gl_effect_layer *TestL, gl_effect_layer *TestM, void *StrokeDa glDrawArrays(GL_TRIANGLE_STRIP, 0, StrokeCount); // } - - 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); -#endif } void @@ -445,6 +366,9 @@ GL_UpdateTexture(gl_effect_layer *Test, void *Data, uint16 Width, uint16 Height, { glViewport(0, 0, Width, Height); + // int err; + // err = glGetError(); Assert(err == 0); + if (!Test->Initialized) { GL_InitHWBuffer(Test); } |