OSDN Git Service

[Draw][Qt][OpenGL] Screen/Background/Button: Draw with GL Shader.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 4 Nov 2015 17:53:24 +0000 (02:53 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 4 Nov 2015 17:53:24 +0000 (02:53 +0900)
source/src/emu.h
source/src/qt/common/chromakey_fragment_shader.glsl [new file with mode: 0644]
source/src/qt/common/fragment_shader.glsl
source/src/qt/common/grids_fragment_shader.glsl
source/src/qt/common/grids_vertex_shader.glsl
source/src/qt/common/normal_fragment_shader.glsl [new file with mode: 0644]
source/src/qt/common/qrc/shaders.qrc
source/src/qt/common/qt_gldraw.cpp
source/src/qt/common/qt_gldraw.h
source/src/qt/common/qt_glutil.cpp
source/src/qt/common/vertex_shader.glsl

index 4650707..bc26982 100644 (file)
@@ -79,7 +79,7 @@
 #include <QSemaphore>
 #include <QMutex>
 #include <QThread>
-//#include "qt_input.h"
+#include "qt_input.h"
 #endif
 
 #if defined(_USE_AGAR) || defined(_USE_QT)
diff --git a/source/src/qt/common/chromakey_fragment_shader.glsl b/source/src/qt/common/chromakey_fragment_shader.glsl
new file mode 100644 (file)
index 0000000..41b8358
--- /dev/null
@@ -0,0 +1,30 @@
+#ifdef GL_ES
+ precision mediump float;
+#endif 
+
+varying vec2 v_texcoord;
+uniform vec4 color;
+uniform vec3 chromakey;
+
+uniform sampler2D a_texture;
+
+// This is from sample of Qt5 , see http://doc.qt.io/qt-5/qtopengl-cube-example.html .
+void main()
+{
+       // Set fragment color from texture
+       vec4 pixel_t = texture2D(a_texture, v_texcoord );
+       vec4 pixel_r;
+       vec4 c = vec4(chromakey, 1.0);
+       pixel_r.b = pixel_t.r;
+       pixel_r.r = pixel_t.b;
+       pixel_r.g = pixel_t.g;
+       pixel_r.a = 1.0;
+    
+       if(pixel_r != c) { // Chromakey;
+               pixel_r.a = pixel_t.a;
+       } else {
+               pixel_r.a = 0.0;
+       }
+       pixel_r = pixel_r * color;
+               gl_FragColor = pixel_r;
+}
index 3fe248d..0677d43 100644 (file)
@@ -1,3 +1,7 @@
+#ifdef GL_ES
+ precision mediump float;
+#endif 
+
 varying vec2 v_texcoord;
 uniform vec4 color;
 
@@ -13,5 +17,6 @@ void main()
     pixel_r.b = pixel_t.r;
     pixel_r.r = pixel_t.b;
     pixel_r.g = pixel_t.g;
+    
     gl_FragColor = pixel_r;
 }
index 70bc98d..946dbb9 100644 (file)
@@ -1,8 +1,13 @@
+#ifdef GL_ES
+ precision mediump float;
+#endif 
+
 uniform vec4 color; // Note: BRGA.
 
 // This is from sample of Qt5 , see http://doc.qt.io/qt-5/qtopengl-cube-example.html .
 void main()
 {
     // Set fragment color from texture
-    gl_FragColor = color;
+    //gl_FragColor = color;
+    gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
 }
index dcf0544..33cce98 100644 (file)
@@ -1,11 +1,15 @@
+#ifdef GL_ES
+ precision mediump float;
+#endif 
+
 attribute vec3 vertex;
 
 // This is from sample of Qt5 , see http://doc.qt.io/qt-5/qtopengl-cube-example.html .
 void main()
 {
     // Calculate vertex position in screen space
-    gl_Position = vec4(vertex, 1.0);
-
+    //gl_Position = vec4(vertex, 1.0);
+    gl_Position = gl_Vertex;
     // Pass texture coordinate to fragment shader
     // Value will be automatically interpolated to fragments inside polygon faces
 }
diff --git a/source/src/qt/common/normal_fragment_shader.glsl b/source/src/qt/common/normal_fragment_shader.glsl
new file mode 100644 (file)
index 0000000..e224919
--- /dev/null
@@ -0,0 +1,18 @@
+#ifdef GL_ES
+ precision mediump float;
+#endif 
+
+varying vec2 v_texcoord;
+uniform vec4 color;
+
+uniform sampler2D a_texture;
+
+// This is from sample of Qt5 , see http://doc.qt.io/qt-5/qtopengl-cube-example.html .
+void main()
+{
+    // Set fragment color from texture
+    vec4 pixel_t = texture2D(a_texture, v_texcoord );
+    vec4 pixel_r;
+    pixel_r = pixel_t * color;
+    gl_FragColor = pixel_r;
+}
index 8ea96ef..c520ad4 100644 (file)
@@ -1,6 +1,8 @@
 <!DOCTYPE RCC><RCC version="1.0">
 <qresource>
     <file alias="fragment_shader.glsl">../fragment_shader.glsl</file>
+    <file alias="normal_fragment_shader.glsl">../normal_fragment_shader.glsl</file>
+    <file alias="chromakey_fragment_shader.glsl">../chromakey_fragment_shader.glsl</file>
     <file alias="vertex_shader.glsl">../vertex_shader.glsl</file>
     <file alias="grids_fragment_shader.glsl">../grids_fragment_shader.glsl</file>
     <file alias="grids_vertex_shader.glsl">../grids_vertex_shader.glsl</file>
index 72a6c39..11e5cb3 100644 (file)
@@ -56,141 +56,78 @@ extern class GLCLDraw *cldraw;
 extern void InitContextCL(void);
 #endif
 
