mesh_drawable
Mesh stored on the GPU (VBOs, shader, texture, model transform), ready to be drawn.
Fields and methods
Members of the struct mesh_drawable. Most of what you do with a CGP type goes through the free functions listed below.
Fields
opengl_shader_structure default_shader | Static shader shared by all mesh_drawable and used by default in initialize_data_on_gpu, loaded from shaders/mesh/mesh.vert.glsl and mesh.frag.glsl by the application. |
opengl_texture_image_structure default_texture | Static 1x1 white RGBA texture shared by all mesh_drawable and used by default in initialize_data_on_gpu. |
opengl_shader_structure shader | Shader program used to draw this drawable, which must be valid (non-zero id) at draw time. |
opengl_texture_image_structure texture | Main texture bound to texture unit 0 and sent to the uniform image_texture at draw time. |
std::map<std::string,opengl_texture_image_structure> supplementary_texture | Additional textures for multi-texturing, keyed by uniform name and bound to texture units 1, 2, ... in the order of the map at draw time. |
opengl_vbo_structure vbo_position | VBO storing the vertex positions, bound to shader location 0. |
opengl_vbo_structure vbo_normal | VBO storing the vertex normals, bound to shader location 1. |
opengl_vbo_structure vbo_color | VBO storing the vertex colors, bound to shader location 2. |
opengl_vbo_structure vbo_uv | VBO storing the vertex texture coordinates, bound to shader location 3. |
std::vector<opengl_vbo_structure> supplementary_vbo | Optional extra VBOs (per-vertex or per-instance), where the element k is bound to shader location k+4. |
opengl_ebo_structure ebo_connectivity | EBO storing the triangle indices used by the indexed draw call. |
GLuint vao = 0 | OpenGL id of the Vertex Array Object describing the VBO layout, 0 when not initialized. |
affine model | Model transform of the drawable (translation, rotation, scaling, scaling_xyz), reset to identity by initialize_data_on_gpu and clear. |
affine_rts hierarchy_transform_model | Global transform set by hierarchy_mesh_drawable::update_local_to_global_coordinates, applied first in the model matrix sent to the shader. |
mat4 supplementary_model_matrix = mat4::build_identity() | Generic 4x4 matrix inserted between hierarchy_transform_model and model in the model matrix, identity by default and reset by initialize_data_on_gpu. |
material_mesh_drawable_phong material | Phong material (color, alpha, shading coefficients, texture settings) sent to the uniform struct material at draw time. |
Methods
| Checks the mesh with mesh_check, uploads its position, normal, color, uv and connectivity into new VBOs, an EBO and a VAO (locations 0 to 3), and resets model, material and supplementary_model_matrix, keeping a previously set shader or texture when the default one is passed. src | |
| Deletes the VBOs (including the supplementary ones), the EBO and the VAO, and resets shader, texture, supplementary_texture, model and material without deleting the shader program or the textures. src | |
| Sends the uniform model = hierarchy_transform_model * supplementary_model_matrix * model and the material uniforms to the current shader. src | |
| Uploads an extra vec2, vec3 or vec4 array into supplementary_vbo and binds it in the VAO at location_index (which must be at least 4), with divisor greater than 0 for per-instance data. src | |
| Overwrites the content of the supplementary VBO at location_index (at least 4, already initialized) without reallocation, sending only the first size_elements_update elements when it is not -1. src |
Functions taking a mesh_drawable
Draw 2
void draw(
mesh_drawable const& drawable,
environment_generic_structure const& environment = environment_generic_structure(),
int instance_count = 1,
bool expected_uniforms = true,
uniform_generic_structure const& additional_uniforms = uniform_generic_structure(),
GLenum draw_mode = GL_TRIANGLES,
material_mesh_drawable_phong const* material_override = nullptr
)Draw a mesh_drawable with its shader, textures, model and material, plus the environment and optional additional uniforms, possibly instanced or with an overriding material.
void draw_wireframe(
mesh_drawable const& drawable,
environment_generic_structure const& environment = environment_generic_structure(),
vec3 const& color = {0,0,1},
int instance_count = 1,
bool expected_uniforms = true,
uniform_generic_structure const& additional_uniforms = uniform_generic_structure()
)Draw the triangle edges of a mesh_drawable in a flat color, slightly offset toward the camera (no effect with Emscripten/WebGL).
Functions returning a mesh_drawable
None.
Operators
None.