• R/O
  • HTTP
  • SSH
  • HTTPS

common_source_project-fm7: Commit

Common Source Code Project for Qt (a.k.a for FM-7).


Commit MetaInfo

Revisionfcc48accba67db9df45193338d76a33fbad98643 (tree)
Time2018-05-11 23:03:00
AuthorK.Ohta <whatisthis.sowhat@gmai...>
CommiterK.Ohta

Log Message

[Qt][Draw][GLES] Add TV renderer for OpenGL ES.

Change Summary

Incremental Difference

--- a/source/src/qt/common/qrc/shaders.qrc
+++ b/source/src/qt/common/qrc/shaders.qrc
@@ -39,5 +39,7 @@
3939 <file alias="gles2/grids_vertex_shader.glsl">../../gui/gles2/grids_vertex_shader.glsl</file>
4040 <file alias="gles2/grids_vertex_shader_fixed.glsl">../../gui/gles2/grids_vertex_shader_fixed.glsl</file>
4141
42+ <file alias="gles2/ntsc_pass1.glsl">../../gui/gles2/ntsc_pass1.glsl</file>
43+ <file alias="gles2/ntsc_pass2.glsl">../../gui/gles2/ntsc_pass2.glsl</file>
4244 </qresource>
4345 </RCC>
--- a/source/src/qt/gui/gles2/chromakey_fragment_shader.glsl
+++ b/source/src/qt/gui/gles2/chromakey_fragment_shader.glsl
@@ -15,9 +15,6 @@ void main ()
1515 if(pixel_r_1.rgb != chromakey.rgb) {
1616 pixel_r_1 = pixel_r_1 * color;
1717 pixel = vec4(pixel_r_1.rgb, 1.0);
18- if(swap_byteorder) {
19- pixel.rgb = pixel.bgr;
20- }
2118 gl_FragColor = pixel;
2219 } else {
2320 pixel = vec4(0.0);
@@ -26,9 +23,6 @@ void main ()
2623 } else {
2724 pixel_r_1 = pixel_r_1 * color;
2825 pixel = vec4(pixel_r_1.rgb, 1.0);
29- if(swap_byteorder) {
30- pixel.rgb = pixel.bgr;
31- }
3226 gl_FragColor = pixel;
3327 }
3428 }
--- a/source/src/qt/gui/gles2/ntsc_pass1.glsl
+++ b/source/src/qt/gui/gles2/ntsc_pass1.glsl
@@ -1,19 +1,22 @@
11 // NTSC Shader - written by Hans-Kristian Arntzen
22 // License: GPLv3
33 // pulled from git://github.com/libretro/common-shaders.git on 01/30/2014
4+precision mediump float;
5+
46 varying mediump vec2 v_texcoord;
57
68 uniform sampler2D a_texture;
79 uniform vec4 source_size;
810 uniform vec4 target_size;
911 uniform float phase;
12+uniform bool swap_byteorder;
1013
1114 // uniforms added for compatibility
1215 //vec3 col;
1316 //float mod_phase;
1417 //float chroma_phase;
1518
16-#define THREE_PHASE
19+#define TWO_PHASE //options here include THREE_PHASE, TWO_PHASE or OLD_THREE_PHASE
1720 #define COMPOSITE
1821
1922 // #include "ntsc-param.inc" //
@@ -71,12 +74,12 @@ vec3 rgb2yiq(vec3 col)
7174 }
7275
7376 // Change Matrix: [RGB]->[YCbCr]
77+
7478 mat3 ycbcr_mat = mat3(
7579 0.29891, -0.16874, 0.50000,
7680 0.58661, -0.33126, -0.41869,
7781 0.11448, 0.50000, -0.08131
7882 );
79-
8083 vec3 rgb2ycbcr(vec3 col)
8184 {
8285 return (col * ycbcr_mat);
@@ -87,7 +90,11 @@ void main() {
8790
8891 vec3 col = texture2D(a_texture, v_texcoord).rgb;
8992 vec3 ycbcr;
90- ycbcr = rgb2yiq(col);
93+ if(swap_byteorder) {
94+ col.rgb = col.bgr;
95+ }
96+ //ycbcr = rgb2yiq(col);
97+ ycbcr = rgb2ycbcr(col);
9198
9299 #if defined(TWO_PHASE)
93100 float chroma_phase = PI * (mod(pix_no.y, 2.0) + phase);
@@ -103,8 +110,9 @@ void main() {
103110 ycbcr *= vec3(1.0, i_mod, q_mod); // Modulate
104111 ycbcr *= mix_mat; // Cross-talk
105112 ycbcr *= vec3(1.0, i_mod, q_mod); // Demodulate
106- //ycbcr = ycbcr + vec3(0.0, 0.5, 0.5);
107- gl_FragColor = vec4(ycbcr, 1.0);
113+
114+ vec4 outvar = vec4(ycbcr, 1.0);
115+ gl_FragColor = outvar;
108116
109117 // END "ntsc-pass1-encode-demodulate.inc" //
110118 }
\ No newline at end of file
--- a/source/src/qt/gui/gles2/ntsc_pass2.glsl
+++ b/source/src/qt/gui/gles2/ntsc_pass2.glsl
@@ -2,6 +2,9 @@
22 // License: GPLv3
33 // pulled from git://github.com/libretro/common-shaders.git on 01/30/2014
44
5+precision mediump float;
6+uniform bool swap_byteorder;
7+
58 varying mediump vec2 v_texcoord;
69
710 uniform sampler2D a_texture;
@@ -12,7 +15,6 @@ uniform vec4 target_size;
1215 uniform float luma_filter[24 + 1];
1316 uniform float chroma_filter[24 + 1];
1417
15-#define THREE_PHASE //options here include THREE_PHASE, TWO_PHASE or OLD_THREE_PHASE
1618 #define GAMMA_CORRECTION //comment to disable gamma correction, usually because higan's gamma correction is enabled or you have another shader already doing it
1719 #define CRT_GAMMA 2.5
1820 #define DISPLAY_GAMMA 2.1
@@ -22,12 +24,11 @@ uniform float chroma_filter[24 + 1];
2224 mat3 yiq2rgb_mat = mat3(
2325 1.0, 1.0, 1.0,
2426 0.956, -0.2720, -1.1060,
25- 0.6210, -0.6474, 1.7046
27+ 0.6210, -0.0, 1.7046
2628 );
2729
2830 vec3 yiq2rgb(vec3 yiq)
2931 {
30- //yiq = yiq - vec3(0.0, 0.5, 0.5);
3132 return (yiq * yiq2rgb_mat);
3233 }
3334
@@ -36,12 +37,10 @@ mat3 ycbcr2rgb_mat = mat3(
3637 0.0, -0.34414 , 1.77200,
3738 1.40200, -0.71414, 0.0
3839 );
39-
4040 vec3 ycbcr2rgb(vec3 ycbcr)
4141 {
42- //vec3 ra = ycbcr - vec3(0.0, 0.5, 0.5);
43- vec3 ra = ycbcr;
44- return (ra * ycbcr2rgb_mat);
42+ //vec3 ra = ycbcr * vec3(1.0, 0.7, 1.0);
43+ return (ycbcr * ycbcr2rgb_mat);
4544 }
4645
4746 mat3 yiq_mat = mat3(
@@ -69,7 +68,7 @@ void main() {
6968 vec3 signal = vec3(0.0);
7069 int i,j;
7170 int ibegin = 1;
72-#if 0
71+#if 0
7372 for (i = ibegin; i < TAPS; i++)
7473 {
7574 float offset = float(i);
@@ -94,17 +93,25 @@ void main() {
9493 signal = signal + pix_p;
9594 addr_p = addr_p - delta;
9695 addr_n = addr_n + delta;
97- }
96+ }
9897 #endif
99- signal += texture2D(a_texture, fixCoord).xyz * vec3(luma_filter[TAPS], chroma_filter[TAPS], chroma_filter[TAPS]);
98+ vec3 texvar = texture2D(a_texture, fixCoord).xyz;
99+ signal += texvar * vec3(luma_filter[TAPS], chroma_filter[TAPS], chroma_filter[TAPS]);
100+
100101 // END "ntsc-pass2-decode.inc" //
101102
102- //vec3 rgb = ycbcr2rgb(signal);
103- vec3 rgb = yiq2rgb(signal);
103+ vec3 rgb = ycbcr2rgb(signal);
104+ //vec3 rgb = yiq2rgb(signal);
104105 #ifdef GAMMA_CORRECTION
105106 vec3 gamma = vec3(CRT_GAMMA / DISPLAY_GAMMA);
106107 rgb = pow(rgb, gamma.rgb);
107108 #endif
108-
109- gl_FragColor = vec4(rgb, 1.0);
109+ vec4 pixel = vec4(rgb, 1.0);
110+ pixel = pixel * vec4(0.8, 1.8, 1.4, 1.0);
111+ if(swap_byteorder) {
112+ pixel.rgba = pixel.bgra;
113+ gl_FragColor = pixel;
114+ } else {
115+ gl_FragColor = pixel;
116+ }
110117 }
\ No newline at end of file
--- a/source/src/qt/gui/gles2/qt_glutil_gles_2.cpp
+++ b/source/src/qt/gui/gles2/qt_glutil_gles_2.cpp
@@ -20,6 +20,22 @@
2020 #include <QImageReader>
2121 #include <QMatrix4x4>
2222 #include <QOpenGLPixelTransferOptions>
23+#include <QOpenGLVertexArrayObject>
24+#include <QOpenGLShaderProgram>
25+#include <QOpenGLBuffer>
26+
27+#include <QOpenGLContext>
28+#include <QOpenGLFramebufferObject>
29+#include <QOpenGLFramebufferObjectFormat>
30+
31+#include <QMatrix4x2>
32+#include <QMatrix4x4>
33+
34+#include <QVector>
35+#include <QVector2D>
36+#include <QVector3D>
37+#include <QVector4D>
38+
2339 //extern USING_FLAGS *using_flags;
2440
2541 GLDraw_ES_2::GLDraw_ES_2(GLDrawClass *parent, USING_FLAGS *p, CSP_Logger *logger, EMU *emu) : GLDraw_2_0(parent, p, logger, emu)
@@ -30,8 +46,8 @@ GLDraw_ES_2::GLDraw_ES_2(GLDrawClass *parent, USING_FLAGS *p, CSP_Logger *logger
3046
3147 main_pass = NULL;
3248 std_pass = NULL;
33- //ntsc_pass1 = NULL;
34- //ntsc_pass2 = NULL;
49+ ntsc_pass1 = NULL;
50+ ntsc_pass2 = NULL;
3551 led_pass = NULL;
3652 for(int i = 0; i < 32; i++) {
3753 led_pass_vao[i] = NULL;
@@ -57,8 +73,8 @@ GLDraw_ES_2::~GLDraw_ES_2()
5773
5874 if(main_pass != NULL) delete main_pass;
5975 if(std_pass != NULL) delete std_pass;
60- //if(ntsc_pass1 != NULL) delete ntsc_pass1;
61- //if(ntsc_pass2 != NULL) delete ntsc_pass2;
76+ if(ntsc_pass1 != NULL) delete ntsc_pass1;
77+ if(ntsc_pass2 != NULL) delete ntsc_pass2;
6278 if(led_pass != NULL) delete led_pass;
6379 for(int i = 0; i < 32; i++) {
6480 if(led_pass_vao[i] != NULL) delete led_pass_vao[i];
@@ -341,7 +357,7 @@ void GLDraw_ES_2::initLocalGLObjects(void)
341357 }
342358 }
343359 }
344-#if 0
360+#if 1
345361
346362 initPackedGLObject(&ntsc_pass1,
347363 _width, _height,
@@ -527,7 +543,9 @@ void GLDraw_ES_2::renderToTmpFrameBuffer_nPass(GLuint src_texture,
527543 {
528544 if((src_texture != 0) && (shader != NULL)) {
529545 QMatrix4x4 ortho;
530- ortho.ortho(0.0f, (float)dst_w, 0.0f, (float)dst_h, -1.0, 1.0);
546+ //ortho.ortho(0.0f, (float)dst_w, 0.0f, (float)dst_h, -1.0, 1.0);
547+ ortho.ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
548+
531549
532550 renderObject->bind();
533551 extfunc->glViewport(0, 0, dst_w, dst_h);
@@ -553,7 +571,7 @@ void GLDraw_ES_2::renderToTmpFrameBuffer_nPass(GLuint src_texture,
553571 }
554572 ii = shader->uniformLocation("phase");
555573 if(ii >= 0) {
556- ringing_phase = ringing_phase + 0.093;
574+ ringing_phase = ringing_phase + 0.04;
557575 if(ringing_phase > 1.0) ringing_phase = ringing_phase - 1.0;
558576 shader->setUniformValue(ii, ringing_phase);
559577 }
@@ -592,6 +610,10 @@ void GLDraw_ES_2::renderToTmpFrameBuffer_nPass(GLuint src_texture,
592610 }
593611 shader->enableAttributeArray("texcoord");
594612 shader->enableAttributeArray("vertex");
613+ ii = shader->uniformLocation("swap_byteorder");
614+ if(ii >= 0) {
615+ shader->setUniformValue(ii, (swap_byteorder) ? GL_TRUE : GL_FALSE);
616+ }
595617
596618 int vertex_loc = shader->attributeLocation("vertex");
597619 int texcoord_loc = shader->attributeLocation("texcoord");
@@ -630,7 +652,7 @@ void GLDraw_ES_2::uploadMainTexture(QImage *p, bool use_chromakey)
630652 p->bits());
631653 extfunc->glBindTexture(GL_TEXTURE_2D, 0);
632654 }
633-#if 0
655+#if 1
634656 if(using_flags->is_support_tv_render() && (using_flags->get_config_ptr()->rendering_type == CONFIG_RENDER_TYPE_TV)) {
635657 renderToTmpFrameBuffer_nPass(uVramTextureID->textureId(),
636658 screen_texture_width,
@@ -649,7 +671,7 @@ void GLDraw_ES_2::uploadMainTexture(QImage *p, bool use_chromakey)
649671 } else
650672 #endif
651673 {
652-#if 0
674+#if 1
653675 renderToTmpFrameBuffer_nPass(uVramTextureID->textureId(),
654676 screen_texture_width,
655677 screen_texture_height,
@@ -1294,7 +1316,7 @@ void GLDraw_ES_2::do_set_texture_size(QImage *p, int w, int h)
12941316 vertexTmpTexture, 4);
12951317 //set_texture_vertex(p, p_wid->width(), p_wid->height(), w, h);
12961318
1297-#if 0
1319+#if 1
12981320 set_texture_vertex((float)w / iw, (float)h / ih);
12991321 setNormalVAO(ntsc_pass1->getShader(), ntsc_pass1->getVAO(),
13001322 ntsc_pass1->getVertexBuffer(),
--- a/source/src/qt/gui/gles2/qt_glutil_gles_2.h
+++ b/source/src/qt/gui/gles2/qt_glutil_gles_2.h
@@ -28,10 +28,65 @@ private:
2828 QOpenGLFunctions *extfunc;
2929 float ringing_phase;
3030 protected:
31+ const float luma_filter[24 + 1] = {
32+ -0.000012020,
33+ -0.000022146,
34+ -0.000013155,
35+ -0.000012020,
36+ -0.000049979,
37+ -0.000113940,
38+ -0.000122150,
39+ -0.000005612,
40+ 0.000170516,
41+ 0.000237199,
42+ 0.000169640,
43+ 0.000285688,
44+ 0.000984574,
45+ 0.002018683,
46+ 0.002002275,
47+ -0.000909882,
48+ -0.007049081,
49+ -0.013222860,
50+ -0.012606931,
51+ 0.002460860,
52+ 0.035868225,
53+ 0.084016453,
54+ 0.135563500,
55+ 0.175261268,
56+ 0.190176552
57+ };
58+ const float chroma_filter[24 + 1] = {
59+ -0.000118847,
60+ -0.000271306,
61+ -0.000502642,
62+ -0.000930833,
63+ -0.001451013,
64+ -0.002064744,
65+ -0.002700432,
66+ -0.003241276,
67+ -0.003524948,
68+ -0.003350284,
69+ -0.002491729,
70+ -0.000721149,
71+ 0.002164659,
72+ 0.006313635,
73+ 0.011789103,
74+ 0.018545660,
75+ 0.026414396,
76+ 0.035100710,
77+ 0.044196567,
78+ 0.053207202,
79+ 0.061590275,
80+ 0.068803602,
81+ 0.074356193,
82+ 0.077856564,
83+ 0.079052396
84+ };
85+
3186 GLScreenPack *main_pass;
3287 GLScreenPack *std_pass;
33- //GLScreenPack *ntsc_pass1;
34- //GLScreenPack *ntsc_pass2;
88+ GLScreenPack *ntsc_pass1;
89+ GLScreenPack *ntsc_pass2;
3590 GLScreenPack *bitmap_block;
3691 GLScreenPack *led_pass;
3792 GLScreenPack *osd_pass;
--- a/source/src/qt/gui/qt_glpack.cpp
+++ b/source/src/qt/gui/qt_glpack.cpp
@@ -1,6 +1,11 @@
1-#include "qt_glpack.h"
21
2+#include <QOpenGLContext>
3+
4+#include <QMatrix4x2>
5+#include <QMatrix4x4>
6+#include <QImage>
37
8+#include "qt_glpack.h"
49
510 GLScreenPack::GLScreenPack(int _width, int _height, QObject *parent) : QObject(parent)
611 {
@@ -8,7 +13,7 @@ GLScreenPack::GLScreenPack(int _width, int _height, QObject *parent) : QObject(p
813
914 vertex_buffer = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
1015 vertex = new QOpenGLVertexArrayObject;
11-
16+ QOpenGLContext *context = QOpenGLContext::currentContext();
1217 init_status = false;
1318 shader_status = false;
1419 Texture = 0;
@@ -36,11 +41,18 @@ GLScreenPack::GLScreenPack(int _width, int _height, QObject *parent) : QObject(p
3641 tex_geometry_h = _height;
3742 tex_geometry_x = 0;
3843 tex_geometry_y = 0;
39- fbo_format.setInternalTextureFormat(GL_RGBA8);
40- //fbo_format.setInternalTextureFormat(GL_RGBA32F);
41- fbo_format.setTextureTarget(GL_TEXTURE_2D);
4244
45+ fbo_format.setInternalTextureFormat(GL_RGBA32F);
46+ if(context != NULL) {
47+ if(context->isOpenGLES()) {
48+ fbo_format.setInternalTextureFormat(GL_RGBA8);
49+ }
50+ }
51+
52+ fbo_format.setTextureTarget(GL_TEXTURE_2D);
53+ //fbo_format.setAttachment();
4354 frame_buffer_object = new QOpenGLFramebufferObject(_width, _height, fbo_format);
55+ frame_buffer_object->setAttachment(QOpenGLFramebufferObject::Depth);
4456 //frame_buffer_object = new QOpenGLFramebufferObject(_width, _height);
4557 Texture = 0;
4658 }
--- a/source/src/qt/gui/qt_glpack.h
+++ b/source/src/qt/gui/qt_glpack.h
@@ -11,17 +11,14 @@
1111 #define _QT_COMMON_GLPACK_H
1212
1313 #include <QString>
14-#include <QOpenGLVertexArrayObject>
15-#include <QOpenGLShaderProgram>
14+#include <QGLWidget>
15+
1616 #include <QOpenGLBuffer>
17-#include <QOpenGLContext>
1817 #include <QOpenGLFramebufferObject>
1918 #include <QOpenGLFramebufferObjectFormat>
20-#include <QGLWidget>
21-#include <QImage>
19+#include <QOpenGLShaderProgram>
2220
23-#include <QMatrix4x2>
24-#include <QMatrix4x4>
21+#include <QOpenGLVertexArrayObject>
2522
2623 #include <QVector>
2724 #include <QVector2D>
@@ -37,6 +34,10 @@ typedef struct {
3734 } VertexLines_t ;
3835
3936 QT_BEGIN_NAMESPACE
37+class QOpenGLVertexArrayObject;
38+class QOpenGLShaderProgram;
39+class QOpenGLBuffer;
40+class QOpenGLContext;
4041 class GLScreenPack : public QObject
4142 {
4243 Q_OBJECT
Show on old repository browser