Refactor Framebuffer attachment application.

Instead of passing texture and renderbufer IDs which requires a call to
gl::getNonLostContext to resolve the objects, pass the Texture and Renderbuffer
objects directly.

BUG=angleproject:733

Change-Id: Ia500a781643e43a17c8e9cea9f95847a7ff7b25d
Reviewed-on: https://chromium-review.googlesource.com/228280
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libGLESv2/libGLESv2.cpp b/src/libGLESv2/libGLESv2.cpp
index a585127..6f4c20d 100644
--- a/src/libGLESv2/libGLESv2.cpp
+++ b/src/libGLESv2/libGLESv2.cpp
@@ -1595,28 +1595,14 @@
         gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
         ASSERT(framebuffer);
 
-        if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
+        if (renderbuffer != 0)
         {
-            unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
-            framebuffer->setColorbuffer(colorAttachment, GL_RENDERBUFFER, renderbuffer, 0, 0);
+            gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
+            framebuffer->setRenderbufferAttachment(attachment, renderbufferObject);
         }
         else
         {
-            switch (attachment)
-            {
-              case GL_DEPTH_ATTACHMENT:
-                framebuffer->setDepthbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
-                break;
-              case GL_STENCIL_ATTACHMENT:
-                framebuffer->setStencilbuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
-                break;
-              case GL_DEPTH_STENCIL_ATTACHMENT:
-                framebuffer->setDepthStencilBuffer(GL_RENDERBUFFER, renderbuffer, 0, 0);
-                break;
-              default:
-                UNREACHABLE();
-                break;
-            }
+            framebuffer->setNULLAttachment(attachment);
         }
     }
 }
@@ -1634,27 +1620,18 @@
             return;
         }
 
-        if (texture == 0)
-        {
-            textarget = GL_NONE;
-        }
-
         gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
         ASSERT(framebuffer);
 
-        if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
+        if (texture != 0)
         {
-            const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
-            framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, 0);
+            gl::Texture *textureObj = context->getTexture(texture);
+            gl::ImageIndex index(textarget, level, gl::ImageIndex::ENTIRE_LEVEL);
+            framebuffer->setTextureAttachment(attachment, textureObj, index);
         }
         else
         {
-            switch (attachment)
-            {
-              case GL_DEPTH_ATTACHMENT:         framebuffer->setDepthbuffer(textarget, texture, level, 0);        break;
-              case GL_STENCIL_ATTACHMENT:       framebuffer->setStencilbuffer(textarget, texture, level, 0);      break;
-              case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, 0); break;
-            }
+            framebuffer->setNULLAttachment(attachment);
         }
     }
 }
@@ -5853,22 +5830,15 @@
         gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
         ASSERT(framebuffer);
 
-        gl::Texture *textureObject = context->getTexture(texture);
-        GLenum textarget = textureObject ? textureObject->getTarget() : GL_NONE;
-
-        if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
+        if (texture != 0)
         {
-            const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
-            framebuffer->setColorbuffer(colorAttachment, textarget, texture, level, layer);
+            gl::Texture *textureObject = context->getTexture(texture);
+            gl::ImageIndex index(textureObject->getTarget(), level, layer);
+            framebuffer->setTextureAttachment(attachment, textureObject, index);
         }
         else
         {
-            switch (attachment)
-            {
-              case GL_DEPTH_ATTACHMENT:         framebuffer->setDepthbuffer(textarget, texture, level, layer);        break;
-              case GL_STENCIL_ATTACHMENT:       framebuffer->setStencilbuffer(textarget, texture, level, layer);      break;
-              case GL_DEPTH_STENCIL_ATTACHMENT: framebuffer->setDepthStencilBuffer(textarget, texture, level, layer); break;
-            }
+            framebuffer->setNULLAttachment(attachment);
         }
     }
 }