starting to abstract the vertext buffers

This commit is contained in:
Hartmut Seichter 2019-01-24 16:29:26 +01:00
parent baa209ceea
commit 9bdc13e3fc
3 changed files with 41 additions and 16 deletions

View file

@ -57,7 +57,7 @@ struct matrix_ : matrixbase_<T, matrix_<R, C, T>>
return *this;
}
explicit matrix_(std::initializer_list<T> args)
matrix_(std::initializer_list<T> args)
{
typename std::initializer_list<T>::iterator it = args.begin();
for (;it != args.end();it++) data[it-args.begin()] = *it;

View file

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

View file

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