Skip to content

Commit

Permalink
gl: upload full texture and render part(roi) of it
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Oct 16, 2013
1 parent f4221a8 commit 1b16535
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
34 changes: 22 additions & 12 deletions src/GLWidgetRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@
//TODO: QGLfunctions?
namespace QtAV {

const GLfloat kTexCoords[] = {
0, 0,
1, 0,
1, 1,
0, 1,
};

const GLfloat kVertices[] = {
-1, 1,
Expand Down Expand Up @@ -216,7 +210,10 @@ void GLWidgetRenderer::drawFrame()
glBindTexture(GL_TEXTURE_2D, d.texture);
d.setupQuality();
QRect roi = realROI();
if (roi.size() == QSize(d.src_width, d.src_height)) {
//uploading part of image eats less gpu memory, but may be more cpu(gles)
//FIXME: more cpu usage then qpainter. FBO, VBO?
#define ROI_TEXCOORDS 1
if (ROI_TEXCOORDS || roi.size() == QSize(d.src_width, d.src_height)) {
glTexImage2D(GL_TEXTURE_2D
, 0 //level
, FMT_INTERNAL //internal format. 4? why GL_RGBA? GL_RGB?
Expand Down Expand Up @@ -247,7 +244,24 @@ void GLWidgetRenderer::drawFrame()
}
#endif //GL_UNPACK_ROW_LENGTH
}

//TODO: compute kTexCoords only if roi changed
#if ROI_TEXCOORDS
const GLfloat kTexCoords[] = {
(GLfloat)roi.x()/(GLfloat)d.src_width, (GLfloat)roi.y()/(GLfloat)d.src_height,
(GLfloat)(roi.x() + roi.width())/(GLfloat)d.src_width, (GLfloat)roi.y()/(GLfloat)d.src_height,
(GLfloat)(roi.x() + roi.width())/(GLfloat)d.src_width, (GLfloat)(roi.y()+roi.height())/(GLfloat)d.src_height,
(GLfloat)roi.x()/(GLfloat)d.src_width, (GLfloat)(roi.y()+roi.height())/(GLfloat)d.src_height,
};
/// glVertexAttribPointer(d.tex_coords_location, 2, GL_FLOAT, GL_FALSE, 0, kTexCoords);
/// glEnableVertexAttribArray(d.tex_coords_location);
#else
const GLfloat kTexCoords[] = {
0, 0,
1, 0,
1, 1,
0, 1,
};
#endif //ROI_TEXCOORDS
#ifndef QT_OPENGL_ES_2
//qpainter will reset gl state, so need glMatrixMode and clear color(in drawBackground())
//TODO: study what state will be reset
Expand Down Expand Up @@ -320,10 +334,6 @@ void GLWidgetRenderer::initializeGL()
checkGlError("glVertexAttribPointer");
glEnableVertexAttribArray(d.position_location);
checkGlError("glEnableVertexAttribArray");
glVertexAttribPointer(d.tex_coords_location, 2, GL_FLOAT, GL_FALSE, 0, kTexCoords);
checkGlError("glVertexAttribPointer");
glEnableVertexAttribArray(d.tex_coords_location);
checkGlError("glEnableVertexAttribArray");
#else
glShadeModel(GL_SMOOTH); //setupQuality?
glClearDepth(1.0f);
Expand Down
5 changes: 4 additions & 1 deletion src/QtAV/private/GLWidgetRenderer_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class GLWidgetRendererPrivate : public VideoRendererPrivate
{
public:
GLWidgetRendererPrivate():
texture(0)
VideoRendererPrivate()
, update_texcoords(true)
, texture(0)
#ifdef QT_OPENGL_ES_2
, program(0)
, position_location(0)
Expand Down Expand Up @@ -110,6 +112,7 @@ class GLWidgetRendererPrivate : public VideoRendererPrivate
#endif
}

bool update_texcoords;
GLuint texture;
#ifdef QT_OPENGL_ES_2
//TODO: u_tex, a_position
Expand Down

0 comments on commit 1b16535

Please sign in to comment.