Commit 64f23f65 by Geoff Lang

Update the getRenderTarget functions to return gl::Error objects.

BUG=angle:520 Change-Id: If1f4f71972b669704eff70b5f60927d8e6ac07b3 Reviewed-on: https://chromium-review.googlesource.com/218767Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 433bfd38
...@@ -1616,7 +1616,11 @@ Error Context::clear(GLbitfield mask) ...@@ -1616,7 +1616,11 @@ Error Context::clear(GLbitfield mask)
ClearParameters clearParams = mState.getClearParameters(mask); ClearParameters clearParams = mState.getClearParameters(mask);
applyRenderTarget(GL_TRIANGLES, true); // Clips the clear to the scissor rectangle but not the viewport Error error = applyRenderTarget(GL_TRIANGLES, true); // Clips the clear to the scissor rectangle but not the viewport
if (error.isError())
{
return error;
}
return mRenderer->clear(clearParams, mState.getDrawFramebuffer()); return mRenderer->clear(clearParams, mState.getDrawFramebuffer());
} }
...@@ -1647,7 +1651,11 @@ Error Context::clearBufferfv(GLenum buffer, int drawbuffer, const float *values) ...@@ -1647,7 +1651,11 @@ Error Context::clearBufferfv(GLenum buffer, int drawbuffer, const float *values)
clearParams.depthClearValue = values[0]; clearParams.depthClearValue = values[0];
} }
applyRenderTarget(GL_TRIANGLES, true); // Clips the clear to the scissor rectangle but not the viewport Error error = applyRenderTarget(GL_TRIANGLES, true); // Clips the clear to the scissor rectangle but not the viewport
if (error.isError())
{
return error;
}
return mRenderer->clear(clearParams, mState.getDrawFramebuffer()); return mRenderer->clear(clearParams, mState.getDrawFramebuffer());
} }
...@@ -1668,7 +1676,11 @@ Error Context::clearBufferuiv(GLenum buffer, int drawbuffer, const unsigned int ...@@ -1668,7 +1676,11 @@ Error Context::clearBufferuiv(GLenum buffer, int drawbuffer, const unsigned int
clearParams.colorUIClearValue = ColorUI(values[0], values[1], values[2], values[3]); clearParams.colorUIClearValue = ColorUI(values[0], values[1], values[2], values[3]);
clearParams.colorClearType = GL_UNSIGNED_INT; clearParams.colorClearType = GL_UNSIGNED_INT;
applyRenderTarget(GL_TRIANGLES, true); // Clips the clear to the scissor rectangle but not the viewport Error error = applyRenderTarget(GL_TRIANGLES, true); // Clips the clear to the scissor rectangle but not the viewport
if (error.isError())
{
return error;
}
return mRenderer->clear(clearParams, mState.getDrawFramebuffer()); return mRenderer->clear(clearParams, mState.getDrawFramebuffer());
} }
...@@ -1699,7 +1711,11 @@ Error Context::clearBufferiv(GLenum buffer, int drawbuffer, const int *values) ...@@ -1699,7 +1711,11 @@ Error Context::clearBufferiv(GLenum buffer, int drawbuffer, const int *values)
clearParams.stencilClearValue = values[1]; clearParams.stencilClearValue = values[1];
} }
applyRenderTarget(GL_TRIANGLES, true); // Clips the clear to the scissor rectangle but not the viewport Error error = applyRenderTarget(GL_TRIANGLES, true); // Clips the clear to the scissor rectangle but not the viewport
if (error.isError())
{
return error;
}
return mRenderer->clear(clearParams, mState.getDrawFramebuffer()); return mRenderer->clear(clearParams, mState.getDrawFramebuffer());
} }
...@@ -1718,7 +1734,11 @@ Error Context::clearBufferfi(GLenum buffer, int drawbuffer, float depth, int ste ...@@ -1718,7 +1734,11 @@ Error Context::clearBufferfi(GLenum buffer, int drawbuffer, float depth, int ste
clearParams.clearStencil = true; clearParams.clearStencil = true;
clearParams.stencilClearValue = stencil; clearParams.stencilClearValue = stencil;
applyRenderTarget(GL_TRIANGLES, true); // Clips the clear to the scissor rectangle but not the viewport Error error = applyRenderTarget(GL_TRIANGLES, true); // Clips the clear to the scissor rectangle but not the viewport
if (error.isError())
{
return error;
}
return mRenderer->clear(clearParams, mState.getDrawFramebuffer()); return mRenderer->clear(clearParams, mState.getDrawFramebuffer());
} }
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
namespace rx namespace rx
{ {
RenderTarget *GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment) gl::Error GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment, RenderTarget **outRT)
{ {
if (attachment->isTexture()) if (attachment->isTexture())
{ {
...@@ -32,14 +32,17 @@ RenderTarget *GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment) ...@@ -32,14 +32,17 @@ RenderTarget *GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment)
TextureD3D *textureD3D = TextureD3D::makeTextureD3D(texture->getImplementation()); TextureD3D *textureD3D = TextureD3D::makeTextureD3D(texture->getImplementation());
const gl::ImageIndex *index = attachment->getTextureImageIndex(); const gl::ImageIndex *index = attachment->getTextureImageIndex();
ASSERT(index); ASSERT(index);
return textureD3D->getRenderTarget(*index); return textureD3D->getRenderTarget(*index, outRT);
} }
else
{
gl::Renderbuffer *renderbuffer = attachment->getRenderbuffer();
ASSERT(renderbuffer);
gl::Renderbuffer *renderbuffer = attachment->getRenderbuffer(); // TODO: cast to RenderbufferD3D
ASSERT(renderbuffer); *outRT = renderbuffer->getStorage()->getRenderTarget();
return gl::Error(GL_NO_ERROR);
// TODO: cast to RenderbufferD3D }
return renderbuffer->getStorage()->getRenderTarget();
} }
// Note: RenderTarget serials should ideally be in the RenderTargets themselves. // Note: RenderTarget serials should ideally be in the RenderTargets themselves.
...@@ -603,33 +606,36 @@ GLenum Framebuffer::completeness() const ...@@ -603,33 +606,36 @@ GLenum Framebuffer::completeness() const
return GL_FRAMEBUFFER_COMPLETE; return GL_FRAMEBUFFER_COMPLETE;
} }
void Framebuffer::invalidate(const Caps &caps, GLsizei numAttachments, const GLenum *attachments) Error Framebuffer::invalidate(const Caps &caps, GLsizei numAttachments, const GLenum *attachments)
{ {
GLuint maxDimension = caps.maxRenderbufferSize; GLuint maxDimension = caps.maxRenderbufferSize;
invalidateSub(caps, numAttachments, attachments, 0, 0, maxDimension, maxDimension); return invalidateSub(numAttachments, attachments, 0, 0, maxDimension, maxDimension);
} }
void Framebuffer::invalidateSub(const Caps &caps, GLsizei numAttachments, const GLenum *attachments, Error Framebuffer::invalidateSub(GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height)
GLint x, GLint y, GLsizei width, GLsizei height)
{ {
ASSERT(completeness() == GL_FRAMEBUFFER_COMPLETE); ASSERT(completeness() == GL_FRAMEBUFFER_COMPLETE);
for (GLsizei attachIndex = 0; attachIndex < numAttachments; ++attachIndex) for (GLsizei attachIndex = 0; attachIndex < numAttachments; ++attachIndex)
{ {
GLenum attachmentTarget = attachments[attachIndex]; GLenum attachmentTarget = attachments[attachIndex];
gl::FramebufferAttachment *attachment = FramebufferAttachment *attachment = (attachmentTarget == GL_DEPTH_STENCIL_ATTACHMENT) ? getDepthOrStencilbuffer()
(attachmentTarget == GL_DEPTH_STENCIL_ATTACHMENT) ? getDepthOrStencilbuffer() : : getAttachment(attachmentTarget);
getAttachment(attachmentTarget);
if (attachment) if (attachment)
{ {
rx::RenderTarget *renderTarget = rx::GetAttachmentRenderTarget(attachment); rx::RenderTarget *renderTarget = NULL;
if (renderTarget) Error error = rx::GetAttachmentRenderTarget(attachment, &renderTarget);
if (error.isError())
{ {
renderTarget->invalidate(x, y, width, height); return error;
} }
renderTarget->invalidate(x, y, width, height);
} }
} }
return Error(GL_NO_ERROR);
} }
DefaultFramebuffer::DefaultFramebuffer(rx::Renderer *renderer, Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil) DefaultFramebuffer::DefaultFramebuffer(rx::Renderer *renderer, Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil)
......
...@@ -10,12 +10,14 @@ ...@@ -10,12 +10,14 @@
#ifndef LIBGLESV2_FRAMEBUFFER_H_ #ifndef LIBGLESV2_FRAMEBUFFER_H_
#define LIBGLESV2_FRAMEBUFFER_H_ #define LIBGLESV2_FRAMEBUFFER_H_
#include <vector> #include "libGLESv2/Error.h"
#include "common/angleutils.h" #include "common/angleutils.h"
#include "common/RefCountObject.h" #include "common/RefCountObject.h"
#include "Constants.h" #include "Constants.h"
#include <vector>
namespace rx namespace rx
{ {
class Renderer; class Renderer;
...@@ -72,9 +74,8 @@ class Framebuffer ...@@ -72,9 +74,8 @@ class Framebuffer
virtual GLenum completeness() const; virtual GLenum completeness() const;
bool hasValidDepthStencil() const; bool hasValidDepthStencil() const;
void invalidate(const Caps &caps, GLsizei numAttachments, const GLenum *attachments); Error invalidate(const Caps &caps, GLsizei numAttachments, const GLenum *attachments);
void invalidateSub(const Caps &caps, GLsizei numAttachments, const GLenum *attachments, Error invalidateSub(GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height);
GLint x, GLint y, GLsizei width, GLsizei height);
// Use this method to retrieve the color buffer map when doing rendering. // Use this method to retrieve the color buffer map when doing rendering.
// It will apply a workaround for poor shader performance on some systems // It will apply a workaround for poor shader performance on some systems
...@@ -118,7 +119,7 @@ namespace rx ...@@ -118,7 +119,7 @@ namespace rx
class RenderTarget; class RenderTarget;
// TODO: place this in FramebufferD3D.h // TODO: place this in FramebufferD3D.h
RenderTarget *GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment); gl::Error GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment, RenderTarget **outRT);
unsigned int GetAttachmentSerial(gl::FramebufferAttachment *attachment); unsigned int GetAttachmentSerial(gl::FramebufferAttachment *attachment);
} }
......
...@@ -8283,7 +8283,12 @@ void GL_APIENTRY glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, ...@@ -8283,7 +8283,12 @@ void GL_APIENTRY glInvalidateFramebuffer(GLenum target, GLsizei numAttachments,
gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target); gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE) if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
{ {
framebuffer->invalidate(context->getCaps(), numAttachments, attachments); gl::Error error = framebuffer->invalidate(context->getCaps(), numAttachments, attachments);
if (error.isError())
{
context->recordError(error);
return;
}
} }
} }
} }
...@@ -8311,7 +8316,12 @@ void GL_APIENTRY glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachment ...@@ -8311,7 +8316,12 @@ void GL_APIENTRY glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachment
gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target); gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE) if (framebuffer && framebuffer->completeness() == GL_FRAMEBUFFER_COMPLETE)
{ {
framebuffer->invalidateSub(context->getCaps(), numAttachments, attachments, x, y, width, height); gl::Error error = framebuffer->invalidateSub(numAttachments, attachments, x, y, width, height);
if (error.isError())
{
context->recordError(error);
return;
}
} }
} }
} }
......
...@@ -32,7 +32,13 @@ gl::Error Image::copy(GLint xoffset, GLint yoffset, GLint zoffset, const gl::Rec ...@@ -32,7 +32,13 @@ gl::Error Image::copy(GLint xoffset, GLint yoffset, GLint zoffset, const gl::Rec
gl::FramebufferAttachment *colorbuffer = source->getReadColorbuffer(); gl::FramebufferAttachment *colorbuffer = source->getReadColorbuffer();
ASSERT(colorbuffer); ASSERT(colorbuffer);
RenderTarget *renderTarget = GetAttachmentRenderTarget(colorbuffer); RenderTarget *renderTarget = NULL;
gl::Error error = GetAttachmentRenderTarget(colorbuffer, &renderTarget);
if (error.isError())
{
return error;
}
ASSERT(renderTarget); ASSERT(renderTarget);
return copy(xoffset, yoffset, zoffset, area, renderTarget); return copy(xoffset, yoffset, zoffset, area, renderTarget);
} }
......
...@@ -528,22 +528,25 @@ gl::Error TextureD3D_2D::setImage(GLenum target, GLint level, GLsizei width, GLs ...@@ -528,22 +528,25 @@ gl::Error TextureD3D_2D::setImage(GLenum target, GLint level, GLsizei width, GLs
if (isFastUnpackable(unpack, sizedInternalFormat) && isLevelComplete(level)) if (isFastUnpackable(unpack, sizedInternalFormat) && isLevelComplete(level))
{ {
// Will try to create RT storage if it does not exist // Will try to create RT storage if it does not exist
RenderTarget *destRenderTarget = getRenderTarget(index); RenderTarget *destRenderTarget = NULL;
gl::Error error = getRenderTarget(index, &destRenderTarget);
if (error.isError())
{
return error;
}
gl::Box destArea(0, 0, 0, getWidth(level), getHeight(level), 1); gl::Box destArea(0, 0, 0, getWidth(level), getHeight(level), 1);
if (destRenderTarget) error = fastUnpackPixels(unpack, pixels, destArea, sizedInternalFormat, type, destRenderTarget);
if (error.isError())
{ {
gl::Error error = fastUnpackPixels(unpack, pixels, destArea, sizedInternalFormat, type, destRenderTarget); return error;
if (error.isError()) }
{
return error;
}
// Ensure we don't overwrite our newly initialized data // Ensure we don't overwrite our newly initialized data
mImageArray[level]->markClean(); mImageArray[level]->markClean();
fastUnpacked = true; fastUnpacked = true;
}
} }
if (!fastUnpacked) if (!fastUnpacked)
...@@ -582,21 +585,23 @@ gl::Error TextureD3D_2D::subImage(GLenum target, GLint level, GLint xoffset, GLi ...@@ -582,21 +585,23 @@ gl::Error TextureD3D_2D::subImage(GLenum target, GLint level, GLint xoffset, GLi
gl::Box destArea(xoffset, yoffset, 0, width, height, 1); gl::Box destArea(xoffset, yoffset, 0, width, height, 1);
if (isFastUnpackable(unpack, getInternalFormat(level)) && isLevelComplete(level)) if (isFastUnpackable(unpack, getInternalFormat(level)) && isLevelComplete(level))
{ {
RenderTarget *renderTarget = getRenderTarget(index); RenderTarget *renderTarget = NULL;
gl::Error error = getRenderTarget(index, &renderTarget);
if (error.isError())
{
return error;
}
if (renderTarget) error = fastUnpackPixels(unpack, pixels, destArea, getInternalFormat(level), type, renderTarget);
if (error.isError())
{ {
gl::Error error = fastUnpackPixels(unpack, pixels, destArea, getInternalFormat(level), type, renderTarget); return error;
if (error.isError()) }
{
return error;
}
// Ensure we don't overwrite our newly initialized data // Ensure we don't overwrite our newly initialized data
mImageArray[level]->markClean(); mImageArray[level]->markClean();
fastUnpacked = true; fastUnpacked = true;
}
} }
if (!fastUnpacked) if (!fastUnpacked)
...@@ -797,7 +802,7 @@ unsigned int TextureD3D_2D::getRenderTargetSerial(const gl::ImageIndex &index) ...@@ -797,7 +802,7 @@ unsigned int TextureD3D_2D::getRenderTargetSerial(const gl::ImageIndex &index)
return (!ensureRenderTarget().isError() ? mTexStorage->getRenderTargetSerial(index) : 0); return (!ensureRenderTarget().isError() ? mTexStorage->getRenderTargetSerial(index) : 0);
} }
RenderTarget *TextureD3D_2D::getRenderTarget(const gl::ImageIndex &index) gl::Error TextureD3D_2D::getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT)
{ {
ASSERT(!index.hasLayer()); ASSERT(!index.hasLayer());
...@@ -805,16 +810,16 @@ RenderTarget *TextureD3D_2D::getRenderTarget(const gl::ImageIndex &index) ...@@ -805,16 +810,16 @@ RenderTarget *TextureD3D_2D::getRenderTarget(const gl::ImageIndex &index)
gl::Error error = ensureRenderTarget(); gl::Error error = ensureRenderTarget();
if (error.isError()) if (error.isError())
{ {
return NULL; return error;
} }
error = updateStorageLevel(index.mipIndex); error = updateStorageLevel(index.mipIndex);
if (error.isError()) if (error.isError())
{ {
return NULL; return error;
} }
return mTexStorage->getRenderTarget(index); return mTexStorage->getRenderTarget(index, outRT);
} }
bool TextureD3D_2D::isValidLevel(int level) const bool TextureD3D_2D::isValidLevel(int level) const
...@@ -1352,7 +1357,7 @@ unsigned int TextureD3D_Cube::getRenderTargetSerial(const gl::ImageIndex &index) ...@@ -1352,7 +1357,7 @@ unsigned int TextureD3D_Cube::getRenderTargetSerial(const gl::ImageIndex &index)
return (ensureRenderTarget().isError() ? mTexStorage->getRenderTargetSerial(index) : 0); return (ensureRenderTarget().isError() ? mTexStorage->getRenderTargetSerial(index) : 0);
} }
RenderTarget *TextureD3D_Cube::getRenderTarget(const gl::ImageIndex &index) gl::Error TextureD3D_Cube::getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT)
{ {
ASSERT(gl::IsCubemapTextureTarget(index.type)); ASSERT(gl::IsCubemapTextureTarget(index.type));
...@@ -1360,16 +1365,16 @@ RenderTarget *TextureD3D_Cube::getRenderTarget(const gl::ImageIndex &index) ...@@ -1360,16 +1365,16 @@ RenderTarget *TextureD3D_Cube::getRenderTarget(const gl::ImageIndex &index)
gl::Error error = ensureRenderTarget(); gl::Error error = ensureRenderTarget();
if (error.isError()) if (error.isError())
{ {
return NULL; return error;
} }
error = updateStorageFaceLevel(index.layerIndex, index.mipIndex); error = updateStorageFaceLevel(index.layerIndex, index.mipIndex);
if (error.isError()) if (error.isError())
{ {
return NULL; return error;
} }
return mTexStorage->getRenderTarget(index); return mTexStorage->getRenderTarget(index, outRT);
} }
gl::Error TextureD3D_Cube::initializeStorage(bool renderTarget) gl::Error TextureD3D_Cube::initializeStorage(bool renderTarget)
...@@ -1703,22 +1708,25 @@ gl::Error TextureD3D_3D::setImage(GLenum target, GLint level, GLsizei width, GLs ...@@ -1703,22 +1708,25 @@ gl::Error TextureD3D_3D::setImage(GLenum target, GLint level, GLsizei width, GLs
if (isFastUnpackable(unpack, sizedInternalFormat)) if (isFastUnpackable(unpack, sizedInternalFormat))
{ {
// Will try to create RT storage if it does not exist // Will try to create RT storage if it does not exist
RenderTarget *destRenderTarget = getRenderTarget(index); RenderTarget *destRenderTarget = NULL;
gl::Error error = getRenderTarget(index, &destRenderTarget);
if (error.isError())
{
return error;
}
gl::Box destArea(0, 0, 0, getWidth(level), getHeight(level), getDepth(level)); gl::Box destArea(0, 0, 0, getWidth(level), getHeight(level), getDepth(level));
if (destRenderTarget) error = fastUnpackPixels(unpack, pixels, destArea, sizedInternalFormat, type, destRenderTarget);
if (error.isError())
{ {
gl::Error error = fastUnpackPixels(unpack, pixels, destArea, sizedInternalFormat, type, destRenderTarget); return error;
if (error.isError()) }
{
return error;
}
// Ensure we don't overwrite our newly initialized data // Ensure we don't overwrite our newly initialized data
mImageArray[level]->markClean(); mImageArray[level]->markClean();
fastUnpacked = true; fastUnpacked = true;
}
} }
if (!fastUnpacked) if (!fastUnpacked)
...@@ -1758,22 +1766,24 @@ gl::Error TextureD3D_3D::subImage(GLenum target, GLint level, GLint xoffset, GLi ...@@ -1758,22 +1766,24 @@ gl::Error TextureD3D_3D::subImage(GLenum target, GLint level, GLint xoffset, GLi
// Attempt a fast gpu copy of the pixel data to the surface if the app bound an unpack buffer // Attempt a fast gpu copy of the pixel data to the surface if the app bound an unpack buffer
if (isFastUnpackable(unpack, getInternalFormat(level))) if (isFastUnpackable(unpack, getInternalFormat(level)))
{ {
RenderTarget *destRenderTarget = getRenderTarget(index); RenderTarget *destRenderTarget = NULL;
gl::Error error = getRenderTarget(index, &destRenderTarget);
if (error.isError())
{
return error;
}
if (destRenderTarget) gl::Box destArea(xoffset, yoffset, zoffset, width, height, depth);
error = fastUnpackPixels(unpack, pixels, destArea, getInternalFormat(level), type, destRenderTarget);
if (error.isError())
{ {
gl::Box destArea(xoffset, yoffset, zoffset, width, height, depth); return error;
gl::Error error = fastUnpackPixels(unpack, pixels, destArea, getInternalFormat(level), type, destRenderTarget); }
if (error.isError())
{
return error;
}
// Ensure we don't overwrite our newly initialized data // Ensure we don't overwrite our newly initialized data
mImageArray[level]->markClean(); mImageArray[level]->markClean();
fastUnpacked = true; fastUnpacked = true;
}
} }
if (!fastUnpacked) if (!fastUnpacked)
...@@ -1922,13 +1932,13 @@ unsigned int TextureD3D_3D::getRenderTargetSerial(const gl::ImageIndex &index) ...@@ -1922,13 +1932,13 @@ unsigned int TextureD3D_3D::getRenderTargetSerial(const gl::ImageIndex &index)
return (!ensureRenderTarget().isError() ? mTexStorage->getRenderTargetSerial(index) : 0); return (!ensureRenderTarget().isError() ? mTexStorage->getRenderTargetSerial(index) : 0);
} }
RenderTarget *TextureD3D_3D::getRenderTarget(const gl::ImageIndex &index) gl::Error TextureD3D_3D::getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT)
{ {
// ensure the underlying texture is created // ensure the underlying texture is created
gl::Error error = ensureRenderTarget(); gl::Error error = ensureRenderTarget();
if (error.isError()) if (error.isError())
{ {
return NULL; return error;
} }
if (index.hasLayer()) if (index.hasLayer())
...@@ -1936,7 +1946,7 @@ RenderTarget *TextureD3D_3D::getRenderTarget(const gl::ImageIndex &index) ...@@ -1936,7 +1946,7 @@ RenderTarget *TextureD3D_3D::getRenderTarget(const gl::ImageIndex &index)
error = updateStorage(); error = updateStorage();
if (error.isError()) if (error.isError())
{ {
return NULL; return error;
} }
} }
else else
...@@ -1944,11 +1954,11 @@ RenderTarget *TextureD3D_3D::getRenderTarget(const gl::ImageIndex &index) ...@@ -1944,11 +1954,11 @@ RenderTarget *TextureD3D_3D::getRenderTarget(const gl::ImageIndex &index)
error = updateStorageLevel(index.mipIndex); error = updateStorageLevel(index.mipIndex);
if (error.isError()) if (error.isError())
{ {
return NULL; return error;
} }
} }
return mTexStorage->getRenderTarget(index); return mTexStorage->getRenderTarget(index, outRT);
} }
gl::Error TextureD3D_3D::initializeStorage(bool renderTarget) gl::Error TextureD3D_3D::initializeStorage(bool renderTarget)
...@@ -2474,22 +2484,22 @@ unsigned int TextureD3D_2DArray::getRenderTargetSerial(const gl::ImageIndex &ind ...@@ -2474,22 +2484,22 @@ unsigned int TextureD3D_2DArray::getRenderTargetSerial(const gl::ImageIndex &ind
return (!ensureRenderTarget().isError() ? mTexStorage->getRenderTargetSerial(index) : 0); return (!ensureRenderTarget().isError() ? mTexStorage->getRenderTargetSerial(index) : 0);
} }
RenderTarget *TextureD3D_2DArray::getRenderTarget(const gl::ImageIndex &index) gl::Error TextureD3D_2DArray::getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT)
{ {
// ensure the underlying texture is created // ensure the underlying texture is created
gl::Error error = ensureRenderTarget(); gl::Error error = ensureRenderTarget();
if (error.isError()) if (error.isError())
{ {
return NULL; return error;
} }
error = updateStorageLevel(index.mipIndex); error = updateStorageLevel(index.mipIndex);
if (error.isError()) if (error.isError())
{ {
return NULL; return error;
} }
return mTexStorage->getRenderTarget(index); return mTexStorage->getRenderTarget(index, outRT);
} }
gl::Error TextureD3D_2DArray::initializeStorage(bool renderTarget) gl::Error TextureD3D_2DArray::initializeStorage(bool renderTarget)
......
...@@ -48,7 +48,7 @@ class TextureD3D : public TextureImpl ...@@ -48,7 +48,7 @@ class TextureD3D : public TextureImpl
bool isImmutable() const { return mImmutable; } bool isImmutable() const { return mImmutable; }
virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index) = 0; virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT) = 0;
virtual unsigned int getRenderTargetSerial(const gl::ImageIndex &index) = 0; virtual unsigned int getRenderTargetSerial(const gl::ImageIndex &index) = 0;
// Returns an iterator over all "Images" for this particular Texture. // Returns an iterator over all "Images" for this particular Texture.
...@@ -130,7 +130,7 @@ class TextureD3D_2D : public TextureD3D ...@@ -130,7 +130,7 @@ class TextureD3D_2D : public TextureD3D
virtual void bindTexImage(egl::Surface *surface); virtual void bindTexImage(egl::Surface *surface);
virtual void releaseTexImage(); virtual void releaseTexImage();
virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index); virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual unsigned int getRenderTargetSerial(const gl::ImageIndex &index); virtual unsigned int getRenderTargetSerial(const gl::ImageIndex &index);
virtual gl::ImageIndexIterator imageIterator() const; virtual gl::ImageIndexIterator imageIterator() const;
...@@ -185,7 +185,7 @@ class TextureD3D_Cube : public TextureD3D ...@@ -185,7 +185,7 @@ class TextureD3D_Cube : public TextureD3D
virtual void bindTexImage(egl::Surface *surface); virtual void bindTexImage(egl::Surface *surface);
virtual void releaseTexImage(); virtual void releaseTexImage();
virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index); virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual unsigned int getRenderTargetSerial(const gl::ImageIndex &index); virtual unsigned int getRenderTargetSerial(const gl::ImageIndex &index);
virtual gl::ImageIndexIterator imageIterator() const; virtual gl::ImageIndexIterator imageIterator() const;
...@@ -239,7 +239,7 @@ class TextureD3D_3D : public TextureD3D ...@@ -239,7 +239,7 @@ class TextureD3D_3D : public TextureD3D
virtual void bindTexImage(egl::Surface *surface); virtual void bindTexImage(egl::Surface *surface);
virtual void releaseTexImage(); virtual void releaseTexImage();
virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index); virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual unsigned int getRenderTargetSerial(const gl::ImageIndex &index); virtual unsigned int getRenderTargetSerial(const gl::ImageIndex &index);
virtual gl::ImageIndexIterator imageIterator() const; virtual gl::ImageIndexIterator imageIterator() const;
...@@ -291,7 +291,7 @@ class TextureD3D_2DArray : public TextureD3D ...@@ -291,7 +291,7 @@ class TextureD3D_2DArray : public TextureD3D
virtual void bindTexImage(egl::Surface *surface); virtual void bindTexImage(egl::Surface *surface);
virtual void releaseTexImage(); virtual void releaseTexImage();
virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index); virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual unsigned int getRenderTargetSerial(const gl::ImageIndex &index); virtual unsigned int getRenderTargetSerial(const gl::ImageIndex &index);
virtual gl::ImageIndexIterator imageIterator() const; virtual gl::ImageIndexIterator imageIterator() const;
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#ifndef LIBGLESV2_RENDERER_TEXTURESTORAGE_H_ #ifndef LIBGLESV2_RENDERER_TEXTURESTORAGE_H_
#define LIBGLESV2_RENDERER_TEXTURESTORAGE_H_ #define LIBGLESV2_RENDERER_TEXTURESTORAGE_H_
#include "libGLESv2/Error.h"
#include "common/debug.h" #include "common/debug.h"
#include "libGLESv2/Error.h" #include "libGLESv2/Error.h"
...@@ -40,7 +42,7 @@ class TextureStorage ...@@ -40,7 +42,7 @@ class TextureStorage
virtual bool isManaged() const = 0; virtual bool isManaged() const = 0;
virtual int getLevelCount() const = 0; virtual int getLevelCount() const = 0;
virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index) = 0; virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT) = 0;
virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex) = 0; virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex) = 0;
virtual gl::Error copyToStorage(TextureStorage *destStorage) = 0; virtual gl::Error copyToStorage(TextureStorage *destStorage) = 0;
......
...@@ -211,10 +211,11 @@ gl::Error Clear11::clearFramebuffer(const gl::ClearParameters &clearParams, gl:: ...@@ -211,10 +211,11 @@ gl::Error Clear11::clearFramebuffer(const gl::ClearParameters &clearParams, gl::
gl::FramebufferAttachment *attachment = frameBuffer->getColorbuffer(colorAttachment); gl::FramebufferAttachment *attachment = frameBuffer->getColorbuffer(colorAttachment);
if (attachment) if (attachment)
{ {
RenderTarget11 *renderTarget = d3d11::GetAttachmentRenderTarget(attachment); RenderTarget11 *renderTarget = NULL;
if (!renderTarget) gl::Error error = d3d11::GetAttachmentRenderTarget(attachment, &renderTarget);
if (error.isError())
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Internal render target view pointer unexpectedly null."); return error;
} }
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(attachment->getInternalFormat()); const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(attachment->getInternalFormat());
...@@ -284,10 +285,11 @@ gl::Error Clear11::clearFramebuffer(const gl::ClearParameters &clearParams, gl:: ...@@ -284,10 +285,11 @@ gl::Error Clear11::clearFramebuffer(const gl::ClearParameters &clearParams, gl::
gl::FramebufferAttachment *attachment = frameBuffer->getDepthOrStencilbuffer(); gl::FramebufferAttachment *attachment = frameBuffer->getDepthOrStencilbuffer();
if (attachment) if (attachment)
{ {
RenderTarget11 *renderTarget = d3d11::GetAttachmentRenderTarget(attachment); RenderTarget11 *renderTarget = NULL;
if (!renderTarget) gl::Error error = d3d11::GetAttachmentRenderTarget(attachment, &renderTarget);
if (error.isError())
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Internal depth stencil view pointer unexpectedly null."); return error;
} }
const gl::InternalFormat &actualFormatInfo = gl::GetInternalFormatInfo(attachment->getActualFormat()); const gl::InternalFormat &actualFormatInfo = gl::GetInternalFormatInfo(attachment->getActualFormat());
......
...@@ -190,7 +190,8 @@ class Renderer11 : public Renderer ...@@ -190,7 +190,8 @@ class Renderer11 : public Renderer
virtual gl::Error fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget, virtual gl::Error fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea); GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea);
bool getRenderTargetResource(gl::FramebufferAttachment *colorbuffer, unsigned int *subresourceIndexOut, ID3D11Texture2D **texture2DOut); gl::Error getRenderTargetResource(gl::FramebufferAttachment *colorbuffer, unsigned int *subresourceIndexOut, ID3D11Texture2D **texture2DOut);
void unapplyRenderTargets(); void unapplyRenderTargets();
void setOneTimeRenderTarget(ID3D11RenderTargetView *renderTargetView); void setOneTimeRenderTarget(ID3D11RenderTargetView *renderTargetView);
gl::Error packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams &params, uint8_t *pixelsOut); gl::Error packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams &params, uint8_t *pixelsOut);
......
...@@ -43,7 +43,7 @@ class TextureStorage11 : public TextureStorage ...@@ -43,7 +43,7 @@ class TextureStorage11 : public TextureStorage
virtual ID3D11Resource *getResource() const = 0; virtual ID3D11Resource *getResource() const = 0;
virtual gl::Error getSRV(const gl::SamplerState &samplerState, ID3D11ShaderResourceView **outSRV); virtual gl::Error getSRV(const gl::SamplerState &samplerState, ID3D11ShaderResourceView **outSRV);
virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index) = 0; virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT) = 0;
virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex); virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex);
...@@ -148,7 +148,7 @@ class TextureStorage11_2D : public TextureStorage11 ...@@ -148,7 +148,7 @@ class TextureStorage11_2D : public TextureStorage11
static TextureStorage11_2D *makeTextureStorage11_2D(TextureStorage *storage); static TextureStorage11_2D *makeTextureStorage11_2D(TextureStorage *storage);
virtual ID3D11Resource *getResource() const; virtual ID3D11Resource *getResource() const;
virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index); virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual void associateImage(Image11* image, const gl::ImageIndex &index); virtual void associateImage(Image11* image, const gl::ImageIndex &index);
virtual void disassociateImage(const gl::ImageIndex &index, Image11* expectedImage); virtual void disassociateImage(const gl::ImageIndex &index, Image11* expectedImage);
...@@ -183,7 +183,7 @@ class TextureStorage11_Cube : public TextureStorage11 ...@@ -183,7 +183,7 @@ class TextureStorage11_Cube : public TextureStorage11
static TextureStorage11_Cube *makeTextureStorage11_Cube(TextureStorage *storage); static TextureStorage11_Cube *makeTextureStorage11_Cube(TextureStorage *storage);
virtual ID3D11Resource *getResource() const; virtual ID3D11Resource *getResource() const;
virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index); virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual void associateImage(Image11* image, const gl::ImageIndex &index); virtual void associateImage(Image11* image, const gl::ImageIndex &index);
virtual void disassociateImage(const gl::ImageIndex &index, Image11* expectedImage); virtual void disassociateImage(const gl::ImageIndex &index, Image11* expectedImage);
...@@ -221,7 +221,7 @@ class TextureStorage11_3D : public TextureStorage11 ...@@ -221,7 +221,7 @@ class TextureStorage11_3D : public TextureStorage11
virtual ID3D11Resource *getResource() const; virtual ID3D11Resource *getResource() const;
// Handles both layer and non-layer RTs // Handles both layer and non-layer RTs
virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index); virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual void associateImage(Image11* image, const gl::ImageIndex &index); virtual void associateImage(Image11* image, const gl::ImageIndex &index);
virtual void disassociateImage(const gl::ImageIndex &index, Image11* expectedImage); virtual void disassociateImage(const gl::ImageIndex &index, Image11* expectedImage);
...@@ -261,7 +261,7 @@ class TextureStorage11_2DArray : public TextureStorage11 ...@@ -261,7 +261,7 @@ class TextureStorage11_2DArray : public TextureStorage11
static TextureStorage11_2DArray *makeTextureStorage11_2DArray(TextureStorage *storage); static TextureStorage11_2DArray *makeTextureStorage11_2DArray(TextureStorage *storage);
virtual ID3D11Resource *getResource() const; virtual ID3D11Resource *getResource() const;
virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index); virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual void associateImage(Image11* image, const gl::ImageIndex &index); virtual void associateImage(Image11* image, const gl::ImageIndex &index);
virtual void disassociateImage(const gl::ImageIndex &index, Image11* expectedImage); virtual void disassociateImage(const gl::ImageIndex &index, Image11* expectedImage);
......
...@@ -1066,10 +1066,16 @@ HRESULT SetDebugName(ID3D11DeviceChild *resource, const char *name) ...@@ -1066,10 +1066,16 @@ HRESULT SetDebugName(ID3D11DeviceChild *resource, const char *name)
#endif #endif
} }
RenderTarget11 *GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment) gl::Error GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment, RenderTarget11 **outRT)
{ {
RenderTarget *renderTarget = rx::GetAttachmentRenderTarget(attachment); RenderTarget *renderTarget = NULL;
return RenderTarget11::makeRenderTarget11(renderTarget); gl::Error error = rx::GetAttachmentRenderTarget(attachment, &renderTarget);
if (error.isError())
{
return error;
}
*outRT = RenderTarget11::makeRenderTarget11(renderTarget);
return gl::Error(GL_NO_ERROR);
} }
Workarounds GenerateWorkarounds() Workarounds GenerateWorkarounds()
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "libGLESv2/angletypes.h" #include "libGLESv2/angletypes.h"
#include "libGLESv2/Caps.h" #include "libGLESv2/Caps.h"
#include "libGLESv2/Error.h"
#include <vector> #include <vector>
...@@ -177,7 +178,7 @@ inline void SetBufferData(ID3D11DeviceContext *context, ID3D11Buffer *constantBu ...@@ -177,7 +178,7 @@ inline void SetBufferData(ID3D11DeviceContext *context, ID3D11Buffer *constantBu
context->Unmap(constantBuffer, 0); context->Unmap(constantBuffer, 0);
} }
RenderTarget11 *GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment); gl::Error GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment, RenderTarget11 **outRT);
Workarounds GenerateWorkarounds(); Workarounds GenerateWorkarounds();
......
...@@ -208,32 +208,23 @@ gl::Error Blit9::boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest) ...@@ -208,32 +208,23 @@ gl::Error Blit9::boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest)
gl::Error Blit9::copy2D(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, TextureStorage *storage, GLint level) gl::Error Blit9::copy2D(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, TextureStorage *storage, GLint level)
{ {
RenderTarget9 *renderTarget = NULL;
IDirect3DSurface9 *source = NULL;
gl::FramebufferAttachment *colorbuffer = framebuffer->getColorbuffer(0); gl::FramebufferAttachment *colorbuffer = framebuffer->getColorbuffer(0);
ASSERT(colorbuffer);
if (colorbuffer) RenderTarget9 *renderTarget9 = NULL;
{ gl::Error error = d3d9::GetAttachmentRenderTarget(colorbuffer, &renderTarget9);
renderTarget = d3d9::GetAttachmentRenderTarget(colorbuffer); if (error.isError())
}
if (renderTarget)
{ {
source = renderTarget->getSurface(); return error;
} }
ASSERT(renderTarget9);
if (!source) IDirect3DSurface9 *source = renderTarget9->getSurface();
{ ASSERT(source);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the internal render target for texture blit.");
}
TextureStorage9_2D *storage9 = TextureStorage9_2D::makeTextureStorage9_2D(storage); TextureStorage9_2D *storage9 = TextureStorage9_2D::makeTextureStorage9_2D(storage);
IDirect3DSurface9 *destSurface = storage9->getSurfaceLevel(level, true); IDirect3DSurface9 *destSurface = storage9->getSurfaceLevel(level, true);
if (!destSurface) ASSERT(destSurface);
{
SafeRelease(source);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the destination surface for texture blit.");
}
gl::Error result = copy(source, sourceRect, destFormat, xoffset, yoffset, destSurface); gl::Error result = copy(source, sourceRect, destFormat, xoffset, yoffset, destSurface);
...@@ -245,33 +236,23 @@ gl::Error Blit9::copy2D(gl::Framebuffer *framebuffer, const RECT &sourceRect, GL ...@@ -245,33 +236,23 @@ gl::Error Blit9::copy2D(gl::Framebuffer *framebuffer, const RECT &sourceRect, GL
gl::Error Blit9::copyCube(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, TextureStorage *storage, GLenum target, GLint level) gl::Error Blit9::copyCube(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, TextureStorage *storage, GLenum target, GLint level)
{ {
RenderTarget9 *renderTarget = NULL;
IDirect3DSurface9 *source = NULL;
gl::FramebufferAttachment *colorbuffer = framebuffer->getColorbuffer(0); gl::FramebufferAttachment *colorbuffer = framebuffer->getColorbuffer(0);
ASSERT(colorbuffer);
if (colorbuffer) RenderTarget9 *renderTarget9 = NULL;
{ gl::Error error = d3d9::GetAttachmentRenderTarget(colorbuffer, &renderTarget9);
renderTarget = d3d9::GetAttachmentRenderTarget(colorbuffer); if (error.isError())
}
if (renderTarget)
{ {
source = renderTarget->getSurface(); return error;
} }
ASSERT(renderTarget9);
if (!source) IDirect3DSurface9 *source = renderTarget9->getSurface();
{ ASSERT(source);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the internal render target for texture blit.");
}
TextureStorage9_Cube *storage9 = TextureStorage9_Cube::makeTextureStorage9_Cube(storage); TextureStorage9_Cube *storage9 = TextureStorage9_Cube::makeTextureStorage9_Cube(storage);
IDirect3DSurface9 *destSurface = storage9->getCubeMapSurface(target, level, true); IDirect3DSurface9 *destSurface = storage9->getCubeMapSurface(target, level, true);
ASSERT(destSurface);
if (!destSurface)
{
SafeRelease(source);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the destination surface for texture blit.");
}
gl::Error result = copy(source, sourceRect, destFormat, xoffset, yoffset, destSurface); gl::Error result = copy(source, sourceRect, destFormat, xoffset, yoffset, destSurface);
......
...@@ -479,17 +479,9 @@ gl::Error Image9::copy(GLint xoffset, GLint yoffset, GLint zoffset, const gl::Re ...@@ -479,17 +479,9 @@ gl::Error Image9::copy(GLint xoffset, GLint yoffset, GLint zoffset, const gl::Re
ASSERT(zoffset == 0); ASSERT(zoffset == 0);
RenderTarget9 *renderTarget = RenderTarget9::makeRenderTarget9(source); RenderTarget9 *renderTarget = RenderTarget9::makeRenderTarget9(source);
IDirect3DSurface9 *surface = NULL;
if (renderTarget) IDirect3DSurface9 *surface = renderTarget->getSurface();
{ ASSERT(surface);
surface = renderTarget->getSurface();
}
if (!surface)
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the internal render target.");
}
IDirect3DDevice9 *device = mRenderer->getDevice(); IDirect3DDevice9 *device = mRenderer->getDevice();
......
...@@ -1191,28 +1191,23 @@ gl::Error Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer) ...@@ -1191,28 +1191,23 @@ gl::Error Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer)
{ {
attachment = getNullColorbuffer(framebuffer->getDepthbuffer()); attachment = getNullColorbuffer(framebuffer->getDepthbuffer());
} }
if (!attachment) ASSERT(attachment);
{
return gl::Error(GL_OUT_OF_MEMORY, "Unable to locate renderbuffer for FBO.");
}
bool renderTargetChanged = false; bool renderTargetChanged = false;
unsigned int renderTargetSerial = GetAttachmentSerial(attachment); unsigned int renderTargetSerial = GetAttachmentSerial(attachment);
if (renderTargetSerial != mAppliedRenderTargetSerial) if (renderTargetSerial != mAppliedRenderTargetSerial)
{ {
// Apply the render target on the device // Apply the render target on the device
IDirect3DSurface9 *renderTargetSurface = NULL; RenderTarget9 *renderTarget = NULL;
gl::Error error = d3d9::GetAttachmentRenderTarget(attachment, &renderTarget);
RenderTarget9 *renderTarget = d3d9::GetAttachmentRenderTarget(attachment); if (error.isError())
if (renderTarget)
{ {
renderTargetSurface = renderTarget->getSurface(); return error;
} }
ASSERT(renderTarget);
if (!renderTargetSurface) IDirect3DSurface9 *renderTargetSurface = renderTarget->getSurface();
{ ASSERT(renderTargetSurface);
return gl::Error(GL_OUT_OF_MEMORY, "Internal render target pointer unexpectedly null.");
}
mDevice->SetRenderTarget(0, renderTargetSurface); mDevice->SetRenderTarget(0, renderTargetSurface);
SafeRelease(renderTargetSurface); SafeRelease(renderTargetSurface);
...@@ -1244,18 +1239,16 @@ gl::Error Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer) ...@@ -1244,18 +1239,16 @@ gl::Error Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer)
// Apply the depth stencil on the device // Apply the depth stencil on the device
if (depthStencil) if (depthStencil)
{ {
IDirect3DSurface9 *depthStencilSurface = NULL; RenderTarget9 *depthStencilRenderTarget = NULL;
rx::RenderTarget9 *depthStencilRenderTarget = d3d9::GetAttachmentRenderTarget(depthStencil); gl::Error error = d3d9::GetAttachmentRenderTarget(depthStencil, &depthStencilRenderTarget);
if (error.isError())
if (depthStencilRenderTarget)
{ {
depthStencilSurface = depthStencilRenderTarget->getSurface(); return error;
} }
ASSERT(depthStencilRenderTarget);
if (!depthStencilSurface) IDirect3DSurface9 *depthStencilSurface = depthStencilRenderTarget->getSurface();
{ ASSERT(depthStencilSurface);
return gl::Error(GL_OUT_OF_MEMORY, "Internal depth stencil pointer unexpectedly null.");
}
mDevice->SetDepthStencilSurface(depthStencilSurface); mDevice->SetDepthStencilSurface(depthStencilSurface);
SafeRelease(depthStencilSurface); SafeRelease(depthStencilSurface);
...@@ -2447,34 +2440,33 @@ gl::Error Renderer9::blitRect(gl::Framebuffer *readFramebuffer, const gl::Rectan ...@@ -2447,34 +2440,33 @@ gl::Error Renderer9::blitRect(gl::Framebuffer *readFramebuffer, const gl::Rectan
if (blitRenderTarget) if (blitRenderTarget)
{ {
gl::FramebufferAttachment *readBuffer = readFramebuffer->getColorbuffer(0); gl::FramebufferAttachment *readBuffer = readFramebuffer->getColorbuffer(0);
gl::FramebufferAttachment *drawBuffer = drawFramebuffer->getColorbuffer(0); ASSERT(readBuffer);
RenderTarget9 *readRenderTarget = NULL;
RenderTarget9 *drawRenderTarget = NULL;
IDirect3DSurface9* readSurface = NULL;
IDirect3DSurface9* drawSurface = NULL;
if (readBuffer) RenderTarget9 *readRenderTarget = NULL;
{ gl::Error error = d3d9::GetAttachmentRenderTarget(readBuffer, &readRenderTarget);
readRenderTarget = d3d9::GetAttachmentRenderTarget(readBuffer); if (error.isError())
}
if (drawBuffer)
{ {
drawRenderTarget = d3d9::GetAttachmentRenderTarget(drawBuffer); return error;
} }
ASSERT(readRenderTarget);
if (readRenderTarget) gl::FramebufferAttachment *drawBuffer = drawFramebuffer->getColorbuffer(0);
{ ASSERT(drawBuffer);
readSurface = readRenderTarget->getSurface();
}
if (drawRenderTarget)
{
drawSurface = drawRenderTarget->getSurface();
}
if (!readSurface || !drawSurface) RenderTarget9 *drawRenderTarget = NULL;
error = d3d9::GetAttachmentRenderTarget(drawBuffer, &drawRenderTarget);
if (error.isError())
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the internal render targets for the blit framebuffers."); return error;
} }
ASSERT(drawRenderTarget);
// The getSurface calls do an AddRef so save them until after no errors are possible
IDirect3DSurface9* readSurface = readRenderTarget->getSurface();
ASSERT(readSurface);
IDirect3DSurface9* drawSurface = drawRenderTarget->getSurface();
ASSERT(drawSurface);
gl::Extents srcSize(readRenderTarget->getWidth(), readRenderTarget->getHeight(), 1); gl::Extents srcSize(readRenderTarget->getWidth(), readRenderTarget->getHeight(), 1);
gl::Extents dstSize(drawRenderTarget->getWidth(), drawRenderTarget->getHeight(), 1); gl::Extents dstSize(drawRenderTarget->getWidth(), drawRenderTarget->getHeight(), 1);
...@@ -2574,34 +2566,33 @@ gl::Error Renderer9::blitRect(gl::Framebuffer *readFramebuffer, const gl::Rectan ...@@ -2574,34 +2566,33 @@ gl::Error Renderer9::blitRect(gl::Framebuffer *readFramebuffer, const gl::Rectan
if (blitDepth || blitStencil) if (blitDepth || blitStencil)
{ {
gl::FramebufferAttachment *readBuffer = readFramebuffer->getDepthOrStencilbuffer(); gl::FramebufferAttachment *readBuffer = readFramebuffer->getDepthOrStencilbuffer();
gl::FramebufferAttachment *drawBuffer = drawFramebuffer->getDepthOrStencilbuffer(); ASSERT(readBuffer);
RenderTarget9 *readDepthStencil = NULL;
RenderTarget9 *drawDepthStencil = NULL;
IDirect3DSurface9* readSurface = NULL;
IDirect3DSurface9* drawSurface = NULL;
if (readBuffer) RenderTarget9 *readDepthStencil = NULL;
{ gl::Error error = d3d9::GetAttachmentRenderTarget(readBuffer, &readDepthStencil);
readDepthStencil = d3d9::GetAttachmentRenderTarget(readBuffer); if (error.isError())
}
if (drawBuffer)
{ {
drawDepthStencil = d3d9::GetAttachmentRenderTarget(drawBuffer); return error;
} }
ASSERT(readDepthStencil);
if (readDepthStencil) gl::FramebufferAttachment *drawBuffer = drawFramebuffer->getDepthOrStencilbuffer();
{ ASSERT(drawBuffer);
readSurface = readDepthStencil->getSurface();
}
if (drawDepthStencil)
{
drawSurface = drawDepthStencil->getSurface();
}
if (!readSurface || !drawSurface) RenderTarget9 *drawDepthStencil = NULL;
error = d3d9::GetAttachmentRenderTarget(drawBuffer, &drawDepthStencil);
if (error.isError())
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the internal render targets for the blit framebuffers."); return error;
} }
ASSERT(drawDepthStencil);
// The getSurface calls do an AddRef so save them until after no errors are possible
IDirect3DSurface9* readSurface = readDepthStencil->getSurface();
ASSERT(readDepthStencil);
IDirect3DSurface9* drawSurface = drawDepthStencil->getSurface();
ASSERT(drawDepthStencil);
HRESULT result = mDevice->StretchRect(readSurface, NULL, drawSurface, NULL, D3DTEXF_NONE); HRESULT result = mDevice->StretchRect(readSurface, NULL, drawSurface, NULL, D3DTEXF_NONE);
...@@ -2622,25 +2613,19 @@ gl::Error Renderer9::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, ...@@ -2622,25 +2613,19 @@ gl::Error Renderer9::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y,
{ {
ASSERT(pack.pixelBuffer.get() == NULL); ASSERT(pack.pixelBuffer.get() == NULL);
RenderTarget9 *renderTarget = NULL;
IDirect3DSurface9 *surface = NULL;
gl::FramebufferAttachment *colorbuffer = framebuffer->getColorbuffer(0); gl::FramebufferAttachment *colorbuffer = framebuffer->getColorbuffer(0);
ASSERT(colorbuffer);
if (colorbuffer) RenderTarget9 *renderTarget = NULL;
{ gl::Error error = d3d9::GetAttachmentRenderTarget(colorbuffer, &renderTarget);
renderTarget = d3d9::GetAttachmentRenderTarget(colorbuffer); if (error.isError())
}
if (renderTarget)
{ {
surface = renderTarget->getSurface(); return error;
} }
ASSERT(renderTarget);
if (!surface) IDirect3DSurface9 *surface = renderTarget->getSurface();
{ ASSERT(surface);
// context must be lost
return gl::Error(GL_NO_ERROR);
}
D3DSURFACE_DESC desc; D3DSURFACE_DESC desc;
surface->GetDesc(&desc); surface->GetDesc(&desc);
......
...@@ -166,9 +166,11 @@ IDirect3DSurface9 *TextureStorage9_2D::getSurfaceLevel(int level, bool dirty) ...@@ -166,9 +166,11 @@ IDirect3DSurface9 *TextureStorage9_2D::getSurfaceLevel(int level, bool dirty)
return surface; return surface;
} }
RenderTarget *TextureStorage9_2D::getRenderTarget(const gl::ImageIndex &/*index*/) gl::Error TextureStorage9_2D::getRenderTarget(const gl::ImageIndex &/*index*/, RenderTarget **outRT)
{ {
return mRenderTarget; ASSERT(outRT);
*outRT = mRenderTarget;
return gl::Error(GL_NO_ERROR);
} }
void TextureStorage9_2D::generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex) void TextureStorage9_2D::generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex)
...@@ -299,9 +301,13 @@ IDirect3DSurface9 *TextureStorage9_Cube::getCubeMapSurface(GLenum faceTarget, in ...@@ -299,9 +301,13 @@ IDirect3DSurface9 *TextureStorage9_Cube::getCubeMapSurface(GLenum faceTarget, in
return surface; return surface;
} }
RenderTarget *TextureStorage9_Cube::getRenderTarget(const gl::ImageIndex &index) gl::Error TextureStorage9_Cube::getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT)
{ {
return mRenderTarget[index.layerIndex]; ASSERT(outRT);
ASSERT(index.mipIndex == 0);
ASSERT(index.layerIndex >= 0 && index.layerIndex < 6);
*outRT = mRenderTarget[index.layerIndex];
return gl::Error(GL_NO_ERROR);
} }
void TextureStorage9_Cube::generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex) void TextureStorage9_Cube::generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex)
......
...@@ -34,7 +34,7 @@ class TextureStorage9 : public TextureStorage ...@@ -34,7 +34,7 @@ class TextureStorage9 : public TextureStorage
DWORD getUsage() const; DWORD getUsage() const;
virtual IDirect3DBaseTexture9 *getBaseTexture() const = 0; virtual IDirect3DBaseTexture9 *getBaseTexture() const = 0;
virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index) = 0; virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT) = 0;
virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex) = 0; virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex) = 0;
virtual int getTopLevel() const; virtual int getTopLevel() const;
...@@ -68,7 +68,7 @@ class TextureStorage9_2D : public TextureStorage9 ...@@ -68,7 +68,7 @@ class TextureStorage9_2D : public TextureStorage9
static TextureStorage9_2D *makeTextureStorage9_2D(TextureStorage *storage); static TextureStorage9_2D *makeTextureStorage9_2D(TextureStorage *storage);
IDirect3DSurface9 *getSurfaceLevel(int level, bool dirty); IDirect3DSurface9 *getSurfaceLevel(int level, bool dirty);
virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index); virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual IDirect3DBaseTexture9 *getBaseTexture() const; virtual IDirect3DBaseTexture9 *getBaseTexture() const;
virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex); virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex);
virtual gl::Error copyToStorage(TextureStorage *destStorage); virtual gl::Error copyToStorage(TextureStorage *destStorage);
...@@ -91,7 +91,7 @@ class TextureStorage9_Cube : public TextureStorage9 ...@@ -91,7 +91,7 @@ class TextureStorage9_Cube : public TextureStorage9
static TextureStorage9_Cube *makeTextureStorage9_Cube(TextureStorage *storage); static TextureStorage9_Cube *makeTextureStorage9_Cube(TextureStorage *storage);
IDirect3DSurface9 *getCubeMapSurface(GLenum faceTarget, int level, bool dirty); IDirect3DSurface9 *getCubeMapSurface(GLenum faceTarget, int level, bool dirty);
virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index); virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual IDirect3DBaseTexture9 *getBaseTexture() const; virtual IDirect3DBaseTexture9 *getBaseTexture() const;
virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex); virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex);
virtual gl::Error copyToStorage(TextureStorage *destStorage); virtual gl::Error copyToStorage(TextureStorage *destStorage);
......
...@@ -533,10 +533,16 @@ void MakeValidSize(bool isImage, D3DFORMAT format, GLsizei *requestWidth, GLsize ...@@ -533,10 +533,16 @@ void MakeValidSize(bool isImage, D3DFORMAT format, GLsizei *requestWidth, GLsize
*levelOffset = upsampleCount; *levelOffset = upsampleCount;
} }
RenderTarget9 *GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment) gl::Error GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment, RenderTarget9 **outRT)
{ {
RenderTarget *renderTarget = rx::GetAttachmentRenderTarget(attachment); RenderTarget *renderTarget = NULL;
return RenderTarget9::makeRenderTarget9(renderTarget); gl::Error error = rx::GetAttachmentRenderTarget(attachment, &renderTarget);
if (error.isError())
{
return error;
}
*outRT = RenderTarget9::makeRenderTarget9(renderTarget);
return gl::Error(GL_NO_ERROR);
} }
Workarounds GenerateWorkarounds() Workarounds GenerateWorkarounds()
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "libGLESv2/angletypes.h" #include "libGLESv2/angletypes.h"
#include "libGLESv2/Caps.h" #include "libGLESv2/Caps.h"
#include "libGLESv2/Error.h"
namespace gl namespace gl
{ {
...@@ -75,7 +76,7 @@ inline bool isDeviceLostError(HRESULT errorCode) ...@@ -75,7 +76,7 @@ inline bool isDeviceLostError(HRESULT errorCode)
} }
} }
RenderTarget9 *GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment); gl::Error GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment, RenderTarget9 **outRT);
Workarounds GenerateWorkarounds(); Workarounds GenerateWorkarounds();
} }
......
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