OSDN Git Service

[Qt][GL][Display] Add NTSC-TV rendering.Still not enabled any VMs.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 7 Nov 2016 07:03:15 +0000 (16:03 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 7 Nov 2016 07:03:15 +0000 (16:03 +0900)
source/src/config.cpp
source/src/config.h
source/src/qt/common/menu_flags.cpp
source/src/qt/common/menu_flags.h
source/src/qt/gui/ntsc_pass1.glsl
source/src/qt/gui/ntsc_pass2.glsl
source/src/qt/gui/qt_glutil_gl3_0.cpp

index 2bcc153..091b108 100644 (file)
@@ -171,6 +171,7 @@ void initialize_config()
        config.sound_buttons = 0;
 
        config.roma_kana_conversion = false;
+       config.rendering_type = CONFIG_RENDER_TYPE_STD;
 #endif 
 }
 
@@ -317,6 +318,10 @@ void load_config(const _TCHAR *config_path)
                                                                                                           config.use_opengl_filters, config_path);
        config.opengl_filter_num =      MyGetPrivateProfileInt(_T("Screen"), _T("OpenGLFilterNum"),
                                                                                                         config.opengl_filter_num, config_path);
+       config.rendering_type = MyGetPrivateProfileInt(_T("Screen"), _T("RenderType"),
+                                                                                                        config.rendering_type, config_path);
+       if(config.rendering_type < 0) config.rendering_type = 0;
+       if(config.rendering_type >= CONFIG_RENDER_TYPE_END) config.rendering_type = CONFIG_RENDER_TYPE_END - 1;
 #endif 
        // sound
        config.sound_frequency = MyGetPrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
@@ -581,11 +586,12 @@ void save_config(const _TCHAR *config_path)
        }
 #endif
 #if defined(_USE_QT)
-       config.use_opengl_scanline = MyGetPrivateProfileBool(_T("Screen"), _T("UseOpenGLScanLine"), config.use_opengl_scanline, config_path);
-       config.opengl_scanline_vert = MyGetPrivateProfileBool(_T("Screen"), _T("OpenGLScanLineVert"), config.opengl_scanline_vert, config_path);;
-       config.opengl_scanline_horiz = MyGetPrivateProfileBool(_T("Screen"), _T("OpenGLScanLineHoriz"), config.opengl_scanline_horiz, config_path);;
-       config.use_opengl_filters = MyGetPrivateProfileBool(_T("Screen"), _T("UseOpenGLFilters"), config.use_opengl_filters, config_path);
-       config.opengl_filter_num = MyGetPrivateProfileInt(_T("Screen"), _T("OpenGLFilterNum"), config.opengl_filter_num, config_path);
+       MyWritePrivateProfileBool(_T("Screen"), _T("UseOpenGLScanLine"), config.use_opengl_scanline, config_path);
+       MyWritePrivateProfileBool(_T("Screen"), _T("OpenGLScanLineVert"), config.opengl_scanline_vert, config_path);;
+       MyWritePrivateProfileBool(_T("Screen"), _T("OpenGLScanLineHoriz"), config.opengl_scanline_horiz, config_path);;
+       MyWritePrivateProfileBool(_T("Screen"), _T("UseOpenGLFilters"), config.use_opengl_filters, config_path);
+       MyWritePrivateProfileInt(_T("Screen"), _T("OpenGLFilterNum"), config.opengl_filter_num, config_path);
+       MyWritePrivateProfileInt(_T("Screen"), _T("RenderType"), config.rendering_type, config_path);
 #endif
        
        // screen
index 7edf90a..a29e7ea 100644 (file)
 #include "qt/gui/csp_logger.h"
 #endif
 
+enum {
+       CONFIG_RENDER_TYPE_STD = 0,
+       CONFIG_RENDER_TYPE_TV,
+       CONFIG_RENDER_TYPE_END
+};
+
 #define MAX_HISTORY    8
 
 #if defined(USE_CART2)
@@ -178,6 +184,7 @@ typedef struct {
        int sound_buttons;
 
        bool roma_kana_conversion;
+       int rendering_type;
 #endif
 } config_t;
 
index 092911d..5b14ba8 100644 (file)
@@ -92,6 +92,7 @@ USING_FLAGS::USING_FLAGS(config_t *cfg)
 
        use_tape = use_tape_baud = use_tape_button = use_tape_ptr = false;
        use_vm_auto_key_table = false;
