diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2018-08-09 03:37:09 +0200 |
---|---|---|
committer | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2018-08-09 03:37:09 +0200 |
commit | 01a40b8f8995b035b293028449f1afc24906b9be (patch) | |
tree | 8069c090f165c05880a2bb6be5d01af4dbb3c1f1 /src/AssetManager.cpp | |
parent | Implemented Creative Flight (diff) | |
download | AltCraft-01a40b8f8995b035b293028449f1afc24906b9be.tar AltCraft-01a40b8f8995b035b293028449f1afc24906b9be.tar.gz AltCraft-01a40b8f8995b035b293028449f1afc24906b9be.tar.bz2 AltCraft-01a40b8f8995b035b293028449f1afc24906b9be.tar.lz AltCraft-01a40b8f8995b035b293028449f1afc24906b9be.tar.xz AltCraft-01a40b8f8995b035b293028449f1afc24906b9be.tar.zst AltCraft-01a40b8f8995b035b293028449f1afc24906b9be.zip |
Diffstat (limited to 'src/AssetManager.cpp')
-rw-r--r-- | src/AssetManager.cpp | 37 |
1 files changed, 13 insertions, 24 deletions
diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp index 9671491..97833f5 100644 --- a/src/AssetManager.cpp +++ b/src/AssetManager.cpp @@ -7,7 +7,10 @@ #include <easylogging++.h> #include <glm/gtc/matrix_transform.hpp> #include <SDL.h> -#include <SDL_image.h> +#define STBI_NO_STDIO +#define STB_IMAGE_IMPLEMENTATION +#define STBI_ONLY_PNG +#include <stb_image.h> #include "Utility.hpp" @@ -132,35 +135,21 @@ void ParseAsset(AssetTreeNode &node) { } void ParseAssetTexture(AssetTreeNode &node) { - SDL_RWops *rw = SDL_RWFromMem(node.data.data(), node.data.size()); - SDL_Surface *surface = IMG_LoadPNG_RW(rw); - - SDL_RWclose(rw); - if (!surface) { + int w, h, n; + unsigned char *data = stbi_load_from_memory(node.data.data(),node.data.size(), &w, &h, &n, 4); + if (data == nullptr) { return; } - if (surface->format->format != SDL_PIXELFORMAT_RGBA8888) { - SDL_Surface *temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA8888, 0); - std::swap(temp, surface); - if (!temp) { - std::swap(temp, surface); - } - SDL_FreeSurface(temp); - } - - SDL_LockSurface(surface); - node.asset = std::make_unique<AssetTexture>(); AssetTexture *asset = dynamic_cast<AssetTexture*>(node.asset.get()); - size_t dataLen = surface->h * surface->pitch; + size_t dataLen = w * h * 4; asset->textureData.resize(dataLen); - std::memcpy(asset->textureData.data(), surface->pixels, dataLen); - asset->realWidth = surface->w; - asset->realHeight = surface->h; + std::memcpy(asset->textureData.data(), data, dataLen); + asset->realWidth = w; + asset->realHeight = h; - SDL_UnlockSurface(surface); - SDL_FreeSurface(surface); + stbi_image_free(data); node.data.swap(std::vector<unsigned char>()); } @@ -525,7 +514,7 @@ const BlockModel *AssetManager::GetBlockModelByBlockId(BlockId block) { AssetBlockModel *assetModel = GetAsset<AssetBlockModel>("/minecraft/models/block/" + model.modelName); if (!assetModel) return &GetAsset<AssetBlockModel>("/minecraft/models/block/error")->blockModel; - + blockIdToBlockModel.insert(std::make_pair(block, &assetModel->blockModel)); return &assetModel->blockModel; |