From e64cfe07d3d93bed798ed61200d1a89eab31f01d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 25 May 2013 04:20:16 -0300 Subject: [PATCH] Improved GLES2 support. Fixed VBOs for GLES2. Fixed a bug in texture size calculation. --- projects/android-project/jni/Application.mk | 16 +- projects/linux/ee.creator.user | 2 +- src/eepp/graphics/cframebufferfbo.cpp | 6 - src/eepp/graphics/ctextureloader.cpp | 18 +-- src/eepp/graphics/cvertexbuffervbo.cpp | 140 +++++++++--------- src/eepp/graphics/renderer/cgl.cpp | 44 ++++-- src/eepp/graphics/renderer/crenderergles2.cpp | 2 - src/test/eetest.cpp | 21 +-- 8 files changed, 123 insertions(+), 126 deletions(-) diff --git a/projects/android-project/jni/Application.mk b/projects/android-project/jni/Application.mk index a729a34ae..9c18c65e0 100644 --- a/projects/android-project/jni/Application.mk +++ b/projects/android-project/jni/Application.mk @@ -1,12 +1,12 @@ APP_PROJECT_PATH := $(call my-dir)/.. -#EE_GLES_VERSION := -DEE_GLES2 -DSOIL_GLES2 -DSDL_GLES2 -#EE_GLES_LINK := -lGLESv2 - EE_SDL_VERSION := EE_SDL_VERSION_2 -EE_GLES_VERSION := -DEE_GLES1 -DSOIL_GLES1 -DSDL_GLES1 -EE_GLES_LINK := -lGLESv1_CM +#EE_GLES_VERSION := -DEE_GLES1 -DSOIL_GLES1 -DSDL_GLES1 +#EE_GLES_LINK := -lGLESv1_CM + +EE_GLES_VERSION := -DEE_GLES2 -DSOIL_GLES2 -DSDL_GLES2 +EE_GLES_LINK := -lGLESv2 APP_STL := stlport_static @@ -14,11 +14,11 @@ APP_LDLIBS := -llog $(EE_GLES_LINK) -lm -lz -lOpenSLES #Debug Build # arm-linux-androideabi-4.4.3 crashes in -O0 mode on SDL sources -APP_CFLAGS := -g -DDEBUG -DEE_DEBUG -DEE_MEMORY_MANAGER -APP_OPTIM :=debug +#APP_CFLAGS := -g -DDEBUG -DEE_DEBUG -DEE_MEMORY_MANAGER +#APP_OPTIM :=debug #Release Build -#APP_CFLAGS := -fno-strict-aliasing -O3 -s -DNDEBUG -ffast-math +APP_CFLAGS := -fno-strict-aliasing -O3 -s -DNDEBUG -ffast-math APP_PLATFORM := android-9 APP_MODULES := main diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 120c17e45..3d7841231 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/src/eepp/graphics/cframebufferfbo.cpp b/src/eepp/graphics/cframebufferfbo.cpp index 981747fdd..2933e2259 100644 --- a/src/eepp/graphics/cframebufferfbo.cpp +++ b/src/eepp/graphics/cframebufferfbo.cpp @@ -6,12 +6,6 @@ namespace EE { namespace Graphics { bool cFrameBufferFBO::IsSupported() { - #ifdef EE_GLES - if ( GLi->Version() == GLv_ES2 ) { - return true; - } - #endif - return 0 != GLi->IsExtension( EEGL_EXT_framebuffer_object ); } diff --git a/src/eepp/graphics/ctextureloader.cpp b/src/eepp/graphics/ctextureloader.cpp index bdabfff66..c7b841325 100644 --- a/src/eepp/graphics/ctextureloader.cpp +++ b/src/eepp/graphics/ctextureloader.cpp @@ -436,18 +436,12 @@ void cTextureLoader::LoadFromPixels() { mWidth = width; mHeight = height; - if ( STBI_dds == mImgType ) { - if ( mIsCompressed && mSize > 128 ) { - mSize -= 128; // Remove the DDS header size - } - } else if ( STBI_pvr == mImgType ) { - if ( mIsCompressed && mSize > 52 ) { - mSize -= 52; // Remove the PVR header size - } - } else if ( STBI_pkm == mImgType ) { - if ( mIsCompressed && mSize > 16 ) { - mSize -= 16; // Remove the PKM header size - } + if ( STBI_dds == mImgType && mIsCompressed && mSize > 128 ) { + mSize -= 128; // Remove the DDS header size + } else if ( STBI_pvr == mImgType && mIsCompressed && mSize > 52 ) { + mSize -= 52; // Remove the PVR header size + } else if ( STBI_pkm == mImgType && mIsCompressed && mSize > 16 ) { + mSize -= 16; // Remove the PKM header size } else { mSize = mWidth * mHeight * mChannels; } diff --git a/src/eepp/graphics/cvertexbuffervbo.cpp b/src/eepp/graphics/cvertexbuffervbo.cpp index c44532fe8..793e8d576 100644 --- a/src/eepp/graphics/cvertexbuffervbo.cpp +++ b/src/eepp/graphics/cvertexbuffervbo.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #if !defined( EE_GLES ) && EE_PLATFORM != EE_PLATFORM_HAIKU // Disabled VAO for the moment, we really don't need them @@ -96,15 +97,15 @@ bool cVertexBufferVBO::Compile() { glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER, 0 ); } + mCompiled = true; + mBuffersSet = false; + #ifdef EE_VBO_USE_VAO if ( GLv_3 == GLi->Version() ) { glBindVertexArray( curVAO ); } #endif - mCompiled = true; - mBuffersSet = false; - return true; } @@ -148,12 +149,6 @@ void cVertexBufferVBO::Draw() { glBindVertexArray( curVAO ); } #endif - - if ( GLv_3 == GLi->Version() || GLv_ES2 == GLi->Version() ) { - if ( !mTextured ) { - GLi->Enable( GL_TEXTURE_2D ); - } - } } void cVertexBufferVBO::SetVertexStates() { @@ -174,50 +169,10 @@ void cVertexBufferVBO::SetVertexStates() { } #endif - /// POSITION - if ( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_POSITION ) ) { - GLi->EnableClientState( GL_VERTEX_ARRAY ); - glBindBufferARB( GL_ARRAY_BUFFER, mArrayHandle[ VERTEX_FLAG_POSITION ] ); - #ifdef EE_GL3_ENABLED - if ( GLv_3 == GLi->Version() ) { - index = GLi->GetRendererGL3()->GetStateIndex( EEGL_VERTEX_ARRAY ); - - if ( -1 != index ) { - glVertexAttribPointerARB( index, eeVertexElements[ VERTEX_FLAG_POSITION ], GL_FP, GL_FALSE, 0, 0 ); - } - } - else - #endif - { - GLi->VertexPointer( eeVertexElements[ VERTEX_FLAG_POSITION ], GL_FP, 0, (char*)NULL, 0 ); - } - } else { - GLi->DisableClientState( GL_VERTEX_ARRAY ); - } - - /// COLOR - if ( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_COLOR ) ) { - GLi->EnableClientState( GL_COLOR_ARRAY ); - glBindBufferARB( GL_ARRAY_BUFFER, mArrayHandle[ VERTEX_FLAG_COLOR ] ); - - #ifdef EE_GL3_ENABLED - if ( GLv_3 == GLi->Version() ) { - index = GLi->GetRendererGL3()->GetStateIndex( EEGL_COLOR_ARRAY ); - - if ( -1 != index ) - glVertexAttribPointerARB( index, eeVertexElements[ VERTEX_FLAG_COLOR ], GL_UNSIGNED_BYTE, GL_TRUE, 0, 0 ); - } - else - #endif - { - GLi->ColorPointer( eeVertexElements[ VERTEX_FLAG_COLOR ], GL_UNSIGNED_BYTE, 0, (char*)NULL, 0 ); - } - } else { - GLi->DisableClientState( GL_COLOR_ARRAY ); - } - /// TEXTURES if ( GLi->IsExtension( EEGL_ARB_multitexture ) ) { + mTextured = false; + for ( Int32 i = 0; i < EE_MAX_TEXTURE_UNITS; i++ ) { if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_TEXTURE0 + i ) ) { GLi->ClientActiveTexture( GL_TEXTURE0 + i ); @@ -226,10 +181,12 @@ void cVertexBufferVBO::SetVertexStates() { glBindBufferARB( GL_ARRAY_BUFFER, mArrayHandle[ VERTEX_FLAG_TEXTURE0 + i ] ); #ifdef EE_GL3_ENABLED - if ( GLv_3 == GLi->Version() ) { - index = GLi->GetRendererGL3()->GetStateIndex( EEGL_TEXTURE_COORD_ARRAY ); + if ( GLv_3 == GLi->Version() || GLv_ES2 == GLi->Version() ) { + index = GLv_3 == GLi->Version() ? + GLi->GetRendererGL3()->GetStateIndex( EEGL_TEXTURE_COORD_ARRAY ) : + GLi->GetRendererGLES2()->GetStateIndex( EEGL_TEXTURE_COORD_ARRAY ); - if ( -1 != index && 0 == i ) + if ( -1 != index ) glVertexAttribPointerARB( index, eeVertexElements[ VERTEX_FLAG_TEXTURE0 + i ], GL_FP, GL_FALSE, 0, 0 ); } else @@ -242,9 +199,6 @@ void cVertexBufferVBO::SetVertexStates() { } else { GLi->DisableClientState( GL_TEXTURE_COORD_ARRAY ); GLi->Disable( GL_TEXTURE_2D ); - - mTextured = false; - break; } } @@ -254,8 +208,10 @@ void cVertexBufferVBO::SetVertexStates() { glBindBufferARB( GL_ARRAY_BUFFER, mArrayHandle[ VERTEX_FLAG_TEXTURE0 ] ); #ifdef EE_GL3_ENABLED - if ( GLv_3 == GLi->Version() ) { - index = GLi->GetRendererGL3()->GetStateIndex( EEGL_TEXTURE_COORD_ARRAY ); + if ( GLv_3 == GLi->Version() || GLv_ES2 == GLi->Version() ) { + index = GLv_3 == GLi->Version() ? + GLi->GetRendererGL3()->GetStateIndex( EEGL_TEXTURE_COORD_ARRAY ) : + GLi->GetRendererGLES2()->GetStateIndex( EEGL_TEXTURE_COORD_ARRAY ); if ( -1 != index ) glVertexAttribPointerARB( index, eeVertexElements[ VERTEX_FLAG_TEXTURE0 ], GL_FP, GL_FALSE, 0, 0 ); @@ -275,18 +231,59 @@ void cVertexBufferVBO::SetVertexStates() { } } - GLi->ActiveTexture( GL_TEXTURE0 ); - GLi->ClientActiveTexture( GL_TEXTURE0 ); + /// POSITION + if ( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_POSITION ) ) { + GLi->EnableClientState( GL_VERTEX_ARRAY ); + glBindBufferARB( GL_ARRAY_BUFFER, mArrayHandle[ VERTEX_FLAG_POSITION ] ); - glBindBufferARB( GL_ARRAY_BUFFER, 0 ); + #ifdef EE_GL3_ENABLED + if ( GLv_3 == GLi->Version() || GLv_ES2 == GLi->Version() ) { + index = GLv_3 == GLi->Version() ? + GLi->GetRendererGL3()->GetStateIndex( EEGL_VERTEX_ARRAY ) : + GLi->GetRendererGLES2()->GetStateIndex( EEGL_VERTEX_ARRAY ); + + if ( -1 != index ) + glVertexAttribPointerARB( index, eeVertexElements[ VERTEX_FLAG_POSITION ], GL_FP, GL_FALSE, 0, 0 ); + } + else + #endif + { + GLi->VertexPointer( eeVertexElements[ VERTEX_FLAG_POSITION ], GL_FP, 0, (char*)NULL, 0 ); + } + } else { + GLi->DisableClientState( GL_VERTEX_ARRAY ); + } + + /// COLOR + if ( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_COLOR ) ) { + GLi->EnableClientState( GL_COLOR_ARRAY ); + glBindBufferARB( GL_ARRAY_BUFFER, mArrayHandle[ VERTEX_FLAG_COLOR ] ); + + #ifdef EE_GL3_ENABLED + if ( GLv_3 == GLi->Version() || GLv_ES2 == GLi->Version() ) { + index = GLv_3 == GLi->Version() ? + GLi->GetRendererGL3()->GetStateIndex( EEGL_COLOR_ARRAY ) : + GLi->GetRendererGLES2()->GetStateIndex( EEGL_COLOR_ARRAY ); + + if ( -1 != index ) + glVertexAttribPointerARB( index, eeVertexElements[ VERTEX_FLAG_COLOR ], GL_UNSIGNED_BYTE, GL_TRUE, 0, 0 ); + } + else + #endif + { + GLi->ColorPointer( eeVertexElements[ VERTEX_FLAG_COLOR ], GL_UNSIGNED_BYTE, 0, (char*)NULL, 0 ); + } + } else { + GLi->DisableClientState( GL_COLOR_ARRAY ); + } + + mBuffersSet = true; #ifdef EE_VBO_USE_VAO if ( GLv_3 == GLi->Version() ) { glBindVertexArray( curVAO ); } #endif - - mBuffersSet = true; } void cVertexBufferVBO::Update( const Uint32& Types, bool Indices ) { @@ -329,6 +326,16 @@ void cVertexBufferVBO::Reload() { void cVertexBufferVBO::Unbind() { + glBindBufferARB( GL_ARRAY_BUFFER, 0 ); + + if ( !mTextured ) { + GLi->Enable( GL_TEXTURE_2D ); + GLi->EnableClientState( GL_TEXTURE_COORD_ARRAY ); + } + + GLi->ActiveTexture( GL_TEXTURE0 ); + GLi->ClientActiveTexture( GL_TEXTURE0 ); + if( !VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_POSITION ) ) { GLi->EnableClientState( GL_VERTEX_ARRAY ); } @@ -336,11 +343,6 @@ void cVertexBufferVBO::Unbind() { if( !VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_COLOR ) ) { GLi->EnableClientState( GL_COLOR_ARRAY ); } - - if( !VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_TEXTURE0 ) ) { - GLi->Enable( GL_TEXTURE_2D ); - GLi->EnableClientState( GL_TEXTURE_COORD_ARRAY ); - } } diff --git a/src/eepp/graphics/renderer/cgl.cpp b/src/eepp/graphics/renderer/cgl.cpp index 7700da88e..7b228d59d 100644 --- a/src/eepp/graphics/renderer/cgl.cpp +++ b/src/eepp/graphics/renderer/cgl.cpp @@ -147,22 +147,42 @@ void cGL::Init() { } - WriteExtension( EEGL_IMG_texture_compression_pvrtc , IsExtension( "GL_IMG_texture_compression_pvrtc" ) ); - WriteExtension( EEGL_OES_compressed_ETC1_RGB8_texture , IsExtension( "GL_OES_compressed_ETC1_RGB8_texture" ) ); + #ifdef EE_GLES + + WriteExtension( EEGL_ARB_point_parameters , 1 ); + WriteExtension( EEGL_ARB_point_sprite , 1 ); + WriteExtension( EEGL_ARB_multitexture , 1 ); + + WriteExtension( EEGL_IMG_texture_compression_pvrtc , IsExtension( "GL_IMG_texture_compression_pvrtc" ) ); + WriteExtension( EEGL_OES_compressed_ETC1_RGB8_texture , IsExtension( "GL_OES_compressed_ETC1_RGB8_texture" ) ); if ( !IsExtension( EEGL_EXT_texture_compression_s3tc ) ) { - WriteExtension( EEGL_EXT_texture_compression_s3tc , IsExtension( "GL_OES_texture_compression_S3TC" ) ); + WriteExtension( EEGL_EXT_texture_compression_s3tc , IsExtension( "GL_OES_texture_compression_S3TC" ) ); } if ( !IsExtension( EEGL_EXT_framebuffer_object ) ) { - WriteExtension( EEGL_EXT_framebuffer_object , IsExtension( "GL_OES_framebuffer_object" ) ); + WriteExtension( EEGL_EXT_framebuffer_object , IsExtension( "GL_OES_framebuffer_object" ) ); } if ( !IsExtension( EEGL_ARB_texture_non_power_of_two ) ) { WriteExtension( EEGL_ARB_texture_non_power_of_two , IsExtension( "GL_IMG_texture_npot" ) || IsExtension( "GL_OES_texture_npot" ) || - IsExtension( "GL_APPLE_texture_2D_limited_npot" ) ); + IsExtension( "GL_APPLE_texture_2D_limited_npot" ) ); } + + if ( !IsExtension( EEGL_ARB_vertex_array_object ) ) { + WriteExtension( EEGL_ARB_vertex_array_object , IsExtension( "GL_OES_vertex_array_object" ) ); + } + + #endif + + #ifdef EE_GLES2 + WriteExtension( EEGL_EXT_framebuffer_object , 1 ); + WriteExtension( EEGL_ARB_vertex_buffer_object , 1 ); + WriteExtension( EEGL_ARB_shader_objects , 1 ); + WriteExtension( EEGL_ARB_vertex_shader , 1 ); + WriteExtension( EEGL_ARB_fragment_shader , 1 ); + #endif } bool cGL::IsExtension( const std::string& name ) { @@ -193,11 +213,7 @@ bool cGL::PointSpriteSupported() { bool cGL::ShadersSupported() { #ifdef EE_GLES - if ( GLv_ES2 == Version() || GLv_3 == Version() ) - return true; - - /// GLES1 - return false; + return ( GLv_ES2 == Version() || GLv_3 == Version() ); #else return IsExtension( EEGL_ARB_shading_language_100 ) && IsExtension( EEGL_ARB_shader_objects ) && IsExtension( EEGL_ARB_vertex_shader ) && IsExtension( EEGL_ARB_fragment_shader ); #endif @@ -375,7 +391,7 @@ void cGL::PolygonMode( const EE_FILL_MODE& Mode ) { } std::string cGL::GetVendor() { - char * str = cGL::instance()->GetString( GL_VENDOR ); + char * str = GetString( GL_VENDOR ); if ( NULL != str ) return std::string( reinterpret_cast ( str ) ); @@ -384,7 +400,7 @@ std::string cGL::GetVendor() { } std::string cGL::GetRenderer() { - char * str = cGL::instance()->GetString( GL_RENDERER ); + char * str = GetString( GL_RENDERER ); if ( NULL != str ) return std::string( reinterpret_cast ( str ) ); @@ -393,7 +409,7 @@ std::string cGL::GetRenderer() { } std::string cGL::GetVersion() { - char * str = cGL::instance()->GetString( GL_VERSION ); + char * str = GetString( GL_VERSION ); if ( NULL != str ) return std::string( reinterpret_cast ( str ) ); @@ -404,7 +420,7 @@ std::string cGL::GetVersion() { std::string cGL::GetShadingLanguageVersion() { if ( ShadersSupported() ) { #ifdef GL_SHADING_LANGUAGE_VERSION - char * str = cGL::instance()->GetString( GL_SHADING_LANGUAGE_VERSION ); + char * str = GetString( GL_SHADING_LANGUAGE_VERSION ); if ( NULL != str ) return std::string( reinterpret_cast ( str ) ); diff --git a/src/eepp/graphics/renderer/crenderergles2.cpp b/src/eepp/graphics/renderer/crenderergles2.cpp index 6b817ae27..9174858a3 100644 --- a/src/eepp/graphics/renderer/crenderergles2.cpp +++ b/src/eepp/graphics/renderer/crenderergles2.cpp @@ -271,9 +271,7 @@ void cRendererGLES2::Enable( GLenum cap ) { if ( 0 == mTexActive ) { mTexActive = 1; - #ifdef EE_GLES2 SetShader( EEGLES2_SHADER_BASE ); - #endif } return; diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 023523ebb..a26234480 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -1175,18 +1175,20 @@ void cEETest::Screen4() { if ( NULL != mFBO ) { mFBO->Bind(); mFBO->Clear(); + } + if ( NULL != mVBO ) { mBlindy.Position( 128-16, 128-16 ); mBlindy.Draw(); - if ( NULL != mVBO ) { - mVBO->Bind(); - mVBO->Draw(); - mVBO->Unbind(); - } + mVBO->Bind(); + mVBO->Draw(); + mVBO->Unbind(); mFBOText.Draw( 128.f - (eeFloat)(Int32)( mFBOText.GetTextWidth() * 0.5f ), 25.f - (eeFloat)(Int32)( mFBOText.GetTextHeight() * 0.5f ), FONT_DRAW_CENTER ); + } + if ( NULL != mFBO ) { mFBO->Unbind(); if ( NULL != mFBO->GetTexture() ) { @@ -1393,15 +1395,6 @@ void cEETest::Input() { if ( KM->IsKeyUp(KEY_6) && KM->ControlPressed() ) SetScreen( 5 ); - #ifdef EE_PLATFORM_TOUCH - std::list Fingers = KM->GetFingersDown(); - std::list FingersDown = KM->GetFingersWasDown(); - - if ( Fingers.size() == 1 && FingersDown.size() == 1 ) { - ShowMenu(); - } - #endif - cJoystick * Joy = JM->GetJoystick(0); if ( mJoyEnabled && NULL != Joy ) {