horde3d / Horde3D

Horde3D is a small 3D rendering and animation engine. It is written in an effort to create an engine being as lightweight and conceptually clean as possible.
http://horde3d.org/
1.51k stars 306 forks source link

Emscripten issues #211

Closed gwald closed 2 weeks ago

gwald commented 1 year ago

Hi algts

Trying to compile in Emscripten

emcmake cmake .. -DHORDE3D_USE_GL4=OFF -DHORDE3D_USE_GLES3=ON -DHORDE3D_BUILD_EXAMPLES=ON -DHORDE3D_USE_GLFW=OFF -DHORDE3D_USE_SDL=ON -DHORDE3D_FORCE_DOWNLOAD_SDL=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=make

It compiled SDL2 and horde3d fine, but came across a few issue, not sure if it's just me: https://github.com/horde3d/Horde3D/compare/master...gwald:Horde3D:master

cmake is looking for SDL2 as a .so but it's a .a

make[2]: No rule to make target 'project_sdl-prefix/lib/libSDL2-2.0.so', needed by 'Binaries/Emscripten/Release/Terrain.js'. Stop. make[1]: [CMakeFiles/Makefile2:657: Extensions/Terrain/Sample/CMakeFiles/Terrain.dir/all] Error 2 make: *** [Makefile:103: all] Error 2

I'm not sure where to look to fix this, any tips?

algts commented 1 year ago

Hello. First of all, Emscripten is not yet officially supported, so engine is not yet adapted to it, expect bugs :)

Are you using linux or mingw? If you are using recent versions, maybe it is a similar bug to glfw, where compiler expects lib64 folder, but cmake scripts force it to search lib folder (check either latest master or develop where this bug should be fixed for glfw). Also look at FindSDL2.cmake in BuildTools/CMake/Modules - it has some hard coded parts for different platforms, maybe you have to add another path for emscripten platform. Also you can try to override sdl library in the cmake gui in SDL category. You should also be able to do it through the console with something like cmake -DSDL_LIBRARY_PATH=<your path>/libSDL2.a .. (not verified). In that case you should probably build sdl separately.

P.S. AFAIK, glfw is also working good in emscripten. Did you try it?

gwald commented 1 year ago

oh cool. linux, using develop branch. SDL2 build well and they were simple bugs... I tried glfw with replacing the SDL command above and it didn't build for me. I'll try your suggestions and get back to you, thanks! :)

gwald commented 1 year ago

ha, I didn't mean to close it :/ sorry

algts commented 1 year ago

@gwald Hello. Did you achieve the required results? I'll try to look into the issue on weekend.

gwald commented 1 year ago

Hi Sorry, I got really distracted!

I got Horde3D (and Assimp converter and viewer) compiled in windows XP and using the dll's with Tiny C Compiler... it works very well :)

I don't know cmake very well, I'll leave it open and when I get back to HTML5, I'll update it.

gwald commented 7 months ago

I'm testing emscripten again, but without the cmake or makefile stuff, just using a batch file based on this project: https://github.com/bosoni/Horde3D_em (I wasn't able to build it with the current emsdk, but the build that's there ran fine).

I got my bouncing ball project building without errors, using the GL2 support!

But it doesn't work on the browser because of a few missing function in emscripten.

image

[h3d-err] Extension EXT_framebuffer_object not supported index.js:1:34760 [h3d-err] Extension EXT_texture_compression_s3tc not supported index.js:1:34760 [h3d-err] Extension EXT_texture_sRGB not supported

I'm not a graphics programmer, not sure if these can be replaced with any of these: [h3d] Supported extensions: 'ANGLE_instanced_arrays EXT_blend_minmax EXT_color_buffer_half_float EXT_float_blend EXT_frag_depth EXT_shader_texture_lod EXT_sRGB EXT_texture_compression_bptc EXT_texture_compression_rgtc EXT_texture_filter_anisotropic OES_element_index_uint OES_fbo_render_mipmap OES_standard_derivatives OES_texture_float OES_texture_float_linear OES_texture_half_float OES_texture_half_float_linear OES_vertex_array_object WEBGL_color_buffer_float WEBGL_compressed_texture_s3tc WEBGL_compressed_texture_s3tc_srgb WEBGL_debug_renderer_info WEBGL_debug_shaders WEBGL_depth_texture WEBGL_draw_buffers WEBGL_lose_context GL_ANGLE_instanced_arrays GL_EXT_blend_minmax GL_EXT_color_buffer_half_float GL_EXT_float_blend GL_EXT_frag_depth GL_EXT_shader_texture_lod GL_EXT_sRGB GL_EXT_texture_compression_bptc GL_EXT_texture_compression_rgtc GL_EXT_texture_filter_anisotropic GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_standard_derivatives GL_OES_texture_float GL_OES_texture_float_linear GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_vertex_array_object GL_WEBGL_color_buffer_float GL_WEBGL_compressed_texture_s3tc GL_WEBGL_compressed_texture_s3tc_srgb GL_WEBGL_debug_renderer_info GL_WEBGL_debug_shaders GL_WEBGL_depth_texture GL_WEBGL_draw_buffers GL_WEBGL_lose_context'

