OSDN Git Service

[VM][Qt][UI][EMU][WIP] Use EMU_TEMPLATE:: instead of EMU:: . Some VMs are not apply...
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / gl4_5 / qt_glutil_gl4_5.h
1 /*
2  * qt_glutil_gl4_5.cpp
3  * (c) 2016 K.Ohta <whatisthis.sowhat@gmail.com>
4  * License: GPLv2.
5  * Renderer with OpenGL v4.5 (extend from renderer with OpenGL v2.0).
6  * History:
7  * Jan 22, 2016 : Initial.
8  */
9
10 #ifndef _QT_COMMON_GLUTIL_4_5_H
11 #define _QT_COMMON_GLUTIL_4_5_H
12
13 #include <QString>
14 #include "../gl/qt_glutil_gl_tmpl.h"
15
16 QT_BEGIN_NAMESPACE
17 class GLScreenPack;
18 class CSP_Logger;
19 class QOpenGLFunctions_4_5_Core;
20 class QOpenGLBuffer;
21 class QOpenGLVertexArrayObject;
22 class QOpenGLShaderProgram;
23 class QOpenGLPixelTransferOptions;
24 class QMutex;
25
26 class DLL_PREFIX GLDraw_4_5 : public GLDraw_Tmpl
27 {
28         Q_OBJECT
29 private:
30         QOpenGLFunctions_4_5_Core *extfunc;
31         float ringing_phase;
32 protected:
33         const float luma_filter[24 + 1] = {
34                 -0.000012020,
35                 -0.000022146,
36                 -0.000013155,
37                 -0.000012020,
38                 -0.000049979,
39                 -0.000113940,
40                 -0.000122150,
41                 -0.000005612,
42                 0.000170516,
43                 0.000237199,
44                 0.000169640,
45                 0.000285688,
46                 0.000984574,
47                 0.002018683,
48                 0.002002275,
49                 -0.000909882,
50                 -0.007049081,
51                 -0.013222860,
52                 -0.012606931,
53                 0.002460860,
54                 0.035868225,
55                 0.084016453,
56                 0.135563500,
57                 0.175261268,
58                 0.190176552
59         };
60         const float chroma_filter[24 + 1] = {
61                 -0.000118847,
62                 -0.000271306,
63                 -0.000502642,
64                 -0.000930833,
65                 -0.001451013,
66                 -0.002064744,
67                 -0.002700432,
68                 -0.003241276,
69                 -0.003524948,
70                 -0.003350284,
71                 -0.002491729,
72                 -0.000721149,
73                 0.002164659,
74                 0.006313635,
75                 0.011789103,
76                 0.018545660,
77                 0.026414396,
78                 0.035100710,
79                 0.044196567,
80                 0.053207202,
81                 0.061590275,
82                 0.068803602,
83                 0.074356193,
84                 0.077856564,
85                 0.079052396
86         };
87         const float rot0[4] =   {1, -0,  0, 1};
88         const float rot90[4] =  {0,  1, -1,  0};
89         const float rot180[4] = {-1, 0,  0, -1};
90         const float rot270[4] = {0, -1,  1, 0};
91
92         int gl_major_version;
93         int gl_minor_version;
94
95         int pixel_width;
96         int pixel_height;
97         GLuint main_texture_buffer;
98         GLuint main_read_texture_buffer;
99         GLsync sync_fence;
100         QMutex *main_mutex;
101         scrntype_t *map_base_address;
102         
103         GLScreenPack *main_pass;
104         GLScreenPack *std_pass;
105         GLScreenPack *ntsc_pass1;
106         GLScreenPack *ntsc_pass2;
107         GLScreenPack *bitmap_block;
108         GLScreenPack *led_pass;
109         GLScreenPack *osd_pass;
110         QOpenGLBuffer *led_pass_vbuffer[32];
111         QOpenGLVertexArrayObject *led_pass_vao[32];
112         QOpenGLBuffer *osd_pass_vbuffer[32];
113         QOpenGLVertexArrayObject *osd_pass_vao[32];
114
115         VertexTexCoord_t vertexTmpTexture[4];
116         
117         QOpenGLShaderProgram *grids_shader;
118         QOpenGLBuffer *grids_horizonal_buffer;
119         QOpenGLVertexArrayObject *grids_horizonal_vertex;
120         QOpenGLBuffer *grids_vertical_buffer;
121         QOpenGLVertexArrayObject *grids_vertical_vertex;
122
123         GLuint uTmpTextureID;
124         bool swap_byteorder;
125         bool main_texture_ready;
126         
127         virtual void setNormalVAO(QOpenGLShaderProgram *prg, QOpenGLVertexArrayObject *vp,
128                                                           QOpenGLBuffer *bp, VertexTexCoord_t *tp, int size = 4);
129         virtual bool initGridShaders(const QString vertex_fixed, const QString vertex_rotate, const QString fragment);
130         virtual bool initGridVertexObject(QOpenGLBuffer **vbo, QOpenGLVertexArrayObject **vao, int alloc_size);
131         virtual void set_texture_vertex(float wmul = 1.0f, float hmul = 1.0f);
132         virtual void updateGridsVAO(QOpenGLBuffer *bp,
133                                                                         QOpenGLVertexArrayObject *vp,
134                                                                         GLfloat *tp,
135                                                                         int number);
136
137         virtual void drawGridsMain(QOpenGLShaderProgram *prg,
138                                                                   QOpenGLBuffer *bp,
139                                                                   QOpenGLVertexArrayObject *vp,
140                                                                   int number,
141                                                                   GLfloat lineWidth = 0.2f,
142                                                                   QVector4D color = QVector4D(0.0, 0.0, 0.0, 1.0));
143         virtual void resizeGL_Screen(void);
144         virtual void initPackedGLObject(GLScreenPack **p,
145                                                                         int _width, int _height,
146                                                                         const QString vertex_shader, const QString fragment_shader,
147                                                                         const QString _name,
148                                                                         bool req_float = false, bool req_highp = false,
149                                                                         bool req_alpha_channel = true);
150         
151         virtual void drawGridsHorizonal(void);
152         virtual void drawGridsVertical(void);
153         virtual void drawGrids();
154
155         virtual void drawMain(QOpenGLShaderProgram *prg,
156                                                   QOpenGLVertexArrayObject *vp,
157                                                   QOpenGLBuffer *bp,
158                                                   GLuint texid,
159                                                   QVector4D color,
160                                                   bool f_smoosing,
161                                                   bool do_chromakey = false,
162                                                   QVector3D chromakey = QVector3D(0.0f, 0.0f, 0.0f));
163         virtual void drawMain(GLScreenPack *obj,
164                                                   GLuint texid,
165                                                   QVector4D color, bool f_smoosing,
166                                                   bool do_chromakey = false,
167                                                   QVector3D chromakey = QVector3D(0.0f, 0.0f, 0.0f));
168         virtual void renderToTmpFrameBuffer_nPass(GLuint src_texture,
169                                                                                   GLuint src_w,
170                                                                                   GLuint src_h,
171                                                                                   GLScreenPack *renderObject,
172                                                                                   GLuint dst_w,
173                                                                                   GLuint dst_h,
174                                                                                   bool use_chromakey = false);
175         virtual void drawBitmapTexture(void);
176         virtual void drawButtonsMain(int num, bool f_smoosing);
177         virtual void drawOsdLeds();
178         virtual void drawOsdIcons();
179         virtual void drawLedMain(GLScreenPack *obj, int num, QVector4D color);
180         virtual void set_led_vertex(int bit);
181         virtual void set_osd_vertex(int bit);
182         virtual void initBitmapVertex(void);
183         virtual QOpenGLTexture *createMainTexture(QImage *img);
184         void updateButtonTexture(void);
185
186 public:
187         GLDraw_4_5(GLDrawClass *parent, USING_FLAGS *p, CSP_Logger *logger, EMU_TEMPLATE *emu = 0);
188         ~GLDraw_4_5();
189         void drawButtons(void);
190         virtual void initGLObjects();
191         virtual void initLocalGLObjects(void);
192         virtual void initFBO(void);
193         void initButtons(void);
194         //virtual void initBitmapVertex(void);
195         
196         virtual void uploadMainTexture(QImage *p, bool chromakey, bool was_mapped);
197         virtual void drawScreenTexture(void);
198         virtual void do_set_screen_multiply(float mul);
199         virtual void doSetGridsHorizonal(int lines, bool force);
200         virtual void doSetGridsVertical(int pixels, bool force);
201         void uploadBitmapTexture(QImage *p);
202         
203 // Note: Mapping vram from draw_thread does'nt work well.
204 // This feature might be disable. 20180728 K.Ohta.
205         void get_screen_geometry(int *w, int *h);
206         bool copy_screen_buffer(scrntype_t* target,int w, int h, int stride);
207
208         scrntype_t *get_screen_buffer(int y);
209         bool is_ready_to_map_vram_texture(void);
210         bool map_vram_texture(void);
211         bool unmap_vram_texture(void);
212         virtual bool is_mapped_buffer(void) {
213                 if(main_texture_buffer == 0) {
214                         return false;
215                 }
216                 return true;
217         }
218         // ToDo: Double buffer
219         virtual GLuint get_mapped_buffer_num(int region) {
220                 return (GLuint)main_texture_buffer;
221         }
222
223 public slots:
224         void updateBitmap(QImage *);
225         void uploadIconTexture(QPixmap *p, int icon_type, int localnum);
226         void setBrightness(GLfloat r, GLfloat g, GLfloat b);
227         void do_set_texture_size(QImage *p, int w, int h);
228         void do_set_horiz_lines(int lines);
229         virtual void paintGL(void);
230         virtual void resizeGL(int width, int height);
231         void do_set_display_osd(bool onoff);
232         void do_display_osd_leds(int lednum, bool onoff);
233
234 };
235 QT_END_NAMESPACE
236 #endif