mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-22 19:29:04 -05:00
Remove unused RenderablePath
Add documentations to base module classes Change RenderableSphere to not use power scaled coordinates
This commit is contained in:
@@ -24,38 +24,75 @@
|
||||
|
||||
#include <modules/base/rendering/renderablesphere.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
|
||||
#include <openspace/util/powerscaledsphere.h>
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
namespace {
|
||||
static const std::string _loggerCat = "RenderableSphere";
|
||||
const char* KeySize = "Size";
|
||||
const char* KeySegments = "Segments";
|
||||
const char* KeyTexture = "Texture";
|
||||
const char* KeyOrientation = "Orientation";
|
||||
|
||||
|
||||
const char* keySize = "Size";
|
||||
const char* keySegments = "Segments";
|
||||
const char* keyTexture = "Texture";
|
||||
const char* keyOrientation = "Orientation";
|
||||
|
||||
enum Orientation {
|
||||
Outside = 1,
|
||||
Inside = 2
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
|
||||
documentation::Documentation RenderableSphere::Documentation() {
|
||||
using namespace documentation;
|
||||
return {
|
||||
"RenderableSphere",
|
||||
"base_renderable_sphere",
|
||||
{
|
||||
{
|
||||
KeySize,
|
||||
new DoubleVerifier,
|
||||
"Specifies the radius of the sphere in meters.",
|
||||
Optional::No
|
||||
},
|
||||
{
|
||||
KeySegments,
|
||||
new IntVerifier,
|
||||
"Specifies the number of segments the sphere is separated in.",
|
||||
Optional::No
|
||||
},
|
||||
{
|
||||
KeyTexture,
|
||||
new StringVerifier,
|
||||
"Specifies the texture that is applied to the sphere.",
|
||||
Optional::No
|
||||
},
|
||||
{
|
||||
KeyOrientation,
|
||||
new StringInListVerifier({ "Inside", "Outside", "Inside/Outside" }),
|
||||
"Specifies whether the texture is applied to the inside of the sphere, "
|
||||
"the outside of the sphere, or both. The default value is 'Outside'.",
|
||||
Optional::Yes
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _texturePath("texture", "Texture")
|
||||
, _orientation("orientation", "Orientation")
|
||||
, _size("size", "Size", glm::vec2(1.f, 1.f), glm::vec2(0.f), glm::vec2(100.f))
|
||||
, _size("size", "Size", 1.f, 0.f, std::pow(10.f, 45))
|
||||
, _segments("segments", "Segments", 8, 4, 100)
|
||||
, _transparency("transparency", "Transparency", 1.f, 0.f, 1.f)
|
||||
, _shader(nullptr)
|
||||
@@ -63,67 +100,68 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary)
|
||||
, _sphere(nullptr)
|
||||
, _sphereIsDirty(false)
|
||||
{
|
||||
if (dictionary.hasKeyAndValue<glm::vec2>(keySize)) {
|
||||
glm::vec2 size;
|
||||
dictionary.getValue(keySize, size);
|
||||
_size = size;
|
||||
}
|
||||
documentation::testSpecificationAndThrow(
|
||||
Documentation(),
|
||||
dictionary,
|
||||
"RenderableSphere"
|
||||
);
|
||||
|
||||
if (dictionary.hasKeyAndValue<glm::vec2>(keySegments)) {
|
||||
int segments;
|
||||
dictionary.getValue(keySegments, segments);
|
||||
_segments = segments;
|
||||
}
|
||||
|
||||
if (dictionary.hasKeyAndValue<std::string>(keyTexture)) {
|
||||
std::string texture;
|
||||
dictionary.getValue(keyTexture, texture);
|
||||
_texturePath = absPath(texture);
|
||||
}
|
||||
_size = dictionary.value<double>(KeySize);
|
||||
_segments = static_cast<int>(dictionary.value<double>(KeySegments));
|
||||
_texturePath = absPath(dictionary.value<std::string>(KeyTexture));
|
||||
|
||||
_orientation.addOption(Outside, "Outside");
|
||||
_orientation.addOption(Inside, "Inside");
|
||||
_orientation.addOption(Outside | Inside, "Outside + Inside");
|
||||
_orientation.addOption(Outside | Inside, "Inside/Outside");
|
||||
|
||||
if (dictionary.hasKeyAndValue<std::string>(keyOrientation)) {
|
||||
std::string orientation;
|
||||
dictionary.getValue(keyOrientation, orientation);
|
||||
if (orientation == "Outside")
|
||||
_orientation = Outside;
|
||||
else if (orientation == "Inside")
|
||||
if (dictionary.hasKey(KeyOrientation)) {
|
||||
const std::string v = dictionary.value<std::string>(KeyOrientation);
|
||||
if (v == "Inside") {
|
||||
_orientation = Inside;
|
||||
else
|
||||
}
|
||||
else if (v == "Outside") {
|
||||
_orientation = Outside;
|
||||
}
|
||||
else if (v == "Inside/Outside") {
|
||||
_orientation = Outside | Inside;
|
||||
}
|
||||
else {
|
||||
ghoul_assert(false, "Missing 'case' label");
|
||||
}
|
||||
}
|
||||
else {
|
||||
_orientation = Outside;
|
||||
}
|
||||
|
||||
addProperty(_orientation);
|
||||
|
||||
addProperty(_size);
|
||||
_size.onChange([this](){ _sphereIsDirty = true; });
|
||||
|
||||
addProperty(_segments);
|
||||
_segments.onChange([this](){ _sphereIsDirty = true; });
|
||||
|
||||
addProperty(_transparency);
|
||||
|
||||
addProperty(_texturePath);
|
||||
_texturePath.onChange(std::bind(&RenderableSphere::loadTexture, this));
|
||||
_texturePath.onChange([this]() {loadTexture(); });
|
||||
|
||||
|
||||
setRenderBin(Renderable::RenderBin::Transparent);
|
||||
}
|
||||
|
||||
bool RenderableSphere::isReady() const {
|
||||
return (_sphere != nullptr) && (_shader != nullptr) && (_texture != nullptr);
|
||||
return _shader && _texture;
|
||||
}
|
||||
|
||||
bool RenderableSphere::initialize() {
|
||||
delete _sphere;
|
||||
_sphere = new PowerScaledSphere(_size.value(), _segments);
|
||||
_sphere = std::make_unique<PowerScaledSphere>(
|
||||
PowerScaledScalar::CreatePSS(_size), _segments
|
||||
);
|
||||
_sphere->initialize();
|
||||
|
||||
// pscstandard
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_shader = renderEngine.buildRenderProgram("Sphere",
|
||||
_shader = OsEng.renderEngine().buildRenderProgram("Sphere",
|
||||
"${MODULE_BASE}/shaders/sphere_vs.glsl",
|
||||
"${MODULE_BASE}/shaders/sphere_fs.glsl");
|
||||
if (!_shader)
|
||||
return false;
|
||||
|
||||
loadTexture();
|
||||
|
||||
@@ -131,28 +169,21 @@ bool RenderableSphere::initialize() {
|
||||
}
|
||||
|
||||
bool RenderableSphere::deinitialize() {
|
||||
delete _sphere;
|
||||
_sphere = nullptr;
|
||||
|
||||
_texture = nullptr;
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
OsEng.renderEngine().removeRenderProgram(_shader);
|
||||
_shader = nullptr;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderableSphere::render(const RenderData& data) {
|
||||
|
||||
glm::mat4 transform = glm::mat4(1.0);
|
||||
|
||||
transform = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(1, 0, 0));
|
||||
|
||||
|
||||
// Activate shader
|
||||
using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError;
|
||||
_shader->activate();
|
||||
@@ -171,20 +202,40 @@ void RenderableSphere::render(const RenderData& data) {
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
bool usingFramebufferRenderer =
|
||||
OsEng.renderEngine().rendererImplementation() == RenderEngine::RendererImplementation::Framebuffer;
|
||||
|
||||
bool usingABufferRenderer =
|
||||
OsEng.renderEngine().rendererImplementation() == RenderEngine::RendererImplementation::ABuffer;
|
||||
|
||||
if (usingABufferRenderer) {
|
||||
_shader->setUniform("additiveBlending", true);
|
||||
}
|
||||
|
||||
if (usingFramebufferRenderer) {
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
}
|
||||
|
||||
_sphere->render();
|
||||
|
||||
if (usingFramebufferRenderer) {
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
_shader->setIgnoreUniformLocationError(IgnoreError::No);
|
||||
_shader->deactivate();
|
||||
}
|
||||
|
||||
void RenderableSphere::update(const UpdateData&) {
|
||||
if (_shader->isDirty())
|
||||
if (_shader->isDirty()) {
|
||||
_shader->rebuildFromFile();
|
||||
}
|
||||
|
||||
if (_sphereIsDirty) {
|
||||
delete _sphere;
|
||||
_sphere = new PowerScaledSphere(_size.value(), _segments);
|
||||
_sphere = std::make_unique<PowerScaledSphere>(
|
||||
PowerScaledScalar::CreatePSS(_size), _segments
|
||||
);
|
||||
_sphere->initialize();
|
||||
_sphereIsDirty = false;
|
||||
}
|
||||
@@ -194,7 +245,10 @@ void RenderableSphere::loadTexture() {
|
||||
if (_texturePath.value() != "") {
|
||||
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(_texturePath);
|
||||
if (texture) {
|
||||
LDEBUG("Loaded texture from '" << absPath(_texturePath) << "'");
|
||||
LDEBUGC(
|
||||
"RenderableSphere",
|
||||
"Loaded texture from '" << absPath(_texturePath) << "'"
|
||||
);
|
||||
texture->uploadTexture();
|
||||
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
|
||||
|
||||
Reference in New Issue
Block a user