Updating project to run with latest Emscripten

This commit is contained in:
Noel 2022-07-30 16:30:13 -07:00
parent f68e4cd8ed
commit e581065bbb
3 changed files with 54 additions and 23 deletions

View File

@ -67,6 +67,7 @@ if (BLAH_PLATFORM_SDL2)
if (EMSCRIPTEN) if (EMSCRIPTEN)
set_target_properties(blah PROPERTIES COMPILE_FLAGS "-s USE_SDL=2") set_target_properties(blah PROPERTIES COMPILE_FLAGS "-s USE_SDL=2")
target_link_libraries(blah "-s USE_SDL=2 -s USE_WEBGL2=1")
# Pull SDL2 from its Github repo # Pull SDL2 from its Github repo
else() else()
@ -106,3 +107,4 @@ endif()
if (BLAH_NO_SHARED_PTR) if (BLAH_NO_SHARED_PTR)
add_compile_definitions(BLAH_NO_SHARED_PTR) add_compile_definitions(BLAH_NO_SHARED_PTR)
endif() endif()

View File

@ -141,7 +141,11 @@ bool SDL2_Platform::init(const Config& config)
// TODO: // TODO:
// control this via some kind of config flag // control this via some kind of config flag
#ifndef __EMSCRIPTEN__
// Note: Emscripten gets a Stack Overflow if this is assigned to Verbose, even when
// increasing the node stack size to +8mb. Some kind of SDL2 problem?
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE); SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE);
#endif
SDL_LogSetOutputFunction(blah_sdl_log, nullptr); SDL_LogSetOutputFunction(blah_sdl_log, nullptr);
// Get SDL version // Get SDL version
@ -164,6 +168,7 @@ bool SDL2_Platform::init(const Config& config)
flags |= SDL_WINDOW_OPENGL; flags |= SDL_WINDOW_OPENGL;
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#else #else
@ -731,3 +736,4 @@ Platform* Platform::try_make_platform(const Config& config)
} }
#endif // BLAH_PLATFORM_SDL2 #endif // BLAH_PLATFORM_SDL2

View File

@ -793,21 +793,32 @@ namespace Blah
virtual void clear(Color color, float depth, u8 stencil, ClearMask mask) override virtual void clear(Color color, float depth, u8 stencil, ClearMask mask) override
{ {
renderer->gl.BindFramebuffer(GL_FRAMEBUFFER, m_id);
renderer->gl.Disable(GL_SCISSOR_TEST);
int clear = 0; int clear = 0;
if (((int)mask & (int)ClearMask::Color) == (int)ClearMask::Color) if (((int)mask & (int)ClearMask::Color) == (int)ClearMask::Color)
{
clear |= GL_COLOR_BUFFER_BIT; clear |= GL_COLOR_BUFFER_BIT;
if (((int)mask & (int)ClearMask::Depth) == (int)ClearMask::Depth)
clear |= GL_DEPTH_BUFFER_BIT;
if (((int)mask & (int)ClearMask::Stencil) == (int)ClearMask::Stencil)
clear |= GL_STENCIL_BUFFER_BIT;
renderer->gl.BindFramebuffer(GL_FRAMEBUFFER, m_id);
renderer->gl.Disable(GL_SCISSOR_TEST);
renderer->gl.ColorMask(true, true, true, true); renderer->gl.ColorMask(true, true, true, true);
renderer->gl.ClearColor(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f); renderer->gl.ClearColor(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f);
}
if (((int)mask & (int)ClearMask::Depth) == (int)ClearMask::Depth)
{
clear |= GL_DEPTH_BUFFER_BIT;
if (renderer->gl.ClearDepth)
renderer->gl.ClearDepth(depth); renderer->gl.ClearDepth(depth);
}
if (((int)mask & (int)ClearMask::Stencil) == (int)ClearMask::Stencil)
{
clear |= GL_STENCIL_BUFFER_BIT;
if (renderer->gl.ClearStencil)
renderer->gl.ClearStencil(stencil); renderer->gl.ClearStencil(stencil);
}
renderer->gl.Clear(clear); renderer->gl.Clear(clear);
} }
}; };
@ -1535,21 +1546,32 @@ namespace Blah
void Renderer_OpenGL::clear_backbuffer(Color color, float depth, u8 stencil, ClearMask mask) void Renderer_OpenGL::clear_backbuffer(Color color, float depth, u8 stencil, ClearMask mask)
{ {
renderer->gl.BindFramebuffer(GL_FRAMEBUFFER, 0);
renderer->gl.Disable(GL_SCISSOR_TEST);
int clear = 0; int clear = 0;
if (((int)mask & (int)ClearMask::Color) == (int)ClearMask::Color) if (((int)mask & (int)ClearMask::Color) == (int)ClearMask::Color)
{
clear |= GL_COLOR_BUFFER_BIT; clear |= GL_COLOR_BUFFER_BIT;
if (((int)mask & (int)ClearMask::Depth) == (int)ClearMask::Depth)
clear |= GL_DEPTH_BUFFER_BIT;
if (((int)mask & (int)ClearMask::Stencil) == (int)ClearMask::Stencil)
clear |= GL_STENCIL_BUFFER_BIT;
renderer->gl.BindFramebuffer(GL_FRAMEBUFFER, 0);
renderer->gl.Disable(GL_SCISSOR_TEST);
renderer->gl.ColorMask(true, true, true, true); renderer->gl.ColorMask(true, true, true, true);
renderer->gl.ClearColor(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f); renderer->gl.ClearColor(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f);
}
if (((int)mask & (int)ClearMask::Depth) == (int)ClearMask::Depth)
{
clear |= GL_DEPTH_BUFFER_BIT;
if (renderer->gl.ClearDepth)
renderer->gl.ClearDepth(depth); renderer->gl.ClearDepth(depth);
}
if (((int)mask & (int)ClearMask::Stencil) == (int)ClearMask::Stencil)
{
clear |= GL_STENCIL_BUFFER_BIT;
if (renderer->gl.ClearStencil)
renderer->gl.ClearStencil(stencil); renderer->gl.ClearStencil(stencil);
}
renderer->gl.Clear(clear); renderer->gl.Clear(clear);
} }
} }
@ -1569,3 +1591,4 @@ Blah::Renderer* Blah::Renderer::try_make_opengl()
#endif #endif