Implements glRenderbufferMultisampleStorage
TRAC #12714
Signed-off-by: Nicolas Capens
Signed-off-by: Daniel Koch

Author:    Shannon Woods

git-svn-id: https://angleproject.googlecode.com/svn/trunk@390 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/Renderbuffer.cpp b/src/libGLESv2/Renderbuffer.cpp
index e7fbe62..0eb4637 100644
--- a/src/libGLESv2/Renderbuffer.cpp
+++ b/src/libGLESv2/Renderbuffer.cpp
@@ -146,6 +146,11 @@
     return mD3DFormat;
 }
 
+GLsizei RenderbufferStorage::getSamples() const
+{
+    return mSamples;
+}
+
 unsigned int RenderbufferStorage::getSerial() const
 {
     return mSerial;
@@ -167,25 +172,34 @@
 
         setSize(description.Width, description.Height);
         mD3DFormat = description.Format;
+        mSamples = es2dx::GetSamplesFromMultisampleType(description.MultiSampleType);
     }
     else
     {
         mD3DFormat = D3DFMT_UNKNOWN;
+        mSamples = 0;
     }
-
 }
 
-Colorbuffer::Colorbuffer(int width, int height, GLenum format)
+Colorbuffer::Colorbuffer(int width, int height, GLenum format, GLsizei samples)
 {
     IDirect3DDevice9 *device = getDevice();
 
     mRenderTarget = NULL;
     D3DFORMAT requestedFormat = es2dx::ConvertRenderbufferFormat(format);
+    int supportedSamples = getContext()->getNearestSupportedSamples(requestedFormat, samples);
+
+    if (supportedSamples == -1)
+    {
+        error(GL_OUT_OF_MEMORY);
+
+        return;
+    }
 
     if (width > 0 && height > 0)
     {
         HRESULT result = device->CreateRenderTarget(width, height, requestedFormat, 
-                                                    D3DMULTISAMPLE_NONE, 0, FALSE, &mRenderTarget, NULL);
+                                                    es2dx::GetMultisampleTypeFromSamples(supportedSamples), 0, FALSE, &mRenderTarget, NULL);
 
         if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
         {
@@ -202,12 +216,14 @@
         setSize(width, height);
         mFormat = format;
         mD3DFormat = requestedFormat;
+        mSamples = supportedSamples;
     }
     else
     {
         setSize(0, 0);
         mFormat = GL_RGBA4;
         mD3DFormat = D3DFMT_UNKNOWN;
+        mSamples = 0;
     }
 }
 
@@ -291,21 +307,34 @@
         depthStencil->GetDesc(&description);
 
         setSize(description.Width, description.Height);
-        mFormat = (description.Format == D3DFMT_D16 ? GL_DEPTH_COMPONENT16 : GL_DEPTH24_STENCIL8_OES); 
+        mFormat = (description.Format == D3DFMT_D16 ? GL_DEPTH_COMPONENT16 : GL_DEPTH24_STENCIL8_OES);
+        mSamples = es2dx::GetSamplesFromMultisampleType(description.MultiSampleType); 
         mD3DFormat = description.Format;
     }
     else
     {
-        mD3DFormat = D3DFMT_UNKNOWN;
+        mD3DFormat = D3DFMT_UNKNOWN; 
+        mSamples = 0;
     }
 }
 
-DepthStencilbuffer::DepthStencilbuffer(int width, int height)
+DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples)
 {
     IDirect3DDevice9 *device = getDevice();
 
     mDepthStencil = NULL;
-    HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &mDepthStencil, 0);
+    
+    int supportedSamples = getContext()->getNearestSupportedSamples(D3DFMT_D24S8, samples);
+
+    if (supportedSamples == -1)
+    {
+        error(GL_OUT_OF_MEMORY);
+
+        return;
+    }
+
+    HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, es2dx::GetMultisampleTypeFromSamples(supportedSamples),
+                                                       0, FALSE, &mDepthStencil, 0);
 
     if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
     {
@@ -319,14 +348,16 @@
     if (mDepthStencil)
     {
         setSize(width, height);
-        mFormat = GL_DEPTH24_STENCIL8_OES;  
+        mFormat = GL_DEPTH24_STENCIL8_OES;
         mD3DFormat = D3DFMT_D24S8;
+        mSamples = supportedSamples;
     }
     else
     {
         setSize(0, 0);
         mFormat = GL_RGBA4; //default format
         mD3DFormat = D3DFMT_UNKNOWN;
+        mSamples = 0;
     }
 }
 
@@ -389,7 +420,7 @@
     }
 }
 
-Depthbuffer::Depthbuffer(int width, int height) : DepthStencilbuffer(width, height)
+Depthbuffer::Depthbuffer(int width, int height, GLsizei samples) : DepthStencilbuffer(width, height, samples)
 {
     if (getDepthStencil())
     {
@@ -427,7 +458,7 @@
     }
 }
 
-Stencilbuffer::Stencilbuffer(int width, int height) : DepthStencilbuffer(width, height)
+Stencilbuffer::Stencilbuffer(int width, int height, GLsizei samples) : DepthStencilbuffer(width, height, samples)
 {
     if (getDepthStencil())
     {