diff --git a/ChangeAppSettings.sh b/ChangeAppSettings.sh index be9be138c..d1f900335 100755 --- a/ChangeAppSettings.sh +++ b/ChangeAppSettings.sh @@ -95,36 +95,6 @@ if [ -n "$AppDataDownloadUrl1" ] ; then fi fi -if [ -z "$SdlVideoResize" -o -z "$AUTO" ]; then -echo -echo "Application window should be resized to fit into native device screen (480x320 or 800x480) (y) or (n) ($SdlVideoResize): " -read var -if [ -n "$var" ] ; then - SdlVideoResize="$var" - CHANGED=1 -fi -fi - -if [ -z "$SdlVideoResizeKeepAspect" -o -z "$AUTO" ]; then -echo -echo -n "Application resizing should use 4:3 aspect ratio, creating black bars (y) or (n) ($SdlVideoResizeKeepAspect): " -read var -if [ -n "$var" ] ; then - SdlVideoResizeKeepAspect="$var" - CHANGED=1 -fi -fi - -if [ -z "$NeedDepthBuffer" -o -z "$AUTO" ]; then -echo -echo -n "Enable OpenGL depth buffer (needed only for 3-d applications, small speed decrease) (y) or (n) ($NeedDepthBuffer): " -read var -if [ -n "$var" ] ; then - NeedDepthBuffer="$var" - CHANGED=1 -fi -fi - if [ "$LibSdlVersion" = "1.2" ]; then if [ -z "$CompatibilityHacks" -o -z "$AUTO" ]; then echo @@ -154,6 +124,76 @@ else SwVideoMode=n fi +if [ -z "$VideoDepthBpp" -o -z "$AUTO" ]; then +echo +echo "Video color depth - 16 BPP is the fastest, other modes are not supported" +echo -n "if you're using SDL_HWSURFACE (16)/(24)/(32) ($VideoDepthBpp): " +read var +if [ -n "$var" ] ; then + VideoDepthBpp="$var" + CHANGED=1 +fi +fi + +if [ "$SwVideoMode" = "y" ]; then +NeedDepthBuffer=n +NeedStencilBuffer=n +NeedGles2=n +else + +if [ -z "$NeedDepthBuffer" -o -z "$AUTO" ]; then +echo +echo -n "Enable OpenGL depth buffer (needed only for 3-d applications, small speed decrease) (y) or (n) ($NeedDepthBuffer): " +read var +if [ -n "$var" ] ; then + NeedDepthBuffer="$var" + CHANGED=1 +fi +fi + +if [ -z "$NeedStencilBuffer" -o -z "$AUTO" ]; then +echo +echo -n "Enable OpenGL stencil buffer (needed only for 3-d applications, small speed decrease) (y) or (n) ($NeedDepthBuffer): " +read var +if [ -n "$var" ] ; then + NeedStencilBuffer="$var" + CHANGED=1 +fi +fi + +if [ -z "$NeedGles2" -o -z "$AUTO" ]; then +echo +echo "Try to use GLES 2.x context - will revert to GLES 1.X if unsupported by device" +ecno -n "you need this option only if you're developing 3-d app (y) or (n) ($NeedGles2): " +read var +if [ -n "$var" ] ; then + NeedGles2="$var" + CHANGED=1 +fi +fi + +fi + +if [ -z "$SdlVideoResize" -o -z "$AUTO" ]; then +echo +echo "Application window should be resized to fit into native device screen (480x320 or 800x480) (y) or (n) ($SdlVideoResize): " +read var +if [ -n "$var" ] ; then + SdlVideoResize="$var" + CHANGED=1 +fi +fi + +if [ -z "$SdlVideoResizeKeepAspect" -o -z "$AUTO" ]; then +echo +echo -n "Application resizing should use 4:3 aspect ratio, creating black bars (y) or (n) ($SdlVideoResizeKeepAspect): " +read var +if [ -n "$var" ] ; then + SdlVideoResizeKeepAspect="$var" + CHANGED=1 +fi +fi + if [ -z "$AppUsesMouse" -o -z "$AUTO" ]; then echo echo -n "Application uses mouse (y) or (n) ($AppUsesMouse): " @@ -476,10 +516,13 @@ echo AppFullName=$AppFullName >> AndroidAppSettings.cfg echo ScreenOrientation=$ScreenOrientation >> AndroidAppSettings.cfg echo InhibitSuspend=$InhibitSuspend >> AndroidAppSettings.cfg echo AppDataDownloadUrl=\"$AppDataDownloadUrl\" >> AndroidAppSettings.cfg +echo VideoDepthBpp=$VideoDepthBpp >> AndroidAppSettings.cfg +echo NeedDepthBuffer=$NeedDepthBuffer >> AndroidAppSettings.cfg +echo NeedStencilBuffer=$NeedStencilBuffer >> AndroidAppSettings.cfg +echo NeedGles2=$NeedGles2 >> AndroidAppSettings.cfg +echo SwVideoMode=$SwVideoMode >> AndroidAppSettings.cfg echo SdlVideoResize=$SdlVideoResize >> AndroidAppSettings.cfg echo SdlVideoResizeKeepAspect=$SdlVideoResizeKeepAspect >> AndroidAppSettings.cfg -echo NeedDepthBuffer=$NeedDepthBuffer >> AndroidAppSettings.cfg -echo SwVideoMode=$SwVideoMode >> AndroidAppSettings.cfg echo CompatibilityHacks=$CompatibilityHacks >> AndroidAppSettings.cfg echo AppUsesMouse=$AppUsesMouse >> AndroidAppSettings.cfg echo AppNeedsTwoButtonMouse=$AppNeedsTwoButtonMouse >> AndroidAppSettings.cfg @@ -551,6 +594,18 @@ else NeedDepthBuffer=false fi +if [ "$NeedStencilBuffer" = "y" ] ; then + NeedStencilBuffer=true +else + NeedStencilBuffer=false +fi + +if [ "$NeedGles2" = "y" ] ; then + NeedGles2=true +else + NeedGles2=false +fi + if [ "$SwVideoMode" = "y" ] ; then SwVideoMode=true else @@ -678,8 +733,11 @@ cat project/src/Globals.java | \ sed "s/public static String ApplicationName = .*;/public static String ApplicationName = \"$AppShortName\";/" | \ sed "s/public static final boolean Using_SDL_1_3 = .*;/public static final boolean Using_SDL_1_3 = $UsingSdl13;/" | \ sed "s@public static String DataDownloadUrl = .*@public static String DataDownloadUrl = \"$AppDataDownloadUrl1\";@" | \ - sed "s/public static boolean NeedDepthBuffer = .*;/public static boolean NeedDepthBuffer = $NeedDepthBuffer;/" | \ sed "s/public static boolean SwVideoMode = .*;/public static boolean SwVideoMode = $SwVideoMode;/" | \ + sed "s/public static int VideoDepthBpp = .*;/public static int VideoDepthBpp = $VideoDepthBpp;/" | \ + sed "s/public static boolean NeedDepthBuffer = .*;/public static boolean NeedDepthBuffer = $NeedDepthBuffer;/" | \ + sed "s/public static boolean NeedStencilBuffer = .*;/public static boolean NeedStencilBuffer = $NeedStencilBuffer;/" | \ + sed "s/public static boolean NeedGles2 = .*;/public static boolean NeedGles2 = $NeedGles2;/" | \ sed "s/public static boolean CompatibilityHacks = .*;/public static boolean CompatibilityHacks = $CompatibilityHacks;/" | \ sed "s/public static boolean HorizontalOrientation = .*;/public static boolean HorizontalOrientation = $HorizontalOrientation;/" | \ sed "s/public static boolean InhibitSuspend = .*;/public static boolean InhibitSuspend = $InhibitSuspend;/" | \ diff --git a/project/java/GLSurfaceView_SDL.java b/project/java/GLSurfaceView_SDL.java index 55fb1b04f..a767dbe11 100644 --- a/project/java/GLSurfaceView_SDL.java +++ b/project/java/GLSurfaceView_SDL.java @@ -280,7 +280,7 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call "setRenderer has already been called for this instance."); } if (mEGLConfigChooser == null) { - mEGLConfigChooser = new SimpleEGLConfigChooser(true); + mEGLConfigChooser = getEglConfigChooser(16, false, false, false); } mGLThread = new GLThread(renderer); mGLThread.start(); @@ -319,8 +319,8 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call * * @param needDepth */ - public void setEGLConfigChooser(boolean needDepth) { - setEGLConfigChooser(new SimpleEGLConfigChooser(needDepth)); + public void setEGLConfigChooser(int bpp, boolean needDepth, boolean stencil, boolean gles2) { + setEGLConfigChooser(getEglConfigChooser(bpp, needDepth, stencil, gles2)); } /** @@ -337,9 +337,9 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call * */ public void setEGLConfigChooser(int redSize, int greenSize, int blueSize, - int alphaSize, int depthSize, int stencilSize) { + int alphaSize, int depthSize, int stencilSize, boolean gles2) { setEGLConfigChooser(new ComponentSizeChooser(redSize, greenSize, - blueSize, alphaSize, depthSize, stencilSize)); + blueSize, alphaSize, depthSize, stencilSize, gles2)); } /** * Set the rendering mode. When renderMode is @@ -619,6 +619,7 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call * @return the chosen configuration. */ EGLConfig chooseConfig(EGL10 egl, EGLDisplay display); + public boolean isGles2Required(); } private static abstract class BaseConfigChooser @@ -655,7 +656,7 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call private static class ComponentSizeChooser extends BaseConfigChooser { public ComponentSizeChooser(int redSize, int greenSize, int blueSize, - int alphaSize, int depthSize, int stencilSize) { + int alphaSize, int depthSize, int stencilSize, boolean isGles2) { super(new int[] { EGL10.EGL_RED_SIZE, redSize, EGL10.EGL_GREEN_SIZE, greenSize, @@ -663,6 +664,7 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call EGL10.EGL_ALPHA_SIZE, alphaSize, EGL10.EGL_DEPTH_SIZE, depthSize, EGL10.EGL_STENCIL_SIZE, stencilSize, + EGL10.EGL_RENDERABLE_TYPE, isGles2 ? EGL_OPENGL_ES2_BIT : 0, EGL10.EGL_NONE}); mValue = new int[1]; mRedSize = redSize; @@ -671,6 +673,7 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call mAlphaSize = alphaSize; mDepthSize = depthSize; mStencilSize = stencilSize; + this.isGles2 = isGles2; } @Override @@ -691,10 +694,13 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call EGL10.EGL_DEPTH_SIZE, 0); int s = findConfigAttrib(egl, display, config, EGL10.EGL_STENCIL_SIZE, 0); + boolean gles2 = (findConfigAttrib(egl, display, config, + EGL10.EGL_RENDERABLE_TYPE, 0) & EGL_OPENGL_ES2_BIT) != 0; int distance = Math.abs(r - mRedSize) + Math.abs(g - mGreenSize) + Math.abs(b - mBlueSize) + Math.abs(a - mAlphaSize) - + Math.abs(d - mDepthSize) + Math.abs(s - mStencilSize); + + Math.abs(d - mDepthSize) + Math.abs(s - mStencilSize) + + (gles2 == isGles2 ? 0 : 17); if (distance < closestDistance) { closestDistance = distance; closestConfig = config; @@ -712,6 +718,11 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call return defaultValue; } + public boolean isGles2Required() + { + return isGles2; + } + private int[] mValue; // Subclasses can adjust these values: protected int mRedSize; @@ -720,6 +731,9 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call protected int mAlphaSize; protected int mDepthSize; protected int mStencilSize; + public boolean isGles2 = false; + + public static final int EGL_OPENGL_ES2_BIT = 4; } /** @@ -727,9 +741,9 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call * RGB565 as possible, with or without a depth buffer. * */ - private static class SimpleEGLConfigChooser extends ComponentSizeChooser { - public SimpleEGLConfigChooser(boolean withDepthBuffer) { - super(4, 4, 4, 0, withDepthBuffer ? 16 : 0, 0); + private static class SimpleEGLConfigChooser16 extends ComponentSizeChooser { + public SimpleEGLConfigChooser16(boolean withDepthBuffer, boolean stencil, boolean gles2) { + super(4, 4, 4, 0, withDepthBuffer ? 16 : 0, stencil ? 8 : 0, gles2); // Adjust target values. This way we'll accept a 4444 or // 555 buffer if there's no 565 buffer available. mRedSize = 5; @@ -738,6 +752,34 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call } } + private static class SimpleEGLConfigChooser24 extends ComponentSizeChooser { + public SimpleEGLConfigChooser24(boolean withDepthBuffer, boolean stencil, boolean gles2) { + super(8, 8, 8, 0, withDepthBuffer ? 16 : 0, stencil ? 8 : 0, gles2); + mRedSize = 8; + mGreenSize = 8; + mBlueSize = 8; + } + } + + private static class SimpleEGLConfigChooser32 extends ComponentSizeChooser { + public SimpleEGLConfigChooser32(boolean withDepthBuffer, boolean stencil, boolean gles2) { + super(8, 8, 8, 8, withDepthBuffer ? 16 : 0, stencil ? 8 : 0, gles2); + mRedSize = 8; + mGreenSize = 8; + mBlueSize = 8; + mAlphaSize = 8; + } + } + private static ComponentSizeChooser getEglConfigChooser(int videoDepthBpp, boolean withDepthBuffer, boolean stencil, boolean gles2) { + if(videoDepthBpp == 16) + return new SimpleEGLConfigChooser16(withDepthBuffer, stencil, gles2); + if(videoDepthBpp == 24) + return new SimpleEGLConfigChooser24(withDepthBuffer, stencil, gles2); + if(videoDepthBpp == 32) + return new SimpleEGLConfigChooser32(withDepthBuffer, stencil, gles2); + return null; + }; + /** * An EGL helper class. */ @@ -775,8 +817,11 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call * Create an OpenGL ES context. This must be done only once, an * OpenGL context is a somewhat heavy object. */ + final int EGL_CONTEXT_CLIENT_VERSION = 0x3098; + final int[] gles2_attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE }; + mEglContext = mEgl.eglCreateContext(mEglDisplay, mEglConfig, - EGL10.EGL_NO_CONTEXT, null); + EGL10.EGL_NO_CONTEXT, mEGLConfigChooser.isGles2Required() ? gles2_attrib_list : null ); mEglSurface = null; } diff --git a/project/java/Globals.java b/project/java/Globals.java index 10699e402..533235756 100644 --- a/project/java/Globals.java +++ b/project/java/Globals.java @@ -32,8 +32,11 @@ class Globals { public static String AppLibraries[] = { "sdl-1.2", }; public static final boolean Using_SDL_1_3 = false; public static String DataDownloadUrl = "Data files are 2 Mb|https://sourceforge.net/projects/libsdl-android/files/CommanderGenius/commandergenius-data.zip/download^High-quality GFX and music - 40 Mb|https://sourceforge.net/projects/libsdl-android/files/CommanderGenius/commandergenius-hqp.zip/download"; - public static boolean NeedDepthBuffer = false; + public static int VideoDepthBpp = 16; public static boolean SwVideoMode = false; + public static boolean NeedDepthBuffer = false; + public static boolean NeedStencilBuffer = false; + public static boolean NeedGles2 = false; public static boolean CompatibilityHacks = false; public static boolean HorizontalOrientation = true; public static boolean InhibitSuspend = false; diff --git a/project/java/Settings.java b/project/java/Settings.java index 8465153c5..00da9873d 100644 --- a/project/java/Settings.java +++ b/project/java/Settings.java @@ -2356,6 +2356,7 @@ class Settings static void Apply(Activity p) { + nativeSetVideoDepth(Globals.VideoDepthBpp); if(Globals.SmoothVideo) nativeSetSmoothVideo(); if( Globals.CompatibilityHacks ) @@ -2488,6 +2489,7 @@ class Settings private static native void nativeSetMultitouchUsed(); private static native void nativeSetTouchscreenKeyboardUsed(); private static native void nativeSetSmoothVideo(); + private static native void nativeSetVideoDepth(int bpp); private static native void nativeSetCompatibilityHacks(); private static native void nativeSetVideoMultithreaded(); private static native void nativeSetupScreenKeyboard(int size, int drawsize, int theme, int nbuttonsAutoFire, int transparency); diff --git a/project/java/Video.java b/project/java/Video.java index 153599b2f..6ca8b3227 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -444,7 +444,7 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL { super(context); mParent = context; touchInput = DifferentTouchInput.getInstance(); - setEGLConfigChooser(Globals.NeedDepthBuffer); + setEGLConfigChooser(Globals.VideoDepthBpp, Globals.NeedDepthBuffer, Globals.NeedStencilBuffer, Globals.NeedGles2); mRenderer = new DemoRenderer(context); setRenderer(mRenderer); } diff --git a/project/jni/application/commandergenius/AndroidAppSettings.cfg b/project/jni/application/commandergenius/AndroidAppSettings.cfg index 2b825ecc3..50a362baf 100644 --- a/project/jni/application/commandergenius/AndroidAppSettings.cfg +++ b/project/jni/application/commandergenius/AndroidAppSettings.cfg @@ -6,10 +6,13 @@ AppFullName=net.sourceforge.clonekeenplus ScreenOrientation=h InhibitSuspend=n AppDataDownloadUrl="!Data files|data.zip^High-quality GFX and music - 40 Mb|https://sourceforge.net/projects/libsdl-android/files/CommanderGenius/commandergenius-hqp-1.8.zip/download" +VideoDepthBpp=16 +NeedDepthBuffer=n +NeedStencilBuffer=n +NeedGles2=n +SwVideoMode=y SdlVideoResize=y SdlVideoResizeKeepAspect=n -NeedDepthBuffer=n -SwVideoMode=y CompatibilityHacks=n AppUsesMouse=n AppNeedsTwoButtonMouse=n diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c index 9c21cc084..0b751c523 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c @@ -77,6 +77,9 @@ static void ANDROID_VideoQuitMT(_THIS); static void ANDROID_UpdateRectsMT(_THIS, int numrects, SDL_Rect *rects); static int ANDROID_FlipHWSurfaceMT(_THIS, SDL_Surface *surface); static int ANDROID_ToggleFullScreen(_THIS, int fullscreen); +static Uint32 PixelFormatEnum = SDL_PIXELFORMAT_RGB565; +static Uint32 PixelFormatEnumAlpha = SDL_PIXELFORMAT_RGBA4444; +static Uint32 PixelFormatEnumColorkey = SDL_PIXELFORMAT_RGBA5551; // Stubs to get rid of crashing in OpenGL mode @@ -117,7 +120,6 @@ static SDL_Rect *SDL_modelist[SDL_NUMMODES+1]; //#define SDL_modelist (this->hidden->SDL_modelist) -enum { ANDROID_BYTESPERPIXEL = 2, ANDROID_BITSPERPIXEL = 16 }; typedef struct SDL_Texture private_hwdata; // Pointer to in-memory video surface @@ -212,21 +214,32 @@ int ANDROID_VideoInit(_THIS, SDL_PixelFormat *vformat) { int i; static SDL_PixelFormat alphaFormat; + int bpp; /* Determine the screen depth (use default 16-bit depth) */ /* we change this during the SDL_SetVideoMode implementation... */ if( vformat ) { - vformat->BitsPerPixel = ANDROID_BITSPERPIXEL; - vformat->BytesPerPixel = ANDROID_BYTESPERPIXEL; + vformat->BitsPerPixel = SDL_ANDROID_BITSPERPIXEL; + vformat->BytesPerPixel = SDL_ANDROID_BYTESPERPIXEL; + } + + if( SDL_ANDROID_BITSPERPIXEL == 24 ) + PixelFormatEnum = SDL_PIXELFORMAT_RGB24; + if( SDL_ANDROID_BITSPERPIXEL == 32 ) + PixelFormatEnum = SDL_PIXELFORMAT_RGBA8888; + + if( SDL_ANDROID_BITSPERPIXEL >= 24 ) + { + PixelFormatEnumAlpha = SDL_PIXELFORMAT_RGBA8888; + PixelFormatEnumColorkey = SDL_PIXELFORMAT_RGBA8888; } - int bpp; SDL_memset(&alphaFormat, 0, sizeof(alphaFormat)); - SDL_PixelFormatEnumToMasks( SDL_PIXELFORMAT_RGBA4444, &bpp, + SDL_PixelFormatEnumToMasks( PixelFormatEnumAlpha, &bpp, &alphaFormat.Rmask, &alphaFormat.Gmask, &alphaFormat.Bmask, &alphaFormat.Amask ); - alphaFormat.BitsPerPixel = ANDROID_BITSPERPIXEL; - alphaFormat.BytesPerPixel = ANDROID_BYTESPERPIXEL; + alphaFormat.BitsPerPixel = SDL_ANDROID_BITSPERPIXEL; + alphaFormat.BytesPerPixel = SDL_ANDROID_BYTESPERPIXEL; this->displayformatalphapixel = &alphaFormat; this->info.hw_available = 1; @@ -269,7 +282,7 @@ int ANDROID_VideoInit(_THIS, SDL_PixelFormat *vformat) SDL_Rect **ANDROID_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) { - if(format->BitsPerPixel != ANDROID_BITSPERPIXEL) + if(format->BitsPerPixel != SDL_ANDROID_BITSPERPIXEL) return NULL; return SDL_modelist; } @@ -280,7 +293,7 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, SDL_PixelFormat format; int bpp1; - __android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_SetVideoMode(): application requested mode %dx%d OpenGL %d HW %d", width, height, flags & SDL_OPENGL, flags & SDL_HWSURFACE); + __android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_SetVideoMode(): application requested mode %dx%d OpenGL %d HW %d BPP %d", width, height, flags & SDL_OPENGL, flags & SDL_HWSURFACE, SDL_ANDROID_BITSPERPIXEL); if( ! SDL_ANDROID_InsideVideoThread() ) { __android_log_print(ANDROID_LOG_INFO, "libSDL", "Error: calling %s not from the main thread!", __PRETTY_FUNCTION__); @@ -295,7 +308,7 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, current->flags = (flags & SDL_FULLSCREEN) | (flags & SDL_OPENGL) | SDL_DOUBLEBUF | ( flags & SDL_HWSURFACE ); current->w = width; current->h = height; - current->pitch = SDL_ANDROID_sFakeWindowWidth * ANDROID_BYTESPERPIXEL; + current->pitch = SDL_ANDROID_sFakeWindowWidth * SDL_ANDROID_BYTESPERPIXEL; current->pixels = NULL; current->hwdata = NULL; @@ -312,7 +325,7 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, SDL_VideoWindow = SDL_CreateWindow("", 0, 0, width, height, SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL); SDL_memset(&mode, 0, sizeof(mode)); - mode.format = SDL_PIXELFORMAT_RGB565; + mode.format = PixelFormatEnum; SDL_SetWindowDisplayMode(SDL_VideoWindow, &mode); if (SDL_CreateRenderer(SDL_VideoWindow, -1, 0) < 0) { @@ -324,14 +337,14 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, current->hwdata = NULL; if( ! (flags & SDL_HWSURFACE) ) { - current->pixels = SDL_malloc(width * height * ANDROID_BYTESPERPIXEL); + current->pixels = SDL_malloc(width * height * SDL_ANDROID_BYTESPERPIXEL); if ( ! current->pixels ) { __android_log_print(ANDROID_LOG_INFO, "libSDL", "Couldn't allocate buffer for requested mode"); SDL_SetError("Couldn't allocate buffer for requested mode"); return(NULL); } - SDL_memset(current->pixels, 0, width * height * ANDROID_BYTESPERPIXEL); - current->hwdata = (struct private_hwdata *)SDL_CreateTexture(SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STATIC, width, height); + SDL_memset(current->pixels, 0, width * height * SDL_ANDROID_BYTESPERPIXEL); + current->hwdata = (struct private_hwdata *)SDL_CreateTexture(PixelFormatEnum, SDL_TEXTUREACCESS_STATIC, width, height); if( !current->hwdata ) { __android_log_print(ANDROID_LOG_INFO, "libSDL", "Couldn't allocate texture for SDL_CurrentVideoSurface"); SDL_free(current->pixels); @@ -354,13 +367,13 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, /* Allocate the new pixel format for the screen */ SDL_memset(&format, 0, sizeof(format)); - SDL_PixelFormatEnumToMasks( SDL_PIXELFORMAT_RGB565, &bpp1, + SDL_PixelFormatEnumToMasks( PixelFormatEnum, &bpp1, &format.Rmask, &format.Gmask, &format.Bmask, &format.Amask ); format.BitsPerPixel = bpp1; - format.BytesPerPixel = ANDROID_BYTESPERPIXEL; + format.BytesPerPixel = SDL_ANDROID_BYTESPERPIXEL; - if ( ! SDL_ReallocFormat(current, ANDROID_BITSPERPIXEL, format.Rmask, format.Gmask, format.Bmask, format.Amask) ) { + if ( ! SDL_ReallocFormat(current, SDL_ANDROID_BITSPERPIXEL, format.Rmask, format.Gmask, format.Bmask, format.Amask) ) { __android_log_print(ANDROID_LOG_INFO, "libSDL", "Couldn't allocate new pixel format for requested mode"); SDL_SetError("Couldn't allocate new pixel format for requested mode"); return(NULL); @@ -437,14 +450,13 @@ static int ANDROID_AllocHWSurface(_THIS, SDL_Surface *surface) return(-1); DEBUGOUT("ANDROID_AllocHWSurface() surface %p w %d h %d", surface, surface->w, surface->h); - Uint32 format = SDL_PIXELFORMAT_RGBA5551; // 1-bit alpha for color key, every surface will have colorkey so it's easier for us + Uint32 format = PixelFormatEnumColorkey; // 1-bit alpha for color key, every surface will have colorkey so it's easier for us if( surface->format->Amask ) { SDL_PixelFormat format1; int bpp; - format = SDL_PIXELFORMAT_RGBA4444; - DEBUGOUT("ANDROID_AllocHWSurface() SDL_PIXELFORMAT_RGBA4444"); - SDL_memset(&format1, 0, sizeof(format1)); + format = PixelFormatEnumAlpha; + SDL_memset(&format1, 0, sizeof(format1)); SDL_PixelFormatEnumToMasks( format, &bpp, &format1.Rmask, &format1.Gmask, &format1.Bmask, &format1.Amask ); @@ -457,7 +469,6 @@ static int ANDROID_AllocHWSurface(_THIS, SDL_Surface *surface) } else { - DEBUGOUT("ANDROID_AllocHWSurface() SDL_PIXELFORMAT_RGBA5551"); // HW-accel surface should be RGB565 if( !( SDL_CurrentVideoSurface->format->BitsPerPixel == surface->format->BitsPerPixel && SDL_CurrentVideoSurface->format->Rmask == surface->format->Rmask && @@ -557,7 +568,7 @@ static int ANDROID_LockHWSurface(_THIS, SDL_Surface *surface) if( ! SDL_CurrentVideoSurface->pixels ) { glPixelStorei(GL_PACK_ALIGNMENT, 1); - SDL_CurrentVideoSurface->pixels = SDL_malloc(SDL_ANDROID_sFakeWindowWidth * SDL_ANDROID_sFakeWindowHeight * ANDROID_BYTESPERPIXEL); + SDL_CurrentVideoSurface->pixels = SDL_malloc(SDL_ANDROID_sFakeWindowWidth * SDL_ANDROID_sFakeWindowHeight * SDL_ANDROID_BYTESPERPIXEL); if ( ! SDL_CurrentVideoSurface->pixels ) { __android_log_print(ANDROID_LOG_INFO, "libSDL", "Couldn't allocate buffer for SDL_CurrentVideoSurface"); SDL_SetError("Couldn't allocate buffer for SDL_CurrentVideoSurface"); @@ -566,7 +577,7 @@ static int ANDROID_LockHWSurface(_THIS, SDL_Surface *surface) } if( ! SDL_CurrentVideoSurface->hwdata ) { - SDL_CurrentVideoSurface->hwdata = (struct private_hwdata *)SDL_CreateTexture(SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STATIC, SDL_ANDROID_sFakeWindowWidth, SDL_ANDROID_sFakeWindowHeight); + SDL_CurrentVideoSurface->hwdata = (struct private_hwdata *)SDL_CreateTexture(PixelFormatEnum, SDL_TEXTUREACCESS_STATIC, SDL_ANDROID_sFakeWindowWidth, SDL_ANDROID_sFakeWindowHeight); if( !SDL_CurrentVideoSurface->hwdata ) { __android_log_print(ANDROID_LOG_INFO, "libSDL", "Couldn't allocate texture for SDL_CurrentVideoSurface"); SDL_OutOfMemory(); @@ -585,6 +596,7 @@ static int ANDROID_LockHWSurface(_THIS, SDL_Surface *surface) for(y=0; yformat->Amask ) - hwformat = SDL_PIXELFORMAT_RGBA4444; + hwformat = PixelFormatEnumAlpha; if( surface == SDL_CurrentVideoSurface ) // Special case - hwformat = SDL_PIXELFORMAT_RGB565; + hwformat = PixelFormatEnum; /* Allocate the new pixel format for the screen */ SDL_memset(&format, 0, sizeof(format)); SDL_PixelFormatEnumToMasks( hwformat, &bpp, &format.Rmask, &format.Gmask, &format.Bmask, &format.Amask ); - format.BytesPerPixel = ANDROID_BYTESPERPIXEL; + format.BytesPerPixel = SDL_ANDROID_BYTESPERPIXEL; format.BitsPerPixel = bpp; + // TODO: support 24bpp and 32bpp if( format.BitsPerPixel == surface->format->BitsPerPixel && format.Rmask == surface->format->Rmask && format.Gmask == surface->format->Gmask && format.Bmask == surface->format->Bmask && format.Amask == surface->format->Amask ) { - DEBUGOUT("ANDROID_UnlockHWSurface() no conversion"); converted = surface; // No need for conversion } else @@ -963,11 +975,11 @@ void SDL_ANDROID_VideoContextRecreated() for( i = 0; i < HwSurfaceCount; i++ ) { // Allocate HW texture - Uint32 format = SDL_PIXELFORMAT_RGBA5551; // 1-bit alpha for color key, every surface will have colorkey so it's easier for us + Uint32 format = PixelFormatEnumColorkey; // 1-bit alpha for color key, every surface will have colorkey so it's easier for us if( HwSurfaceList[i]->format->Amask ) - format = SDL_PIXELFORMAT_RGBA4444; + format = PixelFormatEnumAlpha; if( HwSurfaceList[i] == SDL_CurrentVideoSurface ) - format = SDL_PIXELFORMAT_RGB565; + format = PixelFormatEnum; HwSurfaceList[i]->hwdata = (struct private_hwdata *)SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, HwSurfaceList[i]->w, HwSurfaceList[i]->h); if( !HwSurfaceList[i]->hwdata ) { diff --git a/project/jni/sdl-1.3/src/video/SDL_renderer_gles.c b/project/jni/sdl-1.3/src/video/SDL_renderer_gles.c index d0f149ec9..e176eee37 100644 --- a/project/jni/sdl-1.3/src/video/SDL_renderer_gles.c +++ b/project/jni/sdl-1.3/src/video/SDL_renderer_gles.c @@ -133,8 +133,7 @@ SDL_RenderDriver GL_ES_RenderDriver = { SDL_PIXELFORMAT_RGBA5551, SDL_PIXELFORMAT_RGB565, SDL_PIXELFORMAT_RGB24, - SDL_PIXELFORMAT_BGR888, - SDL_PIXELFORMAT_ABGR8888}, + SDL_PIXELFORMAT_RGBA8888}, 0, 0} }; diff --git a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c index 4d3257545..beae09073 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c +++ b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c @@ -68,6 +68,9 @@ static int showScreenKeyboardSendBackspace = 0; int SDL_ANDROID_SmoothVideo = 0; int SDL_ANDROID_VideoMultithreaded = 0; int SDL_ANDROID_CompatibilityHacks = 0; +int SDL_ANDROID_BYTESPERPIXEL = 2; +int SDL_ANDROID_BITSPERPIXEL = 16; + static void appPutToBackgroundCallbackDefault(void) { @@ -306,3 +309,10 @@ JAVA_EXPORT_NAME(Settings_nativeSetCompatibilityHacks) (JNIEnv* env, jobject thi { SDL_ANDROID_CompatibilityHacks = 1; } + +JNIEXPORT void JNICALL +JAVA_EXPORT_NAME(Settings_nativeSetVideoDepth) (JNIEnv* env, jobject thiz, jint bpp) +{ + SDL_ANDROID_BITSPERPIXEL = bpp; + SDL_ANDROID_BYTESPERPIXEL = SDL_ANDROID_BITSPERPIXEL / 8; +} diff --git a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h index 93adea392..9f25208dc 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h +++ b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h @@ -41,6 +41,8 @@ extern int SDL_ANDROID_TouchscreenCalibrationY; extern int SDL_ANDROID_SmoothVideo; extern int SDL_ANDROID_VideoMultithreaded; extern int SDL_ANDROID_CompatibilityHacks; +extern int SDL_ANDROID_BYTESPERPIXEL; +extern int SDL_ANDROID_BITSPERPIXEL; extern void SDL_ANDROID_TextInputInit(char * buffer, int len); extern void SDL_ANDROID_TextInputFinished(); extern SDL_Surface *SDL_CurrentVideoSurface; diff --git a/readme.txt b/readme.txt index 7ed258f58..d1163edea 100644 --- a/readme.txt +++ b/readme.txt @@ -52,13 +52,12 @@ You may find quick Android game porting manual at http://anddev.at.ua/src/portin If you're porting existing app which uses SDL 1.2 please always use SW mode: neither SDL_SetVideoMode() call nor SDL_CreateRGBSurface() etc functions shall contain SDL_HWSURFACE flags. -The BPP in SDL_SetVideoMode() shall be set to 16, and audio format - to AUDIO_S8 or AUDIO_S16. +The BPP in SDL_SetVideoMode() shall be set to the same value you've specified in ChangeAppSettings.sh, +and audio format - to AUDIO_S8 or AUDIO_S16. -The native Android pixel format is RGB_565, even for OpenGL, not BGR_565 as all other OpenGL implementations have. +The native Android 16-bit pixel format is RGB_565, even for OpenGL, not BGR_565 as all other OpenGL implementations have. -Colorkey images are supported using RGBA_5551 pixelformat with 1-bit alpha - -SDL does conversion internally, for you they are just RGB_565 surfaces. -Alpha surfaces have RGBA_4444 format. SDL_RLEACCEL is not supported. +Colorkey surfaces and alpha surfaces are supported, SDL_RLEACCEL is not supported. To compile your own app, put your app sources into project/jni/application dir (or create symlink to them), and change symlink "src" to point to your app: @@ -98,7 +97,8 @@ SDL_ListModes()[0] will always return native screen resolution. Also make sure that your HW textures are not wider than 1024 pixels, or it will fail to allocate such texture on HTC G1, and other low-end devices. Software surfaces may be of any size of course. -If you want HW acceleration there are some limitations: +If you want HW acceleration - just use OpenGL, the HW acceleration by SDL has some limitations: +You should use 16-bit color depth. You cannot blit SW surface to screen, it should be only HW surface. You can use colorkey, per-surface alpha and per-pixel alpha with HW surfaces. If you're using SDL 1.3 always use SDL_Texture, if you'll be using SDL_Surface with SDL 1.3 it will switch to SW mode.