gpu errors
This commit is contained in:
@@ -7,6 +7,9 @@ namespace Game::Renderer {
|
||||
|
||||
Texture::Texture(const std::string& path, SDL_Renderer* renderer, std::string id)
|
||||
: mTex(nullptr), mId(id) {
|
||||
mPath = path;
|
||||
mIsFromFile = true;
|
||||
|
||||
SDL_Surface* surf = IMG_Load(path.c_str());
|
||||
if (!surf) {
|
||||
ERROR("Failed to load image at " << path);
|
||||
@@ -44,6 +47,34 @@ namespace Game::Renderer {
|
||||
LOG("Tekstura '" << mId << "' uničena")
|
||||
}
|
||||
|
||||
bool Texture::reload(SDL_Renderer* renderer) {
|
||||
if (!mIsFromFile || mPath.empty()) return false;
|
||||
if (mTex) {
|
||||
SDL_DestroyTexture(mTex);
|
||||
mTex = nullptr;
|
||||
}
|
||||
|
||||
SDL_Surface* surf = IMG_Load(mPath.c_str());
|
||||
if (!surf) {
|
||||
ERROR("Failed to reload image at " << mPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
mTex = SDL_CreateTextureFromSurface(renderer, surf);
|
||||
SDL_DestroySurface(surf);
|
||||
if (!mTex) {
|
||||
ERROR("Failed to create texture from surface when reloading " << mPath << ": " << SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Restore scale mode
|
||||
if (!SDL_SetTextureScaleMode(mTex, SDL_SCALEMODE_NEAREST)) {
|
||||
WARN("Failed to set texture scale mode to NEAREST for '" << mId << "' during reload: " << SDL_GetError());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
SDL_Texture* Texture::getSDLTexture() {
|
||||
return mTex;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user