Mark buffer as dirty in mesh helpers

unclear if this fixes any actual bug
This commit is contained in:
sfan5 2024-09-10 20:29:02 +02:00
parent 0fdcba197f
commit cc26b5384c
2 changed files with 11 additions and 6 deletions

View File

@ -34,7 +34,7 @@ inline static void applyShadeFactor(video::SColor& color, float factor)
color.setBlue(core::clamp(core::round32(color.getBlue()*factor), 0, 255)); color.setBlue(core::clamp(core::round32(color.getBlue()*factor), 0, 255));
} }
void applyFacesShading(video::SColor &color, const v3f &normal) void applyFacesShading(video::SColor &color, const v3f normal)
{ {
/* /*
Some drawtypes have normals set to (0, 0, 0), this must result in Some drawtypes have normals set to (0, 0, 0), this must result in
@ -133,6 +133,7 @@ void scaleMesh(scene::IMesh *mesh, v3f scale)
for (u32 i = 0; i < vertex_count; i++) for (u32 i = 0; i < vertex_count; i++)
((video::S3DVertex *)(vertices + i * stride))->Pos *= scale; ((video::S3DVertex *)(vertices + i * stride))->Pos *= scale;
buf->setDirty(scene::EBT_VERTEX);
buf->recalculateBoundingBox(); buf->recalculateBoundingBox();
// calculate total bounding box // calculate total bounding box
@ -161,6 +162,7 @@ void translateMesh(scene::IMesh *mesh, v3f vec)
for (u32 i = 0; i < vertex_count; i++) for (u32 i = 0; i < vertex_count; i++)
((video::S3DVertex *)(vertices + i * stride))->Pos += vec; ((video::S3DVertex *)(vertices + i * stride))->Pos += vec;
buf->setDirty(scene::EBT_VERTEX);
buf->recalculateBoundingBox(); buf->recalculateBoundingBox();
// calculate total bounding box // calculate total bounding box
@ -172,16 +174,17 @@ void translateMesh(scene::IMesh *mesh, v3f vec)
mesh->setBoundingBox(bbox); mesh->setBoundingBox(bbox);
} }
void setMeshBufferColor(scene::IMeshBuffer *buf, const video::SColor &color) void setMeshBufferColor(scene::IMeshBuffer *buf, const video::SColor color)
{ {
const u32 stride = getVertexPitchFromType(buf->getVertexType()); const u32 stride = getVertexPitchFromType(buf->getVertexType());
u32 vertex_count = buf->getVertexCount(); u32 vertex_count = buf->getVertexCount();
u8 *vertices = (u8 *) buf->getVertices(); u8 *vertices = (u8 *) buf->getVertices();
for (u32 i = 0; i < vertex_count; i++) for (u32 i = 0; i < vertex_count; i++)
((video::S3DVertex *) (vertices + i * stride))->Color = color; ((video::S3DVertex *) (vertices + i * stride))->Color = color;
buf->setDirty(scene::EBT_VERTEX);
} }
void setMeshColor(scene::IMesh *mesh, const video::SColor &color) void setMeshColor(scene::IMesh *mesh, const video::SColor color)
{ {
if (mesh == NULL) if (mesh == NULL)
return; return;
@ -202,6 +205,7 @@ static void applyToMesh(scene::IMesh *mesh, const F &fn)
char *vertices = reinterpret_cast<char *>(buf->getVertices()); char *vertices = reinterpret_cast<char *>(buf->getVertices());
for (u32 i = 0; i < vertex_count; i++) for (u32 i = 0; i < vertex_count; i++)
fn(reinterpret_cast<video::S3DVertex *>(vertices + i * stride)); fn(reinterpret_cast<video::S3DVertex *>(vertices + i * stride));
buf->setDirty(scene::EBT_VERTEX);
} }
} }
@ -218,6 +222,7 @@ void colorizeMeshBuffer(scene::IMeshBuffer *buf, const video::SColor *buffercolo
// Apply shading // Apply shading
applyFacesShading(*vc, vertex->Normal); applyFacesShading(*vc, vertex->Normal);
} }
buf->setDirty(scene::EBT_VERTEX);
} }
void setMeshColorByNormalXYZ(scene::IMesh *mesh, void setMeshColorByNormalXYZ(scene::IMesh *mesh,

View File

@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
* Applies shading to a color based on the surface's * Applies shading to a color based on the surface's
* normal vector. * normal vector.
*/ */
void applyFacesShading(video::SColor &color, const v3f &normal); void applyFacesShading(video::SColor &color, const v3f normal);
/* /*
Create a new cube mesh. Create a new cube mesh.
@ -52,12 +52,12 @@ void translateMesh(scene::IMesh *mesh, v3f vec);
/*! /*!
* Sets a constant color for all vertices in the mesh buffer. * Sets a constant color for all vertices in the mesh buffer.
*/ */
void setMeshBufferColor(scene::IMeshBuffer *buf, const video::SColor &color); void setMeshBufferColor(scene::IMeshBuffer *buf, const video::SColor color);
/* /*
Set a constant color for all vertices in the mesh Set a constant color for all vertices in the mesh
*/ */
void setMeshColor(scene::IMesh *mesh, const video::SColor &color); void setMeshColor(scene::IMesh *mesh, const video::SColor color);
/*! /*!
* Overwrites the color of a mesh buffer. * Overwrites the color of a mesh buffer.