Merge branch 'master' into issue/2425

This commit is contained in:
Alexander Bock
2023-01-28 19:50:47 +01:00
290 changed files with 2273 additions and 2405 deletions
+25 -14
View File
@@ -55,6 +55,9 @@ namespace {
};
struct [[codegen::Dictionary(Browser)]] Parameters {
// [[codegen::verbatim(DimensionsInfo.description)]]
std::optional<glm::ivec2> dimensions;
// [[codegen::verbatim(UrlInfo.description)]]
std::optional<std::string> url;
@@ -78,7 +81,7 @@ void Browser::RenderHandler::setTexture(GLuint t) {
Browser::Browser(const ghoul::Dictionary& dictionary)
: _browserDimensions(
DimensionsInfo,
global::windowDelegate->currentSubwindowSize(),
glm::vec2(1000.f),
glm::vec2(10.f),
glm::vec2(3000.f)
)
@@ -90,7 +93,9 @@ Browser::Browser(const ghoul::Dictionary& dictionary)
_url = p.url.value_or(_url);
_url.onChange([this]() { _isUrlDirty = true; });
_browserDimensions = p.dimensions.value_or(_browserDimensions);
_browserDimensions.onChange([this]() { _isDimensionsDirty = true; });
_reload.onChange([this]() { _shouldReload = true; });
// Create browser and render handler
@@ -119,6 +124,9 @@ void Browser::initializeGL() {
_browserInstance->initialize();
_browserInstance->loadUrl(_url);
// Update the dimensions upon initialization. Do this with flag as it affects
// derived classes as well
_isDimensionsDirty = true;
}
void Browser::deinitializeGL() {
@@ -153,11 +161,7 @@ void Browser::update() {
}
if (_isDimensionsDirty) {
glm::vec2 dim = _browserDimensions;
if (dim.x > 0 && dim.y > 0) {
_browserInstance->reshape(dim);
_isDimensionsDirty = false;
}
updateBrowserDimensions();
}
if (_shouldReload) {
@@ -170,10 +174,6 @@ bool Browser::isReady() const {
return _texture.get();
}
glm::vec2 Browser::browserPixelDimensions() const {
return _browserDimensions;
}
// Updates the browser size to match the size of the texture
void Browser::updateBrowserSize() {
_browserDimensions = _texture->dimensions();
@@ -183,15 +183,26 @@ void Browser::reload() {
_reload.set(true);
}
void Browser::setRatio(float ratio) {
float relativeRatio = ratio / browserRatio();
float newX = static_cast<float>(_browserDimensions.value().x) * relativeRatio;
glm::ivec2 newDims = { static_cast<int>(floor(newX)), _browserDimensions.value().y };
_browserDimensions = newDims;
_isDimensionsDirty = true;
}
float Browser::browserRatio() const {
return static_cast<float>(_texture->dimensions().x) /
static_cast<float>(_texture->dimensions().y);
}
void Browser::setCallbackDimensions(const std::function<void(const glm::dvec2&)>& func) {
_browserDimensions.onChange([&]() {
func(_browserDimensions.value());
});
void Browser::updateBrowserDimensions() {
glm::ivec2 dim = _browserDimensions;
if (dim.x > 0 && dim.y > 0) {
_texture->setDimensions(glm::uvec3(_browserDimensions.value(), 1));
_browserInstance->reshape(dim);
_isDimensionsDirty = false;
}
}
void Browser::executeJavascript(const std::string& script) const {
@@ -58,7 +58,7 @@ namespace {
constexpr openspace::properties::Property::PropertyInfo RectangleThresholdInfo = {
"RectangleThreshold",
"Rectangle Threshold",
"When the field of view is larger than the rectangle threshold, a rectangle will"
"When the field of view is larger than the rectangle threshold, a rectangle will "
"be rendered in the target"
};
@@ -188,7 +188,7 @@ void RenderableSkyTarget::render(const RenderData& data, RendererTasks&) {
ZoneScoped
const bool showRectangle = _verticalFov > _showRectangleThreshold;
glm::vec4 color = { glm::vec3(_borderColor) / 255.f, 1.0 };
glm::vec4 color = glm::vec4(glm::vec3(_borderColor) / 255.f, 1.0);
_shader->activate();
_shader->setUniform("opacity", opacity());
@@ -105,7 +105,7 @@ documentation::Documentation ScreenSpaceSkyBrowser::Documentation() {
ScreenSpaceSkyBrowser::ScreenSpaceSkyBrowser(const ghoul::Dictionary& dictionary)
: ScreenSpaceRenderable(dictionary)
, WwtCommunicator(dictionary)
, _textureQuality(TextureQualityInfo, 0.5f, 0.25f, 1.f)
, _textureQuality(TextureQualityInfo, 1.f, 0.25f, 1.f)
, _isHidden(IsHiddenInfo, true)
{
_identifier = makeUniqueIdentifier(_identifier);
@@ -122,17 +122,12 @@ ScreenSpaceSkyBrowser::ScreenSpaceSkyBrowser(const ghoul::Dictionary& dictionary
addProperty(_textureQuality);
addProperty(_verticalFov);
_textureQuality.onChange([this]() { _textureDimensionsIsDirty = true; });
_textureQuality.onChange([this]() { _isDimensionsDirty = true; });
if (global::windowDelegate->isMaster()) {
_borderColor = randomBorderColor();
}
_scale.onChange([this]() {
updateTextureResolution();
_borderRadiusTimer = 0;
});
_useRadiusAzimuthElevation.onChange(
[this]() {
std::for_each(
@@ -160,7 +155,6 @@ ScreenSpaceSkyBrowser::~ScreenSpaceSkyBrowser() {
bool ScreenSpaceSkyBrowser::initializeGL() {
WwtCommunicator::initializeGL();
ScreenSpaceRenderable::initializeGL();
updateTextureResolution();
return true;
}
@@ -192,19 +186,18 @@ void ScreenSpaceSkyBrowser::setIsInitialized(bool isInitialized) {
}
void ScreenSpaceSkyBrowser::updateTextureResolution() {
// Scale texture depending on the height of the window
// Set texture size to the actual pixel size it covers
glm::vec2 pixels = glm::vec2(global::windowDelegate->currentSubwindowSize());
// Check if texture quality has changed. If it has, adjust accordingly
if (abs(_textureQuality.value() - _lastTextureQuality) > glm::epsilon<float>()) {
float diffTextureQuality = _textureQuality / _lastTextureQuality;
glm::vec2 newRes = glm::vec2(_browserDimensions.value()) * diffTextureQuality;
_browserDimensions = glm::ivec2(newRes);
_lastTextureQuality = _textureQuality.value();
}
_objectSize = glm::ivec3(_browserDimensions.value(), 1);
// If the scale is 1, it covers half the window. Hence multiplication with 2
float newResY = pixels.y * 2.f * _scale;
float newResX = newResY * _ratio;
glm::vec2 newSize = glm::vec2(newResX , newResY) * _textureQuality.value();
_browserDimensions = glm::ivec2(newSize);
_texture->setDimensions(glm::ivec3(newSize, 1));
_objectSize = glm::ivec3(_texture->dimensions());
// The radius has to be updated when the texture resolution has changed
_radiusIsDirty = true;
_borderRadiusTimer = 0;
}
void ScreenSpaceSkyBrowser::addDisplayCopy(const glm::vec3& raePosition, int nCopies) {
@@ -313,16 +306,9 @@ void ScreenSpaceSkyBrowser::render() {
}
void ScreenSpaceSkyBrowser::update() {
// Texture of window is 1x1 when minimized
bool isWindow = global::windowDelegate->currentSubwindowSize() != glm::ivec2(1);
bool isWindowResized = global::windowDelegate->windowHasResized();
if ((isWindowResized && isWindow) || _textureDimensionsIsDirty) {
// Check for dirty flags
if (_isDimensionsDirty) {
updateTextureResolution();
_textureDimensionsIsDirty = false;
}
if (_ratioIsDirty) {
updateTextureResolution();
_ratioIsDirty = false;
}
if (_shouldReload) {
_isInitialized = false;
@@ -369,11 +355,6 @@ void ScreenSpaceSkyBrowser::setOpacity(float opacity) {
_opacity = opacity;
}
void ScreenSpaceSkyBrowser::setRatio(float ratio) {
_ratio = ratio;
_ratioIsDirty = true;
}
float ScreenSpaceSkyBrowser::opacity() const {
return _opacity;
}