summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/common/entry/entry_android.cpp
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2017-12-01 13:22:27 +0100
committer Miodrag Milanovic <mmicko@gmail.com>2017-12-01 13:22:27 +0100
commit39176274946d70ff520f265dee8fbd16d5fe0000 (patch)
tree318801d93146752050c9a492654ae3738820e3b9 /3rdparty/bgfx/examples/common/entry/entry_android.cpp
parent6829ecb3b037d6bfbe0b84e818d17d712f71bce6 (diff)
Updated GENie, BGFX, BX, added BIMG since it is separated now, updated all shader binaries and MAME part of code to support new interfaces [Miodrag Milanovic]
Diffstat (limited to '3rdparty/bgfx/examples/common/entry/entry_android.cpp')
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_android.cpp92
1 files changed, 86 insertions, 6 deletions
diff --git a/3rdparty/bgfx/examples/common/entry/entry_android.cpp b/3rdparty/bgfx/examples/common/entry/entry_android.cpp
index 78ed2f7a507..3c39f6085f0 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_android.cpp
+++ b/3rdparty/bgfx/examples/common/entry/entry_android.cpp
@@ -9,8 +9,8 @@
#include <bgfx/platform.h>
-#include <stdio.h>
#include <bx/thread.h>
+#include <bx/file.h>
#include <android/input.h>
#include <android/log.h>
@@ -86,9 +86,87 @@ namespace entry
struct MainThreadEntry
{
int m_argc;
- char** m_argv;
+ const char* const* m_argv;
- static int32_t threadFunc(void* _userData);
+ static int32_t threadFunc(bx::Thread* _thread, void* _userData);
+ };
+
+ class FileReaderAndroid : public bx::FileReaderI
+ {
+ public:
+ FileReaderAndroid(AAssetManager* _assetManager, AAsset* _file)
+ : m_assetManager(_assetManager)
+ , m_file(_file)
+ , m_open(false)
+ {
+ }
+
+ virtual ~FileReaderAndroid()
+ {
+ close();
+ }
+
+ virtual bool open(const bx::FilePath& _filePath, bx::Error* _err) override
+ {
+ BX_CHECK(NULL != _err, "Reader/Writer interface calling functions must handle errors.");
+
+ if (NULL != m_file)
+ {
+ BX_ERROR_SET(_err, BX_ERROR_READERWRITER_ALREADY_OPEN, "FileReader: File is already open.");
+ return false;
+ }
+
+ m_file = AAssetManager_open(m_assetManager, _filePath.get(), AASSET_MODE_RANDOM);
+ if (NULL == m_file)
+ {
+ BX_ERROR_SET(_err, BX_ERROR_READERWRITER_OPEN, "FileReader: Failed to open file.");
+ return false;
+ }
+
+ m_open = true;
+ return true;
+ }
+
+ virtual void close() override
+ {
+ if (m_open
+ && NULL != m_file)
+ {
+ AAsset_close(m_file);
+ m_file = NULL;
+ }
+ }
+
+ virtual int64_t seek(int64_t _offset, bx::Whence::Enum _whence) override
+ {
+ BX_CHECK(NULL != m_file, "Reader/Writer file is not open.");
+ return AAsset_seek64(m_file, _offset, _whence);
+
+ }
+
+ virtual int32_t read(void* _data, int32_t _size, bx::Error* _err) override
+ {
+ BX_CHECK(NULL != m_file, "Reader/Writer file is not open.");
+ BX_CHECK(NULL != _err, "Reader/Writer interface calling functions must handle errors.");
+
+ int32_t size = (int32_t)AAsset_read(m_file, _data, _size);
+ if (size != _size)
+ {
+ if (0 == AAsset_getRemainingLength(m_file) )
+ {
+ BX_ERROR_SET(_err, BX_ERROR_READERWRITER_EOF, "FileReader: EOF.");
+ }
+
+ return size >= 0 ? size : 0;
+ }
+
+ return size;
+ }
+
+ private:
+ AAssetManager* m_assetManager;
+ AAsset* m_file;
+ bool m_open;
};
struct Context
@@ -119,9 +197,9 @@ namespace entry
, 0
);
- const char* argv[1] = { "android.so" };
+ const char* const argv[1] = { "android.so" };
m_mte.m_argc = 1;
- m_mte.m_argv = const_cast<char**>(argv);
+ m_mte.m_argv = argv;
while (0 == m_app->destroyRequested)
{
@@ -472,8 +550,10 @@ namespace entry
BX_UNUSED(_handle, _lock);
}
- int32_t MainThreadEntry::threadFunc(void* _userData)
+ int32_t MainThreadEntry::threadFunc(bx::Thread* _thread, void* _userData)
{
+ BX_UNUSED(_thread);
+
int32_t result = chdir("/sdcard/bgfx/examples/runtime");
BX_CHECK(0 == result, "Failed to chdir to dir. android.permission.WRITE_EXTERNAL_STORAGE?", errno);