From 8ec69cad99dc499637625d2e021c163f991d2ccb Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Wed, 25 Sep 2013 14:14:27 +0300 Subject: EglMacApi: Make sure that some returned EGL configs have alpha == 0 This is what the pixel format attribute lists in MacPixelFormatsAttribs.m try to achieve, but despite this, alpha is nonzero in every returned configuration on certain (all?) machines (at least on 10.8.5 on a nvidia gpu). This means that EGL won't return any configs at all with alpha == 0. The default config chooser in GLSurfaceView requires a config with alpha == 0. This means that previously, this view failed to start up on the emulator on OS X, unless set up with a non-default config chooser. Change-Id: I2bf3e92a026c525a97d6746e491d920ce127787f --- .../opengl/host/libs/Translator/EGL/EglMacApi.cpp | 10 +++++++- .../opengl/host/libs/Translator/EGL/MacNative.h | 1 + .../opengl/host/libs/Translator/EGL/MacNative.m | 28 ++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) (limited to 'emulator/opengl/host/libs/Translator') diff --git a/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp b/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp index 31527af..eeaa25c 100644 --- a/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp +++ b/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp @@ -68,7 +68,15 @@ static EglConfig* pixelFormatToConfig(int index,int renderableType,EGLNativePixe getPixelFormatAttrib(*frmt,MAC_SAMPLES_PER_PIXEL,&samples); getPixelFormatAttrib(*frmt,MAC_COLOR_SIZE,&colorSize); - getPixelFormatAttrib(*frmt,MAC_ALPHA_SIZE,&alpha); + /* All configs can end up having an alpha channel even if none was requested. + * The default config chooser in GLSurfaceView will therefore not find any + * matching config. Thus, make sure alpha is zero (or at least signalled as + * zero to the calling EGL layer) for the configs where it was intended to + * be zero. */ + if (getPixelFormatDefinitionAlpha(index) == 0) + alpha = 0; + else + getPixelFormatAttrib(*frmt,MAC_ALPHA_SIZE,&alpha); getPixelFormatAttrib(*frmt,MAC_DEPTH_SIZE,&depth); getPixelFormatAttrib(*frmt,MAC_STENCIL_SIZE,&stencil); diff --git a/emulator/opengl/host/libs/Translator/EGL/MacNative.h b/emulator/opengl/host/libs/Translator/EGL/MacNative.h index 82ab667..c8a1df2 100644 --- a/emulator/opengl/host/libs/Translator/EGL/MacNative.h +++ b/emulator/opengl/host/libs/Translator/EGL/MacNative.h @@ -33,6 +33,7 @@ extern "C"{ int getNumPixelFormats(); void* getPixelFormat(int i); +int getPixelFormatDefinitionAlpha(int i); void getPixelFormatAttrib(void* pixelFormat,int attrib,int* val); void* nsCreateContext(void* format,void* share); void nsWindowMakeCurrent(void* context,void* nativeWin); diff --git a/emulator/opengl/host/libs/Translator/EGL/MacNative.m b/emulator/opengl/host/libs/Translator/EGL/MacNative.m index 6828655..a2cea93 100644 --- a/emulator/opengl/host/libs/Translator/EGL/MacNative.m +++ b/emulator/opengl/host/libs/Translator/EGL/MacNative.m @@ -75,6 +75,34 @@ void* getPixelFormat(int i){ return [[NSOpenGLPixelFormat alloc] initWithAttributes:attrib_lists[i]]; } +int getPixelFormatDefinitionAlpha(int i) { + int size; + NSOpenGLPixelFormatAttribute** attrib_lists = getPixelFormatsAttributes(&size); + NSOpenGLPixelFormatAttribute* attribs = attrib_lists[i]; + while (*attribs) { + switch (*attribs) { + // These are the ones that take a value, according to the current + // NSOpenGLPixelFormat docs + case NSOpenGLPFAAuxBuffers: + case NSOpenGLPFAColorSize: + case NSOpenGLPFADepthSize: + case NSOpenGLPFAStencilSize: + case NSOpenGLPFAAccumSize: + case NSOpenGLPFARendererID: + case NSOpenGLPFAScreenMask: + attribs += 2; + break; + case NSOpenGLPFAAlphaSize: + return attribs[1]; + break; + // All other attributes are boolean attributes that don't take a value + default: + attribs++; + } + } + return 0; +} + void getPixelFormatAttrib(void* pixelFormat,int attrib,int* val){ NSOpenGLPixelFormat *frmt = (NSOpenGLPixelFormat *)pixelFormat; [frmt getValues:val forAttribute:attrib forVirtualScreen:0]; -- cgit v1.1