Skip to content

Commit c74a6dc

Browse files
committed
gl: use normailized coordinates
simplify vbo computation and reduce vbo updating
1 parent 2efe5fc commit c74a6dc

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/QtAV/OpenGLVideo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class Q_AV_EXPORT OpenGLVideo : public QObject
8383
* the rect will be viewport
8484
*/
8585
void setProjectionMatrixToRect(const QRectF& v);
86+
void setViewport(const QRectF& r);
8687

8788
void setBrightness(qreal value);
8889
void setContrast(qreal value);

src/opengl/OpenGLVideo.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class OpenGLVideoPrivate : public DPtrPrivate<OpenGLVideo>
4444
, manager(0)
4545
, material(new VideoMaterial())
4646
, material_type(0)
47+
, norm_viewport(true)
4748
, update_geo(true)
4849
, tex_target(0)
4950
, valiad_tex_width(1.0)
@@ -77,6 +78,7 @@ class OpenGLVideoPrivate : public DPtrPrivate<OpenGLVideo>
7778
ShaderManager *manager;
7879
VideoMaterial *material;
7980
qint64 material_type;
81+
bool norm_viewport;
8082
bool has_a;
8183
bool update_geo;
8284
int tex_target;
@@ -105,7 +107,8 @@ void OpenGLVideoPrivate::updateGeometry(VideoShader* shader, const QRectF &t, co
105107
tex_target = shader->textureTarget();
106108
update_geo = true;
107109
}
108-
QRectF& target_rect = rect;
110+
// (-1, -1, 2, 2) must flip y
111+
QRectF target_rect = norm_viewport ? QRectF(-1, 1, 2, -2) : rect;
109112
if (target.isValid()) {
110113
if (roi_changed || target != t) {
111114
target = t;
@@ -121,6 +124,7 @@ void OpenGLVideoPrivate::updateGeometry(VideoShader* shader, const QRectF &t, co
121124
return;
122125
//qDebug("updating geometry...");
123126
// setTextureCount may change the vertex data. Call it before setRect()
127+
qDebug() << "target rect: " << target_rect ;
124128
geometry.setTextureCount(shader->textureTarget() == GL_TEXTURE_RECTANGLE ? tc : 1);
125129
geometry.setRect(target_rect, material->mapToTexture(0, roi));
126130
if (shader->textureTarget() == GL_TEXTURE_RECTANGLE) {
@@ -226,14 +230,23 @@ void OpenGLVideo::setCurrentFrame(const VideoFrame &frame)
226230
}
227231

228232
void OpenGLVideo::setProjectionMatrixToRect(const QRectF &v)
233+
{
234+
setViewport(v);
235+
}
236+
237+
void OpenGLVideo::setViewport(const QRectF &r)
229238
{
230239
DPTR_D(OpenGLVideo);
231-
d.rect = v;
232-
d.matrix.setToIdentity();
233-
d.matrix.ortho(v);
240+
d.rect = r;
241+
if (d.norm_viewport) {
242+
d.matrix.setToIdentity();
243+
} else {
244+
d.matrix.setToIdentity();
245+
d.matrix.ortho(r);
246+
d.update_geo = true; // even true for target_rect != d.rect
247+
}
234248
// Mirrored relative to the usual Qt coordinate system with origin in the top left corner.
235249
//mirrored = mat(0, 0) * mat(1, 1) - mat(0, 1) * mat(1, 0) > 0;
236-
d.update_geo = true; // even true for target_rect != d.rect
237250
if (d.ctx && d.ctx == QOpenGLContext::currentContext()) {
238251
DYGL(glViewport(d.rect.x(), d.rect.y(), d.rect.width(), d.rect.height()));
239252
}

0 commit comments

Comments
 (0)