void myDataTransferDecoder(void * receivedData, int receivedlength, int packageId, int clientIndex) { sgct::MessageHandler::instance()->print("Decoding %d bytes in transfer id: %d on node %d\n", receivedlength, packageId, clientIndex); currentPackage.setVal(packageId); //read the image on master readImage( reinterpret_cast<unsigned char*>(receivedData), receivedlength); uploadTexture(); }
Texture TextureLoader::getEmptyTexture(const std::string &name, const char *pixel) { auto it = textureCache.find(name); if (it != textureCache.end()) { return it->second; } Texture texture = uploadTexture((const unsigned char*)pixel, 1, 1); texture.width = 1; texture.height = 1; textureCache.insert(std::pair<std::string, Texture>(name, texture)); return texture; }
Texture TextureLoader::getTexture(std::string path) { auto it = textureCache.find(path); if (it != textureCache.end()) { return it->second; } int width, height, bytes; unsigned char *data = stbi_load((Environment::getDataDir() + "/textures/" + path).c_str(), &width, &height, &bytes, 0); Texture texture = uploadTexture(data, width, height, bytes); texture.width = width; texture.height = height; textureCache.insert(std::pair<std::string, Texture>(path, texture)); return texture; }
bool Texture::loadTexture(sf::Image* img, const std::string& name) { if (img != 0) { mName = name; if (img->getSize().x % 2 != 0 || img->getSize().y % 2 != 0) { dwarn << "Warning: image size is not a multiple of 2, texture " << name << " might cause troubles!" << std::endl; } glGenTextures(1, &mTextureId); //we need to create an unique ID for the texture // Store texture in VRAM or RAM (opengl handles it behind the scene). // There is no need to keep track of the image after that, opengl handles the data itself. uploadTexture(img); return true; } else { derr << "Unable to load texture " << name << std::endl; return false; } }
Texture TextureLoader::getTexture(const std::string &path) { auto it = textureCache.find(path); if (it != textureCache.end()) { return it->second; } int width = 0, height = 0; FIBITMAP *bitmap = FreeImage_Load(FreeImage_GetFileType((Environment::getDataDir() + "/textures/" + path).c_str()), (Environment::getDataDir() + "/textures/" + path).c_str()); FIBITMAP *image = FreeImage_ConvertTo32Bits(bitmap); FreeImage_FlipVertical(image); width = FreeImage_GetWidth(image); height = FreeImage_GetHeight(image); Texture texture = uploadTexture(FreeImage_GetBits(image), width, height); texture.width = width; texture.height = height; textureCache.insert(std::pair<std::string, Texture>(path, texture)); FreeImage_Unload(image); FreeImage_Unload(bitmap); return texture; }
//! constructor for usual textures COpenGLTexture::COpenGLTexture(ISGPImage* origImage, const String& name, COpenGLRenderDevice* renderdevice, bool bHasMipmaps) : ISGPTexture(name), m_ColorFormat(SGPPF_A8R8G8B8), RenderDevice(renderdevice), m_Image(0), /*m_MipImage(0),*/ OpenGLTextureID(0), InternalFormat(GL_RGBA), PixelFormat(GL_BGRA_EXT), PixelType(GL_UNSIGNED_BYTE), HasMipMaps(bHasMipmaps), MipMapLevels(0), IsRenderTarget(false), /*ReadOnlyLock(false),*/ TextureTarget(GL_TEXTURE_2D), TextureMagFilter(TEXTURE_FILTER_MAG_BILINEAR), TextureMinFilter(TEXTURE_FILTER_MIN_BILINEAR), TextureBorderColor(0,0,0,0.0f), TextureAnisotropicFilter(1), TextureLODBias(0.0f), TextureMaxMipLevel(1000) { TextureWrap[0] = TEXTURE_ADDRESS_REPEAT; TextureWrap[1] = TEXTURE_ADDRESS_REPEAT; TextureWrap[2] = TEXTURE_ADDRESS_REPEAT; if( origImage->IsDDSImage() ) { updateDDSTexture(origImage); return; } getImageValues(origImage); glGenTextures(1, &OpenGLTextureID); if( (ImageSize.Width == TextureSize.Width) && (ImageSize.Height == TextureSize.Height) ) { m_Image = RenderDevice->GetTextureManager()->createImage(m_ColorFormat, ImageSize); origImage->copyTo(m_Image, SDimension2D(0,0)); } else { m_Image = RenderDevice->GetTextureManager()->createImage(m_ColorFormat, TextureSize); // scale texture origImage->copyToScaling(m_Image); } uploadTexture(); }
//! Constructor for usual textures COpenGLTexture::COpenGLTexture(IImage* origImage, const core::stringc& name, void* mipmapData, IVideoDriver* driver) : ITexture(name), Image(0), MipImage(0), TextureName(0), InternalFormat( GL_RGBA), PixelFormat(GL_BGRA_EXT), PixelType( GL_UNSIGNED_BYTE), HasMipMaps(false), ColorFormat( ECF_R8G8B8), Driver(driver), IsRenderTarget(false) //FIXME //AutomaticMipmapUpdate(false), //ReadOnlyLock(false), //KeepImage(true) { //TODO: refactor it //HasMipMaps = Driver->getTextureCreationFlag(ETCF_CREATE_MIP_MAPS); getImageValues(origImage); glGenTextures(1, &TextureName); if (ImageSize == TextureSize) { Image = createEmptyImage(ColorFormat, ImageSize); origImage->copyTo(Image); } else { Image = createEmptyImage(ColorFormat, TextureSize); // scale texture origImage->copyToScaling(Image); } uploadTexture(true, mipmapData); //FIXME // if (!KeepImage) // { // Image->drop(); // Image = 0; // } }
void threadWorker(void *arg) { while (running.getVal()) { //runs only on master if (transfer.getVal() && !serverUploadDone.getVal() && !clientsUploadDone.getVal()) { startDataTransfer(); transfer.setVal(false); //load texture on master uploadTexture(); serverUploadDone = true; if(sgct_core::ClusterManager::instance()->getNumberOfNodes() == 1) //no cluster { clientsUploadDone = true; } } sgct::Engine::sleep(0.1); //ten iteration per second } }