Skip to content

Commit

Permalink
Adding support for emscripten
Browse files Browse the repository at this point in the history
  • Loading branch information
vstanchevici authored and LukasBanana committed Aug 22, 2024
1 parent 7798c79 commit 8d8760b
Show file tree
Hide file tree
Showing 27 changed files with 1,869 additions and 6 deletions.
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ if(NOT DEFINED LLGL_TARGET_PLATFORM)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
set(LLGL_TARGET_PLATFORM "${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}")
set(LLGL_UWP_PLATFORM ON)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten")
set(LLGL_TARGET_PLATFORM "Emscripten")
elseif(WIN32)
if(LLGL_BUILD_64BIT)
set(LLGL_TARGET_PLATFORM "Win64")
Expand Down Expand Up @@ -408,7 +410,7 @@ option(LLGL_BUILD_EXAMPLES "Include example projects" OFF)
option(LLGL_BUILD_RENDERER_NULL "Include Null renderer project" ON)

if(NOT LLGL_UWP_PLATFORM)
if(LLGL_MOBILE_PLATFORM)
if(LLGL_MOBILE_PLATFORM OR EMSCRIPTEN)
option(LLGL_BUILD_RENDERER_OPENGLES3 "Include OpenGLES 3 renderer project" ON)
else()
option(LLGL_BUILD_RENDERER_OPENGL "Include OpenGL renderer project" ON)
Expand Down Expand Up @@ -483,6 +485,11 @@ else()
set(SUMMARY_TARGET_ARCH "x86")
endif()

if(EMSCRIPTEN)
add_compile_options("SHELL:-s USE_PTHREADS")
add_link_options("SHELL:-s USE_PTHREADS")
endif()


# === Global files ===

Expand Down Expand Up @@ -522,7 +529,10 @@ if(LLGL_ENABLE_DEBUG_LAYER)
find_source_files(FilesRendererDbgTexture CXX "${PROJECT_SOURCE_DIR}/sources/Renderer/DebugLayer/Texture")
endif()

if(WIN32)
if(EMSCRIPTEN)
find_source_files(FilesPlatform CXX "${PROJECT_SOURCE_DIR}/sources/Platform/Emscripten")
find_source_files(FilesIncludePlatform CXX "${PROJECT_INCLUDE_DIR}/LLGL/Platform/Emscripten")
elseif(WIN32)
if(LLGL_UWP_PLATFORM)
find_source_files(FilesPlatform CXX "${PROJECT_SOURCE_DIR}/sources/Platform/UWP")
find_source_files(FilesIncludePlatform CXX "${PROJECT_INCLUDE_DIR}/LLGL/Platform/UWP")
Expand Down Expand Up @@ -679,6 +689,8 @@ elseif(APPLE)
if(LLGL_MACOS_ENABLE_COREVIDEO)
target_link_libraries(LLGL "-framework CoreVideo")
endif()
elseif(EMSCRIPTEN)
###
elseif(UNIX)
target_link_libraries(LLGL X11 pthread Xrandr)
#elseif(LLGL_UWP_PLATFORM)
Expand Down
9 changes: 9 additions & 0 deletions cmake/FindOpenGLES3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ ELSE (WIN32)
findpkg_framework(OpenGLES)
set(OPENGLES_gl_LIBRARY "-framework OpenGLES")

ELSEIF(EMSCRIPTEN)

find_package(OpenGL REQUIRED)
#message(STATUS "OPENGL_INCLUDE_DIR: " ${OPENGL_INCLUDE_DIR})
#message(STATUS "OPENGL_LIBRARIES: " ${OPENGL_LIBRARIES})