here is my batch file:


REM@echo off
@echo %*
call C:\emsdk\emsdk_env.bat
set PATH=C:\emsdk\python\3.9.2-nuget_64bit;%PATH%

set ENG=C:\Horde3D-master\Horde3D\Source\Horde3DEngine\
set UTL=C:\Horde3D-master\Horde3D\Source\Horde3DUtils\
set TEXT=C:\Horde3D-master\Extensions\ExternalTexture\Source\
set OVER=C:\Horde3D-master\Extensions\Overlays\Source\
set TERR=C:\Horde3D-master\Extensions\Terrain\Source\
set SHAR=C:\Horde3D-master\Horde3D\Source\Shared\
set H3D=C:\Horde3D-master\Horde3D\Bindings\C++\
set SDL2=C:\emsdk\upstream\emscripten\cache\sysroot\include\
REM C:\emsdk\upstream\emscripten\cache\ports\
set Y3D_INC=./includes/

CLS
echo %H3D%
echo %ENG%
echo %UTL%
echo %TEXT%
echo %OVER%
echo %TERR%
echo %SHAR%
echo %SDL2%
echo %Y3D_INC%

rm -f  index.*
rm -f %ENG%config.h
rm -f index.*

emcc  -fmax-errors=5 -w ^
-I. ^
-I%H3D% ^
-I%ENG% ^
-I%TEXT% ^
-I%OVER% ^
-I%TERR% ^
-I%SHAR% ^
-I%SDL2% ^
-I%Y3D_INC% ^
%ENG%egAnimatables.cpp ^
%ENG%egAnimation.cpp ^
%ENG%egCamera.cpp ^
%ENG%egCom.cpp ^
%ENG%egComputeBuffer.cpp ^
%ENG%egComputeNode.cpp ^
%ENG%egExtensions.cpp ^
%ENG%egGeometry.cpp ^
%ENG%egLight.cpp ^
%ENG%egMain.cpp ^
%ENG%egMaterial.cpp ^
%ENG%egModel.cpp ^
%ENG%egModules.cpp ^
%ENG%egParticle.cpp ^
%ENG%egPipeline.cpp ^
%ENG%egPrimitives.cpp ^
%ENG%egRenderer.cpp ^
%ENG%egRendererBaseGL2.cpp ^
%ENG%egResource.cpp ^
%ENG%egScene.cpp ^
%ENG%egSceneGraphRes.cpp ^
%ENG%egShader.cpp ^
%ENG%egTexture.cpp ^
%ENG%utImage.cpp ^
%ENG%utOpenGL.cpp ^
%TEXT%extension.cpp ^
%TEXT%egTextureEx.cpp ^
%OVER%extension.cpp ^
%OVER%overlays.cpp ^
%TERR%extension.cpp ^
%TERR%terrain.cpp ^
%UTL%main.cpp ^
Y3D_PC.c ^
Y3D_API.c ^
game.c ^
-s ERROR_ON_UNDEFINED_SYMBOLS=0   ^
-O3 -DHAVE_EGL -DH3D_USE_GL2  -DDESKTOP_OPENGL_AVAILABLE   ^
-s USE_SDL=2 -s USE_WEBGPU=1 -s USE_WEBGL2=1  -s WASM=1  -s ALLOW_MEMORY_GROWTH=1 ^
--preload-file Content  ^
-o index.html

echo recreate config.h.in
cp %ENG%config.h.in %ENG%config.h.in
rm -rf Z:\Downloads\yarmico3-backup\PC
cp -a ../PC Z:\Downloads\yarmico3-backup\PC
algts commented 7 months ago

You should probably use ES3 backend for webgl2, because it is base on OpenGL ES 3 specification. ES 3 backend may have its own set of issues on desktop though.

gwald commented 7 months ago

Emscripten targets the "WebGL-friendly subset of OpenGL ES 2.0" parts of ES2 & ES3 is emulated.

I wasn't able to build with ES3, using the batch above with:

Y3D_API.c ^ game.c -lGL -DGLES_3 ^ -s ERROR_ON_UNDEFINED_SYMBOLS=0 ^ -O3 -s USE_SDL=2 -s FULL_ES3=1 -s FULL_ES2=1 -sMIN_WEBGL_VERSION=1 -sMAX_WEBGL_VERSION=2 ^ -s DEMANGLE_SUPPORT=1 -s SAFE_HEAP=1 --bind -s WASM=1 ^ -s ALLOW_MEMORY_GROWTH=1 ^ --preload-file Content ^ -o index.html

A lot of undefined symbols:

h3dGLES::glGetQueryObjectivEXT h3dGLES::glGetQueryObjectui64vEXT h3dGLES::glGetQueryObjectui64vEXT h3dGLES::glQueryCounterEXT glESExt::EXT_disjoint_timer_query h3dGLES::glGetQueryObjectivEXT h3dGLES::glGetQueryObjectui64vEXT h3dGLES::glGetQueryObjectui64vEXT h3dGLES::glQueryCounterEXT glESExt::KHR_debug h3dGLES::glDebugMessageControlKHR glESExt::KHR_debug h3dGLES::glDebugMessageControlKHR h3dGLES::glDebugMessageCallbackKHR glESExt::majorVersion glESExt::minorVersion glESExt::EXT_texture_filter_anisotropic glESExt::EXT_color_buffer_float glESExt::EXT_texture_compression_s3tc glESExt::EXT_disjoint_timer_query

I probably missed something either H3D or emscripten related.

The emscripten docs suggest: https://github.com/ptitSeb/gl4es for gl2 support, but it looks like it's missing EXT_texture_sRGB

https://github.com/emscripten-ports/regal looks like it has all the missing functions :)

algts commented 7 months ago

Well, you can just disable extension check in the renderer backend for extensions you don't need (and in utOpenGL/ES). Also, please check the parameters you are using. For Webgl2 you should probably drop FULL_ES2=1 and -sMIN_WEBGL_VERSION=1 - the mixture of these with enabling webgl2 may lead to problems.

Did you use -DH3D_USE_GLES3 in your batch file?

What browser are you using? I've come across an old thread that assumes that extensions may be called differently, at least on Webkit (mac) browsers: https://groups.google.com/g/emscripten-discuss/c/vUYESeFjFIM

gwald commented 7 months ago

These are undefines, so it doesn't link/build. I've set the unsupported features as info so it doesn't stop, but it usually crashes in the browser right after.

I read that having old the emcc parameters for old and new GL/ES support doesnt conflict, I tried it and it's still the same.

H3D_USE_GLES3 was defined in the config.h Firefox seems to work fine, I also use chrome.

I tried building both gles4 and regal in emscripten, but I couldnt get it to emcmake or emmake to work :/

I couldn't even build the old h3d with ES2: https://github./bosoni/Horde3D_em It has these undefined: glBlitFramebufferANGLE glCompressedTexImage3DOES glFramebufferTexture2DMultisampleEXT glRenderbufferStorageMultisampleANGLE glRenderbufferStorageMultisampleEXT glTexImage3DOES

I'm guessing it requires angel, which I couldn't find any emscripten docs.

Ha, too hard for me

algts commented 7 months ago

Ok, I'll dive deeper into the issue and see what can be done.

gwald commented 7 months ago

Hey thanks, I appreciate your help :) it's not urgent but it is an important target for me, so I'm happy to test anything you find.

gwald commented 3 months ago

Hello again,

I got emscripten using ES3 down to 4 undefined symbol:

\Users\dev\AppData\Local\Temp\emscripten_temp_9zhlxuw5\egRendererBaseGLES3_1.o: undefined symbol: glMemoryBarrier

\Users\dev\AppData\Local\Temp\emscripten_temp_9zhlxuw5\egRendererBaseGLES3_1.o: undefined symbol: glGetProgramResourceIndex

\Users\dev\AppData\Local\Temp\emscripten_temp_9zhlxuw5\egRendererBaseGLES3_1.o: undefined symbol: glGetProgramResourceiv

\Users\dev\AppData\Local\Temp\emscripten_temp_9zhlxuw5\egRendererBaseGLES3_1.o: undefined symbol: glDispatchCompute

This is my batch file, which is based on the one above which compiled fine using GL2.

REM@echo off @echo %* call C:\emsdk\emsdk_env.bat set PATH=C:\emsdk\python\3.9.2-nuget_64bit;%PATH%