+       support_tv_render = false;
        
        screen_width = SCREEN_WIDTH;
        screen_height = SCREEN_HEIGHT;
@@ -302,6 +303,9 @@ USING_FLAGS::USING_FLAGS(config_t *cfg)
 #if defined(USE_CRT_FILTER)
        use_crt_filter = true;
 #endif
+#if defined(SUPPORT_TV_RENDER)
+       support_tv_render = true;
+#endif
 #if defined(USE_DEBUGGER)
        use_debugger = true;
 #endif
index 45e67e6..83ce0b5 100644 (file)
@@ -132,6 +132,8 @@ private:
        bool use_datarec_sound;
        bool tape_binary_only;
        int screen_mode_num;
+
+       bool support_tv_render;
        
        bool machine_pasopia_variants;
        bool machine_tk80_series;
@@ -255,6 +257,7 @@ public:
        bool is_use_vm_auto_key_table() { return use_vm_auto_key_table; }
 
        bool is_use_vertical_pixel_lines() { return use_vertical_pixel_lines; }
+       bool is_support_tv_render() { return support_tv_render; }
 
        int get_screen_width() { return screen_width; }
        int get_screen_height() { return screen_height; }
index c9510cd..f4defdb 100644 (file)
@@ -30,7 +30,7 @@ uniform float phase;
 //#define SATURATION 1.0
 #define SATURATION 1.0
 #define BRIGHTNESS 1.0
-#define ARTIFACTING 0.1
+#define ARTIFACTING 0.2
 #define FRINGING 0.2
 #elif defined(SVIDEO)
 #define SATURATION 1.0
@@ -62,25 +62,30 @@ vec3 yiq2rgb(vec3 yiq)
    return (yiq * yiq2rgb_mat);
 }
 