-void GLDrawClass::drawGridsHorizonal(void)
+void GLDrawClass::drawGridsMain(QOpenGLShaderProgram *prg,
+                                                               QOpenGLVertexArrayObject *vp,
+                                                               QOpenGLBuffer *bp,
+                                                               int number,
+                                                               GLfloat lineWidth,
+                                                               QVector4D color)
 {
-       //req_draw_grids_vert = false;
-       extfunc->glLineWidth(0.1f);
-       {
-               QVector4D c;
-               c = QVector4D(0.0, 0.0, 0.0, 1.0);
-               grids_shader->setUniformValue("color", c);
-       }
-       if(vertex_grid_horizonal->isCreated()) {
                extfunc->glDisable(GL_TEXTURE_2D);
-               vertex_grid_horizonal->bind();
+               extfunc->glDisable(GL_BLEND);
+               vp->bind();
+               bp->bind();
+               prg->bind();
+               extfunc->glActiveTexture(GL_TEXTURE0);
+               extfunc->glLineWidth(lineWidth);
+               prg->setUniformValue("color", color);
+               prg->enableAttributeArray("vertex");
                extfunc->glEnableVertexAttribArray(0);
                extfunc->glEnable(GL_VERTEX_ARRAY);
-               extfunc->glDrawArrays(GL_LINES, 0, vert_lines);
-               vertex_grid_horizonal->release();
-       }
+
+               extfunc->glDrawArrays(GL_LINES, 0, number * 2);
+               bp->release();
+               vp->release();
+               prg->release();
+}
+
+void GLDrawClass::drawGridsHorizonal(void)
+{
+       QVector4D c= QVector4D(1.0f, 1.0f, 1.0f, 1.0f);
+       drawGridsMain(grids_shader_horizonal,
+                                 vertex_grid_horizonal,
+                                 buffer_grid_horizonal,
+                                 vert_lines,
+                                 0.1f,
+                                 c);
 }
 
 void GLDrawClass::drawGridsVertical(void)
 {
-         //req_draw_grids_horiz = false;
-       extfunc->glLineWidth(0.5f);
-       {
-               QVector4D c;
-               c = QVector4D(0.0, 0.0, 0.0, 1.0);
-               grids_shader->setUniformValue("color", c);
-       }
-       if(vertex_grid_vertical->isCreated()) {
-               extfunc->glDisable(GL_TEXTURE_2D);
-               extfunc->glClear(GL_COLOR_BUFFER_BIT);
-               vertex_grid_vertical->bind();
-               extfunc->glEnable(GL_VERTEX_ARRAY);
-               extfunc->glDrawArrays(GL_LINES, 0, horiz_pixels);
-               vertex_grid_vertical->release();
-       }
+       QVector4D c= QVector4D(1.0f, 1.0f, 1.0f, 1.0f);
+       drawGridsMain(grids_shader_vertical,
+                                 vertex_grid_vertical,
+                                 buffer_grid_vertical,
+                                 horiz_pixels,
+                                 0.5f,
+                                 c);
 }
 
 
 void GLDrawClass::drawGrids(void)
 {
        extfunc->glDisable(GL_TEXTURE_2D);
-       extfunc->glEnable(GL_DEPTH_TEST);
        extfunc->glDisable(GL_BLEND);
-#if 0  
-       extfunc->glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
-#endif 
-       if(gl_grid_horiz && (vert_lines > 0) && (glHorizGrids != NULL) && req_draw_grids_vert) {
+       //if(gl_grid_horiz && (vert_lines > 0) && (glHorizGrids != NULL) && req_draw_grids_vert) {
                this->drawGridsHorizonal();
-       }
+       //}
 
        if(gl_grid_vert && (horiz_pixels > 0) && (glVertGrids != NULL) && req_draw_grids_horiz) {
                this->drawGridsVertical();
        }
 }
-void GLDrawClass::adjustBrightness()
-{
-
-       QVector4D c;
-       c = QVector4D(fBrightR, fBrightG, fBrightB, 1.0);
-       main_shader->setUniformValue("color", c);
-}
 
 #if defined(USE_BUTTON)
 void GLDrawClass::drawButtons()
 {
        int i;
-       GLfloat Vertexs[4][3];
-       updateButtonTexture();
-       extfunc->glEnable(GL_TEXTURE_2D);
-       extfunc->glEnable(GL_DEPTH_TEST);
+       //updateButtonTexture();
        for(i = 0; i < MAX_BUTTONS; i++) {
-               if(vertex_button[i]->isCreated()) {
-                       extfunc->glClear(GL_COLOR_BUFFER_BIT);
-                       extfunc->glEnable(GL_TEXTURE_2D);
-                       extfunc->glEnable(GL_DEPTH_TEST);
-                       //extfunc->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-                       vertex_button->bind();
-                       buffer_button_vertex[i]->bind();
-                       VertexTexCoord_t vt;
-                       vt[0].x =  fButtonX[i];
-                       vt[0].y =  fButtonY[i];
-                       vt[0].z =  -0.2f;
-                       vt[0].s = 0.0f;
-                       vt[0].t = 1.0f;
-               
-                       vt[1].x =  fButtonX[i] + fButtonWidth[i];
-                       vt[1].y =  fButtonY[i];
-                       vt[1].z =  -0.2f;
-                       vt[1].s = 1.0f;
-                       vt[1].t = 1.0f;
-                  
-                       vt[2].x =  fButtonX[i] + fButtonWidth[i];
-                       vt[2].y =  fButtonY[i] - fButtonHeight[i];
-                       vt[2].z =  -0.2f;
-                       vt[2].s = 1.0f;
-                       vt[2].t = 0.0f;
-                  
-                       vt[3].x =  fButtonX[i];
-                       vt[3].y =  fButtonY[i] - fButtonHeight[i];
-                       vt[3].z =  -0.2f;
-                       vt[3].s = 0.0f;
-                       vt[3].t = 0.0f;
-                  
-                       buffer_bitmap_vertex->write(0, vt, 4 * sizeof(VertexTexCoord_t));
-                       bitmap_shader->bind();
-                       {
-                               QVector4D c;
-                               c = QVector4D(1.0, 1.0, 0.0, 1.0);
-                               button_shader->setUniformValue("color", c);
-                       }
-                       extfunc->glActiveTexture(GL_TEXTURE0);
-# if defined(_USE_GLAPI_QT5_4)
-                       uButtonTextureID[i]->bind();
-# else
-                       extfunc->glBindTexture(GL_TEXTURE_2D, uButtonTextureID[i]);
-# endif
-                       //smoosing = config.use_opengl_filters;
-                       extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-                       extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
-                       button_shader->setUniformValue("a_texture", 0);
-                       button_shader->enableAttributeArray("texcoord");
-                       button_shader->enableAttributeArray("vertex");
-                       extfunc->glEnableVertexAttribArray(0);
-                       extfunc->glEnableVertexAttribArray(1);
-                       extfunc->glEnable(GL_VERTEX_ARRAY);
-                       
-                       extfunc->glDrawArrays(GL_POLYGON, 0, 4);
-                       buffer_button_vertex[i]->release();
-                       vertex_button->release();
-               
-                       button_shader->release();
-                       extfunc->glBindTexture(GL_TEXTURE_2D, 0);
-                       extfunc->glDisable(GL_TEXTURE_2D);
-               }
+               QVector4D c;
+               c = QVector4D(1.0, 1.0, 1.0, 1.0);
+               drawMain(button_shader[i], vertex_button[i],
+                                buffer_button_vertex[i], uButtonTextureID[i],
+                                c, false);
        }
 }
 #endif
@@ -205,21 +142,6 @@ void GLDrawClass::drawBitmapTexture(void)
 
                extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
                extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-#if 0          
-               extfunc->glBegin(GL_POLYGON);
-               extfunc->glTexCoord2f(TexCoords[0][0], TexCoords[0][1]);
-               extfunc->glVertex3f(BitmapVertexs[0][0], BitmapVertexs[0][1], BitmapVertexs[0][2]);
-       
-               extfunc->glTexCoord2f(TexCoords[1][0], TexCoords[1][1]);
-               extfunc->glVertex3f(BitmapVertexs[1][0], BitmapVertexs[1][1], BitmapVertexs[1][2]);
-        
-               extfunc->glTexCoord2f(TexCoords[2][0], TexCoords[2][1]);
-               extfunc->glVertex3f(BitmapVertexs[2][0], BitmapVertexs[2][1], BitmapVertexs[2][2]);
-               
-               extfunc->glTexCoord2f(TexCoords[3][0], TexCoords[3][1]);
-               extfunc->glVertex3f(BitmapVertexs[3][0], BitmapVertexs[3][1], BitmapVertexs[3][2]);
-               extfunc->glEnd();
-#else
                {
                        QVector4D c;
                        c = QVector4D(1.0, 1.0, 1.0, 1.0);
@@ -233,7 +155,6 @@ void GLDrawClass::drawBitmapTexture(void)
                        extfunc->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
                        vertex_bitmap->release();
                }
