@@ -44,6 +44,7 @@ class OpenGLVideoPrivate : public DPtrPrivate<OpenGLVideo>
44
44
, manager(0 )
45
45
, material(new VideoMaterial())
46
46
, material_type(0 )
47
+ , norm_viewport(true )
47
48
, update_geo(true )
48
49
, tex_target(0 )
49
50
, valiad_tex_width(1.0 )
@@ -77,6 +78,7 @@ class OpenGLVideoPrivate : public DPtrPrivate<OpenGLVideo>
77
78
ShaderManager *manager;
78
79
VideoMaterial *material;
79
80
qint64 material_type;
81
+ bool norm_viewport;
80
82
bool has_a;
81
83
bool update_geo;
82
84
int tex_target;
@@ -105,7 +107,8 @@ void OpenGLVideoPrivate::updateGeometry(VideoShader* shader, const QRectF &t, co
105
107
tex_target = shader->textureTarget ();
106
108
update_geo = true ;
107
109
}
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;
109
112
if (target.isValid ()) {
110
113
if (roi_changed || target != t) {
111
114
target = t;
@@ -121,6 +124,7 @@ void OpenGLVideoPrivate::updateGeometry(VideoShader* shader, const QRectF &t, co
121
124
return ;
122
125
// qDebug("updating geometry...");
123
126
// setTextureCount may change the vertex data. Call it before setRect()
127
+ qDebug () << " target rect: " << target_rect ;
124
128
geometry.setTextureCount (shader->textureTarget () == GL_TEXTURE_RECTANGLE ? tc : 1 );
125
129
geometry.setRect (target_rect, material->mapToTexture (0 , roi));
126
130
if (shader->textureTarget () == GL_TEXTURE_RECTANGLE) {
@@ -226,14 +230,23 @@ void OpenGLVideo::setCurrentFrame(const VideoFrame &frame)
226
230
}
227
231
228
232
void OpenGLVideo::setProjectionMatrixToRect (const QRectF &v)
233
+ {
234
+ setViewport (v);
235
+ }
236
+
237
+ void OpenGLVideo::setViewport (const QRectF &r)
229
238
{
230
239
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
+ }
234
248
// Mirrored relative to the usual Qt coordinate system with origin in the top left corner.
235
249
// 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
237
250
if (d.ctx && d.ctx == QOpenGLContext::currentContext ()) {
238
251
DYGL (glViewport (d.rect .x (), d.rect .y (), d.rect .width (), d.rect .height ()));
239
252
}
0 commit comments