From 3c8434bee0aa379481df1be88ccc886823ff7dd5 Mon Sep 17 00:00:00 2001 From: Kalle Bladin Date: Fri, 22 Apr 2016 12:14:37 -0400 Subject: [PATCH] Rename resolution to segments in grid classes. --- modules/globebrowsing/rendering/basicgrid.cpp | 90 +++---- modules/globebrowsing/rendering/basicgrid.h | 28 +-- .../globebrowsing/rendering/clipmapgrid.cpp | 238 +++++++++--------- modules/globebrowsing/rendering/clipmapgrid.h | 54 ++-- modules/globebrowsing/rendering/grid.cpp | 8 +- modules/globebrowsing/rendering/grid.h | 29 ++- .../globebrowsing/rendering/patchrenderer.cpp | 2 +- 7 files changed, 225 insertions(+), 224 deletions(-) diff --git a/modules/globebrowsing/rendering/basicgrid.cpp b/modules/globebrowsing/rendering/basicgrid.cpp index 18e5092a95..801985607b 100644 --- a/modules/globebrowsing/rendering/basicgrid.cpp +++ b/modules/globebrowsing/rendering/basicgrid.cpp @@ -31,32 +31,32 @@ namespace { namespace openspace { BasicGrid::BasicGrid( - unsigned int xRes, - unsigned int yRes, + unsigned int xSegments, + unsigned int ySegments, Geometry::Positions usePositions, Geometry::TextureCoordinates useTextureCoordinates, Geometry::Normals useNormals) : Grid( - xRes, - yRes, + xSegments, + ySegments, usePositions, useTextureCoordinates, useNormals) { _geometry = std::unique_ptr(new Geometry( - CreateElements(xRes, yRes), + CreateElements(xSegments, ySegments), usePositions, useTextureCoordinates, useNormals)); if (usePositions == Geometry::Positions::Yes) { - _geometry->setVertexPositions(CreatePositions(_xRes, _yRes)); + _geometry->setVertexPositions(CreatePositions(_xSegments, _ySegments)); } if (useTextureCoordinates == Geometry::TextureCoordinates::Yes) { - _geometry->setVertexTextureCoordinates(CreateTextureCoordinates(_xRes, _yRes)); + _geometry->setVertexTextureCoordinates(CreateTextureCoordinates(_xSegments, _ySegments)); } if (useNormals == Geometry::Normals::Yes) { - _geometry->setVertexNormals(CreateNormals(_xRes, _yRes)); + _geometry->setVertexNormals(CreateNormals(_xSegments, _ySegments)); } } @@ -65,34 +65,34 @@ BasicGrid::~BasicGrid() } -int BasicGrid::xResolution() const { - return _xRes; +int BasicGrid::xSegments() const { + return _xSegments; } -int BasicGrid::yResolution() const { - return _yRes; +int BasicGrid::ySegments() const { + return _ySegments; } -void BasicGrid::validate(int xRes, int yRes) { - ghoul_assert(xRes > 0 && yRes > 0, - "Resolution must be at least 1x1. (" << xRes << ", " << yRes << ")"); +void BasicGrid::validate(int xSegments, int ySegments) { + ghoul_assert(xSegments > 0 && ySegments > 0, + "Resolution must be at least 1x1. (" << xSegments << ", " << ySegments << ")"); } -inline size_t BasicGrid::numElements(int xRes, int yRes){ - return 3 * 2 * xRes * yRes; +inline size_t BasicGrid::numElements(int xSegments, int ySegments){ + return 3 * 2 * xSegments * ySegments; } -inline size_t BasicGrid::numVertices(int xRes, int yRes) { - return (xRes + 1) * (yRes + 1); +inline size_t BasicGrid::numVertices(int xSegments, int ySegments) { + return (xSegments + 1) * (ySegments + 1); } -std::vector BasicGrid::CreateElements(int xRes, int yRes) { - validate(xRes, yRes); +std::vector BasicGrid::CreateElements(int xSegments, int ySegments) { + validate(xSegments, ySegments); std::vector elements; - elements.reserve(numElements(xRes, yRes)); - for (unsigned int y = 0; y < yRes; y++) { - for (unsigned int x = 0; x < xRes; x++) { + elements.reserve(numElements(xSegments, ySegments)); + for (unsigned int y = 0; y < ySegments; y++) { + for (unsigned int x = 0; x < xSegments; x++) { // x v01---v11 x .. // | / | @@ -101,10 +101,10 @@ std::vector BasicGrid::CreateElements(int xRes, int yRes) { // x x x x .. // : : : : - GLuint v00 = (y + 0) * (xRes + 1) + x + 0; - GLuint v10 = (y + 0) * (xRes + 1) + x + 1; - GLuint v01 = (y + 1) * (xRes + 1) + x + 0; - GLuint v11 = (y + 1) * (xRes + 1) + x + 1; + GLuint v00 = (y + 0) * (xSegments + 1) + x + 0; + GLuint v10 = (y + 0) * (xSegments + 1) + x + 1; + GLuint v01 = (y + 1) * (xSegments + 1) + x + 0; + GLuint v11 = (y + 1) * (xSegments + 1) + x + 1; // add upper triangle elements.push_back(v00); @@ -122,15 +122,15 @@ std::vector BasicGrid::CreateElements(int xRes, int yRes) { } std::vector BasicGrid::CreatePositions( - int xRes, - int yRes) + int xSegments, + int ySegments) { - validate(xRes, yRes); + validate(xSegments, ySegments); std::vector positions; - positions.reserve(numVertices(xRes, yRes)); + positions.reserve(numVertices(xSegments, ySegments)); // Copy from 2d texture coordinates and use as template to create positions - std::vector templateTextureCoords = CreateTextureCoordinates(xRes, yRes); + std::vector templateTextureCoords = CreateTextureCoordinates(xSegments, ySegments); for (unsigned int i = 0; i < templateTextureCoords.size(); i++) { positions.push_back(glm::vec4( @@ -142,29 +142,29 @@ std::vector BasicGrid::CreatePositions( return positions; } -std::vector BasicGrid::CreateTextureCoordinates(int xRes, int yRes){ - validate(xRes, yRes); +std::vector BasicGrid::CreateTextureCoordinates(int xSegments, int ySegments){ + validate(xSegments, ySegments); std::vector textureCoordinates; - textureCoordinates.reserve(numVertices(xRes, yRes)); + textureCoordinates.reserve(numVertices(xSegments, ySegments)); - for (unsigned int y = 0; y < yRes + 1; y++) { - for (unsigned int x = 0; x < xRes + 1; x++) { + for (unsigned int y = 0; y < ySegments + 1; y++) { + for (unsigned int x = 0; x < xSegments + 1; x++) { textureCoordinates.push_back(glm::vec2( - static_cast(x) / static_cast(xRes), - static_cast(y) / static_cast(yRes) + static_cast(x) / static_cast(xSegments), + static_cast(y) / static_cast(ySegments) )); } } return textureCoordinates; } -std::vector BasicGrid::CreateNormals(int xRes, int yRes) { - validate(xRes, yRes); +std::vector BasicGrid::CreateNormals(int xSegments, int ySegments) { + validate(xSegments, ySegments); std::vector normals; - normals.reserve(numVertices(xRes, yRes)); + normals.reserve(numVertices(xSegments, ySegments)); - for (unsigned int y = 0; y < yRes + 1; y++) { - for (unsigned int x = 0; x < xRes + 1; x++) { + for (unsigned int y = 0; y < ySegments + 1; y++) { + for (unsigned int x = 0; x < xSegments + 1; x++) { normals.push_back(glm::vec3(0, 0, 1)); } } diff --git a/modules/globebrowsing/rendering/basicgrid.h b/modules/globebrowsing/rendering/basicgrid.h index 27059ea458..a2f1fd76ef 100644 --- a/modules/globebrowsing/rendering/basicgrid.h +++ b/modules/globebrowsing/rendering/basicgrid.h @@ -38,8 +38,8 @@ class BasicGrid : public Grid { public: /** - \param xRes is the number of grid cells in the x direction. - \param yRes is the number of grid cells in the y direction. + \param xSegments is the number of grid cells in the x direction. + \param ySegments is the number of grid cells in the y direction. \param usePositions determines whether or not to upload any vertex position data to the GPU. \param useTextureCoordinates determines whether or not to upload any vertex texture @@ -48,24 +48,16 @@ public: to the GPU. */ BasicGrid( - unsigned int xRes, - unsigned int yRes, + unsigned int xSegments, + unsigned int ySegments, Geometry::Positions usePositions, Geometry::TextureCoordinates useTextureCoordinates, Geometry::Normals useNormals); ~BasicGrid(); - /** - Returns the number of grid cells in the x direction. Hence the number of vertices - in the x direction is xResolution + 1. - */ - virtual int xResolution() const; - - /** - Returns the number of grid cells in the y direction. Hence the number of vertices - in the y direction is xResolution + 1. - */ - virtual int yResolution() const; + + virtual int xSegments() const; + virtual int ySegments() const; private: virtual std::vector CreateElements( int xRes, int yRes); @@ -73,10 +65,10 @@ private: virtual std::vector CreateTextureCoordinates( int xRes, int yRes); virtual std::vector CreateNormals( int xRes, int yRes); - void validate(int xRes, int yRes); + void validate(int xSegments, int ySegments); - inline size_t numElements(int xRes, int yRes); - inline size_t numVertices(int xRes, int yRes); + inline size_t numElements(int xSegments, int ySegments); + inline size_t numVertices(int xSegments, int ySegments); }; } // namespace openspace #endif // __BASICGRIDGEOMETRY_H__ \ No newline at end of file diff --git a/modules/globebrowsing/rendering/clipmapgrid.cpp b/modules/globebrowsing/rendering/clipmapgrid.cpp index 42ecaeed2a..b535c872d8 100644 --- a/modules/globebrowsing/rendering/clipmapgrid.cpp +++ b/modules/globebrowsing/rendering/clipmapgrid.cpp @@ -36,8 +36,8 @@ namespace openspace { // CLIPMAP GRID (Abstract class) // ////////////////////////////////////////////////////////////////////////////////////////// -ClipMapGrid::ClipMapGrid(unsigned int resolution) - : Grid(resolution, resolution, Geometry::Positions::No, Geometry::TextureCoordinates::Yes, Geometry::Normals::No) +ClipMapGrid::ClipMapGrid(unsigned int segments) + : Grid(segments, segments, Geometry::Positions::No, Geometry::TextureCoordinates::Yes, Geometry::Normals::No) { } @@ -47,32 +47,32 @@ ClipMapGrid::~ClipMapGrid() } -int ClipMapGrid::xResolution() const { - return resolution(); +int ClipMapGrid::xSegments() const { + return segments(); } -int ClipMapGrid::yResolution() const { - return resolution(); +int ClipMapGrid::ySegments() const { + return segments(); } -int ClipMapGrid::resolution() const { - return _xRes; +int ClipMapGrid::segments() const { + return _xSegments; } ////////////////////////////////////////////////////////////////////////////////////////// // OUTER CLIPMAP GRID // ////////////////////////////////////////////////////////////////////////////////////////// -OuterClipMapGrid::OuterClipMapGrid(unsigned int resolution) -: ClipMapGrid(resolution) +OuterClipMapGrid::OuterClipMapGrid(unsigned int segments) +: ClipMapGrid(segments) { _geometry = std::unique_ptr(new Geometry( - CreateElements(resolution, resolution), + CreateElements(segments, segments), Geometry::Positions::No, Geometry::TextureCoordinates::Yes, Geometry::Normals::No)); - _geometry->setVertexTextureCoordinates(CreateTextureCoordinates(resolution, resolution)); + _geometry->setVertexTextureCoordinates(CreateTextureCoordinates(segments, segments)); } OuterClipMapGrid::~OuterClipMapGrid() @@ -80,57 +80,57 @@ OuterClipMapGrid::~OuterClipMapGrid() } -size_t OuterClipMapGrid::numElements(int resolution) +size_t OuterClipMapGrid::numElements(int segments) { - int numElementsInTotalSquare = 6 * (resolution + 1) * (resolution + 1); - int numElementsInHole = 6 * (resolution / 4 * resolution / 4); + int numElementsInTotalSquare = 6 * (segments + 1) * (segments + 1); + int numElementsInHole = 6 * (segments / 4 * segments / 4); return numElementsInTotalSquare - numElementsInHole; } -size_t OuterClipMapGrid::numVerticesBottom(int resolution) +size_t OuterClipMapGrid::numVerticesBottom(int segments) { - return (resolution + 1 + 2) * (resolution / 4 + 1 + 1); + return (segments + 1 + 2) * (segments / 4 + 1 + 1); } -size_t OuterClipMapGrid::numVerticesLeft(int resolution) +size_t OuterClipMapGrid::numVerticesLeft(int segments) { - return (resolution / 4 + 1 + 1) * (resolution / 2 + 1); + return (segments / 4 + 1 + 1) * (segments / 2 + 1); } -size_t OuterClipMapGrid::numVerticesRight(int resolution) +size_t OuterClipMapGrid::numVerticesRight(int segments) { - return (resolution / 4 + 1 + 1) * (resolution / 2 + 1); + return (segments / 4 + 1 + 1) * (segments / 2 + 1); } -size_t OuterClipMapGrid::numVerticesTop(int resolution) +size_t OuterClipMapGrid::numVerticesTop(int segments) { - return (resolution + 1 + 2) * (resolution / 4 + 1 + 1); + return (segments + 1 + 2) * (segments / 4 + 1 + 1); } -size_t OuterClipMapGrid::numVertices(int resolution) +size_t OuterClipMapGrid::numVertices(int segments) { - return numVerticesBottom(resolution) + - numVerticesLeft(resolution) + - numVerticesRight(resolution) + - numVerticesTop(resolution); + return numVerticesBottom(segments) + + numVerticesLeft(segments) + + numVerticesRight(segments) + + numVerticesTop(segments); } void OuterClipMapGrid::validate(int xRes, int yRes) { ghoul_assert(xRes == yRes, - "Resolution must be equal in x and in y. "); - int resolution = xRes; - ghoul_assert(resolution >= 8, - "Resolution must be at least 8. (" << resolution << ")"); - ghoul_assert(resolution == pow(2, int(log2(resolution))), - "Resolution must be a power of 2. (" << resolution << ")"); + "segments must be equal in x and in y. "); + int segments = xRes; + ghoul_assert(segments >= 8, + "segments must be at least 8. (" << segments << ")"); + ghoul_assert(segments == pow(2, int(log2(segments))), + "segments must be a power of 2. (" << segments << ")"); } std::vector OuterClipMapGrid::CreateElements(int xRes, int yRes) { validate(xRes, yRes); - int resolution = xRes; + int segments = xRes; std::vector elements; - elements.reserve(numElements(resolution)); + elements.reserve(numElements(segments)); // The clipmap geometry is built up by four parts as follows: // 0 = Bottom part @@ -155,17 +155,17 @@ std::vector OuterClipMapGrid::CreateElements(int xRes, int yRes) { unsigned int previousVerts[4]; previousVerts[0] = 0; - previousVerts[1] = previousVerts[0] + numVerticesBottom(resolution); - previousVerts[2] = previousVerts[1] + numVerticesLeft(resolution); - previousVerts[3] = previousVerts[2] + numVerticesRight(resolution); + previousVerts[1] = previousVerts[0] + numVerticesBottom(segments); + previousVerts[2] = previousVerts[1] + numVerticesLeft(segments); + previousVerts[3] = previousVerts[2] + numVerticesRight(segments); // Build the bottom part of the clipmap geometry - for (unsigned int y = 0; y < resolution / 4 + 1; y++) { - for (unsigned int x = 0; x < resolution + 2; x++) { - GLuint v00 = previousVerts[0] + (y + 0) * (resolution + 3) + x + 0; - GLuint v10 = previousVerts[0] + (y + 0) * (resolution + 3) + x + 1; - GLuint v01 = previousVerts[0] + (y + 1) * (resolution + 3) + x + 0; - GLuint v11 = previousVerts[0] + (y + 1) * (resolution + 3) + x + 1; + for (unsigned int y = 0; y < segments / 4 + 1; y++) { + for (unsigned int x = 0; x < segments + 2; x++) { + GLuint v00 = previousVerts[0] + (y + 0) * (segments + 3) + x + 0; + GLuint v10 = previousVerts[0] + (y + 0) * (segments + 3) + x + 1; + GLuint v01 = previousVerts[0] + (y + 1) * (segments + 3) + x + 0; + GLuint v11 = previousVerts[0] + (y + 1) * (segments + 3) + x + 1; elements.push_back(v00); elements.push_back(v10); @@ -178,12 +178,12 @@ std::vector OuterClipMapGrid::CreateElements(int xRes, int yRes) { } // Build the left part of the clipmap geometry - for (unsigned int y = 0; y < resolution / 2; y++) { - for (unsigned int x = 0; x < resolution / 4 + 1; x++) { - GLuint v00 = previousVerts[1] + (y + 0) * (resolution / 4 + 2) + x + 0; - GLuint v10 = previousVerts[1] + (y + 0) * (resolution / 4 + 2) + x + 1; - GLuint v01 = previousVerts[1] + (y + 1) * (resolution / 4 + 2) + x + 0; - GLuint v11 = previousVerts[1] + (y + 1) * (resolution / 4 + 2) + x + 1; + for (unsigned int y = 0; y < segments / 2; y++) { + for (unsigned int x = 0; x < segments / 4 + 1; x++) { + GLuint v00 = previousVerts[1] + (y + 0) * (segments / 4 + 2) + x + 0; + GLuint v10 = previousVerts[1] + (y + 0) * (segments / 4 + 2) + x + 1; + GLuint v01 = previousVerts[1] + (y + 1) * (segments / 4 + 2) + x + 0; + GLuint v11 = previousVerts[1] + (y + 1) * (segments / 4 + 2) + x + 1; elements.push_back(v00); elements.push_back(v10); @@ -196,12 +196,12 @@ std::vector OuterClipMapGrid::CreateElements(int xRes, int yRes) { } // Build the left part of the clipmap geometry - for (unsigned int y = 0; y < resolution / 2; y++) { - for (unsigned int x = 0; x < resolution / 4 + 1; x++) { - GLuint v00 = previousVerts[2] + (y + 0) * (resolution / 4 + 2) + x + 0; - GLuint v10 = previousVerts[2] + (y + 0) * (resolution / 4 + 2) + x + 1; - GLuint v01 = previousVerts[2] + (y + 1) * (resolution / 4 + 2) + x + 0; - GLuint v11 = previousVerts[2] + (y + 1) * (resolution / 4 + 2) + x + 1; + for (unsigned int y = 0; y < segments / 2; y++) { + for (unsigned int x = 0; x < segments / 4 + 1; x++) { + GLuint v00 = previousVerts[2] + (y + 0) * (segments / 4 + 2) + x + 0; + GLuint v10 = previousVerts[2] + (y + 0) * (segments / 4 + 2) + x + 1; + GLuint v01 = previousVerts[2] + (y + 1) * (segments / 4 + 2) + x + 0; + GLuint v11 = previousVerts[2] + (y + 1) * (segments / 4 + 2) + x + 1; elements.push_back(v00); elements.push_back(v10); @@ -214,12 +214,12 @@ std::vector OuterClipMapGrid::CreateElements(int xRes, int yRes) { } // Build the left part of the clipmap geometry - for (unsigned int y = 0; y < resolution / 4 + 1; y++) { - for (unsigned int x = 0; x < resolution + 2; x++) { - GLuint v00 = previousVerts[3] + (y + 0) * (resolution + 3) + x + 0; - GLuint v10 = previousVerts[3] + (y + 0) * (resolution + 3) + x + 1; - GLuint v01 = previousVerts[3] + (y + 1) * (resolution + 3) + x + 0; - GLuint v11 = previousVerts[3] + (y + 1) * (resolution + 3) + x + 1; + for (unsigned int y = 0; y < segments / 4 + 1; y++) { + for (unsigned int x = 0; x < segments + 2; x++) { + GLuint v00 = previousVerts[3] + (y + 0) * (segments + 3) + x + 0; + GLuint v10 = previousVerts[3] + (y + 0) * (segments + 3) + x + 1; + GLuint v01 = previousVerts[3] + (y + 1) * (segments + 3) + x + 0; + GLuint v11 = previousVerts[3] + (y + 1) * (segments + 3) + x + 1; elements.push_back(v00); elements.push_back(v10); @@ -236,9 +236,9 @@ std::vector OuterClipMapGrid::CreateElements(int xRes, int yRes) { std::vector OuterClipMapGrid::CreatePositions(int xRes, int yRes) { validate(xRes, yRes); - int resolution = xRes; + int segments = xRes; std::vector positions; - positions.reserve(numVertices(resolution)); + positions.reserve(numVertices(segments)); std::vector templateTextureCoords = CreateTextureCoordinates(xRes, yRes); // Copy from 2d texture coordinates and use as template to create positions @@ -257,43 +257,43 @@ std::vector OuterClipMapGrid::CreatePositions(int xRes, int yRes) std::vector OuterClipMapGrid::CreateTextureCoordinates(int xRes, int yRes){ validate(xRes, yRes); - int resolution = xRes; + int segments = xRes; std::vector textureCoordinates; - textureCoordinates.reserve(numVertices(resolution)); + textureCoordinates.reserve(numVertices(segments)); // Build the bottom part of the clipmap geometry - for (int y = -1; y < resolution / 4 + 1; y++) { - for (int x = -1; x < resolution + 2; x++) { + for (int y = -1; y < segments / 4 + 1; y++) { + for (int x = -1; x < segments + 2; x++) { textureCoordinates.push_back(glm::vec2( - static_cast(x) / resolution, - static_cast(y) / resolution)); + static_cast(x) / segments, + static_cast(y) / segments)); } } // Build the left part of the clipmap geometry - for (int y = resolution / 4; y < 3 * resolution / 4 + 1; y++) { - for (int x = -1; x < resolution / 4 + 1; x++) { + for (int y = segments / 4; y < 3 * segments / 4 + 1; y++) { + for (int x = -1; x < segments / 4 + 1; x++) { textureCoordinates.push_back(glm::vec2( - static_cast(x) / resolution, - static_cast(y) / resolution)); + static_cast(x) / segments, + static_cast(y) / segments)); } } // Build the right part of the clipmap geometry - for (int y = resolution / 4; y < 3 * resolution / 4 + 1; y++) { - for (int x = 3 * resolution / 4; x < resolution + 2; x++) { - float u = static_cast(x) / resolution; - float v = static_cast(y) / resolution; + for (int y = segments / 4; y < 3 * segments / 4 + 1; y++) { + for (int x = 3 * segments / 4; x < segments + 2; x++) { + float u = static_cast(x) / segments; + float v = static_cast(y) / segments; textureCoordinates.push_back(glm::vec2(u, v)); } } // Build the top part of the clipmap geometry - for (int y = 3 * resolution / 4; y < resolution + 2; y++) { - for (int x = -1; x < resolution + 2; x++) { + for (int y = 3 * segments / 4; y < segments + 2; y++) { + for (int x = -1; x < segments + 2; x++) { textureCoordinates.push_back(glm::vec2( - static_cast(x) / resolution, - static_cast(y) / resolution)); + static_cast(x) / segments, + static_cast(y) / segments)); } } @@ -302,12 +302,12 @@ std::vector OuterClipMapGrid::CreateTextureCoordinates(int xRes, int std::vector OuterClipMapGrid::CreateNormals(int xRes, int yRes) { validate(xRes, yRes); - int resolution = xRes; + int segments = xRes; std::vector normals; - normals.reserve(numVertices(resolution)); + normals.reserve(numVertices(segments)); - for (int y = -1; y < resolution + 2; y++) { - for (int x = -1; x < resolution + 2; x++) { + for (int y = -1; y < segments + 2; y++) { + for (int x = -1; x < segments + 2; x++) { normals.push_back(glm::vec3(0, 0, 1)); } } @@ -320,16 +320,16 @@ std::vector OuterClipMapGrid::CreateNormals(int xRes, int yRes) { ////////////////////////////////////////////////////////////////////////////////////////// -InnerClipMapGrid::InnerClipMapGrid(unsigned int resolution) - : ClipMapGrid(resolution) +InnerClipMapGrid::InnerClipMapGrid(unsigned int segments) + : ClipMapGrid(segments) { _geometry = std::unique_ptr(new Geometry( - CreateElements(resolution, resolution), + CreateElements(segments, segments), Geometry::Positions::No, Geometry::TextureCoordinates::Yes, Geometry::Normals::No)); - _geometry->setVertexTextureCoordinates(CreateTextureCoordinates(resolution, resolution)); + _geometry->setVertexTextureCoordinates(CreateTextureCoordinates(segments, segments)); } InnerClipMapGrid::~InnerClipMapGrid() @@ -337,30 +337,30 @@ InnerClipMapGrid::~InnerClipMapGrid() } -size_t InnerClipMapGrid::numElements(int resolution) +size_t InnerClipMapGrid::numElements(int segments) { - return resolution * resolution * 6; + return segments * segments * 6; } -size_t InnerClipMapGrid::numVertices(int resolution) +size_t InnerClipMapGrid::numVertices(int segments) { - return (resolution + 1) * (resolution + 1); + return (segments + 1) * (segments + 1); } void InnerClipMapGrid::validate(int xRes, int yRes) { ghoul_assert(xRes == yRes, - "Resolution must be equal in x and in y. "); - int resolution = xRes; - ghoul_assert(resolution >= 1, - "Resolution must be at least 1. (" << resolution << ")"); + "segments must be equal in x and in y. "); + int segments = xRes; + ghoul_assert(segments >= 1, + "segments must be at least 1. (" << segments << ")"); } std::vector InnerClipMapGrid::CreateElements(int xRes, int yRes) { validate(xRes, yRes); - int resolution = xRes; + int segments = xRes; std::vector elements; - elements.reserve(numElements(resolution)); + elements.reserve(numElements(segments)); // x v01---v11 x .. // | / | @@ -369,12 +369,12 @@ std::vector InnerClipMapGrid::CreateElements(int xRes, int yRes) { // x x x x .. // : : : : - for (unsigned int y = 0; y < resolution + 2; y++) { - for (unsigned int x = 0; x < resolution + 2; x++) { - GLuint v00 = (y + 0) * (resolution + 3) + x + 0; - GLuint v10 = (y + 0) * (resolution + 3) + x + 1; - GLuint v01 = (y + 1) * (resolution + 3) + x + 0; - GLuint v11 = (y + 1) * (resolution + 3) + x + 1; + for (unsigned int y = 0; y < segments + 2; y++) { + for (unsigned int x = 0; x < segments + 2; x++) { + GLuint v00 = (y + 0) * (segments + 3) + x + 0; + GLuint v10 = (y + 0) * (segments + 3) + x + 1; + GLuint v01 = (y + 1) * (segments + 3) + x + 0; + GLuint v11 = (y + 1) * (segments + 3) + x + 1; elements.push_back(v00); elements.push_back(v10); @@ -392,9 +392,9 @@ std::vector InnerClipMapGrid::CreateElements(int xRes, int yRes) { std::vector InnerClipMapGrid::CreatePositions(int xRes, int yRes) { validate(xRes, yRes); - int resolution = xRes; + int segments = xRes; std::vector positions; - positions.reserve(numVertices(resolution)); + positions.reserve(numVertices(segments)); std::vector templateTextureCoords = CreateTextureCoordinates(xRes, yRes); // Copy from 2d texture coordinates and use as template to create positions @@ -413,16 +413,16 @@ std::vector InnerClipMapGrid::CreatePositions(int xRes, int yRes) std::vector InnerClipMapGrid::CreateTextureCoordinates(int xRes, int yRes) { validate(xRes, yRes); - int resolution = xRes; + int segments = xRes; std::vector textureCoordinates; - textureCoordinates.reserve(numVertices(resolution)); + textureCoordinates.reserve(numVertices(segments)); // Build the bottom part of the clipmap geometry - for (int y = -1; y < resolution + 2; y++) { - for (int x = -1; x < resolution + 2; x++) { + for (int y = -1; y < segments + 2; y++) { + for (int x = -1; x < segments + 2; x++) { textureCoordinates.push_back(glm::vec2( - static_cast(x) / resolution, - static_cast(y) / resolution)); + static_cast(x) / segments, + static_cast(y) / segments)); } } @@ -431,12 +431,12 @@ std::vector InnerClipMapGrid::CreateTextureCoordinates(int xRes, int std::vector InnerClipMapGrid::CreateNormals(int xRes, int yRes) { validate(xRes, yRes); - int resolution = xRes; + int segments = xRes; std::vector normals; - normals.reserve(numVertices(resolution)); + normals.reserve(numVertices(segments)); - for (int y = -1; y < resolution + 2; y++) { - for (int x = -1; x < resolution + 2; x++) { + for (int y = -1; y < segments + 2; y++) { + for (int x = -1; x < segments + 2; x++) { normals.push_back(glm::vec3(0, 0, 1)); } } diff --git a/modules/globebrowsing/rendering/clipmapgrid.h b/modules/globebrowsing/rendering/clipmapgrid.h index d37d8d9e66..f3e650a2cd 100644 --- a/modules/globebrowsing/rendering/clipmapgrid.h +++ b/modules/globebrowsing/rendering/clipmapgrid.h @@ -48,19 +48,19 @@ snap to the outer layers grid cells. class ClipMapGrid : public Grid { public: - ClipMapGrid(unsigned int resolution); + ClipMapGrid(unsigned int segments); ~ClipMapGrid(); - virtual int xResolution() const; - virtual int yResolution() const; + virtual int xSegments() const; + virtual int ySegments() const; /** - Returns the resolution of the grid. A ClipMapGrid must have the resolution in x and - y direction equal so this function works as a wrapper for xResolution() and - yResolution(). + Returns the segments of the grid. A ClipMapGrid must have the segments in x and + y direction equal so this function works as a wrapper for xSegments() and + ySegments(). */ - int resolution() const; + int segments() const; }; ////////////////////////////////////////////////////////////////////////////////////////// @@ -75,26 +75,26 @@ a smaller ClipMapGrid of half the size can fit. class OuterClipMapGrid : public ClipMapGrid { public: - OuterClipMapGrid(unsigned int resolution); + OuterClipMapGrid(unsigned int segments); ~OuterClipMapGrid(); protected: - virtual std::vector CreateElements(int xRes, int yRes); - virtual std::vector CreatePositions(int xRes, int yRes); - virtual std::vector CreateTextureCoordinates(int xRes, int yRes); - virtual std::vector CreateNormals(int xRes, int yRes); + virtual std::vector CreateElements(int xSegments, int ySegments); + virtual std::vector CreatePositions(int xSegments, int ySegments); + virtual std::vector CreateTextureCoordinates(int xSegments, int ySegments); + virtual std::vector CreateNormals(int xSegments, int ySegments); private: - void validate(int xRes, int yRes); + void validate(int xSegments, int ySegments); - static size_t numVerticesBottom(int resolution); - static size_t numVerticesLeft(int resolution); - static size_t numVerticesRight(int resolution); - static size_t numVerticesTop(int resolution); + static size_t numVerticesBottom(int segments); + static size_t numVerticesLeft(int segments); + static size_t numVerticesRight(int segments); + static size_t numVerticesTop(int segments); - static size_t numElements(int resolution); - static size_t numVertices(int resolution); + static size_t numElements(int segments); + static size_t numVertices(int segments); }; ////////////////////////////////////////////////////////////////////////////////////////// @@ -109,20 +109,20 @@ a whole where a smaller ClipMapGrid can be positioned. class InnerClipMapGrid : public ClipMapGrid { public: - InnerClipMapGrid(unsigned int resolution); + InnerClipMapGrid(unsigned int segments); ~InnerClipMapGrid(); private: - virtual std::vector CreateElements(int xRes, int yRes); - virtual std::vector CreatePositions(int xRes, int yRes); - virtual std::vector CreateTextureCoordinates(int xRes, int yRes); - virtual std::vector CreateNormals(int xRes, int yRes); + virtual std::vector CreateElements( int xSegments, int ySegments); + virtual std::vector CreatePositions(int xSegments, int ySegments); + virtual std::vector CreateTextureCoordinates(int xSegments, int ySegments); + virtual std::vector CreateNormals(int xSegments, int ySegments); - void validate(int xRes, int yRes); + void validate(int xSegments, int ySegments); - static size_t numElements(int resolution); - static size_t numVertices(int resolution); + static size_t numElements(int segments); + static size_t numVertices(int segments); }; } // namespace openspace diff --git a/modules/globebrowsing/rendering/grid.cpp b/modules/globebrowsing/rendering/grid.cpp index fcf82baae7..fa112d4e82 100644 --- a/modules/globebrowsing/rendering/grid.cpp +++ b/modules/globebrowsing/rendering/grid.cpp @@ -31,13 +31,13 @@ namespace { namespace openspace { Grid::Grid( - int xRes, - int yRes, + int xSegments, + int ySegments, Geometry::Positions usePositions, Geometry::TextureCoordinates useTextures, Geometry::Normals useNormals) - : _xRes(xRes) - , _yRes(yRes) + : _xSegments(xSegments) + , _ySegments(ySegments) { } diff --git a/modules/globebrowsing/rendering/grid.h b/modules/globebrowsing/rendering/grid.h index 2942faf9fb..496319b47a 100644 --- a/modules/globebrowsing/rendering/grid.h +++ b/modules/globebrowsing/rendering/grid.h @@ -38,8 +38,8 @@ class Grid { public: Grid( - int xRes, - int yRes, + int xSegments, + int ySegments, Geometry::Positions usePositions = Geometry::Positions::No, Geometry::TextureCoordinates useTextures = Geometry::TextureCoordinates::No, Geometry::Normals useNormals = Geometry::Normals::No); @@ -47,19 +47,28 @@ public: Geometry& geometry(); - virtual int xResolution() const = 0; - virtual int yResolution() const = 0; + /** + Returns the number of grid cells in the x direction. Hence the number of vertices + in the x direction is xResolution + 1. + */ + virtual int xSegments() const = 0; + + /** + Returns the number of grid cells in the y direction. Hence the number of vertices + in the y direction is xResolution + 1. + */ + virtual int ySegments() const = 0; protected: - virtual std::vector CreateElements( int xRes, int yRes) = 0; - virtual std::vector CreatePositions( int xRes, int yRes) = 0; - virtual std::vector CreateTextureCoordinates( int xRes, int yRes) = 0; - virtual std::vector CreateNormals( int xRes, int yRes) = 0; + virtual std::vector CreateElements( int xSegments, int ySegments) = 0; + virtual std::vector CreatePositions( int xSegments, int ySegments) = 0; + virtual std::vector CreateTextureCoordinates( int xSegments, int ySegments) = 0; + virtual std::vector CreateNormals( int xSegments, int ySegments) = 0; std::unique_ptr _geometry; - const int _xRes; - const int _yRes; + const int _xSegments; + const int _ySegments; }; } // namespace openspace #endif // __GRIDGEOMETRY_H__ \ No newline at end of file diff --git a/modules/globebrowsing/rendering/patchrenderer.cpp b/modules/globebrowsing/rendering/patchrenderer.cpp index b33252ffb3..06317110f6 100644 --- a/modules/globebrowsing/rendering/patchrenderer.cpp +++ b/modules/globebrowsing/rendering/patchrenderer.cpp @@ -183,7 +183,7 @@ namespace openspace { mat4 modelTransform = translate(mat4(1), data.position.vec3()); // Snap patch position - int segmentsPerPatch = _grid->resolution(); + int segmentsPerPatch = _grid->segments(); LatLon stepSize = LatLon( patchSize.lat / segmentsPerPatch, patchSize.lon / segmentsPerPatch);