Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Minimum example to create VboMesh from custom vbos.
#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/VboMesh.h"
#include "cinder/gl/gl.h"
using namespace ci;
using namespace ci::app;
//class VboMesh;
using fms = std::chrono::duration<float, std::milli>;
using Clock = std::chrono::steady_clock;
class BasicApp : public App {
public:
void draw() override;
void setup() override;
private:
struct vertex {
vec2 pos;
vec3 color;
};
gl::GlslProgRef m_shader;
gl::BatchRef m_batchAOS;
gl::BatchRef m_batchSOA;
};
void BasicApp::draw()
{
gl::clear();
m_batchSOA->draw();
m_batchAOS->draw();
}
void BasicApp::setup() {
m_shader = gl::GlslProg::create(loadAsset("vertex.vert"), loadAsset("fragment.frag"));
gl::enableDepthRead();
gl::enableDepthWrite();
std::vector<vertex> vertices = {
{vec2(-0.5, 0.5), vec3(1, 0, 0)},
{vec2(-1, -0.5), vec3(0, 1, 0)},
{vec2(0, -0.5), vec3(0, 0, 1)}
};
std::vector<vec2> position {vec2(0.5, 0.5), vec2(0,-0.5), vec2(1, -0.5)};
std::vector<vec3> colors {vec3(1, 0, 1), vec3(1, 1, 0), vec3(0, 1, 1)};
/**
* @brief try array of structures layout!
*/
auto vbo = gl::Vbo::create(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW);
geom::BufferLayout layout;
layout.append(geom::CUSTOM_0, 2, sizeof(vertex), offsetof(vertex, pos));
layout.append(geom::CUSTOM_1, 3, sizeof(vertex), offsetof(vertex, color));
auto meshAOS = gl::VboMesh::create(
vertices.size(),
GL_TRIANGLES,
{{layout, vbo}}
);
auto glsl = gl::GlslProg::create(loadAsset("vertex.vert"), loadAsset("fragment.frag"));
gl::Batch::AttributeMapping map = {{geom::CUSTOM_0, "pos"},{geom::CUSTOM_1, "color"}};
m_batchAOS = gl::Batch::create(meshAOS, m_shader, map);
/**
* @brief try structure of arrays layout!
*/
auto vboPos = gl::Vbo::create(GL_ARRAY_BUFFER, position);
auto vboColor = gl::Vbo::create(GL_ARRAY_BUFFER, colors);
auto meshSOA = gl::VboMesh::create(
(uint32_t)3, GL_TRIANGLES,
{
{geom::BufferLayout({geom::AttribInfo(geom::CUSTOM_0, 2, 0, 0)}), vboPos},
{geom::BufferLayout({geom::AttribInfo(geom::CUSTOM_1, 3, 0, 0)}), vboColor}
}
);
m_batchSOA = gl::Batch::create(meshSOA, m_shader, map);
}
CINDER_APP( BasicApp, RendererGl )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment