OSDN Git Service

[Qt][MOVIE_SAVER] (MAYBE) Fix not running with Ubuntu 16.04 LTS.
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / qt_glutil_gl2_0.h
1 /*
2  * qt_glutil_gl2_0.h
3  * (c) 2016 K.Ohta <whatisthis.sowhat@gmail.com>
4  * License: GPLv2.
5  * Renderer with OpenGL v2.0 .
6  * History:
7  * Jan 21, 2016 : Initial.
8  */
9
10 #ifndef _QT_COMMON_GLUTIL_2_0_H
11 #define _QT_COMMON_GLUTIL_2_0_H
12
13 #include <QtGui>
14 #include <QColor>
15 #include <QPainter>
16 #include <QPen>
17 #include <QRect>
18 #include <QGLWidget>
19 #include <QImage>
20 #include <QOpenGLFunctions_2_0>
21 #include <QTimer>
22 #include <QOpenGLVertexArrayObject>
23 #include <QOpenGLShaderProgram>
24 #include <QOpenGLBuffer>
25 #include <QOpenGLContext>
26
27 #include <QMatrix4x2>
28 #include <QMatrix4x4>
29
30 #include <QVector>
31 #include <QVector2D>
32 #include <QVector3D>
33 #include <QVector4D>
34
35 #include "common.h"
36 //#include "osd.h"
37 //#include "emu.h"
38
39 typedef struct  {
40                 GLfloat x, y, z;
41                 GLfloat s, t;
42 } VertexTexCoord_t;
43 typedef struct {
44                 GLfloat x, y;
45 } VertexLines_t ;
46
47 class EMU;
48 class QEvent;
49 class GLDrawClass;
50 class QOpenGLFramebufferObject;
51 class QOpenGLFramebufferObjectFormat;
52
53 class DLL_PREFIX GLDraw_2_0 : public QObject
54 {
55         Q_OBJECT
56 protected:
57         GLDrawClass *p_wid;
58         EMU *p_emu;
59         QImage *imgptr;
60         bool smoosing;
61         bool gl_grid_horiz;
62         bool gl_grid_vert;
63         
64         int  vert_lines;
65         int  horiz_pixels;
66         GLfloat *glVertGrids;
67         GLfloat *glHorizGrids;
68         float screen_multiply;
69
70         float screen_width;
71         float screen_height;
72         
73         int screen_texture_width;
74         int screen_texture_width_old;
75         int screen_texture_height;
76         int screen_texture_height_old;
77
78         int rec_count;
79         int rec_width;
80         int rec_height;
81
82         QOpenGLFunctions_2_0 *extfunc;
83         VertexTexCoord_t vertexFormat[4];
84         
85         QOpenGLShaderProgram *main_shader;
86         
87         QOpenGLVertexArrayObject *vertex_screen;
88         QOpenGLBuffer *buffer_screen_vertex;
89         
90         VertexTexCoord_t vertexBitmap[4];
91         QOpenGLShaderProgram *bitmap_shader;
92         QOpenGLBuffer *buffer_bitmap_vertex;
93         QOpenGLVertexArrayObject *vertex_bitmap;
94         QOpenGLVertexArrayObject *vertex_button[128];
95         QOpenGLBuffer *buffer_button_vertex[128];
96         QOpenGLShaderProgram *button_shader;
97
98         GLuint uVramTextureID;
99         GLuint uButtonTextureID[128];
100         GLfloat fButtonX[128];
101         GLfloat fButtonY[128];
102         GLfloat fButtonWidth[128];
103         GLfloat fButtonHeight[128];
104         QVector<VertexTexCoord_t> *vertexButtons;
105
106         bool button_updated;
107         void updateButtonTexture(void);
108
109         GLfloat fBrightR;
110         GLfloat fBrightG;
111         GLfloat fBrightB;
112         bool set_brightness;
113         bool InitVideo;
114         GLuint uBitmapTextureID;
115         bool bitmap_uploaded;
116         virtual void setNormalVAO(QOpenGLShaderProgram *prg, QOpenGLVertexArrayObject *vp,
117                                           QOpenGLBuffer *bp, VertexTexCoord_t *tp, int size = 4);
118         
119         virtual void drawGridsHorizonal(void);
120         virtual void drawGridsVertical(void);
121         void drawGridsMain(GLfloat *tp,
122                                            int number,
123                                            GLfloat lineWidth = 0.2f,
124                                            QVector4D color = QVector4D(0.0f, 0.0f, 0.0f, 1.0f));
125         void drawButtons();
126         bool button_drawn;
127         void drawBitmapTexture(void);
128         bool crt_flag;
129         bool redraw_required;
130
131         QOpenGLFramebufferObject *offscreen_frame_buffer;
132         QOpenGLFramebufferObjectFormat *offscreen_frame_buffer_format;
133         QImage offscreen_image;
134 public:
135         GLDraw_2_0(GLDrawClass *parent, EMU *emu = 0);
136         ~GLDraw_2_0();
137
138         virtual void initGLObjects();
139         void initFBO(void);
140         virtual void initLocalGLObjects(void);
141         virtual void uploadMainTexture(QImage *p, bool chromakey);
142
143         virtual void drawScreenTexture(void);
144         void drawGrids(void);
145         void uploadBitmapTexture(QImage *p);
146
147         virtual void drawMain(QOpenGLShaderProgram *prg, QOpenGLVertexArrayObject *vp,
148                                                   QOpenGLBuffer *bp,
149                                                   VertexTexCoord_t *vertex_data,
150                                                   GLuint texid,
151                                                   QVector4D color, bool f_smoosing,
152                                                   bool do_chromakey = false,
153                                                   QVector3D chromakey = QVector3D(0.0f, 0.0f, 0.0f));
154 public slots:
155         virtual void setBrightness(GLfloat r, GLfloat g, GLfloat b);
156         virtual void do_set_texture_size(QImage *p, int w, int h);
157         void do_set_screen_multiply(float mul);
158         
159         void initializeGL();
160         void paintGL();
161         void resizeGL(int width, int height);
162
163         void setImgPtr(QImage *p);
164         void setSmoosing(bool);
165         void setDrawGLGridVert(bool);
166         void setDrawGLGridHoriz(bool);
167         void setVirtualVramSize(int ,int);      
168         void setEmuPtr(EMU *p);
169         void setChangeBrightness(bool);
170         void doSetGridsHorizonal(int lines, bool force);
171         void doSetGridsVertical(int pixels, bool force);
172         void updateBitmap(QImage *);
173         void paintGL_OffScreen(int count, int w, int h);
174
175 signals:
176         int sig_push_image_to_movie(QImage *);
177 };
178 #endif // _QT_COMMON_GLUTIL_2_0_H