set ENG=C:\Horde3D-master\Horde3D\Source\Horde3DEngine\ set UTL=C:\Horde3D-master\Horde3D\Source\Horde3DUtils\ set TEXT=C:\Horde3D-master\Extensions\ExternalTexture\Source\ set OVER=C:\Horde3D-master\Extensions\Overlays\Source\ set TERR=C:\Horde3D-master\Extensions\Terrain\Source\ set SHAR=C:\Horde3D-master\Horde3D\Source\Shared\ set H3D=C:\Horde3D-master\Horde3D\Bindings\C++\ set SDL2=C:\emsdk\upstream\emscripten\cache\sysroot\include\ REM C:\emsdk\upstream\emscripten\cache\ports\ set Y3D_INC=./includes/

CLS echo %H3D% echo %ENG% echo %UTL% echo %TEXT% echo %OVER% echo %TERR% echo %SHAR% echo %SDL2% echo %Y3D_INC%

rm -f %ENG%config.h rm -f index.*

emcc -fmax-errors=5 -w ^ -I. ^ -I%H3D% ^ -I%ENG% ^ -I%TEXT% ^ -I%OVER% ^ -I%TERR% ^ -I%SHAR% ^ -I%SDL2% ^ -I%Y3D_INC% ^ %ENG%utOpenGLES3.cpp ^ %ENG%egRendererBaseGLES3.cpp ^ %ENG%egAnimatables.cpp ^ %ENG%egAnimation.cpp ^ %ENG%egCamera.cpp ^ %ENG%egCom.cpp ^ %ENG%egComputeBuffer.cpp ^ %ENG%egComputeNode.cpp ^ %ENG%egExtensions.cpp ^ %ENG%egGeometry.cpp ^ %ENG%egLight.cpp ^ %ENG%egMain.cpp ^ %ENG%egMaterial.cpp ^ %ENG%egModel.cpp ^ %ENG%egModules.cpp ^ %ENG%egParticle.cpp ^ %ENG%egPipeline.cpp ^ %ENG%egPrimitives.cpp ^ %ENG%egRenderer.cpp ^ %ENG%egResource.cpp ^ %ENG%egScene.cpp ^ %ENG%egSceneGraphRes.cpp ^ %ENG%egShader.cpp ^ %ENG%egTexture.cpp ^ %ENG%utImage.cpp ^ %TEXT%extension.cpp ^ %TEXT%egTextureEx.cpp ^ %OVER%extension.cpp ^ %OVER%overlays.cpp ^ %TERR%extension.cpp ^ %TERR%terrain.cpp ^ %UTL%main.cpp ^ Y3D_PC.c ^ Y3D_API.c ^ game.c -DGLES_3 -DH3D_USE_GLES3 ^ -s USE_SDL=2 -s FULL_ES3=1 -sMIN_WEBGL_VERSION=3 -sMAX_WEBGL_VERSION=3 ^ -s ALLOW_MEMORY_GROWTH=1 ^ --preload-file Content ^ -o index.html

I'm not sure how or where these function are created. Any ideas on what to try next?

algts commented 3 months ago

