am b5588b2e: Merge "opengles emulator: fixes flashing effect on Mac"

* commit 'b5588b2e86ea7b2f19bed58f2e1078393c66fd6a':
  opengles emulator: fixes flashing effect on Mac
This commit is contained in:
David Turner
2011-08-22 04:11:15 -07:00
committed by Android Git Automerger
3 changed files with 49 additions and 10 deletions

View File

@@ -93,13 +93,13 @@ ColorBuffer *ColorBuffer::create(int p_width, int p_height,
if (fb->getCaps().has_eglimage_texture_2d) { if (fb->getCaps().has_eglimage_texture_2d) {
cb->m_eglImage = s_egl.eglCreateImageKHR(fb->getDisplay(), cb->m_eglImage = s_egl.eglCreateImageKHR(fb->getDisplay(),
fb->getContext(), s_egl.eglGetCurrentContext(),
EGL_GL_TEXTURE_2D_KHR, EGL_GL_TEXTURE_2D_KHR,
(EGLClientBuffer)cb->m_tex, (EGLClientBuffer)cb->m_tex,
NULL); NULL);
cb->m_blitEGLImage = s_egl.eglCreateImageKHR(fb->getDisplay(), cb->m_blitEGLImage = s_egl.eglCreateImageKHR(fb->getDisplay(),
fb->getContext(), s_egl.eglGetCurrentContext(),
EGL_GL_TEXTURE_2D_KHR, EGL_GL_TEXTURE_2D_KHR,
(EGLClientBuffer)cb->m_blitTex, (EGLClientBuffer)cb->m_blitTex,
NULL); NULL);
@@ -254,6 +254,8 @@ bool ColorBuffer::blitFromCurrentReadBuffer()
// render m_blitTex // render m_blitTex
s_gl.glBindTexture(GL_TEXTURE_2D, m_blitTex); s_gl.glBindTexture(GL_TEXTURE_2D, m_blitTex);
s_gl.glEnable(GL_TEXTURE_2D);
s_gl.glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
drawTexQuad(); // this will render the texture flipped drawTexQuad(); // this will render the texture flipped
// unbind the fbo // unbind the fbo
@@ -353,6 +355,7 @@ bool ColorBuffer::post()
{ {
s_gl.glBindTexture(GL_TEXTURE_2D, m_tex); s_gl.glBindTexture(GL_TEXTURE_2D, m_tex);
s_gl.glEnable(GL_TEXTURE_2D); s_gl.glEnable(GL_TEXTURE_2D);
s_gl.glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
drawTexQuad(); drawTexQuad();
return true; return true;

View File

@@ -93,7 +93,9 @@ void FrameBuffer::finalize(){
s_theFrameBuffer->m_colorbuffers.clear(); s_theFrameBuffer->m_colorbuffers.clear();
s_theFrameBuffer->m_windows.clear(); s_theFrameBuffer->m_windows.clear();
s_theFrameBuffer->m_contexts.clear(); s_theFrameBuffer->m_contexts.clear();
s_egl.eglMakeCurrent(s_theFrameBuffer->m_eglDisplay, NULL, NULL, NULL);
s_egl.eglDestroyContext(s_theFrameBuffer->m_eglDisplay,s_theFrameBuffer->m_eglContext); s_egl.eglDestroyContext(s_theFrameBuffer->m_eglDisplay,s_theFrameBuffer->m_eglContext);
s_egl.eglDestroyContext(s_theFrameBuffer->m_eglDisplay,s_theFrameBuffer->m_pbufContext);
s_egl.eglDestroySurface(s_theFrameBuffer->m_eglDisplay,s_theFrameBuffer->m_pbufSurface); s_egl.eglDestroySurface(s_theFrameBuffer->m_eglDisplay,s_theFrameBuffer->m_pbufSurface);
s_theFrameBuffer = NULL; s_theFrameBuffer = NULL;
} }
@@ -221,6 +223,23 @@ bool FrameBuffer::initialize(int width, int height)
return false; return false;
} }
//
// Create another context which shares with the eglContext to be used
// when we bind the pbuffer. That prevent switching drawable binding
// back and forth on framebuffer context.
// The main purpose of it is to solve a "blanking" behaviour we see on
// on Mac platform when switching binded drawable for a context however
// it is more efficient on other platforms as well.
//
fb->m_pbufContext = s_egl.eglCreateContext(fb->m_eglDisplay, fb->m_eglConfig,
fb->m_eglContext,
glContextAttribs);
if (fb->m_pbufContext == EGL_NO_CONTEXT) {
printf("Failed to create Pbuffer Context 0x%x\n", s_egl.eglGetError());
delete fb;
return false;
}
// //
// create a 1x1 pbuffer surface which will be used for binding // create a 1x1 pbuffer surface which will be used for binding
// the FB context. // the FB context.
@@ -329,13 +348,9 @@ bool FrameBuffer::initialize(int width, int height)
} }
// //
// Initialize some GL state // Initialize some GL state in the pbuffer context
// //
s_gl.glMatrixMode(GL_PROJECTION); fb->initGLState();
s_gl.glLoadIdentity();
s_gl.glOrthof(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
s_gl.glMatrixMode(GL_MODELVIEW);
s_gl.glLoadIdentity();
// release the FB context // release the FB context
fb->unbind_locked(); fb->unbind_locked();
@@ -353,6 +368,7 @@ FrameBuffer::FrameBuffer(int p_width, int p_height) :
m_eglDisplay(EGL_NO_DISPLAY), m_eglDisplay(EGL_NO_DISPLAY),
m_eglSurface(EGL_NO_SURFACE), m_eglSurface(EGL_NO_SURFACE),
m_eglContext(EGL_NO_CONTEXT), m_eglContext(EGL_NO_CONTEXT),
m_pbufContext(EGL_NO_CONTEXT),
m_prevContext(EGL_NO_CONTEXT), m_prevContext(EGL_NO_CONTEXT),
m_prevReadSurf(EGL_NO_SURFACE), m_prevReadSurf(EGL_NO_SURFACE),
m_prevDrawSurf(EGL_NO_SURFACE), m_prevDrawSurf(EGL_NO_SURFACE),
@@ -360,6 +376,7 @@ FrameBuffer::FrameBuffer(int p_width, int p_height) :
m_subWinDisplay(NULL), m_subWinDisplay(NULL),
m_lastPostedColorBuffer(0), m_lastPostedColorBuffer(0),
m_zRot(0.0f), m_zRot(0.0f),
m_eglContextInitialized(false),
m_statsNumFrames(0), m_statsNumFrames(0),
m_statsStartTime(0LL) m_statsStartTime(0LL)
{ {
@@ -695,7 +712,7 @@ bool FrameBuffer::bind_locked()
EGLSurface prevDrawSurf = s_egl.eglGetCurrentSurface(EGL_DRAW); EGLSurface prevDrawSurf = s_egl.eglGetCurrentSurface(EGL_DRAW);
if (!s_egl.eglMakeCurrent(m_eglDisplay, m_pbufSurface, if (!s_egl.eglMakeCurrent(m_eglDisplay, m_pbufSurface,
m_pbufSurface, m_eglContext)) { m_pbufSurface, m_pbufContext)) {
ERR("eglMakeCurrent failed\n"); ERR("eglMakeCurrent failed\n");
return false; return false;
} }
@@ -718,6 +735,14 @@ bool FrameBuffer::bindSubwin_locked()
return false; return false;
} }
//
// initialize GL state in eglContext if not yet initilaized
//
if (!m_eglContextInitialized) {
initGLState();
m_eglContextInitialized = true;
}
m_prevContext = prevContext; m_prevContext = prevContext;
m_prevReadSurf = prevReadSurf; m_prevReadSurf = prevReadSurf;
m_prevDrawSurf = prevDrawSurf; m_prevDrawSurf = prevDrawSurf;
@@ -806,3 +831,12 @@ bool FrameBuffer::repost()
} }
return false; return false;
} }
void FrameBuffer::initGLState()
{
s_gl.glMatrixMode(GL_PROJECTION);
s_gl.glLoadIdentity();
s_gl.glOrthof(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
s_gl.glMatrixMode(GL_MODELVIEW);
s_gl.glLoadIdentity();
}

View File

@@ -75,7 +75,6 @@ public:
bool repost(); bool repost();
EGLDisplay getDisplay() const { return m_eglDisplay; } EGLDisplay getDisplay() const { return m_eglDisplay; }
EGLContext getContext() const { return m_eglContext; }
EGLNativeWindowType getSubWindow() const { return m_subWin; } EGLNativeWindowType getSubWindow() const { return m_subWin; }
bool bind_locked(); bool bind_locked();
bool unbind_locked(); bool unbind_locked();
@@ -90,6 +89,7 @@ private:
~FrameBuffer(); ~FrameBuffer();
HandleType genHandle(); HandleType genHandle();
bool bindSubwin_locked(); bool bindSubwin_locked();
void initGLState();
private: private:
static FrameBuffer *s_theFrameBuffer; static FrameBuffer *s_theFrameBuffer;
@@ -109,6 +109,7 @@ private:
EGLSurface m_eglSurface; EGLSurface m_eglSurface;
EGLContext m_eglContext; EGLContext m_eglContext;
EGLSurface m_pbufSurface; EGLSurface m_pbufSurface;
EGLContext m_pbufContext;
EGLContext m_prevContext; EGLContext m_prevContext;
EGLSurface m_prevReadSurf; EGLSurface m_prevReadSurf;
@@ -118,6 +119,7 @@ private:
EGLConfig m_eglConfig; EGLConfig m_eglConfig;
HandleType m_lastPostedColorBuffer; HandleType m_lastPostedColorBuffer;
float m_zRot; float m_zRot;
bool m_eglContextInitialized;
int m_statsNumFrames; int m_statsNumFrames;
long long m_statsStartTime; long long m_statsStartTime;