Skip to content

Commit

Permalink
gl: fix planar formats with rectangle texture. 2d use 1 coord
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Apr 12, 2015
1 parent 740437b commit ce7fd08
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 80 deletions.
31 changes: 18 additions & 13 deletions src/OpenGLVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 127,10 @@ class OpenGLVideoPrivate : public DPtrPrivate<OpenGLVideo>

void OpenGLVideoPrivate::bindAttributes(VideoShader* shader, const QRectF &t, const QRectF &r)
{
const bool tex_2d = shader->textureTarget() == GL_TEXTURE_2D;
const bool tex_rect = shader->textureTarget() == GL_TEXTURE_RECTANGLE;
// also check size change for normalizedROI computation if roi is not normalized
const bool roi_changed = valiad_tex_width != material->validTextureWidth() || roi != r || video_size != material->frameSize();
const int tc = shader->textureLocationCount();
if (roi_changed) {
roi = r;
valiad_tex_width = material->validTextureWidth();
Expand All @@ -149,7 150,14 @@ void OpenGLVideoPrivate::bindAttributes(VideoShader* shader, const QRectF &t, co
if (!update_geo)
goto end;
//qDebug("updating geometry...");
geometry.setRect(target_rect, material->mapToTexture(roi));
geometry.setRect(target_rect, material->mapToTexture(0, roi));
if (tex_rect) {
geometry.setTextureCount(tc);
for (int i = 1; i < tc; i) {
// tc can > planes, but that will compute chroma plane
geometry.setTextureRect(material->mapToTexture(i, roi), i);
}
}
update_geo = false;
if (!try_vbo)
goto end;
Expand Down Expand Up @@ -177,15 185,14 @@ void OpenGLVideoPrivate::bindAttributes(VideoShader* shader, const QRectF &t, co
}
//qDebug("updating vbo...");
vbo.bind(); //check here
vbo.allocate(geometry.data(), geometry.vertexCount()*geometry.stride());
vbo.allocate(geometry.data(), geometry.size());
#if QT_VAO
if (try_vao) {
shader->program()->setAttributeBuffer(0, GL_FLOAT, 0, geometry.tupleSize(), geometry.stride());
shader->program()->setAttributeBuffer(1, GL_FLOAT, geometry.tupleSize()*sizeof(float), geometry.tupleSize(), geometry.stride());
if (tex_2d) {
const int tc = shader->textureLocationCount();
if (tex_rect) {
for (int i = 1; i < tc; i) {
shader->program()->setAttributeBuffer(i 1, GL_FLOAT, geometry.tupleSize()*sizeof(float), geometry.tupleSize(), geometry.stride());
shader->program()->setAttributeBuffer(i 1, GL_FLOAT, i*geometry.textureSize() geometry.tupleSize()*sizeof(float), geometry.tupleSize(), geometry.stride());
}
}
char const *const *attr = shader->attributeNames();
Expand All @@ -207,19 214,17 @@ void OpenGLVideoPrivate::bindAttributes(VideoShader* shader, const QRectF &t, co
vbo.bind();
shader->program()->setAttributeBuffer(0, GL_FLOAT, 0, geometry.tupleSize(), geometry.stride());
shader->program()->setAttributeBuffer(1, GL_FLOAT, geometry.tupleSize()*sizeof(float), geometry.tupleSize(), geometry.stride());
if (tex_2d) {
const int tc = shader->textureLocationCount();
if (tex_rect) {
for (int i = 1; i < tc; i) {
shader->program()->setAttributeBuffer(i 1, GL_FLOAT, geometry.tupleSize()*sizeof(float), geometry.tupleSize(), geometry.stride());
shader->program()->setAttributeBuffer(i 1, GL_FLOAT, i*geometry.textureSize() geometry.tupleSize()*sizeof(float), geometry.tupleSize(), geometry.stride());
}
}
} else {
shader->program()->setAttributeArray(0, GL_FLOAT, geometry.data(0), geometry.tupleSize(), geometry.stride());
shader->program()->setAttributeArray(1, GL_FLOAT, geometry.data(1), geometry.tupleSize(), geometry.stride());
if (tex_2d) {
const int tc = shader->textureLocationCount();
if (tex_rect) {
for (int i = 1; i < tc; i) {
shader->program()->setAttributeArray(i 1, GL_FLOAT, geometry.data(1), geometry.tupleSize(), geometry.stride());
shader->program()->setAttributeArray(i 1, GL_FLOAT, geometry.data(1), i*geometry.textureSize() geometry.tupleSize(), geometry.stride());
}
}
}
Expand Down Expand Up @@ -331,7 336,7 @@ void OpenGLVideo::render(const QRectF &target, const QRectF& roi, const QMatrix4
DYGL(glEnable(GL_BLEND));
DYGL(glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA));
}
DYGL(glDrawArrays(d.geometry.mode(), 0, d.geometry.vertexCount()));
DYGL(glDrawArrays(d.geometry.mode(), 0, d.geometry.textureVertexCount()));
if (blending)
DYGL(glDisable(GL_BLEND));
// d.shader->program()->release(); //glUseProgram(0)
Expand Down
48 changes: 35 additions & 13 deletions src/QtAV/VideoShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 144,13 @@ class Q_AV_EXPORT VideoMaterial
/*!
* \brief mapToFrame
* map a point p or a rect r to video texture (of 1st plane) and scaled to valid width.
* p or r is in video frame's rect.
* p or r is in video frame's rect, no matter which plane is
* \param normalize -1: auto(do not normalize for rectangle texture). 0: no. 1: yes
* \return
* point or rect in current texture valid coordinates. \sa validTextureWidth()
*/
QPointF mapToTexture(const QPointF& p, int normalize = -1) const;
QRectF mapToTexture(const QRectF& r, int normalize = -1) const;
QPointF mapToTexture(int plane, const QPointF& p, int normalize = -1) const;
QRectF mapToTexture(int plane, const QRectF& r, int normalize = -1) const;
void setBrightness(qreal value);
void setContrast(qreal value);
void setHue(qreal value);
Expand All @@ -170,23 170,45 @@ class Q_AV_EXPORT TexturedGeometry {
float tx, ty;
} Point;
enum Triangle { Strip, Fan };
TexturedGeometry(int count = 4, Triangle t = Strip);
TexturedGeometry(int texCount = 1, int count = 4, Triangle t = Strip);
/*!
* \brief setTextureCount
* sometimes we needs more than 1 texture coordinates, for example we have to set rectangle texture
* coordinates for each plane.
*/
void setTextureCount(int value);
int textureCount() const;
/*!
* \brief size
* totoal data size in bytes
*/
int size() const;
/*!
* \brief textureSize
* data size of 1 texture. equals textureVertexCount()*stride()
*/
int textureSize() const;
Triangle triangle() const { return tri;}
int mode() const;
int tupleSize() const { return 2;}
int stride() const { return sizeof(Point); }
/// vertex count per texture
int textureVertexCount() const { return points_per_tex;}
/// totoal vertex count
int vertexCount() const { return v.size(); }
void setPoint(int index, const QPointF& p, const QPointF& tp);
void setGeometryPoint(int index, const QPointF& p);
void setTexturePoint(int index, const QPointF& tp);
void setRect(const QRectF& r, const QRectF& tr);
void setGeometryRect(const QRectF& r);
void setTextureRect(const QRectF& tr);
void* data(int idx = 0) { return (char*)v.data() idx*2*sizeof(float); } //convert to char* float*?
const void* data(int idx = 0) const { return (char*)v.constData() idx*2*sizeof(float); }
const void* constData(int idx = 0) const { return (char*)v.constData() idx*2*sizeof(float); }
void setPoint(int index, const QPointF& p, const QPointF& tp, int texIndex = 0);
void setGeometryPoint(int index, const QPointF& p, int texIndex = 0);
void setTexturePoint(int index, const QPointF& tp, int texIndex = 0);
void setRect(const QRectF& r, const QRectF& tr, int texIndex = 0);
void setGeometryRect(const QRectF& r, int texIndex = 0);
void setTextureRect(const QRectF& tr, int texIndex = 0);
void* data(int idx = 0, int texIndex = 0) { return (char*)v.data() texIndex*textureSize() idx*2*sizeof(float); } //convert to char* float*?
const void* data(int idx = 0, int texIndex = 0) const { return (char*)v.constData() texIndex*textureSize() idx*2*sizeof(float); }
const void* constData(int idx = 0, int texIndex = 0) const { return (char*)v.constData() texIndex*textureSize() idx*2*sizeof(float); }
private:
Triangle tri;
int points_per_tex;
int nb_tex;
QVector<Point> v;
};

Expand Down
Loading

0 comments on commit ce7fd08

Please sign in to comment.