Hello. These functions are used in egRendererBaseGLES3.cpp. You can put them under emscripten platform define to disable them (you may have to create another define in utPlatform.h and in cmake files so that it works correctly). It seems that some functions are missing from WebGL, although there is a project like this (https://github.com/9ballsyndrome/WebGL_Compute_shader/tree/master) that show that compute in webgl should work.

algts commented 2 weeks ago

@gwald Please take a look at newly merged functionality for emscripten (in develop branch).

gwald commented 2 weeks ago

Hey that's pretty cool :+1:

I tried getting it to work for half a day... but the cmake file isn't fully correct and I wasn't able to build it.

call C:\emsdk\emsdk_env.bat set PATH=C:\emsdk\upstream\bin;C:\emsdk\python\3.9.2-nuget_64bit;%PATH% emcmake cmake .. -G "MinGW Makefiles" -DHORDE3D_BUILD_EXAMPLES=ON -DHORDE3D_USE_GLFW=OFF -DHORDE3D_USE_SDL=ON -DHORDE3D_FORCE_DOWNLOAD_SDL=OFF -DCMAKE_MAKE_PROGRAM=make

It failed for me building the SDL framwork on win10. This the cmake file that helped me to get up to that... needs more testing!

``

cmake_minimum_required(VERSION 3.14) # Native support for Android in CMAKE requires at least version 3.7.

# Project details.
project(Horde3D)

set(CMAKE_CXX_STANDARD 14)

SET(${PROJECT_NAME}_MAJOR_VERSION 2)
SET(${PROJECT_NAME}_MINOR_VERSION 1)
SET(${PROJECT_NAME}_PATCH_LEVEL 0)

# Add local repository for FindXXX.cmake modules.
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/BuildTools/CMake/Modules" ${CMAKE_MODULE_PATH})

# Check for strncpy_s function.
include(CheckFunctionExists)
check_function_exists(strncpy_s HAVE_STRNCPY_S)

# To build or not to build examples (removes GLFW or SDL dependency)
option(HORDE3D_BUILD_EXAMPLES "Builds Horde3D examples" ON)

# Specifies whether to build tests
option(HORDE3D_BUILD_TESTS "Build Horde3D unit and integration tests" OFF)

# Check the required windowing backend
if(HORDE3D_BUILD_EXAMPLES)
    include(CMakeDependentOption)
    # We can use SDL or GLFW

    # SDL is the only choice for IOS and Android
    if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows" OR 
       ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
        option(HORDE3D_USE_SDL "Use SDL for window creation/event handling" OFF)
        option(HORDE3D_USE_GLFW "Use GLFW for window creation/event handling" ON)
    else()
        # IOS and android are not supported by glfw   
        option(HORDE3D_USE_SDL "Use SDL for window creation/event handling" ON)
    endif()

    if(HORDE3D_USE_GLFW)
        # Look for required GLFW library.
        option(HORDE3D_FORCE_DOWNLOAD_GLFW "Force linking Horde3D to a downloaded version of GLFW" OFF)
        find_package(GLFW)
        IF(GLFW_FOUND)
            include_directories(${GLFW_INCLUDE_DIR})
        ENDIF(GLFW_FOUND)
    endif()

    if(HORDE3D_USE_SDL)
        # Look for required SDL library.
        option(HORDE3D_FORCE_DOWNLOAD_SDL "Force linking Horde3D to a downloaded version of SDL" OFF)

        IF( ${CMAKE_SYSTEM_NAME} MATCHES "iOS" )
            set( HORDE3D_FORCE_DOWNLOAD_SDL OFF )
        endif()

        IF( ${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten" )
           add_definitions( "-sUSE_SDL" ) # With this flag emscripten itself will handle the rest, including include-directories and linking
            add_link_options( "-sUSE_SDL" )
            set(SDL2_FOUND TRUE)
        ELSE()
            find_package(SDL2)
        ENDIF()

        IF(SDL2_FOUND)
            include_directories(${SDL2_INCLUDE_DIR})
        ENDIF(SDL2_FOUND)
    endif()

        # Only one library can be used, so disable the other one
    if(GLFW_FOUND)
        set(HORDE3D_USE_SDL OFF CACHE BOOL "Use SDL for window creation/event handling" FORCE)
    elseif(SDL_FOUND)
        set(HORDE3D_USE_GLFW OFF CACHE BOOL "Use GLFW for window creation/event handling" FORCE)
    endif()
else()
    message("Not building examples.")
endif(HORDE3D_BUILD_EXAMPLES)

# Render backend selection defaults
option(HORDE3D_USE_GL2 "Add OpenGL 2 render backend. Turns off ES3 render backend." ON)
option(HORDE3D_USE_GL4 "Add OpenGL 4 render backend. Turns off ES3 render backend." ON)
option(HORDE3D_USE_GLES3 "Add OpenGL ES 3 render backend. Turns off desktop GL backends." OFF)
option(HORDE3D_USE_NULL "Add Null render backend. Used for testing. Can work with other render backends." OFF)

if(HORDE3D_USE_NULL)
    set(USE_NULL TRUE)
endif(HORDE3D_USE_NULL)

# Tests always enable Null render backend
if(HORDE3D_BUILD_TESTS)
    set(USE_NULL TRUE)
endif(HORDE3D_BUILD_TESTS)

# Set binaries output folder.
SET(HORDE3D_OUTPUT_PATH_PREFIX "${PROJECT_BINARY_DIR}/Binaries")
SET(HORDE3D_OUTPUT_PATH_SUFFIX "")
IF(${CMAKE_CFG_INTDIR} STREQUAL ".")
    SET(HORDE3D_OUTPUT_PATH_SUFFIX ${CMAKE_BUILD_TYPE})
    IF(NOT HORDE3D_OUTPUT_PATH_SUFFIX)
        SET(HORDE3D_OUTPUT_PATH_SUFFIX "Release")
    ENDIF(NOT HORDE3D_OUTPUT_PATH_SUFFIX)
ENDIF(${CMAKE_CFG_INTDIR} STREQUAL ".")

SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${HORDE3D_OUTPUT_PATH_PREFIX}/${CMAKE_SYSTEM_NAME}/${HORDE3D_OUTPUT_PATH_SUFFIX} CACHE STRING "Where binaries and shared lib files go" FORCE)

IF( ${CMAKE_SYSTEM_NAME} STREQUAL "Android" )
    # Copy android project into build directory
    SET(HORDE3D_ANDROID_PROJECT_PATH "${PROJECT_SOURCE_DIR}/BuildTools/android")

    # For Linux we have to set ANDROID_SDK_ROOT variable
    set(ANDROID_SDK_ROOT_PATH "" CACHE STRING "Path to Android SDK")

    # Set rendering interface to GLES3
    set(USE_GLES3 TRUE)
    set(HORDE3D_USE_GL2 OFF CACHE BOOL "Add OpenGL 2 render backend. Turns off ES3 render backend." FORCE)
    set(HORDE3D_USE_GL4 OFF CACHE BOOL "Add OpenGL 4 render backend. Turns off ES3 render backend." FORCE)

    # On Linux set gradlew to be executable (a bit of a hack)
    if( ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux" )
        execute_process( COMMAND chmod "+x" "${PROJECT_SOURCE_DIR}/BuildTools/android/gradlew" )
    endif()
#     file(COPY "BuildTools/android" DESTINATION ${HORDE3D_OUTPUT_PATH_PREFIX}/${CMAKE_SYSTEM_NAME}) 
#     set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${HORDE3D_OUTPUT_PATH_PREFIX}/${CMAKE_SYSTEM_NAME}/android/app/src/main/jniLibs/${ANDROID_ABI} )
ENDIF()

IF( ${CMAKE_SYSTEM_NAME} MATCHES "iOS" )
    include( "ios" )

    SET(HORDE3D_IOS_TOOLS_PATH "${PROJECT_SOURCE_DIR}/BuildTools/ios")

    set(IOS_CODE_SIGN_IDENTITY "Apple Development" CACHE STRING "Code sign (used for application signing)")
    set(IOS_DEVELOPMENT_TEAM "" CACHE STRING "Development team id (used for application signing)")

    # Set rendering interface to GLES3
    set(USE_GLES3 TRUE)
    set(HORDE3D_USE_GL2 OFF CACHE BOOL "Add OpenGL 2 render backend. Turns off ES3 render backend." FORCE)
    set(HORDE3D_USE_GL4 OFF CACHE BOOL "Add OpenGL 4 render backend. Turns off ES3 render backend." FORCE)
    set(HORDE3D_USE_GLES3 ON CACHE BOOL "Add OpenGL ES 3 render backend. Turns off desktop GL backends." FORCE)
ENDIF()

if( ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten" )
    # WebGL Only support OpenGL ES
    set(HORDE3D_EMSCRIPTEN_STACK_SIZE 524288 CACHE STRING "emscripten stack size (-sSTACKSIZE=...)")
    if(NOT HORDE3D_EMSCRIPTEN_STACK_SIZE)
        set(HORDE3D_EMSCRIPTEN_STACK_SIZE 524288)
    endif()

    set(USE_GLES3 TRUE)
    set(HORDE3D_USE_GL2 OFF CACHE BOOL "Add OpenGL 2 render backend. Turns off ES3 render backend." FORCE)
    set(HORDE3D_USE_GL4 OFF CACHE BOOL "Add OpenGL 4 render backend. Turns off ES3 render backend." FORCE)
    set(HORDE3D_USE_GLES3 ON CACHE BOOL "Add OpenGL ES 3 render backend. Turns off desktop GL backends." FORCE)

    set(CMAKE_EXECUTABLE_SUFFIX ".html")

    add_link_options( -sFULL_ES3 )
    add_link_options( -sSTACK_SIZE=${HORDE3D_EMSCRIPTEN_STACK_SIZE} )
 add_definitions( "-sUSE_SDL" ) # With this flag emscripten itself will handle the rest, including include-directories and linking
            add_link_options( "-sUSE_SDL" )
            set(SDL2_FOUND TRUE)
    if(HORDE3D_BUILD_EXAMPLES)
        set (SAMPLE_HORDE3D_EMSCRIPTEN_CONTENT_FOLDER "${HORDE3D_OUTPUT_PATH_PREFIX}/Content")
    endif(HORDE3D_BUILD_EXAMPLES)
endif()

IF(MSVC)
    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:mainCRTStartup ")
    add_definitions(-D_CRT_SECURE_NO_WARNINGS)
ENDIF(MSVC)

# Render backend selection
if(HORDE3D_USE_GLES3)
    set(USE_GLES3 TRUE)
    set(HORDE3D_USE_GL2 OFF CACHE BOOL "Add OpenGL 2 render backend. Turns off ES3 render backend." FORCE)
    set(HORDE3D_USE_GL4 OFF CACHE BOOL "Add OpenGL 4 render backend. Turns off ES3 render backend." FORCE)
endif(HORDE3D_USE_GLES3)

if(HORDE3D_USE_GL2 OR HORDE3D_USE_GL4)
    if(HORDE3D_USE_GL2)
        set(USE_GL2 TRUE)
    endif(HORDE3D_USE_GL2)

    if(HORDE3D_USE_GL4)
        set(USE_GL4 TRUE)
    endif(HORDE3D_USE_GL4)

    set(HORDE3D_USE_GLES3 OFF CACHE BOOL "Add OpenGL ES 3 render backend. Turns off desktop GL backends." FORCE)
endif(HORDE3D_USE_GL2 OR HORDE3D_USE_GL4)

if (NOT HORDE3D_USE_GL2 AND NOT HORDE3D_USE_GL4 AND NOT HORDE3D_USE_GLES3 )
    message( SEND_ERROR "Rendering backend is not selected!")
endif()

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG" )

# Manage extensions.
include(Extensions/Extensions.txt)

# Add engine target.
add_subdirectory(Horde3D)

option(HORDE3D_BUILD_EDITOR "Build Horde3D Editor" OFF)
if(HORDE3D_BUILD_EDITOR)
  add_subdirectory(Horde3DEditor)
endif(HORDE3D_BUILD_EDITOR)

if(POLICY CMP0058)
    cmake_policy(SET CMP0058 NEW)
endif()
algts commented 2 weeks ago

@JesseVanDis Did you try building for emcsripten on Windows?

JesseVanDis commented 2 weeks ago

SDL Should not be build actually. Emscripten has it build-in. So I wonder why it decides to build that. I will see later today if I can reproduce that issue using your steps

JesseVanDis commented 2 weeks ago

Following your steps from call C:\emsdk\emsdk_env.bat to emcmake... ( assuming later you did emmake make ) works for me, On windows 11.

However: As soon as I copy-pasted your CMakeLists.txt over the current one, I get the same error about SDL Framework not building. When I did a git diff, I notice you changed "--use-port=sdl2" to "-sUSE_SDL" ( which assumes SDL1 )

This is why it has issues building with SDL(2)

Also note that "--use-port=sdl2" is the recommended way of adding SDL2 to your emscripten project. as -sUSE_SDL has been depricated

In short: In order to fix the build issues you are having, change all '-sUSE_SDL' to '--use-port=sdl2' in your CMakeLists.txt files


Lastly, not that it effects anything, but it is maybe usefull information still: The following is actually enough to build the examples

call C:\emsdk\emsdk_env.bat
emcmake cmake -G "MinGW Makefiles" -DHORDE3D_BUILD_EXAMPLES=ON ..
emmake make 
gwald commented 2 weeks ago

Thanks for the tips!

I dont know why but '--use-port=sdl2' didn't work for me, I had to replace them with '-sUSE_SDL=2'

emsdk_env.bat is:
call C:\emsdk\emsdk_env.bat
set PATH=C:\emsdk\upstream\bin;C:\emsdk\python\3.9.2-nuget_64bit;%PATH%
rm -rf bin
mkdir bin
cd bin
call emcmake cmake -G "MinGW Makefiles"  -DHORDE3D_BUILD_EXAMPLES=ON ..
call emmake make 

C:\emsdk\Horde3D-develop>call C:\emsdk\emsdk_env.bat
Setting up EMSDK environment (suppress these messages with EMSDK_QUIET=1)
Setting environment variables:
PATH = C:\emsdk;C:\emsdk\upstream\emscripten;C:\emsdk\node\16.20.0_64bit\bin;C:\psx3\bin;C:\psx3\sbin;C:\w64devkit\bin;C
:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\extras;C:\emulator
s\NOPSX;C:\emulators\NOPSX\tiny;C:\tcc;C:\extras\assimp;C:\extras\7-Zip;C:\extras\NotePad++;C:\eclipse\plugins\org.eclip
se.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.9.v20231028-0858\jre\bin;C:\psx3\sbin\UnxUtils;C:\psx3\sbin\yariso;C
:\PSX\PSX\BIN;C:\extras\DOSBox;C:\Program Files\Git\cmd;C:\Users\dev\AppData\Local\Microsoft\WindowsApps;C:\Users\dev\Ap
pData\Local\Programs\Microsoft VS Code\bin;C:\Users\dev\AppData\Roaming\mips;C:\Users\dev\AppData\Roaming\mips\mips\bin;
C:\extras\remedybg;C:\PSX\GNU\BIN;C:\extras\CMake\bin
Clearing existing environment variable: EMSDK_PY
rm: can't remove 'bin/Binaries/Emscripten/Release': Permission denied
A subdirectory or file bin already exists.
configure: cmake -G "MinGW Makefiles" -DHORDE3D_BUILD_EXAMPLES=ON .. -DCMAKE_TOOLCHAIN_FILE=C:\emsdk\upstream\emscripten
\cmake\Modules\Platform\Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=node
-- Looking for strncpy_s
-- Looking for strncpy_s - not found
-- Configuring done (1.5s)
-- Generating done (0.1s)
-- Build files have been written to: C:/emsdk/Horde3D-develop/bin
make: C:\w64devkit\bin\mingw32-make.EXE
[  2%] Building CXX object Extensions/Overlays/Source/CMakeFiles/Horde3DOverlays.dir/extension.cpp.o
clang++: error: unknown argument: '--use-port=sdl2'
em++: error: 'C:\emsdk\upstream\bin\clang++.exe -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=defau
lt -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --sysroot=C:\emsdk\up
stream\emscripten\cache\sysroot -DEMSCRIPTEN -Xclang -iwithsysroot/include\fakesdl -Xclang -iwithsysroot/include\compat
-IC:/emsdk/Horde3D-develop/Horde3D/Source/Horde3DEngine -IC:/emsdk/Horde3D-develop/Horde3D/Source/Shared -IC:/emsdk/Hord
e3D-develop/bin -std=gnu++14 --use-port=sdl2 -MD -MT Extensions/Overlays/Source/CMakeFiles/Horde3DOverlays.dir/extension
.cpp.o -MF CMakeFiles\Horde3DOverlays.dir\extension.cpp.o.d -c C:\emsdk\Horde3D-develop\Extensions\Overlays\Source\exten
sion.cpp -o CMakeFiles\Horde3DOverlays.dir\extension.cpp.o' failed (returned 1)
Extensions\Overlays\Source\CMakeFiles\Horde3DOverlays.dir\build.make:75: recipe for target 'Extensions/Overlays/Source/C
MakeFiles/Horde3DOverlays.dir/extension.cpp.o' failed
make[2]: *** [Extensions/Overlays/Source/CMakeFiles/Horde3DOverlays.dir/extension.cpp.o] Error 1
CMakeFiles\Makefile2:468: recipe for target 'Extensions/Overlays/Source/CMakeFiles/Horde3DOverlays.dir/all' failed
make[1]: *** [Extensions/Overlays/Source/CMakeFiles/Horde3DOverlays.dir/all] Error 2
make: *** [Makefile:90: all] Error 2
emmake: error: 'C:\w64devkit\bin\mingw32-make.EXE' failed (returned 2)

C:\emsdk\Horde3D-develop\bin>

It's beautiful :) :+1: :heart_eyes: image Terrain was a black screen also for me.

And the knight's skin looks like it failed for me... I'm running win10 in a VMware VM.

image

[h3d] Initializing GLES3 backend using OpenGL ES driver 'OpenGL ES 3.0 (WebGL 2.0 (OpenGL ES 3.0 Chromium))' by 'WebKit' on 'WebKit WebGL'
  [h3d-warn] Extension EXT_texture_compression_s3tc not supported
  [h3d-warn] Extension EXT_disjoint_timer_query not supported
  [h3d-warn] Extension EXT_texture_border_clamp not supported
  [h3d-warn] Extension EXT_geometry_shader not supported
[h3d] Loading resource 'pipelines/forward.pipeline.xml'
[h3d] Loading resource 'pipelines/deferred.pipeline.particles.xml'
[h3d] Loading resource 'pipelines/hdr.pipeline.xml'
[h3d] Loading resource 'overlays/font.material.xml'

Which does run fine... image

Thanks again, very cool! thanks for sharing :)

gwald commented 2 weeks ago

I just saw your link to depricated Since emscripten 3.1.54, --use-port is the preferred syntax to use a port in your project. The legacy syntax (for example -sUSE_SDL2, -sUSE_SDL_IMAGE=2) remains available.

I need to update my emscripten! Cool, no problems then. I guess this can get closed now :+1:

algts commented 2 weeks ago

Seems to be fixed. Reopen if needed.