mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 12:08:54 +02:00
performance optimization to minimize calling usecTimestampNow
This commit is contained in:
parent
ae9fb3768c
commit
36d9f92101
12 changed files with 43 additions and 24 deletions
|
@ -96,16 +96,17 @@ public: \
|
||||||
virtual void removeFromScene(EntityItemPointer self, std::shared_ptr<render::Scene> scene, render::PendingChanges& pendingChanges) override { _renderHelper.removeFromScene(self, scene, pendingChanges); } \
|
virtual void removeFromScene(EntityItemPointer self, std::shared_ptr<render::Scene> scene, render::PendingChanges& pendingChanges) override { _renderHelper.removeFromScene(self, scene, pendingChanges); } \
|
||||||
virtual void locationChanged(bool tellPhysics = true) override { EntityItem::locationChanged(tellPhysics); _renderHelper.notifyChanged(); } \
|
virtual void locationChanged(bool tellPhysics = true) override { EntityItem::locationChanged(tellPhysics); _renderHelper.notifyChanged(); } \
|
||||||
virtual void dimensionsChanged() override { EntityItem::dimensionsChanged(); _renderHelper.notifyChanged(); } \
|
virtual void dimensionsChanged() override { EntityItem::dimensionsChanged(); _renderHelper.notifyChanged(); } \
|
||||||
void checkTransparency() { \
|
void checkFading() { \
|
||||||
bool transparent = isTransparent(); \
|
bool transparent = isTransparent(); \
|
||||||
if (transparent != prevIsTransparent) { \
|
if (transparent != _prevIsTransparent) { \
|
||||||
_renderHelper.notifyChanged(); \
|
_renderHelper.notifyChanged(); \
|
||||||
prevIsTransparent = transparent; \
|
_isFading = false; \
|
||||||
|
_prevIsTransparent = transparent; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
private: \
|
private: \
|
||||||
SimpleRenderableEntityItem _renderHelper; \
|
SimpleRenderableEntityItem _renderHelper; \
|
||||||
bool prevIsTransparent { isTransparent() };
|
bool _prevIsTransparent { isTransparent() };
|
||||||
|
|
||||||
|
|
||||||
#endif // hifi_RenderableEntityItem_h
|
#endif // hifi_RenderableEntityItem_h
|
||||||
|
|
|
@ -28,6 +28,8 @@ EntityItemPointer RenderableLightEntityItem::factory(const EntityItemID& entityI
|
||||||
void RenderableLightEntityItem::render(RenderArgs* args) {
|
void RenderableLightEntityItem::render(RenderArgs* args) {
|
||||||
PerformanceTimer perfTimer("RenderableLightEntityItem::render");
|
PerformanceTimer perfTimer("RenderableLightEntityItem::render");
|
||||||
assert(getType() == EntityTypes::Light);
|
assert(getType() == EntityTypes::Light);
|
||||||
|
checkFading();
|
||||||
|
|
||||||
glm::vec3 position = getPosition();
|
glm::vec3 position = getPosition();
|
||||||
glm::vec3 dimensions = getDimensions();
|
glm::vec3 dimensions = getDimensions();
|
||||||
glm::quat rotation = getRotation();
|
glm::quat rotation = getRotation();
|
||||||
|
@ -35,7 +37,7 @@ void RenderableLightEntityItem::render(RenderArgs* args) {
|
||||||
|
|
||||||
glm::vec3 color = toGlm(getXColor());
|
glm::vec3 color = toGlm(getXColor());
|
||||||
|
|
||||||
float intensity = getIntensity() * Interpolate::calculateFadeRatio(_fadeStartTime);
|
float intensity = getIntensity() * (_isFading ? Interpolate::calculateFadeRatio(_fadeStartTime) : 1.0f);
|
||||||
float falloffRadius = getFalloffRadius();
|
float falloffRadius = getFalloffRadius();
|
||||||
float exponent = getExponent();
|
float exponent = getExponent();
|
||||||
float cutoff = glm::radians(getCutoff());
|
float cutoff = glm::radians(getCutoff());
|
||||||
|
|
|
@ -167,7 +167,7 @@ void RenderablePolyLineEntityItem::update(const quint64& now) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderablePolyLineEntityItem::render(RenderArgs* args) {
|
void RenderablePolyLineEntityItem::render(RenderArgs* args) {
|
||||||
checkTransparency();
|
checkFading();
|
||||||
|
|
||||||
QWriteLocker lock(&_quadReadWriteLock);
|
QWriteLocker lock(&_quadReadWriteLock);
|
||||||
if (_points.size() < 2 || _normals.size () < 2 || _strokeWidths.size() < 2) {
|
if (_points.size() < 2 || _normals.size () < 2 || _strokeWidths.size() < 2) {
|
||||||
|
@ -206,7 +206,9 @@ void RenderablePolyLineEntityItem::render(RenderArgs* args) {
|
||||||
batch.setInputFormat(_format);
|
batch.setInputFormat(_format);
|
||||||
batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride);
|
batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride);
|
||||||
|
|
||||||
batch._glColor4f(1.0f, 1.0f, 1.0f, Interpolate::calculateFadeRatio(_fadeStartTime));
|
if (_isFading) {
|
||||||
|
batch._glColor4f(1.0f, 1.0f, 1.0f, Interpolate::calculateFadeRatio(_fadeStartTime));
|
||||||
|
}
|
||||||
|
|
||||||
batch.draw(gpu::TRIANGLE_STRIP, _numVertices, 0);
|
batch.draw(gpu::TRIANGLE_STRIP, _numVertices, 0);
|
||||||
};
|
};
|
||||||
|
|
|
@ -72,8 +72,10 @@ void RenderableShapeEntityItem::setUserData(const QString& value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderableShapeEntityItem::isTransparent() {
|
bool RenderableShapeEntityItem::isTransparent() {
|
||||||
if (_procedural && _procedural->ready()) {
|
if (_procedural && _procedural->isFading()) {
|
||||||
return Interpolate::calculateFadeRatio(_procedural->getFadeStartTime()) < 1.0f;
|
float isFading = Interpolate::calculateFadeRatio(_procedural->getFadeStartTime()) < 1.0f;
|
||||||
|
_procedural->setIsFading(isFading);
|
||||||
|
return isFading;
|
||||||
} else {
|
} else {
|
||||||
return getLocalRenderAlpha() < 1.0f || EntityItem::isTransparent();
|
return getLocalRenderAlpha() < 1.0f || EntityItem::isTransparent();
|
||||||
}
|
}
|
||||||
|
@ -83,7 +85,7 @@ void RenderableShapeEntityItem::render(RenderArgs* args) {
|
||||||
PerformanceTimer perfTimer("RenderableShapeEntityItem::render");
|
PerformanceTimer perfTimer("RenderableShapeEntityItem::render");
|
||||||
//Q_ASSERT(getType() == EntityTypes::Shape);
|
//Q_ASSERT(getType() == EntityTypes::Shape);
|
||||||
Q_ASSERT(args->_batch);
|
Q_ASSERT(args->_batch);
|
||||||
checkTransparency();
|
checkFading();
|
||||||
|
|
||||||
if (!_procedural) {
|
if (!_procedural) {
|
||||||
_procedural.reset(new Procedural(getUserData()));
|
_procedural.reset(new Procedural(getUserData()));
|
||||||
|
@ -110,12 +112,12 @@ void RenderableShapeEntityItem::render(RenderArgs* args) {
|
||||||
if (_procedural->ready()) {
|
if (_procedural->ready()) {
|
||||||
_procedural->prepare(batch, getPosition(), getDimensions(), getOrientation());
|
_procedural->prepare(batch, getPosition(), getDimensions(), getOrientation());
|
||||||
auto outColor = _procedural->getColor(color);
|
auto outColor = _procedural->getColor(color);
|
||||||
outColor.a *= Interpolate::calculateFadeRatio(_procedural->getFadeStartTime());
|
outColor.a *= _procedural->isFading() ? Interpolate::calculateFadeRatio(_procedural->getFadeStartTime()) : 1.0f;
|
||||||
batch._glColor4f(outColor.r, outColor.g, outColor.b, outColor.a);
|
batch._glColor4f(outColor.r, outColor.g, outColor.b, outColor.a);
|
||||||
DependencyManager::get<GeometryCache>()->renderShape(batch, MAPPING[_shape]);
|
DependencyManager::get<GeometryCache>()->renderShape(batch, MAPPING[_shape]);
|
||||||
} else {
|
} else {
|
||||||
// FIXME, support instanced multi-shape rendering using multidraw indirect
|
// FIXME, support instanced multi-shape rendering using multidraw indirect
|
||||||
color.a *= Interpolate::calculateFadeRatio(_fadeStartTime);
|
color.a *= _isFading ? Interpolate::calculateFadeRatio(_fadeStartTime) : 1.0f;
|
||||||
auto geometryCache = DependencyManager::get<GeometryCache>();
|
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||||
auto pipeline = color.a < 1.0f ? geometryCache->getTransparentShapePipeline() : geometryCache->getOpaqueShapePipeline();
|
auto pipeline = color.a < 1.0f ? geometryCache->getTransparentShapePipeline() : geometryCache->getOpaqueShapePipeline();
|
||||||
geometryCache->renderSolidShapeInstance(batch, MAPPING[_shape], color, pipeline);
|
geometryCache->renderSolidShapeInstance(batch, MAPPING[_shape], color, pipeline);
|
||||||
|
|
|
@ -27,10 +27,10 @@ EntityItemPointer RenderableTextEntityItem::factory(const EntityItemID& entityID
|
||||||
void RenderableTextEntityItem::render(RenderArgs* args) {
|
void RenderableTextEntityItem::render(RenderArgs* args) {
|
||||||
PerformanceTimer perfTimer("RenderableTextEntityItem::render");
|
PerformanceTimer perfTimer("RenderableTextEntityItem::render");
|
||||||
Q_ASSERT(getType() == EntityTypes::Text);
|
Q_ASSERT(getType() == EntityTypes::Text);
|
||||||
checkTransparency();
|
checkFading();
|
||||||
|
|
||||||
static const float SLIGHTLY_BEHIND = -0.005f;
|
static const float SLIGHTLY_BEHIND = -0.005f;
|
||||||
float fadeRatio = Interpolate::calculateFadeRatio(_fadeStartTime);
|
float fadeRatio = _isFading ? Interpolate::calculateFadeRatio(_fadeStartTime) : 1.0f;
|
||||||
bool transparent = fadeRatio < 1.0f;
|
bool transparent = fadeRatio < 1.0f;
|
||||||
glm::vec4 textColor = glm::vec4(toGlm(getTextColorX()), fadeRatio);
|
glm::vec4 textColor = glm::vec4(toGlm(getTextColorX()), fadeRatio);
|
||||||
glm::vec4 backgroundColor = glm::vec4(toGlm(getBackgroundColorX()), fadeRatio);
|
glm::vec4 backgroundColor = glm::vec4(toGlm(getBackgroundColorX()), fadeRatio);
|
||||||
|
|
|
@ -164,7 +164,7 @@ bool RenderableWebEntityItem::buildWebSurface(EntityTreeRenderer* renderer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableWebEntityItem::render(RenderArgs* args) {
|
void RenderableWebEntityItem::render(RenderArgs* args) {
|
||||||
checkTransparency();
|
checkFading();
|
||||||
|
|
||||||
#ifdef WANT_EXTRA_DEBUGGING
|
#ifdef WANT_EXTRA_DEBUGGING
|
||||||
{
|
{
|
||||||
|
@ -210,7 +210,7 @@ void RenderableWebEntityItem::render(RenderArgs* args) {
|
||||||
batch._glActiveBindTexture(GL_TEXTURE0, GL_TEXTURE_2D, _texture);
|
batch._glActiveBindTexture(GL_TEXTURE0, GL_TEXTURE_2D, _texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
float fadeRatio = Interpolate::calculateFadeRatio(_fadeStartTime);
|
float fadeRatio = _isFading ? Interpolate::calculateFadeRatio(_fadeStartTime) : 1.0f;
|
||||||
batch._glColor4f(1.0f, 1.0f, 1.0f, fadeRatio);
|
batch._glColor4f(1.0f, 1.0f, 1.0f, fadeRatio);
|
||||||
|
|
||||||
DependencyManager::get<GeometryCache>()->bindSimpleSRGBTexturedUnlitNoTexAlphaProgram(batch);
|
DependencyManager::get<GeometryCache>()->bindSimpleSRGBTexturedUnlitNoTexAlphaProgram(batch);
|
||||||
|
|
|
@ -2212,4 +2212,4 @@ void EntityItem::globalizeProperties(EntityItemProperties& properties, const QSt
|
||||||
}
|
}
|
||||||
QUuid empty;
|
QUuid empty;
|
||||||
properties.setParentID(empty);
|
properties.setParentID(empty);
|
||||||
}
|
}
|
|
@ -436,7 +436,7 @@ public:
|
||||||
QUuid getOwningAvatarID() const { return _owningAvatarID; }
|
QUuid getOwningAvatarID() const { return _owningAvatarID; }
|
||||||
void setOwningAvatarID(const QUuid& owningAvatarID) { _owningAvatarID = owningAvatarID; }
|
void setOwningAvatarID(const QUuid& owningAvatarID) { _owningAvatarID = owningAvatarID; }
|
||||||
|
|
||||||
virtual bool isTransparent() { return Interpolate::calculateFadeRatio(_fadeStartTime) < 1.0f; }
|
virtual bool isTransparent() { return _isFading ? Interpolate::calculateFadeRatio(_fadeStartTime) < 1.0f : false; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -568,6 +568,7 @@ protected:
|
||||||
quint64 _lastUpdatedAccelerationTimestamp { 0 };
|
quint64 _lastUpdatedAccelerationTimestamp { 0 };
|
||||||
|
|
||||||
quint64 _fadeStartTime { usecTimestampNow() };
|
quint64 _fadeStartTime { usecTimestampNow() };
|
||||||
|
bool _isFading { true };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_EntityItem_h
|
#endif // hifi_EntityItem_h
|
||||||
|
|
|
@ -208,6 +208,7 @@ bool Procedural::ready() {
|
||||||
|
|
||||||
if (!_hasStartedFade) {
|
if (!_hasStartedFade) {
|
||||||
_hasStartedFade = true;
|
_hasStartedFade = true;
|
||||||
|
_isFading = true;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ public:
|
||||||
|
|
||||||
glm::vec4 getColor(const glm::vec4& entityColor);
|
glm::vec4 getColor(const glm::vec4& entityColor);
|
||||||
quint64 getFadeStartTime() { return _fadeStartTime; }
|
quint64 getFadeStartTime() { return _fadeStartTime; }
|
||||||
|
bool isFading() { return _isFading; }
|
||||||
|
void setIsFading(bool isFading) { _isFading = isFading; }
|
||||||
|
|
||||||
uint8_t _version { 1 };
|
uint8_t _version { 1 };
|
||||||
|
|
||||||
|
@ -110,6 +112,7 @@ private:
|
||||||
|
|
||||||
quint64 _fadeStartTime;
|
quint64 _fadeStartTime;
|
||||||
bool _hasStartedFade { false };
|
bool _hasStartedFade { false };
|
||||||
|
bool _isFading { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -391,7 +391,7 @@ ItemKey ModelMeshPartPayload::getKey() const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Interpolate::calculateFadeRatio(_fadeStartTime) < 1.0f) {
|
if (!_hasFinishedFade) {
|
||||||
builder.withTransparent();
|
builder.withTransparent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,7 +446,7 @@ ShapeKey ModelMeshPartPayload::getShapeKey() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapeKey::Builder builder;
|
ShapeKey::Builder builder;
|
||||||
if (isTranslucent || Interpolate::calculateFadeRatio(_fadeStartTime) < 1.0f) {
|
if (isTranslucent || !_hasFinishedFade) {
|
||||||
builder.withTranslucent();
|
builder.withTranslucent();
|
||||||
}
|
}
|
||||||
if (hasTangents) {
|
if (hasTangents) {
|
||||||
|
@ -487,7 +487,7 @@ void ModelMeshPartPayload::bindMesh(gpu::Batch& batch) const {
|
||||||
batch.setInputStream(2, _drawMesh->getVertexStream().makeRangedStream(2));
|
batch.setInputStream(2, _drawMesh->getVertexStream().makeRangedStream(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
float fadeRatio = Interpolate::calculateFadeRatio(_fadeStartTime);
|
float fadeRatio = _isFading ? Interpolate::calculateFadeRatio(_fadeStartTime) : 1.0f;
|
||||||
if (!_hasColorAttrib || fadeRatio < 1.0f) {
|
if (!_hasColorAttrib || fadeRatio < 1.0f) {
|
||||||
batch._glColor4f(1.0f, 1.0f, 1.0f, fadeRatio);
|
batch._glColor4f(1.0f, 1.0f, 1.0f, fadeRatio);
|
||||||
}
|
}
|
||||||
|
@ -519,6 +519,8 @@ void ModelMeshPartPayload::bindTransform(gpu::Batch& batch, const ShapePipeline:
|
||||||
void ModelMeshPartPayload::startFade() {
|
void ModelMeshPartPayload::startFade() {
|
||||||
_fadeStartTime = usecTimestampNow();
|
_fadeStartTime = usecTimestampNow();
|
||||||
_hasStartedFade = true;
|
_hasStartedFade = true;
|
||||||
|
_prevHasStartedFade = false;
|
||||||
|
_hasFinishedFade = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelMeshPartPayload::render(RenderArgs* args) const {
|
void ModelMeshPartPayload::render(RenderArgs* args) const {
|
||||||
|
@ -530,10 +532,13 @@ void ModelMeshPartPayload::render(RenderArgs* args) const {
|
||||||
|
|
||||||
// When an individual mesh parts like this finishes its fade, we will mark the Model as
|
// When an individual mesh parts like this finishes its fade, we will mark the Model as
|
||||||
// having render items that need updating
|
// having render items that need updating
|
||||||
if (_wasFading && !isStillFading()) {
|
bool nextIsFading = _isFading ? isStillFading() : false;
|
||||||
|
if (_isFading != nextIsFading || _prevHasStartedFade != _hasStartedFade) {
|
||||||
|
_isFading = nextIsFading || _prevHasStartedFade != _hasStartedFade;
|
||||||
|
_hasFinishedFade = _prevHasStartedFade == _hasStartedFade && !_isFading;
|
||||||
|
_prevHasStartedFade = _hasStartedFade;
|
||||||
_model->setRenderItemsNeedUpdate();
|
_model->setRenderItemsNeedUpdate();
|
||||||
}
|
}
|
||||||
_wasFading = isStillFading();
|
|
||||||
|
|
||||||
gpu::Batch& batch = *(args->_batch);
|
gpu::Batch& batch = *(args->_batch);
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,9 @@ public:
|
||||||
private:
|
private:
|
||||||
quint64 _fadeStartTime { 0 };
|
quint64 _fadeStartTime { 0 };
|
||||||
bool _hasStartedFade { false };
|
bool _hasStartedFade { false };
|
||||||
mutable bool _wasFading { false };
|
mutable bool _prevHasStartedFade{ false };
|
||||||
|
mutable bool _hasFinishedFade { false };
|
||||||
|
mutable bool _isFading { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace render {
|
namespace render {
|
||||||
|
|
Loading…
Reference in a new issue