mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-10-07 02:43:32 +00:00
Get rid of more unnecessary uses of ManagedTexture
This commit is contained in:
parent
4c3f82da55
commit
2aca8fe3f9
@ -152,6 +152,19 @@ Draw::Texture *CreateTextureFromFileData(Draw::DrawContext *draw, const uint8_t
|
||||
return texture;
|
||||
}
|
||||
|
||||
Draw::Texture *CreateTextureFromFile(Draw::DrawContext *draw, const char *filename, ImageFileType type, bool generateMips) {
|
||||
INFO_LOG(SYSTEM, "CreateTextureFromFile(%s)", filename);
|
||||
size_t fileSize;
|
||||
uint8_t *buffer = g_VFS.ReadFile(filename, &fileSize);
|
||||
if (!buffer) {
|
||||
ERROR_LOG(IO, "Failed to read file '%s'", filename);
|
||||
return nullptr;
|
||||
}
|
||||
Draw::Texture *texture = CreateTextureFromFileData(draw, buffer, fileSize, type, generateMips, filename);
|
||||
delete[] buffer;
|
||||
return texture;
|
||||
}
|
||||
|
||||
bool ManagedTexture::LoadFromFileData(const uint8_t *data, size_t dataSize, ImageFileType type, bool generateMips, const char *name) {
|
||||
generateMips_ = generateMips;
|
||||
|
||||
@ -171,6 +184,7 @@ bool ManagedTexture::LoadFromFileData(const uint8_t *data, size_t dataSize, Imag
|
||||
}
|
||||
|
||||
bool ManagedTexture::LoadFromFile(const std::string &filename, ImageFileType type, bool generateMips) {
|
||||
INFO_LOG(SYSTEM, "ManagedTexture::LoadFromFile (%s)", filename.c_str());
|
||||
generateMips_ = generateMips;
|
||||
size_t fileSize;
|
||||
uint8_t *buffer = g_VFS.ReadFile(filename.c_str(), &fileSize);
|
||||
@ -191,6 +205,7 @@ bool ManagedTexture::LoadFromFile(const std::string &filename, ImageFileType typ
|
||||
}
|
||||
|
||||
std::unique_ptr<ManagedTexture> CreateManagedTextureFromFile(Draw::DrawContext *draw, const char *filename, ImageFileType type, bool generateMips) {
|
||||
INFO_LOG(SYSTEM, "ManagedTexture::CreateFromFile (%s)", filename);
|
||||
if (!draw)
|
||||
return std::unique_ptr<ManagedTexture>();
|
||||
// TODO: Load the texture on a background thread.
|
||||
@ -234,17 +249,3 @@ Draw::Texture *ManagedTexture::GetTexture() {
|
||||
}
|
||||
return texture_;
|
||||
}
|
||||
|
||||
// TODO: Remove the code duplication between this and LoadFromFileData
|
||||
std::unique_ptr<ManagedTexture> CreateManagedTextureFromFileData(Draw::DrawContext *draw, const uint8_t *data, int size, ImageFileType type, bool generateMips, const char *name) {
|
||||
if (!draw)
|
||||
return std::unique_ptr<ManagedTexture>();
|
||||
ManagedTexture *mtex = new ManagedTexture(draw);
|
||||
if (mtex->LoadFromFileData(data, size, type, generateMips, name)) {
|
||||
return std::unique_ptr<ManagedTexture>(mtex);
|
||||
} else {
|
||||
// Best to return a null pointer if we fail!
|
||||
delete mtex;
|
||||
return std::unique_ptr<ManagedTexture>();
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,6 @@ private:
|
||||
};
|
||||
|
||||
Draw::Texture *CreateTextureFromFileData(Draw::DrawContext *draw, const uint8_t *data, size_t dataSize, ImageFileType type, bool generateMips, const char *name);
|
||||
Draw::Texture *CreateTextureFromFile(Draw::DrawContext *draw, const char *filename, ImageFileType type, bool generateMips);
|
||||
|
||||
std::unique_ptr<ManagedTexture> CreateManagedTextureFromFile(Draw::DrawContext *draw, const char *filename, ImageFileType fileType, bool generateMips);
|
||||
std::unique_ptr<ManagedTexture> CreateManagedTextureFromFileData(Draw::DrawContext *draw, const uint8_t *data, int size, ImageFileType fileType, bool generateMips, const char *name);
|
||||
|
@ -22,6 +22,8 @@ UIContext::~UIContext() {
|
||||
sampler_->Release();
|
||||
delete fontStyle_;
|
||||
delete textDrawer_;
|
||||
uitexture_->Release();
|
||||
fontTexture_->Release();
|
||||
}
|
||||
|
||||
void UIContext::Init(Draw::DrawContext *thin3d, Draw::Pipeline *uipipe, Draw::Pipeline *uipipenotex, DrawBuffer *uidrawbuffer) {
|
||||
@ -41,17 +43,17 @@ void UIContext::setUIAtlas(const std::string &name) {
|
||||
|
||||
void UIContext::BeginFrame() {
|
||||
if (!uitexture_ || UIAtlas_ != lastUIAtlas_) {
|
||||
uitexture_ = CreateManagedTextureFromFile(draw_, UIAtlas_.c_str(), ImageFileType::ZIM, false);
|
||||
uitexture_ = CreateTextureFromFile(draw_, UIAtlas_.c_str(), ImageFileType::ZIM, false);
|
||||
lastUIAtlas_ = UIAtlas_;
|
||||
if (!fontTexture_) {
|
||||
#if PPSSPP_PLATFORM(WINDOWS) || PPSSPP_PLATFORM(ANDROID)
|
||||
// Don't bother with loading font_atlas.zim
|
||||
#else
|
||||
fontTexture_ = CreateManagedTextureFromFile(draw_, "font_atlas.zim", ImageFileType::ZIM, false);
|
||||
fontTexture_ = CreateTextureFromFile(draw_, "font_atlas.zim", ImageFileType::ZIM, false);
|
||||
#endif
|
||||
if (!fontTexture_) {
|
||||
// Load the smaller ascii font only, like on Android. For debug ui etc.
|
||||
fontTexture_ = CreateManagedTextureFromFile(draw_, "asciifont_atlas.zim", ImageFileType::ZIM, false);
|
||||
fontTexture_ = CreateTextureFromFile(draw_, "asciifont_atlas.zim", ImageFileType::ZIM, false);
|
||||
if (!fontTexture_) {
|
||||
WARN_LOG(SYSTEM, "Failed to load font_atlas.zim or asciifont_atlas.zim");
|
||||
}
|
||||
@ -88,15 +90,15 @@ void UIContext::BeginPipeline(Draw::Pipeline *pipeline, Draw::SamplerState *samp
|
||||
|
||||
void UIContext::RebindTexture() const {
|
||||
if (uitexture_)
|
||||
draw_->BindTexture(0, uitexture_->GetTexture());
|
||||
draw_->BindTexture(0, uitexture_);
|
||||
}
|
||||
|
||||
void UIContext::BindFontTexture() const {
|
||||
// Fall back to the UI texture, in case they have an old atlas.
|
||||
if (fontTexture_)
|
||||
draw_->BindTexture(0, fontTexture_->GetTexture());
|
||||
draw_->BindTexture(0, fontTexture_);
|
||||
else if (uitexture_)
|
||||
draw_->BindTexture(0, uitexture_->GetTexture());
|
||||
draw_->BindTexture(0, uitexture_);
|
||||
}
|
||||
|
||||
void UIContext::Flush() {
|
||||
|
@ -23,7 +23,6 @@ namespace Draw {
|
||||
}
|
||||
|
||||
class Texture;
|
||||
class ManagedTexture;
|
||||
class DrawBuffer;
|
||||
class TextDrawer;
|
||||
|
||||
@ -128,8 +127,8 @@ private:
|
||||
Draw::SamplerState *sampler_ = nullptr;
|
||||
Draw::Pipeline *ui_pipeline_ = nullptr;
|
||||
Draw::Pipeline *ui_pipeline_notex_ = nullptr;
|
||||
std::unique_ptr<ManagedTexture> uitexture_;
|
||||
std::unique_ptr<ManagedTexture> fontTexture_;
|
||||
Draw::Texture *uitexture_ = nullptr;
|
||||
Draw::Texture *fontTexture_ = nullptr;
|
||||
|
||||
DrawBuffer *uidrawbuffer_ = nullptr;
|
||||
|
||||
|
@ -27,9 +27,9 @@
|
||||
#include "Common/File/VFS/VFS.h"
|
||||
#include "Common/File/FileUtil.h"
|
||||
#include "Common/File/Path.h"
|
||||
#include "Common/Render/ManagedTexture.h"
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Common/TimeUtil.h"
|
||||
#include "Common/Render/ManagedTexture.h"
|
||||
#include "Core/FileSystems/ISOFileSystem.h"
|
||||
#include "Core/FileSystems/DirectoryFileSystem.h"
|
||||
#include "Core/FileSystems/VirtualDiscFileSystem.h"
|
||||
@ -43,6 +43,17 @@
|
||||
|
||||
GameInfoCache *g_gameInfoCache;
|
||||
|
||||
void GameInfoTex::Clear() {
|
||||
if (!data.empty()) {
|
||||
data.clear();
|
||||
dataLoaded = false;
|
||||
}
|
||||
if (texture) {
|
||||
texture->Release();
|
||||
texture = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
GameInfo::GameInfo() : fileType(IdentifiedFileType::UNKNOWN) {
|
||||
pending = true;
|
||||
}
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "Common/Thread/Event.h"
|
||||
#include "Core/ELF/ParamSFO.h"
|
||||
#include "Common/File/Path.h"
|
||||
#include "Common/Render/ManagedTexture.h"
|
||||
|
||||
namespace Draw {
|
||||
class DrawContext;
|
||||
@ -71,16 +70,7 @@ struct GameInfoTex {
|
||||
std::atomic<bool> dataLoaded{};
|
||||
|
||||
// Can ONLY be called from the main thread!
|
||||
void Clear() {
|
||||
if (!data.empty()) {
|
||||
data.clear();
|
||||
dataLoaded = false;
|
||||
}
|
||||
if (texture) {
|
||||
texture->Release();
|
||||
texture = nullptr;
|
||||
}
|
||||
}
|
||||
void Clear();
|
||||
};
|
||||
|
||||
class GameInfo {
|
||||
|
@ -39,6 +39,8 @@
|
||||
#include "Common/Data/Random/Rng.h"
|
||||
#include "Common/TimeUtil.h"
|
||||
#include "Common/File/FileUtil.h"
|
||||
#include "Common/Render/ManagedTexture.h"
|
||||
|
||||
#include "Core/Config.h"
|
||||
#include "Core/System.h"
|
||||
#include "Core/MIPS/JitCommon/JitCommon.h"
|
||||
@ -74,7 +76,7 @@ static const uint32_t colors[4] = {
|
||||
0xC0FFFFFF,
|
||||
};
|
||||
|
||||
static std::unique_ptr<ManagedTexture> bgTexture;
|
||||
static Draw::Texture *bgTexture;
|
||||
|
||||
class Animation {
|
||||
public:
|
||||
@ -96,7 +98,7 @@ public:
|
||||
return;
|
||||
|
||||
dc.Flush();
|
||||
dc.GetDrawContext()->BindTexture(0, bgTexture->GetTexture());
|
||||
dc.GetDrawContext()->BindTexture(0, bgTexture);
|
||||
Bounds bounds = dc.GetBounds();
|
||||
|
||||
x = std::min(std::max(x/bounds.w, 0.0f), 1.0f) * XFAC;
|
||||
@ -287,22 +289,25 @@ private:
|
||||
|
||||
static BackgroundAnimation g_CurBackgroundAnimation = BackgroundAnimation::OFF;
|
||||
static std::unique_ptr<Animation> g_Animation;
|
||||
static bool bgTextureInited = false;
|
||||
static bool bgTextureInited = false; // Separate variable because init could fail.
|
||||
|
||||
void UIBackgroundInit(UIContext &dc) {
|
||||
const Path bgPng = GetSysDirectory(DIRECTORY_SYSTEM) / "background.png";
|
||||
const Path bgJpg = GetSysDirectory(DIRECTORY_SYSTEM) / "background.jpg";
|
||||
if (File::Exists(bgPng) || File::Exists(bgJpg)) {
|
||||
const Path &bgFile = File::Exists(bgPng) ? bgPng : bgJpg;
|
||||
bgTexture = CreateManagedTextureFromFile(dc.GetDrawContext(), bgFile.c_str(), DETECT, true);
|
||||
bgTexture = CreateTextureFromFile(dc.GetDrawContext(), bgFile.c_str(), DETECT, true);
|
||||
}
|
||||
}
|
||||
|
||||
void UIBackgroundShutdown() {
|
||||
bgTexture.reset(nullptr);
|
||||
if (bgTexture) {
|
||||
bgTexture->Release();
|
||||
bgTexture = nullptr;
|
||||
}
|
||||
bgTextureInited = false;
|
||||
g_Animation.reset(nullptr);
|
||||
g_CurBackgroundAnimation = BackgroundAnimation::OFF;
|
||||
bgTextureInited = false;
|
||||
}
|
||||
|
||||
void DrawBackground(UIContext &dc, float alpha, float x, float y, float z) {
|
||||
@ -336,7 +341,7 @@ void DrawBackground(UIContext &dc, float alpha, float x, float y, float z) {
|
||||
if (bgTexture != nullptr) {
|
||||
dc.Flush();
|
||||
dc.Begin();
|
||||
dc.GetDrawContext()->BindTexture(0, bgTexture->GetTexture());
|
||||
dc.GetDrawContext()->BindTexture(0, bgTexture);
|
||||
dc.Draw()->DrawTexRect(dc.GetBounds(), 0, 0, 1, 1, bgColor);
|
||||
|
||||
dc.Flush();
|
||||
|
Loading…
Reference in New Issue
Block a user