Modifying GetAssetPath to support more than just shaders (added jasset)
This commit is contained in:
1 parent
2bd0cf39f1
commit
c70cce463b
7 files changed
+74
-33
No files matched your search
+1
-1
@@ -236,7 +236,7 @@ void RenderWorldEditorUI(World& world)
|
|||||||
static char worldFilePath[256] = "../world.bin";
|
static char worldFilePath[256] = "../world.bin";
|
||||||
ImGui::InputText("World File", worldFilePath, sizeof(worldFilePath));
|
ImGui::InputText("World File", worldFilePath, sizeof(worldFilePath));
|
||||||
|
|
||||||
String path = GetAssetPath(temp.Arena, WrapString(worldFilePath));
|
String path = GetAssetPath(temp.Arena, AssetType::JAsset, ConstString(worldFilePath));
|
||||||
|
|
||||||
if (ImGui::Button("Save World"))
|
if (ImGui::Button("Save World"))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,16 +2,19 @@
|
|||||||
|
|
||||||
#include <Core/Common/String.h>
|
#include <Core/Common/String.h>
|
||||||
|
|
||||||
// Returns the path to the application directory
|
enum class AssetType
|
||||||
[[nodiscard]] extern JULIET_API String GetBasePath();
|
{
|
||||||
|
JAsset,
|
||||||
|
Shader
|
||||||
|
};
|
||||||
|
|
||||||
// Returns the resolved base path to the compiled shaders directory.
|
// Returns the path to the application directory
|
||||||
// In dev, this resolves to ../../Assets/compiled/ relative to the exe.
|
extern JULIET_API String GetBasePath();
|
||||||
// In shipping, this resolves to Assets/Shaders/ next to the exe.
|
|
||||||
[[nodiscard]] extern JULIET_API String GetAssetBasePath();
|
// Path to the /Assets/ folder
|
||||||
|
extern JULIET_API String GetAssetBasePath();
|
||||||
|
|
||||||
// Builds a full path to an asset file given its filename (e.g. "Triangle.vert.dxil").
|
// Builds a full path to an asset file given its filename (e.g. "Triangle.vert.dxil").
|
||||||
// The caller owns the returned buffer and must free it.
|
extern JULIET_API String GetAssetPath(NonNullPtr<Arena> arena, AssetType type, String filename);
|
||||||
[[nodiscard]] extern JULIET_API String GetAssetPath(NonNullPtr<Arena> arena, String filename);
|
|
||||||
|
|
||||||
[[nodiscard]] extern JULIET_API bool IsAbsolutePath(String path);
|
extern JULIET_API bool IsAbsolutePath(String path);
|
||||||
@@ -12,6 +12,7 @@ namespace
|
|||||||
{
|
{
|
||||||
String CachedBasePath = {};
|
String CachedBasePath = {};
|
||||||
String CachedAssetBasePath = {};
|
String CachedAssetBasePath = {};
|
||||||
|
String CachedShaderBasePath = {};
|
||||||
|
|
||||||
bool DirectoryExists(const char* path)
|
bool DirectoryExists(const char* path)
|
||||||
{
|
{
|
||||||
@@ -33,18 +34,32 @@ String GetAssetBasePath()
|
|||||||
return CachedAssetBasePath;
|
return CachedAssetBasePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] String GetAssetPath(NonNullPtr<Arena> arena, String filename)
|
String GetAssetPath(NonNullPtr<Arena> arena, AssetType type, String filename)
|
||||||
{
|
{
|
||||||
// TODO: Path is Assets/Compiled, we need to fix that one day
|
String asset_path = {};
|
||||||
Assert(IsValid(CachedAssetBasePath));
|
switch (type)
|
||||||
|
{
|
||||||
|
case AssetType::Shader:
|
||||||
|
{
|
||||||
|
Assert(IsValid(CachedShaderBasePath));
|
||||||
Assert(IsValid(filename));
|
Assert(IsValid(filename));
|
||||||
|
|
||||||
size_t totalSize = CachedAssetBasePath.Size + filename.Size + 1;
|
size_t totalSize = CachedShaderBasePath.Size + filename.Size + 1;
|
||||||
char* buffer = ArenaPushArray<char>(arena, totalSize);
|
char* buffer = ArenaPushArray<char>(arena, totalSize);
|
||||||
Assert(buffer);
|
Assert(buffer);
|
||||||
|
|
||||||
juliet_snprintf(buffer, totalSize, "%s%s", CStr(CachedAssetBasePath), CStr(filename));
|
juliet_snprintf(buffer, totalSize, "%s%s", CStr(CachedShaderBasePath), CStr(filename));
|
||||||
return { buffer, totalSize - 1 };
|
asset_path = { buffer, totalSize - 1 };
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
asset_path = GetAssetBasePath();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return asset_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsAbsolutePath(String path)
|
bool IsAbsolutePath(String path)
|
||||||
@@ -63,10 +78,10 @@ void InitFilesystem(NonNullPtr<Arena> arena)
|
|||||||
String basePath = GetBasePath();
|
String basePath = GetBasePath();
|
||||||
Assert(IsValid(basePath));
|
Assert(IsValid(basePath));
|
||||||
|
|
||||||
// Probe candidate paths for compiled shader directory
|
// Probe candidate paths base asset folder
|
||||||
// 1. Shipping layout: Assets/Shaders/ next to the exe
|
// 1. Shipping layout: Assets/ next to the exe
|
||||||
// 2. Dev layout: ../../Assets/compiled/ (exe is in bin/x64Clang-<Config>/)
|
// 2. Dev layout: ../../Assets/ (exe is in bin/x64Clang-<Config>/)
|
||||||
constexpr const char* kCandidates[] = { "Assets/Shaders/", "../../Assets/compiled/" };
|
constexpr const char* kCandidates[] = { "Assets/", "../../Assets/" };
|
||||||
|
|
||||||
for (const char* candidate : kCandidates)
|
for (const char* candidate : kCandidates)
|
||||||
{
|
{
|
||||||
@@ -82,6 +97,29 @@ void InitFilesystem(NonNullPtr<Arena> arena)
|
|||||||
CachedAssetBasePath = { buffer, len };
|
CachedAssetBasePath = { buffer, len };
|
||||||
Log(LogLevel::Message, LogCategory::Core, "Asset base path: %s", buffer);
|
Log(LogLevel::Message, LogCategory::Core, "Asset base path: %s", buffer);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Probe candidate paths for compiled shader directory
|
||||||
|
// 1. Shipping layout: Assets/Shaders/
|
||||||
|
// 2. Dev layout: Assets/compiled/
|
||||||
|
constexpr const char* kCandidatesShader[] = { "Shaders/", "compiled/" };
|
||||||
|
|
||||||
|
for (const char* candidate : kCandidatesShader)
|
||||||
|
{
|
||||||
|
char probePath[512];
|
||||||
|
juliet_snprintf(probePath, sizeof(probePath), "%s%s", CStr(CachedAssetBasePath), candidate);
|
||||||
|
|
||||||
|
if (DirectoryExists(probePath))
|
||||||
|
{
|
||||||
|
size_t len = strlen(probePath);
|
||||||
|
if (char* buffer = ArenaPushArray<char>(arena, len + 1 JULIET_DEBUG_PARAM("CachedShaderBasePath")))
|
||||||
|
{
|
||||||
|
juliet_snprintf(buffer, len + 1, "%s", probePath);
|
||||||
|
CachedShaderBasePath = { buffer, len };
|
||||||
|
Log(LogLevel::Message, LogCategory::Core, "Shader base path: %s", buffer);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,4 +133,6 @@ void ShutdownFilesystem()
|
|||||||
CachedBasePath.Str = nullptr;
|
CachedBasePath.Str = nullptr;
|
||||||
CachedAssetBasePath.Size = 0;
|
CachedAssetBasePath.Size = 0;
|
||||||
CachedAssetBasePath.Str = nullptr;
|
CachedAssetBasePath.Str = nullptr;
|
||||||
|
CachedShaderBasePath.Size = 0;
|
||||||
|
CachedShaderBasePath.Str = nullptr;
|
||||||
}
|
}
|
||||||
@@ -86,11 +86,11 @@ namespace
|
|||||||
|
|
||||||
TempArena path = scratch_begin(0, 0);
|
TempArena path = scratch_begin(0, 0);
|
||||||
|
|
||||||
String vertPath = GetAssetPath(path.Arena, WrapString("Debug.vert.dxil"));
|
String vertPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("Debug.vert.dxil"));
|
||||||
shaderCI.Stage = ShaderStage::Vertex;
|
shaderCI.Stage = ShaderStage::Vertex;
|
||||||
Shader* vertexShader = CreateShader(device, vertPath, shaderCI);
|
Shader* vertexShader = CreateShader(device, vertPath, shaderCI);
|
||||||
|
|
||||||
String fragPath = GetAssetPath(path.Arena, WrapString("Debug.frag.dxil"));
|
String fragPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("Debug.frag.dxil"));
|
||||||
shaderCI.Stage = ShaderStage::Fragment;
|
shaderCI.Stage = ShaderStage::Fragment;
|
||||||
Shader* fragmentShader = CreateShader(device, fragPath, shaderCI);
|
Shader* fragmentShader = CreateShader(device, fragPath, shaderCI);
|
||||||
|
|
||||||
|
|||||||
@@ -131,11 +131,11 @@ bool ImGuiRenderer_Initialize(GraphicsDevice* device)
|
|||||||
|
|
||||||
TempArena path = scratch_begin(0, 0);
|
TempArena path = scratch_begin(0, 0);
|
||||||
|
|
||||||
String vertPath = GetAssetPath(path.Arena, WrapString("ImGui.vert.dxil"));
|
String vertPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("ImGui.vert.dxil"));
|
||||||
shaderCI.Stage = ShaderStage::Vertex;
|
shaderCI.Stage = ShaderStage::Vertex;
|
||||||
g_ImGuiState.VertexShader = CreateShader(device, vertPath, shaderCI);
|
g_ImGuiState.VertexShader = CreateShader(device, vertPath, shaderCI);
|
||||||
|
|
||||||
String fragPath = GetAssetPath(path.Arena, WrapString("ImGui.frag.dxil"));
|
String fragPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("ImGui.frag.dxil"));
|
||||||
shaderCI.Stage = ShaderStage::Fragment;
|
shaderCI.Stage = ShaderStage::Fragment;
|
||||||
g_ImGuiState.FragmentShader = CreateShader(device, fragPath, shaderCI);
|
g_ImGuiState.FragmentShader = CreateShader(device, fragPath, shaderCI);
|
||||||
|
|
||||||
|
|||||||
@@ -81,11 +81,11 @@ bool InitializeMeshRendererGraphics(NonNullPtr<GraphicsDevice> device, NonNullPt
|
|||||||
|
|
||||||
TempArena path = scratch_begin(0, 0);
|
TempArena path = scratch_begin(0, 0);
|
||||||
|
|
||||||
String shaderPath = GetAssetPath(path.Arena, WrapString("Triangle.vert.dxil"));
|
String shaderPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("Triangle.vert.dxil"));
|
||||||
shaderCI.Stage = ShaderStage::Vertex;
|
shaderCI.Stage = ShaderStage::Vertex;
|
||||||
Shader* vertexShader = CreateShader(graphicsDevice, shaderPath, shaderCI);
|
Shader* vertexShader = CreateShader(graphicsDevice, shaderPath, shaderCI);
|
||||||
|
|
||||||
shaderPath = GetAssetPath(path.Arena, WrapString("SolidColor.frag.dxil"));
|
shaderPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("SolidColor.frag.dxil"));
|
||||||
shaderCI.Stage = ShaderStage::Fragment;
|
shaderCI.Stage = ShaderStage::Fragment;
|
||||||
Shader* fragmentShader = CreateShader(graphicsDevice, shaderPath, shaderCI);
|
Shader* fragmentShader = CreateShader(graphicsDevice, shaderPath, shaderCI);
|
||||||
|
|
||||||
@@ -149,8 +149,7 @@ bool InitializeMeshRendererGraphics(NonNullPtr<GraphicsDevice> device, NonNullPt
|
|||||||
transformsBufferCI.IsDynamic = true;
|
transformsBufferCI.IsDynamic = true;
|
||||||
g_MeshRenderer.TransformsBuffer = CreateGraphicsBuffer(graphicsDevice, transformsBufferCI);
|
g_MeshRenderer.TransformsBuffer = CreateGraphicsBuffer(graphicsDevice, transformsBufferCI);
|
||||||
Assert(g_MeshRenderer.TransformsBuffer != nullptr);
|
Assert(g_MeshRenderer.TransformsBuffer != nullptr);
|
||||||
g_MeshRenderer.MappedTransforms =
|
g_MeshRenderer.MappedTransforms = static_cast<Matrix*>(MapGraphicsBuffer(graphicsDevice, g_MeshRenderer.TransformsBuffer));
|
||||||
static_cast<Matrix*>(MapGraphicsBuffer(graphicsDevice, g_MeshRenderer.TransformsBuffer));
|
|
||||||
Assert(g_MeshRenderer.MappedTransforms != nullptr);
|
Assert(g_MeshRenderer.MappedTransforms != nullptr);
|
||||||
|
|
||||||
// Sync existing lights that might have been added before graphics initialization
|
// Sync existing lights that might have been added before graphics initialization
|
||||||
@@ -551,11 +550,11 @@ void ReloadMeshRendererShaders()
|
|||||||
String entryPoint = WrapString("main");
|
String entryPoint = WrapString("main");
|
||||||
ShaderCreateInfo shaderCI = {};
|
ShaderCreateInfo shaderCI = {};
|
||||||
shaderCI.EntryPoint = entryPoint;
|
shaderCI.EntryPoint = entryPoint;
|
||||||
String shaderPath = GetAssetPath(path.Arena, WrapString("Triangle.vert.dxil"));
|
String shaderPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("Triangle.vert.dxil"));
|
||||||
shaderCI.Stage = ShaderStage::Vertex;
|
shaderCI.Stage = ShaderStage::Vertex;
|
||||||
Shader* vertexShader = CreateShader(device, shaderPath, shaderCI);
|
Shader* vertexShader = CreateShader(device, shaderPath, shaderCI);
|
||||||
|
|
||||||
shaderPath = GetAssetPath(path.Arena, WrapString("SolidColor.frag.dxil"));
|
shaderPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("SolidColor.frag.dxil"));
|
||||||
shaderCI.Stage = ShaderStage::Fragment;
|
shaderCI.Stage = ShaderStage::Fragment;
|
||||||
Shader* fragmentShader = CreateShader(device, shaderPath, shaderCI);
|
Shader* fragmentShader = CreateShader(device, shaderPath, shaderCI);
|
||||||
|
|
||||||
|
|||||||
@@ -24,14 +24,14 @@ bool InitializeSkyboxRenderer(NonNullPtr<GraphicsDevice> device, NonNullPtr<Wind
|
|||||||
ShaderCreateInfo skyboxVSCI = {};
|
ShaderCreateInfo skyboxVSCI = {};
|
||||||
skyboxVSCI.EntryPoint = skyboxVSEntry;
|
skyboxVSCI.EntryPoint = skyboxVSEntry;
|
||||||
skyboxVSCI.Stage = ShaderStage::Vertex;
|
skyboxVSCI.Stage = ShaderStage::Vertex;
|
||||||
String vsPath = GetAssetPath(path.Arena, WrapString("Skybox.vert.dxil"));
|
String vsPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("Skybox.vert.dxil"));
|
||||||
Shader* skyboxVS = CreateShader(graphicsDevice, vsPath, skyboxVSCI);
|
Shader* skyboxVS = CreateShader(graphicsDevice, vsPath, skyboxVSCI);
|
||||||
|
|
||||||
String skyboxFSEntry = WrapString("main");
|
String skyboxFSEntry = WrapString("main");
|
||||||
ShaderCreateInfo skyboxFSCI = {};
|
ShaderCreateInfo skyboxFSCI = {};
|
||||||
skyboxFSCI.EntryPoint = skyboxFSEntry;
|
skyboxFSCI.EntryPoint = skyboxFSEntry;
|
||||||
skyboxFSCI.Stage = ShaderStage::Fragment;
|
skyboxFSCI.Stage = ShaderStage::Fragment;
|
||||||
String fsPath = GetAssetPath(path.Arena, WrapString("Skybox.frag.dxil"));
|
String fsPath = GetAssetPath(path.Arena, AssetType::Shader, ConstString("Skybox.frag.dxil"));
|
||||||
Shader* skyboxFS = CreateShader(graphicsDevice, fsPath, skyboxFSCI);
|
Shader* skyboxFS = CreateShader(graphicsDevice, fsPath, skyboxFSCI);
|
||||||
|
|
||||||
scratch_end(path);
|
scratch_end(path);
|
||||||
@@ -109,4 +109,3 @@ void ReloadSkyboxShaders()
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Reference in new issue
Block a user