Work around a y-invert bug on Macs w/ Intel GPU
On Macs running OS X 10.6 and 10.7 with Intel HD Graphics 3000, some screens or parts of the screen are displayed upside down. The exact conditions/sequence that triggers this aren't known yet; I haven't been able to reproduce it in a standalone test. This also means I don't know whether it is a driver bug, or a bug in the OpenglRender or Translator code that just happens to work elsewhere. Thanks to zhiyuan.li@intel.com for a patch this change is based on. Change-Id: I04823773818d3b587a6951be48e70b03804b33d0
This commit is contained in:
@@ -113,8 +113,21 @@ ColorBuffer::ColorBuffer() :
|
||||
m_tex(0),
|
||||
m_eglImage(NULL),
|
||||
m_fbo(0),
|
||||
m_internalFormat(0)
|
||||
m_internalFormat(0),
|
||||
m_warYInvertBug(false)
|
||||
{
|
||||
#if __APPLE__
|
||||
// On Macs running OS X 10.6 and 10.7 with Intel HD Graphics 3000, some
|
||||
// screens or parts of the screen are displayed upside down. The exact
|
||||
// conditions/sequence that triggers this aren't known yet; I haven't
|
||||
// been able to reproduce it in a standalone test. This way of enabling the
|
||||
// workaround will break if it is a driver bug (rather than a bug in this
|
||||
// code which works by accident elsewhere) and Apple/Intel release a fix for
|
||||
// it. Running a standalone test to detect the problem at runtime would be
|
||||
// more robust.
|
||||
if (strstr((const char*)s_gl.glGetString(GL_RENDERER), "Intel HD Graphics 3000"))
|
||||
m_warYInvertBug = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
ColorBuffer::~ColorBuffer()
|
||||
@@ -199,7 +212,7 @@ bool ColorBuffer::blitFromCurrentReadBuffer()
|
||||
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(!m_warYInvertBug);
|
||||
|
||||
// unbind the fbo
|
||||
s_gl.glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
|
||||
@@ -299,12 +312,12 @@ bool ColorBuffer::post()
|
||||
s_gl.glBindTexture(GL_TEXTURE_2D, m_tex);
|
||||
s_gl.glEnable(GL_TEXTURE_2D);
|
||||
s_gl.glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
drawTexQuad();
|
||||
drawTexQuad(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ColorBuffer::drawTexQuad()
|
||||
void ColorBuffer::drawTexQuad(bool flipy)
|
||||
{
|
||||
GLfloat verts[] = { -1.0f, -1.0f, 0.0f,
|
||||
-1.0f, +1.0f, 0.0f,
|
||||
@@ -316,6 +329,13 @@ void ColorBuffer::drawTexQuad()
|
||||
1.0f, 1.0f,
|
||||
1.0f, 0.0f };
|
||||
|
||||
if (!flipy) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
// swap 0.0/1.0 in second element of each tcoord vector
|
||||
tcoords[2*i + 1] = tcoords[2*i + 1] == 0.0f ? 1.0f : 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
s_gl.glClientActiveTexture(GL_TEXTURE0);
|
||||
s_gl.glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
s_gl.glTexCoordPointer(2, GL_FLOAT, 0, tcoords);
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
|
||||
private:
|
||||
ColorBuffer();
|
||||
void drawTexQuad();
|
||||
void drawTexQuad(bool flipy);
|
||||
bool bind_fbo(); // binds a fbo which have this texture as render target
|
||||
|
||||
private:
|
||||
@@ -52,6 +52,7 @@ private:
|
||||
GLuint m_height;
|
||||
GLuint m_fbo;
|
||||
GLenum m_internalFormat;
|
||||
bool m_warYInvertBug;
|
||||
};
|
||||
|
||||
typedef SmartPtr<ColorBuffer> ColorBufferPtr;
|
||||
|
||||
Reference in New Issue
Block a user