summaryrefslogtreecommitdiff
path: root/scene/resources/material.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/material.cpp')
-rw-r--r--scene/resources/material.cpp40
1 files changed, 6 insertions, 34 deletions
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index ff51cab0a4..54e9067abb 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -290,17 +290,13 @@ ShaderMaterial::~ShaderMaterial() {
/////////////////////////////////
-Mutex *BaseMaterial3D::material_mutex = NULL;
+Mutex BaseMaterial3D::material_mutex;
SelfList<BaseMaterial3D>::List *BaseMaterial3D::dirty_materials = NULL;
Map<BaseMaterial3D::MaterialKey, BaseMaterial3D::ShaderData> BaseMaterial3D::shader_map;
BaseMaterial3D::ShaderNames *BaseMaterial3D::shader_names = NULL;
void BaseMaterial3D::init_shaders() {
-#ifndef NO_THREADS
- material_mutex = Mutex::create();
-#endif
-
dirty_materials = memnew(SelfList<BaseMaterial3D>::List);
shader_names = memnew(ShaderNames);
@@ -379,10 +375,6 @@ void BaseMaterial3D::finish_shaders() {
materials_for_2d[i].unref();
}
-#ifndef NO_THREADS
- memdelete(material_mutex);
-#endif
-
memdelete(dirty_materials);
dirty_materials = NULL;
@@ -1133,44 +1125,28 @@ void BaseMaterial3D::_update_shader() {
void BaseMaterial3D::flush_changes() {
- if (material_mutex)
- material_mutex->lock();
+ MutexLock lock(material_mutex);
while (dirty_materials->first()) {
dirty_materials->first()->self()->_update_shader();
}
-
- if (material_mutex)
- material_mutex->unlock();
}
void BaseMaterial3D::_queue_shader_change() {
- if (material_mutex)
- material_mutex->lock();
+ MutexLock lock(material_mutex);
if (!element.in_list()) {
dirty_materials->add(&element);
}
-
- if (material_mutex)
- material_mutex->unlock();
}
bool BaseMaterial3D::_is_shader_dirty() const {
- bool dirty = false;
-
- if (material_mutex)
- material_mutex->lock();
-
- dirty = element.in_list();
+ MutexLock lock(material_mutex);
- if (material_mutex)
- material_mutex->unlock();
-
- return dirty;
+ return element.in_list();
}
void BaseMaterial3D::set_albedo(const Color &p_albedo) {
@@ -2580,8 +2556,7 @@ BaseMaterial3D::BaseMaterial3D(bool p_orm) :
BaseMaterial3D::~BaseMaterial3D() {
- if (material_mutex)
- material_mutex->lock();
+ MutexLock lock(material_mutex);
if (shader_map.has(current_key)) {
shader_map[current_key].users--;
@@ -2593,9 +2568,6 @@ BaseMaterial3D::~BaseMaterial3D() {
VS::get_singleton()->material_set_shader(_get_material(), RID());
}
-
- if (material_mutex)
- material_mutex->unlock();
}
//////////////////////