Merge pull request #2608 from OpenSpace/feature/video-module

Video module
This commit is contained in:
Ylva Selling
2023-04-14 18:28:35 -04:00
committed by GitHub
34 changed files with 2763 additions and 53 deletions

View File

@@ -41,6 +41,7 @@
#include <ghoul/glm.h>
#include <glm/gtx/string_cast.hpp>
#include <optional>
#include <variant>
namespace {
enum BlendMode {
@@ -70,6 +71,13 @@ namespace {
"This value specifies the size of the plane in meters"
};
constexpr openspace::properties::Property::PropertyInfo AutoScaleInfo = {
"AutoScale",
"Auto Scale",
"When true, the plane will automatically adjust in size to match the aspect "
"ratio of the content. Otherwise it will remain in the given size."
};
constexpr openspace::properties::Property::PropertyInfo BlendModeInfo = {
"BlendMode",
"Blending Mode",
@@ -91,7 +99,7 @@ namespace {
std::optional<bool> mirrorBackside;
// [[codegen::verbatim(SizeInfo.description)]]
float size;
std::variant<float, glm::vec2> size;
enum class [[codegen::map(BlendMode)]] BlendMode {
Normal,
@@ -117,14 +125,21 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
, _blendMode(BlendModeInfo, properties::OptionProperty::DisplayType::Dropdown)
, _billboard(BillboardInfo, false)
, _mirrorBackside(MirrorBacksideInfo, false)
, _size(SizeInfo, 10.f, 0.f, 1e25f)
, _size(SizeInfo, glm::vec2(10.f), glm::vec2(0.f), glm::vec2(1e25f))
, _autoScale(AutoScaleInfo, false)
, _multiplyColor(MultiplyColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f))
{
Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(Fadeable::_opacity);
_size = p.size;
if (std::holds_alternative<float>(p.size)) {
_size = glm::vec2(std::get<float>(p.size));
}
else {
_size = std::get<glm::vec2>(p.size);
}
_billboard = p.billboard.value_or(_billboard);
_mirrorBackside = p.mirrorBackside.value_or(_mirrorBackside);
@@ -164,9 +179,11 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
addProperty(_size);
_size.onChange([this](){ _planeIsDirty = true; });
addProperty(_autoScale);
addProperty(_multiplyColor);
setBoundingSphere(_size);
setBoundingSphere(glm::compMax(_size.value()));
}
bool RenderablePlane::isReady() const {
@@ -298,15 +315,16 @@ void RenderablePlane::update(const UpdateData&) {
}
void RenderablePlane::createPlane() {
const GLfloat size = _size;
const GLfloat sizeX = _size.value().x;
const GLfloat sizeY = _size.value().y;
const GLfloat vertexData[] = {
// x y z w s t
-size, -size, 0.f, 0.f, 0.f, 0.f,
size, size, 0.f, 0.f, 1.f, 1.f,
-size, size, 0.f, 0.f, 0.f, 1.f,
-size, -size, 0.f, 0.f, 0.f, 0.f,
size, -size, 0.f, 0.f, 1.f, 0.f,
size, size, 0.f, 0.f, 1.f, 1.f,
// x y z w s t
-sizeX, -sizeY, 0.f, 0.f, 0.f, 0.f,
sizeX, sizeY, 0.f, 0.f, 1.f, 1.f,
-sizeX, sizeY, 0.f, 0.f, 0.f, 1.f,
-sizeX, -sizeY, 0.f, 0.f, 0.f, 0.f,
sizeX, -sizeY, 0.f, 0.f, 1.f, 0.f,
sizeX, sizeY, 0.f, 0.f, 1.f, 1.f,
};
glBindVertexArray(_quad);

View File

@@ -30,7 +30,7 @@
#include <openspace/properties/optionproperty.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/vector/vec2property.h>
#include <openspace/properties/vector/vec3property.h>
#include <ghoul/opengl/ghoul_gl.h>
@@ -72,7 +72,8 @@ protected:
properties::OptionProperty _blendMode;
properties::BoolProperty _billboard;
properties::BoolProperty _mirrorBackside;
properties::FloatProperty _size;
properties::Vec2Property _size;
properties::BoolProperty _autoScale;
properties::Vec3Property _multiplyColor;
ghoul::opengl::ProgramObject* _shader = nullptr;

View File

@@ -93,6 +93,31 @@ RenderablePlaneImageLocal::RenderablePlaneImageLocal(const ghoul::Dictionary& di
}
});
}
_autoScale.onChange([this]() {
if (!_autoScale) {
return;
}
// Shape the plane based on the aspect ration of the image
glm::vec2 textureDim = glm::vec2(_texture->dimensions());
if (_textureDimensions != textureDim) {
float aspectRatio = textureDim.x / textureDim.y;
float planeAspectRatio = _size.value().x / _size.value().y;
if (std::abs(planeAspectRatio - aspectRatio) >
std::numeric_limits<float>::epsilon())
{
glm::vec2 newSize =
aspectRatio > 0.f ?
glm::vec2(_size.value().x * aspectRatio, _size.value().y) :
glm::vec2(_size.value().x, _size.value().y * aspectRatio);
_size = newSize;
}
_textureDimensions = textureDim;
}
});
}
bool RenderablePlaneImageLocal::isReady() const {
@@ -162,6 +187,29 @@ void RenderablePlaneImageLocal::loadTexture() {
_textureFile = std::make_unique<ghoul::filesystem::File>(_texturePath.value());
_textureFile->setCallback([this]() { _textureIsDirty = true; });
if (!_autoScale) {
return;
}
// Shape the plane based on the aspect ration of the image
glm::vec2 textureDim = glm::vec2(_texture->dimensions());
if (_textureDimensions != textureDim) {
float aspectRatio = textureDim.x / textureDim.y;
float planeAspectRatio = _size.value().x / _size.value().y;
if (std::abs(planeAspectRatio - aspectRatio) >
std::numeric_limits<float>::epsilon())
{
glm::vec2 newSize =
aspectRatio > 0.f ?
glm::vec2(_size.value().x * aspectRatio, _size.value().y) :
glm::vec2(_size.value().x, _size.value().y * aspectRatio);
_size = newSize;
}
_textureDimensions = textureDim;
}
}
}

View File

@@ -58,6 +58,7 @@ private:
properties::StringProperty _texturePath;
ghoul::opengl::Texture* _texture = nullptr;
glm::vec2 _textureDimensions = glm::vec2(0.f);
std::unique_ptr<ghoul::filesystem::File> _textureFile;
bool _isLoadingLazily = false;

View File

@@ -68,6 +68,31 @@ RenderablePlaneImageOnline::RenderablePlaneImageOnline(
_texturePath.onChange([this]() { _textureIsDirty = true; });
_texturePath = p.url;
addProperty(_texturePath);
_autoScale.onChange([this]() {
if (!_autoScale) {
return;
}
// Shape the plane based on the aspect ration of the image
glm::vec2 textureDim = glm::vec2(_texture->dimensions());
if (_textureDimensions != textureDim) {
float aspectRatio = textureDim.x / textureDim.y;
float planeAspectRatio = _size.value().x / _size.value().y;
if (std::abs(planeAspectRatio - aspectRatio) >
std::numeric_limits<float>::epsilon())
{
glm::vec2 newSize =
aspectRatio > 0.f ?
glm::vec2(_size.value().x * aspectRatio, _size.value().y) :
glm::vec2(_size.value().x, _size.value().y * aspectRatio);
_size = newSize;
}
_textureDimensions = textureDim;
}
});
}
void RenderablePlaneImageOnline::deinitializeGL() {
@@ -132,6 +157,29 @@ void RenderablePlaneImageOnline::update(const UpdateData& data) {
_texture = std::move(texture);
_textureIsDirty = false;
if (!_autoScale) {
return;
}
// Shape the plane based on the aspect ration of the image
glm::vec2 textureDim = glm::vec2(_texture->dimensions());
if (_textureDimensions != textureDim) {
float aspectRatio = textureDim.x / textureDim.y;
float planeAspectRatio = _size.value().x / _size.value().y;
if (std::abs(planeAspectRatio - aspectRatio) >
std::numeric_limits<float>::epsilon())
{
glm::vec2 newSize =
aspectRatio > 0.f ?
glm::vec2(_size.value().x * aspectRatio, _size.value().y) :
glm::vec2(_size.value().x, _size.value().y * aspectRatio);
_size = newSize;
}
_textureDimensions = textureDim;
}
}
}
catch (const ghoul::io::TextureReader::InvalidLoadException& e) {

View File

@@ -60,6 +60,7 @@ private:
std::future<DownloadManager::MemoryFile> _imageFuture;
std::unique_ptr<ghoul::opengl::Texture> _texture;
glm::vec2 _textureDimensions = glm::vec2(0.f);
bool _textureIsDirty = false;
};