SET(OPENGLES_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
SET(OPENGLES_gl_LIBRARY ${OPENGL_LIBRARIES})

ELSE(APPLE)

FIND_PATH(OPENGLES_INCLUDE_DIR GLES3/gl3.h
Expand Down
39 changes: 39 additions & 0 deletions include/LLGL/Backend/OpenGL/Emscripten/EmscriptenNativeHandle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* EmscriptenNativeHandle.h (OpenGL)
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

#ifndef LLGL_OPENGL_EMSCRIPTEN_NATIVE_HANDLE_H
#define LLGL_OPENGL_EMSCRIPTEN_NATIVE_HANDLE_H


namespace LLGL
{

namespace OpenGL
{


/**
\brief Emscripten native handle structure for the OpenGL render system.
\see RenderSystem::GetNativeHandle
\see RenderSystemDescriptor::nativeHandle
*/
struct RenderSystemNativeHandle
{
int context;
};


} // /namespace OpenGL

} // /namespace LLGL


#endif



// ================================================================================
2 changes: 2 additions & 0 deletions include/LLGL/Backend/OpenGL/NativeHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# include <LLGL/Backend/OpenGL/IOS/IOSNativeHandle.h>
#elif defined(LLGL_OS_ANDROID)
# include <LLGL/Backend/OpenGL/Android/AndroidNativeHandle.h>
#elif defined(LLGL_OS_EMSCRIPTEN)
# include <LLGL/Backend/OpenGL/Emscripten/EmscriptenNativeHandle.h>
#endif


Expand Down
32 changes: 32 additions & 0 deletions include/LLGL/Platform/Emscripten/EmscriptenNativeHandle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* LinuxNativeHandle.h
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

#ifndef LLGL_EMSCRIPTEN_NATIVE_HANDLE_H
#define LLGL_EMSCRIPTEN_NATIVE_HANDLE_H

#include <emscripten/val.h>

namespace LLGL
{


//! Emscripten native handle structure.
struct NativeHandle
{
//! HTML canvas object.
emscripten::val canvas;
};


} // /namespace LLGL


#endif



// ================================================================================
2 changes: 2 additions & 0 deletions include/LLGL/Platform/NativeHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# include <LLGL/Platform/MacOS/MacOSNativeHandle.h>
#elif defined(LLGL_OS_LINUX)
# include <LLGL/Platform/Linux/LinuxNativeHandle.h>
#elif defined(LLGL_OS_EMSCRIPTEN)
# include <LLGL/Platform/Emscripten/EmscriptenNativeHandle.h>
#elif defined(LLGL_OS_IOS)
# include <LLGL/Platform/IOS/IOSNativeHandle.h>
#elif defined(LLGL_OS_ANDROID)
Expand Down
2 changes: 2 additions & 0 deletions include/LLGL/Platform/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ see https://sourceforge.net/p/predef/wiki/OperatingSystems/
# endif
#elif defined __ANDROID__ || defined ANDROID
# define LLGL_OS_ANDROID
#elif defined EMSCRIPTEN
# define LLGL_OS_EMSCRIPTEN
#elif defined __linux__
# define LLGL_OS_LINUX
#endif
Expand Down
2 changes: 2 additions & 0 deletions sources/Platform/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# include "MacOS/MacOSDebug.h"
# elif defined(LLGL_OS_LINUX)
# include "Linux/LinuxDebug.h"
# elif defined(LLGL_OS_EMSCRIPTEN)
# include "Emscripten/EmscriptenDebug.h"
# elif defined(LLGL_OS_IOS)
# include "IOS/IOSDebug.h"
# elif defined(LLGL_OS_ANDROID)
Expand Down
26 changes: 26 additions & 0 deletions sources/Platform/Emscripten/EmscriptenDebug.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* LinuxDebug.cpp
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

#include "../Debug.h"
#include <stdio.h>


namespace LLGL
{


LLGL_EXPORT void DebugPuts(const char* text)
{
::fprintf(stderr, "%s\n", text);
}


} // /namespace LLGL



// ================================================================================
25 changes: 25 additions & 0 deletions sources/Platform/Emscripten/EmscriptenDebug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* LinuxDebug.h
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

#ifndef LLGL_EMSCRIPTEN_DEBUG_H
#define LLGL_EMSCRIPTEN_DEBUG_H


#include <signal.h>

#ifdef SIGTRAP
# define LLGL_DEBUG_BREAK() raise(SIGTRAP)
#else
# define LLGL_DEBUG_BREAK()
#endif


#endif



// ================================================================================
Loading

0 comments on commit 8d8760b

Please sign in to comment.