16typedef EXPORT
struct Vertex {
77 Vertex(glm::vec3 p, glm::vec3 n, glm::vec3 tc) {
97 Vertex(glm::vec3 p, glm::vec3 n, glm::vec3 t, glm::vec3 tc) {
106 color = {0, 0, 0, 0};
118 Vertex(glm::vec3 p, glm::vec3 n, glm::vec3 t,
119 glm::vec4 c, glm::vec3 tc) {
143 glm::mat4 *view_matrix;
144 glm::mat4 *projection_matrix;
146 std::vector<std::unique_ptr<Buffer> > vbo;
149 std::vector<std::unique_ptr<Buffer> > ibo;
151 std::vector<Buffer*> attached_buffers;
152 std::vector<GLuint> attached_buffers_targets;
153 std::vector<unsigned int> attached_buffers_indices;
155 void material_uniform();
254 std::vector<std::tuple<std::string, const Texture&, unsigned int> >
auto_textures;
258 std::vector<std::tuple<std::string, const Texture&, unsigned int> >
textures;
286 glm::mat4 *projection_matrix);
389 unsigned int index = 0);
417 template <
typename T>
419 unsigned int number_elements,
420 GLenum usage = GL_STATIC_DRAW);
429 template <
typename T>
431 GLenum usage = GL_STATIC_DRAW);
439 template <
typename T>
442 unsigned int number_elements);
449 template <
typename T>
451 const std::vector<T>& data);
460 template <
typename T>
464 unsigned int number_elements);
472 template <
typename T>
475 const std::vector<T>& data);
489 template <
typename T>
491 GLint number_elements,
494 GLenum usage = GL_STATIC_DRAW);
508 template <
typename T>
510 GLint number_elements,
512 const std::vector<T>& data,
513 GLenum usage = GL_STATIC_DRAW);
527 template <
typename T>
529 GLint number_elements,
532 GLenum usage = GL_STATIC_DRAW);
546 template <
typename T>
548 GLint number_elements,
550 const std::vector<T>& data,
551 GLenum usage = GL_STATIC_DRAW);
571 GLint number_elements,
574 const GLvoid *pointer,
575 unsigned int divisor = 0);
595 GLint number_elements,
598 const GLvoid *pointer,
599 unsigned int divisor = 0);
620 unsigned int buffer_index,
621 GLint number_elements,
624 const GLvoid *pointer,
625 unsigned int divisor = 0);
646 unsigned int buffer_index,
647 GLint number_elements,
650 const GLvoid *pointer,
651 unsigned int divisor = 0);
660 template <
typename T>
669 template <
typename T>
677 EXPORT
void draw(GLenum mode);
696 EXPORT
void draw(GLenum mode,
unsigned int index_buffer,
705 EXPORT
void draw_instanced(GLenum mode,
unsigned int num_instances);
714 EXPORT
void draw_instanced(GLenum mode,
unsigned int index_buffer,
715 unsigned int num_instances);
720 GLint number_elements,
725 std::vector<T> tmp(data, data + number_elements);
732 GLint number_elements,
734 const std::vector<T>& data,
743 GLint number_elements,
748 std::vector<T> tmp(data, data + number_elements);
755 GLint number_elements,
757 const std::vector<T>& data,
766 unsigned int number_elements,
769 std::vector<T> tmp(vertexdata, vertexdata + number_elements);
777 std::unique_ptr<Buffer> buf = std::make_unique<Buffer>(GL_ARRAY_BUFFER);
778 buf->load<T>(vertexdata, usage);
779 vbo.push_back(std::move(buf));
781 return vbo.size() - 1;
787 unsigned int number_elements) {
789 std::vector<T> tmp(data, data + number_elements);
795 const std::vector<T>& data) {
797 if(buffer_index >= vbo.size()) {
799 "buffer_index if greater than the number"
800 "of vertex buffers.");
804 vbo[buffer_index]->replace_data(data);
813 unsigned int number_elements) {
815 std::vector<T> tmp(data, data + number_elements);
822 const std::vector<T>& data) {
824 if(buffer_index >= vbo.size()) {
826 "buffer_index if greater than the number"
827 "of vertex buffers.");
831 return vbo[buffer_index]->replace_partial_data(offset, data);
837 if(index_type && index_type != GL_UNSIGNED_BYTE)
840 index_type = GL_UNSIGNED_BYTE;
841 std::unique_ptr<Buffer> index = std::make_unique<Buffer>(GL_ELEMENT_ARRAY_BUFFER);
842 index->load<
unsigned char>(indices, GL_STATIC_DRAW);
843 ibo.push_back(std::move(index));
844 return ibo.size() - 1;
849 if(index_type && index_type != GL_UNSIGNED_SHORT)
852 index_type = GL_UNSIGNED_SHORT;
853 std::unique_ptr<Buffer> index = std::make_unique<Buffer>(GL_ELEMENT_ARRAY_BUFFER);
854 index->load<
unsigned short>(indices, GL_STATIC_DRAW);
855 ibo.push_back(std::move(index));
856 return ibo.size() - 1;
861 if(index_type && index_type != GL_UNSIGNED_INT)
864 index_type = GL_UNSIGNED_INT;
865 std::unique_ptr<Buffer> index = std::make_unique<Buffer>(GL_ELEMENT_ARRAY_BUFFER);
866 index->load<
unsigned int>(indices, GL_STATIC_DRAW);
867 ibo.push_back(std::move(index));
868 return ibo.size() - 1;
873 glm::vec3 *pos = (glm::vec3 *)(&(vertexdata)[0] + pointer);
876 for(
size_t i = 1; i < vertexdata.size(); i++) {
877 pos = (glm::vec3 *)(&(vertexdata)[i] + pointer);
static std::vector< std::string > error_string
A list of all error strings.
void set_projection_matrix_name(const std::string &name)
Sets the name of the projection matrix in the shader.
void compute_bounding_box(const std::vector< T > &vertexdata, unsigned int pointer)
Computes the bounding box of the mesh.
bool replace_partial_data(unsigned int buffer_index, unsigned int offset, const T *data, unsigned int number_elements)
Modifies the data in a vertex buffer.
int set_buffer_vertex_attribute(const std::string &attrib_name, sgltk::Buffer *buffer, GLint number_elements, GLenum type, GLsizei stride, const GLvoid *pointer, unsigned int divisor=0)
Sets pointers to vertex attributes.
void attach_buffer(const sgltk::Buffer *buffer, GLuint target, unsigned int index=0)
Attaches a buffer that is automatically bound before each draw call.
glm::vec4 color_diffuse
The diffuse color component of the material.
std::string model_view_projection_matrix_name
The name of the model-view-projection matrix in the shader.
std::string view_proj_matrix_name
The name of the view-projection matrix in the shader.
bool twosided
Indicates that the mesh should not be drawn using back face culling.
std::vector< std::tuple< std::string, const Texture &, unsigned int > > textures
Attached user textures.
std::string ambient_color_name
The name of the ambient materiel component.
std::string diffuse_color_name
The name of the diffuse materiel component.
void set_shininess_name(const std::string &name)
Sets the name of the shininess of the material in the shader.
void set_model_view_matrix_name(const std::string &name)
Sets the name of the model-view matrix in the shader.
void set_normal_matrix_name(const std::string &name)
Sets the name of the normal matrix in the shader.
std::string projection_matrix_name
The name of the projection matrix in the shader.
unsigned int attach_vertex_buffer(const T *vertexdata, unsigned int number_elements, GLenum usage=GL_STATIC_DRAW)
Loads data into memory.
std::vector< std::tuple< std::string, const Texture &, unsigned int > > auto_textures
Attached textures.
int attach_index_buffer(const std::vector< T > &indices)
Attaches an index array to the mesh.
void attach_texture(const std::string &name, const sgltk::Texture &texture, unsigned int index=0)
Attaches a texture to the mesh.
void draw_instanced(GLenum mode, unsigned int num_instances)
Renders the mesh multiple times.
void draw(GLenum mode)
Renders the mesh using the first index buffer.
int add_vertex_attribute(std::string attrib_name, GLint number_elements, GLenum type, const T *data, GLenum usage=GL_STATIC_DRAW)
This is a convenience function that combines attach_vertex_buffer and set_vertex_attribute.
void set_ambient_color_name(const std::string &name)
Sets the name of the ambient color in the shader.
std::string model_matrix_name
The name of the model matrix in the shader.
void set_model_matrix_name(const std::string &name)
Sets the name of the model matrix in the shader.
bool replace_buffer_data(unsigned int buffer_index, const T *data, unsigned int number_elements)
Overwrites all data in a vertex buffer.
std::vector< glm::vec3 > bounding_box
The bounding box.
std::string shininess_strength_name
The name of the specular exponent.
void set_diffuse_color_name(const std::string &name)
Sets the name of the diffuse color in the shader.
std::string normal_matrix_name
The name of the normal matrix in the shader.
unsigned int num_col
Number of vertex colors.
void set_shininess_strength_name(const std::string &name)
Sets the name of the shininess strength of the material in the shader.
void setup_shader(Shader *shader)
Specifies the shader to use to render the mesh.
std::string model_view_matrix_name
The name of the model-view matrix in the shader.
Shader * shader
The shader being used to draw the mesh.
float shininess_strength
The strength of the shininess of the material.
glm::vec4 color_ambient
The ambient color component of the material.
void set_specular_color_name(const std::string &name)
Sets the name of the specular color in the shader.
void set_model_view_proj_name(const std::string &name)
Sets the name of the model-view-projection matrix in the shader.
std::string view_matrix_name
The name of the view matrix in the shader.
std::string shininess_name
The name of the specular factor.
bool setup_camera(glm::mat4 *view_matrix, glm::mat4 *projection_matrix)
Sets up the view and projection matrices that will be used by the mesh.
glm::vec4 color_specular
The specular color component of the material.
unsigned int num_vertices
Number of vertices.
void set_transform_feedback_mode(GLenum mode)
Sets the output type for transform feedback operations.
glm::mat4 model_matrix
The model matrix.
int set_vertex_attribute(const std::string &attrib_name, unsigned int buffer_index, GLint number_elements, GLenum type, GLsizei stride, const GLvoid *pointer, unsigned int divisor=0)
Sets pointers to vertex attributes.
unsigned int num_uv
Number of texture coordinates.
std::string specular_color_name
The name of the specular materiel component.
void set_view_proj_matrix_name(const std::string &name)
Sets the name of the view-projection matrix in the shader.
bool wireframe
Indicates that the mesh should be drawn as a wireframe.
float shininess
The shininess of the material.
void set_view_matrix_name(const std::string &name)
Sets the name of the view matrix in the shader.
Vertex(glm::vec3 p, glm::vec3 n)
glm::vec3 normal
Vertex normal.
glm::vec4 bitangent
Vertex bi-tangent.
glm::vec4 color
Vertex color.
glm::vec3 tex_coord
Vertex texture coordinates.
Vertex(glm::vec3 p, glm::vec3 n, glm::vec3 t, glm::vec4 c, glm::vec3 tc)
glm::vec4 tangent
Vertex tangent.
glm::vec4 position
Vertex position.
Vertex(glm::vec3 p, glm::vec3 n, glm::vec3 t, glm::vec3 tc)
Vertex(glm::vec3 p, glm::vec3 n, glm::vec3 tc)