• R/O
  • HTTP
  • SSH
  • HTTPS

common_source_project-fm7: Commit

Common Source Code Project for Qt (a.k.a for FM-7).


Commit MetaInfo

Revisiond15cf6012456bd41a4e2aa93e0f99c07652aff9f (tree)
Time2018-07-28 04:57:31
AuthorK.Ohta <whatisthis.sowhat@gmai...>
CommiterK.Ohta

Log Message

[Qt][OpenGL][WIP] GL4.3: Implementing texture buffer with mapping.

Change Summary

Incremental Difference

--- a/source/src/qt/gui/gl4_3/fragment_shader.glsl
+++ b/source/src/qt/gui/gl4_3/fragment_shader.glsl
@@ -1,11 +1,18 @@
11 //precision mediump float;
22
33 in vec2 v_texcoord;
4-out vec4 opixel;
4+in vec2 v_xy;
5+in float vertex_id;
6+out uvec4 opixel;
7+uniform float tex_width;
8+uniform float tex_height;
59
6-uniform sampler2D a_texture;
10+uniform usamplerBuffer s_texture;
11+//uniform usampler2D a_texture;
712 void main ()
813 {
9- vec4 pixel = texture(a_texture, v_texcoord);
14+ //uvec4 pixel = texture(a_texture, v_texcoord);
15+ uvec4 pixel = texelFetch(s_texture, int(v_texcoord.s * tex_width + v_texcoord.t * tex_width * tex_height));
16+ //uvec4 pixel = texelFetch(s_texture, int(vertex_id));
1017 opixel = pixel;
1118 }
--- a/source/src/qt/gui/gl4_3/qt_glutil_gl4_3.cpp
+++ b/source/src/qt/gui/gl4_3/qt_glutil_gl4_3.cpp
@@ -68,8 +68,10 @@ GLDraw_4_3::GLDraw_4_3(GLDrawClass *parent, USING_FLAGS *p, CSP_Logger *logger,
6868 #else
6969 swap_byteorder = false;
7070 #endif
71-
72- TextureTransferParam = new QOpenGLPixelTransferOptions();
71+ pixel_width = 0;
72+ pixel_height = 0;
73+ main_texture_buffer = 0;
74+ map_base_address = 0;
7375 }
7476
7577 GLDraw_4_3::~GLDraw_4_3()
@@ -99,27 +101,53 @@ GLDraw_4_3::~GLDraw_4_3()
99101 if(grids_horizonal_vertex != NULL) {
100102 if(grids_vertical_vertex->isCreated()) grids_vertical_vertex->destroy();
101103 }
102- if(TextureTransferParam != NULL) delete TextureTransferParam;
103104 }
104105
105106 QOpenGLTexture *GLDraw_4_3::createMainTexture(QImage *img)
106107 {
107108 QOpenGLTexture *tx;
109+ QImage *ip = NULL;
110+ int w;
111+ int h;
108112 if(img == NULL) {
109- QImage nImg(using_flags->get_real_screen_width(), using_flags->get_real_screen_height(), QImage::Format_RGBA8888);
110- tx = new QOpenGLTexture(nImg, QOpenGLTexture::DontGenerateMipMaps);
111- TextureTransferParam->setImageHeight(using_flags->get_real_screen_height());
112- TextureTransferParam->setRowLength(using_flags->get_real_screen_width());
113+ w = using_flags->get_real_screen_width();
114+ h = using_flags->get_real_screen_height();
113115 } else {
114- tx = new QOpenGLTexture(*img, QOpenGLTexture::DontGenerateMipMaps);
115- TextureTransferParam->setImageHeight(img->height());
116- TextureTransferParam->setRowLength(img->width());
116+ w = img->width();
117+ h = img->height();
118+ }
119+ QImage im(w, h, QImage::Format_RGBA8888);
120+ if(img == NULL) {
121+ ip = &im;
122+ } else {
123+ ip = img;
124+ }
125+ //tx->setFormat(QOpenGLTexture::RGBA8_UNorm);
126+
127+ if(main_texture_buffer != 0) {
128+ extfunc->glDeleteBuffers(1, &main_texture_buffer);
117129 }
118- tx->setFormat(QOpenGLTexture::RGBA8_UNorm);
119- tx->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Nearest);
120- tx->setWrapMode(QOpenGLTexture::ClampToEdge);
130+ {
131+ extfunc->glGenBuffers(1, &main_texture_buffer);
132+ extfunc->glBindBuffer(GL_TEXTURE_BUFFER, main_texture_buffer);
133+ extfunc->glBufferData(GL_TEXTURE_BUFFER, w * h * sizeof(uint32_t), ip->constBits(), GL_DYNAMIC_COPY);
134+ tx = new QOpenGLTexture(QOpenGLTexture::TargetBuffer);
135+ tx->setFormat(QOpenGLTexture::RGBA8_UNorm);
136+ tx->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Nearest);
137+ tx->setWrapMode(QOpenGLTexture::ClampToEdge);
138+ tx->setSize(w * h);
139+ tx->bind();
140+ extfunc->glActiveTexture(GL_TEXTURE0);
141+ extfunc->glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA8, main_texture_buffer);
142+ tx->release();
143+ extfunc->glBindBuffer(GL_TEXTURE_BUFFER, 0);
144+ }
145+ pixel_width = w;
146+ pixel_height = h;
147+
121148 return tx;
122149 }
150+
123151 void GLDraw_4_3::initBitmapVertex(void)
124152 {
125153 if(using_flags->is_use_one_board_computer()) {
@@ -560,7 +588,7 @@ void GLDraw_4_3::drawGridsMain(QOpenGLShaderProgram *prg,
560588 extfunc->glVertexAttribPointer(vertex_loc, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 3, 0);
561589 extfunc->glEnableVertexAttribArray(vertex_loc);
562590
563- extfunc->glLineWidth(1.5);
591+ extfunc->glLineWidth(lineWidth);
564592 extfunc->glDrawArrays(GL_LINES, 0, (number + 1) * 2);
565593 prg->release();
566594 vp->release();
@@ -753,9 +781,30 @@ void GLDraw_4_3::uploadMainTexture(QImage *p, bool use_chromakey)
753781 uVramTextureID = createMainTexture(p);
754782 } else {
755783 // Upload to main texture
756- TextureTransferParam->setImageHeight(p->height());
757- TextureTransferParam->setRowLength(p->width());
758- uVramTextureID->setData(QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, p->constBits(), TextureTransferParam);
784+ if(p != NULL) {
785+ extfunc->glBindBuffer(GL_TEXTURE_BUFFER, main_texture_buffer);
786+ uint32_t *pp = (uint32_t *)(extfunc->glMapBuffer(GL_TEXTURE_BUFFER, GL_WRITE_ONLY));
787+ if(pp != NULL) {
788+#if 1
789+ int s1 = pixel_width * pixel_height * sizeof(uint32_t);
790+ int s2 = p->height() * p->width() * sizeof(uint32_t);
791+ int ww = (pixel_width < p->width()) ? pixel_width : p->width();
792+ int hh = (pixel_height < p->height()) ? pixel_height : p->height();
793+ for(int y = 0; y < hh; y++) {
794+ memcpy(&(pp[y * pixel_width]), p->scanLine(y), p->width() * sizeof(uint32_t));
795+ }
796+#else
797+ int s1 = pixel_width * pixel_height * sizeof(uint32_t);
798+ memcpy(pp, p->constBits(), s1);
799+#endif
800+ }
801+ extfunc->glUnmapBuffer(GL_TEXTURE_BUFFER);
802+ extfunc->glBindTexture(GL_TEXTURE_BUFFER, uVramTextureID->textureId());
803+ extfunc->glActiveTexture(GL_TEXTURE0);
804+ extfunc->glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA8, main_texture_buffer);
805+ extfunc->glBindTexture(GL_TEXTURE_BUFFER, 0);
806+ extfunc->glBindBuffer(GL_TEXTURE_BUFFER, 0);
807+ }
759808 }
760809 #if 1
761810 if(using_flags->is_support_tv_render() && (p_config->rendering_type == CONFIG_RENDER_TYPE_TV)) {
@@ -830,7 +879,8 @@ void GLDraw_4_3::drawMain(QOpenGLShaderProgram *prg,
830879 ortho.ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0, 1.0);
831880
832881 extfunc->glActiveTexture(GL_TEXTURE0);
833- extfunc->glBindTexture(GL_TEXTURE_2D, texid);
882+ //extfunc->glBindTexture(GL_TEXTURE_2D, texid);
883+ extfunc->glBindTexture(GL_TEXTURE_BUFFER, texid);
834884
835885 extfunc->glClearColor(1.0, 1.0, 1.0, 1.0);
836886 if(!f_smoosing) {
@@ -912,7 +962,8 @@ void GLDraw_4_3::drawMain(QOpenGLShaderProgram *prg,
912962 vp->release();
913963
914964 prg->release();
915- extfunc->glBindTexture(GL_TEXTURE_2D, 0);
965+ extfunc->glBindTexture(GL_TEXTURE_BUFFER, 0);
966+ //extfunc->glBindTexture(GL_TEXTURE_2D, 0);
916967 }
917968 else {
918969 vp->bind();
@@ -970,7 +1021,7 @@ void GLDraw_4_3::drawMain(QOpenGLShaderProgram *prg,
9701021 bp->release();
9711022 vp->release();
9721023 prg->release();
973- extfunc->glBindTexture(GL_TEXTURE_2D, 0);
1024+ extfunc->glBindTexture(GL_TEXTURE_BUFFER, 0);
9741025 }
9751026 }
9761027
@@ -1431,15 +1482,17 @@ void GLDraw_4_3::do_set_texture_size(QImage *p, int w, int h)
14311482 vertexTmpTexture, 4);
14321483
14331484 }
1434- if(p != NULL) {
1485+ if(((int)iw != pixel_width) || ((int)ih != pixel_height)) {
1486+ QImage im((int)screen_texture_width, (int)screen_texture_height, QImage::Format_RGBA8888);
1487+ if(p == NULL) {
1488+ p = &im;
1489+ }
14351490 if(uVramTextureID != NULL) {
1436- if(((int)iw != uVramTextureID->width()) || ((int)ih != uVramTextureID->height())) {
1437- p_wid->makeCurrent();
1438- uVramTextureID->destroy();
1439- delete uVramTextureID;
1440- uVramTextureID = createMainTexture(p);
1441- p_wid->doneCurrent();
1442- }
1491+ p_wid->makeCurrent();
1492+ uVramTextureID->destroy();
1493+ delete uVramTextureID;
1494+ uVramTextureID = createMainTexture(p);
1495+ p_wid->doneCurrent();
14431496 } else {
14441497 p_wid->makeCurrent();
14451498 uVramTextureID = createMainTexture(p);
@@ -1729,3 +1782,34 @@ void GLDraw_4_3::updateButtonTexture(void)
17291782 button_updated = true;
17301783 }
17311784
1785+void GLDraw_4_3::get_screen_geometry(int *w, int *h)
1786+{
1787+ if(w != NULL) *w = pixel_width;
1788+ if(h != NULL) *h = pixel_height;
1789+}
1790+
1791+scrntype_t *GLDraw_4_3::get_screen_buffer(int y)
1792+{
1793+ if(map_base_address == NULL) {
1794+ return NULL;
1795+ } else {
1796+ scrntype_t *p = (scrntype_t *)map_base_address;
1797+ p = p + (pixel_width * y);
1798+ return p;
1799+ }
1800+}
1801+
1802+bool GLDraw_4_3::is_ready_to_map_vram_texture(void)
1803+{
1804+ return false;
1805+}
1806+
1807+bool GLDraw_4_3::map_vram_texture(void)
1808+{
1809+ return false;
1810+}
1811+
1812+bool GLDraw_4_3::unmap_vram_texture(void)
1813+{
1814+ return false;
1815+}
--- a/source/src/qt/gui/gl4_3/qt_glutil_gl4_3.h
+++ b/source/src/qt/gui/gl4_3/qt_glutil_gl4_3.h
@@ -90,6 +90,12 @@ protected:
9090
9191 int gl_major_version;
9292 int gl_minor_version;
93+
94+ int pixel_width;
95+ int pixel_height;
96+ GLuint main_texture_buffer;
97+ scrntype_t *map_base_address;
98+
9399 GLScreenPack *main_pass;
94100 GLScreenPack *std_pass;
95101 GLScreenPack *ntsc_pass1;
@@ -112,7 +118,6 @@ protected:
112118
113119 GLuint uTmpTextureID;
114120 bool swap_byteorder;
115- QOpenGLPixelTransferOptions *TextureTransferParam;
116121
117122 virtual void setNormalVAO(QOpenGLShaderProgram *prg, QOpenGLVertexArrayObject *vp,
118123 QOpenGLBuffer *bp, VertexTexCoord_t *tp, int size = 4);
@@ -187,6 +192,13 @@ public:
187192 virtual void doSetGridsHorizonal(int lines, bool force);
188193 virtual void doSetGridsVertical(int pixels, bool force);
189194 void uploadBitmapTexture(QImage *p);
195+
196+ void get_screen_geometry(int *w, int *h);
197+ scrntype_t *get_screen_buffer(int y);
198+ bool is_ready_to_map_vram_texture(void);
199+ bool map_vram_texture(void);
200+ bool unmap_vram_texture(void);
201+
190202 public slots:
191203 void updateBitmap(QImage *);
192204 void uploadIconTexture(QPixmap *p, int icon_type, int localnum);
--- a/source/src/qt/gui/gl4_3/vertex_shader.glsl
+++ b/source/src/qt/gui/gl4_3/vertex_shader.glsl
@@ -2,6 +2,8 @@
22 in mediump vec3 vertex;
33 in mediump vec2 texcoord;
44 out mediump vec2 v_texcoord;
5+out vec2 v_xy;
6+out float vertex_id;
57
68 uniform mat2 rotate_mat;
79 void main ()
@@ -10,5 +12,7 @@ void main ()
1012 xy = rotate_mat * xy;
1113 gl_Position = vec4(xy, vertex.z, 1.0);
1214 v_texcoord = texcoord;
15+ v_xy = vertex.xy;
16+ vertex_id = float(gl_VertexID);
1317 }
1418
Show on old repository browser