From 70363e08196fe2603c447fb9fa49a38730b5f02f Mon Sep 17 00:00:00 2001 From: cutealien Date: Mon, 23 Oct 2017 22:03:18 +0000 Subject: [PATCH] Evaluate more device creation parameters in emscripten. We can now use hardware antialiasing in emscripten. Print some info about used SDL flags to log. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@5551 dfc29bdd-3216-0410-991c-e03cc46cb475 --- examples/01.HelloWorld_emscripten/main.cpp | 11 +++-- source/Irrlicht/CIrrDeviceSDL.cpp | 50 ++++++++++++++++++++++ source/Irrlicht/CIrrDeviceSDL.h | 2 + 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/examples/01.HelloWorld_emscripten/main.cpp b/examples/01.HelloWorld_emscripten/main.cpp index 232d7254..8fa5c020 100644 --- a/examples/01.HelloWorld_emscripten/main.cpp +++ b/examples/01.HelloWorld_emscripten/main.cpp @@ -103,6 +103,7 @@ void one_iter() */ int main() { + SIrrlichtCreationParameters parameters; /* Create device flags for emscripten are still experimental and might not all work. @@ -112,12 +113,16 @@ int main() EDT_OGLES2 needs -s FULL_ES2=1 as linker flag in the Makefile. */ #ifndef __EMSCRIPTEN__ - video::E_DRIVER_TYPE deviceType = EDT_OGLES2; + parameters.DriverType = EDT_OGLES2; #else //__EMSCRIPTEN__ - video::E_DRIVER_TYPE deviceType = EDT_WEBGL1; + parameters.DriverType = EDT_WEBGL1; #endif //__EMSCRIPTEN__ - device = createDevice(deviceType, screenSize, 16, false, false, false, 0); + parameters.WindowSize = screenSize; + parameters.Stencilbuffer = false; + parameters.AntiAlias = 4; + + device = createDeviceEx(parameters); if (!device) return 1; diff --git a/source/Irrlicht/CIrrDeviceSDL.cpp b/source/Irrlicht/CIrrDeviceSDL.cpp index ac230f55..d81506f4 100644 --- a/source/Irrlicht/CIrrDeviceSDL.cpp +++ b/source/Irrlicht/CIrrDeviceSDL.cpp @@ -273,6 +273,32 @@ CIrrDeviceSDL::~CIrrDeviceSDL() SDL_Quit(); } +void CIrrDeviceSDL::logAttributes() +{ + core::stringc sdl_attr("SDL attribs:"); + int value = 0; + if ( SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value ) == 0 ) + sdl_attr += core::stringc(" r:") + core::stringc(value); + if ( SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value ) == 0 ) + sdl_attr += core::stringc(" g:") + core::stringc(value); + if ( SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value ) == 0 ) + sdl_attr += core::stringc(" b:") + core::stringc(value); + if ( SDL_GL_GetAttribute( SDL_GL_ALPHA_SIZE, &value ) == 0 ) + sdl_attr += core::stringc(" a:") + core::stringc(value); + + if ( SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value) == 0 ) + sdl_attr += core::stringc(" depth:") + core::stringc(value); + if ( SDL_GL_GetAttribute( SDL_GL_STENCIL_SIZE, &value ) == 0 ) + sdl_attr += core::stringc(" stencil:") + core::stringc(value); + if ( SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value ) == 0 ) + sdl_attr += core::stringc(" doublebuf:") + core::stringc(value); + if ( SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &value ) == 0 ) + sdl_attr += core::stringc(" aa:") + core::stringc(value); + if ( SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &value ) == 0 ) + sdl_attr += core::stringc(" aa-samples:") + core::stringc(value); + + os::Printer::log(sdl_attr.c_str()); +} bool CIrrDeviceSDL::createWindow() { @@ -286,8 +312,31 @@ bool CIrrDeviceSDL::createWindow() Width = w; Height = h; } + + SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 ); + SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 ); + SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 ); + SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel?8:0 ); + + SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, CreationParams.ZBufferBits); + SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, CreationParams.Stencilbuffer ? 8 : 0); + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, CreationParams.Doublebuffer ? 1 : 0); + + if (CreationParams.AntiAlias>1) + { + SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 ); + SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias ); + } + else + { + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); + } + Screen = SDL_SetVideoMode( 0, 0, 32, SDL_Flags); // 0,0 will use the canvas size + logAttributes(); + // "#canvas" is for the opengl context emscripten_set_mousedown_callback("#canvas", (void*)this, true, MouseUpDownCallback); emscripten_set_mouseup_callback("#canvas", (void*)this, true, MouseUpDownCallback); @@ -318,6 +367,7 @@ bool CIrrDeviceSDL::createWindow() SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, CreationParams.ZBufferBits); if (CreationParams.Doublebuffer) SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); + SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, CreationParams.Stencilbuffer ? 8 : 0); if (CreationParams.Stereobuffer) SDL_GL_SetAttribute( SDL_GL_STEREO, 1 ); if (CreationParams.AntiAlias>1) diff --git a/source/Irrlicht/CIrrDeviceSDL.h b/source/Irrlicht/CIrrDeviceSDL.h index 25a61e49..2a29c769 100644 --- a/source/Irrlicht/CIrrDeviceSDL.h +++ b/source/Irrlicht/CIrrDeviceSDL.h @@ -233,6 +233,8 @@ namespace irr void createKeyMap(); + void logAttributes(); + SDL_Surface* Screen; int SDL_Flags; #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)