-#endif         
                uBitmapTextureID->release();
        }
        extfunc->glDisable(GL_TEXTURE_2D);
@@ -254,9 +175,6 @@ void GLDrawClass::drawScreenTexture(void)
                uVramTextureID->bind();
 #if 1
                main_shader->bind();
-               extfunc->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-               main_shader->setUniformValue("texture", 0);
-               //main_shader->setUniformValue("v_texcoord", *texture_texcoord);
 #endif         
                if(!smoosing) {
                        extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -274,6 +192,10 @@ void GLDrawClass::drawScreenTexture(void)
                        main_shader->setAttributeArray(vertex_loc, ScreenVertexs, 4);
                        
                        int texcoord_loc = main_shader->attributeLocation("a_texcoord");
+#if defined(USE_BITMAP) || defined(USE_BUTTON)
+                       QVector3D ch = QVector3D(0.0f, 0.0f, 0.0f);
+                       main_shader->setUniformValue("chromakey", ch);
+#endif                 
                        main_shader->enableAttributeArray(texcoord_loc);
                        main_shader->setAttributeArray(texcoord_loc, TexCoords, 4);
                
@@ -291,42 +213,63 @@ void GLDrawClass::drawScreenTexture(void)
        }
 }
 #else // Not _GLAPI_QT_5_4
-# ifdef USE_BITMAP
-void GLDrawClass::drawBitmapTexture(void)
+void GLDrawClass::drawMain(QOpenGLShaderProgram *prg,
+                                                  QOpenGLVertexArrayObject *vp,
+                                                  QOpenGLBuffer *bp,
+                                                  GLuint texid,
+                                                  QVector4D color,
+                                                  bool f_smoosing,
+                                                  bool use_chromakey,
+                                                  QVector3D chromakey)
+                                                  
 {
-       if(uBitmapTextureID != 0) {
+       if(texid != 0) {
                extfunc->glEnable(GL_TEXTURE_2D);
-               extfunc->glEnable(GL_DEPTH_TEST);
-               extfunc->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-               vertex_bitmap->bind();
-               buffer_bitmap_vertex->bind();
-               bitmap_shader->bind();
-               {
-                       QVector4D c;
-                       c = QVector4D(1.0, 1.0, 0.0, 1.0);
-                       bitmap_shader->setUniformValue("color", c);
-               }
+               vp->bind();
+               bp->bind();
+               prg->bind();
                extfunc->glActiveTexture(GL_TEXTURE0);
-               extfunc->glBindTexture(GL_TEXTURE_2D, uBitmapTextureID);
-               //smoosing = config.use_opengl_filters;
-               extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-               extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
-               bitmap_shader->setUniformValue("a_texture", 0);
-               bitmap_shader->enableAttributeArray("texcoord");
-               bitmap_shader->enableAttributeArray("vertex");
+               extfunc->glBindTexture(GL_TEXTURE_2D, texid);
+               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_NEAREST_MIPMAP_LINEAR);
+               } else {
+                       extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+                       extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+               }
+               prg->setUniformValue("a_texture", 0);
+               prg->setUniformValue("color", color);
+#if defined(USE_BITMAP) || defined(USE_BUTTON)
+               if(use_chromakey) {
+                       main_shader->setUniformValue("chromakey", chromakey);
+               }
+#endif                 
+               prg->enableAttributeArray("texcoord");
+               prg->enableAttributeArray("vertex");
                extfunc->glEnableVertexAttribArray(0);
                extfunc->glEnableVertexAttribArray(1);
                extfunc->glEnable(GL_VERTEX_ARRAY);
 
                extfunc->glDrawArrays(GL_POLYGON, 0, 4);
-               buffer_bitmap_vertex->release();
-               vertex_bitmap->release();
+               bp->release();
+               vp->release();
                
-               bitmap_shader->release();
+               prg->release();
                extfunc->glBindTexture(GL_TEXTURE_2D, 0);
                extfunc->glDisable(GL_TEXTURE_2D);
        }
 }
+
+# ifdef USE_BITMAP
+void GLDrawClass::drawBitmapTexture(void)
+{
+       QVector4D c;
+       c = QVector4D(1.0, 1.0, 1.0, 1.0);
+       drawMain(bitmap_shader, vertex_bitmap,
+                        buffer_bitmap_vertex, uBitmapTextureID,
+                        c, false);
+}
 # endif
 
 
@@ -341,40 +284,30 @@ void GLDrawClass::drawScreenTexture(void)
        extfunc->glDisable(GL_BLEND);
 #endif
        
-       if(uVramTextureID != 0) {
-               extfunc->glEnable(GL_TEXTURE_2D);
-               extfunc->glEnable(GL_DEPTH_TEST);
-#ifndef USE_BITMAP        
-               extfunc->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-#endif    
-               vertex_screen->bind();
-               buffer_screen_vertex->bind();
-               main_shader->bind();
-               extfunc->glActiveTexture(GL_TEXTURE0);
-               extfunc->glBindTexture(GL_TEXTURE_2D, uVramTextureID);
-               smoosing = config.use_opengl_filters;
-               if(!smoosing) {
-                       extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-                       extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
-               } else {
-                       extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-                       extfunc->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
-               }
-               main_shader->setUniformValue("a_texture", 0);
-               main_shader->enableAttributeArray("texcoord");
-               main_shader->enableAttributeArray("vertex");
-               extfunc->glEnableVertexAttribArray(0);
-               extfunc->glEnableVertexAttribArray(1);
-               extfunc->glEnable(GL_VERTEX_ARRAY);
-
-               extfunc->glDrawArrays(GL_POLYGON, 0, 4);
-               buffer_screen_vertex->release();
-               vertex_screen->release();
-               
-               main_shader->release();
-               extfunc->glBindTexture(GL_TEXTURE_2D, 0);
-               extfunc->glDisable(GL_TEXTURE_2D);
+       QVector4D color;
+       if(set_brightness) {
+               color = QVector4D(fBrightR, fBrightG, fBrightB, 1.0);
+       } else {
+               color = QVector4D(1.0, 1.0, 1.0, 1.0);
+       }                       
+#if defined(USE_BITMAP) || defined(USE_BUTTON)
+       {
+               QVector3D ch = QVector3D(0.0f, 0.0f, 0.0f);
+               drawMain(main_shader, vertex_screen,
+                                buffer_screen_vertex, uVramTextureID,
+                                color, smoosing, true, ch);
        }
+#else
+       {
+               main_shader->setUniformValue("color", color);
+               drawMain(main_shader, vertex_screen,
+                                buffer_screen_vertex, uVramTextureID,
+                                color, smoosing);
+       }               
+#endif                 
+#ifdef USE_BITMAP
+       extfunc->glDisable(GL_BLEND);
+#endif 
 }
 #endif
 
@@ -399,7 +332,6 @@ void GLDrawClass::drawUpdateTexture(QImage *p)
                } else {
                        uVramTextureID = this->bindTexture(*p);
                }
-          
 #endif
        }
 //#ifdef _USE_OPENCL
@@ -520,8 +452,8 @@ void GLDrawClass::resizeGL(int width, int height)
                                glHorizGrids[i * 6 + 3] = +screen_width; // XEnd
                                glHorizGrids[i * 6 + 1] = yf; // YBegin
                                glHorizGrids[i * 6 + 4] = yf; // YEnd
