Skip to content

Commit

Permalink
Fix bad rendering in Emscripten, add sample assets as link dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke89 committed Mar 26, 2024
1 parent e96b950 commit c93dbc0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
8 changes: 7 additions & 1 deletion Backends/RmlUi_Renderer_GL3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,13 @@ void RenderInterface_GL3::SetScissor(Rml::Rectanglei region, bool vertically_fli
region = VerticallyFlipped(region, viewport_height);

if (region.Valid() && region != scissor_state)
glScissor(region.Left(), viewport_height - region.Bottom(), region.Width(), region.Height());
{
// Some render APIs don't like offscreen positions (WebGL in particular), so clamp them to the viewport.
const int x = Rml::Math::Clamp(region.Left(), 0, viewport_width);
const int y = Rml::Math::Clamp(viewport_height - region.Bottom(), 0, viewport_height);

glScissor(x, y, region.Width(), region.Height());
}

Gfx::CheckGLError("SetScissorRegion");
scissor_state = region;
Expand Down
15 changes: 11 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ if(BUILD_SAMPLES OR BUILD_TESTING)
if(SAMPLES_BACKEND MATCHES "GL3$")
message("-- Adding OpenGL 3 renderer backend.")
if(EMSCRIPTEN)
set(EMSCRIPTEN_EXE_FLAGS "${EMSCRIPTEN_EXE_FLAGS} -sMAX_WEBGL_VERSION=2")
set(EMSCRIPTEN_EXE_FLAGS "${EMSCRIPTEN_EXE_FLAGS} -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2")
else()
find_package(OpenGL REQUIRED)
target_include_directories(shell PRIVATE ${OPENGL_INCLUDE_DIR})
Expand Down Expand Up @@ -867,17 +867,20 @@ if(BUILD_SAMPLES)

# Add assets to emscripten binaries
if(EMSCRIPTEN)
message("-- Preloading emscipten sample assets")
message("-- Preloading emscripten sample assets")

set(COMMON_ASSET_FOLDER "Samples/assets/")
set(EMSCRIPTEN_EXE_FLAGS "${EMSCRIPTEN_EXE_FLAGS} --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/${COMMON_ASSET_FOLDER}@/${COMMON_ASSET_FOLDER}")
file(GLOB COMMON_ASSET_FILES "${COMMON_ASSET_FOLDER}*")

foreach(sample ${samples})
set(SAMPLE_DATA_FOLDER "Samples/basic/${sample}/data/")
set(ABS_SAMPLE_DATA_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/${SAMPLE_DATA_FOLDER}")
if(EXISTS ${ABS_SAMPLE_DATA_FOLDER})
target_link_libraries(${sample} "--preload-file ${ABS_SAMPLE_DATA_FOLDER}@/${SAMPLE_DATA_FOLDER}")
endif()
file(GLOB SAMPLE_DATA_FILES "${SAMPLE_DATA_FOLDER}*")
set_target_properties(${sample} PROPERTIES LINK_DEPENDS "${COMMON_ASSET_FILES};${SAMPLE_DATA_FILES}")
endforeach()

foreach(tutorial ${tutorials})
Expand All @@ -886,10 +889,14 @@ if(BUILD_SAMPLES)
if(EXISTS ${ABS_TUTORIAL_DATA_FOLDER})
target_link_libraries("tutorial_${tutorial}" "--preload-file ${ABS_TUTORIAL_DATA_FOLDER}@/${TUTORIAL_DATA_FOLDER}")
endif()
file(GLOB TUTORIAL_DATA_FILES "${TUTORIAL_DATA_FOLDER}*")
set_target_properties(${sample} PROPERTIES LINK_DEPENDS "${COMMON_ASSET_FILES};${TUTORIAL_DATA_FILES}")
endforeach()

set(INVADER_DATA_FOLDER "Samples/invaders/data/")
target_link_libraries(invaders "-sALLOW_MEMORY_GROWTH --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/${INVADER_DATA_FOLDER}@/${INVADER_DATA_FOLDER}")
set(INVADERS_DATA_FOLDER "Samples/invaders/data/")
target_link_libraries(invaders "-sALLOW_MEMORY_GROWTH --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/${INVADERS_DATA_FOLDER}@/${INVADERS_DATA_FOLDER}")
file(GLOB INVADERS_DATA_FILES "${INVADERS_DATA_FOLDER}*")
set_target_properties(invaders PROPERTIES LINK_DEPENDS "${COMMON_ASSET_FILES};${INVADERS_DATA_FILES}")
endif()
endif()

Expand Down

0 comments on commit c93dbc0

Please sign in to comment.