27 shader->
uniform(
"color", glm::mix(vec3(1,0,0), vec3(1,1,0), (
float)(0.5 + 0.5*sin(args.
time*5))));
42 glBindBuffer(GL_ARRAY_BUFFER, 0);
46 glBufferData(GL_ARRAY_BUFFER,
m_normals.size() *
sizeof(vec3),
m_normals.data(), GL_STATIC_DRAW);
47 glBindBuffer(GL_ARRAY_BUFFER, 0);
51 glBufferData(GL_ARRAY_BUFFER,
m_uvs.size() *
sizeof(vec2),
m_uvs.data(), GL_STATIC_DRAW);
52 glBindBuffer(GL_ARRAY_BUFFER, 0);
56 glBufferData(GL_ELEMENT_ARRAY_BUFFER,
m_indices.size() *
sizeof(uint),
m_indices.data(), GL_STATIC_DRAW);
57 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
60 glGenVertexArrays(1, &
m_vao);
61 glBindVertexArray(
m_vao);
65 glEnableVertexAttribArray(positionIndex);
66 glVertexAttribPointer(positionIndex, 3, GL_FLOAT, GL_FALSE, 0, 0);
70 glEnableVertexAttribArray(normalIndex);
71 glVertexAttribPointer(normalIndex, 3, GL_FLOAT, GL_FALSE, 0, 0);
75 glEnableVertexAttribArray(uvIndex);
76 glVertexAttribPointer(uvIndex, 2, GL_FLOAT, GL_FALSE, 0, 0);
81 glBindBuffer(GL_ARRAY_BUFFER, 0);
82 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
90 glDeleteVertexArrays(1, &
m_vao);
94 glBindVertexArray(
m_vao);
98 instance->prepareDraw(args, shader);
100 glDrawElements(GL_TRIANGLES,
m_indices.size(), GL_UNSIGNED_INT, 0);
103 glBindVertexArray(0);
131 void copy_to_mesh(vector<vec3>* _positions, vector<vec3>* _normals, vector<vec2>* _uvs, vector<uint>* _idx,
132 float const *positions,
float const * normals,
float const *uvs, uint
const *indices,
size_t vertexCount,
size_t indexCount)
134 _positions->resize(vertexCount);
135 memcpy(_positions->data(), positions, vertexCount *
sizeof(vec3));
137 _normals->resize(vertexCount);
138 memcpy(_normals->data(), normals, vertexCount *
sizeof(vec3));
140 _uvs->resize(vertexCount);
141 memcpy(_uvs->data(), uvs, vertexCount *
sizeof(vec2));
143 _idx->resize(indexCount);
144 memcpy(_idx->data(), indices, indexCount *
sizeof(uint));
146 function<void(vector<vec3>*, vector<vec3>*, vector<vec2>*, vector<uint>*)>
create_mesh(
float const *positions,
float const * normals,
float const *uvs, uint
const *indices,
size_t vertexCount,
size_t indexCount)
148 return [positions, normals, uvs, indices, vertexCount, indexCount]
149 (vector<vec3>* _positions, vector<vec3>* _normals, vector<vec2>* _uvs, vector<uint>* _idx)
151 copy_to_mesh(_positions, _normals, _uvs, _idx, positions, normals, uvs, indices, vertexCount, indexCount);
159 , m_shader(m_app->getShaders().get(
"mesh"))
183 return found->second.get();
194 mesh.second->drawAllInstances(args,
m_shader);
Transformation m_transformation
void copy_to_mesh(vector< vec3 > *_positions, vector< vec3 > *_normals, vector< vec2 > *_uvs, vector< uint > *_idx, float const *positions, float const *normals, float const *uvs, uint const *indices, size_t vertexCount, size_t indexCount)
uint16 id_t
The data-type used for the id-buffer.
vector< vec3 > m_positions
SimpleMeshes(Application *app)
const float plane_positions[]
t_obj & add(t_obj *object)
SimpleMeshInstance * createInstance(bool pickable=true)
set< SimpleMeshInstance * > m_instances
static const uint position
void prepareDraw(DrawArgs &args, Shader *shader)
map< string, function< void(Shader *)> > m_uniforms
function< void(vector< vec3 > *, vector< vec3 > *, vector< vec2 > *, vector< uint > *)> create_mesh(float const *positions, float const *normals, float const *uvs, uint const *indices, size_t vertexCount, size_t indexCount)
SimpleMesh * get(string const &name)
SceneGraph & getSceneGraph()
const float cube_positions[]
mat4 const * projectionMatrix
const float cube_normals[]
void drawAllInstances(DrawArgs &args, Shader *shader)
const unsigned int cube_indices[]
const unsigned int plane_indices[]
SimpleMesh * create(string const &name, t_fnc fnc)
void unregisterInstance(SimpleMeshInstance *obj)
void drawAll(DrawArgs &args)
virtual ~SimpleMeshInstance()
const float plane_normals[]
virtual bool update(double time, double timeDelta)
GLint uniform(string const &name)
SimpleMeshInstance(Application *app, SimpleMesh *mesh, bool pickable=true)