-                               glHorizGrids[i * 6 + 2] = 0.1f; // ZBegin
-                               glHorizGrids[i * 6 + 5] = 0.1f; // ZEnd
+                               glHorizGrids[i * 6 + 2] = -1.0f; // ZBegin
+                               glHorizGrids[i * 6 + 5] = -1.0f; // ZEnd
                                yf = yf + delta;
                        }
                }
@@ -529,10 +461,16 @@ void GLDrawClass::resizeGL(int width, int height)
                        vertex_grid_horizonal->bind();
                        buffer_grid_horizonal->bind();
                        buffer_grid_horizonal->write(0, glHorizGrids, (vert_lines + 1) * 6 * sizeof(GLfloat));
-                       //extfunc->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
-                       extfunc->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), 0);
+       
+                       grids_shader_horizonal->bind();
+                       int vertex_loc = grids_shader_horizonal->attributeLocation("vertex");
+                       grids_shader_horizonal->setAttributeBuffer(0, GL_FLOAT, 0, 3);
+                       extfunc->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
+                       grids_shader_horizonal->release();
+
                        buffer_grid_horizonal->release();
                        vertex_grid_horizonal->release();
+                       grids_shader_horizonal->enableAttributeArray(vertex_loc);
                }
                xf = -screen_width; 
                delta = (2.0f * screen_width) / (float)horiz_pixels;
@@ -544,16 +482,22 @@ void GLDrawClass::resizeGL(int width, int height)
                                glVertGrids[i * 6 + 3] = xf; // XEnd
                                glVertGrids[i * 6 + 1] = -screen_height; // YBegin
                                glVertGrids[i * 6 + 4] =  screen_height; // YEnd
-                               glVertGrids[i * 6 + 2] = 0.1f; // ZBegin
-                               glVertGrids[i * 6 + 5] = 0.1f; // ZEnd
+                               glVertGrids[i * 6 + 2] = -0.1f; // ZBegin
+                               glVertGrids[i * 6 + 5] = -0.1f; // ZEnd
                                xf = xf + delta;
                        }
                        if(vertex_grid_vertical->isCreated()) {
                                vertex_grid_vertical->bind();
                                buffer_grid_vertical->bind();
-                               buffer_grid_vertical->write(0, glVertGrids, (horiz_pixels + 1) * 6 * sizeof(GLfloat));
-                               //extfunc->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
-                               extfunc->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), 0);
+                               buffer_grid_vertical->write(0, glVertGrids, (horiz_pixels + 1)* 6 * sizeof(GLfloat));
+
+                               grids_shader_vertical->bind();
+                               int vertex_loc = grids_shader_vertical->attributeLocation("vertex");
+                               grids_shader_vertical->setAttributeBuffer(0, GL_FLOAT, 0, 3);
+                               extfunc->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
+                               grids_shader_vertical->release();
+                               
+                               extfunc->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
                                buffer_grid_vertical->release();
                                vertex_grid_vertical->release();
                        }
@@ -572,13 +516,9 @@ void GLDrawClass::resizeGL(int width, int height)
                vertexFormat[3].x = -screen_width;
                vertexFormat[3].y = +screen_height;
           
-               vertex_screen->bind();
-               buffer_screen_vertex->bind();
-               buffer_screen_vertex->write(0, vertexFormat, sizeof(vertexFormat));
-               //extfunc->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
-               extfunc->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0);
-               buffer_screen_vertex->release();
-               vertex_screen->release();
+               setNormalVAO(main_shader, vertex_screen,
+                                        buffer_screen_vertex,
+                                        vertexFormat, 4);
        }
 
        
@@ -596,16 +536,47 @@ void GLDrawClass::resizeGL(int width, int height)
                vertexBitmap[3].x = -screen_width;
                vertexBitmap[3].y = +screen_height;
           
-               vertex_bitmap->bind();
-               buffer_bitmap_vertex->bind();
-               buffer_bitmap_vertex->write(0, vertexFormat, sizeof(vertexFormat));
-               //extfunc->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
-               extfunc->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0);
-               buffer_bitmap_vertex->release();
-               vertex_bitmap->release();
+               setNormalVAO(bitmap_shader, vertex_bitmap,
+                                        buffer_bitmap_vertex,
+                                        vertexBitmap, 4);
        }
 #endif
-       
+#if defined(USE_BUTTON)
+       updateButtonTexture();
+       for(int i = 0; i < MAX_BUTTONS; i++) {
+               fButtonX[i] = -1.0 + (float)(buttons[i].x * 2) / (float)SCREEN_WIDTH;
+               fButtonY[i] = 1.0 - (float)(buttons[i].y * 2) / (float)SCREEN_HEIGHT;
+               fButtonWidth[i] = (float)(buttons[i].width * 2) / (float)SCREEN_WIDTH;
+               fButtonHeight[i] = (float)(buttons[i].height * 2) / (float)SCREEN_HEIGHT;
+               VertexTexCoord_t vt[4];
+
+               vt[0] = vertexButtons->value(i * 4);
+               vt[1] = vertexButtons->value(i * 4 + 1);
+               vt[2] = vertexButtons->value(i * 4 + 2);
+               vt[3] = vertexButtons->value(i * 4 + 3);
+               
+               vt[0].x =  fButtonX[i];
+               vt[0].y =  fButtonY[i];
+                                          
+               vt[1].x =  fButtonX[i] + fButtonWidth[i];
+               vt[1].y =  fButtonY[i];
+               
+               vt[2].x =  fButtonX[i] + fButtonWidth[i];
+               vt[2].y =  fButtonY[i] - fButtonHeight[i];
+                                               
+               vt[3].x =  fButtonX[i];
+               vt[3].y =  fButtonY[i] - fButtonHeight[i];
+               
+               vertexButtons->replace(i * 4, vt[0]);
+               vertexButtons->replace(i * 4 + 1, vt[1]);
+               vertexButtons->replace(i * 4 + 2, vt[2]);
+               vertexButtons->replace(i * 4 + 3, vt[3]);
+               
+               setNormalVAO(button_shader[i], vertex_button[i],
+                                        buffer_button_vertex[i],
+                                        vt, 4);
+       }
+#endif 
        AGAR_DebugLog(AGAR_LOG_DEBUG, "ResizeGL: %dx%d", width , height);
        emit sig_resize_uibar(width, height);
 }
@@ -624,17 +595,8 @@ void GLDrawClass::paintGL(void)
                drawUpdateTexture(imgptr);
                crt_flag = false;
        }
-#if 0  
-       extfunc->glPushAttrib(GL_TEXTURE_BIT);
-       extfunc->glPushAttrib(GL_TRANSFORM_BIT);
-       extfunc->glPushAttrib(GL_ENABLE_BIT);
-#endif 
-#ifdef _USE_OPENCL
-       //    InitContextCL();   
-#endif
-
        extfunc->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-       extfunc->glEnable(GL_DEPTH_TEST);
+       extfunc->glDisable(GL_DEPTH_TEST);
        extfunc->glDisable(GL_BLEND);
 
 #ifdef USE_BITMAP
@@ -643,32 +605,17 @@ void GLDrawClass::paintGL(void)
 #ifdef USE_SCREEN_ROTATE   
        extfunc->glPushMatrix();
 #endif   
+#if defined(USE_BUTTON)
+       drawButtons();
+#endif 
        /*
         * VRAMの表示:テクスチャ貼った四角形
         */
        drawScreenTexture();
