OSDN Git Service

[Qt][OpenGL] Initial support of OpenGL 4.3 Core profile.
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / gles2 / qt_glutil_gles_2.h
1 /*
2  * qt_glutil_gles_2.h
3  * (c) 2018 K.Ohta <whatisthis.sowhat@gmail.com>
4  * License: GPLv2.
5  * Renderer with OpenGL ES v2.0 (extend from renderer with OpenGL v2.0).
6  * History:
7  * May 05, 2018 : Copy from GL v3.0.
8  */
9
10 #ifndef _QT_COMMON_GLUTIL_ES_2_H
11 #define _QT_COMMON_GLUTIL_ES_2_H
12
13 #include <QString>
14
15 #include "../gl/qt_glutil_gl_tmpl.h"
16 //#include "../gl2/qt_glutil_gl2_0.h"
17
18 QT_BEGIN_NAMESPACE
19 class GLScreenPack;
20 class CSP_Logger;
21 class QOpenGLFunctions;
22 class QOpenGLBuffer;
23 class QOpenGLVertexArrayObject;
24 class QOpenGLShaderProgram;
25 class QOpenGLPixelTransferOptions;
26
27 class DLL_PREFIX GLDraw_ES_2 : public GLDraw_Tmpl
28 {
29         Q_OBJECT
30 private:
31         QOpenGLFunctions *extfunc;
32         float ringing_phase;
33 protected:
34         const float luma_filter[24 + 1] = {
35                 -0.000012020,
36                 -0.000022146,
37                 -0.000013155,
38                 -0.000012020,
39                 -0.000049979,
40                 -0.000113940,
41                 -0.000122150,
42                 -0.000005612,
43                 0.000170516,
44                 0.000237199,
45                 0.000169640,
46                 0.000285688,
47                 0.000984574,
48                 0.002018683,
49                 0.002002275,
50                 -0.000909882,
51                 -0.007049081,
52                 -0.013222860,
53                 -0.012606931,
54                 0.002460860,
55                 0.035868225,
56                 0.084016453,
57                 0.135563500,
58                 0.175261268,
59                 0.190176552
60         };
61         const float chroma_filter[24 + 1] = {
62                 -0.000118847,
63                 -0.000271306,
64                 -0.000502642,
65                 -0.000930833,
66                 -0.001451013,
67                 -0.002064744,
68                 -0.002700432,
69                 -0.003241276,
70                 -0.003524948,
71                 -0.003350284,
72                 -0.002491729,
73                 -0.000721149,
74                 0.002164659,
75                 0.006313635,
76                 0.011789103,
77                 0.018545660,
78                 0.026414396,
79                 0.035100710,
80                 0.044196567,
81                 0.053207202,
82                 0.061590275,
83                 0.068803602,
84                 0.074356193,
85                 0.077856564,
86                 0.079052396
87         };
88         const float rot0[4] =   {1, -0,  0, 1};
89         const float rot90[4] =  {0,  1, -1,  0};
90         const float rot180[4] = {-1, 0,  0, -1};
91         const float rot270[4] = {0, -1,  1, 0};
92
93         int gl_major_version;
94         int gl_minor_version;
95         GLScreenPack *main_pass;
96         GLScreenPack *std_pass;
97         GLScreenPack *ntsc_pass1;
98         GLScreenPack *ntsc_pass2;
99         GLScreenPack *bitmap_block;
100         GLScreenPack *led_pass;
101         GLScreenPack *osd_pass;
102         QOpenGLBuffer *led_pass_vbuffer[32];
103         QOpenGLVertexArrayObject *led_pass_vao[32];
104         QOpenGLBuffer *osd_pass_vbuffer[32];
105         QOpenGLVertexArrayObject *osd_pass_vao[32];
106
107         VertexTexCoord_t vertexTmpTexture[4];
108         
109         QOpenGLShaderProgram *grids_shader;
110         QOpenGLBuffer *grids_horizonal_buffer;
111         QOpenGLVertexArrayObject *grids_horizonal_vertex;
112         QOpenGLBuffer *grids_vertical_buffer;
113         QOpenGLVertexArrayObject *grids_vertical_vertex;
114
115         GLuint uTmpTextureID;
116         bool swap_byteorder;
117         QOpenGLPixelTransferOptions *TextureTransferParam;
118         
119         virtual void setNormalVAO(QOpenGLShaderProgram *prg, QOpenGLVertexArrayObject *vp,
120                                                           QOpenGLBuffer *bp, VertexTexCoord_t *tp, int size = 4);
121         virtual bool initGridShaders(const QString vertex_fixed, const QString vertex_rotate, const QString fragment);
122         virtual bool initGridVertexObject(QOpenGLBuffer **vbo, QOpenGLVertexArrayObject **vao, int alloc_size);
123         virtual void set_texture_vertex(float wmul = 1.0f, float hmul = 1.0f);
124         virtual void updateGridsVAO(QOpenGLBuffer *bp,
125                                                                         QOpenGLVertexArrayObject *vp,
126                                                                         GLfloat *tp,
127                                                                         int number);
128         virtual void drawGridsMain(QOpenGLShaderProgram *prg,
129                                                                   QOpenGLBuffer *bp,
130                                                                   QOpenGLVertexArrayObject *vp,
131                                                                   int number,
132                                                                   GLfloat lineWidth = 0.2f,
133                                                                   QVector4D color = QVector4D(0.0, 0.0, 0.0, 1.0));
134         virtual void resizeGL_Screen(void);
135         virtual void initPackedGLObject(GLScreenPack **p,
136                                                                 int _width, int _height,
137                                                                 const QString vertex_shader, const QString fragment_shader,
138                                                                 const QString _name);
139
140         virtual void drawGridsHorizonal(void);
141         virtual void drawGridsVertical(void);
142         virtual void drawGrids();
143
144         virtual void drawMain(QOpenGLShaderProgram *prg,
145                                                   QOpenGLVertexArrayObject *vp,
146                                                   QOpenGLBuffer *bp,
147                                                   GLuint texid,
148                                                   QVector4D color,
149                                                   bool f_smoosing,
150                                                   bool do_chromakey = false,
151                                                   QVector3D chromakey = QVector3D(0.0f, 0.0f, 0.0f));
152         virtual void drawMain(GLScreenPack *obj,
153                                                   GLuint texid,
154                                                   QVector4D color, bool f_smoosing,
155                                                   bool do_chromakey = false,
156                                                   QVector3D chromakey = QVector3D(0.0f, 0.0f, 0.0f));
157         virtual void renderToTmpFrameBuffer_nPass(GLuint src_texture,
158                                                                                   GLuint src_w,
159                                                                                   GLuint src_h,
160                                                                                   GLScreenPack *renderObject,
161                                                                                   GLuint dst_w,
162                                                                                   GLuint dst_h,
163                                                                                   bool use_chromakey = false);
164         virtual void drawBitmapTexture(void);
165         virtual void drawButtonsMain(int num, bool f_smoosing);
166         virtual void drawOsdLeds();
167         virtual void drawOsdIcons();
168         virtual void drawLedMain(GLScreenPack *obj, int num, QVector4D color);
169         virtual void set_led_vertex(int bit);
170         virtual void set_osd_vertex(int bit);
171         virtual void initBitmapVertex(void);
172         virtual QOpenGLTexture *createMainTexture(QImage *img);
173         void updateButtonTexture(void);
174
175 public:
176         GLDraw_ES_2(GLDrawClass *parent, USING_FLAGS *p, CSP_Logger *logger, EMU *emu = 0);
177         ~GLDraw_ES_2();
178         void drawButtons(void);
179         virtual void initGLObjects();
180         virtual void initLocalGLObjects(void);
181         virtual void initFBO(void);
182         void initButtons(void);
183         //virtual void initBitmapVertex(void);
184         
185         virtual void uploadMainTexture(QImage *p, bool chromakey);
186         virtual void drawScreenTexture(void);
187         virtual void do_set_screen_multiply(float mul);
188         virtual void doSetGridsHorizonal(int lines, bool force);
189         virtual void doSetGridsVertical(int pixels, bool force);
190         void uploadBitmapTexture(QImage *p);
191 public slots:
192         void updateBitmap(QImage *);
193         void uploadIconTexture(QPixmap *p, int icon_type, int localnum);
194         void setBrightness(GLfloat r, GLfloat g, GLfloat b);
195         void do_set_texture_size(QImage *p, int w, int h);
196         void do_set_horiz_lines(int lines);
197         virtual void paintGL(void);
198         virtual void resizeGL(int width, int height);
199         void do_set_display_osd(bool onoff);
200         void do_display_osd_leds(int lednum, bool onoff);
201
202 };
203 QT_END_NAMESPACE
204 #endif