diff options
Diffstat (limited to 'Source/ThirdParty/ANGLE/src/libGLESv2/Renderbuffer.cpp')
-rw-r--r-- | Source/ThirdParty/ANGLE/src/libGLESv2/Renderbuffer.cpp | 440 |
1 files changed, 223 insertions, 217 deletions
diff --git a/Source/ThirdParty/ANGLE/src/libGLESv2/Renderbuffer.cpp b/Source/ThirdParty/ANGLE/src/libGLESv2/Renderbuffer.cpp index 6e4494b..6004255 100644 --- a/Source/ThirdParty/ANGLE/src/libGLESv2/Renderbuffer.cpp +++ b/Source/ThirdParty/ANGLE/src/libGLESv2/Renderbuffer.cpp @@ -18,137 +18,254 @@ namespace gl { unsigned int RenderbufferStorage::mCurrentSerial = 1; -Renderbuffer::Renderbuffer(GLuint id, RenderbufferStorage *storage) : RefCountObject(id) +RenderbufferInterface::RenderbufferInterface() { - ASSERT(storage != NULL); - mStorage = storage; } -Renderbuffer::~Renderbuffer() +// The default case for classes inherited from RenderbufferInterface is not to +// need to do anything upon the reference count to the parent Renderbuffer incrementing +// or decrementing. +void RenderbufferInterface::addProxyRef(const Renderbuffer *proxy) +{ +} + +void RenderbufferInterface::releaseProxy(const Renderbuffer *proxy) +{ +} + +GLuint RenderbufferInterface::getRedSize() const +{ + return dx2es::GetRedSize(getD3DFormat()); +} + +GLuint RenderbufferInterface::getGreenSize() const +{ + return dx2es::GetGreenSize(getD3DFormat()); +} + +GLuint RenderbufferInterface::getBlueSize() const +{ + return dx2es::GetBlueSize(getD3DFormat()); +} + +GLuint RenderbufferInterface::getAlphaSize() const +{ + return dx2es::GetAlphaSize(getD3DFormat()); +} + +GLuint RenderbufferInterface::getDepthSize() const +{ + return dx2es::GetDepthSize(getD3DFormat()); +} + +GLuint RenderbufferInterface::getStencilSize() const +{ + return dx2es::GetStencilSize(getD3DFormat()); +} + +RenderbufferTexture::RenderbufferTexture(Texture *texture, GLenum target) : mTarget(target) +{ + mTexture.set(texture); +} + +RenderbufferTexture::~RenderbufferTexture() +{ + mTexture.set(NULL); +} + +// Textures need to maintain their own reference count for references via +// Renderbuffers acting as proxies. Here, we notify the texture of a reference. +void RenderbufferTexture::addProxyRef(const Renderbuffer *proxy) +{ + mTexture->addProxyRef(proxy); +} + +void RenderbufferTexture::releaseProxy(const Renderbuffer *proxy) +{ + mTexture->releaseProxy(proxy); +} + +IDirect3DSurface9 *RenderbufferTexture::getRenderTarget() +{ + return mTexture->getRenderTarget(mTarget); +} + +IDirect3DSurface9 *RenderbufferTexture::getDepthStencil() +{ + return NULL; +} + +GLsizei RenderbufferTexture::getWidth() const +{ + return mTexture->getWidth(0); +} + +GLsizei RenderbufferTexture::getHeight() const +{ + return mTexture->getHeight(0); +} + +GLenum RenderbufferTexture::getInternalFormat() const +{ + return mTexture->getInternalFormat(); +} + +D3DFORMAT RenderbufferTexture::getD3DFormat() const +{ + return mTexture->getD3DFormat(); +} + +GLsizei RenderbufferTexture::getSamples() const +{ + return 0; +} + +unsigned int RenderbufferTexture::getSerial() const +{ + return mTexture->getRenderTargetSerial(mTarget); +} + +Renderbuffer::Renderbuffer(GLuint id, RenderbufferInterface *instance) : RefCountObject(id) { - delete mStorage; + ASSERT(instance != NULL); + mInstance = instance; } -bool Renderbuffer::isColorbuffer() const +Renderbuffer::~Renderbuffer() { - return mStorage->isColorbuffer(); + delete mInstance; } -bool Renderbuffer::isDepthbuffer() const +// The RenderbufferInterface contained in this Renderbuffer may need to maintain +// its own reference count, so we pass it on here. +void Renderbuffer::addRef() const { - return mStorage->isDepthbuffer(); + mInstance->addProxyRef(this); + + RefCountObject::addRef(); } -bool Renderbuffer::isStencilbuffer() const +void Renderbuffer::release() const { - return mStorage->isStencilbuffer(); + mInstance->releaseProxy(this); + + RefCountObject::release(); } IDirect3DSurface9 *Renderbuffer::getRenderTarget() { - return mStorage->getRenderTarget(); + return mInstance->getRenderTarget(); } IDirect3DSurface9 *Renderbuffer::getDepthStencil() { - return mStorage->getDepthStencil(); + return mInstance->getDepthStencil(); } -int Renderbuffer::getWidth() const +GLsizei Renderbuffer::getWidth() const { - return mStorage->getWidth(); + return mInstance->getWidth(); } -int Renderbuffer::getHeight() const +GLsizei Renderbuffer::getHeight() const { - return mStorage->getHeight(); + return mInstance->getHeight(); } -GLenum Renderbuffer::getFormat() const +GLenum Renderbuffer::getInternalFormat() const { - return mStorage->getFormat(); + return mInstance->getInternalFormat(); } D3DFORMAT Renderbuffer::getD3DFormat() const { - return mStorage->getD3DFormat(); + return mInstance->getD3DFormat(); } -unsigned int Renderbuffer::getSerial() const +GLuint Renderbuffer::getRedSize() const { - return mStorage->getSerial(); + return mInstance->getRedSize(); } -void Renderbuffer::setStorage(RenderbufferStorage *newStorage) +GLuint Renderbuffer::getGreenSize() const { - ASSERT(newStorage != NULL); + return mInstance->getGreenSize(); +} - delete mStorage; - mStorage = newStorage; +GLuint Renderbuffer::getBlueSize() const +{ + return mInstance->getBlueSize(); } -RenderbufferStorage::RenderbufferStorage() : mSerial(issueSerial()) +GLuint Renderbuffer::getAlphaSize() const { - mWidth = 0; - mHeight = 0; - mFormat = GL_RGBA4; - mD3DFormat = D3DFMT_A8R8G8B8; - mSamples = 0; + return mInstance->getAlphaSize(); } -RenderbufferStorage::~RenderbufferStorage() +GLuint Renderbuffer::getDepthSize() const { + return mInstance->getDepthSize(); } -bool RenderbufferStorage::isColorbuffer() const +GLuint Renderbuffer::getStencilSize() const { - return false; + return mInstance->getStencilSize(); } -bool RenderbufferStorage::isDepthbuffer() const +GLsizei Renderbuffer::getSamples() const { - return false; + return mInstance->getSamples(); } -bool RenderbufferStorage::isStencilbuffer() const +unsigned int Renderbuffer::getSerial() const { - return false; + return mInstance->getSerial(); } -IDirect3DSurface9 *RenderbufferStorage::getRenderTarget() +void Renderbuffer::setStorage(RenderbufferStorage *newStorage) { - return NULL; + ASSERT(newStorage != NULL); + + delete mInstance; + mInstance = newStorage; } -IDirect3DSurface9 *RenderbufferStorage::getDepthStencil() +RenderbufferStorage::RenderbufferStorage() : mSerial(issueSerial()) { - return NULL; + mWidth = 0; + mHeight = 0; + mInternalFormat = GL_RGBA4; + mD3DFormat = D3DFMT_A8R8G8B8; + mSamples = 0; } -int RenderbufferStorage::getWidth() const +RenderbufferStorage::~RenderbufferStorage() { - return mWidth; } -int RenderbufferStorage::getHeight() const +IDirect3DSurface9 *RenderbufferStorage::getRenderTarget() { - return mHeight; + return NULL; } -void RenderbufferStorage::setSize(int width, int height) +IDirect3DSurface9 *RenderbufferStorage::getDepthStencil() { - mWidth = width; - mHeight = height; + return NULL; } -GLenum RenderbufferStorage::getFormat() const +GLsizei RenderbufferStorage::getWidth() const { - return mFormat; + return mWidth; } -bool RenderbufferStorage::isFloatingPoint() const +GLsizei RenderbufferStorage::getHeight() const { - return false; // no floating point renderbuffers + return mHeight; +} + +GLenum RenderbufferStorage::getInternalFormat() const +{ + return mInternalFormat; } D3DFORMAT RenderbufferStorage::getD3DFormat() const @@ -171,6 +288,13 @@ unsigned int RenderbufferStorage::issueSerial() return mCurrentSerial++; } +unsigned int RenderbufferStorage::issueCubeSerials() +{ + unsigned int firstSerial = mCurrentSerial; + mCurrentSerial += 6; + return firstSerial; +} + Colorbuffer::Colorbuffer(IDirect3DSurface9 *renderTarget) : mRenderTarget(renderTarget) { if (renderTarget) @@ -180,25 +304,18 @@ Colorbuffer::Colorbuffer(IDirect3DSurface9 *renderTarget) : mRenderTarget(render D3DSURFACE_DESC description; renderTarget->GetDesc(&description); - setSize(description.Width, description.Height); - mFormat = dx2es::ConvertBackBufferFormat(description.Format); + mWidth = description.Width; + mHeight = description.Height; + mInternalFormat = dx2es::ConvertBackBufferFormat(description.Format); mD3DFormat = description.Format; - mSamples = es2dx::GetSamplesFromMultisampleType(description.MultiSampleType); + mSamples = dx2es::GetSamplesFromMultisampleType(description.MultiSampleType); } } -Colorbuffer::Colorbuffer(const Texture* texture) : mRenderTarget(NULL) -{ - setSize(texture->getWidth(), texture->getHeight()); - mD3DFormat = texture->getD3DFormat(); - mSamples = 0; -} - -Colorbuffer::Colorbuffer(int width, int height, GLenum format, GLsizei samples) +Colorbuffer::Colorbuffer(int width, int height, GLenum format, GLsizei samples) : mRenderTarget(NULL) { IDirect3DDevice9 *device = getDevice(); - mRenderTarget = NULL; D3DFORMAT requestedFormat = es2dx::ConvertRenderbufferFormat(format); int supportedSamples = getContext()->getNearestSupportedSamples(requestedFormat, samples); @@ -224,13 +341,11 @@ Colorbuffer::Colorbuffer(int width, int height, GLenum format, GLsizei samples) ASSERT(SUCCEEDED(result)); } - if (mRenderTarget) - { - setSize(width, height); - mFormat = format; - mD3DFormat = requestedFormat; - mSamples = supportedSamples; - } + mWidth = width; + mHeight = height; + mInternalFormat = format; + mD3DFormat = requestedFormat; + mSamples = supportedSamples; } Colorbuffer::~Colorbuffer() @@ -241,65 +356,13 @@ Colorbuffer::~Colorbuffer() } } -bool Colorbuffer::isColorbuffer() const -{ - return true; -} - -GLuint Colorbuffer::getRedSize() const -{ - if (mRenderTarget) - { - D3DSURFACE_DESC description; - mRenderTarget->GetDesc(&description); - - return es2dx::GetRedSize(description.Format); - } - - return 0; -} - -GLuint Colorbuffer::getGreenSize() const -{ - if (mRenderTarget) - { - D3DSURFACE_DESC description; - mRenderTarget->GetDesc(&description); - - return es2dx::GetGreenSize(description.Format); - } - - return 0; -} - -GLuint Colorbuffer::getBlueSize() const -{ - if (mRenderTarget) - { - D3DSURFACE_DESC description; - mRenderTarget->GetDesc(&description); - - return es2dx::GetBlueSize(description.Format); - } - - return 0; -} - -GLuint Colorbuffer::getAlphaSize() const +IDirect3DSurface9 *Colorbuffer::getRenderTarget() { if (mRenderTarget) { - D3DSURFACE_DESC description; - mRenderTarget->GetDesc(&description); - - return es2dx::GetAlphaSize(description.Format); + mRenderTarget->AddRef(); } - return 0; -} - -IDirect3DSurface9 *Colorbuffer::getRenderTarget() -{ return mRenderTarget; } @@ -312,9 +375,10 @@ DepthStencilbuffer::DepthStencilbuffer(IDirect3DSurface9 *depthStencil) : mDepth D3DSURFACE_DESC description; depthStencil->GetDesc(&description); - setSize(description.Width, description.Height); - mFormat = dx2es::ConvertDepthStencilFormat(description.Format); - mSamples = es2dx::GetSamplesFromMultisampleType(description.MultiSampleType); + mWidth = description.Width; + mHeight = description.Height; + mInternalFormat = dx2es::ConvertDepthStencilFormat(description.Format); + mSamples = dx2es::GetSamplesFromMultisampleType(description.MultiSampleType); mD3DFormat = description.Format; } } @@ -334,25 +398,26 @@ DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples) return; } - HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, es2dx::GetMultisampleTypeFromSamples(supportedSamples), - 0, FALSE, &mDepthStencil, 0); - - if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) + if (width > 0 && height > 0) { - error(GL_OUT_OF_MEMORY); + HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, es2dx::GetMultisampleTypeFromSamples(supportedSamples), + 0, FALSE, &mDepthStencil, 0); - return; - } + if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) + { + error(GL_OUT_OF_MEMORY); - ASSERT(SUCCEEDED(result)); + return; + } - if (mDepthStencil) - { - setSize(width, height); - mFormat = GL_DEPTH24_STENCIL8_OES; - mD3DFormat = D3DFMT_D24S8; - mSamples = supportedSamples; + ASSERT(SUCCEEDED(result)); } + + mWidth = width; + mHeight = height; + mInternalFormat = GL_DEPTH24_STENCIL8_OES; + mD3DFormat = D3DFMT_D24S8; + mSamples = supportedSamples; } DepthStencilbuffer::~DepthStencilbuffer() @@ -363,42 +428,6 @@ DepthStencilbuffer::~DepthStencilbuffer() } } -bool DepthStencilbuffer::isDepthbuffer() const -{ - return true; -} - -bool DepthStencilbuffer::isStencilbuffer() const -{ - return true; -} - -GLuint DepthStencilbuffer::getDepthSize() const -{ - if (mDepthStencil) - { - D3DSURFACE_DESC description; - mDepthStencil->GetDesc(&description); - - return es2dx::GetDepthSize(description.Format); - } - - return 0; -} - -GLuint DepthStencilbuffer::getStencilSize() const -{ - if (mDepthStencil) - { - D3DSURFACE_DESC description; - mDepthStencil->GetDesc(&description); - - return es2dx::GetStencilSize(description.Format); - } - - return 0; -} - IDirect3DSurface9 *DepthStencilbuffer::getDepthStencil() { return mDepthStencil; @@ -408,19 +437,19 @@ Depthbuffer::Depthbuffer(IDirect3DSurface9 *depthStencil) : DepthStencilbuffer(d { if (depthStencil) { - mFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function - // will expect one of the valid renderbuffer formats for use in - // glRenderbufferStorage + mInternalFormat = 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(int width, int height, GLsizei samples) : DepthStencilbuffer(width, height, samples) { - if (getDepthStencil()) + if (mDepthStencil) { - mFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function - // will expect one of the valid renderbuffer formats for use in - // glRenderbufferStorage + mInternalFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function + // will expect one of the valid renderbuffer formats for use in + // glRenderbufferStorage } } @@ -428,37 +457,23 @@ Depthbuffer::~Depthbuffer() { } -bool Depthbuffer::isDepthbuffer() const -{ - return true; -} - -bool Depthbuffer::isStencilbuffer() const -{ - return false; -} - Stencilbuffer::Stencilbuffer(IDirect3DSurface9 *depthStencil) : DepthStencilbuffer(depthStencil) { if (depthStencil) { - 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 - } - else - { - mFormat = GL_RGBA4; //default format + mInternalFormat = 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, GLsizei samples) : DepthStencilbuffer(width, height, samples) { - if (getDepthStencil()) + if (mDepthStencil) { - 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 + mInternalFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function + // will expect one of the valid renderbuffer formats for use in + // glRenderbufferStorage } } @@ -466,13 +481,4 @@ Stencilbuffer::~Stencilbuffer() { } -bool Stencilbuffer::isDepthbuffer() const -{ - return false; -} - -bool Stencilbuffer::isStencilbuffer() const -{ - return true; -} } |