summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Rodin <mrodin@de.adit-jv.com>2018-11-15 09:21:16 +0100
committerMichael Rodin <mrodin@de.adit-jv.com>2018-11-27 16:51:39 +0100
commit620e4c5790b4f479d681ead03932b30c51994a22 (patch)
treeeab564b17c2757b41d348c68a0a448e24069f58a
parentc2fca1e3e7e554826096fd179c1e5c72d403edb0 (diff)
downloadwayland-ivi-extension-620e4c5790b4f479d681ead03932b30c51994a22.tar.gz
EGLWLMockNavigation: add ShaderTexture class
This class supports mapping of textures, which were already loaded using TextureLoader class. ShaderTexture is derived from ShaderBase class, like ShaderLighting. Also add the following new files to CMakeLists.txt : include/ShaderTexture.h src/ShaderTexture.cpp Signed-off-by: Michael Rodin <mrodin@de.adit-jv.com>
-rw-r--r--ivi-layermanagement-examples/EGLWLMockNavigation/CMakeLists.txt2
-rw-r--r--ivi-layermanagement-examples/EGLWLMockNavigation/include/ShaderTexture.h41
-rw-r--r--ivi-layermanagement-examples/EGLWLMockNavigation/src/ShaderTexture.cpp96
3 files changed, 139 insertions, 0 deletions
diff --git a/ivi-layermanagement-examples/EGLWLMockNavigation/CMakeLists.txt b/ivi-layermanagement-examples/EGLWLMockNavigation/CMakeLists.txt
index 5b92848..a43ff86 100644
--- a/ivi-layermanagement-examples/EGLWLMockNavigation/CMakeLists.txt
+++ b/ivi-layermanagement-examples/EGLWLMockNavigation/CMakeLists.txt
@@ -76,6 +76,7 @@ set (HEADER_FILES
include/ShaderBase.h
include/ShaderLighting.h
include/TextureLoader.h
+ include/ShaderTexture.h
)
set (SRC_FILES
@@ -91,6 +92,7 @@ set (SRC_FILES
src/ShaderLighting.cpp
src/main.cpp
src/TextureLoader.cpp
+ src/ShaderTexture.cpp
)
add_executable(${PROJECT_NAME}
diff --git a/ivi-layermanagement-examples/EGLWLMockNavigation/include/ShaderTexture.h b/ivi-layermanagement-examples/EGLWLMockNavigation/include/ShaderTexture.h
new file mode 100644
index 0000000..859f0a7
--- /dev/null
+++ b/ivi-layermanagement-examples/EGLWLMockNavigation/include/ShaderTexture.h
@@ -0,0 +1,41 @@
+/***************************************************************************
+ *
+ * Copyright (C) 2018 Advanced Driver Information Technology Joint Venture GmbH
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
+#ifndef SHADERTEXTURE_H_
+#define SHADERTEXTURE_H_
+
+#include "ShaderBase.h"
+
+class ShaderTexture: public ShaderBase {
+public:
+ ShaderTexture(float* projectionMatrix);
+ virtual ~ShaderTexture();
+
+ virtual void use(vec3f* position, GLuint textureID);
+
+ GLint getAttributeTexCoord();
+ void setTexCoords(vec2f * m_texCoords);
+
+private:
+ int m_uniformModelMatrix;
+ int m_uniformColor;
+ GLint m_uniformSampler;
+ GLint attributeTexCoord;
+};
+
+#endif /* SHADERTEXTURE_H_ */
diff --git a/ivi-layermanagement-examples/EGLWLMockNavigation/src/ShaderTexture.cpp b/ivi-layermanagement-examples/EGLWLMockNavigation/src/ShaderTexture.cpp
new file mode 100644
index 0000000..f04d0a2
--- /dev/null
+++ b/ivi-layermanagement-examples/EGLWLMockNavigation/src/ShaderTexture.cpp
@@ -0,0 +1,96 @@
+/***************************************************************************
+ *
+ * Copyright (C) 2018 Advanced Driver Information Technology Joint Venture GmbH
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
+#include "ShaderTexture.h"
+
+const static char* vertexShaderCode =
+ "attribute mediump vec4 a_vertex; \
+ uniform mediump mat4 u_modelMatrix; \
+ attribute mediump vec2 a_texCoord; \
+ varying mediump vec2 v_texCoord; \
+ void main(void) \
+ { \
+ gl_Position = u_projectionMatrix * u_modelMatrix * a_vertex; \
+ v_texCoord = a_texCoord; \
+ }";
+
+const static char* fragmentShaderCode =
+ "varying mediump vec2 v_texCoord; \
+ uniform sampler2D s_texture; \
+ void main (void) \
+ { \
+ gl_FragColor = texture2D(s_texture, v_texCoord); \
+ }";
+
+ShaderTexture::ShaderTexture(float* projectionMatrix)
+: ShaderBase(vertexShaderCode, fragmentShaderCode, projectionMatrix)
+{
+ glUseProgram(shaderProgramId);
+ m_uniformModelMatrix = glGetUniformLocation(shaderProgramId, "u_modelMatrix");
+ m_uniformSampler = glGetUniformLocation(shaderProgramId, "s_texture");
+ attributeTexCoord = glGetAttribLocation(shaderProgramId, "a_texCoord");
+}
+
+ShaderTexture::~ShaderTexture()
+{
+}
+
+void ShaderTexture::use(vec3f* position, GLuint textureID)
+{
+ ShaderBase::use(position, nullptr);
+
+ float translation[16];
+ translation[0] = 1.0f;
+ translation[1] = 0.0f;
+ translation[2] = 0.0f;
+ translation[3] = 0.0f;
+
+ translation[4] = 0.0f;
+ translation[5] = 1.0f;
+ translation[6] = 0.0f;
+ translation[7] = 0.0f;
+
+ translation[8] = 0.0f;
+ translation[9] = 0.0f;
+ translation[10] = 1.0f;
+ translation[11] = 0.0f;
+
+ translation[12] = position->x;
+ translation[13] = position->y;
+ translation[14] = position->z;
+ translation[15] = 1.0f;
+
+ glUseProgram(shaderProgramId);
+ glUniformMatrix4fv(m_uniformModelMatrix, 1, GL_FALSE, translation);
+
+ // Code for using textures
+ // select active texture unit
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, textureID);
+ // Set the sampler texture unit to 0: GL_TEXTURE0
+ glUniform1i(m_uniformSampler, 0);
+}
+
+GLint ShaderTexture::getAttributeTexCoord() {
+ return attributeTexCoord;
+}
+
+void ShaderTexture::setTexCoords(vec2f * m_texCoords){
+ glEnableVertexAttribArray(attributeTexCoord);
+ glVertexAttribPointer(attributeTexCoord, 2, GL_FLOAT, GL_FALSE, 0, m_texCoords);
+}