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 | |
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')
-rw-r--r-- | src/AssetManager.cpp | 37 | ||||
-rw-r--r-- | src/TextureAtlas.cpp | 2 |
2 files changed, 14 insertions, 25 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; diff --git a/src/TextureAtlas.cpp b/src/TextureAtlas.cpp index ad62073..406418f 100644 --- a/src/TextureAtlas.cpp +++ b/src/TextureAtlas.cpp @@ -106,7 +106,7 @@ TextureAtlas::TextureAtlas(std::vector<TextureData> &textures) { } } glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, textureCoords[i].pixelX, textureSize - textureCoords[i].pixelY - textureCoords[i].pixelH, textureCoords[i].layer, - textureCoords[i].pixelW, textureCoords[i].pixelH, 1, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, textures[i].data.data()); + textureCoords[i].pixelW, textureCoords[i].pixelH, 1, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, textures[i].data.data()); glCheckError(); } |