Skip to content

Commit 14b1cda

Browse files
committed
Fix scanlines with some OGL drivers
1 parent 74209cb commit 14b1cda

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

platforms/shared/desktop/ogl_renderer.cpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,10 @@
3535
#include "ogl_renderer.h"
3636

3737
static uint32_t system_texture;
38-
static uint32_t scanlines_texture;
3938
static uint32_t frame_buffer_object;
4039
static GG_Runtime_Info current_runtime;
4140
static bool first_frame;
4241
static bool mix_round_error = false;
43-
static u8 scanlines[64] = {
44-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46-
0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255,
47-
0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255};
4842

4943
static uint32_t quad_shader_program = 0;
5044
static uint32_t quad_vao = 0;
@@ -61,7 +55,6 @@ static void init_ogl_gui(void);
6155
static void init_ogl_emu(void);
6256
static void init_ogl_debug(void);
6357
static void init_ogl_savestates(void);
64-
static void init_scanlines_texture(void);
6558
static void init_shaders(void);
6659
static void render_gui(void);
6760
static void render_emu_normal(void);
@@ -107,7 +100,6 @@ void ogl_renderer_destroy(void)
107100
glDeleteFramebuffers(1, &frame_buffer_object);
108101
glDeleteTextures(1, &ogl_renderer_emu_texture);
109102
glDeleteTextures(1, &system_texture);
110-
glDeleteTextures(1, &scanlines_texture);
111103

112104
glDeleteTextures(1, &ogl_renderer_emu_debug_huc6270_background[0]);
113105
glDeleteTextures(1, &ogl_renderer_emu_debug_huc6270_background[1]);
@@ -218,8 +210,6 @@ static void init_ogl_emu(void)
218210
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, SYSTEM_TEXTURE_WIDTH, SYSTEM_TEXTURE_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*) emu_frame_buffer);
219211
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
220212
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
221-
222-
init_scanlines_texture();
223213
}
224214

225215
static void init_ogl_debug(void)
@@ -265,17 +255,6 @@ static void init_ogl_savestates(void)
265255
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
266256
}
267257

268-
static void init_scanlines_texture(void)
269-
{
270-
glGenTextures(1, &scanlines_texture);
271-
glBindTexture(GL_TEXTURE_2D, scanlines_texture);
272-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*) scanlines);
273-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
274-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
275-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
276-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
277-
}
278-
279258
static void render_gui(void)
280259
{
281260
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
@@ -446,8 +425,6 @@ static void render_scanlines(void)
446425
glEnable(GL_BLEND);
447426
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
448427

449-
glBindTexture(GL_TEXTURE_2D, scanlines_texture);
450-
451428
int viewportWidth = current_runtime.screen_width;
452429
int viewportHeight = current_runtime.screen_height * FRAME_BUFFER_SCALE;
453430

@@ -457,7 +434,7 @@ static void render_scanlines(void)
457434
glUseProgram(quad_shader_program);
458435
glUniform2f(quad_uniform_tex_scale, tex_h, tex_v);
459436
glUniform2f(quad_uniform_viewport_size, (float)viewportWidth, (float)viewportHeight);
460-
glUniform1i(quad_uniform_use_fragcoord, 1);
437+
glUniform1i(quad_uniform_use_fragcoord, 2);
461438
glUniform4f(quad_uniform_color, 1.0f, 1.0f, 1.0f, config_video.scanlines_intensity);
462439

463440
glViewport(0, 0, viewportWidth, viewportHeight);
@@ -499,6 +476,12 @@ static void init_shaders(void)
499476
"uniform vec2 uViewportSize;\n"
500477
"uniform int uUseFragCoord;\n"
501478
"void main() {\n"
479+
" if (uUseFragCoord == 2) {\n"
480+
" float row = mod(floor(gl_FragCoord.y), 4.0);\n"
481+
" float mask = row >= 2.0 ? 1.0 : 0.0;\n"
482+
" FragColor = vec4(0.0, 0.0, 0.0, uColor.a * mask);\n"
483+
" return;\n"
484+
" }\n"
502485
" vec2 texCoord = vTexCoord;\n"
503486
" if (uUseFragCoord != 0)\n"
504487
" texCoord = (gl_FragCoord.xy / uViewportSize) * uTexScale;\n"

0 commit comments

Comments
 (0)