Audio Abstrakcija - WIP

This commit is contained in:
2026-03-13 14:28:08 +01:00
parent 8ae713ba8a
commit 52df67da09
13 changed files with 324 additions and 43 deletions

View File

@@ -1,42 +1,58 @@
#include <renderer/texture.hpp>
#include <utility>
Game::Renderer::Texture::Texture(std::string id)
: mTex(nullptr), mId(std::move(id)) {}
namespace Game::Renderer {
Texture::Texture(std::string id)
: mTex(nullptr), mId(std::move(id)) {}
Game::Renderer::Texture::Texture(const std::string& path, SDL_Renderer* renderer, std::string id)
: mTex(nullptr), mId(id) {
SDL_Surface* surf = IMG_Load(path.c_str());
if (!surf) {
ERROR("Failed to load image at " << path);
return;
Texture::Texture(const std::string& path, SDL_Renderer* renderer, std::string id)
: mTex(nullptr), mId(id) {
SDL_Surface* surf = IMG_Load(path.c_str());
if (!surf) {
ERROR("Failed to load image at " << path);
return;
}
mTex = SDL_CreateTextureFromSurface(renderer, surf);
SDL_DestroySurface(surf);
}
mTex = SDL_CreateTextureFromSurface(renderer, surf);
SDL_DestroySurface(surf);
}
Texture::Texture(const Texture& other) {
// Copy the references, since copying memory would require re-initing a bunch of things - for now
this->mTex = other.mTex;
}
Game::Renderer::Texture::Texture(const Texture& other) {
// Copy the references, since copying memory would require re-initing a bunch of things - for now
this->mTex = other.mTex;
}
Texture& Texture::operator=(const Texture& other) {
// Same reasoning
this->mTex = other.mTex;
return *this;
}
Game::Renderer::Texture& Game::Renderer::Texture::operator=(const Texture& other) {
// Same reasoning
this->mTex = other.mTex;
return *this;
}
Texture::~Texture() {
if (mTex)
SDL_DestroyTexture(mTex);
LOG("Destroyed texture '" << mId << "'")
}
Game::Renderer::Texture::~Texture() {
if (mTex)
SDL_DestroyTexture(mTex);
LOG("Destroyed texture '" << mId << "'")
}
SDL_Texture* Texture::getSDLTexture() {
return mTex;
}
SDL_Texture* Game::Renderer::Texture::getSDLTexture() {
return mTex;
}
std::string Texture::getId() {
return mId;
}
std::string Game::Renderer::Texture::getId() {
return mId;
float Texture::getWidth() {
if (!mTex) return 0.f;
float width;
SDL_GetTextureSize(mTex, &width, nullptr);
return width;
}
float Texture::getHeight() {
if (!mTex) return 0.f;
float height;
SDL_GetTextureSize(mTex, nullptr, &height);
return height;
}
}