testing uniforms and shaders

This commit is contained in:
Hartmut Seichter 2019-02-07 11:04:10 +01:00
parent 0f823dd419
commit 0f5058bd18
4 changed files with 40 additions and 13 deletions

View file

@ -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;

View file

@ -47,7 +47,7 @@ path::~path()
std::string path::separator()
{
#if defined(WIN32)
return std::string("\");
return std::string("\\");
#else
return std::string("/");
#endif

View file

@ -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,14 +135,11 @@ 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()
@ -155,15 +153,19 @@ struct triangle_renderer
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);
}
};

View file

@ -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();