mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-23 04:30:09 -05:00
Add simple plane geometry class
This commit is contained in:
@@ -133,6 +133,8 @@ RenderableDisc::RenderableDisc(const ghoul::Dictionary& dictionary)
|
||||
_textureFile->setCallback([&](const File&) { _textureIsDirty = true; });
|
||||
|
||||
addProperty(_opacity);
|
||||
|
||||
_plane = std::make_unique<PlaneGeometry>(2*_size);
|
||||
}
|
||||
|
||||
bool RenderableDisc::isReady() const {
|
||||
@@ -148,19 +150,13 @@ void RenderableDisc::initializeGL() {
|
||||
|
||||
ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames);
|
||||
|
||||
glGenVertexArrays(1, &_quad);
|
||||
glGenBuffers(1, &_vertexPositionBuffer);
|
||||
|
||||
createPlane();
|
||||
_plane->initialize();
|
||||
loadTexture();
|
||||
}
|
||||
|
||||
void RenderableDisc::deinitializeGL() {
|
||||
glDeleteVertexArrays(1, &_quad);
|
||||
_quad = 0;
|
||||
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
_vertexPositionBuffer = 0;
|
||||
_plane->deinitialize();
|
||||
_plane = nullptr;
|
||||
|
||||
_textureFile = nullptr;
|
||||
_texture = nullptr;
|
||||
@@ -197,8 +193,7 @@ void RenderableDisc::render(const RenderData& data, RendererTasks&) {
|
||||
glDepthMask(false);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
_plane->render();
|
||||
|
||||
_shader->deactivate();
|
||||
|
||||
@@ -215,7 +210,7 @@ void RenderableDisc::update(const UpdateData&) {
|
||||
}
|
||||
|
||||
if (_planeIsDirty) {
|
||||
createPlane();
|
||||
_plane->updateSize(2*_size);
|
||||
_planeIsDirty = false;
|
||||
}
|
||||
|
||||
@@ -251,46 +246,4 @@ void RenderableDisc::loadTexture() {
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableDisc::createPlane() {
|
||||
const GLfloat size = _size;
|
||||
|
||||
struct VertexData {
|
||||
GLfloat x;
|
||||
GLfloat y;
|
||||
GLfloat s;
|
||||
GLfloat t;
|
||||
};
|
||||
|
||||
VertexData data[] = {
|
||||
{ -size, -size, 0.f, 0.f },
|
||||
{ size, size, 1.f, 1.f },
|
||||
{ -size, size, 0.f, 1.f },
|
||||
{ -size, -size, 0.f, 0.f },
|
||||
{ size, -size, 1.f, 0.f },
|
||||
{ size, size, 1.f, 1.f },
|
||||
};
|
||||
|
||||
glBindVertexArray(_quad);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(
|
||||
0,
|
||||
2,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
sizeof(VertexData),
|
||||
nullptr
|
||||
);
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(
|
||||
1,
|
||||
2,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
sizeof(VertexData),
|
||||
reinterpret_cast<void*>(offsetof(VertexData, s)) // NOLINT
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
|
||||
#include <openspace/util/planegeometry.h>
|
||||
#include <ghoul/opengl/uniformcache.h>
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
@@ -59,7 +59,6 @@ public:
|
||||
|
||||
private:
|
||||
void loadTexture();
|
||||
void createPlane();
|
||||
|
||||
properties::StringProperty _texturePath;
|
||||
properties::FloatProperty _size;
|
||||
@@ -70,9 +69,9 @@ private:
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
std::unique_ptr<ghoul::filesystem::File> _textureFile;
|
||||
|
||||
std::unique_ptr<PlaneGeometry> _plane;
|
||||
|
||||
bool _textureIsDirty = false;
|
||||
GLuint _quad = 0;
|
||||
GLuint _vertexPositionBuffer = 0;
|
||||
bool _planeIsDirty = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -158,6 +158,8 @@ RenderableOrbitDisc::RenderableOrbitDisc(const ghoul::Dictionary& dictionary)
|
||||
addProperty(_eccentricity);
|
||||
|
||||
addProperty(_opacity);
|
||||
|
||||
_plane = std::make_unique<PlaneGeometry>(planeSize());
|
||||
}
|
||||
|
||||
bool RenderableOrbitDisc::isReady() const {
|
||||
@@ -173,19 +175,13 @@ void RenderableOrbitDisc::initializeGL() {
|
||||
|
||||
ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames);
|
||||
|
||||
glGenVertexArrays(1, &_quad);
|
||||
glGenBuffers(1, &_vertexPositionBuffer);
|
||||
|
||||
createPlane();
|
||||
_plane->initialize();
|
||||
loadTexture();
|
||||
}
|
||||
|
||||
void RenderableOrbitDisc::deinitializeGL() {
|
||||
glDeleteVertexArrays(1, &_quad);
|
||||
_quad = 0;
|
||||
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
_vertexPositionBuffer = 0;
|
||||
_plane->deinitialize();
|
||||
_plane = nullptr;
|
||||
|
||||
_textureFile = nullptr;
|
||||
_texture = nullptr;
|
||||
@@ -223,8 +219,7 @@ void RenderableOrbitDisc::render(const RenderData& data, RendererTasks&) {
|
||||
glDepthMask(false);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
_plane->render();
|
||||
|
||||
_shader->deactivate();
|
||||
|
||||
@@ -241,7 +236,7 @@ void RenderableOrbitDisc::update(const UpdateData&) {
|
||||
}
|
||||
|
||||
if (_planeIsDirty) {
|
||||
createPlane();
|
||||
_plane->updateSize(planeSize());
|
||||
_planeIsDirty = false;
|
||||
}
|
||||
|
||||
@@ -274,47 +269,10 @@ void RenderableOrbitDisc::loadTexture() {
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableOrbitDisc::createPlane() {
|
||||
const GLfloat outerDistance = (_size + _offset.value().y * _size);
|
||||
const GLfloat size = outerDistance * (1.f + _eccentricity);
|
||||
|
||||
struct VertexData {
|
||||
GLfloat x;
|
||||
GLfloat y;
|
||||
GLfloat s;
|
||||
GLfloat t;
|
||||
};
|
||||
|
||||
VertexData data[] = {
|
||||
{ -size, -size, 0.f, 0.f },
|
||||
{ size, size, 1.f, 1.f },
|
||||
{ -size, size, 0.f, 1.f },
|
||||
{ -size, -size, 0.f, 0.f },
|
||||
{ size, -size, 1.f, 0.f },
|
||||
{ size, size, 1.f, 1.f },
|
||||
};
|
||||
|
||||
glBindVertexArray(_quad);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(
|
||||
0,
|
||||
2,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
sizeof(VertexData),
|
||||
nullptr
|
||||
);
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(
|
||||
1,
|
||||
2,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
sizeof(VertexData),
|
||||
reinterpret_cast<void*>(offsetof(VertexData, s))
|
||||
);
|
||||
float RenderableOrbitDisc::planeSize() const {
|
||||
float maxRadius = _size + _offset.value().y * _size;
|
||||
maxRadius *= (1.f + _eccentricity);
|
||||
return 2.f * maxRadius;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
#include <openspace/properties/vector/vec2property.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/util/planegeometry.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/uniformcache.h>
|
||||
@@ -58,7 +59,9 @@ public:
|
||||
|
||||
private:
|
||||
void loadTexture();
|
||||
void createPlane();
|
||||
|
||||
// Computes the size of the plane quad using the relevant properties
|
||||
float planeSize() const;
|
||||
|
||||
properties::StringProperty _texturePath;
|
||||
properties::FloatProperty _size;
|
||||
@@ -71,10 +74,10 @@ private:
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture = nullptr;
|
||||
std::unique_ptr<ghoul::filesystem::File> _textureFile;
|
||||
|
||||
std::unique_ptr<PlaneGeometry> _plane;
|
||||
|
||||
bool _textureIsDirty = false;
|
||||
bool _planeIsDirty = false;
|
||||
GLuint _quad = 0;
|
||||
GLuint _vertexPositionBuffer = 0;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user