mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 00:13:53 +02:00
Merge branch 'fix/overlay-property-scene-updates' of github.com:zzmp/hifi into wip
This commit is contained in:
commit
fe6314c388
8 changed files with 72 additions and 32 deletions
|
@ -229,5 +229,6 @@ bool Overlay::addToScene(Overlay::Pointer overlay, std::shared_ptr<render::Scene
|
|||
|
||||
void Overlay::removeFromScene(Overlay::Pointer overlay, std::shared_ptr<render::Scene> scene, render::PendingChanges& pendingChanges) {
|
||||
pendingChanges.removeItem(_renderItemID);
|
||||
_renderItemID = render::Item::INVALID_ITEM_ID;
|
||||
}
|
||||
|
||||
|
|
|
@ -208,9 +208,7 @@ unsigned int Overlays::addOverlay(Overlay::Pointer overlay) {
|
|||
|
||||
render::ScenePointer scene = qApp->getMain3DScene();
|
||||
render::PendingChanges pendingChanges;
|
||||
|
||||
overlay->addToScene(overlay, scene, pendingChanges);
|
||||
|
||||
scene->enqueuePendingChanges(pendingChanges);
|
||||
}
|
||||
} else {
|
||||
|
@ -244,18 +242,35 @@ bool Overlays::editOverlay(unsigned int id, const QScriptValue& properties) {
|
|||
auto overlay3D = std::static_pointer_cast<Base3DOverlay>(thisOverlay);
|
||||
|
||||
bool oldDrawOnHUD = overlay3D->getDrawOnHUD();
|
||||
thisOverlay->setProperties(properties);
|
||||
bool drawOnHUD = overlay3D->getDrawOnHUD();
|
||||
render::ItemKey oldItemKey = render::payloadGetKey(thisOverlay);
|
||||
|
||||
thisOverlay->setProperties(properties);
|
||||
|
||||
render::ScenePointer scene = qApp->getMain3DScene();
|
||||
render::PendingChanges pendingChanges;
|
||||
auto itemID = thisOverlay->getRenderItemID();
|
||||
|
||||
bool drawOnHUD = overlay3D->getDrawOnHUD();
|
||||
render::ItemKey itemKey = render::payloadGetKey(thisOverlay);
|
||||
if (drawOnHUD != oldDrawOnHUD) {
|
||||
if (drawOnHUD) {
|
||||
_overlaysWorld.remove(id);
|
||||
_overlaysHUD[id] = thisOverlay;
|
||||
if (itemID != render::Item::INVALID_ITEM_ID) {
|
||||
thisOverlay->removeFromScene(thisOverlay, scene, pendingChanges);
|
||||
}
|
||||
} else {
|
||||
_overlaysHUD.remove(id);
|
||||
_overlaysWorld[id] = thisOverlay;
|
||||
thisOverlay->addToScene(thisOverlay, scene, pendingChanges);
|
||||
}
|
||||
} else if (itemKey != oldItemKey && !drawOnHUD) {
|
||||
if (itemID != render::Item::INVALID_ITEM_ID) {
|
||||
pendingChanges.resortItem(itemID, oldItemKey, itemKey);
|
||||
}
|
||||
}
|
||||
|
||||
scene->enqueuePendingChanges(pendingChanges);
|
||||
} else {
|
||||
thisOverlay->setProperties(properties);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace render {
|
|||
if (std::dynamic_pointer_cast<Base3DOverlay>(overlay)->getDrawInFront()) {
|
||||
builder.withLayered();
|
||||
}
|
||||
if (overlay->getAlpha() != 1.0f) {
|
||||
if (overlay->getAlphaPulse() != 0.0f || overlay->getAlpha() != 1.0f) {
|
||||
builder.withTransparent();
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
#include <RenderDeferredTask.h>
|
||||
#include <TextRenderer3D.h>
|
||||
|
||||
const xColor DEFAULT_BACKGROUND_COLOR = { 0, 0, 0 };
|
||||
const float DEFAULT_BACKGROUND_ALPHA = 0.7f;
|
||||
const float DEFAULT_MARGIN = 0.1f;
|
||||
const int FIXED_FONT_POINT_SIZE = 40;
|
||||
const int FIXED_FONT_SCALING_RATIO = FIXED_FONT_POINT_SIZE * 80.0f; // this is a ratio determined through experimentation
|
||||
|
@ -26,24 +24,15 @@ const float LINE_SCALE_RATIO = 1.2f;
|
|||
|
||||
QString const Text3DOverlay::TYPE = "text3d";
|
||||
|
||||
Text3DOverlay::Text3DOverlay() :
|
||||
_backgroundColor(DEFAULT_BACKGROUND_COLOR),
|
||||
_backgroundAlpha(DEFAULT_BACKGROUND_ALPHA),
|
||||
_lineHeight(0.1f),
|
||||
_leftMargin(DEFAULT_MARGIN),
|
||||
_topMargin(DEFAULT_MARGIN),
|
||||
_rightMargin(DEFAULT_MARGIN),
|
||||
_bottomMargin(DEFAULT_MARGIN)
|
||||
{
|
||||
Text3DOverlay::Text3DOverlay() {
|
||||
_textRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE);
|
||||
_alpha = _backgroundAlpha;
|
||||
}
|
||||
|
||||
Text3DOverlay::Text3DOverlay(const Text3DOverlay* text3DOverlay) :
|
||||
Billboard3DOverlay(text3DOverlay),
|
||||
_text(text3DOverlay->_text),
|
||||
_backgroundColor(text3DOverlay->_backgroundColor),
|
||||
_backgroundAlpha(text3DOverlay->_backgroundAlpha),
|
||||
_textAlpha(text3DOverlay->_textAlpha),
|
||||
_lineHeight(text3DOverlay->_lineHeight),
|
||||
_leftMargin(text3DOverlay->_leftMargin),
|
||||
_topMargin(text3DOverlay->_topMargin),
|
||||
|
@ -51,7 +40,6 @@ Text3DOverlay::Text3DOverlay(const Text3DOverlay* text3DOverlay) :
|
|||
_bottomMargin(text3DOverlay->_bottomMargin)
|
||||
{
|
||||
_textRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE);
|
||||
_alpha = _backgroundAlpha;
|
||||
}
|
||||
|
||||
Text3DOverlay::~Text3DOverlay() {
|
||||
|
@ -122,7 +110,7 @@ void Text3DOverlay::render(RenderArgs* args) {
|
|||
batch.setModelTransform(transform);
|
||||
|
||||
glm::vec4 textColor = { _color.red / MAX_COLOR, _color.green / MAX_COLOR,
|
||||
_color.blue / MAX_COLOR, getAlpha() };
|
||||
_color.blue / MAX_COLOR, getTextAlpha() };
|
||||
_textRenderer->draw(batch, 0, 0, _text, textColor, glm::vec2(-1.0f), getDrawInFront());
|
||||
}
|
||||
|
||||
|
@ -142,6 +130,11 @@ void Text3DOverlay::setProperties(const QScriptValue& properties) {
|
|||
setText(text.toVariant().toString());
|
||||
}
|
||||
|
||||
QScriptValue textAlpha = properties.property("textAlpha");
|
||||
if (textAlpha.isValid()) {
|
||||
setTextAlpha(textAlpha.toVariant().toFloat());
|
||||
}
|
||||
|
||||
QScriptValue backgroundColor = properties.property("backgroundColor");
|
||||
if (backgroundColor.isValid()) {
|
||||
QScriptValue red = backgroundColor.property("red");
|
||||
|
@ -155,8 +148,7 @@ void Text3DOverlay::setProperties(const QScriptValue& properties) {
|
|||
}
|
||||
|
||||
if (properties.property("backgroundAlpha").isValid()) {
|
||||
_backgroundAlpha = properties.property("backgroundAlpha").toVariant().toFloat();
|
||||
_alpha = _backgroundAlpha;
|
||||
setAlpha(properties.property("backgroundAlpha").toVariant().toFloat());
|
||||
}
|
||||
|
||||
if (properties.property("lineHeight").isValid()) {
|
||||
|
@ -184,11 +176,14 @@ QScriptValue Text3DOverlay::getProperty(const QString& property) {
|
|||
if (property == "text") {
|
||||
return _text;
|
||||
}
|
||||
if (property == "textAlpha") {
|
||||
return _textAlpha;
|
||||
}
|
||||
if (property == "backgroundColor") {
|
||||
return xColorToScriptValue(_scriptEngine, _backgroundColor);
|
||||
}
|
||||
if (property == "backgroundAlpha") {
|
||||
return _backgroundAlpha;
|
||||
return Billboard3DOverlay::getProperty("alpha");
|
||||
}
|
||||
if (property == "lineHeight") {
|
||||
return _lineHeight;
|
||||
|
|
|
@ -41,10 +41,12 @@ public:
|
|||
float getRightMargin() const { return _rightMargin; }
|
||||
float getBottomMargin() const { return _bottomMargin; }
|
||||
xColor getBackgroundColor();
|
||||
float getBackgroundAlpha() const { return _backgroundAlpha; }
|
||||
float getTextAlpha() { return _textAlpha; }
|
||||
float getBackgroundAlpha() { return getAlpha(); }
|
||||
|
||||
// setters
|
||||
void setText(const QString& text) { _text = text; }
|
||||
void setTextAlpha(float alpha) { _textAlpha = alpha; }
|
||||
void setLineHeight(float value) { _lineHeight = value; }
|
||||
void setLeftMargin(float margin) { _leftMargin = margin; }
|
||||
void setTopMargin(float margin) { _topMargin = margin; }
|
||||
|
@ -65,13 +67,13 @@ private:
|
|||
TextRenderer3D* _textRenderer = nullptr;
|
||||
|
||||
QString _text;
|
||||
xColor _backgroundColor;
|
||||
float _backgroundAlpha;
|
||||
float _lineHeight;
|
||||
float _leftMargin;
|
||||
float _topMargin;
|
||||
float _rightMargin;
|
||||
float _bottomMargin;
|
||||
xColor _backgroundColor = xColor { 0, 0, 0 };
|
||||
float _textAlpha { 1.0f };
|
||||
float _lineHeight { 1.0f };
|
||||
float _leftMargin { 0.1f };
|
||||
float _topMargin { 0.1f };
|
||||
float _rightMargin { 0.1f };
|
||||
float _bottomMargin { 0.1f };
|
||||
};
|
||||
|
||||
#endif // hifi_Text3DOverlay_h
|
||||
|
|
|
@ -117,7 +117,10 @@ public:
|
|||
bool isSmall() const { return _flags[SMALLER]; }
|
||||
void setSmaller(bool smaller) { (smaller ? _flags.set(SMALLER) : _flags.reset(SMALLER)); }
|
||||
|
||||
bool operator==(const ItemKey& key) { return (_flags == key._flags); }
|
||||
bool operator!=(const ItemKey& key) { return (_flags != key._flags); }
|
||||
};
|
||||
using ItemKeys = std::vector<ItemKey>;
|
||||
|
||||
inline QDebug operator<<(QDebug debug, const ItemKey& itemKey) {
|
||||
debug << "[ItemKey: isOpaque:" << itemKey.isOpaque()
|
||||
|
|
|
@ -62,6 +62,12 @@ void PendingChanges::resetItem(ItemID id, const PayloadPointer& payload) {
|
|||
_resetPayloads.push_back(payload);
|
||||
}
|
||||
|
||||
void PendingChanges::resortItem(ItemID id, ItemKey oldKey, ItemKey newKey) {
|
||||
_resortItems.push_back(id);
|
||||
_resortOldKeys.push_back(oldKey);
|
||||
_resortNewKeys.push_back(newKey);
|
||||
}
|
||||
|
||||
void PendingChanges::removeItem(ItemID id) {
|
||||
_removedItems.push_back(id);
|
||||
}
|
||||
|
@ -74,6 +80,9 @@ void PendingChanges::updateItem(ItemID id, const UpdateFunctorPointer& functor)
|
|||
void PendingChanges::merge(PendingChanges& changes) {
|
||||
_resetItems.insert(_resetItems.end(), changes._resetItems.begin(), changes._resetItems.end());
|
||||
_resetPayloads.insert(_resetPayloads.end(), changes._resetPayloads.begin(), changes._resetPayloads.end());
|
||||
_resortItems.insert(_resortItems.end(), changes._resortItems.begin(), changes._resortItems.end());
|
||||
_resortOldKeys.insert(_resortOldKeys.end(), changes._resortOldKeys.begin(), changes._resortOldKeys.end());
|
||||
_resortNewKeys.insert(_resortNewKeys.end(), changes._resortNewKeys.begin(), changes._resortNewKeys.end());
|
||||
_removedItems.insert(_removedItems.end(), changes._removedItems.begin(), changes._removedItems.end());
|
||||
_updatedItems.insert(_updatedItems.end(), changes._updatedItems.begin(), changes._updatedItems.end());
|
||||
_updateFunctors.insert(_updateFunctors.end(), changes._updateFunctors.begin(), changes._updateFunctors.end());
|
||||
|
@ -124,6 +133,7 @@ void Scene::processPendingChangesQueue() {
|
|||
// capture anything coming from the pendingChanges
|
||||
resetItems(consolidatedPendingChanges._resetItems, consolidatedPendingChanges._resetPayloads);
|
||||
updateItems(consolidatedPendingChanges._updatedItems, consolidatedPendingChanges._updateFunctors);
|
||||
resortItems(consolidatedPendingChanges._resortItems, consolidatedPendingChanges._resortOldKeys, consolidatedPendingChanges._resortNewKeys);
|
||||
removeItems(consolidatedPendingChanges._removedItems);
|
||||
|
||||
// ready to go back to rendering activities
|
||||
|
@ -156,6 +166,15 @@ void Scene::resetItems(const ItemIDs& ids, Payloads& payloads) {
|
|||
}
|
||||
}
|
||||
|
||||
void Scene::resortItems(const ItemIDs& ids, ItemKeys& oldKeys, ItemKeys& newKeys) {
|
||||
auto resortID = ids.begin();
|
||||
auto oldKey = oldKeys.begin();
|
||||
auto newKey = newKeys.begin();
|
||||
for (; resortID != ids.end(); resortID++, oldKey++, newKey++) {
|
||||
_masterBucketMap.reset(*resortID, *oldKey, *newKey);
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::removeItems(const ItemIDs& ids) {
|
||||
for (auto removedID :ids) {
|
||||
// Access the true item
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
~PendingChanges() {}
|
||||
|
||||
void resetItem(ItemID id, const PayloadPointer& payload);
|
||||
void resortItem(ItemID id, ItemKey oldKey, ItemKey newKey);
|
||||
void removeItem(ItemID id);
|
||||
|
||||
template <class T> void updateItem(ItemID id, std::function<void(T&)> func) {
|
||||
|
@ -50,8 +51,11 @@ public:
|
|||
|
||||
void merge(PendingChanges& changes);
|
||||
|
||||
Payloads _resetPayloads;
|
||||
ItemIDs _resetItems;
|
||||
Payloads _resetPayloads;
|
||||
ItemIDs _resortItems;
|
||||
ItemKeys _resortOldKeys;
|
||||
ItemKeys _resortNewKeys;
|
||||
ItemIDs _removedItems;
|
||||
ItemIDs _updatedItems;
|
||||
UpdateFunctors _updateFunctors;
|
||||
|
@ -107,6 +111,7 @@ protected:
|
|||
|
||||
|
||||
void resetItems(const ItemIDs& ids, Payloads& payloads);
|
||||
void resortItems(const ItemIDs& ids, ItemKeys& oldKeys, ItemKeys& newKeys);
|
||||
void removeItems(const ItemIDs& ids);
|
||||
void updateItems(const ItemIDs& ids, UpdateFunctors& functors);
|
||||
|
||||
|
|
Loading…
Reference in a new issue