From 0f5058bd18e9499d2109c1facb0e41a436c41092 Mon Sep 17 00:00:00 2001
From: Hartmut Seichter <hartmut@technotecture.com>
Date: Thu, 7 Feb 2019 11:04:10 +0100
Subject: [PATCH] testing uniforms and shaders

---
 src/system/include/pw/system/path.hpp | 24 ++++++++++++++++++++++--
 src/system/src/path.cpp               |  2 +-
 src/visual/src/pipeline.cpp           | 22 ++++++++++++----------
 src/visual/src/shader.cpp             |  5 +++++
 4 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/src/system/include/pw/system/path.hpp b/src/system/include/pw/system/path.hpp
index 2812c45..0dd1fb7 100644
--- a/src/system/include/pw/system/path.hpp
+++ b/src/system/include/pw/system/path.hpp
@@ -1,3 +1,25 @@
+/*
+ * Copyright (c) 1999-2019 Hartmut Seichter
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
 #ifndef PW_SYSTEM_PATH_HPP
 #define PW_SYSTEM_PATH_HPP
 
@@ -18,8 +40,6 @@ public:
 
 	typedef std::vector<std::string> path_list;
 
-
-
 protected:
 
 	path_list _plugin_paths;
diff --git a/src/system/src/path.cpp b/src/system/src/path.cpp
index 2d50105..102b654 100644
--- a/src/system/src/path.cpp
+++ b/src/system/src/path.cpp
@@ -47,7 +47,7 @@ path::~path()
 std::string path::separator()
 {
 #if defined(WIN32)
-	return std::string("\");
+    return std::string("\\");
 #else
 	return std::string("/");
 #endif
diff --git a/src/visual/src/pipeline.cpp b/src/visual/src/pipeline.cpp
index eb25bc4..e1952bf 100644
--- a/src/visual/src/pipeline.cpp
+++ b/src/visual/src/pipeline.cpp
@@ -2,6 +2,7 @@
 #include "pw/core/matrix.hpp"
 #include "pw/core/mesh.hpp"
 #include "pw/core/timer.hpp"
+#include "pw/core/axisangle.hpp"
 
 #include "pw/core/debug.hpp"
 #include "pw/visual/pipeline.hpp"
@@ -118,11 +119,11 @@ struct triangle_renderer
 
 		const char* vertex_shader_2 = R"(
 				#version 400
+                uniform mat4 model_mat;
 				in vec3 vertex_p;
-				in vec3 normal_p;
 
 				void main() {
-					gl_Position = vec4(vp, 1.0);
+                    gl_Position = model_mat * vec4(vertex_p, 1.0);
 				}
 				)";
 
@@ -134,36 +135,37 @@ struct triangle_renderer
 				  frag_colour = input_color;
 				})";
 
-
+        shader_p.set_source(vertex_shader_2,shader::vertex);
         shader_p.set_source(fragment_shader,shader::fragment);
-        shader_p.set_source(vertex_shader,shader::vertex);
 
 		if (!shader_p.build())
 			exit(-1);
-
-
     }
 
     void draw()
     {
 		double t0 = timer::now();
 
-		shader_p.use();
+        shader_p.use();
 
 		static float v = 0.0f;
 		v+= 0.01f;
 		if (v>1.0f) v = 0.0f;
 		vector4f test({0.5f,1-v,v,1.0f});
 
+        matrix4x4f model_mat; model_mat.set_identity();
+
+        axisangle rot(vector3::right(),v);
+        model_mat = rot.to_matrix();
+
+        // highly inefficient - should be cached -
 		shader_p.bind("input_color",test);
+        shader_p.bind("model_mat",model_mat);
 
 		amesh_renderer.draw();
 
 		debug::d() << 100 * (timer::now() - t0) << "ms";
 
-//        glBindVertexArray(vao);
-        // draw points 0-3 from the currently bound VAO with current in-use shader
-//        glDrawArrays(GL_TRIANGLES, 0, 3);
     }
 };
 
diff --git a/src/visual/src/shader.cpp b/src/visual/src/shader.cpp
index 5419046..3c55f0a 100644
--- a/src/visual/src/shader.cpp
+++ b/src/visual/src/shader.cpp
@@ -185,6 +185,11 @@ shader &shader::bind(int location, const vector4f &v)
 	_impl->bind(location,v); return *this;
 }
 
+shader &shader::bind(int location, const matrix4x4f &v)
+{
+    _impl->bind(location,v); return *this;
+}
+
 bool shader::build()
 {
 	return _impl->build();