Fix mesh render update blocking main UI

master
Jeremy Hu 2018-09-18 15:20:51 +08:00
parent 1ab3d16bd4
commit d3e28e88f2
2 changed files with 24 additions and 8 deletions

View File

@ -10,9 +10,10 @@
ModelMeshBinder::ModelMeshBinder() :
m_mesh(nullptr),
m_newMesh(nullptr),
m_renderTriangleVertexCount(0),
m_renderEdgeVertexCount(0),
m_meshUpdated(false),
m_newMeshComing(false),
m_showWireframes(false),
m_hasTexture(false),
m_texture(nullptr)
@ -22,16 +23,17 @@ ModelMeshBinder::ModelMeshBinder() :
ModelMeshBinder::~ModelMeshBinder()
{
delete m_mesh;
delete m_newMesh;
delete m_texture;
}
void ModelMeshBinder::updateMesh(MeshLoader *mesh)
{
QMutexLocker lock(&m_meshMutex);
QMutexLocker lock(&m_newMeshMutex);
if (mesh != m_mesh) {
delete m_mesh;
m_mesh = mesh;
m_meshUpdated = true;
delete m_newMesh;
m_newMesh = mesh;
m_newMeshComing = true;
}
}
@ -114,9 +116,22 @@ void ModelMeshBinder::initialize()
void ModelMeshBinder::paint(ModelShaderProgram *program)
{
MeshLoader *newMesh = nullptr;
bool hasNewMesh = false;
if (m_newMeshComing) {
QMutexLocker lock(&m_newMeshMutex);
if (m_newMeshComing) {
newMesh = m_newMesh;
m_newMesh = nullptr;
m_newMeshComing = false;
hasNewMesh = true;
}
}
{
QMutexLocker lock(&m_meshMutex);
if (m_meshUpdated) {
if (hasNewMesh) {
delete m_mesh;
m_mesh = newMesh;
if (m_mesh) {
m_hasTexture = nullptr != m_mesh->textureImage();
delete m_texture;
@ -166,7 +181,6 @@ void ModelMeshBinder::paint(ModelShaderProgram *program)
m_renderTriangleVertexCount = 0;
m_renderEdgeVertexCount = 0;
}
m_meshUpdated = false;
}
}

View File

@ -24,9 +24,10 @@ public:
bool isWireframesVisible();
private:
MeshLoader *m_mesh;
MeshLoader *m_newMesh;
int m_renderTriangleVertexCount;
int m_renderEdgeVertexCount;
bool m_meshUpdated;
bool m_newMeshComing;
bool m_showWireframes;
bool m_hasTexture;
QOpenGLTexture *m_texture;
@ -36,6 +37,7 @@ private:
QOpenGLVertexArrayObject m_vaoEdge;
QOpenGLBuffer m_vboEdge;
QMutex m_meshMutex;
QMutex m_newMeshMutex;
};
#endif