From 0a487f7b9206c201dae0fc8aa325ba3dfe2c7679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 5 Aug 2017 17:46:35 -0300 Subject: [PATCH] Fixed FBOs. Minor fixes for Emscripten and Android. --HG-- branch : dev --- premake4.lua | 4 ++-- src/eepp/graphics/framebuffer.cpp | 2 +- src/eepp/graphics/framebufferfbo.cpp | 25 ++++++++++++---------- src/eepp/graphics/primitives.cpp | 6 +++--- src/eepp/graphics/renderer/renderer.cpp | 2 ++ src/examples/empty_window/empty_window.cpp | 2 +- src/test/eetest.cpp | 7 +++++- 7 files changed, 29 insertions(+), 19 deletions(-) diff --git a/premake4.lua b/premake4.lua index 609a6fa05..28ba6bb94 100644 --- a/premake4.lua +++ b/premake4.lua @@ -441,8 +441,8 @@ function build_link_configuration( package_name, use_ee_icon ) add_cross_config_links() configuration "emscripten" - linkoptions{ "-O1 -s TOTAL_MEMORY=67108864 -s ASM_JS=1 -s VERBOSE=1 -s DISABLE_EXCEPTION_CATCHING=0 -s USE_SDL=2" } - buildoptions { "-fno-strict-aliasing -O2 -ffast-math -s USE_SDL=2" } + linkoptions{ "-O2 -s TOTAL_MEMORY=67108864 -s ASM_JS=1 -s VERBOSE=1 -s DISABLE_EXCEPTION_CATCHING=0 -s USE_SDL=2" } + buildoptions { "-fno-strict-aliasing -O2 -s USE_SDL=2 -s PRECISE_F32=1" } if _OPTIONS["with-gles1"] and ( not _OPTIONS["with-gles2"] or _OPTIONS["force-gles1"] ) then linkoptions{ "-s LEGACY_GL_EMULATION=1" } diff --git a/src/eepp/graphics/framebuffer.cpp b/src/eepp/graphics/framebuffer.cpp index c5993227f..c193d269d 100644 --- a/src/eepp/graphics/framebuffer.cpp +++ b/src/eepp/graphics/framebuffer.cpp @@ -13,7 +13,7 @@ namespace EE { namespace Graphics { FrameBuffer * FrameBuffer::New( const Uint32& Width, const Uint32& Height, bool StencilBuffer, bool DepthBuffer, EE::Window::Window * window ) { if ( FrameBufferFBO::isSupported() ) return eeNew( FrameBufferFBO, ( Width, Height, StencilBuffer, DepthBuffer, window ) ); - + eePRINTL( "FBO not supported" ); return NULL; } diff --git a/src/eepp/graphics/framebufferfbo.cpp b/src/eepp/graphics/framebufferfbo.cpp index 4508bf2ad..b65751186 100644 --- a/src/eepp/graphics/framebufferfbo.cpp +++ b/src/eepp/graphics/framebufferfbo.cpp @@ -82,23 +82,24 @@ bool FrameBufferFBO::create(const Uint32& Width, const Uint32& Height, bool Sten mFrameBuffer = static_cast( frameBuffer ); - if ( !mFrameBuffer) { + if ( !mFrameBuffer ) { eePRINT("FrameBufferFBO::create: Failed to created FrameBuffer Object"); - return false; } bindFrameBuffer(); - if ( DepthBuffer ) { + if ( mHasDepthBuffer ) { unsigned int depth = 0; GLi->genRenderbuffers( 1, &depth ); mDepthBuffer = static_cast(depth); - if ( !mDepthBuffer ) + if ( !mDepthBuffer ) { + eePRINT("FrameBufferFBO::create: Failed to created Depth Buffer"); return false; + } bindDepthBuffer(); @@ -106,10 +107,10 @@ bool FrameBufferFBO::create(const Uint32& Width, const Uint32& Height, bool Sten GLi->framebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mDepthBuffer ); - GLi->bindFramebuffer( GL_RENDERBUFFER, mLastDB ); + GLi->bindRenderbuffer( GL_RENDERBUFFER, mLastDB ); } - if ( StencilBuffer ) { + if ( mHasStencilBuffer ) { GLuint stencil = 0; GLi->genRenderbuffers( 1, &stencil ); @@ -117,17 +118,16 @@ bool FrameBufferFBO::create(const Uint32& Width, const Uint32& Height, bool Sten if (!mStencilBuffer) { eePRINT("FrameBufferFBO::create: Failed to created Stencil Buffer"); - return false; } bindStencilBuffer(); - GLi->renderbufferStorage( GL_RENDERBUFFER, GL_STENCIL_INDEX, Width, Height ); + GLi->renderbufferStorage( GL_RENDERBUFFER, GL_STENCIL_INDEX8, Width, Height ); GLi->framebufferRenderbuffer( GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER_EXT, mStencilBuffer ); - GLi->bindFramebuffer( GL_RENDERBUFFER, mLastSB ); + GLi->bindRenderbuffer( GL_RENDERBUFFER, mLastSB ); } if ( NULL == mTexture ) { @@ -136,15 +136,17 @@ bool FrameBufferFBO::create(const Uint32& Width, const Uint32& Height, bool Sten if ( TextureFactory::instance()->existsId( TexId ) ) { mTexture = TextureFactory::instance()->getTexture( TexId ); } else { + eePRINTL( "FrameBufferFBO::create: failed to create texture" ); return false; } } GLi->framebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture->getHandle(), 0 ); - if ( GLi->checkFramebufferStatus( GL_FRAMEBUFFER ) != GL_FRAMEBUFFER_COMPLETE ) { + Uint32 status = GLi->checkFramebufferStatus( GL_FRAMEBUFFER ); + if ( status != GL_FRAMEBUFFER_COMPLETE ) { + eePRINTL("FrameBufferFBO::create: Failed to attach Frame Buffer. Status: %04X", status ); GLi->bindFramebuffer( GL_FRAMEBUFFER, mLastFB ); - return false; } @@ -177,6 +179,7 @@ void FrameBufferFBO::reload() { void FrameBufferFBO::bindFrameBuffer() { int curFB; + glGetIntegerv( GL_FRAMEBUFFER_BINDING, &curFB ); mLastFB = (Int32)curFB; diff --git a/src/eepp/graphics/primitives.cpp b/src/eepp/graphics/primitives.cpp index 77596a9a1..5afb6dd52 100755 --- a/src/eepp/graphics/primitives.cpp +++ b/src/eepp/graphics/primitives.cpp @@ -161,7 +161,7 @@ void Primitives::drawArc( const Vector2f& p, const Float& radius, Uint32 segment if(segmentsCount < 6) segmentsCount = 6; segmentsCount = segmentsCount > 360 ? 360 : segmentsCount; - Float angle_shift = 360 / static_cast(segmentsCount); + Float angleShift = 360 / static_cast(segmentsCount); Float arcAngleA = arcAngle > 360 ? arcAngle - 360 * std::floor( arcAngle / 360 ) : arcAngle; sBR->setTexture( NULL ); @@ -202,12 +202,12 @@ void Primitives::drawArc( const Vector2f& p, const Float& radius, Uint32 segment sBR->triangleFanBegin(); sBR->triangleFanSetColor( mColor ); - for( Float i = 0; i < arcAngleA; i+= angle_shift ) { + for( Float i = 0; i < arcAngleA; i+= angleShift ) { Float startAngle = arcStartAngle + i; sBR->batchTriangleFan( p.x , p.y, p.x + radius * Math::sinAng( startAngle ), p.y + radius * Math::cosAng( startAngle ), - p.x + radius * Math::sinAng( startAngle + angle_shift ), p.y + radius * Math::cosAng( startAngle + angle_shift ) ); + p.x + radius * Math::sinAng( startAngle + angleShift ), p.y + radius * Math::cosAng( startAngle + angleShift ) ); } break; diff --git a/src/eepp/graphics/renderer/renderer.cpp b/src/eepp/graphics/renderer/renderer.cpp index 95b66c409..7be805e2c 100644 --- a/src/eepp/graphics/renderer/renderer.cpp +++ b/src/eepp/graphics/renderer/renderer.cpp @@ -244,6 +244,8 @@ void Renderer::init() { isExtension( "WEBKIT_WEBGL_compressed_texture_s3tc" ) || isExtension( "MOZ_WEBGL_compressed_texture_s3tc" ) ); } + + writeExtension( EEGL_ARB_texture_non_power_of_two , 1 ); #endif } diff --git a/src/examples/empty_window/empty_window.cpp b/src/examples/empty_window/empty_window.cpp index 521b57338..62005d04c 100644 --- a/src/examples/empty_window/empty_window.cpp +++ b/src/examples/empty_window/empty_window.cpp @@ -23,7 +23,7 @@ void mainLoop() } // Draw a circle - p.drawCircle( Vector2f( win->getWidth() * 0.5f, win->getHeight() * 0.5f ), 200, 50 ); + p.drawCircle( Vector2f( win->getWidth() * 0.5f, win->getHeight() * 0.5f ), 200, 60 ); // Draw frame win->display(); diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index e5c07c0d6..5f9e70b18 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -65,7 +65,7 @@ void EETest::init() { ContextSettings ConSettings = EE->createContextSettings( &Ini ); if ( !( WinSettings.Style & WindowStyle::Fullscreen ) && !( WinSettings.Style & WindowStyle::UseDesktopResolution ) ) { -#if EE_PLATFORM != EE_PLATFORM_MACOSX +#if EE_PLATFORM != EE_PLATFORM_MACOSX && EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN WinSettings.Width *= WinSettings.PixelDensity; WinSettings.Height *= WinSettings.PixelDensity; #endif @@ -74,6 +74,8 @@ void EETest::init() { mWindow = EE->createWindow( WinSettings, ConSettings ); if ( NULL != mWindow && mWindow->isOpen() ) { + MyPath = Sys::getProcessPath() + "assets/"; // Android needs to get the real process path AFTER the window creation + setScreen( StartScreen ); mWindow->setCaption( "eepp - Test Application" ); @@ -196,6 +198,9 @@ void EETest::onFontLoaded( ResourceLoader * ObjLoaded ) { eeASSERT( DBSM != NULL ); Con.create( DBSM, true ); + // RR GG BB AA + // EE 1F 1F 20 + // 20 1F 1F EE Con.setBackgroundColor( 0x201F1FEE ); Con.setBackgroundLineColor( 0x666666EE ); Con.setFontColor( 0xCFCFCFFF );