2
* Copyright (C) 2012 Canonical, Ltd.
5
* Guenter Schwann <guenter.schwann@canonical.com>
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.
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.
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/>.
20
#include "shadervideomaterial.h"
21
#include "shadervideoshader.h"
23
#include <camera_compatibility_layer.h>
25
ShaderVideoMaterial::ShaderVideoMaterial(const QVideoSurfaceFormat &format)
32
QSGMaterialShader *ShaderVideoMaterial::createShader() const
34
m_videoShader = new ShaderVideoShader(m_format.pixelFormat());
38
QSGMaterialType *ShaderVideoMaterial::type() const
40
static QSGMaterialType theType;
44
void ShaderVideoMaterial::setCamControl(CameraControl *cc)
49
CameraControl *ShaderVideoMaterial::cameraControl() const
54
void ShaderVideoMaterial::bind()
57
qWarning() << "No valid CameraControl";
61
android_camera_update_preview_texture(m_camControl);
63
android_camera_get_preview_texture_transformation(m_camControl, m_textureMatrix);
65
glUniformMatrix4fv(m_videoShader->m_tex_matrix, 1, GL_FALSE, m_textureMatrix);
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);
73
// As long as coordinates are 0..1, the y is flipped
74
void ShaderVideoMaterial::flipMatrixY()
76
// reduced way to multiplay the matrix with following matrix and assigin it back again
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];