Added KrCompileAllShaders and stub implementation
This commit is contained in:
@@ -237,7 +237,7 @@ SET(STANDARD_ASSET_BUNDLE "${CMAKE_BINARY_DIR}/output/assets/standard_assets.krb
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${STANDARD_ASSET_BUNDLE}
|
||||
COMMAND kraken_convert -o ${STANDARD_ASSET_BUNDLE} ${KRAKEN_STANDARD_ASSETS}
|
||||
COMMAND kraken_convert -c -o ${STANDARD_ASSET_BUNDLE} ${KRAKEN_STANDARD_ASSETS}
|
||||
DEPENDS kraken_convert ${KRAKEN_STANDARD_ASSETS}
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
COMMENT "Creating Standard Assets"
|
||||
|
||||
@@ -106,6 +106,7 @@ KRContext::KRContext(const KrInitializeInfo* initializeInfo)
|
||||
#endif
|
||||
|
||||
createDeviceContexts();
|
||||
glslang::InitializeProcess();
|
||||
}
|
||||
|
||||
KRContext::~KRContext() {
|
||||
@@ -170,6 +171,7 @@ KRContext::~KRContext() {
|
||||
delete m_resourceMap;
|
||||
m_resourceMap = NULL;
|
||||
}
|
||||
glslang::FinalizeProcess();
|
||||
}
|
||||
|
||||
void KRContext::SetLogCallback(log_callback *log_callback, void *user_data)
|
||||
@@ -493,6 +495,15 @@ KrResult KRContext::moveToBundle(const KrMoveToBundleInfo* moveToBundleInfo)
|
||||
return resource->moveToBundle(bundle);
|
||||
}
|
||||
|
||||
KrResult KRContext::compileAllShaders(const KrCompileAllShadersInfo* pCompileAllShadersInfo) {
|
||||
bool success = m_pShaderManager->compileAll();
|
||||
if (success) {
|
||||
// TODO - Save log to a resource
|
||||
return KR_SUCCESS;
|
||||
}
|
||||
return KR_ERROR_SHADER_COMPILE_FAILED;
|
||||
}
|
||||
|
||||
KrResult KRContext::saveResource(const KrSaveResourceInfo* saveResourceInfo)
|
||||
{
|
||||
if (saveResourceInfo->resourceHandle < 0 || saveResourceInfo->resourceHandle >= m_resourceMapSize) {
|
||||
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
KrResult unmapResource(const KrUnmapResourceInfo* unmapResourceInfo);
|
||||
KrResult saveResource(const KrSaveResourceInfo* saveResourceInfo);
|
||||
|
||||
KrResult compileAllShaders(const KrCompileAllShadersInfo* pCompileAllShadersInfo);
|
||||
|
||||
KrResult createScene(const KrCreateSceneInfo* createSceneInfo);
|
||||
KrResult findNodeByName(const KrFindNodeByNameInfo* pFindNodeByNameInfo);
|
||||
KrResult findAdjacentNodes(const KrFindAdjacentNodesInfo* pFindAdjacentNodesInfo);
|
||||
|
||||
@@ -34,6 +34,7 @@ using namespace kraken;
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../3rdparty/tinyxml2/tinyxml2.h"
|
||||
#include "../3rdparty/glslang/glslang/Public/ShaderLang.h"
|
||||
#if defined(__APPLE__)
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
@@ -115,3 +115,8 @@ const unordered_map<std::string, KRShader *> &KRShaderManager::get(const std::st
|
||||
return m_shaders[lower_extension];
|
||||
}
|
||||
|
||||
|
||||
bool KRShaderManager::compileAll()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ public:
|
||||
KRShader *load(const std::string &name, const std::string &extension, KRDataBlock *data);
|
||||
KRShader *get(const std::string &name, const std::string &extension);
|
||||
|
||||
bool compileAll();
|
||||
|
||||
const unordered_map<std::string, KRShader *> &get(const std::string &extension);
|
||||
|
||||
|
||||
@@ -114,6 +114,14 @@ KrResult KrMoveToBundle(const KrMoveToBundleInfo* pMoveToBundleInfo)
|
||||
return sContext->moveToBundle(pMoveToBundleInfo);
|
||||
}
|
||||
|
||||
KrResult KrCompileAllShaders(const KrCompileAllShadersInfo* pCompileAllShadersInfo)
|
||||
{
|
||||
if (!sContext) {
|
||||
return KR_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
return sContext->compileAllShaders(pCompileAllShadersInfo);
|
||||
}
|
||||
|
||||
KrResult KrCreateScene(const KrCreateSceneInfo* pCreateSceneInfo)
|
||||
{
|
||||
if (!sContext) {
|
||||
|
||||
@@ -50,6 +50,7 @@ typedef enum {
|
||||
KR_ERROR_VULKAN_REQUIRED,
|
||||
KR_ERROR_VULKAN_SWAP_CHAIN,
|
||||
KR_ERROR_NO_DEVICE,
|
||||
KR_ERROR_SHADER_COMPILE_FAILED,
|
||||
KR_ERROR_UNEXPECTED = 0x10000000,
|
||||
KR_RESULT_MAX_ENUM = 0x7FFFFFFF
|
||||
} KrResult;
|
||||
@@ -69,6 +70,8 @@ typedef enum {
|
||||
KR_STRUCTURE_TYPE_CREATE_BUNDLE,
|
||||
KR_STRUCTURE_TYPE_MOVE_TO_BUNDLE,
|
||||
|
||||
KR_STRUCTURE_TYPE_COMPILE_ALL_SHADERS,
|
||||
|
||||
KR_STRUCTURE_TYPE_CREATE_SCENE = 0x00020000,
|
||||
|
||||
KR_STRUCTURE_TYPE_FIND_NODE_BY_NAME = 0x00030000,
|
||||
@@ -165,6 +168,11 @@ typedef struct {
|
||||
KrResourceMapIndex bundleHandle;
|
||||
} KrMoveToBundleInfo;
|
||||
|
||||
typedef struct {
|
||||
KrStructureType sType;
|
||||
KrResourceMapIndex logHandle;
|
||||
} KrCompileAllShadersInfo;
|
||||
|
||||
typedef struct {
|
||||
KrStructureType sType;
|
||||
const char* pSceneName;
|
||||
@@ -395,6 +403,8 @@ KrResult KrCreateBundle(const KrCreateBundleInfo* pCreateBundleInfo);
|
||||
KrResult KrMoveToBundle(const KrMoveToBundleInfo* pMoveToBundleInfo);
|
||||
KrResult KrInitNodeInfo(KrNodeInfo* pNodeInfo, KrStructureType nodeType);
|
||||
|
||||
KrResult KrCompileAllShaders(const KrCompileAllShadersInfo* pCompileAllShadersInfo);
|
||||
|
||||
KrResult KrCreateScene(const KrCreateSceneInfo* pCreateSceneInfo);
|
||||
KrResult KrFindNodeByName(const KrFindNodeByNameInfo* pFindNodeByNameInfo);
|
||||
KrResult KrFindAdjacentNodes(const KrFindAdjacentNodesInfo* pFindAdjacentNodesInfo);
|
||||
|
||||
@@ -5,8 +5,15 @@
|
||||
|
||||
using namespace kraken;
|
||||
|
||||
enum ResourceMapping {
|
||||
output_bundle = 0,
|
||||
loaded_resource = 1,
|
||||
shader_compile_log = 2,
|
||||
};
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
bool failed = false;
|
||||
printf("Kraken Convert\n");
|
||||
printf("Initializing Kraken...\n");
|
||||
KrInitializeInfo init_info = {};
|
||||
@@ -20,7 +27,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
KrCreateBundleInfo create_bundle_info = {};
|
||||
create_bundle_info.sType = KR_STRUCTURE_TYPE_CREATE_BUNDLE;
|
||||
create_bundle_info.resourceHandle = 0;
|
||||
create_bundle_info.resourceHandle = ResourceMapping::output_bundle;
|
||||
create_bundle_info.pBundleName = "output";
|
||||
res = KrCreateBundle(&create_bundle_info);
|
||||
if (res != KR_SUCCESS) {
|
||||
@@ -31,15 +38,16 @@ int main( int argc, char *argv[] )
|
||||
|
||||
KrLoadResourceInfo load_resource_info = {};
|
||||
load_resource_info.sType = KR_STRUCTURE_TYPE_LOAD_RESOURCE;
|
||||
load_resource_info.resourceHandle = 1;
|
||||
load_resource_info.resourceHandle = ResourceMapping::loaded_resource;
|
||||
|
||||
KrMoveToBundleInfo move_to_bundle_info = {};
|
||||
move_to_bundle_info.sType = KR_STRUCTURE_TYPE_MOVE_TO_BUNDLE;
|
||||
move_to_bundle_info.bundleHandle = 0;
|
||||
move_to_bundle_info.bundleHandle = ResourceMapping::output_bundle;
|
||||
|
||||
char* output_bundle = nullptr;
|
||||
bool compile_shaders = false;
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
for (int i = 1; i < argc && !failed; i++) {
|
||||
char *arg = argv[i];
|
||||
if (arg[0] == '-') {
|
||||
continue;
|
||||
@@ -50,6 +58,9 @@ int main( int argc, char *argv[] )
|
||||
case 'o':
|
||||
output_bundle = arg;
|
||||
break;
|
||||
case 'c':
|
||||
compile_shaders = true;
|
||||
break;
|
||||
default:
|
||||
printf("Unknown command: -%c\n", command);
|
||||
break;
|
||||
@@ -62,31 +73,49 @@ int main( int argc, char *argv[] )
|
||||
res = KrLoadResource(&load_resource_info);
|
||||
if (res != KR_SUCCESS) {
|
||||
printf("[FAIL] (KrLoadResource)\n");
|
||||
failed = true;
|
||||
continue;
|
||||
}
|
||||
move_to_bundle_info.resourceHandle = 1;
|
||||
move_to_bundle_info.resourceHandle = ResourceMapping::loaded_resource;
|
||||
res = KrMoveToBundle(&move_to_bundle_info);
|
||||
if (res != KR_SUCCESS) {
|
||||
printf("[FAIL] (KrMoveToBundle)\n");
|
||||
failed = true;
|
||||
continue;
|
||||
}
|
||||
printf("[GOOD]\n");
|
||||
}
|
||||
|
||||
if (output_bundle) {
|
||||
if (compile_shaders && !failed) {
|
||||
printf("Compiling Shaders...\n");
|
||||
KrCompileAllShadersInfo compile_all_shaders_info = {};
|
||||
compile_all_shaders_info.sType = KR_STRUCTURE_TYPE_COMPILE_ALL_SHADERS;
|
||||
compile_all_shaders_info.logHandle = ResourceMapping::shader_compile_log;
|
||||
res = KrCompileAllShaders(&compile_all_shaders_info);
|
||||
if (res != KR_SUCCESS) {
|
||||
printf("[FAIL] (Error %i)\n", res);
|
||||
failed = true;
|
||||
}
|
||||
else {
|
||||
printf("[GOOD]\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (output_bundle && !failed) {
|
||||
printf("Bundling %s... ", output_bundle);
|
||||
KrSaveResourceInfo save_resource_info = {};
|
||||
save_resource_info.sType = KR_STRUCTURE_TYPE_SAVE_RESOURCE;
|
||||
save_resource_info.resourceHandle = 0;
|
||||
save_resource_info.resourceHandle = ResourceMapping::output_bundle;
|
||||
save_resource_info.pResourcePath = output_bundle;
|
||||
res = KrSaveResource(&save_resource_info);
|
||||
if (res != KR_SUCCESS) {
|
||||
printf("[FAIL] (Error %i)\n", res);
|
||||
failed = true;
|
||||
} else {
|
||||
printf("[GOOD]\n");
|
||||
}
|
||||
}
|
||||
|
||||
KrShutdown();
|
||||
return 0;
|
||||
return failed ? 1 : 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user