#include "qt_glutil_gles_2.h"
#include "csp_logger.h"
#include "menu_flags.h"
+#include "common.h"
+
#include <QOpenGLFunctions>
#include <QOpenGLTexture>
#include <QImage>
#include <QImageReader>
+#include <QMatrix4x4>
+#include <QOpenGLPixelTransferOptions>
//extern USING_FLAGS *using_flags;
GLDraw_ES_2::GLDraw_ES_2(GLDrawClass *parent, USING_FLAGS *p, CSP_Logger *logger, EMU *emu) : GLDraw_2_0(parent, p, logger, emu)
grids_vertical_buffer = NULL;
grids_vertical_vertex = NULL;
ringing_phase = 0.0f;
-
+#if defined(__LITTLE_ENDIAN__)
+ swap_byteorder = true;
+#else
+ swap_byteorder = false;
+#endif
}
GLDraw_ES_2::~GLDraw_ES_2()
QVector4D color)
{
if(number <= 0) return;
- extfunc->glDisable(GL_TEXTURE_2D);
extfunc->glDisable(GL_DEPTH_TEST);
extfunc->glDisable(GL_BLEND);
extfunc->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
{
if((src_texture != 0) && (shader != NULL)) {
- extfunc->glEnable(GL_TEXTURE_2D);
+ QMatrix4x4 ortho;
+ ortho.ortho(0.0f, (float)dst_w, 0.0f, (float)dst_h, -1.0, 1.0);
+
renderObject->bind();
- //extfunc->glViewport(0, 0, src_w, src_h);
extfunc->glViewport(0, 0, dst_w, dst_h);
//extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
extfunc->glActiveTexture(GL_TEXTURE0);
extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//extfunc->glColor4f(1.0, 1.0, 1.0, 1.0);
shader->setUniformValue("a_texture", 0);
+ shader->setUniformValue("v_ortho", ortho);
//shader->setUniformValue("a_texture", src_texture);
{
ii = shader->uniformLocation("source_size");
int vertex_loc = shader->attributeLocation("vertex");
int texcoord_loc = shader->attributeLocation("texcoord");
+ shader->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3, sizeof(VertexTexCoord_t));
+ shader->setAttributeBuffer(texcoord_loc, GL_FLOAT, 3 * sizeof(GLfloat), 2, sizeof(VertexTexCoord_t));
extfunc->glEnableVertexAttribArray(vertex_loc);
extfunc->glEnableVertexAttribArray(texcoord_loc);
- extfunc->glEnable(GL_VERTEX_ARRAY);
- extfunc->glDrawArrays(GL_POLYGON, 0, 4);
+ extfunc->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
- extfunc->glViewport(0, 0, dst_w, dst_h);
+ //extfunc->glViewport(0, 0, dst_w, dst_h);
//extfunc->glOrtho(0.0f, (float)dst_w, 0.0f, (float)dst_h, -1.0, 1.0);
renderObject->release();
extfunc->glBindTexture(GL_TEXTURE_2D, 0);
- extfunc->glDisable(GL_TEXTURE_2D);
}
}
}
//redraw_required = true;
imgptr = p;
if(uVramTextureID == NULL) {
- uVramTextureID = new QOpenGLTexture(*p);
- }
-
- {
+ uVramTextureID = new QOpenGLTexture(*p, QOpenGLTexture::DontGenerateMipMaps);
+ } else {
// Upload to main texture
extfunc->glBindTexture(GL_TEXTURE_2D, uVramTextureID->textureId());
extfunc->glTexSubImage2D(GL_TEXTURE_2D, 0,
- 0, 0,
- //screen_texture_width * 2,
- //screen_texture_height * 2,
- p->width(), p->height(),
- GL_BGRA, GL_UNSIGNED_BYTE, p->constBits());
+ 0, 0, p->width(), p->height(),
+ GL_RGBA, GL_UNSIGNED_BYTE,
+ p->bits());
extfunc->glBindTexture(GL_TEXTURE_2D, 0);
}
#if 0
} else
#endif
{
+#if 0
renderToTmpFrameBuffer_nPass(uVramTextureID->textureId(),
screen_texture_width,
screen_texture_height,
std_pass->getViewportHeight(),
use_chromakey);
- //std_pass->bind();
+ std_pass->bind();
uTmpTextureID = std_pass->getTexture();
- //std_pass->release();
+ std_pass->release();
+#else
+ uTmpTextureID = uVramTextureID->textureId();
+#endif
}
crt_flag = true;
}
int ii;
if(texid != 0) {
- extfunc->glEnable(GL_TEXTURE_2D);
vp->bind();
bp->bind();
prg->bind();
extfunc->glViewport(0, 0, p_wid->width(), p_wid->height());
- //extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
+ QMatrix4x4 ortho;
+ ortho.ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
+
extfunc->glActiveTexture(GL_TEXTURE0);
extfunc->glBindTexture(GL_TEXTURE_2D, texid);
+
+ extfunc->glClearColor(1.0, 1.0, 1.0, 1.0);
if(!f_smoosing) {
extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
prg->setUniformValue("a_texture", 0);
+ prg->setUniformValue("v_ortho", ortho);
ii = prg->uniformLocation("color");
if(ii >= 0) {
}
}
+ ii = prg->uniformLocation("swap_byteorder");
+ if(ii >= 0) {
+ prg->setUniformValue(ii, (swap_byteorder) ? GL_TRUE : GL_FALSE);
+ }
prg->enableAttributeArray("texcoord");
prg->enableAttributeArray("vertex");
int vertex_loc = prg->attributeLocation("vertex");
int texcoord_loc = prg->attributeLocation("texcoord");
+
+ //prg->enableAttributeArray(vertex_loc);
+ prg->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3, sizeof(VertexTexCoord_t));
+ prg->setAttributeBuffer(texcoord_loc, GL_FLOAT, 3 * sizeof(GLfloat), 2, sizeof(VertexTexCoord_t));
extfunc->glEnableVertexAttribArray(vertex_loc);
extfunc->glEnableVertexAttribArray(texcoord_loc);
- extfunc->glEnable(GL_VERTEX_ARRAY);
- extfunc->glDrawArrays(GL_POLYGON, 0, 4);
+
+ extfunc->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
bp->release();
vp->release();
prg->release();
extfunc->glBindTexture(GL_TEXTURE_2D, 0);
- extfunc->glDisable(GL_TEXTURE_2D);
- }
+ }
else {
- extfunc->glDisable(GL_TEXTURE_2D);
vp->bind();
bp->bind();
prg->bind();
extfunc->glViewport(0, 0, p_wid->width(), p_wid->height());
+ QMatrix4x4 ortho;
+ ortho.ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
//extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
ii = prg->uniformLocation("color");
if(ii >= 0) {
} else {
prg->setUniformValue("rotate", GL_FALSE);
}
+ prg->setUniformValue("v_ortho", ortho);
if(do_chromakey) {
ii = prg->uniformLocation("chromakey");
prg->enableAttributeArray("vertex");
int vertex_loc = prg->attributeLocation("vertex");
extfunc->glEnableVertexAttribArray(vertex_loc);
- extfunc->glEnable(GL_VERTEX_ARRAY);
- extfunc->glDrawArrays(GL_POLYGON, 0, 4);
- extfunc->glDisable(GL_VERTEX_ARRAY);
+ extfunc->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
bp->release();
vp->release();
prg->release();
extfunc->glBindTexture(GL_TEXTURE_2D, 0);
- extfunc->glDisable(GL_TEXTURE_2D);
}
}
void GLDraw_ES_2::drawButtonsMain(int num, bool f_smoosing)
{
- GLuint texid = uButtonTextureID[num];
+ GLuint texid = uButtonTextureID[num]->textureId();
QOpenGLBuffer *bp = buffer_button_vertex[num];
QOpenGLShaderProgram *prg = button_shader;
QOpenGLVertexArrayObject *vp = vertex_button[num];
prg->setAttributeBuffer(texcoord_loc, GL_FLOAT, 3 * sizeof(GLfloat), 2, sizeof(VertexTexCoord_t));
prg->enableAttributeArray(vertex_loc);
prg->enableAttributeArray(texcoord_loc);
- extfunc->glEnableVertexAttribArray(vertex_loc);
- extfunc->glEnableVertexAttribArray(texcoord_loc);
- extfunc->glEnable(GL_VERTEX_ARRAY);
- extfunc->glDrawArrays(GL_POLYGON, 0, 4);
+ //extfunc->glEnableVertexAttribArray(vertex_loc);
+ //extfunc->glEnableVertexAttribArray(texcoord_loc);
+ extfunc->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
bp->release();
vp->release();
prg->release();
extfunc->glBindTexture(GL_TEXTURE_2D, 0);
- extfunc->glDisable(GL_TEXTURE_2D);
return;
}
}
if(using_flags->is_use_one_board_computer()) {
extfunc->glDisable(GL_BLEND);
drawMain(bitmap_block,
- uBitmapTextureID,
+ uBitmapTextureID->textureId(),
color, smoosing);
}
}
int ii;
{
- extfunc->glDisable(GL_TEXTURE_2D);
extfunc->glEnable(GL_BLEND);
extfunc->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
vp->bind();
extfunc->glVertexAttribPointer(vertex_loc, 3, GL_FLOAT, GL_FALSE, sizeof(VertexTexCoord_t), 0);
extfunc->glEnableVertexAttribArray(vertex_loc);
- extfunc->glEnable(GL_VERTEX_ARRAY);
- extfunc->glDrawArrays(GL_POLYGON, 0, 4);
+ extfunc->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
bp->release();
vp->release();
prg->release();
- extfunc->glDisable(GL_TEXTURE_2D);
extfunc->glDisable(GL_BLEND);
}
}
if(major != 0) {
drawMain(osd_pass->getShader(), osd_pass_vao[i], osd_pass_vbuffer[i],
- icon_texid[major][minor],
+ icon_texid[major][minor]->textureId(),
((osd_led_status & bit) != 0) ? color_on : color_off,
false, false, QVector3D(0.0, 0.0, 0.0));
}
void GLDraw_ES_2::paintGL(void)
{
//p_wid->makeCurrent();
-
+
// if(crt_flag || redraw_required) { //return;
if(emu_launched) {
crt_flag = false;
redraw_required = false;
extfunc->glViewport(0, 0, p_wid->width(), p_wid->height());
//extfunc->glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
-
+
extfunc->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
extfunc->glEnable(GL_DEPTH_TEST);
extfunc->glDisable(GL_BLEND);
if(imgptr != NULL) {
p_wid->makeCurrent();
if(uVramTextureID == NULL) {
- uVramTextureID = new QOpenGLTexture(*imgptr);
+ uVramTextureID = new QOpenGLTexture(*imgptr, QOpenGLTexture::DontGenerateMipMaps);
}
if(using_flags->is_use_one_board_computer() || (using_flags->get_max_button() > 0)) {
uploadMainTexture(imgptr, true);
vertex[0].y = ybase;
vertex[0].z = zbase;
vertex[0].s = 0.0f;
- vertex[0].t = 1.0f;
+ vertex[0].t = 0.0f;
vertex[1].x = xbase + (48.0f / 640.0f);
vertex[1].y = ybase;
vertex[1].z = zbase;
vertex[1].s = 1.0f;
- vertex[1].t = 1.0f;
+ vertex[1].t = 0.0f;
vertex[2].x = xbase + (48.0f / 640.0f);
vertex[2].y = ybase - (48.0f / 400.0f);
vertex[2].z = zbase;
vertex[2].s = 1.0f;
- vertex[2].t = 0.0f;
+ vertex[2].t = 1.0f;
vertex[3].x = xbase;
vertex[3].y = ybase - (48.0f / 400.0f);
vertex[3].z = zbase;
vertex[3].s = 0.0f;
- vertex[3].t = 0.0f;
+ vertex[3].t = 1.0f;
setNormalVAO(osd_pass->getShader(), osd_pass_vao[xbit],
osd_pass_vbuffer[xbit],
}
if(p != NULL) {
- if(uVramTextureID != NULL) delete uVramTextureID;
- uVramTextureID = new QOpenGLTexture(*p);
+ if(uVramTextureID != NULL) {
+ delete uVramTextureID;
+ }
+ uVramTextureID = new QOpenGLTexture(*p, QOpenGLTexture::DontGenerateMipMaps);
}
vertexFormat[0].x = -1.0f;
vertexFormat[0].y = -1.0f;
+++ /dev/null
-/*
- * qt_glutil_gl2_0.h
- * (c) 2016 K.Ohta <whatisthis.sowhat@gmail.com>
- * License: GPLv2.
- * Renderer with OpenGL v2.0 .
- * History:
- * Jan 21, 2016 : Initial.
- */
-
-#ifndef _QT_COMMON_GLUTIL_2_0_H
-#define _QT_COMMON_GLUTIL_2_0_H
-
-#include <QWidget>
-#include <QString>
-#include <QList>
-
-#include "common.h"
-#include "qt_glpack.h"
-
-QT_BEGIN_NAMESPACE
-class EMU;
-class QEvent;
-class GLDrawClass;
-class QOpenGLFramebufferObject;
-class QOpenGLFramebufferObjectFormat;
-class USING_FLAGS;
-class CSP_Logger;
-class QOpenGLFunctions_2_0;
-class QOpenGLBuffer;
-class QOpenGLVertexArrayObject;
-class QOpenGLShaderProgram;
-
-class DLL_PREFIX GLDraw_2_0 : public QObject
-{
- Q_OBJECT
-private:
- QOpenGLFunctions_2_0 *extfunc_2;
-protected:
- GLDrawClass *p_wid;
- USING_FLAGS *using_flags;
- QImage *imgptr;
- CSP_Logger *csp_logger;
- bool smoosing;
- bool gl_grid_horiz;
- bool gl_grid_vert;
-
- int vert_lines;
- int horiz_pixels;
- GLfloat *glVertGrids;
- GLfloat *glHorizGrids;
- float screen_multiply;
-
- float screen_width;
- float screen_height;
-
- int screen_texture_width;
- int screen_texture_width_old;
- int screen_texture_height;
- int screen_texture_height_old;
-
- GLuint icon_texid[9][8];
-
- int rec_count;
- int rec_width;
- int rec_height;
-
- VertexTexCoord_t vertexFormat[4];
-
- QOpenGLShaderProgram *main_shader;
-
- QOpenGLVertexArrayObject *vertex_screen;
- QOpenGLBuffer *buffer_screen_vertex;
-
- VertexTexCoord_t vertexBitmap[4];
- QOpenGLShaderProgram *bitmap_shader;
- QOpenGLBuffer *buffer_bitmap_vertex;
- QOpenGLVertexArrayObject *vertex_bitmap;
- QOpenGLVertexArrayObject *vertex_button[128];
- QOpenGLBuffer *buffer_button_vertex[128];
- QOpenGLShaderProgram *button_shader;
- VertexTexCoord_t vertexOSD[32][4];
- QOpenGLVertexArrayObject *vertex_osd[32];
- QOpenGLBuffer *buffer_osd[32];
- QOpenGLShaderProgram *osd_shader;
-
- virtual void initButtons(void);
- virtual void initBitmapVertex(void);
- virtual void initBitmapVAO(void);
-
- GLuint uVramTextureID;
- GLuint uButtonTextureID[128];
- GLfloat fButtonX[128];
- GLfloat fButtonY[128];
- GLfloat fButtonWidth[128];
- GLfloat fButtonHeight[128];
- QVector<VertexTexCoord_t> *vertexButtons;
-
- QVector<QImage> ButtonImages;
- bool button_updated;
- void updateButtonTexture(void);
-
-
- GLfloat fBrightR;
- GLfloat fBrightG;
- GLfloat fBrightB;
- bool set_brightness;
- bool InitVideo;
- GLuint uBitmapTextureID;
- bool bitmap_uploaded;
- virtual void setNormalVAO(QOpenGLShaderProgram *prg, QOpenGLVertexArrayObject *vp,
- QOpenGLBuffer *bp, VertexTexCoord_t *tp, int size = 4);
-
- virtual void resizeGL_Screen(void);
- virtual void drawGridsHorizonal(void);
- virtual void drawGridsVertical(void);
- void resizeGL_SetVertexs(void);
-
- void drawGridsMain(GLfloat *tp,
- int number,
- GLfloat lineWidth = 0.2f,
- QVector4D color = QVector4D(0.0f, 0.0f, 0.0f, 1.0f));
- void drawButtons();
- bool button_drawn;
- void drawBitmapTexture(void);
- bool crt_flag;
- bool redraw_required;
-
- virtual void drawOsdLeds();
- virtual void drawOsdIcons();
- virtual void set_osd_vertex(int xbit);
-
- QOpenGLFramebufferObject *offscreen_frame_buffer;
- QOpenGLFramebufferObjectFormat *offscreen_frame_buffer_format;
- QImage offscreen_image;
- GLint texture_max_size;
-
- bool low_resolution_screen;
- bool emu_launched;
-
- uint32_t osd_led_status;
- uint32_t osd_led_status_bak;
- int osd_led_bit_width;
- bool osd_onoff;
-public:
- GLDraw_2_0(GLDrawClass *parent, USING_FLAGS *p, CSP_Logger *logger, EMU *emu = 0);
- ~GLDraw_2_0();
-
- virtual void initGLObjects();
- virtual void initFBO(void);
- virtual void initLocalGLObjects(void);
- virtual void initOsdObjects(void);
-
- virtual void uploadMainTexture(QImage *p, bool chromakey);
-
- virtual void drawScreenTexture(void);
- void drawGrids(void);
- void uploadBitmapTexture(QImage *p);
-
- virtual void drawMain(QOpenGLShaderProgram *prg, QOpenGLVertexArrayObject *vp,
- QOpenGLBuffer *bp,
- VertexTexCoord_t *vertex_data,
- GLuint texid,
- QVector4D color, bool f_smoosing,
- bool do_chromakey = false,
- QVector3D chromakey = QVector3D(0.0f, 0.0f, 0.0f));
- virtual void doSetGridsHorizonal(int lines, bool force);
- virtual void doSetGridsVertical(int pixels, bool force);
-public slots:
- virtual void setBrightness(GLfloat r, GLfloat g, GLfloat b);
- virtual void do_set_texture_size(QImage *p, int w, int h);
- virtual void do_set_horiz_lines(int lines);
- virtual void do_set_screen_multiply(float mul);
- virtual void uploadIconTexture(QPixmap *p, int icon_type, int localnum);
-
- void initializeGL();
- virtual void paintGL();
- virtual void resizeGL(int width, int height);
-
- void setImgPtr(QImage *p);
- void setSmoosing(bool);
- void setDrawGLGridVert(bool);
- void setDrawGLGridHoriz(bool);
- void setVirtualVramSize(int ,int);
- void setChangeBrightness(bool);
- void updateBitmap(QImage *);
- void paintGL_OffScreen(int count, int w, int h);
- void set_emu_launched(void);
- void do_set_display_osd(bool onoff);
- void do_display_osd_leds(int lednum, bool onoff);
- void do_set_led_width(int bitwidth);
-signals:
- int sig_push_image_to_movie(int, int, int, QImage *);
-};
-QT_END_NAMESPACE
-
-#endif // _QT_COMMON_GLUTIL_2_0_H