From 3fc25492f2727b4c446a42c3c9ef8e7090350aca Mon Sep 17 00:00:00 2001 From: Sebastian Piwell Date: Mon, 25 Apr 2016 11:26:15 -0400 Subject: [PATCH] Read texture from memory with bare pointer --- ext/ghoul | 2 +- modules/iswa/rendering/iswacygnet.cpp | 10 +++++----- modules/iswa/rendering/iswacygnet.h | 1 - modules/iswa/rendering/screenspacecygnet.cpp | 18 +++++++++++++++++- modules/iswa/rendering/screenspacecygnet.h | 4 +++- modules/iswa/rendering/textureplane.cpp | 20 +++++++++++++++++++- modules/iswa/rendering/textureplane.h | 2 ++ src/rendering/renderable.cpp | 2 +- 8 files changed, 48 insertions(+), 11 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index ef1063b4af..f6fcc8c142 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit ef1063b4afb99826e7c254b2e7f9ed79f5bd600c +Subproject commit f6fcc8c142f24c63b4eb5987e88ef37c6ef2ff51 diff --git a/modules/iswa/rendering/iswacygnet.cpp b/modules/iswa/rendering/iswacygnet.cpp index 1102365a4f..366108a6b5 100644 --- a/modules/iswa/rendering/iswacygnet.cpp +++ b/modules/iswa/rendering/iswacygnet.cpp @@ -79,14 +79,14 @@ ISWACygnet::ISWACygnet(const ghoul::Dictionary& dictionary) addProperty(_delete); // std::cout << _data->id << std::endl; - std::cout << std::to_string(_data->offset) << std::endl; - std::cout << std::to_string(_data->scale) << std::endl; + // std::cout << std::to_string(_data->offset) << std::endl; + // std::cout << std::to_string(_data->scale) << std::endl; // std::cout << std::to_string(_data->max) << std::endl; // std::cout << std::to_string(_data->min) << std::endl; - std::cout << std::to_string(_data->spatialScale) << std::endl; + // std::cout << std::to_string(_data->spatialScale) << std::endl; // std::cout << _data->path << std::endl; - std::cout << _data->parent << std::endl; - std::cout << _data->frame << std::endl; + // std::cout << _data->parent << std::endl; + // std::cout << _data->frame << std::endl; _delete.onChange([this](){ISWAManager::ref().deleteISWACygnet(name());}); } diff --git a/modules/iswa/rendering/iswacygnet.h b/modules/iswa/rendering/iswacygnet.h index 8ff0b8563f..3b36d7c5bc 100644 --- a/modules/iswa/rendering/iswacygnet.h +++ b/modules/iswa/rendering/iswacygnet.h @@ -60,7 +60,6 @@ struct Metadata { glm::vec3 scale; glm::vec4 spatialScale; std::string scaleVariable; - std::shared_ptr kw; }; diff --git a/modules/iswa/rendering/screenspacecygnet.cpp b/modules/iswa/rendering/screenspacecygnet.cpp index e01d7dbef4..0898f113c8 100644 --- a/modules/iswa/rendering/screenspacecygnet.cpp +++ b/modules/iswa/rendering/screenspacecygnet.cpp @@ -122,6 +122,7 @@ void ScreenSpaceCygnet::update(){ if(_futureTexture && _futureTexture->isFinished){ loadTexture(); + _futureTexture = nullptr; } } @@ -149,7 +150,10 @@ void ScreenSpaceCygnet::loadTexture() { if(_memorybuffer != ""){ - std::unique_ptr texture = ghoul::io::TextureReader::ref().loadTextureFromMemory(_memorybuffer); + std::unique_ptr texture = ghoul::io::TextureReader::ref().loadTexture( + (void*) _memorybuffer.c_str(), + _memorybuffer.size(), + imageFormat(_futureTexture->format)); // std::unique_ptr texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_path)); if (texture) { @@ -164,6 +168,18 @@ void ScreenSpaceCygnet::loadTexture() { } } +std::string ScreenSpaceCygnet::imageFormat(std::string format){ + if(format == "image/png"){ + return std::string("png"); + }else if(format == "image/jpeg"){ + return std::string("jpg"); + }else if(format == "image/gif"){ + return std::string("gif"); + }else{ + return std::string("noImage"); + } +} + int ScreenSpaceCygnet::id(){ static int id = 0; return id++; diff --git a/modules/iswa/rendering/screenspacecygnet.h b/modules/iswa/rendering/screenspacecygnet.h index 23a4f07235..48c3e9bb06 100644 --- a/modules/iswa/rendering/screenspacecygnet.h +++ b/modules/iswa/rendering/screenspacecygnet.h @@ -47,6 +47,8 @@ private: void updateTexture(); void loadTexture(); + std::string imageFormat(std::string format); + properties::FloatProperty _updateInterval; std::string _path; @@ -56,7 +58,7 @@ private: std::shared_ptr _futureTexture; std::string _memorybuffer; - + int _id; }; diff --git a/modules/iswa/rendering/textureplane.cpp b/modules/iswa/rendering/textureplane.cpp index b9a8fa1353..4bb0a19212 100644 --- a/modules/iswa/rendering/textureplane.cpp +++ b/modules/iswa/rendering/textureplane.cpp @@ -77,7 +77,11 @@ bool TexturePlane::deinitialize(){ bool TexturePlane::loadTexture() { if(_memorybuffer != ""){ - std::unique_ptr texture = ghoul::io::TextureReader::ref().loadTextureFromMemory(_memorybuffer); + std::unique_ptr texture = ghoul::io::TextureReader::ref().loadTexture( + (void*) _memorybuffer.c_str(), + _memorybuffer.size(), + imageFormat(_futureObject->format)); + if (texture) { texture->uploadTexture(); // Textures of planets looks much smoother with AnisotropicMipMap rather than linear @@ -92,6 +96,8 @@ bool TexturePlane::loadTexture() { return false; } + + bool TexturePlane::updateTexture(){ if(_futureObject) return false; @@ -108,6 +114,18 @@ bool TexturePlane::updateTexture(){ return false; } +std::string TexturePlane::imageFormat(std::string format){ + if(format == "image/png"){ + return std::string("png"); + }else if(format == "image/jpeg"){ + return std::string("jpg"); + }else if(format == "image/gif"){ + return std::string("gif"); + }else{ + return std::string("noImage"); + } +} + int TexturePlane::id(){ static int id = 0; return id++; diff --git a/modules/iswa/rendering/textureplane.h b/modules/iswa/rendering/textureplane.h index 51c26b9b25..83e81f6826 100644 --- a/modules/iswa/rendering/textureplane.h +++ b/modules/iswa/rendering/textureplane.h @@ -46,6 +46,8 @@ virtual bool loadTexture() override; virtual bool updateTexture() override; + std::string imageFormat(std::string format); + static int id(); }; diff --git a/src/rendering/renderable.cpp b/src/rendering/renderable.cpp index f2288defa2..0f7f167c2a 100644 --- a/src/rendering/renderable.cpp +++ b/src/rendering/renderable.cpp @@ -53,7 +53,7 @@ Renderable* Renderable::createFromDictionary(const ghoul::Dictionary& dictionary std::string renderableType; success = dictionary.getValue(KeyType, renderableType); - std::cout << renderableType << std::endl; + if (!success) { LERROR("Renderable '" << name << "' did not have key '" << KeyType << "'"); return nullptr;