From 9bdc13e3fcb0d2340052ae36983a39f28f95f9e2 Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Thu, 24 Jan 2019 16:29:26 +0100 Subject: [PATCH] starting to abstract the vertext buffers --- src/core/include/pw/core/matrix.hpp | 2 +- src/scripting/src/script.cpp | 3 +- src/visual/src/pipeline.cpp | 52 +++++++++++++++++++++-------- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/core/include/pw/core/matrix.hpp b/src/core/include/pw/core/matrix.hpp index 0fcdc4d..27cf492 100644 --- a/src/core/include/pw/core/matrix.hpp +++ b/src/core/include/pw/core/matrix.hpp @@ -57,7 +57,7 @@ struct matrix_ : matrixbase_> return *this; } - explicit matrix_(std::initializer_list args) + matrix_(std::initializer_list args) { typename std::initializer_list::iterator it = args.begin(); for (;it != args.end();it++) data[it-args.begin()] = *it; diff --git a/src/scripting/src/script.cpp b/src/scripting/src/script.cpp index e455c64..0d24f5e 100644 --- a/src/scripting/src/script.cpp +++ b/src/scripting/src/script.cpp @@ -59,11 +59,10 @@ void script::state::load_all() { // open all libraries _state.open_libraries(); - // for (auto m : runtime_lua::get().register_functions()) { m.second(_state,_namespace); - debug::d() << "loading module " << m.first; +// debug::d() << "loading module " << m.first; } } diff --git a/src/visual/src/pipeline.cpp b/src/visual/src/pipeline.cpp index ced54c3..87e5817 100644 --- a/src/visual/src/pipeline.cpp +++ b/src/visual/src/pipeline.cpp @@ -1,6 +1,8 @@ #include "pw/core/size.hpp" #include "pw/core/matrix.hpp" +#include "pw/core/mesh.hpp" + #include "pw/core/debug.hpp" #include "pw/visual/pipeline.hpp" @@ -19,30 +21,54 @@ struct triangle_renderer GLuint shader_programme = 0; shader shader_p; + mesh amesh; triangle_renderer() { } - void setup() { - float points[] = { - 0.0f, 0.5f, 0.0f, - 0.5f, -0.5f, 0.0f, - -0.5f, -0.5f, 0.0f +// float points[] = { +// 0.0f, 0.5f, 0.0f, +// 0.5f, -0.5f, 0.0f, +// -0.5f, -0.5f, 0.0f +// }; + + + mesh::vertex3array_t vertices = { + {0.0f, 0.5f, 0.0f} + ,{0.5f, -0.5f, 0.0f} + ,{-0.5f, -0.5f, 0.0f} }; + mesh::indexarray_t indices = { 0, 1, 2}; + + amesh.set_indices(indices); + amesh.set_vertices(vertices); + + size_t vertex_size_bytes = amesh.vertices().size() * sizeof(mesh::vertex3array_t::value_type); + size_t vertex_stride = amesh.vertices().front().size(); + + + debug::d() << 9 * sizeof(mesh::vertex3array_t::value_type::value_type) << " " + << vertex_size_bytes; + + + +// sizeof(mesh::vertex3array_t::value_type) +// 9 * sizeof(mesh::vertex3array_t::value_type::value_type) + glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); - glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(float), points, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, vertex_size_bytes , amesh.vertices().data(), GL_STATIC_DRAW); glGenVertexArrays(1, &vao); glBindVertexArray(vao); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vbo); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr); + glVertexAttribPointer(0, vertex_stride, GL_FLOAT, GL_FALSE, 0, nullptr); const char* vertex_shader = "#version 400\n" @@ -52,12 +78,12 @@ struct triangle_renderer "}"; - const char* fragment_shader = - "#version 400\n" - "out vec4 frag_colour;" - "void main() {" - " frag_colour = vec4(0.1, 0.0, 0.5, 1.0);" - "}"; + const char *fragment_shader = R"(#version 400 + out vec4 frag_colour; + void main() { + frag_colour = vec4(0.5, 0.5, 0.5, 1.0); + })"; + #if 0 GLuint vs = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vs, 1, &vertex_shader, NULL);