Solve merge conflict

This commit is contained in:
Kalle Bladin
2016-05-02 17:30:59 -04:00
7 changed files with 173 additions and 119 deletions
+15 -1
View File
@@ -91,8 +91,22 @@ using HashKey = unsigned long;
struct GeodeticTileIndex {
const int x, y, level;
int x, y, level;
GeodeticTileIndex() = delete;
GeodeticTileIndex(int x, int y, int level)
: x(x), y(y), level(level) {
}
GeodeticTileIndex(const GeodeticTileIndex& other)
: x(other.x), y(other.y), level(other.level) {
}
HashKey hashKey() const;
+46 -45
View File
@@ -41,59 +41,60 @@
namespace {
const std::string _loggerCat = "ClipMapGlobe";
const std::string _loggerCat = "ClipMapGlobe";
}
namespace openspace {
ClipMapGlobe::ClipMapGlobe(const Ellipsoid& ellipsoid)
: _clipMapPyramid(Geodetic2(M_PI / 2, M_PI / 2))
, _ellipsoid(ellipsoid)
{
// init Renderer
auto outerPatchRenderer = new ClipMapPatchRenderer(shared_ptr<OuterClipMapGrid>(new OuterClipMapGrid(256)));
_outerPatchRenderer.reset(outerPatchRenderer);
auto innerPatchRenderer = new ClipMapPatchRenderer(shared_ptr<InnerClipMapGrid>(new InnerClipMapGrid(256)));
_innerPatchRenderer.reset(innerPatchRenderer);
}
ClipMapGlobe::ClipMapGlobe(const Ellipsoid& ellipsoid)
: _clipMapPyramid(Geodetic2(M_PI / 2, M_PI / 2))
, _ellipsoid(ellipsoid)
{
// init Renderer
auto outerPatchRenderer = new ClipMapPatchRenderer(shared_ptr<OuterClipMapGrid>(new OuterClipMapGrid(256)));
_outerPatchRenderer.reset(outerPatchRenderer);
auto innerPatchRenderer = new ClipMapPatchRenderer(shared_ptr<InnerClipMapGrid>(new InnerClipMapGrid(256)));
_innerPatchRenderer.reset(innerPatchRenderer);
}
ClipMapGlobe::~ClipMapGlobe() {
}
const Ellipsoid& ClipMapGlobe::ellipsoid() const
{
return _ellipsoid;
}
ClipMapGlobe::~ClipMapGlobe() {
}
const Ellipsoid& ClipMapGlobe::ellipsoid() const
{
return _ellipsoid;
}
bool ClipMapGlobe::initialize() {
return isReady();
}
bool ClipMapGlobe::initialize() {
return isReady();
}
bool ClipMapGlobe::deinitialize() {
return true;
}
bool ClipMapGlobe::deinitialize() {
return true;
}
bool ClipMapGlobe::isReady() const {
bool ready = true;
return ready;
}
bool ClipMapGlobe::isReady() const {
bool ready = true;
return ready;
}
void ClipMapGlobe::render(const RenderData& data)
{
// TODO : Choose the max depth and the min depth depending on the camera
int maxDepth = 10;
int minDepth = 0;
// render patches
for (size_t i = minDepth; i < maxDepth; i++)
{
Geodetic2 patchSize = _clipMapPyramid.getPatchSizeAtLevel(i);
_outerPatchRenderer->renderPatch(patchSize, data, _ellipsoid);
}
Geodetic2 patchSize = _clipMapPyramid.getPatchSizeAtLevel(maxDepth);
_innerPatchRenderer->renderPatch(patchSize, data, _ellipsoid);
}
void ClipMapGlobe::render(const RenderData& data)
{
// TODO : Choose the max depth and the min depth depending on the camera
int maxDepth = 5;
int minDepth = 0;
// render patches
for (size_t i = minDepth; i < maxDepth; i++)
{
Geodetic2 patchSize = _clipMapPyramid.getPatchSizeAtLevel(i);
_outerPatchRenderer->renderPatch(patchSize, data, _ellipsoid);
}
Geodetic2 patchSize = _clipMapPyramid.getPatchSizeAtLevel(maxDepth);
_innerPatchRenderer->renderPatch(patchSize, data, _ellipsoid);
}
void ClipMapGlobe::update(const UpdateData& data) {
}
void ClipMapGlobe::update(const UpdateData& data) {
_innerPatchRenderer->update();
_outerPatchRenderer->update();
}
} // namespace openspace
@@ -121,6 +121,7 @@ namespace openspace {
// Using this atomic bool is probably not optimal - Should probably
// use a conditional variable instead
std::atomic<bool> _hasWorkingThread;
std::atomic<int> _numActiveThreads;
};
@@ -69,10 +69,8 @@ namespace openspace {
assert(poDataset != nullptr, "Unable to read dataset" << testFile);
GdalDataConverter conv;
GeodeticTileIndex ti;
ti.x = 0;
ti.y = 0;
ti.level = 0;
GeodeticTileIndex ti(0, 0, 0);
_testTexture = conv.convertToOpenGLTexture(poDataset, ti, GL_UNSIGNED_BYTE);
_testTexture->uploadTexture();
+39 -29
View File
@@ -73,7 +73,13 @@ namespace openspace {
void TileProvider::prerender() {
while (_tileLoadManager.numFinishedJobs() > 0) {
auto finishedJob = _tileLoadManager.popFinishedJob();
std::shared_ptr<UninitializedTextureTile> uninitedTex = finishedJob->product();
HashKey key = uninitedTex->tileIndex.hashKey();
std::shared_ptr<Texture> texture = initializeTexture(uninitedTex);
_tileCache.put(key, texture);
}
}
@@ -84,14 +90,15 @@ namespace openspace {
return _tileCache.get(hashkey);
}
else {
//GeodeticTileIndex ti0 = { 0, 0, 0 };
//auto texture = _converter.convertToOpenGLTexture(_gdalDataSet, tileIndex, GL_UNSIGNED_BYTE);
auto texture = getTileInternal(tileIndex, GL_UNSIGNED_BYTE);
texture->uploadTexture();
texture->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToBorder);
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_tileCache.put(hashkey, texture);
return texture;
// enque load job
std::shared_ptr<TextureTileLoadJob> job = std::shared_ptr<TextureTileLoadJob>(
new TextureTileLoadJob(this, tileIndex));
_tileLoadManager.enqueueJob(job);
// map key to nullptr while tile is loaded
_tileCache.put(hashkey, nullptr);
return nullptr;
}
}
@@ -99,10 +106,7 @@ namespace openspace {
std::shared_ptr<Texture> TileProvider::getTileInternal(const GeodeticTileIndex& tileIndex, int GLType) {
std::shared_ptr<UninitializedTextureTile> TileProvider::getUninitializedTextureTile(const GeodeticTileIndex& tileIndex) {
int nRasters = _gdalDataSet->GetRasterCount();
ghoul_assert(nRasters > 0, "Bad dataset. Contains no rasterband.");
@@ -120,24 +124,21 @@ namespace openspace {
glm::uvec2 pixelStart0 = _converter.geodeticToPixel(_gdalDataSet, patch.northWestCorner());
glm::uvec2 pixelEnd0 = _converter.geodeticToPixel(_gdalDataSet, patch.southEastCorner());
glm::uvec2 numberOfPixels0 = pixelEnd0 - pixelStart0;
int minNumPixels0 = glm::min(numberOfPixels0.x, numberOfPixels0.y);
int minNumPixelsRequired = 256;
int ov = log2(minNumPixels0) - log2(minNumPixelsRequired);
ov = glm::clamp(ov, 0, numOverviews-1);
ov = glm::clamp(ov, 0, numOverviews - 1);
glm::uvec2 pixelStart(pixelStart0.x >> (ov+1), pixelStart0.y >> (ov + 1));
glm::uvec2 pixelStart(pixelStart0.x >> (ov + 1), pixelStart0.y >> (ov + 1));
glm::uvec2 numberOfPixels(numberOfPixels0.x >> (ov + 1), numberOfPixels0.y >> (ov + 1));
// For testing
/*pixelStart = glm::uvec2(0, 0);
numberOfPixels = glm::uvec2(512, 256);
ov = 15;
*/
// The data that the texture should read
// GDAL reads image data top to bottom
GLubyte* imageData = new GLubyte[numberOfPixels.x * numberOfPixels.y * nRasters];
// Read the data (each rasterband is a separate channel)
@@ -168,15 +169,22 @@ namespace openspace {
}
}
delete[] imageData;
glm::uvec3 dims(numberOfPixels.x, numberOfPixels.y, 1);
GdalDataConverter::TextureFormat textrureFormat = _converter.getTextureFormatFromRasterCount(nRasters);
UninitializedTextureTile* uninitedTexPtr = new UninitializedTextureTile(imageDataYflipped, dims, textrureFormat, tileIndex);
std::shared_ptr<UninitializedTextureTile> uninitedTex = std::shared_ptr<UninitializedTextureTile>(uninitedTexPtr);
return uninitedTex;
}
std::shared_ptr<Texture> TileProvider::initializeTexture(std::shared_ptr<UninitializedTextureTile> uninitedTexture) {
Texture* tex = new Texture(
static_cast<void*>(imageDataYflipped),
glm::uvec3(numberOfPixels.x, numberOfPixels.y, 1),
textrureFormat.ghoulFormat,
textrureFormat.glFormat,
static_cast<void*>(uninitedTexture->imageData),
uninitedTexture->dimensions,
uninitedTexture->texFormat.ghoulFormat,
uninitedTexture->texFormat.glFormat,
GL_UNSIGNED_BYTE,
Texture::FilterMode::Linear,
Texture::WrappingMode::Repeat);
@@ -184,11 +192,13 @@ namespace openspace {
// The texture should take ownership of the data
std::shared_ptr<Texture> texture = std::shared_ptr<Texture>(tex);
delete[] imageData;
texture->uploadTexture();
texture->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToBorder);
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
// Do not free imageData since the texture now has ownership of it
return texture;
}
} // namespace openspace
+51 -36
View File
@@ -40,53 +40,36 @@
#include <modules/globebrowsing/other/gdaldataconverter.h>
/*
namespace openspace {
using namespace ghoul::opengl;
struct TextureLoadJob : public Job<Texture> {
TextureLoadJob(const std::string& filePath, HashKey hashkey)
: _filePath(filePath)
, _hashkey(hashkey){
struct UninitializedTextureTile {
UninitializedTextureTile(GLubyte* data, glm::uvec3 dims,
GdalDataConverter::TextureFormat format, const GeodeticTileIndex& ti)
: imageData(data)
, dimensions(dims)
, texFormat(format)
, tileIndex(ti){
}
virtual ~TextureLoadJob() { }
virtual void execute() {
auto textureReader = ghoul::io::TextureReader::ref();
_texture = std::move(textureReader.loadTexture(absPath(_filePath)));
}
virtual std::shared_ptr<Texture> product() {
return _texture;
}
HashKey hashKey() { return _hashkey; }
private:
std::string _filePath;
HashKey _hashkey;
std::shared_ptr<Texture> _texture;
GLubyte * imageData;
glm::uvec3 dimensions;
GdalDataConverter::TextureFormat texFormat;
const GeodeticTileIndex tileIndex;
};
}
*/
//////////////////////////////////////////////////////////////////////////////////////////
// TILE PROVIDER //
//////////////////////////////////////////////////////////////////////////////////////////
namespace openspace {
using namespace ghoul::opengl;
class TileProvider {
@@ -101,7 +84,10 @@ namespace openspace {
private:
std::shared_ptr<Texture> getTileInternal(const GeodeticTileIndex& tileIndex, int GLType);
friend class TextureTileLoadJob;
std::shared_ptr<UninitializedTextureTile> getUninitializedTextureTile(const GeodeticTileIndex& tileIndex);
std::shared_ptr<Texture> initializeTexture(std::shared_ptr<UninitializedTextureTile> uninitedTexture);
LRUCache<HashKey, std::shared_ptr<Texture>> _tileCache;
@@ -113,10 +99,39 @@ namespace openspace {
GDALDataset* _gdalDataSet;
GdalDataConverter _converter;
ConcurrentJobManager<UninitializedTextureTile> _tileLoadManager;
};
} // namespace openspace
namespace openspace {
using namespace ghoul::opengl;
struct TextureTileLoadJob : public Job<UninitializedTextureTile> {
TextureTileLoadJob(TileProvider * tileProvider, const GeodeticTileIndex& tileIndex)
: _tileProvider(tileProvider)
, _tileIndex(tileIndex) {
}
virtual ~TextureTileLoadJob() { }
virtual void execute() {
_uninitedTexture = _tileProvider->getUninitializedTextureTile(_tileIndex);
}
virtual std::shared_ptr<UninitializedTextureTile> product() {
return _uninitedTexture;
}
private:
GeodeticTileIndex _tileIndex;
TileProvider * _tileProvider;
std::shared_ptr<UninitializedTextureTile> _uninitedTexture;
};
}
#endif // __TILE_PROVIDER_H__
@@ -189,7 +189,7 @@ namespace openspace {
}
void ClipMapPatchRenderer::update() {
_tileProvider.prerender();
}
@@ -236,14 +236,27 @@ namespace openspace {
// Get the textures that should be used for rendering
GeodeticTileIndex tileIndex00 = _patchCoverageProvider.getTileIndex(newPatch);
GeodeticTileIndex tileIndex10 = tileIndex00; tileIndex10.x += 1;
GeodeticTileIndex tileIndex01 = tileIndex00; tileIndex01.y += 1;
GeodeticTileIndex tileIndex11 = tileIndex00; tileIndex11.x += 1; tileIndex11.y += 1;
GeodeticTileIndex tileIndex10 = { tileIndex00.x + 1, tileIndex00.y, tileIndex00.level };
GeodeticTileIndex tileIndex01 = { tileIndex00.x, tileIndex00.y + 1, tileIndex00.level };
GeodeticTileIndex tileIndex11 = { tileIndex00.x + 1, tileIndex00.y + 1, tileIndex00.level };
std::shared_ptr<ghoul::opengl::Texture> tile00 = _tileProvider.getTile(tileIndex00);
std::shared_ptr<ghoul::opengl::Texture> tile10 = _tileProvider.getTile(tileIndex10);
std::shared_ptr<ghoul::opengl::Texture> tile01 = _tileProvider.getTile(tileIndex01);
std::shared_ptr<ghoul::opengl::Texture> tile11 = _tileProvider.getTile(tileIndex11);
if (tile00 == nullptr) {
tile00 = _tileSet.getTile(tileIndex00);
}
if (tile10 == nullptr) {
tile10 = _tileSet.getTile(tileIndex01);
}
if (tile01 == nullptr) {
tile01 = _tileSet.getTile(tileIndex10);
}
if (tile11 == nullptr) {
tile11 = _tileSet.getTile(tileIndex11);
}
glm::mat3 uvTransform00 = _patchCoverageProvider.getUvTransformationPatchToTile(newPatch, tileIndex00);
glm::mat3 uvTransform10 = _patchCoverageProvider.getUvTransformationPatchToTile(newPatch, tileIndex10);
@@ -252,6 +265,8 @@ namespace openspace {
//std::shared_ptr<ghoul::opengl::Texture> tile00 = _tileSet.getTile(tileIndex);
// Bind and use the texture
ghoul::opengl::TextureUnit texUnit00;
texUnit00.activate();