-       extfunc->glEnable(GL_DEPTH_TEST);
-       extfunc->glDisable(GL_BLEND);
-
-       if(set_brightness) {
-               adjustBrightness();
-       }
        drawGrids();
-#if defined(USE_BUTTON)
-       drawButtons();
-#endif 
 #ifdef USE_SCREEN_ROTATE   
        extfunc->glPopMatrix();
 #endif   
-       extfunc->glDisable(GL_DEPTH_TEST);
-#ifdef USE_OPENGL
-       //DrawOSDGL(glv);
-#endif
-#if 0  
-       extfunc->glPopAttrib();
-       extfunc->glPopAttrib();
-       extfunc->glPopAttrib();
-#endif 
        extfunc->glFlush();
 }
 
@@ -782,7 +729,6 @@ GLDrawClass::~GLDrawClass()
 # endif
        }
 #endif
-#if 1
        if(buffer_screen_vertex->isCreated()) buffer_screen_vertex->destroy();
        if(vertex_screen->isCreated()) vertex_screen->destroy();
        if(vertex_grid_vertical->isCreated()) vertex_grid_vertical->destroy();
@@ -795,7 +741,6 @@ GLDrawClass::~GLDrawClass()
                if(vertex_button[i]->isCreated()) vertex_button[i]->destroy();
        }
 # endif        
-#endif
        if(glVertGrids != NULL) free(glVertGrids);
        if(glHorizGrids != NULL) free(glHorizGrids);
        if(extfunc != NULL) delete extfunc;
index c6e315d..1a3701b 100644 (file)
@@ -41,7 +41,6 @@
 #include <QOpenGLVertexArrayObject>
 #include <QOpenGLShaderProgram>
 #include <QOpenGLBuffer>
-#include <QOpenGLFunctions_3_0>
 
 #include <QMatrix4x2>
 #include <QMatrix4x4>
@@ -112,7 +111,8 @@ class GLDrawClass: public QGLWidget
 #endif   
        VertexTexCoord_t vertexFormat[4];
        QOpenGLShaderProgram *main_shader;
-       QOpenGLShaderProgram *grids_shader;
+       QOpenGLShaderProgram *grids_shader_horizonal;
+       QOpenGLShaderProgram *grids_shader_vertical;
        QOpenGLVertexArrayObject *vertex_grid_horizonal;
        QOpenGLVertexArrayObject *vertex_grid_vertical;
        QOpenGLVertexArrayObject *vertex_screen;
@@ -123,12 +123,12 @@ class GLDrawClass: public QGLWidget
        VertexTexCoord_t vertexBitmap[4];
        QOpenGLShaderProgram *bitmap_shader;
        QOpenGLBuffer *buffer_bitmap_vertex;
-       QOpenGLBuffer *buffer_screen_vertex;
+       QOpenGLVertexArrayObject *vertex_bitmap;
 # endif
 # if defined(USE_BUTTON)
        QOpenGLVertexArrayObject *vertex_button[MAX_BUTTONS];
        QOpenGLBuffer *buffer_button_vertex[MAX_BUTTONS];
-       QOpenGLShaderProgram *button_shader;
+       QOpenGLShaderProgram *button_shader[MAX_BUTTONS];
 # endif        
 
  protected:
@@ -139,28 +139,39 @@ class GLDrawClass: public QGLWidget
        void keyPressEvent(QKeyEvent *event);
        void initializeGL();
        void paintGL();
+
+       void setNormalVAO(QOpenGLShaderProgram *prg, QOpenGLVertexArrayObject *vp,
+                                         QOpenGLBuffer *bp, VertexTexCoord_t *tp, int size = 4);
+       void drawMain(QOpenGLShaderProgram *prg, QOpenGLVertexArrayObject *vp,
+                                 QOpenGLBuffer *bp, GLuint texid,
+                                 QVector4D color,
+                                 bool f_smoosing = false, bool use_chromakey = false,
+                                 QVector3D chromakey = QVector3D(0.0f, 0.0f, 0.0f));
 #if defined(_USE_GLAPI_QT5_4)   
        QOpenGLTexture *uVramTextureID;
 #else
        GLuint uVramTextureID;
 #endif
 #if defined(USE_BUTTON)
-#if defined(_USE_GLAPI_QT5_4)   
+# if defined(_USE_GLAPI_QT5_4)   
        QOpenGLTexture *uButtonTextureID[MAX_BUTTONS];
-#else
+# else
        GLuint uButtonTextureID[MAX_BUTTONS];
-#endif
+# endif
        GLfloat fButtonX[MAX_BUTTONS];
        GLfloat fButtonY[MAX_BUTTONS];
        GLfloat fButtonWidth[MAX_BUTTONS];
        GLfloat fButtonHeight[MAX_BUTTONS];
+       QVector<VertexTexCoord_t> *vertexButtons;
+
        bool button_updated;
        void updateButtonTexture(void);
+       
 #endif
        GLfloat fBrightR;
        GLfloat fBrightG;
        GLfloat fBrightB;
-        bool set_brightness;
+       bool set_brightness;
 
        // Will move to OpenCL
        bool bInitCL;
@@ -193,11 +204,14 @@ class GLDrawClass: public QGLWidget
        bool QueryGLExtensions(const char *str);
        void InitGLExtensionVars(void);
        void InitContextCL(void);
-       void adjustBrightness();
        
        void drawUpdateTexture(QImage *p);
        void drawGridsHorizonal(void);
        void drawGridsVertical(void);
+       void drawGridsMain(QOpenGLShaderProgram *prg, QOpenGLVertexArrayObject *vp,
+                                          QOpenGLBuffer *bp, int number,
+                                          GLfloat lineWidth = 0.2f,
+                                          QVector4D color = QVector4D(0.0f, 0.0f, 0.0f, 1.0f));
        void drawScreenTexture(void);
        
 #if defined(USE_BUTTON)
index 70a4201..b51e0b7 100644 (file)
@@ -17,9 +17,6 @@
 
 //extern const char *cl_render;
 
-#ifdef _USE_OPENCL
-//class GLCLDraw *cldraw = NULL;
-#endif
 void GLDrawClass::update_screen(QImage *p)
 {
        //if(tick < (1000 / 75)) tick = 1000 / 75;
@@ -48,36 +45,6 @@ void GLDrawClass::initializeGL(void)
         */
        InitFBO(); // 拡張の有無を調べてからFBOを初期化する。
        InitGLExtensionVars();
-       glHorizGrids = (GLfloat *)malloc(sizeof(float) * (SCREEN_HEIGHT + 2) * 6);
-       if(glHorizGrids != NULL) {
-               yf = -1.0f;
-               delta = 2.0f / (float)SCREEN_HEIGHT;
-               yf = yf - delta * 0.75f;
-               for(i = 0; i < (SCREEN_HEIGHT + 1) ; i++) {
-                       glHorizGrids[i * 6]     = -1.0f; // XBegin
-                       glHorizGrids[i * 6 + 3] = +1.0f; // XEnd
-                       glHorizGrids[i * 6 + 1] = yf; // YBegin
-                       glHorizGrids[i * 6 + 4] = yf; // YEnd
-                       glHorizGrids[i * 6 + 2] = 0.1f; // ZBegin
-                       glHorizGrids[i * 6 + 5] = 0.1f; // ZEnd
-                       yf = yf + delta;
-               }
-       }
-       glVertGrids  = (GLfloat *)malloc(sizeof(float) * (SCREEN_WIDTH + 2) * 6);
-       if(glVertGrids != NULL) {
-               xf = -1.0f; 
-               delta = 2.0f / (float)SCREEN_WIDTH;
-               xf = xf - delta * 0.75f;
-               for(i = 0; i < (SCREEN_WIDTH + 1) ; i++) {
-                       glVertGrids[i * 6]     = xf; // XBegin
-                       glVertGrids[i * 6 + 3] = xf; // XEnd
-                       glVertGrids[i * 6 + 1] = -1.0f; // YBegin
-                       glVertGrids[i * 6 + 4] =  1.0f; // YEnd
-                       glVertGrids[i * 6 + 2] = 0.1f; // ZBegin
-                       glVertGrids[i * 6 + 5] = 0.1f; // ZEnd
-                       xf = xf + delta;
-               }
-       }
        
        // Init view
        extfunc->glClearColor(0.0, 0.0, 0.0, 1.0);
@@ -142,9 +109,40 @@ void GLDrawClass::InitGLExtensionVars(void)
        bCLGLInterop = false;
 }
 
