2012-07-02 56 views
4

我有EGL/GLES 2.0代碼,我嘗試在Linux(通過Mesa)和Android(iOS來)上運行。在Linux上,它工作正常,並呈現像預期的一樣。 在Android上運行(手機,平板電腦和模擬器 - 全部4.01),它通過很好但沒有顯示(屏幕保持黑屏)。 所有3的代碼都是99% - 對於Android有一些特殊處理。 繼我EGL屬性:EGL在Linux上工作,但不在Android上

EGLint attribList[] = 
{ 
    EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 
    EGL_RED_SIZE,  8, 
    EGL_GREEN_SIZE,  8, 
    EGL_BLUE_SIZE,  8, 
    //EGL_ALPHA_SIZE,  (flags & ES_WINDOW_ALPHA) ? 8 : EGL_DONT_CARE, 
    //EGL_DEPTH_SIZE,  (flags & ES_WINDOW_DEPTH) ? 8 : EGL_DONT_CARE, 
    //EGL_STENCIL_SIZE, (flags & ES_WINDOW_STENCIL) ? 8 : EGL_DONT_CARE, 
    EGL_SAMPLE_BUFFERS, (flags & ES_WINDOW_MULTISAMPLE) ? 1 : 0, 
    // For Android this is extremely important - eglCreateContext will fail without it 
    EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 
    EGL_NONE, EGL_NONE 
}; 

繼EGL創建代碼:

EGLint numConfigs; 
EGLint majorVersion; 
EGLint minorVersion; 
EGLDisplay display; 
EGLContext context; 
EGLSurface surface; 
EGLConfig config; 
EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE }; 

// Get Display 
display = eglGetDisplay((EGLNativeDisplayType)x_display); 
if (display == EGL_NO_DISPLAY) 
{ 
    esLogMessage("eglGetDisplay failed %d\n", eglGetError()); 
    return EGL_FALSE; 
} 

// Initialize EGL 
if (!eglInitialize(display, &majorVersion, &minorVersion)) 
{ 
    esLogMessage("eglInitialize failed %d\n", eglGetError()); 
    return EGL_FALSE; 
} 

static const size_t CONFIG_COUNT = 128; 
EGLConfig configs[CONFIG_COUNT]; 

// Get configs 
if (!eglGetConfigs(display, configs, CONFIG_COUNT, &numConfigs)) 
{ 
    esLogMessage("eglGetConfigs failed %d\n", eglGetError()); 
    return EGL_FALSE; 
} 
else if(numConfigs == 0) 
{ 
    esLogMessage("eglGetConfigs found no configs for the display\n"); 
    return EGL_FALSE; 
} 

EGLint chosenConfigCount = 0; 
// Choose config 
if (!eglChooseConfig(display, attribList, &config, 1, &chosenConfigCount)) 
{ 
    esLogMessage("eglChooseConfig failed %d\n", eglGetError()); 
    return EGL_FALSE; 
} 
else if(chosenConfigCount == 0) 
{ 
    esLogMessage("eglChooseConfig found no matching configs (%d available)\n", numConfigs); 
    return EGL_FALSE; 
} 

EGLint format; 
/* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is 
* guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). 
* As soon as we picked a EGLConfig, we can safely reconfigure the 
* ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ 
if(!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format)) 
{ 
    esLogMessage("eglGetConfigAttrib failed %d\n", eglGetError()); 
    return EGL_FALSE; 
} 

#ifdef ANDROID 

if(ANativeWindow_setBuffersGeometry(hWnd, 0, 0, format)) 
{ 
    esLogMessage("ANativeWindow_setBuffersGeometry failed\n"); 
    return EGL_FALSE; 
} 

#endif 

// Create a surface 
surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)hWnd, NULL); 
if (surface == EGL_NO_SURFACE) 
{ 
    esLogMessage("eglCreateWindowSurface failed %d\n", eglGetError()); 
    return EGL_FALSE; 
} 

// Create a GL context 
context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs); 
if (context == EGL_NO_CONTEXT) 
{ 
    esLogMessage("eglCreateContext failed %d\n", eglGetError()); 
    return EGL_FALSE; 
} 

// Make the context current 
if (!eglMakeCurrent(display, surface, surface, context)) 
{ 
    esLogMessage("eglMakeCurrent failed %d\n", eglGetError()); 
    return EGL_FALSE; 
} 

可能有人流下了光,測試什麼,或者如何發現問題?

編輯:

我修正了一些其他錯誤,它現在在Android模擬器和惠普TouchPad(的CyanogenMod 9阿爾法)工作正常,但仍然會導致黑屏我三星Galaxy S1Cyanogenmod 9 *嘆*。

+0

你試過glGetError嗎? – Tim

+1

你使用真正的android設備或模擬器?如果模擬器,這個鏈接可以幫助你:http://www.androidng.com/how-to-boost-speedup-android-emulator – chrisendymion

+1

什麼是'x_display'?您通常希望將EGL_DEFAULT_DISPLAY傳遞給eglGetDisplay()。 –

回答

0

首先,只需要說一句:您不需要兩個EGL_NONE來結束屬性定義。

其次,您的問題來自於eglGetConfigs()返回可用配置的事實,但eglChooseConfig(...,1,..)不一定會返回與您請求的配置完全匹配的配置。 因此,您必須掃描配置以找到最接近您的需求的配置。

你必須調用eglGetConfigAttrib()比較,例如,EGL_RED_SIZEEGL_GREEN_SIZEEGL_BLUE_SIZEEGL_ALPHA_SIZEEGL_RENDERABLE_TYPEEGL_DEPTH_SIZEEGL_STENCIL_SIZE

查看eglChooseConfig()瞭解更多詳情。

相關問題