mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 12:08:54 +02:00
Merge pull request #5940 from ericrius1/polyLineFix
Made polyline painting experience smoother- no more flickering
This commit is contained in:
commit
b4ca03ac3f
2 changed files with 65 additions and 65 deletions
|
@ -65,9 +65,9 @@ void RenderablePolyLineEntityItem::createPipeline() {
|
|||
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
|
||||
state->setDepthTest(true, true, gpu::LESS_EQUAL);
|
||||
state->setBlendFunction(true,
|
||||
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
|
||||
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
|
||||
_pipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
|
||||
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
|
||||
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
|
||||
_pipeline = gpu::PipelinePointer(gpu::Pipeline::create(program, state));
|
||||
}
|
||||
|
||||
void RenderablePolyLineEntityItem::updateGeometry() {
|
||||
|
@ -84,20 +84,20 @@ void RenderablePolyLineEntityItem::updateGeometry() {
|
|||
float headLength = headEnd - headStart;
|
||||
float uCoord, vCoord;
|
||||
|
||||
int numTailStrips = 5;
|
||||
int numTailStrips = 5;
|
||||
int numHeadStrips = 10;
|
||||
int startHeadIndex = _normals.size() - numHeadStrips;
|
||||
for (int i = 0; i < _normals.size(); i++) {
|
||||
int startHeadIndex = _vertices.size() / 2 - numHeadStrips;
|
||||
for (int i = 0; i < _vertices.size() / 2; i++) {
|
||||
uCoord = 0.26f;
|
||||
vCoord = 0.0f;
|
||||
//tail
|
||||
if(i < numTailStrips) {
|
||||
uCoord = float(i)/numTailStrips * tailLength + tailStart;
|
||||
if (i < numTailStrips) {
|
||||
uCoord = float(i) / numTailStrips * tailLength + tailStart;
|
||||
}
|
||||
|
||||
//head
|
||||
if( i > startHeadIndex) {
|
||||
uCoord = float( (i+ 1) - startHeadIndex)/numHeadStrips * headLength + headStart;
|
||||
if (i > startHeadIndex) {
|
||||
uCoord = float((i + 1) - startHeadIndex) / numHeadStrips * headLength + headStart;
|
||||
}
|
||||
|
||||
uv = vec2(uCoord, vCoord);
|
||||
|
@ -115,7 +115,7 @@ void RenderablePolyLineEntityItem::updateGeometry() {
|
|||
_verticesBuffer->append(sizeof(glm::vec2), (const gpu::Byte*)&uv);
|
||||
vertexIndex++;
|
||||
|
||||
_numVertices +=2;
|
||||
_numVertices += 2;
|
||||
}
|
||||
_pointsChanged = false;
|
||||
|
||||
|
@ -124,7 +124,7 @@ void RenderablePolyLineEntityItem::updateGeometry() {
|
|||
|
||||
void RenderablePolyLineEntityItem::render(RenderArgs* args) {
|
||||
QWriteLocker lock(&_quadReadWriteLock);
|
||||
if (_points.size() < 2 || _vertices.size() != _normals.size() * 2) {
|
||||
if (_points.size() < 2 || _normals.size () < 2 || _vertices.size() < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,12 +27,12 @@ const int PolyLineEntityItem::MAX_POINTS_PER_LINE = 70;
|
|||
|
||||
|
||||
EntityItemPointer PolyLineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
|
||||
EntityItemPointer result { new PolyLineEntityItem(entityID, properties) };
|
||||
EntityItemPointer result{ new PolyLineEntityItem(entityID, properties) };
|
||||
return result;
|
||||
}
|
||||
|
||||
PolyLineEntityItem::PolyLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
|
||||
EntityItem(entityItemID) ,
|
||||
EntityItem(entityItemID),
|
||||
_lineWidth(DEFAULT_LINE_WIDTH),
|
||||
_pointsChanged(true),
|
||||
_points(QVector<glm::vec3>(0.0f)),
|
||||
|
@ -80,7 +80,7 @@ bool PolyLineEntityItem::setProperties(const EntityItemProperties& properties) {
|
|||
uint64_t now = usecTimestampNow();
|
||||
int elapsed = now - getLastEdited();
|
||||
qCDebug(entities) << "PolyLineEntityItem::setProperties() AFTER update... edited AGO=" << elapsed <<
|
||||
"now=" << now << " getLastEdited()=" << getLastEdited();
|
||||
"now=" << now << " getLastEdited()=" << getLastEdited();
|
||||
}
|
||||
setLastEdited(properties._lastEdited);
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ bool PolyLineEntityItem::appendPoint(const glm::vec3& point) {
|
|||
return false;
|
||||
}
|
||||
glm::vec3 halfBox = getDimensions() * 0.5f;
|
||||
if ( (point.x < - halfBox.x || point.x > halfBox.x) || (point.y < -halfBox.y || point.y > halfBox.y) || (point.z < - halfBox.z || point.z > halfBox.z) ) {
|
||||
if ((point.x < -halfBox.x || point.x > halfBox.x) || (point.y < -halfBox.y || point.y > halfBox.y) || (point.z < -halfBox.z || point.z > halfBox.z)) {
|
||||
qDebug() << "Point is outside entity's bounding box";
|
||||
return false;
|
||||
}
|
||||
|
@ -102,14 +102,14 @@ bool PolyLineEntityItem::appendPoint(const glm::vec3& point) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths ) {
|
||||
bool PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths) {
|
||||
_strokeWidths = strokeWidths;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
|
||||
_normals = normals;
|
||||
if (_points.size () < 2 || _normals.size() < 2) {
|
||||
if (_points.size() < 2 || _normals.size() < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -124,11 +124,11 @@ bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
|
|||
_vertices.clear();
|
||||
glm::vec3 v1, v2, tangent, binormal, point;
|
||||
|
||||
for (int i = 0; i < minVectorSize-1; i++) {
|
||||
for (int i = 0; i < minVectorSize - 1; i++) {
|
||||
float width = _strokeWidths.at(i);
|
||||
point = _points.at(i);
|
||||
|
||||
tangent = _points.at(i+1) - point;
|
||||
tangent = _points.at(i + 1) - point;
|
||||
glm::vec3 normal = normals.at(i);
|
||||
binormal = glm::normalize(glm::cross(tangent, normal)) * width;
|
||||
|
||||
|
@ -139,7 +139,7 @@ bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
|
|||
_vertices << v1 << v2;
|
||||
}
|
||||
//for last point we can just assume binormals are same since it represents last two vertices of quad
|
||||
point = _points.at(_points.size() - 1);
|
||||
point = _points.at(minVectorSize - 1);
|
||||
v1 = point + binormal;
|
||||
v2 = point - binormal;
|
||||
_vertices << v1 << v2;
|
||||
|
@ -157,7 +157,7 @@ bool PolyLineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
|
|||
//Check to see if points actually changed. If they haven't, return before doing anything else
|
||||
else if (points.size() == _points.size()) {
|
||||
//same number of points, so now compare every point
|
||||
for (int i = 0; i < points.size(); i++ ) {
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
if (points.at(i) != _points.at(i)){
|
||||
_pointsChanged = true;
|
||||
break;
|
||||
|
@ -171,9 +171,9 @@ bool PolyLineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
|
|||
for (int i = 0; i < points.size(); i++) {
|
||||
glm::vec3 point = points.at(i);
|
||||
glm::vec3 halfBox = getDimensions() * 0.5f;
|
||||
if ((point.x < - halfBox.x || point.x > halfBox.x) ||
|
||||
if ((point.x < -halfBox.x || point.x > halfBox.x) ||
|
||||
(point.y < -halfBox.y || point.y > halfBox.y) ||
|
||||
(point.z < - halfBox.z || point.z > halfBox.z)) {
|
||||
(point.z < -halfBox.z || point.z > halfBox.z)) {
|
||||
qDebug() << "Point is outside entity's bounding box";
|
||||
return false;
|
||||
}
|
||||
|
@ -183,16 +183,16 @@ bool PolyLineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
|
|||
}
|
||||
|
||||
int PolyLineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
|
||||
ReadBitstreamToTreeParams& args,
|
||||
EntityPropertyFlags& propertyFlags, bool overwriteLocalData) {
|
||||
QWriteLocker lock(&_quadReadWriteLock);
|
||||
ReadBitstreamToTreeParams& args,
|
||||
EntityPropertyFlags& propertyFlags, bool overwriteLocalData) {
|
||||
QWriteLocker lock(&_quadReadWriteLock);
|
||||
int bytesRead = 0;
|
||||
const unsigned char* dataAt = data;
|
||||
|
||||
READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor);
|
||||
READ_ENTITY_PROPERTY(PROP_LINE_WIDTH, float, setLineWidth);
|
||||
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);
|
||||
READ_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, QVector<float>, setStrokeWidths);
|
||||
|
||||
return bytesRead;
|
||||
|
@ -211,12 +211,12 @@ EntityPropertyFlags PolyLineEntityItem::getEntityProperties(EncodeBitstreamParam
|
|||
}
|
||||
|
||||
void PolyLineEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
|
||||
EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData,
|
||||
EntityPropertyFlags& requestedProperties,
|
||||
EntityPropertyFlags& propertyFlags,
|
||||
EntityPropertyFlags& propertiesDidntFit,
|
||||
int& propertyCount,
|
||||
OctreeElement::AppendState& appendState) const {
|
||||
EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData,
|
||||
EntityPropertyFlags& requestedProperties,
|
||||
EntityPropertyFlags& propertyFlags,
|
||||
EntityPropertyFlags& propertiesDidntFit,
|
||||
int& propertyCount,
|
||||
OctreeElement::AppendState& appendState) const {
|
||||
|
||||
QWriteLocker lock(&_quadReadWriteLock);
|
||||
bool successPropertyFits = true;
|
||||
|
|
Loading…
Reference in a new issue