-   
+
+void GLDrawClass::setNormalVAO(QOpenGLShaderProgram *prg,
+                                                          QOpenGLVertexArrayObject *vp,
+                                                          QOpenGLBuffer *bp,
+                                                          VertexTexCoord_t *tp,
+                                                          int size)
+{
+       int vertex_loc = prg->attributeLocation("vertex");
+       int texcoord_loc = prg->attributeLocation("texcoord");
+
+       vp->bind();
+       bp->bind();
+
+       bp->write(0, tp, sizeof(VertexTexCoord_t) * size);
+       prg->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3, sizeof(VertexTexCoord_t));
+       prg->setAttributeBuffer(texcoord_loc, GL_FLOAT, 3 * sizeof(GLfloat), 2, sizeof(VertexTexCoord_t));
+       bp->release();
+       vp->release();
+       prg->setUniformValue("a_texture", 0);
+                          
+       extfunc->glVertexAttribPointer(vertex_loc, 3, GL_FLOAT, GL_FALSE, sizeof(VertexTexCoord_t), 0); 
+       extfunc->glVertexAttribPointer(texcoord_loc, 2, GL_FLOAT, GL_FALSE, sizeof(VertexTexCoord_t), 
+                                                              (char *)NULL + 3 * sizeof(GLfloat)); 
+       prg->enableAttributeArray(vertex_loc);
+       prg->enableAttributeArray(texcoord_loc);
+}
+
+
+
 void GLDrawClass::InitFBO(void)
 {
+       int i;
+       GLfloat xf, yf, delta;
+       
        bGL_EXT_VERTEX_ARRAY = false;
 #if defined(_USE_GLAPI_QT5_4) || defined(_USE_GLAPI_QT5_1)
        extfunc = new QOpenGLFunctions;
@@ -156,41 +154,94 @@ void GLDrawClass::InitFBO(void)
        main_shader = new QOpenGLShaderProgram(this);
        if(main_shader != NULL) {
                main_shader->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/vertex_shader.glsl");
+#if defined(USE_BITMAP) || defined(USE_BUTTON)
+               main_shader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/chromakey_fragment_shader.glsl");
+#else
                main_shader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/fragment_shader.glsl");
+#endif         
                main_shader->link();
        }
-       grids_shader = new QOpenGLShaderProgram(this);
-       if(grids_shader != NULL) {
-               grids_shader->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/grids_vertex_shader.glsl");
-               grids_shader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/grids_fragment_shader.glsl");
-               grids_shader->link();
+       grids_shader_horizonal = new QOpenGLShaderProgram(this);
+       if(grids_shader_horizonal != NULL) {
+               grids_shader_horizonal->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/grids_vertex_shader.glsl");
+               grids_shader_horizonal->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/grids_fragment_shader.glsl");
+               grids_shader_horizonal->link();
+       }
+       grids_shader_vertical = new QOpenGLShaderProgram(this);
+       if(grids_shader_vertical != NULL) {
+               grids_shader_vertical->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/grids_vertex_shader.glsl");
+               grids_shader_vertical->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/grids_fragment_shader.glsl");
+               grids_shader_vertical->link();
        }
 
 # if defined(USE_BITMAP)
        bitmap_shader = new QOpenGLShaderProgram(this);
        if(bitmap_shader != NULL) {
                bitmap_shader->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/vertex_shader.glsl");
-               bitmap_shader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/fragment_shader.glsl");
+               bitmap_shader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/normal_fragment_shader.glsl");
                bitmap_shader->link();
        }
 # endif
 # if defined(USE_BUTTON)
-       button_shader = new QOpenGLShaderProgram(this);
-       if(button_shader != NULL) {
-               button_shader->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/vertex_shader.glsl");
-               button_shader->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/fragment_shader.glsl");
-               button_shader->link();
+       for(i = 0; i < MAX_BUTTONS; i++) {
+               button_shader[i] = new QOpenGLShaderProgram(this);
+               if(button_shader[i] != NULL) {
+                       button_shader[i]->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/vertex_shader.glsl");
+                       button_shader[i]->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/normal_fragment_shader.glsl");
+                       button_shader[i]->link();
+               }
        }
 # endif
+       glHorizGrids = (GLfloat *)malloc(sizeof(float) * (SCREEN_HEIGHT + 2) * 6);
+       if(glHorizGrids != NULL) {
+               yf = -1.0f;
+               delta = 2.0f / (float)SCREEN_HEIGHT;
+               yf = yf - delta * 0.75f;
+               for(i = 0; i < (SCREEN_HEIGHT + 1) ; i++) {
+                       glHorizGrids[i * 6]     = -1.0f; // XBegin
+                       glHorizGrids[i * 6 + 3] = +1.0f; // XEnd
+                       glHorizGrids[i * 6 + 1] = yf; // YBegin
+                       glHorizGrids[i * 6 + 4] = yf; // YEnd
+                       glHorizGrids[i * 6 + 2] = -1.0f; // ZBegin
+                       glHorizGrids[i * 6 + 5] = -1.0f; // ZEnd
+                       yf = yf + delta;
+               }
+       }
+       glVertGrids  = (GLfloat *)malloc(sizeof(float) * (SCREEN_WIDTH + 2) * 6);
+       if(glVertGrids != NULL) {
+               xf = -1.0f; 
+               delta = 2.0f / (float)SCREEN_WIDTH;
+               xf = xf - delta * 0.75f;
+               for(i = 0; i < (SCREEN_WIDTH + 1) ; i++) {
+                       glVertGrids[i * 6]     = xf; // XBegin
+                       glVertGrids[i * 6 + 3] = xf; // XEnd
+                       glVertGrids[i * 6 + 1] = -1.0f; // YBegin
+                       glVertGrids[i * 6 + 4] =  1.0f; // YEnd
+                       glVertGrids[i * 6 + 2] = -0.1f; // ZBegin
+                       glVertGrids[i * 6 + 5] = -0.1f; // ZEnd
+                       xf = xf + delta;
+               }
+       }
        if(extfunc) {
                buffer_grid_horizonal = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
                vertex_grid_horizonal = new QOpenGLVertexArrayObject;
-               QVector3D hg;
+
                if(vertex_grid_horizonal != NULL) {
                        if(vertex_grid_horizonal->create()) {
                                vertex_grid_horizonal->bind();
-                               buffer_grid_horizonal->allocate(SCREEN_HEIGHT * 6 * sizeof(GLfloat));
+                               buffer_grid_horizonal->bind();
+                               buffer_grid_horizonal->allocate((SCREEN_HEIGHT + 1)* 6 * sizeof(GLfloat));
+                               buffer_grid_horizonal->setUsagePattern(QOpenGLBuffer::StaticDraw);
+                               buffer_grid_horizonal->write(0, glHorizGrids, (vert_lines + 1)* 6 * sizeof(GLfloat));
+                               grids_shader_horizonal->bind();
+                               int vertex_loc = grids_shader_horizonal->attributeLocation("vertex");
+                               grids_shader_horizonal->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3);
+                               extfunc->glVertexAttribPointer(vertex_loc, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), 0);
+
+                               grids_shader_horizonal->release();
+                               buffer_grid_horizonal->release();
                                vertex_grid_horizonal->release();
+                               grids_shader_horizonal->enableAttributeArray(vertex_loc);
                        }
                }
                
@@ -199,16 +250,28 @@ void GLDrawClass::InitFBO(void)
                if(vertex_grid_vertical != NULL) {
                        if(vertex_grid_vertical->create()) {
                                vertex_grid_vertical->bind();
-                               buffer_grid_horizonal->allocate(SCREEN_WIDTH * 6 * sizeof(GLfloat));
+                               buffer_grid_vertical->bind();
+                               buffer_grid_vertical->allocate((SCREEN_WIDTH + 1)* 6 * sizeof(GLfloat));
+                               buffer_grid_vertical->setUsagePattern(QOpenGLBuffer::StaticDraw);
+                               buffer_grid_vertical->write(0, glHorizGrids, (horiz_pixels + 1)* 6 * sizeof(GLfloat));
+                               grids_shader_vertical->bind();
+                               int vertex_loc = grids_shader_vertical->attributeLocation("vertex");
+                               grids_shader_vertical->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3);
+                               extfunc->glVertexAttribPointer(vertex_loc, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), 0);
+
+                               grids_shader_vertical->release();
+                               buffer_grid_vertical->release();
                                vertex_grid_vertical->release();
+                               grids_shader_vertical->enableAttributeArray(vertex_loc);
                        }
                }
 # if defined(USE_BUTTON)
                {
+                       vertexButtons = new QVector<VertexTexCoord_t>;
                        int i;
-                       GLfloat Vertexs[4][3];
                        for(i = 0; i < MAX_BUTTONS; i++) {
                                buffer_button_vertex[i] = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
+                               buffer_button_vertex[i]->create();
                                fButtonX[i] = -1.0 + (float)(buttons[i].x * 2) / (float)SCREEN_WIDTH;
                                fButtonY[i] = 1.0 - (float)(buttons[i].y * 2) / (float)SCREEN_HEIGHT;
                                fButtonWidth[i] = (float)(buttons[i].width * 2) / (float)SCREEN_WIDTH;
@@ -217,54 +280,45 @@ void GLDrawClass::InitFBO(void)
                                vertex_button[i] = new QOpenGLVertexArrayObject;
                                if(vertex_button[i] != NULL) {
                                        if(vertex_button[i]->create()) {
-                                       VertexTexCoord_t vt;
-                                          vt[0].x =  fButtonX[i];
-                                          vt[0].y =  fButtonY[i];
-                                          vt[0].z =  -0.2f;
-                                          vt[0].s = 0.0f;
-                                          vt[0].t = 1.0f;
+                                               VertexTexCoord_t vt[4];
+                                               vt[0].x =  fButtonX[i];
+                                               vt[0].y =  fButtonY[i];
+                                               vt[0].z =  -0.2f;
+                                               vt[0].s = 0.0f;
+                                               vt[0].t = 1.0f;
                                           
-                                          vt[1].x =  fButtonX[i] + fButtonWidth[i];
-                                          vt[1].y =  fButtonY[i];
-                                          vt[1].z =  -0.2f;
-                                          vt[1].s = 1.0f;
-                                          vt[1].t = 1.0f;
+                                               vt[1].x =  fButtonX[i] + fButtonWidth[i];
+                                               vt[1].y =  fButtonY[i];
+                                               vt[1].z =  -0.2f;
+                                               vt[1].s = 1.0f;
+                                               vt[1].t = 1.0f;
                                           
-                                          vt[2].x =  fButtonX[i] + fButtonWidth[i];
-                                          vt[2].y =  fButtonY[i] - fButtonHeight[i];
-                                          vt[2].z =  -0.2f;
-                                          vt[2].s = 1.0f;
-                                          vt[2].t = 0.0f;
-                                          
-                                          vt[3].x =  fButtonX[i];
-                                          vt[3].y =  fButtonY[i] - fButtonHeight[i];
-                                          vt[3].z =  -0.2f;
-                                          vt[3].s = 0.0f;
-                                          vt[3].t = 0.0f;
-                  
-                                          buffer_button_vertex->write(0, vt, 4 * sizeof(VertexTexCoord_t));
-                                          buffer_button_vertex[i]->create();
-                                          buffer_button_vertex[i]->setUsagePattern(QOpenGLBuffer::DynamicDraw);
-                                          int vertex_loc = main_shader->attributeLocation("vertex");
-                                          int texcoord_loc = main_shader->attributeLocation("texcoord");
-                                          
-                                          vertex_button[i]->bind();
-                                          buffer_button_vertex[i]->bind();
-                                          buffer_button_vertex[i]->allocate(sizeof(vt));
-                               
-                                          buffer_button_vertex[i]->write(0, vertexFormat, sizeof(vertexFormat));
-                                          button_shader->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3, 5 * sizeof(GLfloat));
-                                          button_shader->setAttributeBuffer(texcoord_loc, GL_FLOAT, 3 * sizeof(GLfloat), 2, 5 * sizeof(GLfloat));
-                                          buffer_button_vertex[i]->release();
-                                          vertex_button[i]->release();
-                                          button_shader->setUniformValue("a_texture", 0);
-                       
-                                          extfunc->glVertexAttribPointer(vertex_loc, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0); 
-                                          extfunc->glVertexAttribPointer(texcoord_loc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 
-                                                                         (char *)NULL + 3 * sizeof(GLfloat)); 
-                                          button_shader->enableAttributeArray(vertex_loc);
-                                          button_shader->enableAttributeArray(texcoord_loc);
-                                          vertex_button[i]->release();
+                                               vt[2].x =  fButtonX[i] + fButtonWidth[i];
+                                               vt[2].y =  fButtonY[i] - fButtonHeight[i];
+                                               vt[2].z =  -0.2f;
+                                               vt[2].s = 1.0f;
+                                               vt[2].t = 0.0f;
+                                               
+                                               vt[3].x =  fButtonX[i];
+                                               vt[3].y =  fButtonY[i] - fButtonHeight[i];
+                                               vt[3].z =  -0.2f;
+                                               vt[3].s = 0.0f;
+                                               vt[3].t = 0.0f;
+
+                                               vertexButtons->append(vt[0]);
+                                               vertexButtons->append(vt[1]);
+                                               vertexButtons->append(vt[2]);
+                                               vertexButtons->append(vt[3]);
+                                               vertex_button[i]->bind();
+                                               buffer_button_vertex[i]->bind();
+                                               buffer_button_vertex[i]->allocate(4 * sizeof(VertexTexCoord_t));
+                                               
+                                               buffer_button_vertex[i]->setUsagePattern(QOpenGLBuffer::StaticDraw);
+                                               buffer_button_vertex[i]->release();
+                                               vertex_button[i]->release();
+                                               setNormalVAO(button_shader[i], vertex_button[i],
+                                                                        buffer_button_vertex[i],
+                                                                        vt, 4);
                                        }
                                }
                        }
