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)
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());
}
......@@ -1647,7 +1651,11 @@ Error Context::clearBufferfv(GLenum buffer, int drawbuffer, const float *values)
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());
}
......@@ -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.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());
}
......@@ -1699,7 +1711,11 @@ Error Context::clearBufferiv(GLenum buffer, int drawbuffer, const int *values)
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());
}
......@@ -1718,7 +1734,11 @@ Error Context::clearBufferfi(GLenum buffer, int drawbuffer, float depth, int ste
clearParams.clearStencil = true;
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());
}
......
......@@ -23,7 +23,7 @@
namespace rx
{
RenderTarget *GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment)
gl::Error GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment, RenderTarget **outRT)
{
if (attachment->isTexture())
{
......@@ -32,14 +32,17 @@ RenderTarget *GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment)
TextureD3D *textureD3D = TextureD3D::makeTextureD3D(texture->getImplementation());
const gl::ImageIndex *index = attachment->getTextureImageIndex();
ASSERT(index);
return textureD3D->getRenderTarget(*index);
return textureD3D->getRenderTarget(*index, outRT);
}
else
{
gl::Renderbuffer *renderbuffer = attachment->getRenderbuffer();
ASSERT(renderbuffer);
gl::Renderbuffer *renderbuffer = attachment->getRenderbuffer();
ASSERT(renderbuffer);
// TODO: cast to RenderbufferD3D
return renderbuffer->getStorage()->getRenderTarget();
// TODO: cast to RenderbufferD3D
*outRT = renderbuffer->getStorage()->getRenderTarget();
return gl::Error(GL_NO_ERROR);
}
}
// Note: RenderTarget serials should ideally be in the RenderTargets themselves.
......@@ -603,33 +606,36 @@ GLenum Framebuffer::completeness() const
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;
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,
GLint x, GLint y, GLsizei width, GLsizei height)
Error Framebuffer::invalidateSub(GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height)
{
ASSERT(completeness() == GL_FRAMEBUFFER_COMPLETE);
for (GLsizei attachIndex = 0; attachIndex < numAttachments; ++attachIndex)
{
GLenum attachmentTarget = attachments[attachIndex];
gl::FramebufferAttachment *attachment =
(attachmentTarget == GL_DEPTH_STENCIL_ATTACHMENT) ? getDepthOrStencilbuffer() :
getAttachment(attachmentTarget);
FramebufferAttachment *attachment = (attachmentTarget == GL_DEPTH_STENCIL_ATTACHMENT) ? getDepthOrStencilbuffer()
: getAttachment(attachmentTarget);
if (attachment)
{
rx::RenderTarget *renderTarget = rx::GetAttachmentRenderTarget(attachment);
if (renderTarget)
rx::RenderTarget *renderTarget = NULL;
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)
......
......@@ -10,12 +10,14 @@
#ifndef LIBGLESV2_FRAMEBUFFER_H_
#define LIBGLESV2_FRAMEBUFFER_H_
#include <vector>
#include "libGLESv2/Error.h"
#include "common/angleutils.h"
#include "common/RefCountObject.h"
#include "Constants.h"
#include <vector>
namespace rx
{
class Renderer;
......@@ -72,9 +74,8 @@ class Framebuffer
virtual GLenum completeness() const;
bool hasValidDepthStencil() const;
void invalidate(const Caps &caps, GLsizei numAttachments, const GLenum *attachments);
void invalidateSub(const Caps &caps, GLsizei numAttachments, const GLenum *attachments,
GLint x, GLint y, GLsizei width, GLsizei height);
Error invalidate(const Caps &caps, GLsizei numAttachments, const GLenum *attachments);
Error invalidateSub(GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height);
// Use this method to retrieve the color buffer map when doing rendering.
// It will apply a workaround for poor shader performance on some systems
......@@ -118,7 +119,7 @@ namespace rx
class RenderTarget;
// 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);
}
......
......@@ -8283,7 +8283,12 @@ void GL_APIENTRY glInvalidateFramebuffer(GLenum target, GLsizei numAttachments,
gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
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
gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
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
gl::FramebufferAttachment *colorbuffer = source->getReadColorbuffer();
ASSERT(colorbuffer);
RenderTarget *renderTarget = GetAttachmentRenderTarget(colorbuffer);
RenderTarget *renderTarget = NULL;
gl::Error error = GetAttachmentRenderTarget(colorbuffer, &renderTarget);
if (error.isError())
{
return error;
}
ASSERT(renderTarget);
return copy(xoffset, yoffset, zoffset, area, renderTarget);
}
......
......@@ -528,22 +528,25 @@ gl::Error TextureD3D_2D::setImage(GLenum target, GLint level, GLsizei width, GLs
if (isFastUnpackable(unpack, sizedInternalFormat) && isLevelComplete(level))
{
// 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);
if (destRenderTarget)
error = fastUnpackPixels(unpack, pixels, destArea, sizedInternalFormat, type, destRenderTarget);
if (error.isError())
{
gl::Error error = fastUnpackPixels(unpack, pixels, destArea, sizedInternalFormat, type, destRenderTarget);
if (error.isError())
{
return error;
}
return error;
}
// Ensure we don't overwrite our newly initialized data
mImageArray[level]->markClean();
// Ensure we don't overwrite our newly initialized data
mImageArray[level]->markClean();
fastUnpacked = true;
}
fastUnpacked = true;
}
if (!fastUnpacked)
......@@ -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);
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);
if (error.isError())
{
return error;
}
return error;
}
// Ensure we don't overwrite our newly initialized data
mImageArray[level]->markClean();
// Ensure we don't overwrite our newly initialized data
mImageArray[level]->markClean();
fastUnpacked = true;
}
fastUnpacked = true;
}
if (!fastUnpacked)
......@@ -797,7 +802,7 @@ unsigned int TextureD3D_2D::getRenderTargetSerial(const gl::ImageIndex &index)
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());
......@@ -805,16 +810,16 @@ RenderTarget *TextureD3D_2D::getRenderTarget(const gl::ImageIndex &index)
gl::Error error = ensureRenderTarget();
if (error.isError())
{
return NULL;
return error;
}
error = updateStorageLevel(index.mipIndex);
if (error.isError())
{
return NULL;
return error;
}
return mTexStorage->getRenderTarget(index);
return mTexStorage->getRenderTarget(index, outRT);
}
bool TextureD3D_2D::isValidLevel(int level) const
......@@ -1352,7 +1357,7 @@ unsigned int TextureD3D_Cube::getRenderTargetSerial(const gl::ImageIndex &index)
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));
......@@ -1360,16 +1365,16 @@ RenderTarget *TextureD3D_Cube::getRenderTarget(const gl::ImageIndex &index)
gl::Error error = ensureRenderTarget();
if (error.isError())
{
return NULL;
return error;
}
error = updateStorageFaceLevel(index.layerIndex, index.mipIndex);
if (error.isError())
{
return NULL;
return error;
}
return mTexStorage->getRenderTarget(index);
return mTexStorage->getRenderTarget(index, outRT);
}
gl::Error TextureD3D_Cube::initializeStorage(bool renderTarget)
......@@ -1703,22 +1708,25 @@ gl::Error TextureD3D_3D::setImage(GLenum target, GLint level, GLsizei width, GLs
if (isFastUnpackable(unpack, sizedInternalFormat))
{
// 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));
if (destRenderTarget)
error = fastUnpackPixels(unpack, pixels, destArea, sizedInternalFormat, type, destRenderTarget);
if (error.isError())
{
gl::Error error = fastUnpackPixels(unpack, pixels, destArea, sizedInternalFormat, type, destRenderTarget);
if (error.isError())
{
return error;
}
return error;
}
// Ensure we don't overwrite our newly initialized data
mImageArray[level]->markClean();
// Ensure we don't overwrite our newly initialized data
mImageArray[level]->markClean();
fastUnpacked = true;
}
fastUnpacked = true;
}
if (!fastUnpacked)
......@@ -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
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);
gl::Error error = fastUnpackPixels(unpack, pixels, destArea, getInternalFormat(level), type, destRenderTarget);
if (error.isError())
{
return error;
}
return error;
}
// Ensure we don't overwrite our newly initialized data
mImageArray[level]->markClean();
// Ensure we don't overwrite our newly initialized data
mImageArray[level]->markClean();
fastUnpacked = true;
}
fastUnpacked = true;
}
if (!fastUnpacked)
......@@ -1922,13 +1932,13 @@ unsigned int TextureD3D_3D::getRenderTargetSerial(const gl::ImageIndex &index)
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
gl::Error error = ensureRenderTarget();
if (error.isError())
{
return NULL;
return error;
}
if (index.hasLayer())
......@@ -1936,7 +1946,7 @@ RenderTarget *TextureD3D_3D::getRenderTarget(const gl::ImageIndex &index)
error = updateStorage();
if (error.isError())
{
return NULL;
return error;
}
}
else
......@@ -1944,11 +1954,11 @@ RenderTarget *TextureD3D_3D::getRenderTarget(const gl::ImageIndex &index)
error = updateStorageLevel(index.mipIndex);
if (error.isError())
{
return NULL;
return error;
}
}
return mTexStorage->getRenderTarget(index);
return mTexStorage->getRenderTarget(index, outRT);
}
gl::Error TextureD3D_3D::initializeStorage(bool renderTarget)
......@@ -2474,22 +2484,22 @@ unsigned int TextureD3D_2DArray::getRenderTargetSerial(const gl::ImageIndex &ind
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
gl::Error error = ensureRenderTarget();
if (error.isError())
{
return NULL;
return error;
}
error = updateStorageLevel(index.mipIndex);
if (error.isError())
{
return NULL;
return error;
}
return mTexStorage->getRenderTarget(index);
return mTexStorage->getRenderTarget(index, outRT);
}
gl::Error TextureD3D_2DArray::initializeStorage(bool renderTarget)
......
......@@ -48,7 +48,7 @@ class TextureD3D : public TextureImpl
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;
// Returns an iterator over all "Images" for this particular Texture.
......@@ -130,7 +130,7 @@ class TextureD3D_2D : public TextureD3D
virtual void bindTexImage(egl::Surface *surface);
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 gl::ImageIndexIterator imageIterator() const;
......@@ -185,7 +185,7 @@ class TextureD3D_Cube : public TextureD3D
virtual void bindTexImage(egl::Surface *surface);
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 gl::ImageIndexIterator imageIterator() const;
......@@ -239,7 +239,7 @@ class TextureD3D_3D : public TextureD3D
virtual void bindTexImage(egl::Surface *surface);
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 gl::ImageIndexIterator imageIterator() const;
......@@ -291,7 +291,7 @@ class TextureD3D_2DArray : public TextureD3D
virtual void bindTexImage(egl::Surface *surface);
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 gl::ImageIndexIterator imageIterator() const;
......
......@@ -9,6 +9,8 @@
#ifndef LIBGLESV2_RENDERER_TEXTURESTORAGE_H_
#define LIBGLESV2_RENDERER_TEXTURESTORAGE_H_
#include "libGLESv2/Error.h"
#include "common/debug.h"
#include "libGLESv2/Error.h"
......@@ -40,7 +42,7 @@ class TextureStorage
virtual bool isManaged() 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 gl::Error copyToStorage(TextureStorage *destStorage) = 0;
......
......@@ -211,10 +211,11 @@ gl::Error Clear11::clearFramebuffer(const gl::ClearParameters &clearParams, gl::
gl::FramebufferAttachment *attachment = frameBuffer->getColorbuffer(colorAttachment);
if (attachment)
{
RenderTarget11 *renderTarget = d3d11::GetAttachmentRenderTarget(attachment);
if (!renderTarget)
RenderTarget11 *renderTarget = NULL;
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());
......@@ -284,10 +285,11 @@ gl::Error Clear11::clearFramebuffer(const gl::ClearParameters &clearParams, gl::
gl::FramebufferAttachment *attachment = frameBuffer->getDepthOrStencilbuffer();
if (attachment)
{
RenderTarget11 *renderTarget = d3d11::GetAttachmentRenderTarget(attachment);
if (!renderTarget)
RenderTarget11 *renderTarget = NULL;
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());
......
......@@ -190,7 +190,8 @@ class Renderer11 : public Renderer
virtual gl::Error fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
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 setOneTimeRenderTarget(ID3D11RenderTargetView *renderTargetView);
gl::Error packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams &params, uint8_t *pixelsOut);
......
......@@ -43,7 +43,7 @@ class TextureStorage11 : public TextureStorage
virtual ID3D11Resource *getResource() const = 0;
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);
......@@ -148,7 +148,7 @@ class TextureStorage11_2D : public TextureStorage11
static TextureStorage11_2D *makeTextureStorage11_2D(TextureStorage *storage);
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 disassociateImage(const gl::ImageIndex &index, Image11* expectedImage);
......@@ -183,7 +183,7 @@ class TextureStorage11_Cube : public TextureStorage11
static TextureStorage11_Cube *makeTextureStorage11_Cube(TextureStorage *storage);
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 disassociateImage(const gl::ImageIndex &index, Image11* expectedImage);
......@@ -221,7 +221,7 @@ class TextureStorage11_3D : public TextureStorage11
virtual ID3D11Resource *getResource() const;
// 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 disassociateImage(const gl::ImageIndex &index, Image11* expectedImage);
......@@ -261,7 +261,7 @@ class TextureStorage11_2DArray : public TextureStorage11
static TextureStorage11_2DArray *makeTextureStorage11_2DArray(TextureStorage *storage);
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 disassociateImage(const gl::ImageIndex &index, Image11* expectedImage);
......
......@@ -1066,10 +1066,16 @@ HRESULT SetDebugName(ID3D11DeviceChild *resource, const char *name)
#endif
}
RenderTarget11 *GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment)
gl::Error GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment, RenderTarget11 **outRT)
{
RenderTarget *renderTarget = rx::GetAttachmentRenderTarget(attachment);
return RenderTarget11::makeRenderTarget11(renderTarget);
RenderTarget *renderTarget = NULL;
gl::Error error = rx::GetAttachmentRenderTarget(attachment, &renderTarget);
if (error.isError())
{
return error;
}
*outRT = RenderTarget11::makeRenderTarget11(renderTarget);
return gl::Error(GL_NO_ERROR);
}
Workarounds GenerateWorkarounds()
......
......@@ -12,6 +12,7 @@
#include "libGLESv2/angletypes.h"
#include "libGLESv2/Caps.h"
#include "libGLESv2/Error.h"
#include <vector>
......@@ -177,7 +178,7 @@ inline void SetBufferData(ID3D11DeviceContext *context, ID3D11Buffer *constantBu
context->Unmap(constantBuffer, 0);
}
RenderTarget11 *GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment);
gl::Error GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment, RenderTarget11 **outRT);
Workarounds GenerateWorkarounds();
......
......@@ -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)
{
RenderTarget9 *renderTarget = NULL;
IDirect3DSurface9 *source = NULL;
gl::FramebufferAttachment *colorbuffer = framebuffer->getColorbuffer(0);
ASSERT(colorbuffer);
if (colorbuffer)
{
renderTarget = d3d9::GetAttachmentRenderTarget(colorbuffer);
}
if (renderTarget)
RenderTarget9 *renderTarget9 = NULL;
gl::Error error = d3d9::GetAttachmentRenderTarget(colorbuffer, &renderTarget9);
if (error.isError())
{
source = renderTarget->getSurface();
return error;
}
ASSERT(renderTarget9);
if (!source)
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the internal render target for texture blit.");
}
IDirect3DSurface9 *source = renderTarget9->getSurface();
ASSERT(source);
TextureStorage9_2D *storage9 = TextureStorage9_2D::makeTextureStorage9_2D(storage);
IDirect3DSurface9 *destSurface = storage9->getSurfaceLevel(level, true);
if (!destSurface)
{
SafeRelease(source);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the destination surface for texture blit.");
}
ASSERT(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
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);
ASSERT(colorbuffer);
if (colorbuffer)
{
renderTarget = d3d9::GetAttachmentRenderTarget(colorbuffer);
}
if (renderTarget)
RenderTarget9 *renderTarget9 = NULL;
gl::Error error = d3d9::GetAttachmentRenderTarget(colorbuffer, &renderTarget9);
if (error.isError())
{
source = renderTarget->getSurface();
return error;
}
ASSERT(renderTarget9);
if (!source)
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the internal render target for texture blit.");
}
IDirect3DSurface9 *source = renderTarget9->getSurface();
ASSERT(source);
TextureStorage9_Cube *storage9 = TextureStorage9_Cube::makeTextureStorage9_Cube(storage);
IDirect3DSurface9 *destSurface = storage9->getCubeMapSurface(target, level, true);
if (!destSurface)
{
SafeRelease(source);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the destination surface for texture blit.");
}
ASSERT(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
ASSERT(zoffset == 0);
RenderTarget9 *renderTarget = RenderTarget9::makeRenderTarget9(source);
IDirect3DSurface9 *surface = NULL;
if (renderTarget)
{
surface = renderTarget->getSurface();
}
if (!surface)
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the internal render target.");
}
IDirect3DSurface9 *surface = renderTarget->getSurface();
ASSERT(surface);
IDirect3DDevice9 *device = mRenderer->getDevice();
......
......@@ -1191,28 +1191,23 @@ gl::Error Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer)
{
attachment = getNullColorbuffer(framebuffer->getDepthbuffer());
}
if (!attachment)
{
return gl::Error(GL_OUT_OF_MEMORY, "Unable to locate renderbuffer for FBO.");
}
ASSERT(attachment);
bool renderTargetChanged = false;
unsigned int renderTargetSerial = GetAttachmentSerial(attachment);
if (renderTargetSerial != mAppliedRenderTargetSerial)
{
// Apply the render target on the device
IDirect3DSurface9 *renderTargetSurface = NULL;
RenderTarget9 *renderTarget = d3d9::GetAttachmentRenderTarget(attachment);
if (renderTarget)
RenderTarget9 *renderTarget = NULL;
gl::Error error = d3d9::GetAttachmentRenderTarget(attachment, &renderTarget);
if (error.isError())
{
renderTargetSurface = renderTarget->getSurface();
return error;
}
ASSERT(renderTarget);
if (!renderTargetSurface)
{
return gl::Error(GL_OUT_OF_MEMORY, "Internal render target pointer unexpectedly null.");
}
IDirect3DSurface9 *renderTargetSurface = renderTarget->getSurface();
ASSERT(renderTargetSurface);
mDevice->SetRenderTarget(0, renderTargetSurface);
SafeRelease(renderTargetSurface);
......@@ -1244,18 +1239,16 @@ gl::Error Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer)
// Apply the depth stencil on the device
if (depthStencil)
{
IDirect3DSurface9 *depthStencilSurface = NULL;
rx::RenderTarget9 *depthStencilRenderTarget = d3d9::GetAttachmentRenderTarget(depthStencil);
if (depthStencilRenderTarget)
RenderTarget9 *depthStencilRenderTarget = NULL;
gl::Error error = d3d9::GetAttachmentRenderTarget(depthStencil, &depthStencilRenderTarget);
if (error.isError())
{
depthStencilSurface = depthStencilRenderTarget->getSurface();
return error;
}
ASSERT(depthStencilRenderTarget);
if (!depthStencilSurface)
{
return gl::Error(GL_OUT_OF_MEMORY, "Internal depth stencil pointer unexpectedly null.");
}
IDirect3DSurface9 *depthStencilSurface = depthStencilRenderTarget->getSurface();
ASSERT(depthStencilSurface);
mDevice->SetDepthStencilSurface(depthStencilSurface);
SafeRelease(depthStencilSurface);
......@@ -2447,34 +2440,33 @@ gl::Error Renderer9::blitRect(gl::Framebuffer *readFramebuffer, const gl::Rectan
if (blitRenderTarget)
{
gl::FramebufferAttachment *readBuffer = readFramebuffer->getColorbuffer(0);
gl::FramebufferAttachment *drawBuffer = drawFramebuffer->getColorbuffer(0);
RenderTarget9 *readRenderTarget = NULL;
RenderTarget9 *drawRenderTarget = NULL;
IDirect3DSurface9* readSurface = NULL;
IDirect3DSurface9* drawSurface = NULL;
ASSERT(readBuffer);
if (readBuffer)
{
readRenderTarget = d3d9::GetAttachmentRenderTarget(readBuffer);
}
if (drawBuffer)
RenderTarget9 *readRenderTarget = NULL;
gl::Error error = d3d9::GetAttachmentRenderTarget(readBuffer, &readRenderTarget);
if (error.isError())
{
drawRenderTarget = d3d9::GetAttachmentRenderTarget(drawBuffer);
return error;
}
ASSERT(readRenderTarget);
if (readRenderTarget)
{
readSurface = readRenderTarget->getSurface();
}
if (drawRenderTarget)
{
drawSurface = drawRenderTarget->getSurface();
}
gl::FramebufferAttachment *drawBuffer = drawFramebuffer->getColorbuffer(0);
ASSERT(drawBuffer);
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 dstSize(drawRenderTarget->getWidth(), drawRenderTarget->getHeight(), 1);
......@@ -2574,34 +2566,33 @@ gl::Error Renderer9::blitRect(gl::Framebuffer *readFramebuffer, const gl::Rectan
if (blitDepth || blitStencil)
{
gl::FramebufferAttachment *readBuffer = readFramebuffer->getDepthOrStencilbuffer();
gl::FramebufferAttachment *drawBuffer = drawFramebuffer->getDepthOrStencilbuffer();
RenderTarget9 *readDepthStencil = NULL;
RenderTarget9 *drawDepthStencil = NULL;
IDirect3DSurface9* readSurface = NULL;
IDirect3DSurface9* drawSurface = NULL;
ASSERT(readBuffer);
if (readBuffer)
{
readDepthStencil = d3d9::GetAttachmentRenderTarget(readBuffer);
}
if (drawBuffer)
RenderTarget9 *readDepthStencil = NULL;
gl::Error error = d3d9::GetAttachmentRenderTarget(readBuffer, &readDepthStencil);
if (error.isError())
{
drawDepthStencil = d3d9::GetAttachmentRenderTarget(drawBuffer);
return error;
}
ASSERT(readDepthStencil);
if (readDepthStencil)
{
readSurface = readDepthStencil->getSurface();
}
if (drawDepthStencil)
{
drawSurface = drawDepthStencil->getSurface();
}
gl::FramebufferAttachment *drawBuffer = drawFramebuffer->getDepthOrStencilbuffer();
ASSERT(drawBuffer);
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);
......@@ -2622,25 +2613,19 @@ gl::Error Renderer9::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y,
{
ASSERT(pack.pixelBuffer.get() == NULL);
RenderTarget9 *renderTarget = NULL;
IDirect3DSurface9 *surface = NULL;
gl::FramebufferAttachment *colorbuffer = framebuffer->getColorbuffer(0);
ASSERT(colorbuffer);
if (colorbuffer)
{
renderTarget = d3d9::GetAttachmentRenderTarget(colorbuffer);
}
if (renderTarget)
RenderTarget9 *renderTarget = NULL;
gl::Error error = d3d9::GetAttachmentRenderTarget(colorbuffer, &renderTarget);
if (error.isError())
{
surface = renderTarget->getSurface();
return error;
}
ASSERT(renderTarget);
if (!surface)
{
// context must be lost
return gl::Error(GL_NO_ERROR);
}
IDirect3DSurface9 *surface = renderTarget->getSurface();
ASSERT(surface);
D3DSURFACE_DESC desc;
surface->GetDesc(&desc);
......
......@@ -166,9 +166,11 @@ IDirect3DSurface9 *TextureStorage9_2D::getSurfaceLevel(int level, bool dirty)
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)
......@@ -299,9 +301,13 @@ IDirect3DSurface9 *TextureStorage9_Cube::getCubeMapSurface(GLenum faceTarget, in
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)
......
......@@ -34,7 +34,7 @@ class TextureStorage9 : public TextureStorage
DWORD getUsage() const;
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 int getTopLevel() const;
......@@ -68,7 +68,7 @@ class TextureStorage9_2D : public TextureStorage9
static TextureStorage9_2D *makeTextureStorage9_2D(TextureStorage *storage);
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 void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex);
virtual gl::Error copyToStorage(TextureStorage *destStorage);
......@@ -91,7 +91,7 @@ class TextureStorage9_Cube : public TextureStorage9
static TextureStorage9_Cube *makeTextureStorage9_Cube(TextureStorage *storage);
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 void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex);
virtual gl::Error copyToStorage(TextureStorage *destStorage);
......
......@@ -533,10 +533,16 @@ void MakeValidSize(bool isImage, D3DFORMAT format, GLsizei *requestWidth, GLsize
*levelOffset = upsampleCount;
}
RenderTarget9 *GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment)
gl::Error GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment, RenderTarget9 **outRT)
{
RenderTarget *renderTarget = rx::GetAttachmentRenderTarget(attachment);
return RenderTarget9::makeRenderTarget9(renderTarget);
RenderTarget *renderTarget = NULL;
gl::Error error = rx::GetAttachmentRenderTarget(attachment, &renderTarget);
if (error.isError())
{
return error;
}
*outRT = RenderTarget9::makeRenderTarget9(renderTarget);
return gl::Error(GL_NO_ERROR);
}
Workarounds GenerateWorkarounds()
......
......@@ -12,6 +12,7 @@
#include "libGLESv2/angletypes.h"
#include "libGLESv2/Caps.h"
#include "libGLESv2/Error.h"
namespace gl
{
......@@ -75,7 +76,7 @@ inline bool isDeviceLostError(HRESULT errorCode)
}
}
RenderTarget9 *GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment);
gl::Error GetAttachmentRenderTarget(gl::FramebufferAttachment *attachment, RenderTarget9 **outRT);
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