grutil: add thread safety to ShaderTerrainMesh

This commit is contained in:
rdb 2018-09-25 21:00:08 +02:00
parent a6ad608207
commit cd033c27e8
3 changed files with 16 additions and 0 deletions

View File

@ -22,6 +22,7 @@
* @param filename Heightfield texture
*/
INLINE void ShaderTerrainMesh::set_heightfield(Texture* heightfield) {
MutexHolder holder(_lock);
_heightfield_tex = heightfield;
}
@ -33,6 +34,7 @@ INLINE void ShaderTerrainMesh::set_heightfield(Texture* heightfield) {
* @return Path to the heightfield
*/
INLINE Texture* ShaderTerrainMesh::get_heightfield() const {
MutexHolder holder(_lock);
return _heightfield_tex;
}
@ -54,6 +56,7 @@ INLINE Texture* ShaderTerrainMesh::get_heightfield() const {
* @param chunk_size Size of the chunks, has to be a power of two
*/
INLINE void ShaderTerrainMesh::set_chunk_size(size_t chunk_size) {
MutexHolder holder(_lock);
_chunk_size = chunk_size;
}
@ -63,6 +66,7 @@ INLINE void ShaderTerrainMesh::set_chunk_size(size_t chunk_size) {
* @return Chunk size
*/
INLINE size_t ShaderTerrainMesh::get_chunk_size() const {
MutexHolder holder(_lock);
return _chunk_size;
}
@ -81,6 +85,7 @@ INLINE size_t ShaderTerrainMesh::get_chunk_size() const {
* @param generate_patches [description]
*/
INLINE void ShaderTerrainMesh::set_generate_patches(bool generate_patches) {
MutexHolder holder(_lock);
_generate_patches = generate_patches;
}
@ -92,6 +97,7 @@ INLINE void ShaderTerrainMesh::set_generate_patches(bool generate_patches) {
* @return Whether to generate patches
*/
INLINE bool ShaderTerrainMesh::get_generate_patches() const {
MutexHolder holder(_lock);
return _generate_patches;
}
@ -107,6 +113,7 @@ INLINE bool ShaderTerrainMesh::get_generate_patches() const {
* @param target_triangle_width Desired triangle width in pixels
*/
INLINE void ShaderTerrainMesh::set_target_triangle_width(PN_stdfloat target_triangle_width) {
MutexHolder holder(_lock);
_target_triangle_width = target_triangle_width;
}
@ -118,6 +125,7 @@ INLINE void ShaderTerrainMesh::set_target_triangle_width(PN_stdfloat target_tria
* @return Target triangle width
*/
INLINE PN_stdfloat ShaderTerrainMesh::get_target_triangle_width() const {
MutexHolder holder(_lock);
return _target_triangle_width;
}
@ -131,6 +139,7 @@ INLINE PN_stdfloat ShaderTerrainMesh::get_target_triangle_width() const {
* @param update_enabled Whether to update the terrain
*/
INLINE void ShaderTerrainMesh::set_update_enabled(bool update_enabled) {
MutexHolder holder(_lock);
_update_enabled = update_enabled;
}
@ -142,6 +151,7 @@ INLINE void ShaderTerrainMesh::set_update_enabled(bool update_enabled) {
* @return Whether to update the terrain
*/
INLINE bool ShaderTerrainMesh::get_update_enabled() const {
MutexHolder holder(_lock);
return _update_enabled;
}

View File

@ -122,6 +122,7 @@ ShaderTerrainMesh::ShaderTerrainMesh() :
* @return true if the terrain was initialized, false if an error occured
*/
bool ShaderTerrainMesh::generate() {
MutexHolder holder(_lock);
if (!do_check_heightfield())
return false;
@ -461,6 +462,7 @@ bool ShaderTerrainMesh::safe_to_combine() const {
* @copydoc PandaNode::add_for_draw()
*/
void ShaderTerrainMesh::add_for_draw(CullTraverser *trav, CullTraverserData &data) {
MutexHolder holder(_lock);
// Make sure the terrain was properly initialized, and the geom was created
// successfully
@ -711,6 +713,7 @@ void ShaderTerrainMesh::do_emit_chunk(Chunk* chunk, TraversalData* data) {
* @return World-Space point
*/
LPoint3 ShaderTerrainMesh::uv_to_world(const LTexCoord& coord) const {
MutexHolder holder(_lock);
nassertr(_heightfield_tex != nullptr, LPoint3(0)); // Heightfield not set yet
nassertr(_heightfield_tex->has_ram_image(), LPoint3(0)); // Heightfield not in memory

View File

@ -25,6 +25,8 @@
#include "configVariableInt.h"
#include "pStatCollector.h"
#include "filename.h"
#include "pmutex.h"
#include "mutexHolder.h"
#include <stdint.h>
extern ConfigVariableBool stm_use_hexagonal_layout;
@ -160,6 +162,7 @@ private:
void do_emit_chunk(Chunk* chunk, TraversalData* data);
bool do_check_lod_matches(Chunk* chunk, TraversalData* data);
Mutex _lock;
Chunk _base_chunk;
size_t _size;
size_t _chunk_size;