diff options
author | RSDuck <rsduck@users.noreply.github.com> | 2021-01-02 08:55:48 +0100 |
---|---|---|
committer | RSDuck <rsduck@users.noreply.github.com> | 2021-01-02 08:55:48 +0100 |
commit | 18fe5c67592b560236b7f0ed9663826293648626 (patch) | |
tree | 44fefe21551f903c2d7e5918c47642f4f3085535 /src | |
parent | fa4363ede69bcef919310863ba262c9691c179e6 (diff) |
prevent bleeding in screen texture
fixes #920
Diffstat (limited to 'src')
-rw-r--r-- | src/GPU_OpenGL.cpp | 52 | ||||
-rw-r--r-- | src/GPU_OpenGL_shaders.h | 3 | ||||
-rw-r--r-- | src/frontend/qt_sdl/main.cpp | 25 |
3 files changed, 52 insertions, 28 deletions
diff --git a/src/GPU_OpenGL.cpp b/src/GPU_OpenGL.cpp index 0c6cf00..f60ca97 100644 --- a/src/GPU_OpenGL.cpp +++ b/src/GPU_OpenGL.cpp @@ -40,7 +40,13 @@ GLuint Comp3DXPosLoc[1]; GLuint CompVertexBufferID; GLuint CompVertexArrayID; -float CompVertices[2 * 3*2 * 2]; // position + +struct CompVertex +{ + float Position[2]; + float Texcoord[2]; +}; +CompVertex CompVertices[2 * 3*2]; GLuint CompScreenInputTex; GLuint CompScreenOutputTex; @@ -59,6 +65,7 @@ bool Init() GLint uni_id; glBindAttribLocation(CompShader[i][2], 0, "vPosition"); + glBindAttribLocation(CompShader[i][2], 1, "vTexcoord"); glBindFragDataLocation(CompShader[i][2], 0, "oColor"); if (!OpenGL::LinkShaderProgram(CompShader[i])) @@ -74,25 +81,29 @@ bool Init() glUniform1i(uni_id, 1); } -#define SETVERTEX(i, x, y) \ - CompVertices[2*(i) + 0] = x; \ - CompVertices[2*(i) + 1] = y; + // all this mess is to prevent bleeding +#define SETVERTEX(i, x, y, offset) \ + CompVertices[i].Position[0] = x; \ + CompVertices[i].Position[1] = y + offset; \ + CompVertices[i].Texcoord[0] = (x + 1.f) * (256.f / 2.f); \ + CompVertices[i].Texcoord[1] = (y + 1.f) * (384.f / 2.f) + const float padOffset = 1.f/(192*2.f+2.f)*2.f; // top screen - SETVERTEX(0, -1, 1); - SETVERTEX(1, 1, 0); - SETVERTEX(2, 1, 1); - SETVERTEX(3, -1, 1); - SETVERTEX(4, -1, 0); - SETVERTEX(5, 1, 0); + SETVERTEX(0, -1, 1, 0); + SETVERTEX(1, 1, 0, padOffset); + SETVERTEX(2, 1, 1, 0); + SETVERTEX(3, -1, 1, 0); + SETVERTEX(4, -1, 0, padOffset); + SETVERTEX(5, 1, 0, padOffset); // bottom screen - SETVERTEX(6, -1, 0); - SETVERTEX(7, 1, -1); - SETVERTEX(8, 1, 0); - SETVERTEX(9, -1, 0); - SETVERTEX(10, -1, -1); - SETVERTEX(11, 1, -1); + SETVERTEX(6, -1, 0, -padOffset); + SETVERTEX(7, 1, -1, 0); + SETVERTEX(8, 1, 0, -padOffset); + SETVERTEX(9, -1, 0, -padOffset); + SETVERTEX(10, -1, -1, 0); + SETVERTEX(11, 1, -1, 0); #undef SETVERTEX @@ -103,7 +114,9 @@ bool Init() glGenVertexArrays(1, &CompVertexArrayID); glBindVertexArray(CompVertexArrayID); glEnableVertexAttribArray(0); // position - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2*4, (void*)(0)); + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(CompVertex), (void*)(offsetof(CompVertex, Position))); + glEnableVertexAttribArray(1); // texcoord + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(CompVertex), (void*)(offsetof(CompVertex, Texcoord))); glGenFramebuffers(1, &CompScreenOutputFB); @@ -152,10 +165,13 @@ void SetRenderSettings(RenderSettings& settings) Scale = scale; ScreenW = 256 * scale; - ScreenH = 384 * scale; + ScreenH = (384+2) * scale; glBindTexture(GL_TEXTURE_2D, CompScreenOutputTex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + // fill the padding + u8 zeroPixels[ScreenW*2*scale*4] = {0}; + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192*scale, ScreenW, 2*scale, GL_RGBA, GL_UNSIGNED_BYTE, zeroPixels); GLenum fbassign[] = {GL_COLOR_ATTACHMENT0}; glBindFramebuffer(GL_FRAMEBUFFER, CompScreenOutputFB); diff --git a/src/GPU_OpenGL_shaders.h b/src/GPU_OpenGL_shaders.h index 03ddb7a..44be4d0 100644 --- a/src/GPU_OpenGL_shaders.h +++ b/src/GPU_OpenGL_shaders.h @@ -22,6 +22,7 @@ const char* kCompositorVS = R"(#version 140 in vec2 vPosition; +in vec2 vTexcoord; smooth out vec2 fTexcoord; @@ -33,7 +34,7 @@ void main() fpos.w = 1.0; gl_Position = fpos; - fTexcoord = (vPosition + vec2(1.0, 1.0)) * (vec2(256.0, 384.0) / 2.0); + fTexcoord = vTexcoord; } )"; diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 8e44bf0..d7821fa 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -867,22 +867,26 @@ void ScreenPanelGL::initializeGL() screenShader->setUniformValue("ScreenTex", (GLint)0); screenShader->release(); + // to prevent bleeding between both parts of the screen + // with bilinear filtering enabled + const int paddedHeight = 192*2+2; + const float padPixels = 1.f / paddedHeight; - float vertices[] = + const float vertices[] = { 0, 0, 0, 0, - 0, 192, 0, 0.5, - 256, 192, 1, 0.5, + 0, 192, 0, 0.5 - padPixels, + 256, 192, 1, 0.5 - padPixels, 0, 0, 0, 0, - 256, 192, 1, 0.5, + 256, 192, 1, 0.5 - padPixels, 256, 0, 1, 0, - 0, 0, 0, 0.5, + 0, 0, 0, 0.5 + padPixels, 0, 192, 0, 1, 256, 192, 1, 1, - 0, 0, 0, 0.5, + 0, 0, 0, 0.5 + padPixels, 256, 192, 1, 1, - 256, 0, 1, 0.5 + 256, 0, 1, 0.5 + padPixels }; glGenBuffers(1, &screenVertexBuffer); @@ -903,7 +907,10 @@ void ScreenPanelGL::initializeGL() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 192*2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, paddedHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + // fill the padding + u8 zeroData[256*4*4] = {0}; + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192, 256, 2, GL_RGBA, GL_UNSIGNED_BYTE, zeroData); OSD::Init(this); } @@ -941,7 +948,7 @@ void ScreenPanelGL::paintGL() { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 192, GL_RGBA, GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][0]); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192, 256, 192, GL_RGBA, + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192+2, 256, 192, GL_RGBA, GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]); } } |