testing uniforms and shaders
This commit is contained in:
parent
0f823dd419
commit
0f5058bd18
4 changed files with 40 additions and 13 deletions
|
@ -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
|
#ifndef PW_SYSTEM_PATH_HPP
|
||||||
#define PW_SYSTEM_PATH_HPP
|
#define PW_SYSTEM_PATH_HPP
|
||||||
|
|
||||||
|
@ -18,8 +40,6 @@ public:
|
||||||
|
|
||||||
typedef std::vector<std::string> path_list;
|
typedef std::vector<std::string> path_list;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
path_list _plugin_paths;
|
path_list _plugin_paths;
|
||||||
|
|
|
@ -47,7 +47,7 @@ path::~path()
|
||||||
std::string path::separator()
|
std::string path::separator()
|
||||||
{
|
{
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
return std::string("\");
|
return std::string("\\");
|
||||||
#else
|
#else
|
||||||
return std::string("/");
|
return std::string("/");
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "pw/core/matrix.hpp"
|
#include "pw/core/matrix.hpp"
|
||||||
#include "pw/core/mesh.hpp"
|
#include "pw/core/mesh.hpp"
|
||||||
#include "pw/core/timer.hpp"
|
#include "pw/core/timer.hpp"
|
||||||
|
#include "pw/core/axisangle.hpp"
|
||||||
|
|
||||||
#include "pw/core/debug.hpp"
|
#include "pw/core/debug.hpp"
|
||||||
#include "pw/visual/pipeline.hpp"
|
#include "pw/visual/pipeline.hpp"
|
||||||
|
@ -118,11 +119,11 @@ struct triangle_renderer
|
||||||
|
|
||||||
const char* vertex_shader_2 = R"(
|
const char* vertex_shader_2 = R"(
|
||||||
#version 400
|
#version 400
|
||||||
|
uniform mat4 model_mat;
|
||||||
in vec3 vertex_p;
|
in vec3 vertex_p;
|
||||||
in vec3 normal_p;
|
|
||||||
|
|
||||||
void main() {
|
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;
|
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(fragment_shader,shader::fragment);
|
||||||
shader_p.set_source(vertex_shader,shader::vertex);
|
|
||||||
|
|
||||||
if (!shader_p.build())
|
if (!shader_p.build())
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw()
|
void draw()
|
||||||
{
|
{
|
||||||
double t0 = timer::now();
|
double t0 = timer::now();
|
||||||
|
|
||||||
shader_p.use();
|
shader_p.use();
|
||||||
|
|
||||||
static float v = 0.0f;
|
static float v = 0.0f;
|
||||||
v+= 0.01f;
|
v+= 0.01f;
|
||||||
if (v>1.0f) v = 0.0f;
|
if (v>1.0f) v = 0.0f;
|
||||||
vector4f test({0.5f,1-v,v,1.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("input_color",test);
|
||||||
|
shader_p.bind("model_mat",model_mat);
|
||||||
|
|
||||||
amesh_renderer.draw();
|
amesh_renderer.draw();
|
||||||
|
|
||||||
debug::d() << 100 * (timer::now() - t0) << "ms";
|
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);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -185,6 +185,11 @@ shader &shader::bind(int location, const vector4f &v)
|
||||||
_impl->bind(location,v); return *this;
|
_impl->bind(location,v); return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shader &shader::bind(int location, const matrix4x4f &v)
|
||||||
|
{
|
||||||
|
_impl->bind(location,v); return *this;
|
||||||
|
}
|
||||||
|
|
||||||
bool shader::build()
|
bool shader::build()
|
||||||
{
|
{
|
||||||
return _impl->build();
|
return _impl->build();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue