Dawn/src/file/loaders/shader.c

55 lines
1.5 KiB
C

/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "shader.h"
assetmanageritem_t * assetManagerLoadShader(
assetmanager_t *manager, assetmanagerowner_t owner,
char *fileVert, char *fileFrag
) {
assetmanageritem_t *item;
char buffer[ASSET_MANAGER_ITEM_NAME_MAX];
sprintf(buffer, "%s/%s", fileVert, fileFrag);
item = assetManagerItemGet(manager, buffer);
if(item == NULL) {
item = assetManagerItemAdd(manager, buffer);
item->type = ASSET_MANAGER_TYPE_SHADER;
item->data.shader.fileVert = fileVert;
item->data.shader.fileFrag = fileFrag;
}
assetManagerItemGetOrAddHolder(item, owner);
return item;
}
bool _assetManagerLoaderShaderAsync(assetmanageritem_t *item) {
item->data.shader.dataVert = assetStringLoad(item->data.shader.fileVert);
if(item->data.shader.dataVert == NULL) return false;
item->data.shader.dataFrag = assetStringLoad(item->data.shader.fileFrag);
if(item->data.shader.dataFrag == NULL) {
free(item->data.shader.fileVert);
return false;
}
return true;
}
bool _assetManagerLoaderShaderSync(assetmanageritem_t *item) {
shaderInit(
&item->data.shader.shader,
item->data.shader.dataVert,
item->data.shader.dataFrag
);
free(item->data.shader.dataFrag);
free(item->data.shader.dataVert);
return true;
}
bool _assetManagerLoaderShaderDispose(assetmanageritem_t *item) {
shaderDispose(&item->data.shader.shader);
return true;
}