3 * (c) 2016 K.Ohta <whatisthis.sowhat@gmail.com>
5 * Renderer with OpenGL v2.0 .
7 * Jan 21, 2016 : Initial.
12 #include <QOpenGLFramebufferObject>
14 #include <QImageReader>
16 #include <QOpenGLFunctions_2_0>
18 #include "osd_types.h"
19 #include "qt_gldraw.h"
20 #include "qt_glutil_gl2_0.h"
21 #include "menu_flags.h"
23 GLDraw_2_0::GLDraw_2_0(GLDrawClass *parent, USING_FLAGS *p, CSP_Logger *logger, EMU *emu) : GLDraw_Tmpl(parent, p, logger, emu)
29 GLDraw_2_0::~GLDraw_2_0()
31 if(buffer_screen_vertex->isCreated()) buffer_screen_vertex->destroy();
32 if(vertex_screen->isCreated()) vertex_screen->destroy();
33 if(glVertGrids != NULL) free(glVertGrids);
34 if(glHorizGrids != NULL) free(glHorizGrids);
35 if(using_flags->is_use_one_board_computer()) {
36 if(uBitmapTextureID != NULL) {
37 delete uBitmapTextureID;
40 if(using_flags->get_max_button() > 0) {
42 for(i = 0; i < using_flags->get_max_button(); i++) {
43 if(uButtonTextureID[i] != NULL) delete uButtonTextureID[i];
45 for(i = 0; i < using_flags->get_max_button(); i++) {
46 if(vertex_button[i]->isCreated()) vertex_button[i]->destroy();
50 if(using_flags->is_use_one_board_computer()) {
51 if(vertex_bitmap->isCreated()) vertex_bitmap->destroy();
53 if(uVramTextureID != NULL) {
54 delete uVramTextureID;
56 if(extfunc_2 != NULL) delete extfunc_2;
59 void GLDraw_2_0::initializeGL(void)
63 void GLDraw_2_0::do_set_display_osd(bool onoff)
68 void GLDraw_2_0::set_osd_vertex(int xbit)
70 float xbase, ybase, zbase;
73 if((xbit < 0) || (xbit >= 32)) return;
74 if((i >= 2) && (i < 10)) { // FD
77 nl = using_flags->get_max_drive();
78 } else if((i >= 10) && (i < 12)) { // QD
81 nl = using_flags->get_max_qd();
82 } else if((i >= 12) && (i < 14)) { // CMT(R)
85 nl = using_flags->get_max_tape();
86 } else if((i >= 14) && (i < 16)) { // CMT(W)
89 nl = using_flags->get_max_tape();
91 major = 4 + (i / 8) - 2;
99 xbase = 1.0f - (1.0f * 48.0f / 640.0f) * (float)(nl - minor) - (4.0f / 640.0f);;
100 ybase = -1.0f + (1.0f * 48.0f / 400.0f) * (float)(major + 1) + (4.0f / 400.0f);
102 vertexOSD[i][0].x = xbase;
103 vertexOSD[i][0].y = ybase;
104 vertexOSD[i][0].z = zbase;
105 vertexOSD[i][0].s = 0.0f;
106 vertexOSD[i][0].t = 0.0f;
108 vertexOSD[i][1].x = xbase + (48.0f / 640.0f);
109 vertexOSD[i][1].y = ybase;
110 vertexOSD[i][1].z = zbase;
111 vertexOSD[i][1].s = 1.0f;
112 vertexOSD[i][1].t = 0.0f;
114 vertexOSD[i][2].x = xbase + (48.0f / 640.0f);
115 vertexOSD[i][2].y = ybase - (48.0f / 400.0f);
116 vertexOSD[i][2].z = zbase;
117 vertexOSD[i][2].s = 1.0f;
118 vertexOSD[i][2].t = 1.0f;
120 vertexOSD[i][3].x = xbase;
121 vertexOSD[i][3].y = ybase - (48.0f / 400.0f);
122 vertexOSD[i][3].z = zbase;
123 vertexOSD[i][3].s = 0.0f;
124 vertexOSD[i][3].t = 1.0f;
126 setNormalVAO(osd_shader, vertex_osd[xbit],
128 &(vertexOSD[i][0]), 4);
132 void GLDraw_2_0::do_display_osd_leds(int lednum, bool onoff)
135 osd_led_status = (onoff) ? 0xffffffff : 0x00000000;
136 } else if((lednum >= 0) && (lednum < 32)) {
138 nn = 0x00000001 << lednum;
140 osd_led_status |= nn;
142 osd_led_status &= ~nn;
147 void GLDraw_2_0::drawOsdLeds()
151 VertexTexCoord_t vertex[4];
152 float xbase, ybase, zbase;
154 color_on = QVector4D(0.95, 0.0, 0.05, 1.0);
155 color_off = QVector4D(0.05,0.05, 0.05, 0.10);
157 color_on = QVector4D(0.00,0.00, 0.00, 0.0);
158 color_off = QVector4D(0.00,0.00, 0.00, 0.0);
160 xbase = 0.0f + (1.0f / 32.0f) * 31.0f + (1.0f / 128.0f);
161 ybase = -1.0f + (2.0f / 64.0f) * 1.5f;
164 extfunc_2->glEnable(GL_BLEND);
165 extfunc_2->glDisable(GL_TEXTURE_2D);
166 extfunc_2->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
167 extfunc_2->glDisable(GL_DEPTH_TEST);
168 extfunc_2->glViewport(0, 0, p_wid->width(), p_wid->height());
169 extfunc_2->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
170 if(osd_led_status != osd_led_status_bak) {
172 uint32_t _bit = 0x00000001;
173 for(int ii = 0; ii < osd_led_bit_width; ii++) {
174 if((_bit & osd_led_status) == (_bit & osd_led_status_bak)) {
175 xbase = xbase - (1.0f / 32.0f);
183 vertex[1].x = xbase + (1.0f / 64.0f);
187 vertex[2].x = xbase + (1.0f / 64.0f);
188 vertex[2].y = ybase - (1.0f / 64.0f);
192 vertex[3].y = ybase - (1.0f / 64.0f);
194 if(_bit & osd_led_status) {
195 extfunc_2->glColor4f(color_on.x(), color_on.y(), color_on.z(), color_on.w());
197 extfunc_2->glColor4f(color_off.x(), color_off.y(), color_off.z(), color_off.w());
199 extfunc_2->glBegin(GL_POLYGON);
200 for(int j = 0; j < 4; j++) {
201 extfunc_2->glVertex3f(vertex[j].x, vertex[j].y, vertex[j].z);
204 xbase = xbase - (1.0f / 32.0f);
207 osd_led_status_bak = osd_led_status;
213 void GLDraw_2_0::drawOsdIcons()
219 color_on = QVector4D(1.0, 1.0, 1.0, 0.8);
220 color_off = QVector4D(1.0, 1.0, 1.0, 0.00);
222 color_on = QVector4D(0.00,0.00, 0.00, 0.0);
223 color_off = QVector4D(0.00,0.00, 0.00, 0.0);
225 extfunc_2->glEnable(GL_BLEND);
226 extfunc_2->glEnable(GL_TEXTURE_2D);
227 extfunc_2->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
228 extfunc_2->glDisable(GL_DEPTH_TEST);
229 extfunc_2->glViewport(0, 0, p_wid->width(), p_wid->height());
230 extfunc_2->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
232 uint32_t _bit = 0x00000001;
234 for(int ii = 0; ii < osd_led_bit_width; ii++) {
235 checkf = ((_bit & osd_led_status) != 0);
236 if(checkf == ((_bit & osd_led_status_bak) != 0)) {
242 if((ii >= 2) && (ii < 10)) { // FD
245 } else if((ii >= 10) && (ii < 12)) { // QD
248 } else if((ii >= 12) && (ii < 14)) { // CMT(R)
251 } else if((ii >= 14) && (ii < 16)) { // CMT(W)
254 } else if(ii >= 16) {
255 major = 4 + (ii / 8) - 2;
261 // ToDo: CD,LD and HDD.
263 drawMain(osd_shader, vertex_osd[ii],
266 icon_texid[major][minor]->textureId(),
269 drawMain(osd_shader, vertex_osd[ii],
272 icon_texid[major][minor]->textureId(),
277 osd_led_status_bak = osd_led_status;
281 void GLDraw_2_0::setNormalVAO(QOpenGLShaderProgram *prg,
282 QOpenGLVertexArrayObject *vp,
284 VertexTexCoord_t *tp,
287 int vertex_loc = prg->attributeLocation("vertex");
288 int texcoord_loc = prg->attributeLocation("texcoord");
290 if(bp == NULL) return;
291 if(prg == NULL) return;
292 if(!bp->isCreated()) return;
295 bp->write(0, tp, sizeof(VertexTexCoord_t) * size);
296 prg->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3, sizeof(VertexTexCoord_t));
297 prg->setAttributeBuffer(texcoord_loc, GL_FLOAT, 3 * sizeof(GLfloat), 2, sizeof(VertexTexCoord_t));
300 prg->setUniformValue("a_texture", 0);
304 void GLDraw_2_0::setChangeBrightness(bool flag)
306 set_brightness = flag;
309 void GLDraw_2_0::setBrightness(GLfloat r, GLfloat g, GLfloat b)
316 void GLDraw_2_0::setImgPtr(QImage *p)
321 void GLDraw_2_0::setSmoosing(bool flag)
327 void GLDraw_2_0::setVirtualVramSize(int width, int height)
330 horiz_pixels = width;
334 void GLDraw_2_0::set_emu_launched(void)
339 void GLDraw_2_0::setDrawGLGridVert(bool flag)
345 void GLDraw_2_0::setDrawGLGridHoriz(bool flag)
351 void GLDraw_2_0::initGLObjects()
353 extfunc_2 = new QOpenGLFunctions_2_0;
354 extfunc_2->initializeOpenGLFunctions();
355 extfunc_2->glViewport(0, 0, p_wid->width(), p_wid->height());
356 extfunc_2->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
357 extfunc_2->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texture_max_size);
360 void GLDraw_2_0::initButtons(void)
362 button_desc_t *vm_buttons_d = using_flags->get_vm_buttons();
364 if(vm_buttons_d != NULL) {
365 button_shader = new QOpenGLShaderProgram(p_wid);
366 if(button_shader != NULL) {
367 button_shader->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/gl2/vertex_shader.glsl");
368 button_shader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/gl2/normal_fragment_shader.glsl");
369 button_shader->link();
372 int ip = using_flags->get_max_button();
374 for(int num = 0; num < ip; num++) {
376 tmps = QString::asprintf(":/button%02d.png", num);
377 QImageReader *reader = new QImageReader(tmps);
378 QImage *result = new QImage(reader->read());
381 if(!result->isNull()) {
382 pic = result->convertToFormat(QImage::Format_ARGB32);
384 pic = QImage(10, 10, QImage::Format_RGBA8888);
385 pic.fill(QColor(0,0,0,0));
389 pic = QImage(10, 10, QImage::Format_RGBA8888);
390 pic.fill(QColor(0,0,0,0));
392 ButtonImages.push_back(pic);
395 vertexButtons = new QVector<VertexTexCoord_t>;
396 for(int i = 0; i < using_flags->get_max_button(); i++) {
397 buffer_button_vertex[i] = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
398 buffer_button_vertex[i]->create();
399 fButtonX[i] = -1.0 + (float)(vm_buttons_d[i].x * 2) / (float)using_flags->get_screen_width();
400 fButtonY[i] = 1.0 - (float)(vm_buttons_d[i].y * 2) / (float)using_flags->get_screen_height();
401 fButtonWidth[i] = (float)(vm_buttons_d[i].width * 2) / (float)using_flags->get_screen_width();
402 fButtonHeight[i] = (float)(vm_buttons_d[i].height * 2) / (float)using_flags->get_screen_height();
404 vertex_button[i] = new QOpenGLVertexArrayObject;
405 if(vertex_button[i] != NULL) {
406 if(vertex_button[i]->create()) {
407 VertexTexCoord_t vt[4];
409 vt[0].x = fButtonX[i];
410 vt[0].y = fButtonY[i];
415 vt[1].x = fButtonX[i] + fButtonWidth[i];
416 vt[1].y = fButtonY[i];
421 vt[2].x = fButtonX[i] + fButtonWidth[i];
422 vt[2].y = fButtonY[i] - fButtonHeight[i];
427 vt[3].x = fButtonX[i];
428 vt[3].y = fButtonY[i] - fButtonHeight[i];
433 vertexButtons->append(vt[0]);
434 vertexButtons->append(vt[1]);
435 vertexButtons->append(vt[2]);
436 vertexButtons->append(vt[3]);
437 vertex_button[i]->bind();
438 buffer_button_vertex[i]->bind();
439 buffer_button_vertex[i]->allocate(4 * sizeof(VertexTexCoord_t));
441 buffer_button_vertex[i]->setUsagePattern(QOpenGLBuffer::StaticDraw);
442 buffer_button_vertex[i]->release();
443 vertex_button[i]->release();
444 setNormalVAO(button_shader, vertex_button[i],
445 buffer_button_vertex[i],
453 void GLDraw_2_0::initBitmapVertex(void)
455 if(using_flags->is_use_one_board_computer()) {
456 vertexBitmap[0].x = -1.0f;
457 vertexBitmap[0].y = -1.0f;
458 vertexBitmap[0].z = -0.1f;
459 vertexBitmap[0].s = 0.0f;
460 vertexBitmap[0].t = 1.0f;
462 vertexBitmap[1].x = +1.0f;
463 vertexBitmap[1].y = -1.0f;
464 vertexBitmap[1].z = -0.1f;
465 vertexBitmap[1].s = 1.0f;
466 vertexBitmap[1].t = 1.0f;
468 vertexBitmap[2].x = +1.0f;
469 vertexBitmap[2].y = +1.0f;
470 vertexBitmap[2].z = -0.1f;
471 vertexBitmap[2].s = 1.0f;
472 vertexBitmap[2].t = 0.0f;
474 vertexBitmap[3].x = -1.0f;
475 vertexBitmap[3].y = +1.0f;
476 vertexBitmap[3].z = -0.1f;
477 vertexBitmap[3].s = 0.0f;
478 vertexBitmap[3].t = 0.0f;
483 void GLDraw_2_0::initBitmapVAO(void)
485 if(using_flags->is_use_one_board_computer()) {
486 bitmap_shader = new QOpenGLShaderProgram(p_wid);
487 if(bitmap_shader != NULL) {
488 bitmap_shader->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/gl2/vertex_shader.glsl");
489 bitmap_shader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/gl2/normal_fragment_shader.glsl");
490 bitmap_shader->link();
492 buffer_bitmap_vertex = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
493 vertex_bitmap = new QOpenGLVertexArrayObject;
494 if(vertex_bitmap != NULL) {
495 if(vertex_bitmap->create()) {
496 buffer_bitmap_vertex->create();
497 buffer_bitmap_vertex->setUsagePattern(QOpenGLBuffer::StaticDraw);
501 c = QVector4D(1.0, 1.0, 1.0, 1.0);
502 bitmap_shader->setUniformValue("color", c);
504 vertex_bitmap->bind();
505 buffer_bitmap_vertex->bind();
506 buffer_bitmap_vertex->allocate(sizeof(vertexBitmap));
507 buffer_bitmap_vertex->release();
508 vertex_bitmap->release();
509 setNormalVAO(bitmap_shader, vertex_bitmap,
510 buffer_bitmap_vertex,
517 void GLDraw_2_0::initFBO(void)
519 // Will fix around vm_buttons[].
521 if(using_flags->get_max_button() > 0) {
524 glHorizGrids = (GLfloat *)malloc(sizeof(float) * (using_flags->get_real_screen_height() + 2) * 6);
525 if(glHorizGrids != NULL) {
526 doSetGridsHorizonal(using_flags->get_real_screen_height(), true);
528 glVertGrids = (GLfloat *)malloc(sizeof(float) * (using_flags->get_real_screen_width() + 2) * 6);
529 if(glVertGrids != NULL) {
530 doSetGridsVertical(using_flags->get_real_screen_width(), true);
533 extfunc_2->glClearColor(0.0, 0.0, 0.0, 1.0);
536 void GLDraw_2_0::initLocalGLObjects(void)
538 main_shader = new QOpenGLShaderProgram(p_wid);
539 if(main_shader != NULL) {
540 main_shader->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/gl2/vertex_shader.glsl");
541 main_shader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/gl2/chromakey_fragment_shader2.glsl");
544 buffer_screen_vertex = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
545 vertex_screen = new QOpenGLVertexArrayObject;
547 vertexFormat[0].x = -0.5f;
548 vertexFormat[0].y = -0.5f;
549 vertexFormat[0].z = -0.9f;
550 vertexFormat[0].s = 0.0f;
551 vertexFormat[0].t = 1.0f;
553 vertexFormat[1].x = +0.5f;
554 vertexFormat[1].y = -0.5f;
555 vertexFormat[1].z = -0.9f;
556 vertexFormat[1].s = 1.0f;
557 vertexFormat[1].t = 1.0f;
559 vertexFormat[2].x = +0.5f;
560 vertexFormat[2].y = +0.5f;
561 vertexFormat[2].z = -0.9f;
562 vertexFormat[2].s = 1.0f;
563 vertexFormat[2].t = 0.0f;
565 vertexFormat[3].x = -0.5f;
566 vertexFormat[3].y = +0.5f;
567 vertexFormat[3].z = -0.9f;
568 vertexFormat[3].s = 0.0f;
569 vertexFormat[3].t = 0.0f;
570 if(buffer_screen_vertex != NULL) {
571 if(buffer_screen_vertex->create()) {
574 c = QVector4D(1.0, 1.0, 1.0, 1.0);
575 main_shader->setUniformValue("color", c);
578 //buffer_screen_vertex->create();
579 buffer_screen_vertex->setUsagePattern(QOpenGLBuffer::DynamicDraw);
580 vertex_screen->create();
582 if(vertex_screen != NULL) vertex_screen->bind();
583 buffer_screen_vertex->bind();
584 buffer_screen_vertex->allocate(sizeof(VertexTexCoord_t) * 4);
585 if(vertex_screen != NULL) vertex_screen->release();
586 buffer_screen_vertex->release();
587 setNormalVAO(main_shader, vertex_screen,
588 buffer_screen_vertex,
596 void GLDraw_2_0::initOsdObjects(void)
598 osd_shader = new QOpenGLShaderProgram(p_wid);
599 if(osd_shader != NULL) {
600 osd_shader->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/gl2/vertex_shader.glsl");
601 osd_shader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/gl2/icon_fragment_shader.glsl");
604 for(int i = 0; i < 32; i++) {
605 buffer_osd[i] = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
606 vertex_osd[i] = new QOpenGLVertexArrayObject;
608 if(buffer_osd[i] != NULL) {
609 if(buffer_osd[i]->create()) {
612 c = QVector4D(1.0, 1.0, 1.0, 1.0);
613 osd_shader->setUniformValue("color", c);
616 //buffer_screen_vertex->create();
617 buffer_osd[i]->setUsagePattern(QOpenGLBuffer::StaticDraw);
618 vertex_osd[i]->create();
620 if(vertex_osd[i] != NULL) vertex_osd[i]->bind();
621 buffer_osd[i]->bind();
622 buffer_osd[i]->allocate(sizeof(VertexTexCoord_t) * 4);
623 if(vertex_osd[i] != NULL) vertex_osd[i]->release();
624 buffer_osd[i]->release();
631 void GLDraw_2_0::drawGridsMain(GLfloat *tp,
636 if(number <= 0) return;
637 extfunc_2->glDisable(GL_TEXTURE_2D);
638 extfunc_2->glDisable(GL_DEPTH_TEST);
639 extfunc_2->glDisable(GL_BLEND);
645 extfunc_2->glColor4f(color.x(), color.y(), color.z(), color.w());
646 extfunc_2->glLineWidth(lineWidth);
647 extfunc_2->glBegin(GL_LINES);
648 if((p_config->rotate_type == 1) || (p_config->rotate_type == 3)) {
649 for(i = 0; i < (number + 1); i++) {
650 extfunc_2->glVertex3f(tp[p + 1], tp[p + 0], tp[p + 2]);
651 extfunc_2->glVertex3f(tp[p + 4], tp[p + 3], tp[p + 5]);
655 for(i = 0; i < (number + 1); i++) {
656 extfunc_2->glVertex3f(tp[p + 0], tp[p + 1], tp[p + 2]);
657 extfunc_2->glVertex3f(tp[p + 3], tp[p + 4], tp[p + 5]);
666 void GLDraw_2_0::drawGridsHorizonal(void)
668 QVector4D c= QVector4D(0.0f, 0.0f, 0.0f, 1.0f);
669 drawGridsMain(glHorizGrids,
675 void GLDraw_2_0::drawGridsVertical(void)
677 QVector4D c= QVector4D(0.0f, 0.0f, 0.0f, 1.0f);
678 drawGridsMain(glVertGrids,
685 void GLDraw_2_0::drawGrids(void)
687 gl_grid_horiz = p_config->opengl_scanline_horiz;
688 gl_grid_vert = p_config->opengl_scanline_vert;
689 if(gl_grid_horiz && (vert_lines > 0)) {
690 drawGridsHorizonal();
692 if(using_flags->is_use_vertical_pixel_lines()) {
693 if(gl_grid_vert && (horiz_pixels > 0)) {
699 void GLDraw_2_0::updateButtonTexture(void)
702 button_desc_t *vm_buttons_d = using_flags->get_vm_buttons();
703 if(button_updated) return;
704 if(vm_buttons_d != NULL) {
705 for(i = 0; i < using_flags->get_max_button(); i++) {
706 QImage img = ButtonImages.at(i);
707 if(uButtonTextureID[i] != NULL) {
708 delete uButtonTextureID[i];
710 uButtonTextureID[i] = new QOpenGLTexture(img);
713 button_updated = true;
716 void GLDraw_2_0::drawButtons()
719 updateButtonTexture();
720 for(i = 0; i < using_flags->get_max_button(); i++) {
722 VertexTexCoord_t vt[4];
723 vt[0].x = fButtonX[i];
724 vt[0].y = fButtonY[i];
729 vt[1].x = fButtonX[i] + fButtonWidth[i];
730 vt[1].y = fButtonY[i];
735 vt[2].x = fButtonX[i] + fButtonWidth[i];
736 vt[2].y = fButtonY[i] - fButtonHeight[i];
741 vt[3].x = fButtonX[i];
742 vt[3].y = fButtonY[i] - fButtonHeight[i];
746 c = QVector4D(1.0, 1.0, 1.0, 1.0);
747 if(uButtonTextureID[i] == NULL) continue;
748 drawMain(button_shader, vertex_button[i],
749 buffer_button_vertex[i],
751 uButtonTextureID[i]->textureId(),
757 void GLDraw_2_0::drawBitmapTexture(void)
759 if(using_flags->is_use_one_board_computer()) {
761 c = QVector4D(1.0, 1.0, 1.0, 1.0);
762 if(uBitmapTextureID == NULL) return;
763 drawMain(bitmap_shader, vertex_bitmap,
764 buffer_bitmap_vertex,
766 uBitmapTextureID->textureId(),
771 void GLDraw_2_0::drawScreenTexture(void)
773 if(using_flags->is_use_one_board_computer()) {
774 if(uBitmapTextureID != NULL) {
775 extfunc_2->glEnable(GL_BLEND);
776 extfunc_2->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
779 extfunc_2->glDisable(GL_BLEND);
781 if(uVramTextureID == NULL) return;
783 smoosing = p_config->use_opengl_filters;
785 color = QVector4D(fBrightR, fBrightG, fBrightB, 1.0);
787 color = QVector4D(1.0, 1.0, 1.0, 1.0);
789 if(using_flags->is_use_one_board_computer()) {
790 QVector3D cc = QVector3D(0.0, 0.0, 0.0);
791 drawMain(main_shader, vertex_screen,
792 buffer_screen_vertex,
794 uVramTextureID->textureId(), // v2.0
797 extfunc_2->glDisable(GL_BLEND);
799 drawMain(main_shader, vertex_screen,
800 buffer_screen_vertex,
802 uVramTextureID->textureId(), // v2.0
807 void GLDraw_2_0::drawMain(QOpenGLShaderProgram *prg,
808 QOpenGLVertexArrayObject *vp,
810 VertexTexCoord_t *vertex_data,
820 extfunc_2->glEnable(GL_TEXTURE_2D);
822 extfunc_2->glViewport(0, 0, p_wid->width(), p_wid->height());
823 extfunc_2->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
824 extfunc_2->glBindTexture(GL_TEXTURE_2D, texid);
827 extfunc_2->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
828 extfunc_2->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
830 extfunc_2->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
831 extfunc_2->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
834 if((bp != NULL) && (vp != NULL) && (prg != NULL)) {
835 if((bp->isCreated()) && (vp->isCreated()) && (prg->isLinked())) {
839 prg->setUniformValue("a_texture", 0);
840 prg->setUniformValue("color", color);
841 //prg->setUniformValue("tex_width", (float)screen_texture_width);
842 //prg->setUniformValue("tex_height", (float)screen_texture_height);
844 prg->setUniformValue("tex_width", (float)p->width());
845 prg->setUniformValue("tex_height", (float)p->height());
848 switch(p_config->rotate_type) {
850 rot = QMatrix2x2(rot0);
853 rot = QMatrix2x2(rot90);
856 rot = QMatrix2x2(rot180);
859 rot = QMatrix2x2(rot270);
862 rot = QMatrix2x2(rot0);
865 prg->setUniformValue("rotate_mat", rot);
867 prg->setUniformValue("chromakey", chromakey);
868 prg->setUniformValue("do_chromakey", GL_TRUE);
870 prg->setUniformValue("do_chromakey", GL_FALSE);
872 int vertex_loc = prg->attributeLocation("vertex");
873 int texcoord_loc = prg->attributeLocation("texcoord");
874 prg->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3, sizeof(VertexTexCoord_t));
875 prg->setAttributeBuffer(texcoord_loc, GL_FLOAT, 3 * sizeof(GLfloat), 2, sizeof(VertexTexCoord_t));
876 prg->enableAttributeArray(vertex_loc);
877 prg->enableAttributeArray(texcoord_loc);
879 extfunc_2->glDisable(GL_DEPTH_TEST);
880 extfunc_2->glEnableClientState(GL_VERTEX_ARRAY);
881 extfunc_2->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
882 extfunc_2->glColor3f(1.0f, 1.0f, 1.0f);
884 extfunc_2->glVertexPointer(3, GL_FLOAT, sizeof(VertexTexCoord_t), (void *)0);
885 extfunc_2->glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTexCoord_t), (void *)(0 + 3 * sizeof(GLfloat)));
886 extfunc_2->glDrawArrays(GL_POLYGON, 0, 4);
887 extfunc_2->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
888 extfunc_2->glDisableClientState(GL_VERTEX_ARRAY);
893 extfunc_2->glBindTexture(GL_TEXTURE_2D, 0);
894 extfunc_2->glDisable(GL_TEXTURE_2D);
901 extfunc_2->glDisable(GL_DEPTH_TEST);
902 extfunc_2->glBegin(GL_POLYGON);
903 for(i = 0; i < 4; i++) {
904 extfunc_2->glTexCoord2f(vertex_data[i].s, vertex_data[i].t);
905 extfunc_2->glVertex3f(vertex_data[i].x, vertex_data[i].y, vertex_data[i].z);
908 extfunc_2->glBindTexture(GL_TEXTURE_2D, 0);
909 extfunc_2->glDisable(GL_TEXTURE_2D);
914 void GLDraw_2_0::uploadBitmapTexture(QImage *p)
916 if(!using_flags->is_use_one_board_computer()) return;
917 if(p == NULL) return;
918 if(!bitmap_uploaded) {
919 p_wid->makeCurrent();
920 if(uBitmapTextureID != NULL) {
921 delete uBitmapTextureID;
923 uBitmapTextureID = new QOpenGLTexture(*p);
924 p_wid->doneCurrent();
925 bitmap_uploaded = true;
930 void GLDraw_2_0::uploadIconTexture(QPixmap *p, int icon_type, int localnum)
932 if((icon_type > 8) || (icon_type < 0)) return;
933 if((localnum >= 9) || (localnum < 0)) return;
934 if(p == NULL) return;
935 p_wid->makeCurrent();
936 QImage image = p->toImage();
938 if(icon_texid[icon_type][localnum] != NULL) delete icon_texid[icon_type][localnum];
940 icon_texid[icon_type][localnum] = new QOpenGLTexture(image);
942 p_wid->doneCurrent();
946 void GLDraw_2_0::updateBitmap(QImage *p)
948 if(!using_flags->is_use_one_board_computer()) return;
949 redraw_required = true;
950 bitmap_uploaded = false;
951 uploadBitmapTexture(p);
954 void GLDraw_2_0::uploadMainTexture(QImage *p, bool use_chromakey, bool was_mapped)
957 redraw_required = true;
959 if(p == NULL) return;
961 // Upload to main texture
962 if(uVramTextureID == NULL) {
963 uVramTextureID = new QOpenGLTexture(*p);
965 extfunc_2->glBindTexture(GL_TEXTURE_2D, uVramTextureID->textureId());
966 extfunc_2->glTexSubImage2D(GL_TEXTURE_2D, 0,
968 p->width(), p->height(),
969 GL_RGBA, GL_UNSIGNED_BYTE, p->constBits());
970 extfunc_2->glBindTexture(GL_TEXTURE_2D, 0);
975 void GLDraw_2_0::resizeGL_Screen(void)
977 if(buffer_screen_vertex->isCreated()) {
978 setNormalVAO(main_shader, vertex_screen,
979 buffer_screen_vertex,
984 void GLDraw_2_0::resizeGL_SetVertexs(void)
986 vertexFormat[0].x = -screen_width;
987 vertexFormat[0].y = -screen_height;
988 vertexFormat[1].x = +screen_width;
989 vertexFormat[1].y = -screen_height;
990 vertexFormat[2].x = +screen_width;
991 vertexFormat[2].y = +screen_height;
992 vertexFormat[3].x = -screen_width;
993 vertexFormat[3].y = +screen_height;
995 if(using_flags->is_use_one_board_computer()) {
996 #if !defined(BITMAP_OFFSET_X)
997 #define BITMAP_OFFSET_X 0
999 #if !defined(BITMAP_OFFSET_Y)
1000 #define BITMAP_OFFSET_Y 0
1002 vertexBitmap[0].x = -1.0f;
1003 vertexBitmap[0].y = -1.0f;
1005 vertexBitmap[1].x = 1.0f - (float)BITMAP_OFFSET_X / (float)using_flags->get_screen_width();
1006 vertexBitmap[1].y = -1.0f;
1008 vertexBitmap[2].x = 1.0f - (float)BITMAP_OFFSET_X / (float)using_flags->get_screen_width();
1009 vertexBitmap[2].y = 1.0f - (float)BITMAP_OFFSET_Y * 2.0 / (float)using_flags->get_screen_height();
1011 vertexBitmap[3].x = -1.0f;
1012 vertexBitmap[3].y = 1.0f - (float)BITMAP_OFFSET_Y * 2.0 / (float)using_flags->get_screen_height();
1017 void GLDraw_2_0::resizeGL(int width, int height)
1019 //int side = qMin(width, height);
1020 p_wid->makeCurrent();
1021 extfunc_2->glViewport(0, 0, width, height);
1022 extfunc_2->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
1024 if(!using_flags->is_use_one_board_computer() && (using_flags->get_max_button() <= 0)) {
1025 doSetGridsHorizonal(vert_lines, true);
1026 if(using_flags->is_use_vertical_pixel_lines()) {
1027 doSetGridsVertical(horiz_pixels, true);
1030 resizeGL_SetVertexs();
1032 if(using_flags->is_use_one_board_computer()) {
1033 if(vertex_bitmap != NULL) {
1034 if(vertex_bitmap->isCreated()) {
1035 setNormalVAO(bitmap_shader, vertex_bitmap,
1036 buffer_bitmap_vertex,
1042 if(using_flags->get_max_button() > 0) {
1043 updateButtonTexture();
1045 p_wid->doneCurrent();
1048 void GLDraw_2_0::paintGL(void)
1050 //p_wid->makeCurrent();
1051 //if(crt_flag || redraw_required) { //return;
1055 redraw_required = false;
1056 extfunc_2->glViewport(0, 0, p_wid->width(), p_wid->height());
1057 extfunc_2->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
1059 extfunc_2->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1060 //extfunc_2->glDisable(GL_DEPTH_TEST);
1061 extfunc_2->glEnable(GL_DEPTH_TEST);
1062 extfunc_2->glDisable(GL_BLEND);
1063 if(using_flags->is_use_one_board_computer() || using_flags->is_use_bitmap()) {
1064 drawBitmapTexture();
1066 if((using_flags->get_max_button() > 0)) {
1070 * VRAMの表示:テクスチャ貼った四角形
1072 drawScreenTexture();
1073 extfunc_2->glDisable(GL_BLEND);
1074 if(!using_flags->is_use_one_board_computer() && (using_flags->get_max_button() <= 0)) {
1077 if(p_config->use_osd_virtual_media) drawOsdIcons();
1078 extfunc_2->glFlush();
1081 void GLDraw_2_0::paintGL_OffScreen(int count, int w, int h)
1088 void GLDraw_2_0::do_set_screen_multiply(float mul)
1090 screen_multiply = mul;
1091 do_set_texture_size(imgptr, screen_texture_width, screen_texture_height);
1092 //do_set_texture_size(imgptr, -1, -1);
1096 void GLDraw_2_0::do_set_texture_size(QImage *p, int w, int h)
1098 if(w <= 0) w = using_flags->get_real_screen_width();
1099 if(h <= 0) h = using_flags->get_real_screen_height();
1104 iw = (float)p->width();
1105 ih = (float)p->height();
1107 iw = (float)using_flags->get_real_screen_width();
1108 ih = (float)using_flags->get_real_screen_height();
1110 screen_texture_width = w;
1111 screen_texture_height = h;
1114 p_wid->makeCurrent();
1115 vertexFormat[0].s = 0.0f;
1116 vertexFormat[0].t = (float)h / ih;
1117 vertexFormat[1].s = (float)w / iw;
1118 vertexFormat[1].t = (float)h / ih;
1119 vertexFormat[2].s = (float)w / iw;
1120 vertexFormat[2].t = 0.0f;
1121 vertexFormat[3].s = 0.0f;
1122 vertexFormat[3].t = 0.0f;
1123 setNormalVAO(main_shader, vertex_screen,
1124 buffer_screen_vertex,
1126 p_wid->doneCurrent();
1128 if(w > using_flags->get_real_screen_width()) {
1129 w = using_flags->get_real_screen_width();
1131 if(h > using_flags->get_real_screen_height()) {
1132 h = using_flags->get_real_screen_height();
1134 this->doSetGridsVertical(w, false);
1135 this->doSetGridsHorizonal(h, false);
1139 void GLDraw_2_0::do_set_horiz_lines(int lines)
1141 if(lines > using_flags->get_real_screen_height()) {
1142 lines = using_flags->get_real_screen_height();
1144 this->doSetGridsHorizonal(lines, false);
1147 void GLDraw_2_0::do_set_led_width(int bitwidth)
1149 if((bitwidth >= 0) && (bitwidth < 32)) osd_led_bit_width = bitwidth;
1150 printf("%d\n", bitwidth);