OSDN Git Service

[Qt][OSD][LAMP] Improbe LED displaying.
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / qt_glutil_gl3_0.cpp
1 /*
2  * qt_glutil_gl3_0.cpp
3  * (c) 2016 K.Ohta <whatisthis.sowhat@gmail.com>
4  * License: GPLv2.
5  * Renderer with OpenGL v3.0 (extend from renderer with OpenGL v2.0).
6  * History:
7  * Jan 22, 2016 : Initial.
8  */
9
10 #include "qt_gldraw.h"
11 #include "qt_glpack.h"
12 #include "qt_glutil_gl3_0.h"
13 #include "csp_logger.h"
14 #include "menu_flags.h"
15
16 //extern USING_FLAGS *using_flags;
17 #if 0
18         // OLD_THREE_PHASE
19 const float luma_filter[24 + 1] = {
20                 -0.000071070,
21                 -0.000032816,
22                 0.000128784,
23                 0.000134711,
24                 -0.000226705,
25                 -0.000777988,
26                 -0.000997809,
27                 -0.000522802,
28                 0.000344691,
29                 0.000768930,
30                 0.000275591,
31                 -0.000373434,
32                 0.000522796,
33                 0.003813817,
34                 0.007502825,
35                 0.006786001,
36                 -0.002636726,
37                 -0.019461182,
38                 -0.033792479,
39                 -0.029921972,
40                 0.005032552,
41                 0.071226466,
42                 0.151755921,
43                 0.218166470,
44                 0.243902439
45         };
46 const float chroma_filter[24 + 1] = {
47                 0.001845562,
48                 0.002381606,
49                 0.003040177,
50                 0.003838976,
51                 0.004795341,
52                 0.005925312,
53                 0.007242534,
54                 0.008757043,
55                 0.010473987,
56                 0.012392365,
57                 0.014503872,
58                 0.016791957,
59                 0.019231195,
60                 0.021787070,
61                 0.024416251,
62                 0.027067414,
63                 0.029682613,
64                 0.032199202,
65                 0.034552198,
66                 0.036677005,
67                 0.038512317,
68                 0.040003044,
69                 0.041103048,
70                 0.041777517,
71                 0.042004791
72         };
73 #else
74 #if 1
75         // THREE_PHASE
76 const float luma_filter[24 + 1] = {
77                 -0.000012020,
78                 -0.000022146,
79                 -0.000013155,
80                 -0.000012020,
81                 -0.000049979,
82                 -0.000113940,
83                 -0.000122150,
84                 -0.000005612,
85                 0.000170516,
86                 0.000237199,
87                 0.000169640,
88                 0.000285688,
89                 0.000984574,
90                 0.002018683,
91                 0.002002275,
92                 -0.000909882,
93                 -0.007049081,
94                 -0.013222860,
95                 -0.012606931,
96                 0.002460860,
97                 0.035868225,
98                 0.084016453,
99                 0.135563500,
100                 0.175261268,
101                 0.190176552
102         };
103 const float chroma_filter[24 + 1] = {
104                 -0.000118847,
105                 -0.000271306,
106                 -0.000502642,
107                 -0.000930833,
108                 -0.001451013,
109                 -0.002064744,
110                 -0.002700432,
111                 -0.003241276,
112                 -0.003524948,
113                 -0.003350284,
114                 -0.002491729,
115                 -0.000721149,
116                 0.002164659,
117                 0.006313635,
118                 0.011789103,
119                 0.018545660,
120                 0.026414396,
121                 0.035100710,
122                 0.044196567,
123                 0.053207202,
124                 0.061590275,
125                 0.068803602,
126                 0.074356193,
127                 0.077856564,
128                 0.079052396
129         };
130 // END "ntsc-decode-filter-3phase.inc" //
131 #else
132                                 // TWO_PHASE
133 const float luma_filter[24 + 1] = {
134                 -0.000012020,
135                 -0.000022146,
136                 -0.000013155,
137                 -0.000012020,
138                 -0.000049979,
139                 -0.000113940,
140                 -0.000122150,
141                 -0.000005612,
142                 0.000170516,
143                 0.000237199,
144                 0.000169640,
145                 0.000285688,
146                 0.000984574,
147                 0.002018683,
148                 0.002002275,
149                 -0.000909882,
150                 -0.007049081,
151                 -0.013222860,
152                 -0.012606931,
153                 0.002460860,
154                 0.035868225,
155                 0.084016453,
156                 0.135563500,
157                 0.175261268,
158                 0.190176552
159         };
160         
161 const float chroma_filter[24 + 1] = {
162                 -0.000118847,
163                 -0.000271306,
164                 -0.000502642,
165                 -0.000930833,
166                 -0.001451013,
167                 -0.002064744,
168                 -0.002700432,
169                 -0.003241276,
170                 -0.003524948,
171                 -0.003350284,
172                 -0.002491729,
173                 -0.000721149,
174                 0.002164659,
175                 0.006313635,
176                 0.011789103,
177                 0.018545660,
178                 0.026414396,
179                 0.035100710,
180                 0.044196567,
181                 0.053207202,
182                 0.061590275,
183                 0.068803602,
184                 0.074356193,
185                 0.077856564,
186                 0.079052396
187         };
188 // END "ntsc-decode-filter-3phase.inc" //
189 #endif
190 #endif
191
192 GLDraw_3_0::GLDraw_3_0(GLDrawClass *parent, USING_FLAGS *p, CSP_Logger *logger, EMU *emu) : GLDraw_2_0(parent, p, logger, emu)
193 {
194         uTmpTextureID = 0;
195         
196         grids_shader = NULL;
197         
198         main_pass = NULL;
199         std_pass = NULL;
200         ntsc_pass1 = NULL;
201         ntsc_pass2 = NULL;
202         for(int i = 0; i < 32; i++) {
203                 led_pass[i] = NULL;
204         }
205         grids_horizonal_buffer = NULL;
206         grids_horizonal_vertex = NULL;
207         
208         grids_vertical_buffer = NULL;
209         grids_vertical_vertex = NULL;
210         ringing_phase = 0.0f;
211 }
212
213 GLDraw_3_0::~GLDraw_3_0()
214 {
215
216         if(main_pass  != NULL) delete main_pass;
217         if(std_pass   != NULL) delete std_pass;
218         if(ntsc_pass1 != NULL) delete ntsc_pass1;
219         if(ntsc_pass2 != NULL) delete ntsc_pass2;
220         for(int i = 0; i < 32; i++) {
221                 if(led_pass[i] != NULL) delete led_pass[i];
222         }
223         
224         if(grids_horizonal_buffer != NULL) {
225                 if(grids_horizonal_buffer->isCreated()) grids_horizonal_buffer->destroy();
226         }
227         if(grids_horizonal_vertex != NULL) {
228                 if(grids_horizonal_vertex->isCreated()) grids_horizonal_vertex->destroy();
229         }
230         if(grids_vertical_buffer != NULL) {
231                 if(grids_vertical_buffer->isCreated()) grids_vertical_buffer->destroy();
232         }
233         if(grids_horizonal_vertex != NULL) {
234                 if(grids_vertical_vertex->isCreated()) grids_vertical_vertex->destroy();
235         }
236
237 }
238
239 void GLDraw_3_0::initFBO(void)
240 {
241         glHorizGrids = (GLfloat *)malloc(sizeof(float) * (using_flags->get_real_screen_height() + 2) * 6);
242         if(glHorizGrids != NULL) {
243                 doSetGridsHorizonal(using_flags->get_real_screen_height(), true);
244         }
245         glVertGrids  = (GLfloat *)malloc(sizeof(float) * (using_flags->get_real_screen_width() + 2) * 6);
246         if(glVertGrids != NULL) {
247                 doSetGridsVertical(using_flags->get_real_screen_width(), true);
248         }
249         if(using_flags->get_max_button() > 0) {
250                 initButtons();
251         }
252         // Init view
253         extfunc->glClearColor(0.0, 0.0, 0.0, 1.0);
254 }
255
256 void GLDraw_3_0::setNormalVAO(QOpenGLShaderProgram *prg,
257                                                            QOpenGLVertexArrayObject *vp,
258                                                            QOpenGLBuffer *bp,
259                                                            VertexTexCoord_t *tp,
260                                                            int size)
261 {
262         int vertex_loc = prg->attributeLocation("vertex");
263         int texcoord_loc = prg->attributeLocation("texcoord");
264
265         vp->bind();
266         bp->bind();
267
268         if(tp == NULL) {
269 #if 0
270                 VertexTexCoord_t tv[4];
271                 tv[0].x = -1.0f;
272                 tv[0].y = -1.0f;
273                 tv[0].z = -0.9f;
274                 tv[0].s = 0.0f;
275                 tv[0].t = 1.0f;
276                 
277                 tv[1].x = +1.0f;
278                 tv[1].y = -1.0f;
279                 tv[1].z = -0.9f;
280                 tv[1].s = 1.0f;
281                 tv[1].t = 1.0f;
282                 
283                 tv[2].x = +1.0f;
284                 tv[2].y = +1.0f;
285                 tv[2].z = -0.9f;
286                 tv[2].s = 1.0f;
287                 tv[2].t = 0.0f;
288
289                 tv[3].x = -1.0f;
290                 tv[3].y = +1.0f;
291                 tv[3].z = -0.9f;
292                 tv[3].s = 0.0f;
293                 tv[3].t = 0.0f;
294                 bp->write(0, tv, sizeof(VertexTexCoord_t) * 4);
295 #endif
296         } else {
297                 bp->write(0, tp, sizeof(VertexTexCoord_t) * size);
298         }
299         prg->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3, sizeof(VertexTexCoord_t));
300         prg->setAttributeBuffer(texcoord_loc, GL_FLOAT, 3 * sizeof(GLfloat), 2, sizeof(VertexTexCoord_t));
301         prg->setUniformValue("a_texture", 0);
302                            
303         extfunc->glVertexAttribPointer(vertex_loc, 3, GL_FLOAT, GL_FALSE, sizeof(VertexTexCoord_t), 0); 
304         extfunc->glVertexAttribPointer(texcoord_loc, 2, GL_FLOAT, GL_FALSE, sizeof(VertexTexCoord_t), 
305                                                                (char *)NULL + 3 * sizeof(GLfloat)); 
306         bp->release();
307         vp->release();
308         prg->enableAttributeArray(vertex_loc);
309         prg->enableAttributeArray(texcoord_loc);
310 }
311
312 void GLDraw_3_0::initGLObjects()
313 {
314         extfunc = new QOpenGLFunctions_3_0;
315         extfunc->initializeOpenGLFunctions();
316         extfunc->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texture_max_size);
317 }       
318
319 void GLDraw_3_0::initPackedGLObject(GLScreenPack **p,
320                                                                         int _width, int _height,
321                                                                         const QString vertex_shader, const QString fragment_shader,
322                                                                         const QString _name)
323 {
324         QString s;
325         GLScreenPack *pp;
326         if(p != NULL) {
327                 pp = new GLScreenPack(_width, _height, p_wid);
328                 *p = pp;
329                 if(pp != NULL) {
330                         pp->initialize(_width, _height, vertex_shader, fragment_shader);
331                         s = pp->getShaderLog();
332                         if(s.size() > 0) {
333                                 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GL_SHADER, "In shader of %s ", _name.toLocal8Bit().constData());
334                                 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GL_SHADER, "Vertex: %s ",  vertex_shader.toLocal8Bit().constData());
335                                 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GL_SHADER, "Fragment: %s ", fragment_shader.toLocal8Bit().constData());
336                                 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GL_SHADER, "%s", s.toLocal8Bit().constData());
337                         }
338                 }
339         }
340 }
341                                         
342
343
344 bool GLDraw_3_0::initGridShaders(const QString vertex_fixed, const QString vertex_rotate, const QString fragment)
345 {
346         bool f = false;
347         grids_shader = new QOpenGLShaderProgram(p_wid);
348         if(grids_shader != NULL) {
349                 if(using_flags->is_use_screen_rotate()) {
350                         f = grids_shader->addShaderFromSourceFile(QOpenGLShader::Vertex, vertex_rotate);
351                 } else {
352                         f = grids_shader->addShaderFromSourceFile(QOpenGLShader::Vertex, vertex_fixed);
353                 }
354                 f &= grids_shader->addShaderFromSourceFile(QOpenGLShader::Fragment, fragment);
355                 f &= grids_shader->link();
356         }
357         return f;
358 }
359
360 bool GLDraw_3_0::initGridVertexObject(QOpenGLBuffer **vbo, QOpenGLVertexArrayObject **vao, int alloc_size)
361 {
362         QOpenGLBuffer *bp = NULL;
363         QOpenGLVertexArrayObject *ap = NULL;
364         *vao = NULL;
365         *vbo = NULL;
366         *vbo  = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
367         bp = *vbo;
368         if(bp != NULL) {
369                 if(bp->create()) {
370                         bp->bind();
371                         bp->allocate(alloc_size * sizeof(GLfloat) * 3 * 2);
372                         bp->release();
373                 } else {
374                         delete *vbo;
375                         return false;
376                 }
377         } else {
378                 return false;
379         }
380         
381         *vao = new QOpenGLVertexArrayObject;
382         ap = *vao;
383         if(ap == NULL) {
384                 bp->destroy();
385                 delete *vbo;
386                 return false;
387         }
388         if(!ap->create()) {
389                 delete *vao;
390                 bp->destroy();
391                 delete *vbo;
392                 return false;
393         }
394         return true;
395 }
396
397
398 void GLDraw_3_0::initLocalGLObjects(void)
399 {
400
401         int _width = using_flags->get_screen_width();
402         int _height = using_flags->get_screen_height();
403         
404         if((_width * 4) <= texture_max_size) {
405                 _width = _width * 4;
406                 low_resolution_screen = true;
407         } else {
408                 _width = _width * 2;
409         }
410         p_wid->makeCurrent();
411         
412         vertexFormat[0].x = -1.0f;
413         vertexFormat[0].y = -1.0f;
414         vertexFormat[0].z = -0.9f;
415         vertexFormat[0].s = 0.0f;
416         vertexFormat[0].t = 1.0f;
417         
418         vertexFormat[1].x = +1.0f;
419         vertexFormat[1].y = -1.0f;
420         vertexFormat[1].z = -0.9f;
421         vertexFormat[1].s = 1.0f;
422         vertexFormat[1].t = 1.0f;
423         
424         vertexFormat[2].x = +1.0f;
425         vertexFormat[2].y = +1.0f;
426         vertexFormat[2].z = -0.9f;
427         vertexFormat[2].s = 1.0f;
428         vertexFormat[2].t = 0.0f;
429         
430         vertexFormat[3].x = -1.0f;
431         vertexFormat[3].y = +1.0f;
432         vertexFormat[3].z = -0.9f;
433         vertexFormat[3].s = 0.0f;
434         vertexFormat[3].t = 0.0f;
435
436         if(using_flags->is_use_one_board_computer() || (using_flags->get_max_button() > 0)) {
437                 initPackedGLObject(&main_pass,
438                                                    using_flags->get_screen_width() * 2, using_flags->get_screen_height() * 2,
439                                                    ":/vertex_shader.glsl" , ":/chromakey_fragment_shader2.glsl",
440                                                    "Main Shader");
441         } else {
442                 initPackedGLObject(&main_pass,
443                                                    using_flags->get_screen_width() * 2, using_flags->get_screen_height() * 2,
444                                                    ":/vertex_shader.glsl" , ":/fragment_shader.glsl",
445                                                    "Main Shader");
446         }               
447         if(main_pass != NULL) {
448                 setNormalVAO(main_pass->getShader(), main_pass->getVAO(),
449                                          main_pass->getVertexBuffer(),
450                                          vertexFormat, 4);
451         }
452         initPackedGLObject(&std_pass,
453                                            using_flags->get_screen_width(), using_flags->get_screen_height(),
454                                            ":/vertex_shader.glsl" , ":/chromakey_fragment_shader.glsl",
455                                            "Standard Shader");
456         for(int i = 0; i < 32; i++) {
457                 initPackedGLObject(&(led_pass[i]),
458                                            10, 10,
459                                            ":/led_vertex_shader.glsl" , ":/led_fragment_shader.glsl",
460                                            "LED Shader");
461                 set_led_vertex(i);
462         }
463
464         initPackedGLObject(&ntsc_pass1,
465                                            _width, _height,
466                                            ":/vertex_shader.glsl" , ":/ntsc_pass1.glsl",
467                                            "NTSC Shader Pass1");
468         initPackedGLObject(&ntsc_pass2,
469                                            _width / 2, _height,
470                                            ":/vertex_shader.glsl" , ":/ntsc_pass2.glsl",
471                                            "NTSC Shader Pass2");
472         {
473                 int ii;
474                 QOpenGLShaderProgram *shader = ntsc_pass2->getShader();
475                 shader->bind();
476                 ii = shader->uniformLocation("luma_filter");
477                 if(ii >= 0) {
478                         shader->setUniformValueArray(ii, luma_filter, 24 + 1, 1);
479                 }
480                 ii = shader->uniformLocation("chroma_filter");
481                 if(ii >= 0) {
482                         shader->setUniformValueArray(ii, chroma_filter, 24 + 1, 1);
483                 }
484                 shader->release();
485         }
486    
487         if(using_flags->is_use_one_board_computer()) {
488                 initBitmapVertex();
489                 initPackedGLObject(&bitmap_block,
490                                                    _width * 2, _height * 2,
491                                                    ":/vertex_shader.glsl", ":/normal_fragment_shader.glsl",
492                                                    "Background Bitmap Shader");
493                 if(bitmap_block != NULL) {
494                         setNormalVAO(bitmap_block->getShader(), bitmap_block->getVAO(),
495                                                  bitmap_block->getVertexBuffer(),
496                                                  vertexBitmap, 4);
497                 }
498         }
499         initGridShaders(":/grids_vertex_shader_fixed.glsl", ":/grids_vertex_shader.glsl", ":/grids_fragment_shader.glsl");
500         
501         initGridVertexObject(&grids_horizonal_buffer, &grids_horizonal_vertex, using_flags->get_real_screen_height() + 3);
502         doSetGridsHorizonal(using_flags->get_real_screen_height(), true);
503         
504         initGridVertexObject(&grids_vertical_buffer, &grids_vertical_vertex, using_flags->get_real_screen_width() + 3);
505         doSetGridsVertical(using_flags->get_real_screen_width(), true);
506
507         do_set_texture_size(NULL, -1, -1);
508         p_wid->doneCurrent();
509 }
510
511 void GLDraw_3_0::updateGridsVAO(QOpenGLBuffer *bp,
512                                                                 QOpenGLVertexArrayObject *vp,
513                                                                 GLfloat *tp,
514                                                                 int number)
515
516 {
517         bool checkf = false;
518         if((bp != NULL) && (vp != NULL)) {
519                 if(bp->isCreated()) {
520                         if(bp->size() < (int)((number + 1) * sizeof(GLfloat) * 3 * 2)) {
521                                 bp->destroy();
522                                 bp->create();
523                                 checkf = true;
524                         }
525                 } else {
526                         bp->create();
527                         checkf = true;
528                 }
529                 vp->bind();
530                 bp->bind();
531                 if(checkf) {
532                         bp->allocate((number + 1) * sizeof(GLfloat) * 3 * 2);
533                 }
534                 if(tp != NULL) {
535                         bp->write(0, tp, (number + 1) * sizeof(GLfloat) * 3 * 2);
536                 }
537                 bp->release();
538                 vp->release();
539         }
540 }
541 void GLDraw_3_0::drawGridsMain_3(QOpenGLShaderProgram *prg,
542                                                                  QOpenGLBuffer *bp,
543                                                                  QOpenGLVertexArrayObject *vp,
544                                                                  int number,
545                                                                  GLfloat lineWidth,
546                                                                  QVector4D color)
547 {
548         if(number <= 0) return;
549         extfunc->glDisable(GL_TEXTURE_2D);
550         extfunc->glDisable(GL_DEPTH_TEST);
551         extfunc->glDisable(GL_BLEND);
552
553         if((bp == NULL) || (vp == NULL) || (prg == NULL)) return;
554         if((!bp->isCreated()) || (!vp->isCreated()) || (!prg->isLinked())) return;
555         {
556                 bp->bind();
557                 vp->bind();
558                 prg->bind();
559                 //GLfloat ff[2];
560                 //bp->read(8, &ff, sizeof(GLfloat) * 2);
561                 //printf("%d %f %f\n", number, ff[0], ff[1]);
562                 
563                 prg->setUniformValue("color", color);
564                 prg->enableAttributeArray("vertex");
565                 int vertex_loc = prg->attributeLocation("vertex");
566                 
567                 extfunc->glViewport(0, 0, p_wid->width(), p_wid->height());
568                 extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
569                 //extfunc->glEnable(GL_BLEND);
570                 //extfunc->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
571                 //extfunc->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
572                 extfunc->glVertexAttribPointer(vertex_loc, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 3, 0); 
573                 extfunc->glEnableVertexAttribArray(vertex_loc);
574                 
575                 extfunc->glEnableClientState(GL_VERTEX_ARRAY);
576                 extfunc->glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
577                 extfunc->glLineWidth(lineWidth);
578                 extfunc->glVertexPointer(3, GL_FLOAT, 0, 0);
579                 extfunc->glDrawArrays(GL_LINES, 0, (number + 1) * 2);
580                 extfunc->glDisableClientState(GL_VERTEX_ARRAY);
581                 //extfunc->glDisable(GL_BLEND);
582                 prg->release();
583                 vp->release();
584                 bp->release();
585         }
586 }
587
588 void GLDraw_3_0::doSetGridsVertical(int pixels, bool force)
589 {
590         GLDraw_2_0::doSetGridsVertical(pixels, force);
591         updateGridsVAO(grids_vertical_buffer,
592                                    grids_vertical_vertex,
593                                    glVertGrids,
594                                    pixels);
595         
596 }
597 void GLDraw_3_0::doSetGridsHorizonal(int lines, bool force)
598 {
599         GLDraw_2_0::doSetGridsHorizonal(lines, force);
600         updateGridsVAO(grids_horizonal_buffer,
601                                    grids_horizonal_vertex,
602                                    glHorizGrids,
603                                    lines);
604 }
605
606 void GLDraw_3_0::drawGridsHorizonal(void)
607 {
608         QVector4D c= QVector4D(0.0f, 0.0f, 0.0f, 1.0f);
609         drawGridsMain_3(grids_shader,
610                                         grids_horizonal_buffer,
611                                         grids_horizonal_vertex,
612                                         vert_lines,
613                                         0.15f,
614                                         c);
615 }
616
617 void GLDraw_3_0::drawGridsVertical(void)
618 {
619         QVector4D c= QVector4D(0.0f, 0.0f, 0.0f, 1.0f);
620         drawGridsMain_3(grids_shader,
621                                         grids_vertical_buffer,
622                                         grids_vertical_vertex,
623                                         horiz_pixels,
624                                         0.5f,
625                                         c);
626 }
627
628 void GLDraw_3_0::renderToTmpFrameBuffer_nPass(GLuint src_texture,
629                                                                                           GLuint src_w,
630                                                                                           GLuint src_h,
631                                                                                           GLScreenPack *renderObject,
632                                                                                           GLuint dst_w,
633                                                                                           GLuint dst_h,
634                                                                                           bool use_chromakey)
635 {
636         {
637                 QOpenGLShaderProgram *shader = renderObject->getShader();
638                 int ii;
639                 // NTSC_PASSx
640
641                 extfunc->glClearColor(0.0, 0.0, 0.0, 1.0);
642                 extfunc->glClearDepth(1.0f);
643                 extfunc->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
644                 {
645                         if((src_texture != 0) && (shader != NULL)) {
646                                 extfunc->glEnable(GL_TEXTURE_2D);
647                                 renderObject->bind();
648                                 //extfunc->glViewport(0, 0, src_w, src_h);
649                                 extfunc->glViewport(0, 0, dst_w, dst_h);
650                                 extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
651                                 extfunc->glActiveTexture(GL_TEXTURE0);
652                                 extfunc->glBindTexture(GL_TEXTURE_2D, src_texture);
653                                 extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
654                                 extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
655                                 //extfunc->glColor4f(1.0, 1.0, 1.0, 1.0);
656                                 shader->setUniformValue("a_texture", 0);
657                                 //shader->setUniformValue("a_texture", src_texture);
658                                 {
659                                         ii = shader->uniformLocation("source_size");
660                                         if(ii >= 0) {
661                                                 QVector4D source_size = QVector4D((float)src_w, (float)src_h, 0, 0);
662                                                 shader->setUniformValue(ii, source_size);
663                                         }
664                                         ii = shader->uniformLocation("target_size");
665                                         if(ii >= 0) {
666                                                 QVector4D target_size = QVector4D((float)dst_w, (float)dst_h, 0, 0);
667                                                 shader->setUniformValue(ii, target_size);
668                                         }
669                                         ii = shader->uniformLocation("phase");
670                                         if(ii >= 0) {
671                                                 ringing_phase = ringing_phase + 0.093;
672                                                 if(ringing_phase > 1.0) ringing_phase = ringing_phase - 1.0;
673                                                 shader->setUniformValue(ii,  ringing_phase);
674                                         }
675                                         //ii = shader->uniformLocation("luma_filter");
676                                         //if(ii >= 0) {
677                                         //      shader->setUniformValueArray(ii, luma_filter, 24 + 1, 1);
678                                         //}
679                                         //ii = shader->uniformLocation("chroma_filter");
680                                         //if(ii >= 0) {
681                                         //      shader->setUniformValueArray(ii, chroma_filter, 24 + 1, 1);
682                                         //}
683                                 }
684                                 {
685                                         QVector4D c(fBrightR, fBrightG, fBrightB, 1.0);
686                                         QVector3D chromakey(0.0, 0.0, 0.0);
687                 
688                                         ii = shader->uniformLocation("color");
689                                         if(ii >= 0) {
690                                                 shader->setUniformValue(ii, c);
691                                         }
692                                         ii = shader->uniformLocation("do_chromakey");
693                                         if(ii >= 0) {
694                                                 if(use_chromakey) {
695                                                         int ij;
696                                                         ij = shader->uniformLocation("chromakey");
697                                                         if(ij >= 0) {
698                                                                 shader->setUniformValue(ij, chromakey);
699                                                         }
700                                                         shader->setUniformValue(ii, GL_TRUE);
701                                                 } else {
702                                                         shader->setUniformValue(ii, GL_FALSE);
703                                                 }
704                                         }
705                                         //shader->setUniformValue("tex_width",  (float)w); 
706                                         //shader->setUniformValue("tex_height", (float)h);
707                                 }
708                                 shader->enableAttributeArray("texcoord");
709                                 shader->enableAttributeArray("vertex");
710                                 
711                                 int vertex_loc = shader->attributeLocation("vertex");
712                                 int texcoord_loc = shader->attributeLocation("texcoord");
713                                 extfunc->glEnableVertexAttribArray(vertex_loc);
714                                 extfunc->glEnableVertexAttribArray(texcoord_loc);
715                                 extfunc->glEnable(GL_VERTEX_ARRAY);
716
717                                 extfunc->glDrawArrays(GL_POLYGON, 0, 4);
718                                 
719                                 extfunc->glViewport(0, 0, dst_w, dst_h);
720                                 extfunc->glOrtho(0.0f, (float)dst_w, 0.0f, (float)dst_h, -1.0, 1.0);
721                                 renderObject->release();
722                                 extfunc->glBindTexture(GL_TEXTURE_2D, 0);
723                                 extfunc->glDisable(GL_TEXTURE_2D);
724                         }
725                 }
726         }
727 }
728
729
730 void GLDraw_3_0::uploadMainTexture(QImage *p, bool use_chromakey)
731 {
732         // set vertex
733         redraw_required = true;
734         if(p == NULL) return;
735         //redraw_required = true;
736         imgptr = p;
737         if(uVramTextureID == 0) {
738                 uVramTextureID = p_wid->bindTexture(*p);
739         }
740         {
741                 // Upload to main texture
742                 extfunc->glBindTexture(GL_TEXTURE_2D, uVramTextureID);
743                 extfunc->glTexSubImage2D(GL_TEXTURE_2D, 0,
744                                                                  0, 0,
745                                                                  //screen_texture_width * 2,
746                                                                  //screen_texture_height * 2,
747                                                                  p->width(), p->height(),
748                                                                  GL_BGRA, GL_UNSIGNED_BYTE, p->constBits());
749                 extfunc->glBindTexture(GL_TEXTURE_2D, 0);
750         }
751         if(using_flags->is_support_tv_render() && (using_flags->get_config_ptr()->rendering_type == CONFIG_RENDER_TYPE_TV)) {
752                 renderToTmpFrameBuffer_nPass(uVramTextureID,
753                                                                          screen_texture_width,
754                                                                          screen_texture_height,
755                                                                          ntsc_pass1,
756                                                                          ntsc_pass1->getViewportWidth(),
757                                                                          ntsc_pass1->getViewportHeight());
758                 
759                 renderToTmpFrameBuffer_nPass(ntsc_pass1->getTexture(),
760                                                                          ntsc_pass1->getViewportWidth(),
761                                                                          ntsc_pass1->getViewportHeight(),
762                                                                          ntsc_pass2,
763                                                                          ntsc_pass2->getViewportWidth(),
764                                                                          ntsc_pass2->getViewportHeight());
765                 uTmpTextureID = ntsc_pass2->getTexture();
766         } else {
767                 renderToTmpFrameBuffer_nPass(uVramTextureID,
768                                                                          screen_texture_width,
769                                                                          screen_texture_height,
770                                                                          std_pass,
771                                                                          std_pass->getViewportWidth(),
772                                                                          std_pass->getViewportHeight(),
773                                                                          use_chromakey);
774
775                 //std_pass->bind();
776                 uTmpTextureID = std_pass->getTexture();
777                 //std_pass->release();
778         }
779         crt_flag = true;
780 }
781
782 void GLDraw_3_0::drawScreenTexture(void)
783 {
784         if(using_flags->is_use_one_board_computer()) {
785                 extfunc->glEnable(GL_BLEND);
786                 extfunc->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
787         } else {
788                 extfunc->glDisable(GL_BLEND);
789         }
790         
791         QVector4D color;
792         smoosing = using_flags->get_config_ptr()->use_opengl_filters;
793         if(set_brightness) {
794                 color = QVector4D(fBrightR, fBrightG, fBrightB, 1.0);
795         } else {
796                 color = QVector4D(1.0, 1.0, 1.0, 1.0);
797         }
798         if(using_flags->is_use_one_board_computer()) {
799                 drawMain(main_pass,
800                                  uTmpTextureID, // v2.0
801                                  color, smoosing,
802                                  true, QVector3D(0.0, 0.0, 0.0));       
803                 extfunc->glDisable(GL_BLEND);
804         } else {
805                 drawMain(main_pass,
806                                  uTmpTextureID, // v2.0
807                                  color, smoosing);      
808         }
809 }
810
811
812 void GLDraw_3_0::drawMain(GLScreenPack *obj,
813                                                   GLuint texid,
814                                                   QVector4D color,
815                                                   bool f_smoosing,
816                                                   bool do_chromakey,
817                                                   QVector3D chromakey)
818                                                    
819 {
820         QOpenGLShaderProgram *prg = obj->getShader();
821         QOpenGLVertexArrayObject *vp = obj->getVAO();
822         QOpenGLBuffer *bp = obj->getVertexBuffer();
823         int ii;
824                 
825         if(texid != 0) {
826                 extfunc->glEnable(GL_TEXTURE_2D);
827                 vp->bind();
828                 bp->bind();
829                 prg->bind();
830                 extfunc->glViewport(0, 0, p_wid->width(), p_wid->height());
831                 extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
832                 extfunc->glActiveTexture(GL_TEXTURE0);
833                 extfunc->glBindTexture(GL_TEXTURE_2D, texid);
834                 if(!f_smoosing) {
835                         extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
836                         extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
837                 } else {
838                         extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
839                         extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
840                 }
841                 prg->setUniformValue("a_texture", 0);
842                 
843                 ii = prg->uniformLocation("color");
844                 if(ii >= 0) {
845                         prg->setUniformValue(ii,  color);
846                 }
847                 
848                 ii = prg->uniformLocation("tex_width");
849                 if(ii >= 0) {
850                         prg->setUniformValue(ii,  (float)screen_texture_width);
851                 }
852                 
853                 ii = prg->uniformLocation("tex_height");
854                 if(ii >= 0) {
855                         prg->setUniformValue(ii,  (float)screen_texture_height);
856                 }
857                 if(using_flags->is_use_screen_rotate()) {
858                         if(using_flags->get_config_ptr()->rotate_type) {
859                                 prg->setUniformValue("rotate", GL_TRUE);
860                         } else {
861                                 prg->setUniformValue("rotate", GL_FALSE);
862                         }
863                 } else {
864                         prg->setUniformValue("rotate", GL_FALSE);
865                 }
866
867                 if(do_chromakey) {
868                         ii = prg->uniformLocation("chromakey");
869                         if(ii >= 0) {
870                                 prg->setUniformValue(ii, chromakey);
871                         }
872                         ii = prg->uniformLocation("do_chromakey");
873                         if(ii >= 0) {
874                                 prg->setUniformValue(ii, GL_TRUE);
875                         }
876                 } else {
877                         ii = prg->uniformLocation("do_chromakey");
878                         if(ii >= 0) {
879                                 prg->setUniformValue(ii, GL_FALSE);
880                         }
881                 }
882                 
883                 prg->enableAttributeArray("texcoord");
884                 prg->enableAttributeArray("vertex");
885                 int vertex_loc = prg->attributeLocation("vertex");
886                 int texcoord_loc = prg->attributeLocation("texcoord");
887                 extfunc->glEnableVertexAttribArray(vertex_loc);
888                 extfunc->glEnableVertexAttribArray(texcoord_loc);
889                 extfunc->glEnable(GL_VERTEX_ARRAY);
890                 extfunc->glDrawArrays(GL_POLYGON, 0, 4);
891                 bp->release();
892                 vp->release();
893                 
894                 prg->release();
895                 extfunc->glBindTexture(GL_TEXTURE_2D, 0);
896                 extfunc->glDisable(GL_TEXTURE_2D);
897         }
898 }
899
900 void GLDraw_3_0::drawButtonsMain(int num, bool f_smoosing)
901 {
902         GLuint texid = uButtonTextureID[num];
903         QOpenGLBuffer *bp = buffer_button_vertex[num];
904         QOpenGLShaderProgram  *prg = button_shader;
905         QOpenGLVertexArrayObject *vp = vertex_button[num];
906         QVector4D color;
907         int ii;
908         
909         color = QVector4D(1.0, 1.0, 1.0, 1.0);
910         
911         if((bp != NULL) && (vp != NULL) && (prg != NULL)) {
912                 if((bp->isCreated()) && (vp->isCreated()) && (prg->isLinked())) {
913                         bp->bind();
914                         vp->bind();
915                         prg->bind();
916                         extfunc->glViewport(0, 0, p_wid->width(), p_wid->height());
917                         extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
918                         extfunc->glActiveTexture(GL_TEXTURE0);
919                         extfunc->glBindTexture(GL_TEXTURE_2D, texid);
920                         if(!f_smoosing) {
921                                 extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
922                                 extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
923                         } else {
924                                 extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
925                                 extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
926                         }
927                         prg->setUniformValue("a_texture", 0);
928                         
929                         ii = prg->uniformLocation("color");
930                         if(ii >= 0) {
931                                 prg->setUniformValue(ii,  color);
932                         }
933                         ii = prg->uniformLocation("do_chromakey");
934                         if(ii >= 0) {
935                                 prg->setUniformValue(ii, GL_FALSE);
936                         }
937                         if(using_flags->is_use_screen_rotate()) {
938                                 if(using_flags->get_config_ptr()->rotate_type) {
939                                         prg->setUniformValue("rotate", GL_TRUE);
940                                 } else {
941                                         prg->setUniformValue("rotate", GL_FALSE);
942                                 }
943                         } else {
944                                 prg->setUniformValue("rotate", GL_FALSE);
945                         }
946                         int vertex_loc = prg->attributeLocation("vertex");
947                         int texcoord_loc = prg->attributeLocation("texcoord");
948                         //prg->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3, sizeof(VertexTexCoord_t));
949                         //prg->setAttributeBuffer(texcoord_loc, GL_FLOAT, 3 * sizeof(GLfloat), 2, sizeof(VertexTexCoord_t));
950                         prg->enableAttributeArray(vertex_loc);
951                         prg->enableAttributeArray(texcoord_loc);
952                         extfunc->glEnableVertexAttribArray(vertex_loc);
953                         extfunc->glEnableVertexAttribArray(texcoord_loc);
954                         extfunc->glEnable(GL_VERTEX_ARRAY);
955                         extfunc->glDrawArrays(GL_POLYGON, 0, 4);
956                         bp->release();
957                         vp->release();
958                         prg->release();
959                         extfunc->glBindTexture(GL_TEXTURE_2D, 0);
960                         extfunc->glDisable(GL_TEXTURE_2D);
961                         return;
962                         }
963                 }
964
965 }
966
967 void GLDraw_3_0::drawButtons(void)
968 {
969         for(int i = 0; i < using_flags->get_max_button(); i++) {
970                 drawButtonsMain(i, false);
971         }
972 }
973
974 void GLDraw_3_0::drawBitmapTexture(void)
975 {
976         QVector4D color = QVector4D(1.0f, 1.0f, 1.0f, 1.0f);
977         smoosing = using_flags->get_config_ptr()->use_opengl_filters;
978
979         if(using_flags->is_use_one_board_computer()) {
980                 extfunc->glDisable(GL_BLEND);
981                 drawMain(bitmap_block,
982                                  uBitmapTextureID,
983                                  color, smoosing);
984         }
985 }
986
987 void GLDraw_3_0::drawLedMain(GLScreenPack *obj,
988                                                          QVector4D color)
989 {
990         QOpenGLShaderProgram *prg = obj->getShader();
991         QOpenGLVertexArrayObject *vp = obj->getVAO();
992         QOpenGLBuffer *bp = obj->getVertexBuffer();
993         int ii;
994                 
995         {
996                 extfunc->glDisable(GL_TEXTURE_2D);
997                 extfunc->glEnable(GL_BLEND);
998                 extfunc->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
999                 vp->bind();
1000                 bp->bind();
1001                 prg->bind();
1002                 extfunc->glViewport(0, 0, p_wid->width(), p_wid->height());
1003                 extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
1004                 ii = prg->uniformLocation("color");
1005                 if(ii >= 0) {
1006                         prg->setUniformValue(ii,  color);
1007                 }
1008                 
1009                 prg->enableAttributeArray("vertex");
1010                 int vertex_loc = prg->attributeLocation("vertex");
1011                 extfunc->glEnableVertexAttribArray(vertex_loc);
1012                 extfunc->glEnable(GL_VERTEX_ARRAY);
1013                 extfunc->glDrawArrays(GL_POLYGON, 0, 4);
1014                 bp->release();
1015                 vp->release();
1016                 
1017                 prg->release();
1018                 extfunc->glDisable(GL_TEXTURE_2D);
1019                 extfunc->glDisable(GL_BLEND);
1020         }
1021
1022 }
1023
1024 void GLDraw_3_0::drawOsdLeds()
1025 {
1026         QVector4D color_on;
1027         QVector4D color_off;
1028         uint32_t bit = 0x00000001;
1029         if(osd_onoff) {
1030                 color_on = QVector4D(0.95, 0.0, 0.05, 1.0);
1031                 color_off = QVector4D(0.05,0.05, 0.05, 0.10);
1032         } else {
1033                 color_on = QVector4D(0.00,0.00, 0.00, 0.0);
1034                 color_off = QVector4D(0.00,0.00, 0.00, 0.0);
1035         }
1036         if(osd_onoff) {
1037                 if(osd_led_status_bak != osd_led_status) {
1038                         for(int i = 0; i < osd_led_bit_width; i++) {
1039                                 if((bit & osd_led_status) == (bit & osd_led_status_bak)) {
1040                                         bit <<= 1;
1041                                         continue;
1042                                 }
1043                                 drawLedMain(led_pass[i],
1044                                                         ((osd_led_status & bit) != 0) ? color_on : color_off);
1045                                 bit <<= 1;
1046                         }
1047                         osd_led_status_bak = osd_led_status;
1048                 }
1049         }
1050 }
1051
1052 void GLDraw_3_0::paintGL(void)
1053 {
1054         //p_wid->makeCurrent();
1055
1056         if(crt_flag || redraw_required) { //return;
1057                 if(emu_launched) {
1058                         crt_flag = false;
1059                 }
1060                 redraw_required = false;
1061                 extfunc->glViewport(0, 0, p_wid->width(), p_wid->height());
1062                 extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
1063                 
1064                 extfunc->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1065                 extfunc->glEnable(GL_DEPTH_TEST);
1066                 extfunc->glDisable(GL_BLEND);
1067                 if(using_flags->is_use_one_board_computer() || using_flags->is_use_bitmap()) {
1068                         extfunc->glEnable(GL_BLEND);
1069                         drawBitmapTexture();
1070                 }
1071                 if(using_flags->get_max_button() > 0) {
1072                         extfunc->glEnable(GL_BLEND);
1073                         drawButtons();
1074                 }
1075                 drawScreenTexture();
1076                 extfunc->glDisable(GL_BLEND);
1077                 if(!using_flags->is_use_one_board_computer() && (using_flags->get_max_button() <= 0)) {
1078                         drawGrids();
1079                 }
1080                 drawOsdLeds();
1081                 extfunc->glFlush();
1082         } else {
1083                 extfunc->glViewport(0, 0, p_wid->width(), p_wid->height());
1084                 extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
1085                 drawOsdLeds();
1086                 extfunc->glFlush();
1087         }               
1088         //p_wid->doneCurrent();
1089 }
1090
1091 void GLDraw_3_0::setBrightness(GLfloat r, GLfloat g, GLfloat b)
1092 {
1093         fBrightR = r;
1094         fBrightG = g;
1095         fBrightB = b;
1096
1097         if(imgptr != NULL) {
1098                 p_wid->makeCurrent();
1099                 if(uVramTextureID != 0) {
1100                         uVramTextureID = p_wid->bindTexture(*imgptr);
1101                 }
1102                 if(using_flags->is_use_one_board_computer() || (using_flags->get_max_button() > 0)) {
1103                         uploadMainTexture(imgptr, true);
1104                 } else {
1105                         uploadMainTexture(imgptr, false);
1106                 }
1107                 crt_flag = true;
1108                 p_wid->doneCurrent();
1109         }
1110 }
1111
1112 void GLDraw_3_0::set_texture_vertex(float wmul, float hmul)
1113 {
1114         float wfactor = 1.0f;
1115         float hfactor = 1.0f;
1116
1117         vertexTmpTexture[0].x = -1.0f;
1118         vertexTmpTexture[0].y = -1.0f;
1119         vertexTmpTexture[0].z = -0.1f;
1120         vertexTmpTexture[0].s = 0.0f;
1121         vertexTmpTexture[0].t = 0.0f;
1122         
1123         vertexTmpTexture[1].x = wfactor;
1124         vertexTmpTexture[1].y = -1.0f;
1125         vertexTmpTexture[1].z = -0.1f;
1126         vertexTmpTexture[1].s = wmul;
1127         vertexTmpTexture[1].t = 0.0f;
1128         
1129         vertexTmpTexture[2].x = wfactor;
1130         vertexTmpTexture[2].y = hfactor;
1131         vertexTmpTexture[2].z = -0.1f;
1132         vertexTmpTexture[2].s = wmul;
1133         vertexTmpTexture[2].t = hmul;
1134         
1135         vertexTmpTexture[3].x = -1.0f;
1136         vertexTmpTexture[3].y = hfactor;
1137         vertexTmpTexture[3].z = -0.1f;
1138         vertexTmpTexture[3].s = 0.0f;
1139         vertexTmpTexture[3].t = hmul;
1140 }
1141
1142 void GLDraw_3_0::set_led_vertex(int xbit)
1143 {
1144         float xbase, ybase, zbase;
1145         VertexTexCoord_t vertex[4];
1146
1147         if((xbit < 0) || (xbit >=32)) return;
1148         xbase = 0.0f + (1.0f / 32.0f) * 31.0f - ((1.0f * (float)xbit) / 32.0f) + (1.0f / 128.0f);
1149         ybase = -1.0f + (2.0f / 64.0f) * 1.5f;
1150         zbase = -0.999f;
1151         vertex[0].x = xbase;
1152         vertex[0].y = ybase;
1153         vertex[0].z = zbase;
1154         vertex[0].s = 0.0f;
1155         vertex[0].t = 0.0f;
1156         
1157         vertex[1].x = xbase + (1.0f / 64.0f);
1158         vertex[1].y = ybase;
1159         vertex[1].z = zbase;
1160         vertex[1].s = 1.0f;
1161         vertex[1].t = 0.0f;
1162         
1163         vertex[2].x = xbase + (1.0f / 64.0f);
1164         vertex[2].y = ybase - (1.0f / 64.0f);
1165         vertex[2].z = zbase;
1166         vertex[2].s = 1.0f;
1167         vertex[2].t = 1.0f;
1168         
1169         vertex[3].x = xbase;
1170         vertex[3].y = ybase - (1.0f / 64.0f);
1171         vertex[3].z = zbase;
1172         vertex[3].s = 0.0f;
1173         vertex[3].t = 1.0f;
1174         
1175         setNormalVAO(led_pass[xbit]->getShader(), led_pass[xbit]->getVAO(),
1176                                  led_pass[xbit]->getVertexBuffer(),
1177                                  vertex, 4);
1178 }
1179
1180 void GLDraw_3_0::do_set_screen_multiply(float mul)
1181 {
1182         screen_multiply = mul;
1183         do_set_texture_size(imgptr, screen_texture_width, screen_texture_height);
1184 }
1185
1186 void GLDraw_3_0::do_set_texture_size(QImage *p, int w, int h)
1187 {
1188         if(w <= 0) w = using_flags->get_real_screen_width();
1189         if(h <= 0) h = using_flags->get_real_screen_height();
1190         imgptr = p;
1191         float iw, ih;
1192         if(p != NULL) {
1193                 iw = (float)p->width();
1194                 ih = (float)p->height();
1195         } else {
1196                 iw = (float)using_flags->get_real_screen_width();
1197                 ih = (float)using_flags->get_real_screen_height();
1198         }
1199         //printf("%dx%d -> %fx%f\n", w, h, iw, ih);
1200         if(p_wid != NULL) {
1201                 screen_texture_width = w;
1202                 screen_texture_height = h;
1203
1204                 p_wid->makeCurrent();
1205                 {
1206                         set_texture_vertex((float)w / iw, (float)h / ih);
1207                         setNormalVAO(std_pass->getShader(), std_pass->getVAO(),
1208                                                  std_pass->getVertexBuffer(),
1209                                                  vertexTmpTexture, 4);
1210                         //set_texture_vertex(p, p_wid->width(), p_wid->height(), w, h);
1211                         set_texture_vertex((float)w / iw, (float)h / ih);
1212                         setNormalVAO(ntsc_pass1->getShader(), ntsc_pass1->getVAO(),
1213                                                  ntsc_pass1->getVertexBuffer(),
1214                                                  vertexTmpTexture, 4);
1215
1216                         set_texture_vertex(1.0f, 1.0f);
1217                         setNormalVAO(ntsc_pass2->getShader(), ntsc_pass2->getVAO(),
1218                                                  ntsc_pass2->getVertexBuffer(),
1219                                                  vertexTmpTexture, 4);
1220                         
1221                 }
1222                 if(p != NULL) {
1223                         p_wid->deleteTexture(uVramTextureID);
1224                         uVramTextureID = p_wid->bindTexture(*p);
1225                 }
1226                 vertexFormat[0].x = -1.0f;
1227                 vertexFormat[0].y = -1.0f;
1228                 vertexFormat[0].z = -0.9f;
1229                 vertexFormat[1].x =  1.0f;
1230                 vertexFormat[1].y = -1.0f;
1231                 vertexFormat[1].z = -0.9f;
1232                 vertexFormat[2].x =  1.0f;
1233                 vertexFormat[2].y =  1.0f;
1234                 vertexFormat[2].z = -0.9f;
1235                 vertexFormat[3].x = -1.0f;
1236                 vertexFormat[3].y =  1.0f;
1237                 vertexFormat[3].z = -0.9f;
1238
1239                 vertexFormat[0].s = 0.0f;
1240                 //vertexFormat[0].t = (float)h / ih;
1241                 //vertexFormat[1].s = (float)w / iw;
1242                 //vertexFormat[1].t = (float)h / ih;
1243                 //vertexFormat[2].s = (float)w / iw;
1244                 vertexFormat[0].t = 1.0f;
1245                 vertexFormat[1].s = 1.0f;
1246                 vertexFormat[1].t = 1.0f;
1247                 vertexFormat[2].s = 1.0f;
1248                 vertexFormat[2].t = 0.0f;
1249                 vertexFormat[3].s = 0.0f;
1250                 vertexFormat[3].t = 0.0f;
1251                 
1252                 setNormalVAO(main_pass->getShader(), main_pass->getVAO(),
1253                                          main_pass->getVertexBuffer(),
1254                                          vertexFormat, 4);
1255                 
1256                 this->doSetGridsHorizonal(h, true);
1257                 this->doSetGridsVertical(w, true);
1258                 p_wid->doneCurrent();
1259         }
1260 }
1261
1262 void GLDraw_3_0::resizeGL_Screen(void)
1263 {
1264         if(main_pass != NULL) {
1265                 setNormalVAO(main_pass->getShader(), main_pass->getVAO(),
1266                                          main_pass->getVertexBuffer(),
1267                                          vertexFormat, 4);
1268         }
1269 }       
1270
1271 void GLDraw_3_0::resizeGL(int width, int height)
1272 {
1273         //int side = qMin(width, height);
1274         p_wid->makeCurrent();
1275         extfunc->glViewport(0, 0, width, height);
1276         extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
1277         crt_flag = true;
1278         if(!using_flags->is_use_one_board_computer() && (using_flags->get_max_button() <= 0)) {
1279                 doSetGridsHorizonal(vert_lines, true);
1280                 if(using_flags->is_use_vertical_pixel_lines()) {
1281                         doSetGridsVertical(horiz_pixels, true);
1282                 }
1283         }
1284         resizeGL_SetVertexs();
1285         resizeGL_Screen();
1286         if(using_flags->is_use_one_board_computer()) {
1287                 setNormalVAO(bitmap_block->getShader(), bitmap_block->getVAO(),
1288                                          bitmap_block->getVertexBuffer(),
1289                                          vertexBitmap, 4);
1290         }       
1291         if(using_flags->get_max_button() > 0) {
1292                 updateButtonTexture();
1293         }
1294         p_wid->doneCurrent();
1295 }