gpu errors

This commit is contained in:
2026-05-02 21:56:33 +02:00
parent fcc598adb1
commit c46443e2f4
6 changed files with 103 additions and 4 deletions

View File

@@ -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;
}