kore::ResourceManager::~ResourceManager(void) { // Delete all shaders. for (auto it = _shaders.begin(); it != _shaders.end(); ++it) { delete it->second; } _shaders.clear(); // Delete textures. for (auto itPath = _textures.begin(); itPath != _textures.end(); ++itPath) { delete itPath->second; } _textures.clear(); // Delete shaderPrograms. for (auto it2 = _shaderPrograms.begin(); it2 != _shaderPrograms.end(); ++it2) { delete it2->second; } _shaderPrograms.clear(); // Delete all texture samplers. for (uint i = 0; i < _textureSamplers.size(); ++i) { KORE_SAFE_DELETE(_textureSamplers[i]); } _textureSamplers.clear(); // Delete all mesh resources and entries. for (auto it = _meshes.begin(); it != _meshes.end(); ++it) { Mesh* mesh = it->second; delete mesh; } _meshes.clear(); // Delete Framebuffers. for (auto it = _frameBuffers.begin(); it != _frameBuffers.end(); ++it) { delete it->second; } _frameBuffers.clear(); // Delete Texture samplers for (uint i = 0; i < _textureSamplers.size(); ++i) { KORE_SAFE_DELETE(_textureSamplers[i]); } _textureSamplers.clear(); // Delete Materials for(auto it = _materials.begin(); it != _materials.end(); ++it) { delete it->second; } // Delete IndexedBuffers for (auto it = _indexedBuffers.begin(); it != _indexedBuffers.end(); ++it) { delete it->second; } }
void kore::MeshComponent::destroyAttributes() { for (uint i = 0; i < _shaderData.size(); ++i) { KORE_SAFE_DELETE(_shaderData[i].data); } _shaderData.clear(); }
kore::ShaderProgramPass::~ShaderProgramPass(void) { for (uint i = 0; i < _startupOperations.size(); ++i) { KORE_SAFE_DELETE(_startupOperations[i]); } for (uint i = 0; i < _internalStartup.size(); ++i) { KORE_SAFE_DELETE(_internalStartup[i]); } for (uint i = 0; i < _finishOperations.size(); ++i) { KORE_SAFE_DELETE(_finishOperations[i]); } for (uint i = 0; i < _internalFinish.size(); ++i) { KORE_SAFE_DELETE(_internalFinish[i]); } for (uint i = 0; i < _nodePasses.size(); ++i) { KORE_SAFE_DELETE(_nodePasses[i]); } }
void kore::ResourceManager:: removeFramebuffer(FrameBuffer* fbo) { for (auto it = _frameBuffers.begin(); it != _frameBuffers.end(); ++it) { if (it->second == fbo) { KORE_SAFE_DELETE(it->second); _frameBuffers.erase(it); } } }
kore::Texture* kore::TextureLoader::loadTexture(const std::string& filepath) { std::vector<unsigned char> imageData; std::vector<unsigned char> buffer; lodepng::load_file(buffer, filepath); uint width, height; lodepng::State pngState; pngState.decoder.color_convert = false; uint err = lodepng::decode(imageData, width, height, pngState, buffer); if ( err != 0) { kore::Log::getInstance()->write("[ERROR] Failed to load texture '%s' :\n" "\t%s\n", filepath.c_str(), lodepng_error_text(err)); return NULL; } else { kore::Texture* tex = new Texture(); LodePNGColorMode& color = pngState.info_raw; STextureProperties texProperties; texProperties.targetType = GL_TEXTURE_2D; texProperties.border = 0; texProperties.width = width; texProperties.height = height; //Pass the actual Texture Data if(color.colortype == LCT_RGB) { texProperties.internalFormat = GL_RGB8; texProperties.format = GL_RGB; texProperties.pixelType = GL_UNSIGNED_BYTE; } else if(color.colortype == LCT_RGBA) { texProperties.internalFormat = GL_SRGB8_ALPHA8; texProperties.format = GL_RGBA; texProperties.pixelType = GL_UNSIGNED_BYTE; } if (tex->create(texProperties, filepath, &imageData[0])) { ResourceManager::getInstance()->addTexture(tex); kore::Log::getInstance() ->write("[DEBUG] Texture '%s' successfully loaded\n", filepath.c_str()); tex->genMipmapHierarchy(); return tex; } else { kore::Log::getInstance() ->write("[ERROR] Texture '%s' could not be loaded\n", filepath.c_str()); KORE_SAFE_DELETE(tex); return NULL; } } }
void kore::ResourceManager::removeShaderProgram(const uint64 id) { auto it = _shaderPrograms.find(id); if (it != _shaderPrograms.end()) { _shaderProgramDeleteEvent.raiseEvent(it->second); KORE_SAFE_DELETE(it->second); _shaderPrograms.erase(it); return; } }
void kore::ResourceManager::removeTexture(const uint64 id) { auto it = _textures.find(id); if (it != _textures.end()) { _textureDeleteEvent.raiseEvent(it->second); KORE_SAFE_DELETE(it->second); _textures.erase(it); return; } }
void kore::ShaderProgramPass::setShaderProgram(ShaderProgram* program) { if (_program == program) return; if (_program != NULL) { for (uint i = 0; i < _internalStartup.size(); ++i) { KORE_SAFE_DELETE(_internalStartup[i]); } _internalStartup.clear(); _internalFinish.clear(); } _program = program; UseShaderProgram* pUseProgram = new UseShaderProgram; pUseProgram->connect(program); if (_useGPUProfiling) { _internalStartup.push_back( new FunctionOp(std::bind(&kore::ShaderProgramPass::startQuery, this))); _internalFinish.push_back( new FunctionOp(std::bind(&kore::ShaderProgramPass::endQuery, this))); } _internalStartup.push_back(pUseProgram); }
kore::Texture* kore::TextureLoader::loadTexture(const std::string& filepath) { std::vector<unsigned char> imageData; std::vector<unsigned char> buffer; std::string loadFilePath = filepath; lodepng::load_file(buffer, loadFilePath); if (buffer.size() == 0) { // Texture does not exist in the provided path -> try once again in the textures-folder loadFilePath = "assets/textures/" + filepath; lodepng::load_file(buffer, loadFilePath); } uint width, height; lodepng::State pngState; pngState.decoder.color_convert = false; uint err = lodepng::decode(imageData, width, height, pngState, buffer); if ( err != 0) { kore::Log::getInstance()->write("[ERROR] Failed to load texture '%s' :\n" "\t%s\n", loadFilePath.c_str(), lodepng_error_text(err)); return NULL; } else { kore::Texture* tex = new Texture(); LodePNGColorMode& color = pngState.info_raw; STextureProperties texProperties; texProperties.targetType = GL_TEXTURE_2D; texProperties.border = 0; texProperties.width = width; texProperties.height = height; //Pass the actual Texture Data if(color.colortype == LCT_RGB) { texProperties.internalFormat = GL_RGB8; texProperties.format = GL_RGB; texProperties.pixelType = GL_UNSIGNED_BYTE; } else if(color.colortype == LCT_RGBA) { texProperties.internalFormat = GL_RGBA8; texProperties.format = GL_RGBA; texProperties.pixelType = GL_UNSIGNED_BYTE; } std::string name = filepath.substr(filepath.find_last_of('/')+1); if (tex->init(texProperties, name, TEXSEMANTICS_UNKNOWN, &imageData[0])) { ResourceManager::getInstance()->addTexture(tex); std::string url = IDManager::getInstance()->genURL("", filepath, 0); IDManager::getInstance()->registerURL(tex->getID(), url); kore::Log::getInstance() ->write("[DEBUG] Texture '%s' successfully loaded.\n", filepath.c_str()); tex->genMipmapHierarchy(); return tex; } else { kore::Log::getInstance() ->write("[ERROR] Texture '%s' could not be loaded.\n", filepath.c_str()); KORE_SAFE_DELETE(tex); return NULL; } } }
kore::TexturesComponent::~TexturesComponent(void) { for (uint i = 0; i < _vTextureInfos.size(); ++i) { KORE_SAFE_DELETE(_vTextureInfos[i]); } }
kore::NodePass::~NodePass(void) { for (uint i = 0; i < _operations.size(); ++i) { KORE_SAFE_DELETE(_operations[i]); } }