Asset manager is now in charge of the loaded assets.
This commit is contained in:
@ -61,8 +61,8 @@ elseif(TARGET_TYPE STREQUAL game)
|
||||
)
|
||||
|
||||
# Textures
|
||||
tool_copy(texture_test
|
||||
${ASSETS_SOURCE_DIR}/shared/textures/test_texture.png textures/test_texture.png
|
||||
tool_texture(texture_test
|
||||
${ASSETS_SOURCE_DIR}/shared/textures/test_texture.png textures/test_texture
|
||||
)
|
||||
|
||||
# Locales
|
||||
|
@ -268,8 +268,7 @@ bool assetManagerItemIsFinished(assetmanageritem_t *item) {
|
||||
|
||||
// Font
|
||||
assetmanageritem_t * assetManagerLoadFont(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
font_t *font, char *fileName
|
||||
assetmanager_t *manager, assetmanagerowner_t owner, char *fileName
|
||||
) {
|
||||
assetmanageritem_t *item;
|
||||
item = assetManagerItemGet(manager, fileName);
|
||||
@ -277,7 +276,6 @@ assetmanageritem_t * assetManagerLoadFont(
|
||||
item = assetManagerItemAdd(manager, fileName);
|
||||
item->type = ASSET_MANAGER_TYPE_FONT;
|
||||
item->data.font.fileName = fileName;
|
||||
item->data.font.font = font;
|
||||
}
|
||||
assetManagerItemGetOrAddHolder(item, owner);
|
||||
|
||||
@ -290,20 +288,19 @@ bool _assetManagerLoaderFontAsync(assetmanageritem_t *item) {
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderFontSync(assetmanageritem_t *item) {
|
||||
fontInit(item->data.font.font, item->data.font.data);
|
||||
fontInit(&item->data.font.font, item->data.font.data);
|
||||
free(item->data.font.data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderFontDispose(assetmanageritem_t *item) {
|
||||
fontDispose(item->data.font.font);
|
||||
fontDispose(&item->data.font.font);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Texture
|
||||
assetmanageritem_t * assetManagerLoadTexture(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
texture_t *texture, char *fileName
|
||||
assetmanager_t *manager, assetmanagerowner_t owner, char *fileName
|
||||
) {
|
||||
assetmanageritem_t *item;
|
||||
item = assetManagerItemGet(manager, fileName);
|
||||
@ -311,7 +308,6 @@ assetmanageritem_t * assetManagerLoadTexture(
|
||||
item = assetManagerItemAdd(manager, fileName);
|
||||
item->type = ASSET_MANAGER_TYPE_TEXTURE;
|
||||
item->data.texture.fileName = fileName;
|
||||
item->data.texture.texture = texture;
|
||||
}
|
||||
assetManagerItemGetOrAddHolder(item, owner);
|
||||
|
||||
@ -348,7 +344,7 @@ bool _assetManagerLoaderTextureAsync(assetmanageritem_t *item) {
|
||||
bool _assetManagerLoaderTextureSync(assetmanageritem_t *item) {
|
||||
// Turn into a texture.
|
||||
textureInit(
|
||||
item->data.texture.texture,
|
||||
&item->data.texture.texture,
|
||||
item->data.texture.width,
|
||||
item->data.texture.height,
|
||||
item->data.texture.data
|
||||
@ -360,16 +356,16 @@ bool _assetManagerLoaderTextureSync(assetmanageritem_t *item) {
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderTextureDispose(assetmanageritem_t *item) {
|
||||
textureDispose(item->data.texture.texture);
|
||||
textureDispose(&item->data.texture.texture);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Scaled Texture
|
||||
assetmanageritem_t * assetManagerLoadScaledTexture(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
scaledtexture_t *st, char *path, char *file
|
||||
assetmanager_t *manager, assetmanagerowner_t owner, char *path, char *file
|
||||
) {
|
||||
assetmanageritem_t *item;
|
||||
scaledtexture_t *st;
|
||||
char buffer[ASSET_MANAGER_ITEM_NAME_MAX];
|
||||
sprintf(buffer, "%s/%s", path, file);
|
||||
item = assetManagerItemGet(manager, buffer);
|
||||
@ -377,8 +373,7 @@ assetmanageritem_t * assetManagerLoadScaledTexture(
|
||||
item = assetManagerItemAdd(manager, buffer);
|
||||
|
||||
item->type = ASSET_MANAGER_TYPE_SCALED_TEXTURE;
|
||||
item->data.scaledTexture.scaledTexture = st;
|
||||
|
||||
st = &item->data.scaledTexture.scaledTexture;
|
||||
st->scaleCount = 0;
|
||||
st->baseWidth = 0;
|
||||
st->baseHeight = 0;
|
||||
@ -397,7 +392,7 @@ bool _assetManagerLoaderScaledTextureAsync(assetmanageritem_t *item) {
|
||||
xml_t *child;
|
||||
int16_t i, j;
|
||||
scaledtexture_t *st;
|
||||
st = item->data.scaledTexture.scaledTexture;
|
||||
st = &item->data.scaledTexture.scaledTexture;
|
||||
|
||||
// Begin loading texture XML
|
||||
sprintf(buffer, "%s/%s.xml", st->path, st->file);
|
||||
@ -434,7 +429,7 @@ bool _assetManagerLoaderScaledTextureAsync(assetmanageritem_t *item) {
|
||||
// Texture Scale
|
||||
assetmanageritem_t * assetManagerLoadTextureScale(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
scaledtexture_t *st, texture_t *text, uint8_t scale
|
||||
scaledtexture_t *st, uint8_t scale
|
||||
) {
|
||||
assetmanageritem_t *item;
|
||||
char buffer[ASSET_MANAGER_ITEM_NAME_MAX];
|
||||
@ -444,7 +439,6 @@ assetmanageritem_t * assetManagerLoadTextureScale(
|
||||
item = assetManagerItemAdd(manager, buffer);
|
||||
item->type = ASSET_MANAGER_TYPE_SCALE_TEXTURE;
|
||||
item->data.scaleTexture.scale = scale;
|
||||
item->data.scaleTexture.texture = text;
|
||||
item->data.scaleTexture.scaledTexture = st;
|
||||
}
|
||||
assetManagerItemGetOrAddHolder(item, owner);
|
||||
@ -485,7 +479,7 @@ bool _assetManagerLoaderTextureScaleSync(assetmanageritem_t *item) {
|
||||
sts = st->scales + item->data.scaleTexture.scale;
|
||||
|
||||
textureInit(
|
||||
item->data.scaleTexture.texture,
|
||||
&item->data.scaleTexture.texture,
|
||||
sts->width, sts->height,
|
||||
item->data.scaleTexture.data
|
||||
);
|
||||
@ -495,14 +489,14 @@ bool _assetManagerLoaderTextureScaleSync(assetmanageritem_t *item) {
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderTextureScaleDispose(assetmanageritem_t *item) {
|
||||
textureDispose(item->data.scaleTexture.texture);
|
||||
textureDispose(&item->data.scaleTexture.texture);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Shader
|
||||
assetmanageritem_t * assetManagerLoadShader(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
shader_t *shader, char *fileVert, char *fileFrag
|
||||
char *fileVert, char *fileFrag
|
||||
) {
|
||||
assetmanageritem_t *item;
|
||||
char buffer[ASSET_MANAGER_ITEM_NAME_MAX];
|
||||
@ -511,7 +505,6 @@ assetmanageritem_t * assetManagerLoadShader(
|
||||
if(item == NULL) {
|
||||
item = assetManagerItemAdd(manager, buffer);
|
||||
item->type = ASSET_MANAGER_TYPE_SHADER;
|
||||
item->data.shader.shader = shader;
|
||||
item->data.shader.fileVert = fileVert;
|
||||
item->data.shader.fileFrag = fileFrag;
|
||||
}
|
||||
@ -534,7 +527,7 @@ bool _assetManagerLoaderShaderAsync(assetmanageritem_t *item) {
|
||||
|
||||
bool _assetManagerLoaderShaderSync(assetmanageritem_t *item) {
|
||||
shaderInit(
|
||||
item->data.shader.shader,
|
||||
&item->data.shader.shader,
|
||||
item->data.shader.dataVert,
|
||||
item->data.shader.dataFrag
|
||||
);
|
||||
@ -544,6 +537,6 @@ bool _assetManagerLoaderShaderSync(assetmanageritem_t *item) {
|
||||
}
|
||||
|
||||
bool _assetManagerLoaderShaderDispose(assetmanageritem_t *item) {
|
||||
shaderDispose(item->data.shader.shader);
|
||||
shaderDispose(&item->data.shader.shader);
|
||||
return true;
|
||||
}
|
@ -38,31 +38,31 @@
|
||||
|
||||
// Loader Types
|
||||
typedef struct {
|
||||
font_t *font;
|
||||
font_t font;
|
||||
char *fileName;
|
||||
char *data;
|
||||
} assetmanagerfont_t;
|
||||
|
||||
typedef struct {
|
||||
texture_t *texture;
|
||||
texture_t texture;
|
||||
char *fileName;
|
||||
int32_t width, height;
|
||||
pixel_t *data;
|
||||
} assetmanagertexture_t;
|
||||
|
||||
typedef struct {
|
||||
scaledtexture_t *scaledTexture;
|
||||
scaledtexture_t scaledTexture;
|
||||
} assetmanagerscaledtexture_t;
|
||||
|
||||
typedef struct {
|
||||
scaledtexture_t *scaledTexture;
|
||||
texture_t *texture;
|
||||
texture_t texture;
|
||||
uint8_t scale;
|
||||
pixel_t *data;
|
||||
} assetmanagerscaletexture_t;
|
||||
|
||||
typedef struct {
|
||||
shader_t *shader;
|
||||
shader_t shader;
|
||||
char *fileVert;
|
||||
char *fileFrag;
|
||||
char *dataVert;
|
||||
@ -205,8 +205,7 @@ bool assetManagerItemIsFinished(assetmanageritem_t *item);
|
||||
* @return A pointer to the asset manager item for tracking.
|
||||
*/
|
||||
assetmanageritem_t * assetManagerLoadFont(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
font_t *font, char *fileName
|
||||
assetmanager_t *manager, assetmanagerowner_t owner, char *fileName
|
||||
);
|
||||
|
||||
bool _assetManagerLoaderFontAsync(assetmanageritem_t *item);
|
||||
@ -223,8 +222,7 @@ bool _assetManagerLoaderFontDispose(assetmanageritem_t *item);
|
||||
* @return A pointer to the asset manager item for tracking.
|
||||
*/
|
||||
assetmanageritem_t * assetManagerLoadTexture(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
texture_t *texture, char *fileName
|
||||
assetmanager_t *manager, assetmanagerowner_t owner, char *fileName
|
||||
);
|
||||
|
||||
bool _assetManagerLoaderTextureAsync(assetmanageritem_t *item);
|
||||
@ -237,14 +235,12 @@ bool _assetManagerLoaderTextureDispose(assetmanageritem_t *item);
|
||||
*
|
||||
* @param manager Manager to queue on to.
|
||||
* @param owner Owner ID requesting to load this resource.
|
||||
* @param mt Scaled Texture to load in to.
|
||||
* @param path Path of the texture files
|
||||
* @param file File name of the texture sets.
|
||||
* @return A pointer to the asset manager item for tracking.
|
||||
*/
|
||||
assetmanageritem_t * assetManagerLoadScaledTexture(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
scaledtexture_t *st, char *path, char *file
|
||||
assetmanager_t *manager, assetmanagerowner_t owner, char *path, char *file
|
||||
);
|
||||
|
||||
bool _assetManagerLoaderScaledTextureAsync(assetmanageritem_t *item);
|
||||
@ -261,7 +257,7 @@ bool _assetManagerLoaderScaledTextureAsync(assetmanageritem_t *item);
|
||||
*/
|
||||
assetmanageritem_t * assetManagerLoadTextureScale(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
scaledtexture_t *st, texture_t *text, uint8_t scale
|
||||
scaledtexture_t *st, uint8_t scale
|
||||
);
|
||||
|
||||
bool _assetManagerLoaderTextureScaleAsync(assetmanageritem_t *item);
|
||||
@ -280,7 +276,7 @@ bool _assetManagerLoaderTextureScaleDispose(assetmanageritem_t *item);
|
||||
*/
|
||||
assetmanageritem_t * assetManagerLoadShader(
|
||||
assetmanager_t *manager, assetmanagerowner_t owner,
|
||||
shader_t *shader, char *fileVert, char *fileFrag
|
||||
char *fileVert, char *fileFrag
|
||||
);
|
||||
|
||||
bool _assetManagerLoaderShaderAsync(assetmanageritem_t *item);
|
||||
|
@ -14,32 +14,30 @@ bool sandboxGameInit(sandboxgame_t *game) {
|
||||
sceneInit(&game->scene, &game->engine);
|
||||
|
||||
// Load Shader
|
||||
assetManagerLoadShader(&game->engine.assetManager, game->scene.assetOwner,
|
||||
&game->shader, "shaders/textured.vert", "shaders/textured.frag"
|
||||
game->shader = assetManagerLoadShader(
|
||||
&game->engine.assetManager, game->scene.assetOwner,
|
||||
"shaders/textured.vert", "shaders/textured.frag"
|
||||
);
|
||||
assetManagerLoadShader(&game->engine.assetManager, game->scene.assetOwner,
|
||||
&game->shader2, "shaders/test.vert", "shaders/test.frag"
|
||||
game->shader2 = assetManagerLoadShader(
|
||||
&game->engine.assetManager, game->scene.assetOwner,
|
||||
"shaders/test.vert", "shaders/test.frag"
|
||||
);
|
||||
|
||||
// Load the texture
|
||||
assetManagerLoadScaledTexture(
|
||||
game->scaledTexture = assetManagerLoadScaledTexture(
|
||||
&game->engine.assetManager, game->scene.assetOwner,
|
||||
&game->st, "poker/characters/sammy", "sprite"
|
||||
"textures", "test_texture"
|
||||
);
|
||||
assetManagerLoadTextureScale(
|
||||
game->textureScale = assetManagerLoadTextureScale(
|
||||
&game->engine.assetManager, game->scene.assetOwner,
|
||||
&game->st, &game->texture, 0
|
||||
);
|
||||
|
||||
assetManagerLoadTexture(
|
||||
&game->engine.assetManager, game->scene.assetOwner,
|
||||
&game->texture, "textures/test_texture.png"
|
||||
&game->scaledTexture->data.scaledTexture.scaledTexture, 0
|
||||
);
|
||||
|
||||
// quadInit(&game->quad, 0, 0,0,0,0, 1,1,1,1);
|
||||
cubeInit(&game->quad, 1, 1, 1);
|
||||
|
||||
i = renderPassAdd(&game->scene.renderList, &game->shader);
|
||||
i = renderPassAdd(&game->scene.renderList, &game->shader);
|
||||
i = renderPassAdd(&game->scene.renderList, &game->shader->data.shader.shader);
|
||||
i = renderPassAdd(&game->scene.renderList, &game->shader->data.shader.shader);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -47,6 +45,7 @@ bool sandboxGameInit(sandboxgame_t *game) {
|
||||
void sandboxGameUpdate(sandboxgame_t *game) {
|
||||
camera_t camera;
|
||||
float n;
|
||||
shader_t *shader, *shader2;
|
||||
|
||||
n = assetManagerProgressGet(&game->engine.assetManager);
|
||||
if(n < 1.0f) return;
|
||||
@ -54,13 +53,15 @@ void sandboxGameUpdate(sandboxgame_t *game) {
|
||||
sceneRenderStart(&game->scene);
|
||||
|
||||
// First pass
|
||||
shaderuniform_t uniView = shaderGetUniform(&game->shader, "u_View");
|
||||
shaderuniform_t uniProj = shaderGetUniform(&game->shader, "u_Proj");
|
||||
shaderuniform_t uniModel = shaderGetUniform(&game->shader, "u_Modl");
|
||||
shaderuniform_t uniColor = shaderGetUniform(&game->shader, "u_Colr");
|
||||
shaderuniform_t uniTexture = shaderGetUniform(&game->shader, "u_Text");
|
||||
shader = &game->shader->data.shader.shader;
|
||||
shader2 = &game->shader2->data.shader.shader;
|
||||
shaderuniform_t uniView = shaderGetUniform(shader, "u_View");
|
||||
shaderuniform_t uniProj = shaderGetUniform(shader, "u_Proj");
|
||||
shaderuniform_t uniModel = shaderGetUniform(shader, "u_Modl");
|
||||
shaderuniform_t uniColor = shaderGetUniform(shader, "u_Colr");
|
||||
shaderuniform_t uniTexture = shaderGetUniform(shader, "u_Text");
|
||||
|
||||
renderpass_t *pass =renderListRenderPass(
|
||||
renderpass_t *pass = renderListRenderPass(
|
||||
&game->scene.renderList, &game->engine, 0
|
||||
);
|
||||
cameraPerspective(&camera, 45.0f,
|
||||
@ -70,29 +71,30 @@ void sandboxGameUpdate(sandboxgame_t *game) {
|
||||
|
||||
shaderUseCamera(pass->shader, uniView, uniProj, &camera);
|
||||
shaderUseColor(pass->shader, uniColor, PIXEL_COLOR_WHITE);
|
||||
shaderUseTexture(pass->shader, uniTexture, &game->texture);
|
||||
shaderUseTexture(pass->shader, uniTexture, &game->textureScale->data.scaleTexture.texture);
|
||||
shaderUsePosition(pass->shader, uniModel, 0,0,0,
|
||||
game->engine.time.current/2.0f, game->engine.time.current, 0
|
||||
);
|
||||
primitiveDraw(&game->quad, 0, -1);
|
||||
|
||||
|
||||
// // Second Pass
|
||||
pass = renderListRenderPass(&game->scene.renderList, &game->engine, 1);
|
||||
shaderUsePosition(pass->shader, uniModel, 0,0,0,
|
||||
-game->engine.time.current/2.0f, -game->engine.time.current, 0
|
||||
);
|
||||
primitiveDraw(&game->quad, 0, -1);
|
||||
|
||||
// Merge Shader
|
||||
shaderuniform_t uniTextureSet[2];
|
||||
uniTextureSet[0] = shaderGetUniform(&game->shader2, "u_Text0");
|
||||
uniTextureSet[1] = shaderGetUniform(&game->shader2, "u_Text1");
|
||||
uniTextureSet[0] = shaderGetUniform(shader2, "u_Text0");
|
||||
uniTextureSet[1] = shaderGetUniform(shader2, "u_Text1");
|
||||
|
||||
sceneRenderEnd(&game->scene, &game->shader2,
|
||||
shaderGetUniform(&game->shader2, "u_View"),
|
||||
shaderGetUniform(&game->shader2, "u_Proj"),
|
||||
shaderGetUniform(&game->shader2, "u_Modl"),
|
||||
sceneRenderEnd(&game->scene, shader2,
|
||||
shaderGetUniform(shader2, "u_View"),
|
||||
shaderGetUniform(shader2, "u_Proj"),
|
||||
shaderGetUniform(shader2, "u_Modl"),
|
||||
uniTextureSet,
|
||||
&game->shader, uniView, uniProj, uniModel, uniTexture
|
||||
shader, uniView, uniProj, uniModel, uniTexture
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -26,11 +26,12 @@
|
||||
typedef struct {
|
||||
engine_t engine;
|
||||
scene_t scene;
|
||||
shader_t shader;
|
||||
shader_t shader2;
|
||||
texture_t texture;
|
||||
primitive_t quad;
|
||||
scaledtexture_t st;
|
||||
|
||||
assetmanageritem_t *shader;
|
||||
assetmanageritem_t *shader2;
|
||||
assetmanageritem_t *scaledTexture;
|
||||
assetmanageritem_t *textureScale;
|
||||
} sandboxgame_t;
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user