mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-05 21:00:39 +02:00
adding locking to updateGeometry method to prevent race conditions
This commit is contained in:
parent
9fd30581d1
commit
0131a502cc
4 changed files with 41 additions and 27 deletions
|
@ -23,6 +23,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EntityItemPointer RenderableQuadEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
|
EntityItemPointer RenderableQuadEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
|
||||||
return EntityItemPointer(new RenderableQuadEntityItem(entityID, properties));
|
return EntityItemPointer(new RenderableQuadEntityItem(entityID, properties));
|
||||||
}
|
}
|
||||||
|
@ -70,25 +72,28 @@ int generateColor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableQuadEntityItem::updateGeometry() {
|
void RenderableQuadEntityItem::updateGeometry() {
|
||||||
if (_pointsChanged) {
|
|
||||||
int compactColor = generateColor();
|
int compactColor = generateColor();
|
||||||
_numVertices = 0;
|
_numVertices = 0;
|
||||||
_verticesBuffer.reset(new gpu::Buffer());
|
_verticesBuffer.reset(new gpu::Buffer());
|
||||||
int vertexIndex = 0;
|
int vertexIndex = 0;
|
||||||
for (int i = 0; i < _normals.size(); i++) {
|
for (int i = 0; i < _normals.size(); i++) {
|
||||||
compactColor = generateColor();
|
compactColor = generateColor();
|
||||||
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex++));
|
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex));
|
||||||
|
vertexIndex++;
|
||||||
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i));
|
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i));
|
||||||
_verticesBuffer->append(sizeof(int), (gpu::Byte*)&compactColor);
|
_verticesBuffer->append(sizeof(int), (gpu::Byte*)&compactColor);
|
||||||
|
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex));
|
||||||
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex++));
|
vertexIndex++;
|
||||||
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i));
|
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i));
|
||||||
_verticesBuffer->append(sizeof(int), (gpu::Byte*)&compactColor);
|
_verticesBuffer->append(sizeof(int), (gpu::Byte*)&compactColor);
|
||||||
|
|
||||||
_numVertices +=2;
|
_numVertices +=2;
|
||||||
}
|
}
|
||||||
_pointsChanged = false;
|
_pointsChanged = false;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,12 +107,14 @@ void RenderableQuadEntityItem::render(RenderArgs* args) {
|
||||||
createPipeline();
|
createPipeline();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PerformanceTimer perfTimer("RenderableQuadEntityItem::render");
|
PerformanceTimer perfTimer("RenderableQuadEntityItem::render");
|
||||||
Q_ASSERT(getType() == EntityTypes::Quad);
|
Q_ASSERT(getType() == EntityTypes::Quad);
|
||||||
|
|
||||||
Q_ASSERT(args->_batch);
|
Q_ASSERT(args->_batch);
|
||||||
|
if (_pointsChanged) {
|
||||||
updateGeometry();
|
updateGeometry();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
gpu::Batch& batch = *args->_batch;
|
gpu::Batch& batch = *args->_batch;
|
||||||
Transform transform = Transform();
|
Transform transform = Transform();
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "RenderableDebugableEntityItem.h"
|
#include "RenderableDebugableEntityItem.h"
|
||||||
#include "RenderableEntityItem.h"
|
#include "RenderableEntityItem.h"
|
||||||
#include <GeometryCache.h>
|
#include <GeometryCache.h>
|
||||||
|
#include <QReadWriteLock>
|
||||||
|
|
||||||
class RenderableQuadEntityItem : public QuadEntityItem {
|
class RenderableQuadEntityItem : public QuadEntityItem {
|
||||||
public:
|
public:
|
||||||
|
@ -35,6 +36,7 @@ protected:
|
||||||
void updateGeometry();
|
void updateGeometry();
|
||||||
gpu::BufferPointer _verticesBuffer;
|
gpu::BufferPointer _verticesBuffer;
|
||||||
unsigned int _numVertices;
|
unsigned int _numVertices;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ _vertices(QVector<glm::vec3>(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityItemProperties QuadEntityItem::getProperties() const {
|
EntityItemProperties QuadEntityItem::getProperties() const {
|
||||||
|
_quadReadWriteLock.lockForWrite();
|
||||||
EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class
|
EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,11 +59,12 @@ EntityItemProperties QuadEntityItem::getProperties() const {
|
||||||
|
|
||||||
properties._glowLevel = getGlowLevel();
|
properties._glowLevel = getGlowLevel();
|
||||||
properties._glowLevelChanged = false;
|
properties._glowLevelChanged = false;
|
||||||
|
_quadReadWriteLock.unlock();
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QuadEntityItem::setProperties(const EntityItemProperties& properties) {
|
bool QuadEntityItem::setProperties(const EntityItemProperties& properties) {
|
||||||
|
_quadReadWriteLock.lockForWrite();
|
||||||
bool somethingChanged = false;
|
bool somethingChanged = false;
|
||||||
somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class
|
somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class
|
||||||
|
|
||||||
|
@ -83,7 +84,10 @@ bool QuadEntityItem::setProperties(const EntityItemProperties& properties) {
|
||||||
}
|
}
|
||||||
setLastEdited(properties._lastEdited);
|
setLastEdited(properties._lastEdited);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_quadReadWriteLock.unlock();
|
||||||
return somethingChanged;
|
return somethingChanged;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QuadEntityItem::appendPoint(const glm::vec3& point) {
|
bool QuadEntityItem::appendPoint(const glm::vec3& point) {
|
||||||
|
@ -106,7 +110,6 @@ bool QuadEntityItem::setNormals(const QVector<glm::vec3> &normals) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_normals = normals;
|
_normals = normals;
|
||||||
qDebug() << "NORMALS: " << normals;
|
|
||||||
_vertices.clear();
|
_vertices.clear();
|
||||||
//Go through and create vertices for triangle strip based on normals
|
//Go through and create vertices for triangle strip based on normals
|
||||||
if (_normals.size() != _points.size()) {
|
if (_normals.size() != _points.size()) {
|
||||||
|
@ -114,10 +117,11 @@ bool QuadEntityItem::setNormals(const QVector<glm::vec3> &normals) {
|
||||||
}
|
}
|
||||||
glm::vec3 v1, v2, tangent, binormal, point;
|
glm::vec3 v1, v2, tangent, binormal, point;
|
||||||
for (int i = 0; i < _points.size()-1; i++) {
|
for (int i = 0; i < _points.size()-1; i++) {
|
||||||
|
float width = (static_cast <float> (rand()) / static_cast <float> (RAND_MAX) * .1) + .02;
|
||||||
point = _points.at(i);
|
point = _points.at(i);
|
||||||
//Get tangent
|
//Get tangent
|
||||||
tangent = _points.at(i+1) - point;
|
tangent = _points.at(i+1) - point;
|
||||||
binormal = glm::normalize(glm::cross(tangent, normals.at(i))) * _lineWidth;
|
binormal = glm::normalize(glm::cross(tangent, normals.at(i))) * width;
|
||||||
v1 = point + binormal;
|
v1 = point + binormal;
|
||||||
v2 = point - binormal;
|
v2 = point - binormal;
|
||||||
_vertices << v1 << v2;
|
_vertices << v1 << v2;
|
||||||
|
@ -172,7 +176,7 @@ bool QuadEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
|
||||||
int QuadEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
|
int QuadEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
|
||||||
ReadBitstreamToTreeParams& args,
|
ReadBitstreamToTreeParams& args,
|
||||||
EntityPropertyFlags& propertyFlags, bool overwriteLocalData) {
|
EntityPropertyFlags& propertyFlags, bool overwriteLocalData) {
|
||||||
|
_quadReadWriteLock.lockForWrite();
|
||||||
int bytesRead = 0;
|
int bytesRead = 0;
|
||||||
const unsigned char* dataAt = data;
|
const unsigned char* dataAt = data;
|
||||||
|
|
||||||
|
@ -181,7 +185,7 @@ int QuadEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data,
|
||||||
READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector<glm::vec3>, setLinePoints);
|
READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector<glm::vec3>, setLinePoints);
|
||||||
READ_ENTITY_PROPERTY(PROP_NORMALS, QVector<glm::vec3>, setNormals);
|
READ_ENTITY_PROPERTY(PROP_NORMALS, QVector<glm::vec3>, setNormals);
|
||||||
|
|
||||||
|
_quadReadWriteLock.unlock();
|
||||||
return bytesRead;
|
return bytesRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ class QuadEntityItem : public EntityItem {
|
||||||
QVector<glm::vec3> _points;
|
QVector<glm::vec3> _points;
|
||||||
QVector<glm::vec3> _vertices;
|
QVector<glm::vec3> _vertices;
|
||||||
QVector<glm::vec3> _normals;
|
QVector<glm::vec3> _normals;
|
||||||
|
mutable QReadWriteLock _quadReadWriteLock;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_QuadEntityItem_h
|
#endif // hifi_QuadEntityItem_h
|
||||||
|
|
Loading…
Reference in a new issue