mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 19:19:39 -06:00
Started working on Renderables
- Making sure isReady is properly set - Making sure initialization is done correctly - Making sure deinitialization is done correctly
This commit is contained in:
@@ -32,8 +32,12 @@
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
class Texture;
|
||||
}
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ private:
|
||||
|
||||
ghoul::opengl::ProgramObject* _shader;
|
||||
GLuint _fieldlineVAO;
|
||||
GLuint _vertexPositionBuffer;
|
||||
|
||||
std::vector<GLint> _lineStart;
|
||||
std::vector<GLsizei> _lineCount;
|
||||
|
||||
@@ -67,6 +67,7 @@ private:
|
||||
ghoul::opengl::ProgramObject* _shader;
|
||||
ghoul::opengl::Texture* _texture;
|
||||
GLuint _quad;
|
||||
GLuint _vertexPositionBuffer;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -53,6 +53,7 @@ namespace openspace {
|
||||
class RenderableConstellationBounds : public Renderable {
|
||||
public:
|
||||
RenderableConstellationBounds(const ghoul::Dictionary& dictionary);
|
||||
~RenderableConstellationBounds();
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
|
||||
@@ -56,7 +56,6 @@ private:
|
||||
GLuint _vBufferID;
|
||||
GLuint _iBufferID;
|
||||
|
||||
GLenum _mode;
|
||||
unsigned int _isize;
|
||||
unsigned int _vsize;
|
||||
Vertex* _varray;
|
||||
|
||||
@@ -52,7 +52,12 @@ namespace {
|
||||
|
||||
namespace openspace {
|
||||
|
||||
ABuffer::ABuffer() : _validShader(false), _resolveShader(nullptr) {
|
||||
ABuffer::ABuffer()
|
||||
: _validShader(false)
|
||||
, _resolveShader(nullptr)
|
||||
, _volumeStepFactor(0.0f)
|
||||
{
|
||||
|
||||
updateDimensions();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,16 +25,18 @@
|
||||
// open space includes
|
||||
#include <openspace/rendering/planets/renderableplanet.h>
|
||||
#include <openspace/util/constants.h>
|
||||
#include <openspace/rendering/planets/planetgeometry.h>
|
||||
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
|
||||
#include <openspace/rendering/planets/planetgeometry.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <sgct.h>
|
||||
|
||||
namespace {
|
||||
@@ -52,11 +54,13 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
|
||||
{
|
||||
std::string name;
|
||||
bool success = dictionary.getValue(constants::scenegraphnode::keyName, name);
|
||||
assert(success);
|
||||
ghoul_assert(success,
|
||||
"RenderablePlanet need the '" <<constants::scenegraphnode::keyName<<"' be specified");
|
||||
|
||||
std::string path;
|
||||
success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
|
||||
assert(success);
|
||||
ghoul_assert(success,
|
||||
"RenderablePlanet need the '"<<constants::scenegraph::keyPathModule<<"' be specified");
|
||||
|
||||
ghoul::Dictionary geometryDictionary;
|
||||
success = dictionary.getValue(
|
||||
@@ -87,34 +91,37 @@ RenderablePlanet::~RenderablePlanet() {}
|
||||
bool RenderablePlanet::initialize() {
|
||||
bool completeSuccess = true;
|
||||
if (_programObject == nullptr)
|
||||
completeSuccess
|
||||
&= OsEng.ref().configurationManager().getValue("pscShader", _programObject);
|
||||
OsEng.ref().configurationManager().getValue("pscShader", _programObject);
|
||||
|
||||
loadTexture();
|
||||
completeSuccess &= (_texture != nullptr);
|
||||
completeSuccess &= _geometry->initialize(this);
|
||||
_geometry->initialize(this);
|
||||
|
||||
return completeSuccess;
|
||||
return isReady();
|
||||
}
|
||||
|
||||
bool RenderablePlanet::deinitialize() {
|
||||
_geometry->deinitialize();
|
||||
delete _geometry;
|
||||
if(_geometry) {
|
||||
_geometry->deinitialize();
|
||||
delete _geometry;
|
||||
}
|
||||
if(_texture)
|
||||
delete _texture;
|
||||
|
||||
_geometry = nullptr;
|
||||
delete _texture;
|
||||
_texture = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderablePlanet::isReady() const {
|
||||
return (_geometry != nullptr);
|
||||
bool ready = true;
|
||||
ready &= (_programObject != nullptr);
|
||||
ready &= (_texture != nullptr);
|
||||
ready &= (_geometry != nullptr);
|
||||
return ready;
|
||||
}
|
||||
|
||||
void RenderablePlanet::render(const RenderData& data)
|
||||
{
|
||||
if (!_programObject) return;
|
||||
if (!_texture) return;
|
||||
|
||||
// activate shader
|
||||
_programObject->activate();
|
||||
|
||||
|
||||
@@ -109,7 +109,9 @@ void SimpleSphereGeometry::createSphere()
|
||||
PowerScaledScalar planetSize(_radius);
|
||||
_parent->setBoundingSphere(planetSize);
|
||||
|
||||
delete _planet;
|
||||
if(_planet)
|
||||
delete _planet;
|
||||
|
||||
_planet = new PowerScaledSphere(planetSize, _segments);
|
||||
_planet->initialize();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <openspace/util/constants.h>
|
||||
|
||||
#include <ghoul/filesystem/file.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "RenderableFieldlines";
|
||||
@@ -43,6 +44,7 @@ namespace openspace {
|
||||
RenderableFieldlines::RenderableFieldlines(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _fieldlineVAO(0)
|
||||
, _vertexPositionBuffer(0)
|
||||
, _shader(nullptr)
|
||||
{
|
||||
std::string name;
|
||||
@@ -86,6 +88,7 @@ RenderableFieldlines::RenderableFieldlines(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
|
||||
RenderableFieldlines::~RenderableFieldlines() {
|
||||
deinitialize();
|
||||
}
|
||||
|
||||
bool RenderableFieldlines::isReady() const {
|
||||
@@ -93,8 +96,14 @@ bool RenderableFieldlines::isReady() const {
|
||||
}
|
||||
|
||||
bool RenderableFieldlines::initialize() {
|
||||
assert(_filenames.size() != 0);
|
||||
assert(_hintsDictionaries.size() != 0);
|
||||
if(_filenames.size() == 0) {
|
||||
LWARNING("No proper filenames provided, cannot initialize!");
|
||||
return false;
|
||||
}
|
||||
|
||||
ghoul_assert(_hintsDictionaries.size() != _filenames.size(),
|
||||
"The dictionary sizes should match, "
|
||||
<< _hintsDictionaries.size() << " != " << _filenames.size());
|
||||
|
||||
int prevEnd = 0;
|
||||
std::vector<LinePoint> vertexData;
|
||||
@@ -115,11 +124,10 @@ bool RenderableFieldlines::initialize() {
|
||||
LDEBUG("Number of vertices : " << vertexData.size());
|
||||
|
||||
// ------ FIELDLINES -----------------
|
||||
GLuint vertexPositionBuffer;
|
||||
glGenVertexArrays(1, &_fieldlineVAO); // generate array
|
||||
glBindVertexArray(_fieldlineVAO); // bind array
|
||||
glGenBuffers(1, &vertexPositionBuffer); // generate buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexPositionBuffer); // bind buffer
|
||||
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer
|
||||
glBufferData(GL_ARRAY_BUFFER, vertexData.size()*sizeof(LinePoint), &vertexData.front(), GL_STATIC_DRAW);
|
||||
|
||||
// Vertex positions
|
||||
@@ -136,18 +144,19 @@ bool RenderableFieldlines::initialize() {
|
||||
glBindVertexArray(0); //unbind array
|
||||
|
||||
OsEng.ref().configurationManager().getValue("FieldlineProgram", _shader);
|
||||
assert(_shader);
|
||||
|
||||
return true;
|
||||
return isReady();
|
||||
}
|
||||
|
||||
bool RenderableFieldlines::deinitialize() {
|
||||
glDeleteVertexArrays(1, &_fieldlineVAO);
|
||||
_fieldlineVAO = 0;
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
_vertexPositionBuffer = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderableFieldlines::render(const RenderData& data) {
|
||||
if (!_shader)
|
||||
return;
|
||||
|
||||
_shader->activate();
|
||||
_shader->setUniform("modelViewProjection", data.camera.viewProjectionMatrix());
|
||||
@@ -158,8 +167,8 @@ void RenderableFieldlines::render(const RenderData& data) {
|
||||
// ------ DRAW FIELDLINES -----------------
|
||||
glBindVertexArray(_fieldlineVAO);
|
||||
glMultiDrawArrays(GL_LINE_STRIP_ADJACENCY, &_lineStart[0], &_lineCount[0], _lineStart.size());
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
_shader->deactivate();
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
|
||||
, _shader(nullptr)
|
||||
, _texture(nullptr)
|
||||
, _quad(0)
|
||||
, _vertexPositionBuffer(0)
|
||||
{
|
||||
|
||||
dictionary.getValue("Size", _size);
|
||||
@@ -87,7 +88,6 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
|
||||
if (success)
|
||||
_texturePath = findPath(texturePath);
|
||||
|
||||
|
||||
addProperty(_texturePath);
|
||||
_texturePath.onChange(std::bind(&RenderablePlane::loadTexture, this));
|
||||
|
||||
@@ -95,10 +95,16 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
|
||||
RenderablePlane::~RenderablePlane() {
|
||||
deinitialize();
|
||||
}
|
||||
|
||||
bool RenderablePlane::isReady() const {
|
||||
return _shader != nullptr;
|
||||
bool ready = true;
|
||||
if (!_shader)
|
||||
ready &= false;
|
||||
if(!_texture)
|
||||
ready &= false;
|
||||
return ready;
|
||||
}
|
||||
|
||||
bool RenderablePlane::initialize() {
|
||||
@@ -108,8 +114,6 @@ bool RenderablePlane::initialize() {
|
||||
// ============================
|
||||
const GLfloat size = _size[0];
|
||||
const GLfloat w = _size[1];
|
||||
LDEBUG("size:" << size);
|
||||
LDEBUG("w:" << w);
|
||||
const GLfloat vertex_data[] = { // square of two triangles (sigh)
|
||||
// x y z w s t
|
||||
-size, -size, 0.0f, w, 0,1,
|
||||
@@ -120,11 +124,10 @@ bool RenderablePlane::initialize() {
|
||||
size, size, 0.0f, w, 1, 0,
|
||||
};
|
||||
|
||||
GLuint vertexPositionBuffer;
|
||||
glGenVertexArrays(1, &_quad); // generate array
|
||||
glBindVertexArray(_quad); // bind array
|
||||
glGenBuffers(1, &vertexPositionBuffer); // generate buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexPositionBuffer); // bind buffer
|
||||
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(0));
|
||||
@@ -133,25 +136,23 @@ bool RenderablePlane::initialize() {
|
||||
|
||||
OsEng.ref().configurationManager().getValue("PlaneProgram", _shader);
|
||||
|
||||
if (!_shader)
|
||||
return false;
|
||||
|
||||
loadTexture();
|
||||
|
||||
return true;
|
||||
return isReady();
|
||||
}
|
||||
|
||||
bool RenderablePlane::deinitialize() {
|
||||
glDeleteVertexArrays(1, &_quad);
|
||||
_quad = 0;
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
_vertexPositionBuffer = 0;
|
||||
if(_texture)
|
||||
delete _texture;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderablePlane::render(const RenderData& data) {
|
||||
|
||||
if (!_shader)
|
||||
return;
|
||||
if (!_texture)
|
||||
return;
|
||||
|
||||
glm::mat4 transform = glm::mat4(1.0);
|
||||
if (_billboard)
|
||||
transform = glm::inverse(data.camera.viewRotationMatrix());
|
||||
|
||||
@@ -136,6 +136,15 @@ bool RenderableSphericalGrid::isReady() const {
|
||||
}
|
||||
|
||||
bool RenderableSphericalGrid::deinitialize(){
|
||||
glDeleteVertexArrays(1,&_vaoID);
|
||||
_vaoID = 0;
|
||||
|
||||
glDeleteBuffers(1,&_vBufferID);
|
||||
_vBufferID = 0;
|
||||
|
||||
glDeleteBuffers(1,&_iBufferID);
|
||||
_iBufferID = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -173,7 +182,6 @@ bool RenderableSphericalGrid::initialize(){
|
||||
}
|
||||
|
||||
void RenderableSphericalGrid::render(const RenderData& data){
|
||||
assert(_gridProgram);
|
||||
_gridProgram->activate();
|
||||
|
||||
// setup the data to the shader
|
||||
@@ -194,8 +202,8 @@ void RenderableSphericalGrid::render(const RenderData& data){
|
||||
glBindVertexArray(0);
|
||||
|
||||
_gridProgram->deactivate();
|
||||
|
||||
}
|
||||
|
||||
void RenderableSphericalGrid::update(const UpdateData& data){
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,10 @@ RenderableConstellationBounds::RenderableConstellationBounds(
|
||||
);
|
||||
}
|
||||
|
||||
RenderableConstellationBounds::~RenderableConstellationBounds() {
|
||||
deinitialize();
|
||||
}
|
||||
|
||||
bool RenderableConstellationBounds::initialize() {
|
||||
_program = ghoul::opengl::ProgramObject::Build("ConstellationBounds",
|
||||
"${SHADERS}/modules/constellationbounds/constellationbounds_vs.glsl",
|
||||
@@ -138,7 +142,7 @@ bool RenderableConstellationBounds::deinitialize() {
|
||||
}
|
||||
|
||||
bool RenderableConstellationBounds::isReady() const {
|
||||
return (_vao != 0) && (_vbo != 0);
|
||||
return (_vao != 0) && (_vbo != 0) && (_program != nullptr);
|
||||
}
|
||||
|
||||
void RenderableConstellationBounds::render(const RenderData& data) {
|
||||
|
||||
@@ -40,7 +40,6 @@ PowerScaledSphere::PowerScaledSphere(const PowerScaledScalar& radius, int segmen
|
||||
: _vaoID(0)
|
||||
, _vBufferID(0)
|
||||
, _iBufferID(0)
|
||||
, _mode(GL_TRIANGLES)
|
||||
, _isize(6 * segments * segments)
|
||||
, _vsize((segments + 1) * (segments + 1))
|
||||
, _varray(new Vertex[_vsize])
|
||||
@@ -191,7 +190,7 @@ void PowerScaledSphere::render()
|
||||
{
|
||||
glBindVertexArray(_vaoID); // select first VAO
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID);
|
||||
glDrawElements(_mode, _isize, GL_UNSIGNED_INT, 0);
|
||||
glDrawElements(GL_TRIANGLES, _isize, GL_UNSIGNED_INT, 0);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user