Added support for more depth types
Added format arguments to DepthBuffer/DepthStencilBuffer
constructors and added existing types to type conversion
functions so that more than one depth/stencil format may
be supported.
Change-Id: Ifd60b896e93a1ba4d05a30f123a1322cdd5254a5
Reviewed-on: https://swiftshader-review.googlesource.com/4766
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/OpenGL/libGLESv2/Device.cpp b/src/OpenGL/libGLESv2/Device.cpp
index e6e8cfe..bc43c01 100644
--- a/src/OpenGL/libGLESv2/Device.cpp
+++ b/src/OpenGL/libGLESv2/Device.cpp
@@ -259,6 +259,8 @@
case FORMAT_D24FS8:
case FORMAT_D32:
case FORMAT_D16:
+ case FORMAT_D32F:
+ case FORMAT_D32F_COMPLEMENTARY:
lockable = false;
break;
// case FORMAT_S8_LOCKABLE:
@@ -267,6 +269,8 @@
// case FORMAT_D32_LOCKABLE:
case FORMAT_DF24S8:
case FORMAT_DF16S8:
+ case FORMAT_D32FS8_TEXTURE:
+ case FORMAT_D32FS8_SHADOW:
lockable = true;
break;
default:
diff --git a/src/OpenGL/libGLESv2/Renderbuffer.cpp b/src/OpenGL/libGLESv2/Renderbuffer.cpp
index 2f28509..39c9a79 100644
--- a/src/OpenGL/libGLESv2/Renderbuffer.cpp
+++ b/src/OpenGL/libGLESv2/Renderbuffer.cpp
@@ -544,15 +544,41 @@
}
}
-DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples) : mDepthStencil(nullptr)
+DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLenum requestedFormat, GLsizei samples) : mDepthStencil(nullptr)
{
+ format = requestedFormat;
+ switch(requestedFormat)
+ {
+ case GL_STENCIL_INDEX8:
+ case GL_DEPTH_COMPONENT24:
+ case GL_DEPTH24_STENCIL8_OES:
+ internalFormat = sw::FORMAT_D24S8;
+ break;
+ case GL_DEPTH32F_STENCIL8:
+ internalFormat = sw::FORMAT_D32FS8_TEXTURE;
+ break;
+ case GL_DEPTH_COMPONENT16:
+ internalFormat = sw::FORMAT_D16;
+ break;
+ case GL_DEPTH_COMPONENT32_OES:
+ internalFormat = sw::FORMAT_D32;
+ break;
+ case GL_DEPTH_COMPONENT32F:
+ internalFormat = sw::FORMAT_D32F;
+ break;
+ default:
+ UNREACHABLE(requestedFormat);
+ format = GL_DEPTH24_STENCIL8_OES;
+ internalFormat = sw::FORMAT_D24S8;
+ }
+
Device *device = getDevice();
int supportedSamples = Context::getSupportedMultisampleCount(samples);
if(width > 0 && height > 0)
{
- mDepthStencil = device->createDepthStencilSurface(width, height, sw::FORMAT_D24S8, supportedSamples, false);
+ mDepthStencil = device->createDepthStencilSurface(width, height, internalFormat, supportedSamples, false);
if(!mDepthStencil)
{
@@ -563,8 +589,6 @@
mWidth = width;
mHeight = height;
- format = GL_DEPTH24_STENCIL8_OES;
- internalFormat = sw::FORMAT_D24S8;
mSamples = supportedSamples;
}
@@ -616,14 +640,8 @@
}
}
-Depthbuffer::Depthbuffer(int width, int height, GLsizei samples) : DepthStencilbuffer(width, height, samples)
+Depthbuffer::Depthbuffer(int width, int height, GLenum format, GLsizei samples) : DepthStencilbuffer(width, height, format, samples)
{
- if(mDepthStencil)
- {
- format = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function
- // will expect one of the valid renderbuffer formats for use in
- // glRenderbufferStorage
- }
}
Depthbuffer::~Depthbuffer()
@@ -640,14 +658,8 @@
}
}
-Stencilbuffer::Stencilbuffer(int width, int height, GLsizei samples) : DepthStencilbuffer(width, height, samples)
+Stencilbuffer::Stencilbuffer(int width, int height, GLsizei samples) : DepthStencilbuffer(width, height, GL_STENCIL_INDEX8, samples)
{
- if(mDepthStencil)
- {
- format = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function
- // will expect one of the valid renderbuffer formats for use in
- // glRenderbufferStorage
- }
}
Stencilbuffer::~Stencilbuffer()
diff --git a/src/OpenGL/libGLESv2/Renderbuffer.h b/src/OpenGL/libGLESv2/Renderbuffer.h
index a4e2a20..d40d141 100644
--- a/src/OpenGL/libGLESv2/Renderbuffer.h
+++ b/src/OpenGL/libGLESv2/Renderbuffer.h
@@ -246,7 +246,7 @@
{
public:
explicit DepthStencilbuffer(egl::Image *depthStencil);
- DepthStencilbuffer(GLsizei width, GLsizei height, GLsizei samples);
+ DepthStencilbuffer(GLsizei width, GLsizei height, GLenum format, GLsizei samples);
~DepthStencilbuffer();
@@ -262,7 +262,7 @@
{
public:
explicit Depthbuffer(egl::Image *depthStencil);
- Depthbuffer(GLsizei width, GLsizei height, GLsizei samples);
+ Depthbuffer(GLsizei width, GLsizei height, GLenum format, GLsizei samples);
virtual ~Depthbuffer();
};
diff --git a/src/OpenGL/libGLESv2/libGLESv2.cpp b/src/OpenGL/libGLESv2/libGLESv2.cpp
index 0fb7c30..19db3b2 100644
--- a/src/OpenGL/libGLESv2/libGLESv2.cpp
+++ b/src/OpenGL/libGLESv2/libGLESv2.cpp
@@ -4766,7 +4766,7 @@
case GL_DEPTH_COMPONENT16:
case GL_DEPTH_COMPONENT24:
case GL_DEPTH_COMPONENT32_OES:
- context->setRenderbufferStorage(new es2::Depthbuffer(width, height, samples));
+ context->setRenderbufferStorage(new es2::Depthbuffer(width, height, internalformat, samples));
break;
case GL_R8:
case GL_R8UI:
@@ -4821,7 +4821,7 @@
}
// fall through
case GL_DEPTH24_STENCIL8_OES:
- context->setRenderbufferStorage(new es2::DepthStencilbuffer(width, height, samples));
+ context->setRenderbufferStorage(new es2::DepthStencilbuffer(width, height, internalformat, samples));
break;
default:
return error(GL_INVALID_ENUM);
diff --git a/src/OpenGL/libGLESv2/libGLESv3.cpp b/src/OpenGL/libGLESv2/libGLESv3.cpp
index 94fe8c6..c69fd35 100644
--- a/src/OpenGL/libGLESv2/libGLESv3.cpp
+++ b/src/OpenGL/libGLESv2/libGLESv3.cpp
@@ -1484,7 +1484,7 @@
case GL_DEPTH_COMPONENT24:
case GL_DEPTH_COMPONENT32_OES:
case GL_DEPTH_COMPONENT32F:
- context->setRenderbufferStorage(new es2::Depthbuffer(width, height, samples));
+ context->setRenderbufferStorage(new es2::Depthbuffer(width, height, internalformat, samples));
break;
case GL_R8UI:
case GL_R8I:
@@ -1531,7 +1531,7 @@
break;
case GL_DEPTH24_STENCIL8:
case GL_DEPTH32F_STENCIL8:
- context->setRenderbufferStorage(new es2::DepthStencilbuffer(width, height, samples));
+ context->setRenderbufferStorage(new es2::DepthStencilbuffer(width, height, internalformat, samples));
break;
default:
diff --git a/src/OpenGL/libGLESv2/utilities.cpp b/src/OpenGL/libGLESv2/utilities.cpp
index b738d0d..8ef44e8 100644
--- a/src/OpenGL/libGLESv2/utilities.cpp
+++ b/src/OpenGL/libGLESv2/utilities.cpp
@@ -1356,6 +1356,8 @@
case sw::FORMAT_D24FS8:
case sw::FORMAT_D24S8:
case sw::FORMAT_D32FS8_TEXTURE:
+ case sw::FORMAT_D32FS8_SHADOW:
+ case sw::FORMAT_S8:
return 8;
// case sw::FORMAT_D24X4S4:
// return 4;
@@ -1568,11 +1570,16 @@
case sw::FORMAT_D24S8: return 24;
case sw::FORMAT_D24X8: return 24;
// case sw::FORMAT_D24X4S4: return 24;
+ case sw::FORMAT_DF16S8:
case sw::FORMAT_D16: return 16;
+ case sw::FORMAT_D32F:
+ case sw::FORMAT_D32F_COMPLEMENTARY:
case sw::FORMAT_D32F_LOCKABLE: return 32;
+ case sw::FORMAT_DF24S8:
case sw::FORMAT_D24FS8: return 24;
// case sw::FORMAT_D32_LOCKABLE: return 32;
// case sw::FORMAT_S8_LOCKABLE: return 0;
+ case sw::FORMAT_D32FS8_SHADOW:
case sw::FORMAT_D32FS8_TEXTURE: return 32;
default: return 0;
}
@@ -1710,6 +1717,15 @@
return GL_DEPTH_COMPONENT16;
case sw::FORMAT_D24S8:
return GL_DEPTH24_STENCIL8_OES;
+ case sw::FORMAT_D32F:
+ case sw::FORMAT_D32F_COMPLEMENTARY:
+ case sw::FORMAT_D32F_LOCKABLE:
+ return GL_DEPTH_COMPONENT32F;
+ case sw::FORMAT_D32FS8_TEXTURE:
+ case sw::FORMAT_D32FS8_SHADOW:
+ return GL_DEPTH32F_STENCIL8;
+ case sw::FORMAT_S8:
+ return GL_STENCIL_INDEX8;
default:
UNREACHABLE(format);
}