A few fixes to prevent compositor crashes
[profile/ivi/qtwayland.git] / src / compositor / compositor_api / waylandsurfacetexturematerial.cpp
1 #include "waylandsurfacetexturematerial.h"
2 #include <QtGui/QOpenGLContext>
3
4 static const char wayland_surface_texture_material_vertex[] =
5            "uniform highp mat4 qt_Matrix;                      \n"
6            "attribute highp vec4 qt_VertexPosition;            \n"
7            "attribute highp vec2 qt_VertexTexCoord;            \n"
8            "varying highp vec2 qt_TexCoord;                    \n"
9            "void main() {                                      \n"
10            "    qt_TexCoord = qt_VertexTexCoord;               \n"
11            "    gl_Position = qt_Matrix * qt_VertexPosition;   \n"
12            "}";
13
14
15 static const char wayland_surface_texture_opaque_material_fragment[] =
16            "varying highp vec2 qt_TexCoord;                    \n"
17            "uniform sampler2D qt_Texture;                      \n"
18            "uniform lowp float qt_Opacity;                     \n"
19            "void main() {                                      \n"
20            "    gl_FragColor = vec4(texture2D(qt_Texture, qt_TexCoord).rgb, 1.0) * qt_Opacity; \n"
21            "}";
22
23 static const char wayland_surface_texture_material_fragment[] =
24            "varying highp vec2 qt_TexCoord;                    \n"
25            "uniform sampler2D qt_Texture;                      \n"
26            "uniform lowp float qt_Opacity;                     \n"
27            "void main() {                                      \n"
28            "    gl_FragColor = texture2D(qt_Texture, qt_TexCoord) * qt_Opacity; \n"
29            "}";
30
31 QList<QByteArray> WaylandSurfaceTextureMaterial::attributes() const
32 {
33     QList<QByteArray> attributeList;
34     attributeList << "qt_VertexPosition";
35     attributeList << "qt_VertexTexCoord";
36     return attributeList;
37 }
38
39 void WaylandSurfaceTextureMaterial::updateState(const WaylandSurfaceTextureState *newState, const WaylandSurfaceTextureState *oldState)
40 {
41     Q_UNUSED(oldState);
42     newState->texture()->bind();
43 }
44
45 const char *WaylandSurfaceTextureMaterial::vertexShader() const
46 {
47     return wayland_surface_texture_material_vertex;
48 }
49
50 const char *WaylandSurfaceTextureMaterial::fragmentShader() const
51 {
52     return wayland_surface_texture_material_fragment;
53 }
54
55 QList<QByteArray> WaylandSurfaceTextureOpaqueMaterial::attributes() const
56 {
57     QList<QByteArray> attributeList;
58     attributeList << "qt_VertexPosition";
59     attributeList << "qt_VertexTexCoord";
60     return attributeList;
61 }
62
63 void WaylandSurfaceTextureOpaqueMaterial::updateState(const WaylandSurfaceTextureState *newState, const WaylandSurfaceTextureState *oldState)
64 {
65     Q_UNUSED(oldState);
66     newState->texture()->bind();
67 }
68
69 const char *WaylandSurfaceTextureOpaqueMaterial::vertexShader() const
70 {
71     return wayland_surface_texture_material_vertex;
72 }
73
74 const char *WaylandSurfaceTextureOpaqueMaterial::fragmentShader() const
75 {
76     return wayland_surface_texture_opaque_material_fragment;
77 }