~mterry/qtvideo-node/dont-install-tests

« back to all changes in this revision

Viewing changes to src/shadervideomaterial.cpp

  • Committer: Tarmac
  • Author(s): Guenter Schwann
  • Date: 2012-11-09 10:57:05 UTC
  • mfrom: (5.1.1 qtvideonode-plugin-tests)
  • Revision ID: tarmac-20121109105705-4i02o2phcmtfowde
* Spliting up code in separate files
* Add a unit test.

Approved by PS Jenkins bot, Michael Zanetti.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 Canonical, Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *  Guenter Schwann <guenter.schwann@canonical.com>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; version 3.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include "shadervideomaterial.h"
 
21
#include "shadervideoshader.h"
 
22
 
 
23
#include <camera_compatibility_layer.h>
 
24
 
 
25
ShaderVideoMaterial::ShaderVideoMaterial(const QVideoSurfaceFormat &format)
 
26
    : m_format(format),
 
27
    m_camControl(0),
 
28
    m_videoShader(0)
 
29
{
 
30
}
 
31
 
 
32
QSGMaterialShader *ShaderVideoMaterial::createShader() const
 
33
{
 
34
    m_videoShader = new ShaderVideoShader(m_format.pixelFormat());
 
35
    return m_videoShader;
 
36
}
 
37
 
 
38
QSGMaterialType *ShaderVideoMaterial::type() const
 
39
{
 
40
    static QSGMaterialType theType;
 
41
    return &theType;
 
42
}
 
43
 
 
44
void ShaderVideoMaterial::setCamControl(CameraControl *cc)
 
45
{
 
46
    m_camControl = cc;
 
47
}
 
48
 
 
49
CameraControl *ShaderVideoMaterial::cameraControl() const
 
50
{
 
51
    return m_camControl;
 
52
}
 
53
 
 
54
void ShaderVideoMaterial::bind()
 
55
{
 
56
    if (!m_camControl) {
 
57
        qWarning() << "No valid CameraControl";
 
58
        return;
 
59
    }
 
60
 
 
61
    android_camera_update_preview_texture(m_camControl);
 
62
 
 
63
    android_camera_get_preview_texture_transformation(m_camControl, m_textureMatrix);
 
64
    flipMatrixY();
 
65
    glUniformMatrix4fv(m_videoShader->m_tex_matrix, 1, GL_FALSE, m_textureMatrix);
 
66
 
 
67
    glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
68
    glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 
69
    glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 
70
    glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
71
}
 
72
 
 
73
// As long as coordinates are 0..1, the y is flipped
 
74
void ShaderVideoMaterial::flipMatrixY()
 
75
{
 
76
    // reduced way to multiplay the matrix with following matrix and assigin it back again
 
77
    // 1  0  0  0
 
78
    // 0 -1  0  1
 
79
    // 0  0  1  0
 
80
    // 0  0  0  1
 
81
    m_textureMatrix[1] = -m_textureMatrix[1] + m_textureMatrix[3];
 
82
    m_textureMatrix[5] = -m_textureMatrix[5] + m_textureMatrix[7];
 
83
    m_textureMatrix[9] = -m_textureMatrix[9] + m_textureMatrix[11];
 
84
    m_textureMatrix[13] = -m_textureMatrix[13] + m_textureMatrix[15];
 
85
}