Improved GLES2 support.

Fixed VBOs for GLES2.
Fixed a bug in texture size calculation.
This commit is contained in:
Martín Lucas Golini
2013-05-25 04:20:16 -03:00
parent c68b9c75f4
commit e64cfe07d3
8 changed files with 123 additions and 126 deletions

View File

@@ -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

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 2.7.1, 2013-05-20T03:12:18. -->
<!-- Written by QtCreator 2.7.1, 2013-05-25T04:18:17. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>

View File

@@ -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 );
}

View File

@@ -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;
}

View File

@@ -1,6 +1,7 @@
#include <eepp/graphics/cvertexbuffervbo.hpp>
#include <eepp/graphics/renderer/cgl.hpp>
#include <eepp/graphics/renderer/crenderergl3.hpp>
#include <eepp/graphics/renderer/crenderergles2.hpp>
#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 );
}
}

View File

@@ -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<const char*> ( 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<const char*> ( 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<const char*> ( 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<const char*> ( str ) );

View File

@@ -271,9 +271,7 @@ void cRendererGLES2::Enable( GLenum cap ) {
if ( 0 == mTexActive ) {
mTexActive = 1;
#ifdef EE_GLES2
SetShader( EEGLES2_SHADER_BASE );
#endif
}
return;

View File

@@ -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<cInputFinger*> Fingers = KM->GetFingersDown();
std::list<cInputFinger*> FingersDown = KM->GetFingersWasDown();
if ( Fingers.size() == 1 && FingersDown.size() == 1 ) {
ShowMenu();
}
#endif
cJoystick * Joy = JM->GetJoystick(0);
if ( mJoyEnabled && NULL != Joy ) {