@@ -275,105 +329,96 @@ void GLDrawClass::InitFBO(void)
           vertex_bitmap = new QOpenGLVertexArrayObject;
           if(vertex_bitmap != NULL) {
                   if(vertex_bitmap->create()) {
+                          {
+                                  QVector4D c;
+                                  c = QVector4D(1.0, 1.0, 1.0, 1.0);
+                                  bitmap_shader->setUniformValue("color", c);
+                          }
                           vertexBitmap[0].x = -1.0f;
                           vertexBitmap[0].y = -1.0f;
                           vertexBitmap[0].z = -0.9f;
                           vertexBitmap[0].s = 0.0f;
-                          vertexBitmap[0].t = 1.0f;
+                          vertexBitmap[0].t = 0.0f;
                           
                           vertexBitmap[1].x = +1.0f;
                           vertexBitmap[1].y = -1.0f;
                           vertexBitmap[1].z = -0.9f;
                           vertexBitmap[1].s = 1.0f;
-                          vertexBitmap[1].t = 1.0f;
+                          vertexBitmap[1].t = 0.0f;
                           
                           vertexBitmap[2].x = +1.0f;
                           vertexBitmap[2].y = +1.0f;
                           vertexBitmap[2].z = -0.9f;
                           vertexBitmap[2].s = 1.0f;
-                          vertexBitmap[2].t = 0.0f;
+                          vertexBitmap[2].t = 1.0f;
                           
                           vertexBitmap[3].x = -1.0f;
                           vertexBitmap[3].y = +1.0f;
                           vertexBitmap[3].z = -0.9f;
                           vertexBitmap[3].s = 0.0f;
-                          vertexBitmap[3].t = 0.0f;
+                          vertexBitmap[3].t = 1.0f;
                           
                           buffer_bitmap_vertex->create();
-                          buffer_bitmap_vertex->setUsagePattern(QOpenGLBuffer::DynamicDraw);
+                          buffer_bitmap_vertex->setUsagePattern(QOpenGLBuffer::StaticDraw);
                           int vertex_loc = main_shader->attributeLocation("vertex");
                           int texcoord_loc = main_shader->attributeLocation("texcoord");
                           
                           vertex_bitmap->bind();
                           buffer_bitmap_vertex->bind();
                           buffer_bitmap_vertex->allocate(sizeof(vertexBitmap));
-                          
-                          buffer_bitmap_vertex->write(0, vertexFormat, sizeof(vertexFormat));
-                          bitmap_shader->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3, 5 * sizeof(GLfloat));
-                          bitmap_shader->setAttributeBuffer(texcoord_loc, GL_FLOAT, 3 * sizeof(GLfloat), 2, 5 * sizeof(GLfloat));
                           buffer_bitmap_vertex->release();
                           vertex_bitmap->release();
-                          bitmap_shader->setUniformValue("a_texture", 0);
-                          
-                          extfunc->glVertexAttribPointer(vertex_loc, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0); 
-                          extfunc->glVertexAttribPointer(texcoord_loc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 
-                                                                                         (char *)NULL + 3 * sizeof(GLfloat)); 
-                          bitmap_shader->enableAttributeArray(vertex_loc);
-                          bitmap_shader->enableAttributeArray(texcoord_loc);
-                          vertex_bitmap->release();
+                          setNormalVAO(bitmap_shader, vertex_bitmap,
+                                                       buffer_bitmap_vertex,
+                                                       vertexBitmap, 4);
                   }
