Skip drawing to a zero-area render target
TRAC #12172
This also generates a GL_INVALID_FRAMEBUFFER_OPERATION error when glClear attempt to operate on an invalid or incomplete framebuffer.
Signed-off-by: Shannon Woods
Signed-off-by: Daniel Koch

Author:    Nicolas Capens

git-svn-id: https://angleproject.googlecode.com/svn/trunk@241 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/Context.cpp b/src/libGLESv2/Context.cpp
index 0d87a7e..9483680 100644
--- a/src/libGLESv2/Context.cpp
+++ b/src/libGLESv2/Context.cpp
@@ -1479,6 +1479,8 @@
 
     if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE)
     {
+        error(GL_INVALID_FRAMEBUFFER_OPERATION);
+
         return false;
     }
 
@@ -1511,6 +1513,11 @@
         viewport.MaxZ = clamp01(mState.zFar);
     }
 
+    if (viewport.Width <= 0 || viewport.Height <= 0)
+    {
+        return false;   // Nothing to render
+    }
+
     device->SetViewport(&viewport);
 
     if (mState.scissorTest)
@@ -1999,6 +2006,15 @@
 
 void Context::clear(GLbitfield mask)
 {
+    Framebuffer *framebufferObject = getFramebuffer();
+
+    if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE)
+    {
+        error(GL_INVALID_FRAMEBUFFER_OPERATION);
+
+        return;
+    }
+
     egl::Display *display = getDisplay();
     IDirect3DDevice9 *device = getDevice();
     DWORD flags = 0;
@@ -2018,7 +2034,6 @@
         }
     }
 
-    Framebuffer *framebufferObject = getFramebuffer();
     IDirect3DSurface9 *depthStencil = framebufferObject->getDepthStencil();
 
     GLuint stencilUnmasked = 0x0;
@@ -2043,7 +2058,10 @@
         return error(GL_INVALID_VALUE);
     }
 
-    applyRenderTarget(true);   // Clips the clear to the scissor rectangle but not the viewport
+    if (!applyRenderTarget(true))   // Clips the clear to the scissor rectangle but not the viewport
+    {
+        return;
+    }
 
     D3DCOLOR color = D3DCOLOR_ARGB(unorm<8>(mState.colorClearValue.alpha), 
                                             unorm<8>(mState.colorClearValue.red), 
@@ -2177,7 +2195,7 @@
 
     if (!applyRenderTarget(false))
     {
-        return error(GL_INVALID_FRAMEBUFFER_OPERATION);
+        return;
     }
 
     applyState(mode);
@@ -2224,7 +2242,7 @@
 
     if (!applyRenderTarget(false))
     {
-        return error(GL_INVALID_FRAMEBUFFER_OPERATION);
+        return;
     }
 
     applyState(mode);