added asset loading class, zoom factor, vbo switch, shader version
This commit is contained in:
59
engine/asset.cpp
Normal file
59
engine/asset.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "pch.h"
|
||||
#include "asset.h"
|
||||
|
||||
#ifdef __ANDROID__
|
||||
AAssetManager* Asset::m_am;
|
||||
#endif
|
||||
|
||||
bool Asset::open(const char* path)
|
||||
{
|
||||
LOG("Asset::open %s", path);
|
||||
m_current_path = path;
|
||||
#ifdef __ANDROID__
|
||||
if (!(m_asset = AAssetManager_open(m_am, path, AASSET_MODE_RANDOM)))
|
||||
{
|
||||
LOG("AAssetManager_open failed");
|
||||
return false;
|
||||
}
|
||||
m_len = (int)AAsset_getLength(m_asset);
|
||||
m_data = (uint8_t*)AAsset_getBuffer(m_asset);
|
||||
#else
|
||||
if (!(m_fp = fopen(path, "rb")))
|
||||
return false;
|
||||
fseek(m_fp, 0, SEEK_END);
|
||||
m_len = (int)ftell(m_fp);
|
||||
fseek(m_fp, 0, SEEK_SET);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::uint8_t* Asset::read_all()
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
return m_data;
|
||||
#else
|
||||
if (!m_data)
|
||||
{
|
||||
m_data = new uint8_t[m_len];
|
||||
if (m_len != fread(m_data, 1, m_len, m_fp))
|
||||
{
|
||||
LOG("ASSET READ FAILED for %s", m_current_path.c_str());
|
||||
delete m_data;
|
||||
m_data = nullptr;
|
||||
}
|
||||
}
|
||||
return m_data;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Asset::close()
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
AAsset_close(m_asset);
|
||||
#else
|
||||
fclose(m_fp);
|
||||
if (m_data)
|
||||
delete m_data;
|
||||
m_data = nullptr;
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user