|
libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
|
A single OpenGL sub-mesh: geometry buffers, texture bindings, and deformers. More...
#include <model.hpp>
Public Member Functions | |
| Mesh () | |
| Default constructor — zeroes all buffer IDs. | |
| ~Mesh () | |
| Destructor — calls cleanup(). | |
| Mesh (const Mesh &m)=delete | |
| Mesh & | operator= (const Mesh &m)=delete |
| Mesh (Mesh &&m) noexcept | |
| Move constructor. | |
| Mesh & | operator= (Mesh &&m) noexcept |
| Move-assign operator. | |
| void | compressIndices () |
| Build an optimised index list from the flat vertex arrays. | |
| void | generateBuffers () |
| Upload vertex data to the GPU (must be called after populating arrays). | |
| void | cleanup () |
| Delete all GL objects (VAO, VBOs, textures). | |
| void | draw () |
| Issue a GL draw call using the stored VAO/index count. | |
| void | drawWithForcedTexture (gl::ShaderProgram &shader, GLuint texture, const std::string texture_name) |
| Draw with a texture override without changing the mesh's stored texture. | |
| void | setShapeType (GLuint type) |
| Set the GL primitive drawing type. | |
| void | bindTexture (gl::ShaderProgram &shader, const std::string texture_name) |
| Bind the mesh's primary texture to a shader sampler. | |
| void | bindCubemapTexture (gl::ShaderProgram &shader, GLuint cubemap, const std::string texture_name) |
| Bind a cubemap texture to a shader sampler. | |
| void | saveOriginal () |
| Take a snapshot of the current vertex and normal arrays. | |
| void | resetToOriginal () |
| Restore vertex and normal arrays from the last saveOriginal() snapshot. | |
| void | updateBuffers () |
| Synchronise CPU-side vertex data to the GPU buffers. | |
| void | recalculateNormals () |
| Recompute per-vertex normals from the current vertex positions. | |
| void | setNormalMap (GLuint normalMapTexture) |
| void | setParallaxMap (GLuint heightMapTexture) |
| void | setDisplacementMap (GLuint displacementMapTexture) |
| void | setAmbientOcclusionMap (GLuint aoMapTexture) |
| void | generateTangentBitangent () |
| Compute tangent and bitangent vectors for normal mapping. | |
| void | uvScroll (float uOffset, float vOffset) |
| Scroll UV coordinates by an offset. | |
| void | uvScale (float uScale, float vScale) |
| Scale UV coordinates. | |
| void | uvRotate (float angle) |
| Rotate UV coordinates around the origin. | |
| void | applyChromaticAberration (float intensity) |
| Apply a chromatic aberration effect to vertex colours. | |
| void | applyColorGrading (const glm::vec3 &colorShift) |
| Shift vertex colours by a multiplied colour vector. | |
| void | applyHSV (float hueShift, float saturation, float value) |
| Apply hue/saturation/value adjustment to vertex colours. | |
| void | setCubemapBlending (GLuint cubemap1, GLuint cubemap2, float blendFactor) |
| Blend between two cubemap textures in the shader. | |
| GLuint | getNormalMap () const |
| GLuint | getParallaxMap () const |
| GLuint | getAmbientOcclusionMap () const |
| void | scale (float factor) |
| Uniformly scale all vertices. | |
| void | scale (float sx, float sy, float sz) |
| Non-uniformly scale vertices along each axis. | |
| void | bend (DeformAxis axis, float angle, float center=0.0f, float range=1.0f) |
| Bend the mesh around an axis. | |
| void | twist (DeformAxis axis, float angle, float center=0.0f) |
| Twist vertices around an axis. | |
| void | wave (DeformAxis axis, float amplitude, float frequency, float phase=0.0f) |
| Apply a sinusoidal wave deformation. | |
| void | ripple (float amplitude, float frequency, float phase=0.0f, float cx=0.0f, float cy=0.0f, float cz=0.0f) |
| Apply a radial ripple deformation centred on a point. | |
| void | noise (float amplitude, unsigned int seed=12345) |
| Add random noise to vertex positions. | |
| void | taper (DeformAxis axis, float factor, float center=0.0f) |
| Taper (scale cross-section) along an axis. | |
| void | bulge (float factor, float cx=0.0f, float cy=0.0f, float cz=0.0f, float radius=1.0f) |
| Bulge vertices outward from a sphere centre. | |
| void | morph (float t) |
| Interpolate (morph) vertices between original and current. | |
| void | translate (float tx, float ty, float tz) |
| Translate all vertices by an offset. | |
| void | rotate (DeformAxis axis, float angle) |
| Rotate all vertices around an axis. | |
Public Attributes | |
| std::vector< GLfloat > | vert |
| Vertex position data (x,y,z triples). | |
| std::vector< GLfloat > | tex |
| Texture coordinate data (u,v pairs). | |
| std::vector< GLfloat > | norm |
| Normal vector data (x,y,z triples). | |
| std::vector< GLfloat > | tangent |
| Tangent vector data. | |
| std::vector< GLfloat > | bitangent |
| Bitangent vector data. | |
| std::vector< GLuint > | indices |
| Optional index list for indexed drawing. | |
| std::vector< GLfloat > | originalVert |
| Saved copy of vertex positions. | |
| std::vector< GLfloat > | originalNorm |
| Saved copy of normals. | |
| bool | hasOriginal |
| Whether an original snapshot exists. | |
| GLuint | shape_type |
| GL primitive type (e.g. GL_TRIANGLES). | |
| GLuint | texture |
| Primary diffuse texture ID. | |
| std::string | materialName |
| Material name from OBJ usemtl directive. | |
| GLuint | EBO |
| GLuint | VAO |
| GLuint | positionVBO |
| GLuint | normalVBO |
| GLuint | texCoordVBO |
| GLuint | tangentVBO |
| GLuint | bitangentVBO |
| GLuint | normalMapTexture |
| Normal map texture ID. | |
| GLuint | parallaxMapTexture |
| Parallax/height map texture ID. | |
| GLuint | aoMapTexture |
| Ambient occlusion map texture ID. | |
| GLuint | displacementMapTexture |
| Displacement map texture ID. | |
| size_t | vertIndex |
| Current write position in the vertex array. | |
| size_t | texIndex |
| Current write position in the UV array. | |
| size_t | normIndex |
| Current write position in the normal array. | |
A single OpenGL sub-mesh: geometry buffers, texture bindings, and deformers.
Stores vertex, normal, UV, tangent, and bitangent arrays together with an optional index list. All geometry lives in CPU memory and must be synchronised to the GPU via generateBuffers() / updateBuffers(). A snapshot of the original geometry can be preserved with saveOriginal() and restored with resetToOriginal().
| mx::Mesh::Mesh | ( | ) |
Default constructor — zeroes all buffer IDs.
Definition at line 70 of file model.cpp.
References aoMapTexture, bitangentVBO, displacementMapTexture, EBO, hasOriginal, normalMapTexture, normalVBO, normIndex, parallaxMapTexture, positionVBO, shape_type, tangentVBO, texCoordVBO, texIndex, texture, VAO, and vertIndex.
Referenced by Mesh(), Mesh(), operator=(), and operator=().
| mx::Mesh::~Mesh | ( | ) |
|
delete |
References Mesh().
|
noexcept |
Move constructor.
Definition at line 77 of file model.cpp.
References aoMapTexture, bitangent, bitangentVBO, displacementMapTexture, EBO, hasOriginal, indices, materialName, Mesh(), norm, normalMapTexture, normalVBO, normIndex, originalNorm, originalVert, parallaxMapTexture, positionVBO, shape_type, tangent, tangentVBO, tex, texCoordVBO, texIndex, texture, VAO, vert, and vertIndex.
| void mx::Mesh::applyChromaticAberration | ( | float | intensity | ) |
| void mx::Mesh::applyColorGrading | ( | const glm::vec3 & | colorShift | ) |
| void mx::Mesh::applyHSV | ( | float | hueShift, |
| float | saturation, | ||
| float | value ) |
| void mx::Mesh::bend | ( | DeformAxis | axis, |
| float | angle, | ||
| float | center = 0.0f, | ||
| float | range = 1.0f ) |
| void mx::Mesh::bindCubemapTexture | ( | gl::ShaderProgram & | shader, |
| GLuint | cubemap, | ||
| const std::string | texture_name ) |
Bind a cubemap texture to a shader sampler.
| shader | Bound shader program. |
| cubemap | GL cubemap texture ID. |
| texture_name | Uniform sampler name. |
Definition at line 325 of file model.cpp.
References gl::ShaderProgram::setUniform().
| void mx::Mesh::bindTexture | ( | gl::ShaderProgram & | shader, |
| const std::string | texture_name ) |
Bind the mesh's primary texture to a shader sampler.
| shader | Bound shader program. |
| texture_name | Uniform sampler name. |
Definition at line 299 of file model.cpp.
References normalMapTexture, gl::ShaderProgram::setUniform(), and texture.
| void mx::Mesh::bulge | ( | float | factor, |
| float | cx = 0.0f, | ||
| float | cy = 0.0f, | ||
| float | cz = 0.0f, | ||
| float | radius = 1.0f ) |
| void mx::Mesh::cleanup | ( | ) |
Delete all GL objects (VAO, VBOs, textures).
Definition at line 155 of file model.cpp.
References bitangentVBO, EBO, normalVBO, positionVBO, tangentVBO, texCoordVBO, and VAO.
Referenced by operator=(), and ~Mesh().
| void mx::Mesh::compressIndices | ( | ) |
Build an optimised index list from the flat vertex arrays.
Definition at line 175 of file model.cpp.
References indices, norm, mx::Vertex::normal, mx::Vertex::position, tex, mx::Vertex::texCoord, and vert.
Referenced by mx::Model::openModelString(), and mx::Model::openOBJ().
| void mx::Mesh::draw | ( | ) |
Issue a GL draw call using the stored VAO/index count.
Definition at line 292 of file model.cpp.
References indices, shape_type, VAO, and vert.
Referenced by drawWithForcedTexture().
| void mx::Mesh::drawWithForcedTexture | ( | gl::ShaderProgram & | shader, |
| GLuint | texture, | ||
| const std::string | texture_name ) |
Draw with a texture override without changing the mesh's stored texture.
| shader | Bound shader program. |
| texture | Temporary GL texture to use. |
| texture_name | Uniform sampler name in the shader. |
Definition at line 311 of file model.cpp.
References draw(), normalMapTexture, and gl::ShaderProgram::setUniform().
| void mx::Mesh::generateBuffers | ( | ) |
Upload vertex data to the GPU (must be called after populating arrays).
Definition at line 242 of file model.cpp.
References bitangent, bitangentVBO, EBO, indices, norm, normalVBO, positionVBO, tangent, tangentVBO, tex, texCoordVBO, VAO, and vert.
Referenced by mx::Model::openModelString(), and mx::Model::openOBJ().
| void mx::Mesh::generateTangentBitangent | ( | ) |
Compute tangent and bitangent vectors for normal mapping.
Definition at line 388 of file model.cpp.
References bitangent, indices, tangent, tex, and vert.
Referenced by mx::Model::openModelString(), and mx::Model::openOBJ().
|
inline |
Definition at line 223 of file model.hpp.
References aoMapTexture.
|
inline |
Definition at line 219 of file model.hpp.
References normalMapTexture.
|
inline |
Definition at line 221 of file model.hpp.
References parallaxMapTexture.
| void mx::Mesh::morph | ( | float | t | ) |
Interpolate (morph) vertices between original and current.
| t | Interpolation factor (0 = original, 1 = current). |
| void mx::Mesh::noise | ( | float | amplitude, |
| unsigned int | seed = 12345 ) |
Add random noise to vertex positions.
| amplitude | Noise magnitude. |
| seed | RNG seed for reproducibility. |
References aoMapTexture, displacementMapTexture, Mesh(), normalMapTexture, and texture.
Move-assign operator.
Definition at line 113 of file model.cpp.
References aoMapTexture, bitangent, bitangentVBO, cleanup(), displacementMapTexture, EBO, hasOriginal, indices, materialName, Mesh(), norm, normalMapTexture, normalVBO, normIndex, originalNorm, originalVert, parallaxMapTexture, positionVBO, shape_type, tangent, tangentVBO, tex, texCoordVBO, texIndex, texture, VAO, vert, and vertIndex.
| void mx::Mesh::recalculateNormals | ( | ) |
Recompute per-vertex normals from the current vertex positions.
Definition at line 345 of file model.cpp.
References indices, norm, and vert.
Referenced by mx::Model::openModelString(), and mx::Model::openOBJ().
| void mx::Mesh::resetToOriginal | ( | ) |
Restore vertex and normal arrays from the last saveOriginal() snapshot.
Definition at line 337 of file model.cpp.
References hasOriginal, norm, originalNorm, originalVert, updateBuffers(), and vert.
| void mx::Mesh::ripple | ( | float | amplitude, |
| float | frequency, | ||
| float | phase = 0.0f, | ||
| float | cx = 0.0f, | ||
| float | cy = 0.0f, | ||
| float | cz = 0.0f ) |
| void mx::Mesh::rotate | ( | DeformAxis | axis, |
| float | angle ) |
Rotate all vertices around an axis.
| axis | Rotation axis. |
| angle | Angle in degrees. |
| void mx::Mesh::saveOriginal | ( | ) |
Take a snapshot of the current vertex and normal arrays.
Definition at line 331 of file model.cpp.
References hasOriginal, norm, originalNorm, originalVert, and vert.
| void mx::Mesh::scale | ( | float | factor | ) |
| void mx::Mesh::scale | ( | float | sx, |
| float | sy, | ||
| float | sz ) |
| void mx::Mesh::setAmbientOcclusionMap | ( | GLuint | aoMapTexture | ) |
| aoMapTexture | GL texture ID to use as an ambient-occlusion map. |
Definition at line 590 of file model.cpp.
References aoMapTexture.
Blend between two cubemap textures in the shader.
| cubemap1 | First cubemap GL ID. |
| cubemap2 | Second cubemap GL ID. |
| blendFactor | Interpolation factor (0 = fully cubemap1, 1 = fully cubemap2). |
| void mx::Mesh::setDisplacementMap | ( | GLuint | displacementMapTexture | ) |
| displacementMapTexture | GL texture ID to use as a displacement map. |
Definition at line 589 of file model.cpp.
References displacementMapTexture.
| void mx::Mesh::setNormalMap | ( | GLuint | normalMapTexture | ) |
| normalMapTexture | GL texture ID to use as a normal map. |
Definition at line 587 of file model.cpp.
References normalMapTexture.
| void mx::Mesh::setParallaxMap | ( | GLuint | heightMapTexture | ) |
| heightMapTexture | GL texture ID to use as a parallax/height map. |
Definition at line 588 of file model.cpp.
References parallaxMapTexture.
| void mx::Mesh::setShapeType | ( | GLuint | type | ) |
Set the GL primitive drawing type.
| type | GL_TRIANGLES, GL_LINES, etc. |
Definition at line 166 of file model.cpp.
References shape_type.
Referenced by mx::Model::openModelString(), and mx::Model::openOBJ().
| void mx::Mesh::taper | ( | DeformAxis | axis, |
| float | factor, | ||
| float | center = 0.0f ) |
Taper (scale cross-section) along an axis.
| axis | Taper axis. |
| factor | Taper rate. |
| center | Centre position. |
| void mx::Mesh::translate | ( | float | tx, |
| float | ty, | ||
| float | tz ) |
| void mx::Mesh::twist | ( | DeformAxis | axis, |
| float | angle, | ||
| float | center = 0.0f ) |
| void mx::Mesh::updateBuffers | ( | ) |
Synchronise CPU-side vertex data to the GPU buffers.
Definition at line 270 of file model.cpp.
References norm, normalVBO, positionVBO, tex, texCoordVBO, VAO, and vert.
Referenced by resetToOriginal().
| void mx::Mesh::uvRotate | ( | float | angle | ) |
Rotate UV coordinates around the origin.
| angle | Rotation angle in degrees. |
| void mx::Mesh::uvScale | ( | float | uScale, |
| float | vScale ) |
Scale UV coordinates.
| uScale | U-axis scale factor. |
| vScale | V-axis scale factor. |
| void mx::Mesh::uvScroll | ( | float | uOffset, |
| float | vOffset ) |
Scroll UV coordinates by an offset.
| uOffset | U-axis scroll amount. |
| vOffset | V-axis scroll amount. |
Definition at line 572 of file model.cpp.
References tex, and texCoordVBO.
| void mx::Mesh::wave | ( | DeformAxis | axis, |
| float | amplitude, | ||
| float | frequency, | ||
| float | phase = 0.0f ) |
| GLuint mx::Mesh::aoMapTexture |
Ambient occlusion map texture ID.
Definition at line 86 of file model.hpp.
Referenced by getAmbientOcclusionMap(), Mesh(), Mesh(), operator=(), operator=(), and setAmbientOcclusionMap().
| std::vector<GLfloat> mx::Mesh::bitangent |
Bitangent vector data.
Definition at line 72 of file model.hpp.
Referenced by mx::Model::dumpMeshStats(), generateBuffers(), generateTangentBitangent(), Mesh(), mx::Model::openModelString(), mx::Model::openOBJ(), operator=(), and mx::Model::parseLine().
| GLuint mx::Mesh::bitangentVBO |
Definition at line 82 of file model.hpp.
Referenced by cleanup(), generateBuffers(), Mesh(), Mesh(), and operator=().
| GLuint mx::Mesh::displacementMapTexture |
Displacement map texture ID.
Definition at line 87 of file model.hpp.
Referenced by Mesh(), Mesh(), operator=(), operator=(), and setDisplacementMap().
| GLuint mx::Mesh::EBO |
Definition at line 82 of file model.hpp.
Referenced by cleanup(), generateBuffers(), Mesh(), Mesh(), and operator=().
| bool mx::Mesh::hasOriginal |
Whether an original snapshot exists.
Definition at line 77 of file model.hpp.
Referenced by Mesh(), Mesh(), operator=(), resetToOriginal(), and saveOriginal().
| std::vector<GLuint> mx::Mesh::indices |
Optional index list for indexed drawing.
Definition at line 73 of file model.hpp.
Referenced by compressIndices(), draw(), mx::Model::dumpMeshStats(), generateBuffers(), generateTangentBitangent(), Mesh(), mx::Model::openModelString(), mx::Model::openOBJ(), operator=(), mx::Model::parseLine(), and recalculateNormals().
| std::string mx::Mesh::materialName |
Material name from OBJ usemtl directive.
Definition at line 80 of file model.hpp.
Referenced by Mesh(), mx::Model::openOBJ(), and operator=().
| std::vector<GLfloat> mx::Mesh::norm |
Normal vector data (x,y,z triples).
Definition at line 70 of file model.hpp.
Referenced by compressIndices(), mx::Model::dumpMeshStats(), generateBuffers(), Mesh(), mx::Model::openModelString(), mx::Model::openOBJ(), operator=(), mx::Model::parseLine(), recalculateNormals(), resetToOriginal(), saveOriginal(), and updateBuffers().
| GLuint mx::Mesh::normalMapTexture |
Normal map texture ID.
Definition at line 84 of file model.hpp.
Referenced by bindTexture(), drawWithForcedTexture(), getNormalMap(), Mesh(), Mesh(), operator=(), operator=(), and setNormalMap().
| GLuint mx::Mesh::normalVBO |
Definition at line 82 of file model.hpp.
Referenced by cleanup(), generateBuffers(), Mesh(), Mesh(), operator=(), and updateBuffers().
| size_t mx::Mesh::normIndex |
Current write position in the normal array.
Definition at line 91 of file model.hpp.
Referenced by Mesh(), Mesh(), operator=(), and mx::Model::parseLine().
| std::vector<GLfloat> mx::Mesh::originalNorm |
Saved copy of normals.
Definition at line 75 of file model.hpp.
Referenced by Mesh(), operator=(), resetToOriginal(), and saveOriginal().
| std::vector<GLfloat> mx::Mesh::originalVert |
Saved copy of vertex positions.
Definition at line 74 of file model.hpp.
Referenced by Mesh(), operator=(), resetToOriginal(), and saveOriginal().
| GLuint mx::Mesh::parallaxMapTexture |
Parallax/height map texture ID.
Definition at line 85 of file model.hpp.
Referenced by getParallaxMap(), Mesh(), Mesh(), operator=(), and setParallaxMap().
| GLuint mx::Mesh::positionVBO |
Definition at line 82 of file model.hpp.
Referenced by cleanup(), generateBuffers(), Mesh(), Mesh(), operator=(), and updateBuffers().
| GLuint mx::Mesh::shape_type |
GL primitive type (e.g. GL_TRIANGLES).
Definition at line 78 of file model.hpp.
Referenced by draw(), Mesh(), Mesh(), operator=(), and setShapeType().
| std::vector<GLfloat> mx::Mesh::tangent |
Tangent vector data.
Definition at line 71 of file model.hpp.
Referenced by mx::Model::dumpMeshStats(), generateBuffers(), generateTangentBitangent(), Mesh(), mx::Model::openModelString(), mx::Model::openOBJ(), operator=(), and mx::Model::parseLine().
| GLuint mx::Mesh::tangentVBO |
Definition at line 82 of file model.hpp.
Referenced by cleanup(), generateBuffers(), Mesh(), Mesh(), and operator=().
| std::vector<GLfloat> mx::Mesh::tex |
Texture coordinate data (u,v pairs).
Definition at line 69 of file model.hpp.
Referenced by compressIndices(), mx::Model::dumpMeshStats(), generateBuffers(), generateTangentBitangent(), Mesh(), mx::Model::openModelString(), mx::Model::openOBJ(), operator=(), mx::Model::parseLine(), updateBuffers(), and uvScroll().
| GLuint mx::Mesh::texCoordVBO |
Definition at line 82 of file model.hpp.
Referenced by cleanup(), generateBuffers(), Mesh(), Mesh(), operator=(), updateBuffers(), and uvScroll().
| size_t mx::Mesh::texIndex |
Current write position in the UV array.
Definition at line 90 of file model.hpp.
Referenced by Mesh(), Mesh(), operator=(), and mx::Model::parseLine().
| GLuint mx::Mesh::texture |
Primary diffuse texture ID.
Definition at line 79 of file model.hpp.
Referenced by bindTexture(), Mesh(), Mesh(), mx::Model::openModelString(), mx::Model::openOBJ(), operator=(), and operator=().
| GLuint mx::Mesh::VAO |
Definition at line 82 of file model.hpp.
Referenced by cleanup(), draw(), generateBuffers(), Mesh(), Mesh(), operator=(), and updateBuffers().
| std::vector<GLfloat> mx::Mesh::vert |
Vertex position data (x,y,z triples).
Definition at line 68 of file model.hpp.
Referenced by bend(), bulge(), compressIndices(), draw(), mx::Model::dumpMeshStats(), generateBuffers(), generateTangentBitangent(), Mesh(), mx::Model::openModelString(), mx::Model::openOBJ(), operator=(), mx::Model::parseLine(), recalculateNormals(), resetToOriginal(), ripple(), saveOriginal(), scale(), translate(), twist(), updateBuffers(), and wave().
| size_t mx::Mesh::vertIndex |
Current write position in the vertex array.
Definition at line 89 of file model.hpp.
Referenced by Mesh(), Mesh(), operator=(), and mx::Model::parseLine().