GridGeometry knows its resolution

This commit is contained in:
Erik Broberg
2016-04-01 12:55:36 -04:00
parent 9779cf83e8
commit 109cd463a8
6 changed files with 47 additions and 7 deletions
@@ -78,8 +78,12 @@ void DistanceSwitch::update(const UpdateData& data) {
void DistanceSwitch::addSwitchValue(std::shared_ptr<Renderable> renderable, double maxDistance) {
ghoul_assert(maxDistance > _maxDistances.back(), "Renderables must be inserted in ascending order wrt distance");
ghoul_assert(maxDistance > 0, "Renderable must have a positive maxDistance");
if (_maxDistances.size() > 0){
ghoul_assert(maxDistance > _maxDistances.back(),
"Renderables must be inserted in ascending order wrt distance");
}
_renderables.push_back(renderable);
_maxDistances.push_back(maxDistance);
}
@@ -45,7 +45,7 @@ class DistanceSwitch : public Renderable {
public:
DistanceSwitch();
~DistanceSwitch();
virtual ~DistanceSwitch();
bool initialize() override;
bool deinitialize() override;
+8 -1
View File
@@ -67,6 +67,8 @@ public:
void render() const;
protected:
// Determines what attribute data is in use
@@ -74,17 +76,22 @@ protected:
bool _useTextureCoordinates;
bool _useVertexNormals;
private:
typedef struct {
public:
GLfloat position[4];
GLfloat texture[2];
GLfloat normal[3];
private:
GLubyte padding[28]; // Pads the struct out to 64 bytes for performance increase
} Vertex;
// Vertex data
std::vector<Vertex> _vertexData;
std::vector<GLuint> _elementData;
private:
// GL handles
GLuint _vaoID;
GLuint _vertexBufferID;
@@ -11,6 +11,7 @@ namespace openspace {
GridGeometry::GridGeometry(unsigned int xRes, unsigned int yRes, Positions usePositions, TextureCoordinates useTextures, Normals useNormals)
: Geometry(CreateElements(xRes, yRes), usePositions, useTextures, useNormals)
{
if(_useVertexPositions){
setVertexPositions(CreatePositions(xRes, yRes));
}
@@ -22,6 +23,9 @@ GridGeometry::GridGeometry(unsigned int xRes, unsigned int yRes, Positions usePo
if (_useVertexNormals) {
setVertexNormals(CreateNormals(xRes, yRes));
}
_xRes = xRes;
_yRes = yRes;
}
@@ -31,9 +35,24 @@ GridGeometry::~GridGeometry()
}
const unsigned int GridGeometry::xResolution() const {
return _xRes;
}
const unsigned int GridGeometry::yResolution() const {
return _yRes;
}
void GridGeometry::validate(unsigned int xRes, unsigned int yRes) {
ghoul_assert(xRes > 0 && yRes > 0,
"Resolution must be larger than 1x1. (" << xRes << ", " << yRes << ")");
"Resolution must be at least 1x1. (" << xRes << ", " << yRes << ")");
}
void GridGeometry::validateIndices(unsigned int x, unsigned int y) {
validate(x, y);
ghoul_assert(x < _xRes, "x index is outside range: x = " << x << " xRes = " << _xRes);
ghoul_assert(y < _yRes, "y index is outside range: y = " << y << " yRes = " << _yRes);
}
inline size_t GridGeometry::numElements(unsigned int xRes, unsigned int yRes){
@@ -53,7 +72,7 @@ std::vector<GLuint> GridGeometry::CreateElements(unsigned int xRes, unsigned int
std::vector<GLuint> elements;
elements.reserve(numElements(xRes, yRes));
for (unsigned int y = 0; y < yRes-1; y++) {
for (unsigned int x = 0; x< xRes-1; x++) {
for (unsigned int x = 0; x < xRes-1; x++) {
// x v00---v10 x ..
// | / |
@@ -49,6 +49,9 @@ public:
~GridGeometry();
inline const unsigned int xResolution() const;
inline const unsigned int yResolution() const;
inline static size_t numElements(unsigned int xRes, unsigned int yRes);
static size_t numVertices(unsigned int xRes, unsigned int yRes);
@@ -59,7 +62,11 @@ private:
static std::vector<glm::vec2> CreateTextureCoordinates(unsigned int xRes, unsigned int yRes);
static std::vector<glm::vec3> CreateNormals(unsigned int xRes, unsigned int yRes);
static void validate(unsigned int xRes, unsigned int yRes);
inline static void validate(unsigned int xRes, unsigned int yRes);
inline void validateIndices(unsigned int x, unsigned int y);
unsigned int _xRes;
unsigned int _yRes;
};
} // namespace openspace
#endif // __GRIDGEOMETRY_H__
@@ -26,6 +26,7 @@
#include <modules/planetbrowsing/rendering/Planet.h>
#include <openspace/scene/scenegraphnode.h>
#include <modules/planetbrowsing/rendering/gridgeometry.h>
namespace {
const std::string _loggerCat = "Planet";
@@ -42,6 +43,8 @@ Planet::Planet(const ghoul::Dictionary& dictionary){
ghoul_assert(success,
"Planet need the '" << SceneGraphNode::KeyName << "' be specified");
new GridGeometry(4, 4, Geometry::Positions::Yes, Geometry::TextureCoordinates::Yes, Geometry::Normals::Yes);
}
Planet::~Planet() {