Skip to content

Commit

Permalink
[Examples] Started porting HelloGame example to Android and Wasm.
Browse files Browse the repository at this point in the history
- Allow bundling assets from project folder alongside shared asset folder:
  This is added in CMakeLists.txt script function "add_project_resource_files()" for iOS,
  BuildAndroid.sh script for Android, and GenerateHTML5Examples.sh script for Wasm.
- Fixed linker errors of static constexpr members in HelloGame example on Android and compiler error of narrowed type casts on Wasm.
- Allow running examples with immediate command buffer via -i/--icontext arguments.
- Re-enabled selected GL extensions for WebGL profile (this likely broke in 00caa11).
  • Loading branch information
LukasBanana committed Oct 17, 2024
1 parent e207f7d commit 85da158
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 28 deletions.
11 changes: 10 additions & 1 deletion BuildAndroid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ BASE_OPTIONS=(
-DLLGL_GL_ENABLE_OPENGLES=$GLES_VER
-DLLGL_BUILD_RENDERER_NULL=$ENABLE_NULL
-DLLGL_BUILD_RENDERER_VULKAN=$ENABLE_VULKAN
-DLLGL_VK_ENABLE_SPIRV_REFLECT=$ENABLE_VULKAN
-DLLGL_BUILD_EXAMPLES=$ENABLE_EXAMPLES
-DLLGL_BUILD_TESTS=OFF
-DLLGL_BUILD_STATIC_LIB=$STATIC_LIB
Expand Down Expand Up @@ -284,8 +285,16 @@ generate_app_project()
readarray -t ASSET_FILTERS < <(tr -d '\r' < "$ASSETS_LIST_FILE")
ASSET_FILES=()
for FILTER in ${ASSET_FILTERS[@]}; do
# Search for patterns in both the shared assets and current project folder
for FILE in $ASSETS_SOURCE_DIR/$FILTER; do
ASSET_FILES+=( "$FILE" )
if [ -f "$FILE" ]; then
ASSET_FILES+=( "$FILE" )
fi
done
for FILE in $PROJECT_SOURCE_DIR/$FILTER; do
if [ -f "$FILE" ]; then
ASSET_FILES+=( "$FILE" )
fi
done
done

Expand Down
16 changes: 7 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,19 @@ function(find_source_files OUTPUT_LIST FILTERS)
endfunction()

# Adds a (variadic) list of resource files to the output project files.
# The resource files must be located in the shared assets folder,
# The resource files must be located in either the shared assets folder,
# i.e. either under "examples/Shared/Assets/".
# Example:
# add_project_resource_files(MyProjectFiles "Models/ModelAssets-*.obj" "Textures/TextureAsset-1.jpg")
function(add_project_resource_files OUTPUT_LIST)
function(add_project_resource_files OUTPUT_LIST SRC_FOLDER)
# Iterate over all input filenames and expand their paths depending on their file extensions
set(ResourceFiles "")
set(InputFilenames "${ARGN}")
foreach(InputFile ${InputFilenames})
if("${InputFile}" MATCHES ".+\\.(png|jpg|dds|tga)")
file(GLOB TextureResourceFiles "${SHARED_ASSETS_DIR}/${InputFile}")
list(APPEND ResourceFiles "${TextureResourceFiles}")
elseif("${InputFile}" MATCHES ".+\\.(obj)")
file(GLOB ModelResourceFiles "${SHARED_ASSETS_DIR}/${InputFile}")
list(APPEND ResourceFiles "${ModelResourceFiles}")
if("${InputFile}" MATCHES ".+\\.(png|jpg|dds|tga|obj|txt)")
file(GLOB SharedResourceFiles "${SHARED_ASSETS_DIR}/${InputFile}")
file(GLOB ProjectResourceFiles "${SRC_FOLDER}/${InputFile}")
list(APPEND ResourceFiles "${SharedResourceFiles}" "${ProjectResourceFiles}")
endif()
endforeach()

Expand Down Expand Up @@ -215,7 +213,7 @@ function(find_project_source_files OUTPUT_LIST SRC_FILES)
if(NOT "${AssetsListContents}" STREQUAL "")
string(REGEX REPLACE ";" "\\\\;" AssetsListContents "${AssetsListContents}")
string(REGEX REPLACE "\n" ";" AssetsListContents "${AssetsListContents}")
add_project_resource_files(OutputProjectFiles ${AssetsListContents})
add_project_resource_files(OutputProjectFiles "${SRC_FILES}" ${AssetsListContents})
endif()
endif()
endif()
Expand Down
12 changes: 6 additions & 6 deletions examples/Cpp/Animation/Example.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ cbuffer Settings : register(b1)

struct VIn
{
float3 position : POSITION;
float3 normal : NORMAL;
float3 position : POSITION;
float3 normal : NORMAL;
float2 texCoord : TEXCOORD;
};

struct VOut
{
float4 position : SV_Position;
float4 position : SV_Position;
float4 worldPos : WORLDPOS;
float4 normal : NORMAL;
float4 normal : NORMAL;
float2 texCoord : TEXCOORD;
};

void VS(VIn inp, out VOut outp)
{
outp.worldPos = mul(wMatrix, float4(inp.position, 1));
outp.position = mul(vpMatrix, outp.worldPos);
outp.normal = mul(wMatrix, float4(inp.normal, 0));
outp.position = mul(vpMatrix, outp.worldPos);
outp.normal = mul(wMatrix, float4(inp.normal, 0));
outp.texCoord = inp.texCoord;
}

Expand Down
10 changes: 5 additions & 5 deletions examples/Cpp/ExampleBase/ExampleBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ See https://www.gnu.org/software/gnulib/manual/html_node/inttypes_002eh.html
# include <emscripten/html5.h>
#endif

#define IMMEDIATE_SUBMIT_CMDBUFFER 0


/*
* Global helper functions
Expand Down Expand Up @@ -343,6 +341,7 @@ struct ExampleConfig
bool vsync = true;
bool debugger = false;
long flags = 0;
bool immediateSubmit = false;
};

static ExampleConfig g_Config;
Expand All @@ -360,6 +359,8 @@ void ExampleBase::ParseProgramArgs(int argc, char* argv[])
g_Config.vsync = false;
if (HasArgument("-d", argc, argv) || HasArgument("--debug", argc, argv))
g_Config.debugger = true;
if (HasArgument("-i", argc, argv) || HasArgument("--icontext", argc, argv))
g_Config.immediateSubmit = true;
if (HasArgument("-nvidia", argc, argv))
g_Config.flags |= LLGL::RenderSystemFlags::PreferNVIDIA;
if (HasArgument("-amd", argc, argv))
Expand Down Expand Up @@ -533,9 +534,8 @@ ExampleBase::ExampleBase(const LLGL::UTF8String& title)
LLGL::CommandBufferDescriptor cmdBufferDesc;
{
cmdBufferDesc.debugName = "Commands";
#if IMMEDIATE_SUBMIT_CMDBUFFER
cmdBufferDesc.flags = LLGL::CommandBufferFlags::ImmediateSubmit;
#endif
if (g_Config.immediateSubmit)
cmdBufferDesc.flags = LLGL::CommandBufferFlags::ImmediateSubmit;
}
commands = renderer->CreateCommandBuffer(cmdBufferDesc);

Expand Down
Binary file added examples/Cpp/HelloGame/HelloGame.Android.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion examples/Cpp/HelloGame/HelloGame.assets.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Models/HelloGame_*.obj
Textures/Grass.jpg
Textures/Grass.jpg
HelloGame.levels.txt
31 changes: 27 additions & 4 deletions examples/Cpp/HelloGame/HelloGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ class Example_HelloGame : public ExampleBase
groundShaders.vs = LoadShader({ LLGL::ShaderType::Vertex, "HelloGame.hlsl", "VSGround", "vs_5_0" }, { vertexFormat });
groundShaders.ps = LoadShader({ LLGL::ShaderType::Fragment, "HelloGame.hlsl", "PSGround", "ps_5_0" });
}
else if (Supported(LLGL::ShadingLanguage::GLSL))
else if (Supported(LLGL::ShadingLanguage::GLSL) || Supported(LLGL::ShadingLanguage::ESSL))
{
sceneShaders.vs = LoadShaderAndPatchClippingOrigin({ LLGL::ShaderType::Vertex, "HelloGame.VSInstance.450core.vert" }, { vertexFormat });
sceneShaders.ps = LoadShader ({ LLGL::ShaderType::Fragment, "HelloGame.PSInstance.450core.frag" });
Expand Down Expand Up @@ -960,9 +960,9 @@ class Example_HelloGame : public ExampleBase

return LLGL::ColorRGBub
{
((color >> 16) & 0xFF),
((color >> 8) & 0xFF),
((color ) & 0xFF)
static_cast<std::uint8_t>((color >> 16) & 0xFF),
static_cast<std::uint8_t>((color >> 8) & 0xFF),
static_cast<std::uint8_t>((color ) & 0xFF)
};
};

Expand Down Expand Up @@ -1676,6 +1676,29 @@ class Example_HelloGame : public ExampleBase

};

// Clang/GCC need these declared here as well prior to C++17
constexpr float Example_HelloGame::levelTransitionSpeed ;
constexpr float Example_HelloGame::levelDoneSpeed ;
constexpr float Example_HelloGame::wallPosY ;
constexpr int Example_HelloGame::inputStackSize ;
constexpr float Example_HelloGame::playerColor[3] ;
constexpr float Example_HelloGame::treeColorGradient[2][3];
constexpr float Example_HelloGame::treeAnimSpeed ;
constexpr float Example_HelloGame::treeAnimRadius ;
constexpr int Example_HelloGame::shadowMapSize ;
constexpr float Example_HelloGame::timeOfDayChangeSpeed ;

constexpr float Example_HelloGame::playerMoveSpeed ;
constexpr float Example_HelloGame::playerFallAcceleration ;
constexpr float Example_HelloGame::playerJumpWait ;
constexpr float Example_HelloGame::playerJumpDuration ;
constexpr float Example_HelloGame::playerJumpHeight ;
constexpr int Example_HelloGame::playerJumpBounces ;
constexpr float Example_HelloGame::playerExplodeDuration ;
constexpr float Example_HelloGame::playerDescendRotations ;
constexpr float Example_HelloGame::playerDescendHeight ;
constexpr float Example_HelloGame::playerDescendDuration ;

LLGL_IMPLEMENT_EXAMPLE(Example_HelloGame);


Expand Down
13 changes: 11 additions & 2 deletions scripts/GenerateHTML5Examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,19 @@ generate_html5_page()
ASSETS_LIST_FILE=$(find "$PROJECT_SOURCE_DIR" -type f -name *.assets.txt)
if [ -f "$ASSETS_LIST_FILE" ]; then
# Read asset filenames to copy to package output
# and remove '\r' characters when reading the *.asset.txt file from WSL
ASSET_FILES=()
for FILTER in $(cat $ASSETS_LIST_FILE); do
for FILTER in $(cat $ASSETS_LIST_FILE | tr -d '\r'); do
# Search for patterns in both the shared assets and current project folder
for FILE in $ASSETS_SOURCE_DIR/$FILTER; do
ASSET_FILES+=( $(echo "$FILE" | tr -d '\r') ) # Remove '\r' characters when reading .txt file from WSL
if [ -f "$FILE" ]; then
ASSET_FILES+=( "$FILE" )
fi
done
for FILE in $PROJECT_SOURCE_DIR/$FILTER; do
if [ -f "$FILE" ]; then
ASSET_FILES+=( "$FILE" )
fi
done
done

Expand Down
5 changes: 5 additions & 0 deletions sources/Renderer/OpenGL/OpenGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@

#if LLGL_WEBGL

#define LLGL_GLEXT_DRAW_INSTANCED 1
#define LLGL_GLEXT_UNIFORM_BUFFER_OBJECT 1
#define LLGL_GLEXT_SAMPLER_OBJECTS 1
#define LLGL_GLEXT_TRANSFORM_FEEDBACK 1
#define LLGL_GLEXT_VERTEX_ARRAY_OBJECT 1
#define LLGL_GLEXT_FRAMEBUFFER_OBJECT 1

#else // LLGL_WEBGL

Expand Down

0 comments on commit 85da158

Please sign in to comment.