-               }
+          }
 #endif
           buffer_screen_vertex = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
           vertex_screen = new QOpenGLVertexArrayObject;
           if(vertex_screen != NULL) {
                   if(vertex_screen->create()) {
+                          {
+                                  QVector4D c;
+                                  c = QVector4D(1.0, 1.0, 1.0, 1.0);
+                                  main_shader->setUniformValue("color", c);
+                          }
                           vertexFormat[0].x = -0.5f;
                           vertexFormat[0].y = -0.5f;
-                          vertexFormat[0].z = 0.0f;
+                          vertexFormat[0].z = -1.0f;
                           vertexFormat[0].s = 0.0f;
                           vertexFormat[0].t = 1.0f;
                           
                           vertexFormat[1].x = +0.5f;
                           vertexFormat[1].y = -0.5f;
-                          vertexFormat[1].z = 0.0f;
+                          vertexFormat[1].z = -1.0f;
                           vertexFormat[1].s = 1.0f;
                           vertexFormat[1].t = 1.0f;
                           
                           vertexFormat[2].x = +0.5f;
                           vertexFormat[2].y = +0.5f;
-                          vertexFormat[2].z = 0.0f;
+                          vertexFormat[2].z = -1.0f;
                           vertexFormat[2].s = 1.0f;
                           vertexFormat[2].t = 0.0f;
                           
                           vertexFormat[3].x = -0.5f;
                           vertexFormat[3].y = +0.5f;
-                          vertexFormat[3].z = 0.0f;
+                          vertexFormat[3].z = -1.0f;
                           vertexFormat[3].s = 0.0f;
                           vertexFormat[3].t = 0.0f;
                           
                           
                           buffer_screen_vertex->create();
                           buffer_screen_vertex->setUsagePattern(QOpenGLBuffer::DynamicDraw);
-                          int vertex_loc = main_shader->attributeLocation("vertex");
-                          int texcoord_loc = main_shader->attributeLocation("texcoord");
                           
                           vertex_screen->bind();
                           buffer_screen_vertex->bind();
-                          buffer_screen_vertex->allocate(sizeof(vertexFormat));
-                          
-                          buffer_screen_vertex->write(0, vertexFormat, sizeof(vertexFormat));
-                          main_shader->setAttributeBuffer(vertex_loc, GL_FLOAT, 0, 3, 5 * sizeof(GLfloat));
-                          main_shader->setAttributeBuffer(texcoord_loc, GL_FLOAT, 3 * sizeof(GLfloat), 2, 5 * sizeof(GLfloat));
-                          buffer_screen_vertex->release();
+                          buffer_screen_vertex->allocate(sizeof(VertexTexCoord_t) * 4);
                           vertex_screen->release();
-                          main_shader->setUniformValue("a_texture", 0);
-                          
-                          extfunc->glVertexAttribPointer(vertex_loc, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0); 
-                          extfunc->glVertexAttribPointer(texcoord_loc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 
-                                                              (char *)NULL + 3 * sizeof(GLfloat)); 
-                          main_shader->enableAttributeArray(vertex_loc);
-                          main_shader->enableAttributeArray(texcoord_loc);
+                          buffer_screen_vertex->release();
+                          setNormalVAO(main_shader, vertex_screen,
+                                                       buffer_screen_vertex,
+                                                       vertexFormat, 4);
                           QMatrix4x4 mat;
                           mat.ortho(-1.0, 1.0, -1.0, +1.0, -1.0, 1.0);
                           mat.translate(0, 0, 0);
index dbe0425..2abb66f 100644 (file)
@@ -1,3 +1,7 @@
+#ifdef GL_ES
+ precision mediump float;
+#endif 
+
 attribute vec3 vertex;
 attribute vec2 texcoord;
 varying vec2 v_texcoord;