Implement GL_OES_packed_depth_stencil

TRAC #12336 Signed-off-by: Andrew Lewycky Signed-off-by: Daniel Koch Author: Shannon Woods git-svn-id: https://angleproject.googlecode.com/svn/trunk@358 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 162267d6
...@@ -113,8 +113,7 @@ Context::Context(const egl::Config *config) ...@@ -113,8 +113,7 @@ Context::Context(const egl::Config *config)
mTextureCubeMapZero = new TextureCubeMap(this); mTextureCubeMapZero = new TextureCubeMap(this);
mColorbufferZero = NULL; mColorbufferZero = NULL;
mDepthbufferZero = NULL; mDepthStencilbufferZero = NULL;
mStencilbufferZero = NULL;
mState.activeSampler = 0; mState.activeSampler = 0;
mState.arrayBuffer = 0; mState.arrayBuffer = 0;
...@@ -172,8 +171,7 @@ Context::~Context() ...@@ -172,8 +171,7 @@ Context::~Context()
delete mTextureCubeMapZero; delete mTextureCubeMapZero;
delete mColorbufferZero; delete mColorbufferZero;
delete mDepthbufferZero; delete mDepthStencilbufferZero;
delete mStencilbufferZero;
delete mBufferBackEnd; delete mBufferBackEnd;
delete mVertexDataManager; delete mVertexDataManager;
...@@ -250,13 +248,11 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface) ...@@ -250,13 +248,11 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
Framebuffer *framebufferZero = new Framebuffer(); Framebuffer *framebufferZero = new Framebuffer();
Colorbuffer *colorbufferZero = new Colorbuffer(defaultRenderTarget); Colorbuffer *colorbufferZero = new Colorbuffer(defaultRenderTarget);
Depthbuffer *depthbufferZero = new Depthbuffer(depthStencil); DepthStencilbuffer *depthStencilbufferZero = new DepthStencilbuffer(depthStencil);
Stencilbuffer *stencilbufferZero = new Stencilbuffer(depthStencil);
setFramebufferZero(framebufferZero); setFramebufferZero(framebufferZero);
setColorbufferZero(colorbufferZero); setColorbufferZero(colorbufferZero);
setDepthbufferZero(depthbufferZero); setDepthStencilbufferZero(depthStencilbufferZero);
setStencilbufferZero(stencilbufferZero);
framebufferZero->setColorbuffer(GL_RENDERBUFFER, 0); framebufferZero->setColorbuffer(GL_RENDERBUFFER, 0);
framebufferZero->setDepthbuffer(GL_RENDERBUFFER, 0); framebufferZero->setDepthbuffer(GL_RENDERBUFFER, 0);
...@@ -1008,16 +1004,10 @@ void Context::setColorbufferZero(Colorbuffer *buffer) ...@@ -1008,16 +1004,10 @@ void Context::setColorbufferZero(Colorbuffer *buffer)
mColorbufferZero = buffer; mColorbufferZero = buffer;
} }
void Context::setDepthbufferZero(Depthbuffer *buffer) void Context::setDepthStencilbufferZero(DepthStencilbuffer *buffer)
{ {
delete mDepthbufferZero; delete mDepthStencilbufferZero;
mDepthbufferZero = buffer; mDepthStencilbufferZero = buffer;
}
void Context::setStencilbufferZero(Stencilbuffer *buffer)
{
delete mStencilbufferZero;
mStencilbufferZero = buffer;
} }
void Context::setRenderbuffer(Renderbuffer *buffer) void Context::setRenderbuffer(Renderbuffer *buffer)
...@@ -1131,7 +1121,7 @@ Colorbuffer *Context::getColorbuffer(GLuint handle) ...@@ -1131,7 +1121,7 @@ Colorbuffer *Context::getColorbuffer(GLuint handle)
return NULL; return NULL;
} }
Depthbuffer *Context::getDepthbuffer(GLuint handle) DepthStencilbuffer *Context::getDepthbuffer(GLuint handle)
{ {
if (handle != 0) if (handle != 0)
{ {
...@@ -1139,18 +1129,18 @@ Depthbuffer *Context::getDepthbuffer(GLuint handle) ...@@ -1139,18 +1129,18 @@ Depthbuffer *Context::getDepthbuffer(GLuint handle)
if (renderbuffer && renderbuffer->isDepthbuffer()) if (renderbuffer && renderbuffer->isDepthbuffer())
{ {
return static_cast<Depthbuffer*>(renderbuffer); return static_cast<DepthStencilbuffer*>(renderbuffer);
} }
} }
else // Special case: 0 refers to different initial render targets based on the attachment type else // Special case: 0 refers to different initial render targets based on the attachment type
{ {
return mDepthbufferZero; return mDepthStencilbufferZero;
} }
return NULL; return NULL;
} }
Stencilbuffer *Context::getStencilbuffer(GLuint handle) DepthStencilbuffer *Context::getStencilbuffer(GLuint handle)
{ {
if (handle != 0) if (handle != 0)
{ {
...@@ -1158,12 +1148,12 @@ Stencilbuffer *Context::getStencilbuffer(GLuint handle) ...@@ -1158,12 +1148,12 @@ Stencilbuffer *Context::getStencilbuffer(GLuint handle)
if (renderbuffer && renderbuffer->isStencilbuffer()) if (renderbuffer && renderbuffer->isStencilbuffer())
{ {
return static_cast<Stencilbuffer*>(renderbuffer); return static_cast<DepthStencilbuffer*>(renderbuffer);
} }
} }
else else
{ {
return mStencilbufferZero; return mDepthStencilbufferZero;
} }
return NULL; return NULL;
...@@ -1406,7 +1396,7 @@ bool Context::getIntegerv(GLenum pname, GLint *params) ...@@ -1406,7 +1396,7 @@ bool Context::getIntegerv(GLenum pname, GLint *params)
case GL_DEPTH_BITS: case GL_DEPTH_BITS:
{ {
gl::Framebuffer *framebuffer = getFramebuffer(); gl::Framebuffer *framebuffer = getFramebuffer();
gl::Depthbuffer *depthbuffer = framebuffer->getDepthbuffer(); gl::DepthStencilbuffer *depthbuffer = framebuffer->getDepthbuffer();
if (depthbuffer) if (depthbuffer)
{ {
...@@ -1421,7 +1411,7 @@ bool Context::getIntegerv(GLenum pname, GLint *params) ...@@ -1421,7 +1411,7 @@ bool Context::getIntegerv(GLenum pname, GLint *params)
case GL_STENCIL_BITS: case GL_STENCIL_BITS:
{ {
gl::Framebuffer *framebuffer = getFramebuffer(); gl::Framebuffer *framebuffer = getFramebuffer();
gl::Stencilbuffer *stencilbuffer = framebuffer->getStencilbuffer(); gl::DepthStencilbuffer *stencilbuffer = framebuffer->getStencilbuffer();
if (stencilbuffer) if (stencilbuffer)
{ {
...@@ -1627,7 +1617,7 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -1627,7 +1617,7 @@ bool Context::applyRenderTarget(bool ignoreViewport)
} }
IDirect3DSurface9 *renderTarget = framebufferObject->getRenderTarget(); IDirect3DSurface9 *renderTarget = framebufferObject->getRenderTarget();
IDirect3DSurface9 *depthStencil = framebufferObject->getDepthStencil(); IDirect3DSurface9 *depthStencil = NULL;
unsigned int renderTargetSerial = framebufferObject->getRenderTargetSerial(); unsigned int renderTargetSerial = framebufferObject->getRenderTargetSerial();
if (renderTargetSerial != mAppliedRenderTargetSerial) if (renderTargetSerial != mAppliedRenderTargetSerial)
...@@ -1636,11 +1626,25 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -1636,11 +1626,25 @@ bool Context::applyRenderTarget(bool ignoreViewport)
mAppliedRenderTargetSerial = renderTargetSerial; mAppliedRenderTargetSerial = renderTargetSerial;
} }
unsigned int depthbufferSerial = framebufferObject->getDepthbufferSerial(); unsigned int depthbufferSerial = 0;
if (depthbufferSerial != mAppliedDepthbufferSerial) unsigned int stencilbufferSerial = 0;
if (framebufferObject->getDepthbufferType() != GL_NONE)
{
depthStencil = framebufferObject->getDepthbuffer()->getDepthStencil();
depthbufferSerial = framebufferObject->getDepthbuffer()->getSerial();
}
else if (framebufferObject->getStencilbufferType() != GL_NONE)
{
depthStencil = framebufferObject->getStencilbuffer()->getDepthStencil();
stencilbufferSerial = framebufferObject->getStencilbuffer()->getSerial();
}
if (depthbufferSerial != mAppliedDepthbufferSerial ||
stencilbufferSerial != mAppliedStencilbufferSerial)
{ {
device->SetDepthStencilSurface(depthStencil); device->SetDepthStencilSurface(depthStencil);
mAppliedDepthbufferSerial = depthbufferSerial; mAppliedDepthbufferSerial = depthbufferSerial;
mAppliedStencilbufferSerial = stencilbufferSerial;
} }
D3DVIEWPORT9 viewport; D3DVIEWPORT9 viewport;
...@@ -1739,6 +1743,8 @@ void Context::applyState(GLenum drawMode) ...@@ -1739,6 +1743,8 @@ void Context::applyState(GLenum drawMode)
GLint alwaysFront = !isTriangleMode(drawMode); GLint alwaysFront = !isTriangleMode(drawMode);
programObject->setUniform1iv(pointsOrLines, 1, &alwaysFront); programObject->setUniform1iv(pointsOrLines, 1, &alwaysFront);
Framebuffer *framebufferObject = getFramebuffer();
if (mCullStateDirty || mFrontFaceDirty) if (mCullStateDirty || mFrontFaceDirty)
{ {
if (mState.cullFace) if (mState.cullFace)
...@@ -1755,7 +1761,7 @@ void Context::applyState(GLenum drawMode) ...@@ -1755,7 +1761,7 @@ void Context::applyState(GLenum drawMode)
if (mDepthStateDirty) if (mDepthStateDirty)
{ {
if (mState.depthTest) if (mState.depthTest && framebufferObject->getDepthbufferType() != GL_NONE)
{ {
device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
device->SetRenderState(D3DRS_ZFUNC, es2dx::ConvertComparison(mState.depthFunc)); device->SetRenderState(D3DRS_ZFUNC, es2dx::ConvertComparison(mState.depthFunc));
...@@ -1836,7 +1842,7 @@ void Context::applyState(GLenum drawMode) ...@@ -1836,7 +1842,7 @@ void Context::applyState(GLenum drawMode)
// get the maximum size of the stencil ref // get the maximum size of the stencil ref
gl::Framebuffer *framebuffer = getFramebuffer(); gl::Framebuffer *framebuffer = getFramebuffer();
gl::Stencilbuffer *stencilbuffer = framebuffer->getStencilbuffer(); gl::DepthStencilbuffer *stencilbuffer = framebuffer->getStencilbuffer();
GLuint maxStencil = (1 << stencilbuffer->getStencilSize()) - 1; GLuint maxStencil = (1 << stencilbuffer->getStencilSize()) - 1;
device->SetRenderState(mState.frontFace == GL_CCW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK, mState.stencilWritemask); device->SetRenderState(mState.frontFace == GL_CCW ? D3DRS_STENCILWRITEMASK : D3DRS_CCW_STENCILWRITEMASK, mState.stencilWritemask);
...@@ -1888,7 +1894,7 @@ void Context::applyState(GLenum drawMode) ...@@ -1888,7 +1894,7 @@ void Context::applyState(GLenum drawMode)
{ {
if (mState.polygonOffsetFill) if (mState.polygonOffsetFill)
{ {
gl::Depthbuffer *depthbuffer = getFramebuffer()->getDepthbuffer(); gl::DepthStencilbuffer *depthbuffer = getFramebuffer()->getDepthbuffer();
if (depthbuffer) if (depthbuffer)
{ {
device->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, *((DWORD*)&mState.polygonOffsetFactor)); device->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, *((DWORD*)&mState.polygonOffsetFactor));
...@@ -2290,22 +2296,24 @@ void Context::clear(GLbitfield mask) ...@@ -2290,22 +2296,24 @@ void Context::clear(GLbitfield mask)
} }
} }
IDirect3DSurface9 *depthStencil = framebufferObject->getDepthStencil();
GLuint stencilUnmasked = 0x0; GLuint stencilUnmasked = 0x0;
if ((mask & GL_STENCIL_BUFFER_BIT) && depthStencil) if (mask & GL_STENCIL_BUFFER_BIT)
{ {
D3DSURFACE_DESC desc;
depthStencil->GetDesc(&desc);
mask &= ~GL_STENCIL_BUFFER_BIT; mask &= ~GL_STENCIL_BUFFER_BIT;
unsigned int stencilSize = es2dx::GetStencilSize(desc.Format); if (framebufferObject->getStencilbufferType() != GL_NONE)
stencilUnmasked = (0x1 << stencilSize) - 1;
if (stencilUnmasked != 0x0)
{ {
flags |= D3DCLEAR_STENCIL; IDirect3DSurface9 *depthStencil = framebufferObject->getStencilbuffer()->getDepthStencil();
D3DSURFACE_DESC desc;
depthStencil->GetDesc(&desc);
unsigned int stencilSize = es2dx::GetStencilSize(desc.Format);
stencilUnmasked = (0x1 << stencilSize) - 1;
if (stencilUnmasked != 0x0)
{
flags |= D3DCLEAR_STENCIL;
}
} }
} }
...@@ -2901,9 +2909,9 @@ bool Context::hasStencil() ...@@ -2901,9 +2909,9 @@ bool Context::hasStencil()
{ {
Framebuffer *framebufferObject = getFramebuffer(); Framebuffer *framebufferObject = getFramebuffer();
if (framebufferObject) if (framebufferObject && framebufferObject->getStencilbufferType() != GL_NONE)
{ {
Stencilbuffer *stencilbufferObject = framebufferObject->getStencilbuffer(); DepthStencilbuffer *stencilbufferObject = framebufferObject->getStencilbuffer();
if (stencilbufferObject) if (stencilbufferObject)
{ {
...@@ -2928,6 +2936,8 @@ void Context::setVertexAttrib(GLuint index, const GLfloat *values) ...@@ -2928,6 +2936,8 @@ void Context::setVertexAttrib(GLuint index, const GLfloat *values)
void Context::initExtensionString() void Context::initExtensionString()
{ {
mExtensionString += "GL_OES_packed_depth_stencil ";
if (mBufferBackEnd->supportIntIndices()) if (mBufferBackEnd->supportIntIndices())
{ {
mExtensionString += "GL_OES_element_index_uint "; mExtensionString += "GL_OES_element_index_uint ";
......
...@@ -43,6 +43,7 @@ class Renderbuffer; ...@@ -43,6 +43,7 @@ class Renderbuffer;
class Colorbuffer; class Colorbuffer;
class Depthbuffer; class Depthbuffer;
class Stencilbuffer; class Stencilbuffer;
class DepthStencilbuffer;
class VertexDataManager; class VertexDataManager;
class IndexDataManager; class IndexDataManager;
class BufferBackEnd; class BufferBackEnd;
...@@ -320,8 +321,7 @@ class Context ...@@ -320,8 +321,7 @@ class Context
void setFramebufferZero(Framebuffer *framebuffer); void setFramebufferZero(Framebuffer *framebuffer);
void setColorbufferZero(Colorbuffer *renderbuffer); void setColorbufferZero(Colorbuffer *renderbuffer);
void setDepthbufferZero(Depthbuffer *depthBuffer); void setDepthStencilbufferZero(DepthStencilbuffer *depthStencilBuffer);
void setStencilbufferZero(Stencilbuffer *stencilBuffer);
void setRenderbuffer(Renderbuffer *renderbuffer); void setRenderbuffer(Renderbuffer *renderbuffer);
void setVertexAttrib(GLuint index, const GLfloat *values); void setVertexAttrib(GLuint index, const GLfloat *values);
...@@ -333,8 +333,8 @@ class Context ...@@ -333,8 +333,8 @@ class Context
Framebuffer *getFramebuffer(GLuint handle); Framebuffer *getFramebuffer(GLuint handle);
Renderbuffer *getRenderbuffer(GLuint handle); Renderbuffer *getRenderbuffer(GLuint handle);
Colorbuffer *getColorbuffer(GLuint handle); Colorbuffer *getColorbuffer(GLuint handle);
Depthbuffer *getDepthbuffer(GLuint handle); DepthStencilbuffer *getDepthbuffer(GLuint handle);
Stencilbuffer *getStencilbuffer(GLuint handle); DepthStencilbuffer *getStencilbuffer(GLuint handle);
Buffer *getArrayBuffer(); Buffer *getArrayBuffer();
Buffer *getElementArrayBuffer(); Buffer *getElementArrayBuffer();
...@@ -405,8 +405,7 @@ class Context ...@@ -405,8 +405,7 @@ class Context
TextureCubeMap *mTextureCubeMapZero; TextureCubeMap *mTextureCubeMapZero;
Colorbuffer *mColorbufferZero; Colorbuffer *mColorbufferZero;
Depthbuffer *mDepthbufferZero; DepthStencilbuffer *mDepthStencilbufferZero;
Stencilbuffer *mStencilbufferZero;
typedef std::map<GLuint, Buffer*> BufferMap; typedef std::map<GLuint, Buffer*> BufferMap;
BufferMap mBufferMap; BufferMap mBufferMap;
...@@ -449,6 +448,7 @@ class Context ...@@ -449,6 +448,7 @@ class Context
unsigned int mAppliedProgram; unsigned int mAppliedProgram;
unsigned int mAppliedRenderTargetSerial; unsigned int mAppliedRenderTargetSerial;
unsigned int mAppliedDepthbufferSerial; unsigned int mAppliedDepthbufferSerial;
unsigned int mAppliedStencilbufferSerial;
bool mSupportsShaderModel3; bool mSupportsShaderModel3;
......
...@@ -119,7 +119,7 @@ IDirect3DSurface9 *Framebuffer::getRenderTarget() ...@@ -119,7 +119,7 @@ IDirect3DSurface9 *Framebuffer::getRenderTarget()
unsigned int Framebuffer::getDepthbufferSerial() unsigned int Framebuffer::getDepthbufferSerial()
{ {
gl::Context *context = gl::getContext(); gl::Context *context = gl::getContext();
Depthbuffer *depthbuffer = context->getDepthbuffer(mDepthbufferHandle); DepthStencilbuffer *depthbuffer = context->getDepthbuffer(mDepthbufferHandle);
if (depthbuffer) if (depthbuffer)
{ {
...@@ -129,19 +129,6 @@ unsigned int Framebuffer::getDepthbufferSerial() ...@@ -129,19 +129,6 @@ unsigned int Framebuffer::getDepthbufferSerial()
return 0; return 0;
} }
IDirect3DSurface9 *Framebuffer::getDepthStencil()
{
gl::Context *context = gl::getContext();
Depthbuffer *depthbuffer = context->getDepthbuffer(mDepthbufferHandle);
if (depthbuffer)
{
return depthbuffer->getDepthStencil();
}
return NULL;
}
Colorbuffer *Framebuffer::getColorbuffer() Colorbuffer *Framebuffer::getColorbuffer()
{ {
gl::Context *context = gl::getContext(); gl::Context *context = gl::getContext();
...@@ -169,27 +156,33 @@ Colorbuffer *Framebuffer::getColorbuffer() ...@@ -169,27 +156,33 @@ Colorbuffer *Framebuffer::getColorbuffer()
return NULL; return NULL;
} }
Depthbuffer *Framebuffer::getDepthbuffer() DepthStencilbuffer *Framebuffer::getDepthbuffer()
{ {
gl::Context *context = gl::getContext(); if (mDepthbufferType != GL_NONE)
Depthbuffer *depthbuffer = context->getDepthbuffer(mDepthbufferHandle);
if (depthbuffer && depthbuffer->isDepthbuffer())
{ {
return depthbuffer; gl::Context *context = gl::getContext();
DepthStencilbuffer *depthbuffer = context->getDepthbuffer(mDepthbufferHandle);
if (depthbuffer && depthbuffer->isDepthbuffer())
{
return depthbuffer;
}
} }
return NULL; return NULL;
} }
Stencilbuffer *Framebuffer::getStencilbuffer() DepthStencilbuffer *Framebuffer::getStencilbuffer()
{ {
gl::Context *context = gl::getContext(); if (mStencilbufferType != GL_NONE)
Stencilbuffer *stencilbuffer = context->getStencilbuffer(mStencilbufferHandle);
if (stencilbuffer && stencilbuffer->isStencilbuffer())
{ {
return stencilbuffer; gl::Context *context = gl::getContext();
DepthStencilbuffer *stencilbuffer = context->getStencilbuffer(mStencilbufferHandle);
if (stencilbuffer && stencilbuffer->isStencilbuffer())
{
return stencilbuffer;
}
} }
return NULL; return NULL;
...@@ -250,9 +243,12 @@ GLenum Framebuffer::completeness() ...@@ -250,9 +243,12 @@ GLenum Framebuffer::completeness()
height = colorbuffer->getHeight(); height = colorbuffer->getHeight();
} }
DepthStencilbuffer *depthbuffer = NULL;
DepthStencilbuffer *stencilbuffer = NULL;
if (mDepthbufferType != GL_NONE) if (mDepthbufferType != GL_NONE)
{ {
Depthbuffer *depthbuffer = context->getDepthbuffer(mDepthbufferHandle); depthbuffer = context->getDepthbuffer(mDepthbufferHandle);
if (!depthbuffer) if (!depthbuffer)
{ {
...@@ -277,7 +273,7 @@ GLenum Framebuffer::completeness() ...@@ -277,7 +273,7 @@ GLenum Framebuffer::completeness()
if (mStencilbufferType != GL_NONE) if (mStencilbufferType != GL_NONE)
{ {
Stencilbuffer *stencilbuffer = context->getStencilbuffer(mStencilbufferHandle); stencilbuffer = context->getStencilbuffer(mStencilbufferHandle);
if (!stencilbuffer) if (!stencilbuffer)
{ {
...@@ -300,6 +296,16 @@ GLenum Framebuffer::completeness() ...@@ -300,6 +296,16 @@ GLenum Framebuffer::completeness()
} }
} }
if (mDepthbufferType == GL_RENDERBUFFER && mStencilbufferType == GL_RENDERBUFFER)
{
if (depthbuffer->getFormat() != GL_DEPTH24_STENCIL8_OES ||
stencilbuffer->getFormat() != GL_DEPTH24_STENCIL8_OES ||
depthbuffer->getSerial() != stencilbuffer->getSerial())
{
return GL_FRAMEBUFFER_UNSUPPORTED;
}
}
return GL_FRAMEBUFFER_COMPLETE; return GL_FRAMEBUFFER_COMPLETE;
} }
} }
...@@ -21,6 +21,7 @@ namespace gl ...@@ -21,6 +21,7 @@ namespace gl
class Colorbuffer; class Colorbuffer;
class Depthbuffer; class Depthbuffer;
class Stencilbuffer; class Stencilbuffer;
class DepthStencilbuffer;
class Framebuffer class Framebuffer
{ {
...@@ -43,8 +44,8 @@ class Framebuffer ...@@ -43,8 +44,8 @@ class Framebuffer
unsigned int getDepthbufferSerial(); unsigned int getDepthbufferSerial();
Colorbuffer *getColorbuffer(); Colorbuffer *getColorbuffer();
Depthbuffer *getDepthbuffer(); DepthStencilbuffer *getDepthbuffer();
Stencilbuffer *getStencilbuffer(); DepthStencilbuffer *getStencilbuffer();
GLenum getColorbufferType(); GLenum getColorbufferType();
GLenum getDepthbufferType(); GLenum getDepthbufferType();
......
...@@ -199,7 +199,7 @@ IDirect3DSurface9 *Colorbuffer::getRenderTarget() ...@@ -199,7 +199,7 @@ IDirect3DSurface9 *Colorbuffer::getRenderTarget()
return mRenderTarget; return mRenderTarget;
} }
Depthbuffer::Depthbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil) DepthStencilbuffer::DepthStencilbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil)
{ {
if (depthStencil) if (depthStencil)
{ {
...@@ -209,13 +209,11 @@ Depthbuffer::Depthbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthS ...@@ -209,13 +209,11 @@ Depthbuffer::Depthbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthS
depthStencil->GetDesc(&description); depthStencil->GetDesc(&description);
setSize(description.Width, description.Height); setSize(description.Width, description.Height);
mFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function mFormat = GL_DEPTH24_STENCIL8_OES;
// will expect one of the valid renderbuffer formats for use in
// glRenderbufferStorage
} }
} }
Depthbuffer::Depthbuffer(int width, int height) DepthStencilbuffer::DepthStencilbuffer(int width, int height)
{ {
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
...@@ -234,9 +232,7 @@ Depthbuffer::Depthbuffer(int width, int height) ...@@ -234,9 +232,7 @@ Depthbuffer::Depthbuffer(int width, int height)
if (mDepthStencil) if (mDepthStencil)
{ {
setSize(width, height); setSize(width, height);
mFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function mFormat = GL_DEPTH24_STENCIL8_OES;
// will expect one of the valid renderbuffer formats for use in
// glRenderbufferStorage
} }
else else
{ {
...@@ -245,7 +241,7 @@ Depthbuffer::Depthbuffer(int width, int height) ...@@ -245,7 +241,7 @@ Depthbuffer::Depthbuffer(int width, int height)
} }
} }
Depthbuffer::~Depthbuffer() DepthStencilbuffer::~DepthStencilbuffer()
{ {
if (mDepthStencil) if (mDepthStencil)
{ {
...@@ -253,12 +249,17 @@ Depthbuffer::~Depthbuffer() ...@@ -253,12 +249,17 @@ Depthbuffer::~Depthbuffer()
} }
} }
bool Depthbuffer::isDepthbuffer() bool DepthStencilbuffer::isDepthbuffer()
{
return true;
}
bool DepthStencilbuffer::isStencilbuffer()
{ {
return true; return true;
} }
GLuint Depthbuffer::getDepthSize() GLuint DepthStencilbuffer::getDepthSize()
{ {
if (mDepthStencil) if (mDepthStencil)
{ {
...@@ -271,85 +272,93 @@ GLuint Depthbuffer::getDepthSize() ...@@ -271,85 +272,93 @@ GLuint Depthbuffer::getDepthSize()
return 0; return 0;
} }
IDirect3DSurface9 *Depthbuffer::getDepthStencil() GLuint DepthStencilbuffer::getStencilSize()
{
if (mDepthStencil)
{
D3DSURFACE_DESC description;
mDepthStencil->GetDesc(&description);
return es2dx::GetStencilSize(description.Format);
}
return 0;
}
IDirect3DSurface9 *DepthStencilbuffer::getDepthStencil()
{ {
return mDepthStencil; return mDepthStencil;
} }
Stencilbuffer::Stencilbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil) Depthbuffer::Depthbuffer(IDirect3DSurface9 *depthStencil) : DepthStencilbuffer(depthStencil)
{ {
if (depthStencil) if (depthStencil)
{ {
depthStencil->AddRef(); mFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function
// will expect one of the valid renderbuffer formats for use in
D3DSURFACE_DESC description; // glRenderbufferStorage
depthStencil->GetDesc(&description);
setSize(description.Width, description.Height);
mFormat = 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(int width, int height) Depthbuffer::Depthbuffer(int width, int height) : DepthStencilbuffer(width, height)
{ {
IDirect3DDevice9 *device = getDevice(); if (getDepthStencil())
mDepthStencil = NULL;
HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &mDepthStencil, 0);
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
{ {
error(GL_OUT_OF_MEMORY); mFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function
// will expect one of the valid renderbuffer formats for use in
return; // glRenderbufferStorage
} }
}
ASSERT(SUCCEEDED(result)); Depthbuffer::~Depthbuffer()
{
}
if (mDepthStencil) bool Depthbuffer::isDepthbuffer()
{
return true;
}
bool Depthbuffer::isStencilbuffer()
{
return false;
}
Stencilbuffer::Stencilbuffer(IDirect3DSurface9 *depthStencil) : DepthStencilbuffer(depthStencil)
{
if (depthStencil)
{ {
setSize(width, height);
mFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function mFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function
// will expect one of the valid renderbuffer formats for use in // will expect one of the valid renderbuffer formats for use in
// glRenderbufferStorage // glRenderbufferStorage
} }
else else
{ {
setSize(0, 0);
mFormat = GL_RGBA4; //default format mFormat = GL_RGBA4; //default format
} }
} }
Stencilbuffer::~Stencilbuffer() Stencilbuffer::Stencilbuffer(int width, int height) : DepthStencilbuffer(width, height)
{ {
if (mDepthStencil) if (getDepthStencil())
{ {
mDepthStencil->Release(); mFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function
// will expect one of the valid renderbuffer formats for use in
// glRenderbufferStorage
} }
} }
GLuint Stencilbuffer::getStencilSize() Stencilbuffer::~Stencilbuffer()
{ {
if (mDepthStencil)
{
D3DSURFACE_DESC description;
mDepthStencil->GetDesc(&description);
return es2dx::GetStencilSize(description.Format);
}
return 0;
} }
bool Stencilbuffer::isStencilbuffer() bool Stencilbuffer::isDepthbuffer()
{ {
return true; return false;
} }
IDirect3DSurface9 *Stencilbuffer::getDepthStencil() bool Stencilbuffer::isStencilbuffer()
{ {
return mDepthStencil; return true;
} }
} }
...@@ -78,26 +78,43 @@ class Colorbuffer : public Renderbuffer ...@@ -78,26 +78,43 @@ class Colorbuffer : public Renderbuffer
DISALLOW_COPY_AND_ASSIGN(Colorbuffer); DISALLOW_COPY_AND_ASSIGN(Colorbuffer);
}; };
class Depthbuffer : public Renderbuffer class DepthStencilbuffer : public Renderbuffer
{ {
public: public:
explicit Depthbuffer(IDirect3DSurface9 *depthStencil); explicit DepthStencilbuffer(IDirect3DSurface9 *depthStencil);
Depthbuffer(int width, int height); DepthStencilbuffer(int width, int height);
~Depthbuffer(); ~DepthStencilbuffer();
bool isDepthbuffer(); virtual bool isDepthbuffer();
virtual bool isStencilbuffer();
GLuint getDepthSize(); GLuint getDepthSize();
GLuint getStencilSize();
IDirect3DSurface9 *getDepthStencil(); IDirect3DSurface9 *getDepthStencil();
private: private:
DISALLOW_COPY_AND_ASSIGN(Depthbuffer); DISALLOW_COPY_AND_ASSIGN(DepthStencilbuffer);
IDirect3DSurface9 *mDepthStencil; IDirect3DSurface9 *mDepthStencil;
}; };
class Stencilbuffer : public Renderbuffer class Depthbuffer : public DepthStencilbuffer
{
public:
explicit Depthbuffer(IDirect3DSurface9 *depthStencil);
Depthbuffer(int width, int height);
~Depthbuffer();
bool isDepthbuffer();
bool isStencilbuffer();
private:
DISALLOW_COPY_AND_ASSIGN(Depthbuffer);
};
class Stencilbuffer : public DepthStencilbuffer
{ {
public: public:
explicit Stencilbuffer(IDirect3DSurface9 *depthStencil); explicit Stencilbuffer(IDirect3DSurface9 *depthStencil);
...@@ -105,15 +122,11 @@ class Stencilbuffer : public Renderbuffer ...@@ -105,15 +122,11 @@ class Stencilbuffer : public Renderbuffer
~Stencilbuffer(); ~Stencilbuffer();
bool isDepthbuffer();
bool isStencilbuffer(); bool isStencilbuffer();
GLuint getStencilSize();
IDirect3DSurface9 *getDepthStencil();
private: private:
DISALLOW_COPY_AND_ASSIGN(Stencilbuffer); DISALLOW_COPY_AND_ASSIGN(Stencilbuffer);
IDirect3DSurface9 *mDepthStencil;
}; };
} }
......
...@@ -3543,6 +3543,7 @@ void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsiz ...@@ -3543,6 +3543,7 @@ void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsiz
case GL_RGB5_A1: case GL_RGB5_A1:
case GL_RGB565: case GL_RGB565:
case GL_STENCIL_INDEX8: case GL_STENCIL_INDEX8:
case GL_DEPTH24_STENCIL8_OES:
break; break;
default: default:
return error(GL_INVALID_ENUM); return error(GL_INVALID_ENUM);
...@@ -3575,6 +3576,9 @@ void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsiz ...@@ -3575,6 +3576,9 @@ void __stdcall glRenderbufferStorage(GLenum target, GLenum internalformat, GLsiz
case GL_STENCIL_INDEX8: case GL_STENCIL_INDEX8:
context->setRenderbuffer(new gl::Stencilbuffer(width, height)); context->setRenderbuffer(new gl::Stencilbuffer(width, height));
break; break;
case GL_DEPTH24_STENCIL8_OES:
context->setRenderbuffer(new gl::DepthStencilbuffer(width, height));
break;
default: default:
return error(GL_INVALID_ENUM); return error(GL_INVALID_ENUM);
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#define GL_APICALL #define GL_APICALL
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include "common/debug.h" #include "common/debug.h"
#include "libEGL/Display.h" #include "libEGL/Display.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment