Disabled the OpenGL state save/restore, because many older devices do not support any glGet()

This commit is contained in:
pelya
2013-02-04 13:07:49 +02:00
parent 8f57488043
commit e214d265e7
2 changed files with 31 additions and 16 deletions

View File

@@ -114,16 +114,30 @@ oldGlState;
static inline void beginDrawingTex()
{
#ifndef SDL_TOUCHSCREEN_KEYBOARD_SAVE_RESTORE_OPENGL_STATE
// Make the video somehow work on emulator
oldGlState.texture2d = GL_TRUE;
oldGlState.texunitId = GL_TEXTURE0;
oldGlState.clientTexunitId = GL_TEXTURE0;
oldGlState.textureId = 0;
oldGlState.texEnvMode = GL_MODULATE;
oldGlState.blend = GL_TRUE;
oldGlState.blend1 = GL_SRC_ALPHA;
oldGlState.blend2 = GL_ONE_MINUS_SRC_ALPHA;
oldGlState.colorArray = GL_FALSE;
#else
// Save OpenGL state
glGetError(); // Clear error flag
// This code does not work on 1.6 emulator, and on some older devices
// However GLES 1.1 spec defines all theese values, so it's a device fault for not implementing them
oldGlState.texture2d = glIsEnabled(GL_TEXTURE_2D);
glGetIntegerv(GL_ACTIVE_TEXTURE, &oldGlState.texunitId);
glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &oldGlState.clientTexunitId);
#endif
glActiveTexture(GL_TEXTURE0);
glClientActiveTexture(GL_TEXTURE0);
#ifdef SDL_TOUCHSCREEN_KEYBOARD_SAVE_RESTORE_OPENGL_STATE
glGetIntegerv(GL_TEXTURE_BINDING_2D, &oldGlState.textureId);
glGetFloatv(GL_CURRENT_COLOR, &(oldGlState.color[0]));
glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &oldGlState.texEnvMode);
@@ -132,19 +146,7 @@ static inline void beginDrawingTex()
glGetIntegerv(GL_BLEND_DST, &oldGlState.blend2);
glGetBooleanv(GL_COLOR_ARRAY, &oldGlState.colorArray);
// It's very unlikely that some app will use GL_TEXTURE_CROP_RECT_OES, so just skip it
if( glGetError() != GL_NO_ERROR )
{
// Make the video somehow work on emulator
oldGlState.texture2d = GL_FALSE;
oldGlState.texunitId = GL_TEXTURE0;
oldGlState.clientTexunitId = GL_TEXTURE0;
oldGlState.textureId = 0;
oldGlState.texEnvMode = GL_MODULATE;
oldGlState.blend = GL_FALSE;
oldGlState.blend1 = GL_SRC_ALPHA;
oldGlState.blend2 = GL_ONE_MINUS_SRC_ALPHA;
oldGlState.colorArray = GL_FALSE;
}
#endif
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

View File

@@ -120,8 +120,21 @@ Also make sure that your HW textures are not wider than 1024 pixels, or it will
texture on HTC G1, and other low-end devices. Software surfaces may be of any size of course.
If you want HW acceleration - just use OpenGL, that's the easiest and most cross-platform way,
however note that on-screen keyboard (even the text input button) is also drawn using OpenGL,
so it might mess up your GL state (although it should not do that due to recent code changes).
however if you'll use on-screen keyboard (even the text input button) the OpenGL state will get
messed up after each frame - after each SDL_GL_SwapBuffers() you'll need to restore following GL state:
glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
glClientActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, your_texture_id);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glEnable(GL_BLEND);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnableClientState(GL_COLOR_ARRAY);
Previously I've got the code to save/restore OpenGL state, but it doens't work on every device -
you may wish to uncomment it inside file SDL_touchscreenkeyboard.c in functions beginDrawingTex() and endDrawingTex().
If you don't use on-screen keyboard you don't need to reinit OpenGL state - set following in AndroidAppSettings.cfg:
AppNeedsArrowKeys=n