-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15f10bd
commit 9cddcdf
Showing
13 changed files
with
147 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include "PreLoader.h" | ||
#include "RenderStateManager.h" | ||
#include "TextureManager.h" | ||
|
||
#include <Gensys/DebugUtility.h> | ||
#include <Gensys/StringUtility.h> | ||
#include <Gensys/TimeUtility.h> | ||
#include <stdexcept> | ||
#include <algorithm> | ||
#include <string> | ||
#include <vector> | ||
|
||
using namespace Gensys; | ||
using namespace NexgenRedux; | ||
|
||
namespace | ||
{ | ||
std::vector<std::string> m_textureKeys; | ||
} | ||
|
||
void PreLoader::Close(void) | ||
{ | ||
RenderStateManager* renderStateManager = RenderStateManager::GetInstance(); | ||
|
||
for (size_t i = 0; i < m_textureKeys.size(); ++i) | ||
{ | ||
const std::string value = m_textureKeys[i]; | ||
|
||
uint32_t textureID = 0; | ||
bool textureExists = renderStateManager->TextureExists(StringUtility::ToWideString(value), textureID); | ||
if (textureExists == true) | ||
{ | ||
renderStateManager->DeleteTextureReference(textureID); | ||
} | ||
} | ||
} | ||
|
||
void PreLoader::LoadTexture(const std::string value) | ||
{ | ||
// Only load if we dont a ref to key ourselves | ||
if (std::find(m_textureKeys.begin(), m_textureKeys.end(), value) != m_textureKeys.end()) | ||
{ | ||
return; | ||
} | ||
|
||
RenderStateManager* renderStateManager = RenderStateManager::GetInstance(); | ||
|
||
uint32_t textureID = 0; | ||
|
||
bool textureExists = renderStateManager->TextureExists(StringUtility::ToWideString(value), textureID); | ||
renderStateManager->CreateTextureReference(StringUtility::ToWideString(value), textureID); | ||
if (textureExists == false) | ||
{ | ||
TextureManager::Request(StringUtility::ToWideString(value), textureID); | ||
} | ||
} | ||
|
||
void PreLoader::UnLoadTexture(const std::string value) | ||
{ | ||
// Only unload if we have a ref to key ourselves | ||
if (std::find(m_textureKeys.begin(), m_textureKeys.end(), value) == m_textureKeys.end()) | ||
{ | ||
return; | ||
} | ||
|
||
RenderStateManager* renderStateManager = RenderStateManager::GetInstance(); | ||
|
||
uint32_t textureID = 0; | ||
|
||
bool textureExists = renderStateManager->TextureExists(StringUtility::ToWideString(value), textureID); | ||
if (textureExists == true) | ||
{ | ||
renderStateManager->DeleteTextureReference(textureID); | ||
} | ||
} | ||
|
||
void PreLoader::WaitTexturesLoaded() | ||
{ | ||
// This should not be called until render engine / window created | ||
|
||
RenderStateManager* renderStateManager = RenderStateManager::GetInstance(); | ||
|
||
for (size_t i = 0; i < m_textureKeys.size(); ++i) | ||
{ | ||
const std::string value = m_textureKeys[i]; | ||
|
||
uint32_t textureID = 0; | ||
bool textureExists = renderStateManager->TextureExists(StringUtility::ToWideString(value), textureID); | ||
if (textureExists == true) | ||
{ | ||
while (renderStateManager->IsTextureLoaded(textureID) == false) | ||
{ | ||
TimeUtility::SleepMilliseconds(100); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
namespace NexgenRedux | ||
{ | ||
class PreLoader | ||
{ | ||
public: | ||
static void Close(void); | ||
static void LoadTexture(const std::string value); | ||
static void UnLoadTexture(const std::string value); | ||
static void WaitTexturesLoaded(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters