Mercurial > repos > blastem
comparison render_sdl.c @ 2390:9264c847ceb7
Add some uniforms to allow more sophisticated interlace and scanline handling in shaders
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 25 Nov 2023 11:54:56 -0800 |
parents | a8c069d847a0 |
children | a71176b9903d |
comparison
equal
deleted
inserted
replaced
2389:66b3f2eda0c8 | 2390:9264c847ceb7 |
---|---|
301 } | 301 } |
302 } | 302 } |
303 | 303 |
304 static int tex_width, tex_height; | 304 static int tex_width, tex_height; |
305 #ifndef DISABLE_OPENGL | 305 #ifndef DISABLE_OPENGL |
306 static GLuint textures[3], buffers[2], vshader, fshader, program, un_textures[2], un_width, un_height, un_texsize, at_pos; | 306 static GLuint textures[3], buffers[2], vshader, fshader, program; |
307 static GLint un_textures[2], un_width, un_height, un_texsize, un_curfield, un_interlaced, un_scanlines, at_pos; | |
307 | 308 |
308 static GLfloat vertex_data_default[] = { | 309 static GLfloat vertex_data_default[] = { |
309 -1.0f, -1.0f, | 310 -1.0f, -1.0f, |
310 1.0f, -1.0f, | 311 1.0f, -1.0f, |
311 -1.0f, 1.0f, | 312 -1.0f, 1.0f, |
455 un_textures[0] = glGetUniformLocation(program, "textures[0]"); | 456 un_textures[0] = glGetUniformLocation(program, "textures[0]"); |
456 un_textures[1] = glGetUniformLocation(program, "textures[1]"); | 457 un_textures[1] = glGetUniformLocation(program, "textures[1]"); |
457 un_width = glGetUniformLocation(program, "width"); | 458 un_width = glGetUniformLocation(program, "width"); |
458 un_height = glGetUniformLocation(program, "height"); | 459 un_height = glGetUniformLocation(program, "height"); |
459 un_texsize = glGetUniformLocation(program, "texsize"); | 460 un_texsize = glGetUniformLocation(program, "texsize"); |
461 un_curfield = glGetUniformLocation(program, "curfield"); | |
462 un_interlaced = glGetUniformLocation(program, "interlaced"); | |
463 un_scanlines = glGetUniformLocation(program, "scanlines"); | |
460 at_pos = glGetAttribLocation(program, "pos"); | 464 at_pos = glGetAttribLocation(program, "pos"); |
461 } | 465 } |
462 | 466 |
463 static void gl_teardown() | 467 static void gl_teardown() |
464 { | 468 { |
1580 #else | 1584 #else |
1581 #define FPS_INTERVAL 1000 | 1585 #define FPS_INTERVAL 1000 |
1582 #endif | 1586 #endif |
1583 | 1587 |
1584 static uint32_t last_width, last_height; | 1588 static uint32_t last_width, last_height; |
1585 static uint8_t interlaced; | 1589 static uint8_t interlaced, last_field; |
1586 static void process_framebuffer(uint32_t *buffer, uint8_t which, int width) | 1590 static void process_framebuffer(uint32_t *buffer, uint8_t which, int width) |
1587 { | 1591 { |
1588 static uint8_t last; | |
1589 if (sync_src == SYNC_VIDEO && which <= FRAMEBUFFER_EVEN && source_frame_count < 0) { | 1592 if (sync_src == SYNC_VIDEO && which <= FRAMEBUFFER_EVEN && source_frame_count < 0) { |
1590 source_frame++; | 1593 source_frame++; |
1591 if (source_frame >= source_hz) { | 1594 if (source_frame >= source_hz) { |
1592 source_frame = 0; | 1595 source_frame = 0; |
1593 } | 1596 } |
1614 warning("Failed to open screenshot file %s for writing\n", screenshot_path); | 1617 warning("Failed to open screenshot file %s for writing\n", screenshot_path); |
1615 } | 1618 } |
1616 free(screenshot_path); | 1619 free(screenshot_path); |
1617 screenshot_path = NULL; | 1620 screenshot_path = NULL; |
1618 } | 1621 } |
1619 interlaced = last != which; | 1622 interlaced = last_field != which; |
1620 buffer += overscan_left[video_standard] + LINEBUF_SIZE * overscan_top[video_standard]; | 1623 buffer += overscan_left[video_standard] + LINEBUF_SIZE * overscan_top[video_standard]; |
1621 #ifndef DISABLE_OPENGL | 1624 #ifndef DISABLE_OPENGL |
1622 if (render_gl && which <= FRAMEBUFFER_EVEN) { | 1625 if (render_gl && which <= FRAMEBUFFER_EVEN) { |
1623 SDL_GL_MakeCurrent(main_window, main_context); | 1626 SDL_GL_MakeCurrent(main_window, main_context); |
1624 glBindTexture(GL_TEXTURE_2D, textures[which]); | 1627 glBindTexture(GL_TEXTURE_2D, textures[which]); |
1649 #endif | 1652 #endif |
1650 } else { | 1653 } else { |
1651 #endif | 1654 #endif |
1652 uint32_t shot_height = height; | 1655 uint32_t shot_height = height; |
1653 //TODO: Support SYNC_AUDIO_THREAD/SYNC_EXTERNAL for render API framebuffers | 1656 //TODO: Support SYNC_AUDIO_THREAD/SYNC_EXTERNAL for render API framebuffers |
1654 if (which <= FRAMEBUFFER_EVEN && last != which) { | 1657 if (which <= FRAMEBUFFER_EVEN && last_field != which) { |
1655 uint8_t *cur_dst = (uint8_t *)locked_pixels; | 1658 uint8_t *cur_dst = (uint8_t *)locked_pixels; |
1656 uint8_t *cur_saved = (uint8_t *)texture_buf; | 1659 uint8_t *cur_saved = (uint8_t *)texture_buf; |
1657 uint32_t dst_off = which == FRAMEBUFFER_EVEN ? 0 : locked_pitch; | 1660 uint32_t dst_off = which == FRAMEBUFFER_EVEN ? 0 : locked_pitch; |
1658 uint32_t src_off = which == FRAMEBUFFER_EVEN ? locked_pitch : 0; | 1661 uint32_t src_off = which == FRAMEBUFFER_EVEN ? locked_pitch : 0; |
1659 for (int i = 0; i < height; ++i) | 1662 for (int i = 0; i < height; ++i) |
1709 } | 1712 } |
1710 if (screenshot_file) { | 1713 if (screenshot_file) { |
1711 fclose(screenshot_file); | 1714 fclose(screenshot_file); |
1712 } | 1715 } |
1713 if (which <= FRAMEBUFFER_EVEN) { | 1716 if (which <= FRAMEBUFFER_EVEN) { |
1714 last = which; | 1717 last_field = which; |
1715 static uint32_t frame_counter, start; | 1718 static uint32_t frame_counter, start; |
1716 frame_counter++; | 1719 frame_counter++; |
1717 last_frame= SDL_GetTicks(); | 1720 last_frame= SDL_GetTicks(); |
1718 if ((last_frame - start) > FPS_INTERVAL) { | 1721 if ((last_frame - start) > FPS_INTERVAL) { |
1719 if (start && (last_frame-start)) { | 1722 if (start && (last_frame-start)) { |
1884 glActiveTexture(GL_TEXTURE0); | 1887 glActiveTexture(GL_TEXTURE0); |
1885 glBindTexture(GL_TEXTURE_2D, textures[0]); | 1888 glBindTexture(GL_TEXTURE_2D, textures[0]); |
1886 glUniform1i(un_textures[0], 0); | 1889 glUniform1i(un_textures[0], 0); |
1887 | 1890 |
1888 glActiveTexture(GL_TEXTURE1); | 1891 glActiveTexture(GL_TEXTURE1); |
1889 glBindTexture(GL_TEXTURE_2D, textures[interlaced ? 1 : scanlines ? 2 : 0]); | 1892 int bot_texture = 2; //black texture |
1893 if (interlaced) { | |
1894 bot_texture = 1; | |
1895 } else if (!scanlines && un_scanlines == -1) { | |
1896 bot_texture = 0; | |
1897 } | |
1898 glBindTexture(GL_TEXTURE_2D, textures[bot_texture]); | |
1890 glUniform1i(un_textures[1], 1); | 1899 glUniform1i(un_textures[1], 1); |
1891 | 1900 |
1892 glUniform1f(un_width, render_emulated_width()); | 1901 glUniform1f(un_width, render_emulated_width()); |
1893 glUniform1f(un_height, last_height); | 1902 glUniform1f(un_height, last_height); |
1894 glUniform2f(un_texsize, tex_width, tex_height); | 1903 glUniform2f(un_texsize, tex_width, tex_height); |
1904 if (un_curfield != -1) { | |
1905 glUniform1i(un_curfield, last_field); | |
1906 } | |
1907 if (un_interlaced != -1) { | |
1908 glUniform1i(un_interlaced, interlaced); | |
1909 } | |
1910 if (un_scanlines != -1) { | |
1911 glUniform1i(un_scanlines, scanlines); | |
1912 } | |
1895 | 1913 |
1896 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); | 1914 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); |
1897 glVertexAttribPointer(at_pos, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat[2]), (void *)0); | 1915 glVertexAttribPointer(at_pos, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat[2]), (void *)0); |
1898 glEnableVertexAttribArray(at_pos); | 1916 glEnableVertexAttribArray(at_pos); |
1899 | 1917 |