3 * (c) 2018 K.Ohta <whatisthis.sowhat@gmail.com>
5 * Renderer with OpenGL ES v2.0 (extend from renderer with OpenGL v2.0).
7 * May 05, 2018 : Copy from GL v3.0.
10 #include "osd_types.h"
11 #include "qt_gldraw.h"
12 #include "qt_glpack.h"
13 #include "qt_glutil_gles_2.h"
14 #include "csp_logger.h"
15 #include "menu_flags.h"
18 #include <QOpenGLFunctions>
19 #include <QOpenGLTexture>
21 #include <QImageReader>
23 #include <QOpenGLPixelTransferOptions>
24 #include <QOpenGLVertexArrayObject>
25 #include <QOpenGLShaderProgram>
26 #include <QOpenGLBuffer>
28 #include <QOpenGLContext>
29 #include <QOpenGLFramebufferObject>
30 #include <QOpenGLFramebufferObjectFormat>
31 #include <QOpenGLPixelTransferOptions>
41 //extern USING_FLAGS *using_flags;
43 GLDraw_ES_2::GLDraw_ES_2(GLDrawClass *parent, USING_FLAGS *p, CSP_Logger *logger, EMU *emu) : GLDraw_Tmpl(parent, p, logger, emu)
54 for(int i = 0; i < 32; i++) {
55 led_pass_vao[i] = NULL;
56 led_pass_vbuffer[i] = NULL;
57 osd_pass_vao[i] = NULL;
58 osd_pass_vbuffer[i] = NULL;
60 grids_horizonal_buffer = NULL;
61 grids_horizonal_vertex = NULL;
63 grids_vertical_buffer = NULL;
64 grids_vertical_vertex = NULL;
66 #if defined(__LITTLE_ENDIAN__)
67 swap_byteorder = true;
69 swap_byteorder = false;
72 TextureTransferParam = new QOpenGLPixelTransferOptions();
75 GLDraw_ES_2::~GLDraw_ES_2()
78 if(main_pass != NULL) delete main_pass;
79 if(std_pass != NULL) delete std_pass;
80 if(ntsc_pass1 != NULL) delete ntsc_pass1;
81 if(ntsc_pass2 != NULL) delete ntsc_pass2;
82 if(led_pass != NULL) delete led_pass;
83 for(int i = 0; i < 32; i++) {
84 if(led_pass_vao[i] != NULL) delete led_pass_vao[i];
85 if(led_pass_vbuffer[i] != NULL) delete led_pass_vbuffer[i];
86 if(osd_pass_vao[i] != NULL) delete osd_pass_vao[i];
87 if(osd_pass_vbuffer[i] != NULL) delete osd_pass_vbuffer[i];
90 if(grids_horizonal_buffer != NULL) {
91 if(grids_horizonal_buffer->isCreated()) grids_horizonal_buffer->destroy();
93 if(grids_horizonal_vertex != NULL) {
94 if(grids_horizonal_vertex->isCreated()) grids_horizonal_vertex->destroy();
96 if(grids_vertical_buffer != NULL) {
97 if(grids_vertical_buffer->isCreated()) grids_vertical_buffer->destroy();
99 if(grids_horizonal_vertex != NULL) {
100 if(grids_vertical_vertex->isCreated()) grids_vertical_vertex->destroy();
102 if(TextureTransferParam != NULL) delete TextureTransferParam;
105 QOpenGLTexture *GLDraw_ES_2::createMainTexture(QImage *img)
109 QImage nImg(using_flags->get_real_screen_width(), using_flags->get_real_screen_height(), QImage::Format_RGBA8888);
110 tx = new QOpenGLTexture(nImg, QOpenGLTexture::DontGenerateMipMaps);
111 TextureTransferParam->setImageHeight(using_flags->get_real_screen_height());
112 TextureTransferParam->setRowLength(using_flags->get_real_screen_width());
114 tx = new QOpenGLTexture(*img, QOpenGLTexture::DontGenerateMipMaps);
115 TextureTransferParam->setImageHeight(img->height());
116 TextureTransferParam->setRowLength(img->width());
118 tx->setFormat(QOpenGLTexture::RGBA8_UNorm);
119 tx->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Nearest);
120 tx->setWrapMode(QOpenGLTexture::ClampToEdge);
123 void GLDraw_ES_2::initBitmapVertex(void)
125 if(using_flags->is_use_one_board_computer()) {
126 vertexBitmap[0].x = -1.0f;
127 vertexBitmap[0].y = -1.0f;
128 vertexBitmap[0].z = 0.5f;
129 vertexBitmap[0].s = 0.0f;
130 vertexBitmap[0].t = 1.0f;
132 vertexBitmap[1].x = +1.0f;
133 vertexBitmap[1].y = -1.0f;
134 vertexBitmap[1].z = 0.5f;
135 vertexBitmap[1].s = 1.0f;
136 vertexBitmap[1].t = 1.0f;
138 vertexBitmap[2].x = +1.0f;
139 vertexBitmap[2].y = +1.0f;
140 vertexBitmap[2].z = 0.5f;
141 vertexBitmap[2].s = 1.0f;
142 vertexBitmap[2].t = 0.0f;
144 vertexBitmap[3].x = -1.0f;
145 vertexBitmap[3].y = +1.0f;
146 vertexBitmap[3].z = 0.5f;
147 vertexBitmap[3].s = 0.0f;
148 vertexBitmap[3].t = 0.0f;
153 void GLDraw_ES_2::initFBO(void)
155 glHorizGrids = (GLfloat *)malloc(sizeof(float) * (using_flags->get_real_screen_height() + 2) * 6);
157 if(glHorizGrids != NULL) {
158 doSetGridsHorizonal(using_flags->get_real_screen_height(), true);
160 glVertGrids = (GLfloat *)malloc(sizeof(float) * (using_flags->get_real_screen_width() + 2) * 6);
161 if(glVertGrids != NULL) {
162 doSetGridsVertical(using_flags->get_real_screen_width(), true);
164 if(using_flags->get_max_button() > 0) {
168 extfunc->glClearColor(0.0, 0.0, 0.0, 1.0);
171 void GLDraw_ES_2::setNormalVAO(QOpenGLShaderProgram *prg,
172 QOpenGLVertexArrayObject *vp,
174 VertexTexCoord_t *tp,
177 int vertex_loc = prg->attributeLocation("vertex");
178 int texcoord_loc = prg->attributeLocation("texcoord");
185 bp->write(0, tp, sizeof(VertexTexCoord_t) * size);
187 prg->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3, sizeof(VertexTexCoord_t));
188 prg->setAttributeBuffer(texcoord_loc, GL_FLOAT, 3 * sizeof(GLfloat), 2, sizeof(VertexTexCoord_t));
189 prg->setUniformValue("a_texture", 0);
191 extfunc->glVertexAttribPointer(vertex_loc, 3, GL_FLOAT, GL_FALSE, sizeof(VertexTexCoord_t), 0);
192 extfunc->glVertexAttribPointer(texcoord_loc, 2, GL_FLOAT, GL_FALSE, sizeof(VertexTexCoord_t),
193 (char *)NULL + 3 * sizeof(GLfloat));
196 prg->enableAttributeArray(vertex_loc);
197 prg->enableAttributeArray(texcoord_loc);
200 void GLDraw_ES_2::initGLObjects()
202 extfunc = new QOpenGLFunctions;
203 extfunc->initializeOpenGLFunctions();
204 extfunc->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texture_max_size);
207 void GLDraw_ES_2::initPackedGLObject(GLScreenPack **p,
208 int _width, int _height,
209 const QString vertex_shader, const QString fragment_shader,
210 const QString _name, bool req_float, bool req_highp)
215 pp = new GLScreenPack(_width, _height, _name, p_wid, req_float, req_highp);
218 pp->initialize(_width, _height, vertex_shader, fragment_shader);
219 s = pp->getShaderLog();
221 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GL_SHADER, "In shader of %s ", _name.toLocal8Bit().constData());
222 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GL_SHADER, "Vertex: %s ", vertex_shader.toLocal8Bit().constData());
223 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GL_SHADER, "Fragment: %s ", fragment_shader.toLocal8Bit().constData());
224 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GL_SHADER, "%s", s.toLocal8Bit().constData());
228 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GL_SHADER, "In shader of %s ", _name.toLocal8Bit().constData());
229 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GL_SHADER, "Vertex: %s ", vertex_shader.toLocal8Bit().constData());
230 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GL_SHADER, "Fragment: %s ", fragment_shader.toLocal8Bit().constData());
231 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GL_SHADER, "%s", s.toLocal8Bit().constData());
236 QOpenGLContext *context = QOpenGLContext::currentContext();
237 gl_major_version = context->format().version().first;
238 gl_minor_version = context->format().version().second;
244 bool GLDraw_ES_2::initGridShaders(const QString vertex_fixed, const QString vertex_rotate, const QString fragment)
247 grids_shader = new QOpenGLShaderProgram(p_wid);
248 if(grids_shader != NULL) {
249 f = grids_shader->addShaderFromSourceFile(QOpenGLShader::Vertex, vertex_rotate);
250 f &= grids_shader->addShaderFromSourceFile(QOpenGLShader::Fragment, fragment);
251 f &= grids_shader->link();
256 bool GLDraw_ES_2::initGridVertexObject(QOpenGLBuffer **vbo, QOpenGLVertexArrayObject **vao, int alloc_size)
258 QOpenGLBuffer *bp = NULL;
259 QOpenGLVertexArrayObject *ap = NULL;
262 *vbo = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
267 bp->allocate(alloc_size * sizeof(GLfloat) * 3 * 2);
277 *vao = new QOpenGLVertexArrayObject;
294 void GLDraw_ES_2::initLocalGLObjects(void)
297 int _width = using_flags->get_screen_width();
298 int _height = using_flags->get_screen_height();
300 if((_width * 4) <= texture_max_size) {
302 low_resolution_screen = true;
306 p_wid->makeCurrent();
308 vertexFormat[0].x = -1.0f;
309 vertexFormat[0].y = -1.0f;
310 vertexFormat[0].z = -0.9f;
311 vertexFormat[0].s = 0.0f;
312 vertexFormat[0].t = 1.0f;
314 vertexFormat[1].x = +1.0f;
315 vertexFormat[1].y = -1.0f;
316 vertexFormat[1].z = -0.9f;
317 vertexFormat[1].s = 1.0f;
318 vertexFormat[1].t = 1.0f;
320 vertexFormat[2].x = +1.0f;
321 vertexFormat[2].y = +1.0f;
322 vertexFormat[2].z = -0.9f;
323 vertexFormat[2].s = 1.0f;
324 vertexFormat[2].t = 0.0f;
326 vertexFormat[3].x = -1.0f;
327 vertexFormat[3].y = +1.0f;
328 vertexFormat[3].z = -0.9f;
329 vertexFormat[3].s = 0.0f;
330 vertexFormat[3].t = 0.0f;
332 if(using_flags->is_use_one_board_computer() || (using_flags->get_max_button() > 0)) {
333 initPackedGLObject(&main_pass,
334 using_flags->get_screen_width() * 2, using_flags->get_screen_height() * 2,
335 ":/gles2/vertex_shader.glsl" , ":/gles2/chromakey_fragment_shader2.glsl",
336 "Main Shader", false, false);
338 initPackedGLObject(&main_pass,
339 using_flags->get_screen_width() * 2, using_flags->get_screen_height() * 2,
340 ":/gles2/vertex_shader.glsl" , ":/gles2/fragment_shader.glsl",
341 "Main Shader", false, false);
343 if(main_pass != NULL) {
344 setNormalVAO(main_pass->getShader(), main_pass->getVAO(),
345 main_pass->getVertexBuffer(),
349 initPackedGLObject(&std_pass,
350 using_flags->get_screen_width(), using_flags->get_screen_height(),
351 ":/gles2/vertex_shader.glsl" , ":/gles2/chromakey_fragment_shader.glsl",
354 initPackedGLObject(&led_pass,
356 ":/gles2/led_vertex_shader.glsl" , ":/gles2/led_fragment_shader.glsl",
357 "LED Shader", false, false);
358 for(int i = 0; i < 32; i++) {
359 led_pass_vao[i] = new QOpenGLVertexArrayObject;
360 led_pass_vbuffer[i] = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
361 if(led_pass_vao[i]->create()) {
362 if(led_pass_vbuffer[i]->create()) {
363 led_pass_vbuffer[i]->setUsagePattern(QOpenGLBuffer::DynamicDraw);
364 led_pass_vao[i]->bind();
365 led_pass_vbuffer[i]->bind();
366 led_pass_vbuffer[i]->allocate(sizeof(VertexTexCoord_t) * 4);
367 led_pass_vbuffer[i]->release();
368 led_pass_vao[i]->release();
373 initPackedGLObject(&osd_pass,
375 ":/gles2/vertex_shader.glsl" , ":/gles2/icon_fragment_shader.glsl",
376 "OSD Shader", false, false);
377 for(int i = 0; i < 32; i++) {
378 osd_pass_vao[i] = new QOpenGLVertexArrayObject;
379 osd_pass_vbuffer[i] = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
380 if(osd_pass_vao[i]->create()) {
381 if(osd_pass_vbuffer[i]->create()) {
382 osd_pass_vbuffer[i]->setUsagePattern(QOpenGLBuffer::DynamicDraw);
383 osd_pass_vao[i]->bind();
384 osd_pass_vbuffer[i]->bind();
385 osd_pass_vbuffer[i]->allocate(sizeof(VertexTexCoord_t) * 4);
386 osd_pass_vbuffer[i]->release();
387 osd_pass_vao[i]->release();
394 initPackedGLObject(&ntsc_pass1,
396 ":/gles2/vertex_shader.glsl" , ":/gles2/ntsc_pass1.glsl",
397 "NTSC Shader Pass1", true, false);
398 initPackedGLObject(&ntsc_pass2,
400 ":/gles2/vertex_shader.glsl" , ":/gles2/ntsc_pass2.glsl",
401 "NTSC Shader Pass2", true, false);
402 if(!(((gl_major_version >= 3) && (gl_minor_version >= 1)) || (gl_major_version >= 4))){
404 QOpenGLShaderProgram *shader = ntsc_pass2->getShader();
406 ii = shader->uniformLocation("luma_filter");
408 shader->setUniformValueArray(ii, luma_filter, 24 + 1, 1);
410 ii = shader->uniformLocation("chroma_filter");
412 shader->setUniformValueArray(ii, chroma_filter, 24 + 1, 1);
418 if(using_flags->is_use_one_board_computer()) {
420 initPackedGLObject(&bitmap_block,
421 _width * 2, _height * 2,
422 ":/gles2/vertex_shader.glsl", ":/gles2/normal_fragment_shader.glsl",
423 "Background Bitmap Shader", false, false);
424 if(bitmap_block != NULL) {
425 setNormalVAO(bitmap_block->getShader(), bitmap_block->getVAO(),
426 bitmap_block->getVertexBuffer(),
431 initGridShaders(":/gles2/grids_vertex_shader_fixed.glsl", ":/gles2/grids_vertex_shader.glsl", ":/gles2/grids_fragment_shader.glsl");
433 initGridVertexObject(&grids_horizonal_buffer, &grids_horizonal_vertex, using_flags->get_real_screen_height() + 3);
434 doSetGridsHorizonal(using_flags->get_real_screen_height(), true);
436 initGridVertexObject(&grids_vertical_buffer, &grids_vertical_vertex, using_flags->get_real_screen_width() + 3);
437 doSetGridsVertical(using_flags->get_real_screen_width(), true);
439 do_set_texture_size(NULL, -1, -1);
440 p_wid->doneCurrent();
443 void GLDraw_ES_2::updateGridsVAO(QOpenGLBuffer *bp,
444 QOpenGLVertexArrayObject *vp,
450 if((bp != NULL) && (vp != NULL)) {
451 if(bp->isCreated()) {
452 if(bp->size() < (int)((number + 1) * sizeof(GLfloat) * 3 * 2)) {
464 bp->allocate((number + 1) * sizeof(GLfloat) * 3 * 2);
467 bp->write(0, tp, number * sizeof(GLfloat) * 3 * 2);
473 void GLDraw_ES_2::drawGridsMain(QOpenGLShaderProgram *prg,
475 QOpenGLVertexArrayObject *vp,
480 if(number <= 0) return;
481 extfunc->glDisable(GL_DEPTH_TEST);
482 extfunc->glDisable(GL_BLEND);
484 if((bp == NULL) || (vp == NULL) || (prg == NULL)) return;
485 if((!bp->isCreated()) || (!vp->isCreated()) || (!prg->isLinked())) return;
491 switch(p_config->rotate_type) {
493 rot = QMatrix2x2(rot0);
496 rot = QMatrix2x2(rot90);
499 rot = QMatrix2x2(rot180);
502 rot = QMatrix2x2(rot270);
505 rot = QMatrix2x2(rot0);
508 prg->setUniformValue("rotate_mat", rot);
509 prg->setUniformValue("color", color);
510 prg->enableAttributeArray("vertex");
511 int vertex_loc = prg->attributeLocation("vertex");
513 extfunc->glViewport(0, 0, p_wid->width(), p_wid->height());
514 extfunc->glVertexAttribPointer(vertex_loc, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 3, 0);
515 extfunc->glEnableVertexAttribArray(vertex_loc);
517 extfunc->glLineWidth(lineWidth);
518 extfunc->glDrawArrays(GL_LINES, 0, (number + 1) * 2);
525 void GLDraw_ES_2::doSetGridsVertical(int pixels, bool force)
527 GLDraw_Tmpl::doSetGridsVertical(pixels, force);
528 updateGridsVAO(grids_vertical_buffer,
529 grids_vertical_vertex,
534 void GLDraw_ES_2::doSetGridsHorizonal(int lines, bool force)
536 if((lines == vert_lines) && !force) return;
537 GLDraw_Tmpl::doSetGridsHorizonal(lines, force);
539 updateGridsVAO(grids_horizonal_buffer,
540 grids_horizonal_vertex,
545 void GLDraw_ES_2::drawGridsHorizonal(void)
547 QVector4D c= QVector4D(0.0f, 0.0f, 0.0f, 1.0f);
548 drawGridsMain(grids_shader,
549 grids_horizonal_buffer,
550 grids_horizonal_vertex,
556 void GLDraw_ES_2::drawGridsVertical(void)
558 QVector4D c= QVector4D(0.0f, 0.0f, 0.0f, 1.0f);
559 drawGridsMain(grids_shader,
560 grids_vertical_buffer,
561 grids_vertical_vertex,
567 void GLDraw_ES_2::drawGrids(void)
569 gl_grid_horiz = p_config->opengl_scanline_horiz;
570 gl_grid_vert = p_config->opengl_scanline_vert;
571 if(gl_grid_horiz && (vert_lines > 0)) {
572 drawGridsHorizonal();
574 if(using_flags->is_use_vertical_pixel_lines()) {
575 if(gl_grid_vert && (horiz_pixels > 0)) {
581 void GLDraw_ES_2::renderToTmpFrameBuffer_nPass(GLuint src_texture,
584 GLScreenPack *renderObject,
590 QOpenGLShaderProgram *shader = renderObject->getShader();
594 extfunc->glClearColor(0.0, 0.0, 0.0, 1.0);
595 extfunc->glClearDepthf(1.0f);
596 extfunc->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
598 if((src_texture != 0) && (shader != NULL)) {
600 //ortho.ortho(0.0f, (float)dst_w, 0.0f, (float)dst_h, -1.0, 1.0);
601 ortho.ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
604 renderObject->bind();
605 extfunc->glViewport(0, 0, dst_w, dst_h);
606 //extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
607 extfunc->glActiveTexture(GL_TEXTURE0);
608 extfunc->glBindTexture(GL_TEXTURE_2D, src_texture);
609 extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
610 extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
611 //extfunc->glColor4f(1.0, 1.0, 1.0, 1.0);
612 shader->setUniformValue("a_texture", 0);
613 shader->setUniformValue("v_ortho", ortho);
614 //shader->setUniformValue("a_texture", src_texture);
616 ii = shader->uniformLocation("source_size");
618 QVector4D source_size = QVector4D((float)src_w, (float)src_h, 0, 0);
619 shader->setUniformValue(ii, source_size);
621 ii = shader->uniformLocation("target_size");
623 QVector4D target_size = QVector4D((float)dst_w, (float)dst_h, 0, 0);
624 shader->setUniformValue(ii, target_size);
626 ii = shader->uniformLocation("phase");
628 ringing_phase = ringing_phase + 0.093;
629 if(ringing_phase > 1.0) ringing_phase = ringing_phase - 1.0;
630 shader->setUniformValue(ii, ringing_phase);
634 * Note : Not rotate within renderer.
637 switch(p_config->rotate_type) {
639 rot = QMatrix2x2(rot0);
642 rot = QMatrix2x2(rot90);
645 rot = QMatrix2x2(rot180);
648 rot = QMatrix2x2(rot270);
651 rot = QMatrix2x2(rot0);
655 rot = QMatrix2x2(rot0);
656 shader->setUniformValue("rotate_mat", rot);
657 //if(!(((gl_major_version >= 3) && (gl_minor_version >= 1)) || (gl_major_version >= 4))){
658 //ii = shader->uniformLocation("luma_filter");
660 // shader->setUniformValueArray(ii, luma_filter, 24 + 1, 1);
662 //ii = shader->uniformLocation("chroma_filter");
664 // shader->setUniformValueArray(ii, chroma_filter, 24 + 1, 1);
669 QVector4D c(fBrightR, fBrightG, fBrightB, 1.0);
670 QVector3D chromakey(0.0, 0.0, 0.0);
672 ii = shader->uniformLocation("color");
674 shader->setUniformValue(ii, c);
676 ii = shader->uniformLocation("do_chromakey");
680 ij = shader->uniformLocation("chromakey");
682 shader->setUniformValue(ij, chromakey);
684 shader->setUniformValue(ii, GL_TRUE);
686 shader->setUniformValue(ii, GL_FALSE);
691 shader->enableAttributeArray("texcoord");
692 shader->enableAttributeArray("vertex");
694 int vertex_loc = shader->attributeLocation("vertex");
695 int texcoord_loc = shader->attributeLocation("texcoord");
696 shader->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3, sizeof(VertexTexCoord_t));
697 shader->setAttributeBuffer(texcoord_loc, GL_FLOAT, 3 * sizeof(GLfloat), 2, sizeof(VertexTexCoord_t));
698 extfunc->glEnableVertexAttribArray(vertex_loc);
699 extfunc->glEnableVertexAttribArray(texcoord_loc);
701 extfunc->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
703 //extfunc->glViewport(0, 0, dst_w, dst_h);
704 //extfunc->glOrtho(0.0f, (float)dst_w, 0.0f, (float)dst_h, -1.0, 1.0);
705 renderObject->release();
706 extfunc->glBindTexture(GL_TEXTURE_2D, 0);
713 void GLDraw_ES_2::uploadMainTexture(QImage *p, bool use_chromakey, bool was_mapped)
716 redraw_required = true;
717 if(p == NULL) return;
718 //redraw_required = true;
720 if(uVramTextureID == NULL) {
721 uVramTextureID = createMainTexture(p);
723 // Upload to main texture
724 TextureTransferParam->setImageHeight(p->height());
725 TextureTransferParam->setRowLength(p->width());
726 uVramTextureID->setData(QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, p->constBits(), TextureTransferParam);
729 if(using_flags->is_support_tv_render() && (p_config->rendering_type == CONFIG_RENDER_TYPE_TV)) {
730 renderToTmpFrameBuffer_nPass(uVramTextureID->textureId(),
731 screen_texture_width,
732 screen_texture_height,
734 ntsc_pass1->getViewportWidth(),
735 ntsc_pass1->getViewportHeight());
737 renderToTmpFrameBuffer_nPass(ntsc_pass1->getTexture(),
738 ntsc_pass1->getViewportWidth(),
739 ntsc_pass1->getViewportHeight(),
741 ntsc_pass2->getViewportWidth(),
742 ntsc_pass2->getViewportHeight());
743 uTmpTextureID = ntsc_pass2->getTexture();
747 uTmpTextureID = uVramTextureID->textureId();
752 void GLDraw_ES_2::drawScreenTexture(void)
754 if(using_flags->is_use_one_board_computer()) {
755 extfunc->glEnable(GL_BLEND);
756 extfunc->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
758 extfunc->glDisable(GL_BLEND);
762 smoosing = p_config->use_opengl_filters;
764 color = QVector4D(fBrightR, fBrightG, fBrightB, 1.0);
766 color = QVector4D(1.0, 1.0, 1.0, 1.0);
768 if(using_flags->is_use_one_board_computer()) {
770 uTmpTextureID, // v2.0
772 true, QVector3D(0.0, 0.0, 0.0));
773 extfunc->glDisable(GL_BLEND);
776 uTmpTextureID, // v2.0
781 void GLDraw_ES_2::drawMain(QOpenGLShaderProgram *prg,
782 QOpenGLVertexArrayObject *vp,
796 extfunc->glViewport(0, 0, p_wid->width(), p_wid->height());
798 ortho.ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
800 extfunc->glActiveTexture(GL_TEXTURE0);
801 extfunc->glBindTexture(GL_TEXTURE_2D, texid);
803 extfunc->glClearColor(1.0, 1.0, 1.0, 1.0);
805 extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
806 extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
808 extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
809 extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
811 prg->setUniformValue("a_texture", 0);
812 prg->setUniformValue("v_ortho", ortho);
814 ii = prg->uniformLocation("color");
816 prg->setUniformValue(ii, color);
819 ii = prg->uniformLocation("tex_width");
821 prg->setUniformValue(ii, (float)screen_texture_width);
824 ii = prg->uniformLocation("tex_height");
826 prg->setUniformValue(ii, (float)screen_texture_height);
829 switch(p_config->rotate_type) {
831 rot = QMatrix2x2(rot0);
834 rot = QMatrix2x2(rot90);
837 rot = QMatrix2x2(rot180);
840 rot = QMatrix2x2(rot270);
843 rot = QMatrix2x2(rot0);
846 prg->setUniformValue("rotate_mat", rot);
848 //prg->setUniformValue("rotate", GL_FALSE);
852 ii = prg->uniformLocation("chromakey");
854 prg->setUniformValue(ii, chromakey);
856 ii = prg->uniformLocation("do_chromakey");
858 prg->setUniformValue(ii, GL_TRUE);
861 ii = prg->uniformLocation("do_chromakey");
863 prg->setUniformValue(ii, GL_FALSE);
867 prg->enableAttributeArray("texcoord");
868 prg->enableAttributeArray("vertex");
869 int vertex_loc = prg->attributeLocation("vertex");
870 int texcoord_loc = prg->attributeLocation("texcoord");
872 //prg->enableAttributeArray(vertex_loc);
873 prg->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3, sizeof(VertexTexCoord_t));
874 prg->setAttributeBuffer(texcoord_loc, GL_FLOAT, 3 * sizeof(GLfloat), 2, sizeof(VertexTexCoord_t));
875 extfunc->glEnableVertexAttribArray(vertex_loc);
876 extfunc->glEnableVertexAttribArray(texcoord_loc);
878 extfunc->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
883 extfunc->glBindTexture(GL_TEXTURE_2D, 0);
889 extfunc->glViewport(0, 0, p_wid->width(), p_wid->height());
891 ortho.ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
892 //extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
893 ii = prg->uniformLocation("color");
895 prg->setUniformValue(ii, color);
898 switch(p_config->rotate_type) {
900 rot = QMatrix2x2(rot0);
903 rot = QMatrix2x2(rot90);
906 rot = QMatrix2x2(rot180);
909 rot = QMatrix2x2(rot270);
912 rot = QMatrix2x2(rot0);
915 prg->setUniformValue("rotate_mat", rot);
916 prg->setUniformValue("v_ortho", ortho);
919 ii = prg->uniformLocation("chromakey");
921 prg->setUniformValue(ii, chromakey);
923 ii = prg->uniformLocation("do_chromakey");
925 prg->setUniformValue(ii, GL_TRUE);
928 ii = prg->uniformLocation("do_chromakey");
930 prg->setUniformValue(ii, GL_FALSE);
934 prg->enableAttributeArray("vertex");
935 int vertex_loc = prg->attributeLocation("vertex");
936 extfunc->glEnableVertexAttribArray(vertex_loc);
937 extfunc->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
941 extfunc->glBindTexture(GL_TEXTURE_2D, 0);
945 void GLDraw_ES_2::drawMain(GLScreenPack *obj,
953 QOpenGLShaderProgram *prg = obj->getShader();
954 QOpenGLVertexArrayObject *vp = obj->getVAO();
955 QOpenGLBuffer *bp = obj->getVertexBuffer();
957 drawMain(prg, vp, bp, texid, color, f_smoosing, do_chromakey, chromakey);
960 void GLDraw_ES_2::drawButtonsMain(int num, bool f_smoosing)
962 GLuint texid = uButtonTextureID[num]->textureId();
963 QOpenGLBuffer *bp = buffer_button_vertex[num];
964 QOpenGLShaderProgram *prg = button_shader;
965 QOpenGLVertexArrayObject *vp = vertex_button[num];
969 color = QVector4D(1.0, 1.0, 1.0, 1.0);
970 if((bp != NULL) && (vp != NULL) && (prg != NULL)) {
971 if((bp->isCreated()) && (vp->isCreated()) && (prg->isLinked())) {
976 ortho.ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
977 extfunc->glViewport(0, 0, p_wid->width(), p_wid->height());
979 extfunc->glActiveTexture(GL_TEXTURE0);
980 extfunc->glBindTexture(GL_TEXTURE_2D, texid);
982 extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
983 extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
985 extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
986 extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
988 prg->setUniformValue("a_texture", 0);
989 prg->setUniformValue("v_ortho", ortho);
991 ii = prg->uniformLocation("color");
993 prg->setUniformValue(ii, color);
995 ii = prg->uniformLocation("do_chromakey");
997 prg->setUniformValue(ii, GL_FALSE);
1000 switch(p_config->rotate_type) {
1002 rot = QMatrix2x2(rot0);
1005 rot = QMatrix2x2(rot90);
1008 rot = QMatrix2x2(rot180);
1011 rot = QMatrix2x2(rot270);
1014 rot = QMatrix2x2(rot0);
1017 prg->setUniformValue("rotate_mat", rot);
1019 int vertex_loc = prg->attributeLocation("vertex");
1020 int texcoord_loc = prg->attributeLocation("texcoord");
1021 prg->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3, sizeof(VertexTexCoord_t));
1022 prg->setAttributeBuffer(texcoord_loc, GL_FLOAT, 3 * sizeof(GLfloat), 2, sizeof(VertexTexCoord_t));
1023 prg->enableAttributeArray(vertex_loc);
1024 prg->enableAttributeArray(texcoord_loc);
1025 //extfunc->glEnableVertexAttribArray(vertex_loc);
1026 //extfunc->glEnableVertexAttribArray(texcoord_loc);
1027 extfunc->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1031 extfunc->glBindTexture(GL_TEXTURE_2D, 0);
1038 void GLDraw_ES_2::drawButtons(void)
1040 for(int i = 0; i < using_flags->get_max_button(); i++) {
1041 drawButtonsMain(i, false);
1045 void GLDraw_ES_2::drawBitmapTexture(void)
1047 QVector4D color = QVector4D(1.0f, 1.0f, 1.0f, 1.0f);
1048 smoosing = p_config->use_opengl_filters;
1050 if(using_flags->is_use_one_board_computer() && (uBitmapTextureID != NULL)) {
1051 //extfunc->glDisable(GL_BLEND);
1052 drawMain(bitmap_block,
1053 uBitmapTextureID->textureId(),
1058 void GLDraw_ES_2::drawLedMain(GLScreenPack *obj, int num, QVector4D color)
1060 QOpenGLShaderProgram *prg = obj->getShader();
1061 QOpenGLVertexArrayObject *vp = led_pass_vao[num];
1062 QOpenGLBuffer *bp = led_pass_vbuffer[num];
1066 extfunc->glEnable(GL_BLEND);
1067 extfunc->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1071 extfunc->glViewport(0, 0, p_wid->width(), p_wid->height());
1072 //extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
1073 ii = prg->uniformLocation("color");
1075 prg->setUniformValue(ii, color);
1078 prg->enableAttributeArray("vertex");
1079 int vertex_loc = prg->attributeLocation("vertex");
1080 prg->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3, sizeof(VertexTexCoord_t));
1081 extfunc->glVertexAttribPointer(vertex_loc, 3, GL_FLOAT, GL_FALSE, sizeof(VertexTexCoord_t), 0);
1083 extfunc->glEnableVertexAttribArray(vertex_loc);
1084 extfunc->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1089 extfunc->glDisable(GL_BLEND);
1095 void GLDraw_ES_2::drawOsdLeds()
1098 QVector4D color_off;
1099 uint32_t bit = 0x00000001;
1101 color_on = QVector4D(0.95, 0.0, 0.05, 1.0);
1102 color_off = QVector4D(0.05,0.05, 0.05, 0.10);
1104 color_on = QVector4D(0.00,0.00, 0.00, 0.0);
1105 color_off = QVector4D(0.00,0.00, 0.00, 0.0);
1108 //if(osd_led_status_bak != osd_led_status) {
1109 for(int i = 0; i < osd_led_bit_width; i++) {
1110 if((bit & osd_led_status) == (bit & osd_led_status_bak)) {
1114 drawLedMain(led_pass, i,
1115 ((osd_led_status & bit) != 0) ? color_on : color_off);
1118 osd_led_status_bak = osd_led_status;
1123 void GLDraw_ES_2::drawOsdIcons()
1126 QVector4D color_off;
1127 uint32_t bit = 0x00000001;
1129 color_on = QVector4D(1.0, 1.0, 1.0, 0.8);
1130 color_off = QVector4D(1.0, 1.0, 1.0, 0.00);
1132 color_on = QVector4D(0.00,0.00, 0.00, 0.0);
1133 color_off = QVector4D(0.00,0.00, 0.00, 0.0);
1137 //if(osd_led_status_bak != osd_led_status) {
1138 for(int i = 0; i < osd_led_bit_width; i++) {
1139 if((bit & osd_led_status) == (bit & osd_led_status_bak)) {
1140 if((bit & osd_led_status) == 0) {
1145 if((i >= 2) && (i < 10)) { // FD
1148 } else if((i >= 10) && (i < 12)) { // QD
1151 } else if((i >= 12) && (i < 14)) { // CMT(R)
1154 } else if((i >= 14) && (i < 16)) { // CMT(W)
1162 drawMain(osd_pass->getShader(), osd_pass_vao[i], osd_pass_vbuffer[i],
1163 icon_texid[major][minor]->textureId(),
1164 ((osd_led_status & bit) != 0) ? color_on : color_off,
1165 false, false, QVector3D(0.0, 0.0, 0.0));
1169 osd_led_status_bak = osd_led_status;
1174 void GLDraw_ES_2::paintGL(void)
1176 //p_wid->makeCurrent();
1178 // if(crt_flag || redraw_required) { //return;
1182 redraw_required = false;
1183 extfunc->glViewport(0, 0, p_wid->width(), p_wid->height());
1184 //extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
1186 extfunc->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1187 extfunc->glDisable(GL_DEPTH_TEST);
1188 extfunc->glDisable(GL_BLEND);
1189 if(using_flags->is_use_one_board_computer() || using_flags->is_use_bitmap()) {
1190 extfunc->glEnable(GL_BLEND);
1191 drawBitmapTexture();
1193 if(using_flags->get_max_button() > 0) {
1194 extfunc->glEnable(GL_BLEND);
1197 drawScreenTexture();
1198 extfunc->glEnable(GL_BLEND);
1199 extfunc->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1200 extfunc->glDisable(GL_DEPTH_TEST);
1202 if(p_config->use_osd_virtual_media) drawOsdIcons();
1203 extfunc->glDisable(GL_BLEND);
1204 if(!using_flags->is_use_one_board_computer() && (using_flags->get_max_button() <= 0)) {
1209 // extfunc->glViewport(0, 0, p_wid->width(), p_wid->height());
1210 /// extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
1212 // extfunc->glClear(GL_DEPTH_BUFFER_BIT);
1213 // extfunc->glEnable(GL_DEPTH_TEST);
1214 // extfunc->glEnable(GL_BLEND);
1217 // extfunc->glFlush();
1219 //p_wid->doneCurrent();
1222 void GLDraw_ES_2::setBrightness(GLfloat r, GLfloat g, GLfloat b)
1228 if(imgptr != NULL) {
1229 p_wid->makeCurrent();
1230 if(uVramTextureID == NULL) {
1231 uVramTextureID = createMainTexture(imgptr);
1233 //if(using_flags->is_use_one_board_computer() || (using_flags->get_max_button() > 0)) {
1234 // uploadMainTexture(imgptr, true);
1236 // uploadMainTexture(imgptr, false);
1239 p_wid->doneCurrent();
1243 void GLDraw_ES_2::set_texture_vertex(float wmul, float hmul)
1245 float wfactor = 1.0f;
1246 float hfactor = 1.0f;
1248 vertexTmpTexture[0].x = -1.0f;
1249 vertexTmpTexture[0].y = -1.0f;
1250 vertexTmpTexture[0].z = -0.1f;
1251 vertexTmpTexture[0].s = 0.0f;
1252 vertexTmpTexture[0].t = 0.0f;
1254 vertexTmpTexture[1].x = wfactor;
1255 vertexTmpTexture[1].y = -1.0f;
1256 vertexTmpTexture[1].z = -0.1f;
1257 vertexTmpTexture[1].s = wmul;
1258 vertexTmpTexture[1].t = 0.0f;
1260 vertexTmpTexture[2].x = wfactor;
1261 vertexTmpTexture[2].y = hfactor;
1262 vertexTmpTexture[2].z = -0.1f;
1263 vertexTmpTexture[2].s = wmul;
1264 vertexTmpTexture[2].t = hmul;
1266 vertexTmpTexture[3].x = -1.0f;
1267 vertexTmpTexture[3].y = hfactor;
1268 vertexTmpTexture[3].z = -0.1f;
1269 vertexTmpTexture[3].s = 0.0f;
1270 vertexTmpTexture[3].t = hmul;
1274 void GLDraw_ES_2::set_osd_vertex(int xbit)
1276 float xbase, ybase, zbase;
1277 VertexTexCoord_t vertex[4];
1278 int major, minor, nl;
1280 if((xbit < 0) || (xbit >= 32)) return;
1281 if((i >= 2) && (i < 10)) { // FD
1284 nl = using_flags->get_max_drive();
1285 } else if((i >= 10) && (i < 12)) { // QD
1288 nl = using_flags->get_max_qd();
1289 } else if((i >= 12) && (i < 14)) { // CMT(R)
1292 nl = using_flags->get_max_tape();
1293 } else if((i >= 14) && (i < 16)) { // CMT(W)
1296 nl = using_flags->get_max_tape();
1297 } else if(i >= 16) {
1298 major = 4 + (i / 8) - 2;
1306 xbase = 1.0f - (1.0f * 48.0f / 640.0f) * (float)(nl - minor) - (4.0f / 640.0f);;
1307 ybase = -1.0f + (1.0f * 48.0f / 400.0f) * (float)(major + 1) + (4.0f / 400.0f);
1309 vertex[0].x = xbase;
1310 vertex[0].y = ybase;
1311 vertex[0].z = zbase;
1315 vertex[1].x = xbase + (48.0f / 640.0f);
1316 vertex[1].y = ybase;
1317 vertex[1].z = zbase;
1321 vertex[2].x = xbase + (48.0f / 640.0f);
1322 vertex[2].y = ybase - (48.0f / 400.0f);
1323 vertex[2].z = zbase;
1327 vertex[3].x = xbase;
1328 vertex[3].y = ybase - (48.0f / 400.0f);
1329 vertex[3].z = zbase;
1333 setNormalVAO(osd_pass->getShader(), osd_pass_vao[xbit],
1334 osd_pass_vbuffer[xbit],
1338 void GLDraw_ES_2::set_led_vertex(int xbit)
1340 float xbase, ybase, zbase;
1341 VertexTexCoord_t vertex[4];
1343 if((xbit < 0) || (xbit >=32)) return;
1344 xbase = 0.0f + (1.0f / 32.0f) * 31.0f - ((1.0f * (float)xbit) / 32.0f) + (1.0f / 128.0f);
1345 ybase = -1.0f + (2.0f / 64.0f) * 1.5f;
1347 vertex[0].x = xbase;
1348 vertex[0].y = ybase;
1349 vertex[0].z = zbase;
1353 vertex[1].x = xbase + (1.0f / 64.0f);
1354 vertex[1].y = ybase;
1355 vertex[1].z = zbase;
1359 vertex[2].x = xbase + (1.0f / 64.0f);
1360 vertex[2].y = ybase - (1.0f / 64.0f);
1361 vertex[2].z = zbase;
1365 vertex[3].x = xbase;
1366 vertex[3].y = ybase - (1.0f / 64.0f);
1367 vertex[3].z = zbase;
1371 setNormalVAO(led_pass->getShader(), led_pass_vao[xbit],
1372 led_pass_vbuffer[xbit],
1376 void GLDraw_ES_2::do_set_screen_multiply(float mul)
1378 screen_multiply = mul;
1379 do_set_texture_size(imgptr, screen_texture_width, screen_texture_height);
1382 void GLDraw_ES_2::do_set_texture_size(QImage *p, int w, int h)
1384 if(w <= 0) w = using_flags->get_real_screen_width();
1385 if(h <= 0) h = using_flags->get_real_screen_height();
1389 iw = (float)p->width();
1390 ih = (float)p->height();
1392 iw = (float)using_flags->get_real_screen_width();
1393 ih = (float)using_flags->get_real_screen_height();
1395 //printf("%dx%d -> %fx%f\n", w, h, iw, ih);
1397 screen_texture_width = w;
1398 screen_texture_height = h;
1400 p_wid->makeCurrent();
1402 //set_texture_vertex(p, p_wid->width(), p_wid->height(), w, h);
1403 set_texture_vertex((float)w / iw, (float)h / ih);
1404 setNormalVAO(ntsc_pass1->getShader(), ntsc_pass1->getVAO(),
1405 ntsc_pass1->getVertexBuffer(),
1406 vertexTmpTexture, 4);
1408 set_texture_vertex(1.0f, 1.0f);
1409 setNormalVAO(ntsc_pass2->getShader(), ntsc_pass2->getVAO(),
1410 ntsc_pass2->getVertexBuffer(),
1411 vertexTmpTexture, 4);
1415 if(uVramTextureID != NULL) {
1416 if(((int)iw != uVramTextureID->width()) || ((int)ih != uVramTextureID->height())) {
1417 p_wid->makeCurrent();
1418 uVramTextureID->destroy();
1419 delete uVramTextureID;
1420 uVramTextureID = createMainTexture(p);
1421 p_wid->doneCurrent();
1424 p_wid->makeCurrent();
1425 uVramTextureID = createMainTexture(p);
1426 p_wid->doneCurrent();
1429 vertexFormat[0].x = -1.0f;
1430 vertexFormat[0].y = -1.0f;
1431 vertexFormat[0].z = -0.9f;
1432 vertexFormat[1].x = 1.0f;
1433 vertexFormat[1].y = -1.0f;
1434 vertexFormat[1].z = -0.9f;
1435 vertexFormat[2].x = 1.0f;
1436 vertexFormat[2].y = 1.0f;
1437 vertexFormat[2].z = -0.9f;
1438 vertexFormat[3].x = -1.0f;
1439 vertexFormat[3].y = 1.0f;
1440 vertexFormat[3].z = -0.9f;
1442 vertexFormat[0].s = 0.0f;
1443 //vertexFormat[0].t = (float)h / ih;
1444 //vertexFormat[1].s = (float)w / iw;
1445 //vertexFormat[1].t = (float)h / ih;
1446 //vertexFormat[2].s = (float)w / iw;
1447 vertexFormat[0].t = 1.0f;
1448 vertexFormat[1].s = 1.0f;
1449 vertexFormat[1].t = 1.0f;
1450 vertexFormat[2].s = 1.0f;
1451 vertexFormat[2].t = 0.0f;
1452 vertexFormat[3].s = 0.0f;
1453 vertexFormat[3].t = 0.0f;
1455 setNormalVAO(main_pass->getShader(), main_pass->getVAO(),
1456 main_pass->getVertexBuffer(),
1459 if(w > using_flags->get_real_screen_width()) {
1460 w = using_flags->get_real_screen_width();
1462 if(h > using_flags->get_real_screen_height()) {
1463 h = using_flags->get_real_screen_height();
1465 this->doSetGridsHorizonal(h, false);
1466 this->doSetGridsVertical(w, false);
1467 p_wid->doneCurrent();
1470 void GLDraw_ES_2::do_set_horiz_lines(int lines)
1472 if(lines > using_flags->get_real_screen_height()) {
1473 lines = using_flags->get_real_screen_height();
1475 this->doSetGridsHorizonal(lines, false);
1478 void GLDraw_ES_2::resizeGL_Screen(void)
1480 if(main_pass != NULL) {
1481 setNormalVAO(main_pass->getShader(), main_pass->getVAO(),
1482 main_pass->getVertexBuffer(),
1487 void GLDraw_ES_2::resizeGL(int width, int height)
1489 //int side = qMin(width, height);
1490 p_wid->makeCurrent();
1491 extfunc->glViewport(0, 0, width, height);
1492 //extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
1494 if(!using_flags->is_use_one_board_computer() && (using_flags->get_max_button() <= 0)) {
1495 doSetGridsHorizonal(vert_lines, true);
1496 if(using_flags->is_use_vertical_pixel_lines()) {
1497 doSetGridsVertical(horiz_pixels, true);
1500 resizeGL_SetVertexs();
1502 if(using_flags->is_use_one_board_computer()) {
1503 setNormalVAO(bitmap_block->getShader(), bitmap_block->getVAO(),
1504 bitmap_block->getVertexBuffer(),
1507 if(using_flags->get_max_button() > 0) {
1508 updateButtonTexture();
1510 p_wid->doneCurrent();
1513 void GLDraw_ES_2::initButtons(void)
1515 button_desc_t *vm_buttons_d = using_flags->get_vm_buttons();
1516 QOpenGLContext *context = QOpenGLContext::currentContext();
1517 QPair<int, int> _version = QOpenGLVersionProfile(context->format()).version();
1518 QString versionext = QString::fromUtf8("");
1519 if(((_version.first == 3) && (_version.second >= 1)) || (_version.first >= 4)){
1520 versionext = QString::fromUtf8("#version 310 es \n");
1521 } /* else if((_version.first == 3)) {
1522 _ext = _ext + QString::fromUtf8("#version 300 es \n");
1524 versionext = QString::fromUtf8("#version 100 \n");
1527 if(vm_buttons_d != NULL) {
1528 button_shader = new QOpenGLShaderProgram(p_wid);
1529 if(button_shader != NULL) {
1531 QFile vertex_src(QString::fromUtf8(":/gles2/vertex_shader.glsl"));
1532 if (vertex_src.open(QIODevice::ReadOnly | QIODevice::Text)) {
1533 QString srcs = versionext;
1534 srcs = srcs + QString::fromUtf8(vertex_src.readAll());
1535 f = button_shader->addShaderFromSourceCode(QOpenGLShader::Vertex, srcs);
1540 QFile fragment_src(QString::fromUtf8(":/gles2/normal_fragment_shader.glsl"));
1541 if (fragment_src.open(QIODevice::ReadOnly | QIODevice::Text)) {
1542 QString srcs = versionext;
1543 srcs = srcs + QString::fromUtf8(fragment_src.readAll());
1544 f &= button_shader->addShaderFromSourceCode(QOpenGLShader::Fragment, srcs);
1545 fragment_src.close();
1550 button_shader->link();
1553 int ip = using_flags->get_max_button();
1555 for(int num = 0; num < ip; num++) {
1557 tmps = QString::asprintf(":/button%02d.png", num);
1558 QImageReader *reader = new QImageReader(tmps);
1559 QImage *result = new QImage(reader->read());
1561 if(result != NULL) {
1562 if(!result->isNull()) {
1563 pic = result->convertToFormat(QImage::Format_ARGB32);
1565 pic = QImage(10, 10, QImage::Format_RGBA8888);
1566 pic.fill(QColor(0,0,0,0));
1570 pic = QImage(10, 10, QImage::Format_RGBA8888);
1571 pic.fill(QColor(0,0,0,0));
1573 ButtonImages.push_back(pic);
1576 vertexButtons = new QVector<VertexTexCoord_t>;
1577 for(int i = 0; i < using_flags->get_max_button(); i++) {
1578 buffer_button_vertex[i] = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
1579 buffer_button_vertex[i]->create();
1580 fButtonX[i] = -1.0 + (float)(vm_buttons_d[i].x * 2) / (float)using_flags->get_screen_width();
1581 fButtonY[i] = 1.0 - (float)(vm_buttons_d[i].y * 2) / (float)using_flags->get_screen_height();
1582 fButtonWidth[i] = (float)(vm_buttons_d[i].width * 2) / (float)using_flags->get_screen_width();
1583 fButtonHeight[i] = (float)(vm_buttons_d[i].height * 2) / (float)using_flags->get_screen_height();
1585 vertex_button[i] = new QOpenGLVertexArrayObject;
1586 if(vertex_button[i] != NULL) {
1587 if(vertex_button[i]->create()) {
1588 VertexTexCoord_t vt[4];
1590 vt[0].x = fButtonX[i];
1591 vt[0].y = fButtonY[i];
1596 vt[1].x = fButtonX[i] + fButtonWidth[i];
1597 vt[1].y = fButtonY[i];
1602 vt[2].x = fButtonX[i] + fButtonWidth[i];
1603 vt[2].y = fButtonY[i] - fButtonHeight[i];
1608 vt[3].x = fButtonX[i];
1609 vt[3].y = fButtonY[i] - fButtonHeight[i];
1614 vertexButtons->append(vt[0]);
1615 vertexButtons->append(vt[1]);
1616 vertexButtons->append(vt[2]);
1617 vertexButtons->append(vt[3]);
1618 vertex_button[i]->bind();
1619 buffer_button_vertex[i]->bind();
1620 buffer_button_vertex[i]->allocate(4 * sizeof(VertexTexCoord_t));
1622 buffer_button_vertex[i]->setUsagePattern(QOpenGLBuffer::StaticDraw);
1623 buffer_button_vertex[i]->release();
1624 vertex_button[i]->release();
1625 setNormalVAO(button_shader, vertex_button[i],
1626 buffer_button_vertex[i],
1634 void GLDraw_ES_2::do_set_display_osd(bool onoff)
1639 void GLDraw_ES_2::do_display_osd_leds(int lednum, bool onoff)
1642 osd_led_status = (onoff) ? 0xffffffff : 0x00000000;
1643 } else if((lednum >= 0) && (lednum < 32)) {
1645 nn = 0x00000001 << lednum;
1647 osd_led_status |= nn;
1649 osd_led_status &= ~nn;
1654 void GLDraw_ES_2::uploadIconTexture(QPixmap *p, int icon_type, int localnum)
1656 if((icon_type > 7) || (icon_type < 0)) return;
1657 if((localnum >= 9) || (localnum < 0)) return;
1658 if(p == NULL) return;
1659 p_wid->makeCurrent();
1660 QImage image = p->toImage();
1662 if(icon_texid[icon_type][localnum] != NULL) delete icon_texid[icon_type][localnum];
1664 icon_texid[icon_type][localnum] = new QOpenGLTexture(image);
1666 p_wid->doneCurrent();
1671 void GLDraw_ES_2::updateBitmap(QImage *p)
1673 if(!using_flags->is_use_one_board_computer()) return;
1674 redraw_required = true;
1675 bitmap_uploaded = false;
1676 uploadBitmapTexture(p);
1679 void GLDraw_ES_2::uploadBitmapTexture(QImage *p)
1681 if(!using_flags->is_use_one_board_computer()) return;
1682 if(p == NULL) return;
1683 if(!bitmap_uploaded) {
1684 p_wid->makeCurrent();
1685 if(uBitmapTextureID != NULL) {
1686 delete uBitmapTextureID;
1688 uBitmapTextureID = new QOpenGLTexture(*p);
1689 p_wid->doneCurrent();
1690 bitmap_uploaded = true;
1695 void GLDraw_ES_2::updateButtonTexture(void)
1698 button_desc_t *vm_buttons_d = using_flags->get_vm_buttons();
1699 if(button_updated) return;
1700 if(vm_buttons_d != NULL) {
1701 for(i = 0; i < using_flags->get_max_button(); i++) {
1702 QImage img = ButtonImages.at(i);
1703 if(uButtonTextureID[i] != NULL) {
1704 delete uButtonTextureID[i];
1706 uButtonTextureID[i] = new QOpenGLTexture(img);
1709 button_updated = true;