-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Examples] Refactored asset loading in examples.
- Replaced filename resolution via FindResourcePath() with abstraction to load entire asset via ReadAsset(). - Replaced individual uses of stbi_load() with new ImageReader class. - Started with asset loading for Android. - Also use different header guard for examples: Renamed "LLGL_*" to "LLGLEXAMPLES_*". TODO: Android asset reading will need connection to JNI to access 'AAssetManager'.
- Loading branch information
1 parent
561e6ab
commit 1047789
Showing
17 changed files
with
487 additions
and
170 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* AppUtils.c (Android) | ||
* | ||
* Copyright (c) 2015 Lukas Hermanns. All rights reserved. | ||
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt). | ||
*/ | ||
|
||
#include "AppUtils.h" | ||
#include <errno.h> | ||
|
||
|
||
static int AndroidFileRead(void* userData, char* buffer, int size) | ||
{ | ||
return AAsset_read((AAsset*)userData, buffer, (size_t)size); | ||
} | ||
|
||
static int AndroidFileWrite(void* userData, const char* buffer, int size) | ||
{ | ||
return EACCES; // dummy - cannot provide access to write to APK | ||
} | ||
|
||
static fpos_t AndroidFileSeek(void* userData, fpos_t offset, int whence) | ||
{ | ||
return AAsset_seek((AAsset*)userData, offset, whence); | ||
} | ||
|
||
static int AndroidFileClose(void* userData) | ||
{ | ||
AAsset_close((AAsset*)userData); | ||
return 0; | ||
} | ||
|
||
static AAssetManager* g_assetMngr = NULL; | ||
|
||
void AndroidSetAssetManager(AAssetManager* assetMngr) | ||
{ | ||
g_assetMngr = assetMngr; | ||
} | ||
|
||
FILE* AndroidOpenFile(const char* filename, const char* mode) | ||
{ | ||
if (g_assetMngr == NULL) | ||
return NULL; // No asset manager provided | ||
|
||
if (mode[0] == 'w') | ||
return NULL; // Write access is not supported on APK package | ||
|
||
// Open asset via AAssetManager | ||
AAsset* asset = AAssetManager_open(g_assetMngr, filename, AASSET_MODE_STREAMING); | ||
if (asset == NULL) | ||
return NULL; // Failed to open asset | ||
|
||
// Open FILE descriptor with custom read/seek functions | ||
return funopen(asset, AndroidFileRead, AndroidFileWrite, AndroidFileSeek, AndroidFileClose); | ||
} | ||
|
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,29 @@ | ||
/* | ||
* AppUtils.h (Android) | ||
* | ||
* Copyright (c) 2015 Lukas Hermanns. All rights reserved. | ||
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt). | ||
*/ | ||
|
||
#ifndef __USE_BSD | ||
#define __USE_BSD /* Defines funopen() */ | ||
#endif | ||
|
||
#include <stdio.h> | ||
#include <android/asset_manager.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
// Sets the current asset manager. | ||
void AndroidSetAssetManager(AAssetManager* assetMngr); | ||
|
||
// Opens an STD file stream via the AAssetManager. | ||
FILE* AndroidOpenFile(const char* filename, const char* mode); | ||
|
||
#define fopen(NAME, MODE) AndroidOpenFile(NAME, MODE) | ||
|
||
#ifdef __cplusplus | ||
} // /extern "C" | ||
#endif |
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
Oops, something went wrong.