-mat3 yiq_mat = mat3(
-      0.2989, 0.5959, 0.2115,
-      0.5870, -0.2744, -0.5229,
-      0.1140, -0.3216, 0.3114
+//mat3 yiq_mat = mat3(
+//      0.2989, 0.5959, 0.2115,
+//      0.5870, -0.2744, -0.5229,
+//    0.1140, -0.3216, 0.3114
+//);
+
+// Change Matrix: [RGB]->[YCbCr]
+mat3 ycbcr_mat = mat3(
+      0.29891, -0.16874,  0.50000,
+      0.58661, -0.33126, -0.41869,
+      0.11448,  0.50000, -0.08131
 );
 
-vec3 rgb2yiq(vec3 col)
+vec3 rgb2ycbcr(vec3 col)
 {
-   return (col * yiq_mat);
+   return (col * ycbcr_mat);
 }
 
 void main() {
        // #include "ntsc-pass1-encode-demodulate.inc" //
        
        vec3 col = texture2D(a_texture, v_texcoord).rgb;
-       vec3 yiq;
-       //col = pow(col, vec3(0.45));
-       //col = col * 0.925 + vec3(0.075);
-       yiq = rgb2yiq(col);
+       vec3 ycbcr;
+       ycbcr = rgb2ycbcr(col);
 
 #if defined(TWO_PHASE)
        float chroma_phase = PI * (mod(pix_no.y, 2.0) + phase);
@@ -93,11 +98,12 @@ void main() {
        float i_mod = cos(mod_phase);
        float q_mod = sin(mod_phase);
 
-       yiq.yz *= vec2(i_mod, q_mod); // Modulate
-       yiq *= mix_mat; // Cross-talk
-       yiq.yz *= vec2(i_mod, q_mod); // Demodulate
-
-       gl_FragColor = vec4(yiq, 1.0);
+       ycbcr.yz *= vec2(i_mod, q_mod); // Modulate
+       ycbcr *= mix_mat; // Cross-talk
+       ycbcr.yz *= vec2(i_mod, q_mod); // Demodulate
+       ycbcr = ycbcr + vec3(0.0, 0.5, 0.5);
+       //ycbcr = ycbcr * vec3(0.75, 0.75, 0.75);
+       gl_FragColor = vec4(ycbcr, 1.0);
 
 // END "ntsc-pass1-encode-demodulate.inc" //
 }
\ No newline at end of file
index 981407e..a62811a 100644 (file)
@@ -12,7 +12,7 @@ uniform vec4 target_size;
 uniform float luma_filter[24 + 1];
 uniform float chroma_filter[24 + 1];
 
-#define OLD_THREE_PHASE //options here include THREE_PHASE, TWO_PHASE or OLD_THREE_PHASE
+#define THREE_PHASE //options here include THREE_PHASE, TWO_PHASE or OLD_THREE_PHASE
 #define GAMMA_CORRECTION //comment to disable gamma correction, usually because higan's gamma correction is enabled or you have another shader already doing it
 #define CRT_GAMMA 2.2
 #define DISPLAY_GAMMA 2.1
@@ -27,7 +27,19 @@ mat3 yiq2rgb_mat = mat3(
 
 vec3 yiq2rgb(vec3 yiq)
 {
-   return (yiq * yiq2rgb_mat);
+   return ((yiq - vec3(0.0, 0.5, 0.5)) * yiq2rgb_mat);
+}
+
+mat3 ycbcr2rgb_mat = mat3(
+        1.0, 1.0, 1.0,
+        0.0, -0.34414 , 1.77200,
+        1.40200, -0.71414, 0.0
+ );
+vec3 ycbcr2rgb(vec3 ycbcr)
+{
+       vec3 ra = ycbcr - vec3(0.0, 0.5, 0.5);
+       return (ra * ycbcr2rgb_mat);
 }
 
 mat3 yiq_mat = mat3(
@@ -54,8 +66,8 @@ void main() {
        float one_x = 1.0 / source_size.x;
        vec3 signal = vec3(0.0);
        int i;
-       
-       for (i = 0; i < TAPS; i++)
+#if 0
+       for (i = 1; i < TAPS; i++)
        {
                float offset = float(i);
                vec3 sums = fetch_offset(offset - float(TAPS), one_x) +
@@ -65,10 +77,23 @@ void main() {
        }               
 
        signal += texture2D(a_texture, fixCoord).xyz * vec3(luma_filter[TAPS], chroma_filter[TAPS], chroma_filter[TAPS]);
-
+#else
+       for (i = 1; i < 7; i++)
+       {
+               float offset = float(i);
+               float luma_weight = pow(2.7, (1.0 - offset) / 2.0);
+               float chroma_weight = pow(2.8, (1.0 - offset) / 2.0);
+               vec3 sums = fetch_offset(offset, one_x) +
+                               fetch_offset(0.0 - offset, one_x);
+               signal += sums * vec3(luma_weight, chroma_weight, chroma_weight);
+       }
+       signal = signal * vec3(0.2, 0.2, 0.2); 
+       signal += texture2D(a_texture, fixCoord).xyz;
+       signal = signal * vec3(0.5);
+#endif
 // END "ntsc-pass2-decode.inc" //
 
-   vec3 rgb = yiq2rgb(signal);
+   vec3 rgb = ycbcr2rgb(signal);
 
 #ifdef GAMMA_CORRECTION
    vec3 gamma = vec3(CRT_GAMMA / DISPLAY_GAMMA);
index cc54b34..0136595 100644 (file)
@@ -572,6 +572,7 @@ void GLDraw_3_0::renderToTmpFrameBuffer_nPass(GLuint src_texture,
                0.042004791
        };
 #else
+#if 1
        // THREE_PHASE
        const float luma_filter[24 + 1] = {
                -0.000012020,
@@ -628,7 +629,7 @@ void GLDraw_3_0::renderToTmpFrameBuffer_nPass(GLuint src_texture,
                0.079052396
        };
 // END "ntsc-decode-filter-3phase.inc" //
-#if 0
+#else
                                // TWO_PHASE
        const float luma_filter[24 + 1] = {
                -0.000012020,
@@ -726,7 +727,7 @@ void GLDraw_3_0::renderToTmpFrameBuffer_nPass(GLuint src_texture,
                                        }
                                        ii = shader->uniformLocation("phase");
                                        if(ii >= 0) {
-                                               float phase = 3.14f / 4;
+                                               float phase = 1.0 / 32.0;
                                                shader->setUniformValue(ii,  phase);
                                        }
                                        ii = shader->uniformLocation("luma_filter");
@@ -808,57 +809,55 @@ void GLDraw_3_0::uploadMainTexture(QImage *p, bool use_chromakey)
                                                         GL_BGRA, GL_UNSIGNED_BYTE, p->constBits());
                extfunc_3_0->glBindTexture(GL_TEXTURE_2D, 0);
        }
-#if 1
-       renderToTmpFrameBuffer_nPass(uVramTextureID,
-                                                                screen_texture_width,
-                                                                screen_texture_height,
-                                                                tmp_shader,
-                                                                uTmpTextureID,
-                                                                p_wid->width(),
-                                                                p_wid->height(),
-                                                                buffer_vertex_tmp_texture,
-                                                                vertex_tmp_texture,
-                                                                uTmpFrameBuffer,
-                                                                uTmpDepthBuffer,
-                                                                use_chromakey);
-       
-#else
-       renderToTmpFrameBuffer_nPass(uVramTextureID,
-                                                                screen_texture_width,
-                                                                screen_texture_height,
-                                                                ntsc_pass1_shader,
-                                                                uVramPass1Texture,
-                                                                screen_texture_width * 2,
-                                                                screen_texture_height,
-                                                                buffer_vertex_pass1_texture,
-                                                                vertex_pass1_texture,
-                                                                uVramPass1FrameBuffer,
-                                                                uVramPass1RenderBuffer);
-       renderToTmpFrameBuffer_nPass(uVramPass1Texture,
-                                                                screen_texture_width * 2,
-                                                                screen_texture_height,
-                                                                ntsc_pass2_shader,
-                                                                uVramPass2Texture,
-                                                                screen_texture_width,
-                                                                screen_texture_height,
-                                                                buffer_vertex_pass2_texture,
-                                                                vertex_pass2_texture,
-                                                                uVramPass2FrameBuffer,
-                                                                uVramPass2RenderBuffer);
-       renderToTmpFrameBuffer_nPass(uVramPass2Texture,
-                                                                screen_texture_width,
-                                                                screen_texture_height,
-                                                                tmp_shader,
-                                                                uTmpTextureID,
-                                                                p_wid->width(),
-                                                                p_wid->height(),
-                                                                buffer_vertex_tmp_texture,
-                                                                vertex_tmp_texture,
-                                                                uTmpFrameBuffer,
-                                                                uTmpDepthBuffer,
-                                                                use_chromakey);
-       
-#endif                                                  
+       if(using_flags->is_support_tv_render() && (using_flags->get_config_ptr()->rendering_type == CONFIG_RENDER_TYPE_TV)) {
+               renderToTmpFrameBuffer_nPass(uVramTextureID,
+                                                                        screen_texture_width,
+                                                                        screen_texture_height,
+                                                                        ntsc_pass1_shader,
+                                                                        uVramPass1Texture,
+                                                                        screen_texture_width * 2,
+                                                                        screen_texture_height,
+                                                                        buffer_vertex_pass1_texture,
+                                                                        vertex_pass1_texture,
+                                                                        uVramPass1FrameBuffer,
+                                                                        uVramPass1RenderBuffer);
+               renderToTmpFrameBuffer_nPass(uVramPass1Texture,
+                                                                        screen_texture_width * 2,
+                                                                        screen_texture_height,
+                                                                        ntsc_pass2_shader,
+                                                                        uVramPass2Texture,
+                                                                        screen_texture_width,
+                                                                        screen_texture_height,
+                                                                        buffer_vertex_pass2_texture,
+                                                                        vertex_pass2_texture,
+                                                                        uVramPass2FrameBuffer,
+                                                                        uVramPass2RenderBuffer);
+               renderToTmpFrameBuffer_nPass(uVramPass2Texture,
+                                                                        screen_texture_width,
+                                                                        screen_texture_height,
+                                                                        tmp_shader,
+                                                                        uTmpTextureID,
+                                                                        p_wid->width(),
+                                                                        p_wid->height(),
+                                                                        buffer_vertex_tmp_texture,
+                                                                        vertex_tmp_texture,
+                                                                        uTmpFrameBuffer,
+                                                                        uTmpDepthBuffer,
+                                                                        use_chromakey);
+       } else {
+               renderToTmpFrameBuffer_nPass(uVramTextureID,
+                                                                        screen_texture_width,
+                                                                        screen_texture_height,
+                                                                        tmp_shader,
+                                                                        uTmpTextureID,
+                                                                        p_wid->width(),
+                                                                        p_wid->height(),
+                                                                        buffer_vertex_tmp_texture,
+                                                                        vertex_tmp_texture,
+                                                                        uTmpFrameBuffer,
+                                                                        uTmpDepthBuffer,
+                                                                        use_chromakey);
+       }               
        crt_flag = true;
 }