OSDN Git Service

[Qt][OSD][LAMP] Improbe LED displaying.
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / qt_gldraw.cpp
1 /*
2  * qt_gldraw.cpp
3  * (c) 2011 K.Ohta <whatisthis.sowhat@gmail.com>
4  * Modified to Common Source code Project, License is changed to GPLv2.
5  * 
6  */
7
8
9 //#include "emu.h"
10
11 #include <QtGui>
12 #include <QColor>
13 #include <QPainter>
14 #include <QPen>
15 #include <QRect>
16 //#include <SDL/SDL.h>
17 #if defined(_WINDOWS) || defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
18 #include <GL/gl.h>
19 #include <GL/glext.h>
20 #include <GL/wglext.h>
21 #else
22 # if !defined(_USE_GLAPI_QT5_4) || !defined(_USE_GLAPI_QT5_1)  
23 #  include <GL/glx.h>
24 #  include <GL/glxext.h>
25 # endif
26 #endif
27 #include <GL/glu.h>
28
29
30 #ifdef USE_OPENMP
31 #include <omp.h>
32 #endif //_OPENMP
33 #include "qt_gldraw.h"
34 #include "qt_glutil_gl2_0.h"
35
36 #include "csp_logger.h"
37 #include "../osd.h"
38
39 //extern USING_FLAGS *using_flags;
40
41 void GLDrawClass::drawGrids(void)
42 {
43         if(extfunc != NULL) extfunc->drawGrids();
44 }
45
46 void GLDrawClass::drawUpdateTexture(bitmap_t *p)
47 {
48         if(using_flags->get_osd() != NULL)      using_flags->get_osd()->screen_mutex->lock();
49         if((p != NULL)) {
50                 if(extfunc != NULL) {
51 // Will fix at implemenitin PX7.
52                         if(using_flags->is_use_one_board_computer() || (using_flags->get_max_button() > 0)) {
53                                 extfunc->uploadMainTexture(&(p->pImage), true);
54                         } else {
55                                 extfunc->uploadMainTexture(&(p->pImage), false);
56                         }
57                 }
58         }
59         if(using_flags->get_osd() != NULL)      using_flags->get_osd()->screen_mutex->unlock();
60 }
61
62 void GLDrawClass::updateBitmap(QImage *p)
63 {
64         if(using_flags->is_use_one_board_computer()) {
65                 if(extfunc != NULL) extfunc->updateBitmap(p);
66         }
67 }
68
69 void GLDrawClass::resizeGL(int width, int height)
70 {
71         if(extfunc != NULL) {
72                 extfunc->resizeGL(width, height);
73         } else {
74                 draw_width = width;
75                 draw_height = height;
76                 delay_update = true;
77         }
78         //do_set_texture_size(imgptr, screen_texture_width, screen_texture_height);
79         csp_logger->debug_log(CSP_LOG_DEBUG, CSP_LOG_TYPE_GENERAL, "ResizeGL: %dx%d", width , height);
80         emit sig_resize_uibar(width, height);
81         emit sig_resize_osd(width);
82 }
83
84
85 /*
86  * "Paint" Event handler
87  */
88
89 void GLDrawClass::paintGL(void)
90 {
91         SaveToPixmap(); // If save requested, then Save to Pixmap.
92         //qWarning("Test");
93         if(extfunc != NULL) {
94                 if(delay_update) {
95                         extfunc->setVirtualVramSize(vram_width, vram_height);
96                         extfunc->resizeGL(draw_width, draw_height);
97                         delay_update = false;
98                 }
99                 //extfunc->paintGL();
100         }
101         emit sig_draw_timing();
102 }
103
104 void GLDrawClass::do_set_display_osd(bool onoff)
105 {
106         emit sig_set_display_osd(onoff);
107 }
108
109 void GLDrawClass::do_display_osd_leds(int lednum, bool onoff)
110 {
111         if((lednum >= -1) && (lednum < 32)) {
112                 emit sig_display_osd_leds(lednum, onoff);
113         }
114 }
115
116 //void GLDrawClass::paintEvent(QPaintEvent *ev)
117 //{
118 //      // Do Nothing.
119 //      // http://doc.qt.io/qt-5/qopenglwidget.html#Threading
120 //}
121
122 #ifndef GL_MULTISAMPLE
123 #define GL_MULTISAMPLE  0x809D
124 #endif
125
126 #if defined(_USE_GLAPI_QT5_4)
127 GLDrawClass::GLDrawClass(USING_FLAGS *p, CSP_Logger *logger, QWidget *parent, const QSurfaceFormat &fmt)
128         : QOpenGLWidget(parent, Qt::Widget)
129 #else
130 GLDrawClass::GLDrawClass(USING_FLAGS *p, CSP_Logger *logger, QWidget *parent, const QGLFormat &fmt)
131         : QGLWidget(fmt, parent)
132 #endif
133 {
134 #if defined(_USE_GLAPI_QT5_4)
135         this->setFormat(fmt);
136 #endif
137         csp_logger = logger;
138         save_pixmap_req = false;
139         enable_mouse = true;
140         p_emu = NULL;
141         using_flags = p;
142         
143         filename_screen_pixmap.clear();
144         //imgptr = NULL;
145         extfunc = NULL;
146         vram_width = using_flags->get_screen_width();
147         vram_height = using_flags->get_screen_height();
148         draw_width = using_flags->get_screen_width();
149         draw_height = using_flags->get_screen_height();
150         delay_update = false;
151         is_mouse_enabled = false;
152         emu_launched = false;
153         run_vm = true;
154         this->initKeyCode();
155 }
156
157 GLDrawClass::~GLDrawClass()
158 {
159         if(extfunc != NULL) delete extfunc;
160 //      this->releaseKeyCode();
161         emit sig_finished();
162
163 }
164
165 void GLDrawClass::do_set_led_width(int bitwidth)
166 {
167         if(extfunc != NULL) {
168                 extfunc->do_set_led_width(bitwidth);
169         }
170 }
171 void GLDrawClass::set_emu_launched()
172 {
173         emu_launched = true;
174         if(extfunc != NULL) {
175                 extfunc->set_emu_launched();
176         }
177 }
178
179 QSize GLDrawClass::minimumSizeHint() const
180 {
181         return QSize(50, 50);
182 }
183
184 QSize GLDrawClass::sizeHint() const
185 {
186         return QSize(400, 400);
187 }
188
189 QSize GLDrawClass::getCanvasSize(void)
190 {
191         return QSize(this->width(), this->height());
192 }
193
194 QSize GLDrawClass::getDrawSize(void)
195 {
196         return QSize(draw_width, draw_height);
197 }
198
199 void GLDrawClass::do_stop_run_vm()
200 {
201         run_vm = false;
202 }