Moves copyToRenderTarget to Renderer
TRAC #22000
Signed-off-by: Daniel Koch
Author: Shannon Woods
git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1409 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/Texture.cpp b/src/libGLESv2/Texture.cpp
index 08b4c4c..41c2ba1 100644
--- a/src/libGLESv2/Texture.cpp
+++ b/src/libGLESv2/Texture.cpp
@@ -782,7 +782,7 @@
if (mTexStorage != NULL)
{
- if (!TextureStorage2D::copyToRenderTarget(newTexStorage, mTexStorage))
+ if (!mRenderer->copyToRenderTarget(newTexStorage, mTexStorage))
{
delete newTexStorage;
return error(GL_OUT_OF_MEMORY);
@@ -1240,7 +1240,7 @@
if (mTexStorage != NULL)
{
- if (!TextureStorageCubeMap::copyToRenderTarget(newTexStorage, mTexStorage))
+ if (!mRenderer->copyToRenderTarget(newTexStorage, mTexStorage))
{
delete newTexStorage;
return error(GL_OUT_OF_MEMORY);
diff --git a/src/libGLESv2/renderer/Renderer.h b/src/libGLESv2/renderer/Renderer.h
index db8c32d..e808f9a 100644
--- a/src/libGLESv2/renderer/Renderer.h
+++ b/src/libGLESv2/renderer/Renderer.h
@@ -37,6 +37,12 @@
class Display;
}
+namespace gl
+{
+class TextureStorage2D;
+class TextureStorageCubeMap;
+}
+
namespace rx
{
@@ -106,6 +112,9 @@
virtual GLsizei getMaxSupportedSamples() const = 0;
+ virtual bool copyToRenderTarget(gl::TextureStorage2D *dest, gl::TextureStorage2D *source) = 0;
+ virtual bool copyToRenderTarget(gl::TextureStorageCubeMap *dest, gl::TextureStorageCubeMap *source) = 0;
+
protected:
egl::Display *mDisplay;
diff --git a/src/libGLESv2/renderer/Renderer9.cpp b/src/libGLESv2/renderer/Renderer9.cpp
index 517cc27..5e128b7 100644
--- a/src/libGLESv2/renderer/Renderer9.cpp
+++ b/src/libGLESv2/renderer/Renderer9.cpp
@@ -11,6 +11,7 @@
#include "libGLESv2/renderer/Renderer9.h"
#include "libGLESv2/renderer/renderer9_utils.h"
#include "libGLESv2/renderer/TextureStorage.h"
+#include "libGLESv2/renderer/Image.h"
#include "libEGL/Config.h"
#include "libEGL/Display.h"
@@ -1052,6 +1053,59 @@
return D3DFMT_A8R8G8B8;
}
+bool Renderer9::copyToRenderTarget(gl::TextureStorage2D *dest, gl::TextureStorage2D *source)
+{
+ bool result = false;
+
+ if (source && dest)
+ {
+ int levels = source->levelCount();
+ for (int i = 0; i < levels; ++i)
+ {
+ IDirect3DSurface9 *srcSurf = source->getSurfaceLevel(i, false);
+ IDirect3DSurface9 *dstSurf = dest->getSurfaceLevel(i, false);
+
+ result = copyToRenderTarget(dstSurf, srcSurf, source->isManaged());
+
+ if (srcSurf) srcSurf->Release();
+ if (dstSurf) dstSurf->Release();
+
+ if (!result)
+ return false;
+ }
+ }
+
+ return result;
+}
+
+bool Renderer9::copyToRenderTarget(gl::TextureStorageCubeMap *dest, gl::TextureStorageCubeMap *source)
+{
+ bool result = false;
+
+ if (source && dest)
+ {
+ int levels = source->levelCount();
+ for (int f = 0; f < 6; f++)
+ {
+ for (int i = 0; i < levels; i++)
+ {
+ IDirect3DSurface9 *srcSurf = source->getCubeMapSurface(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, false);
+ IDirect3DSurface9 *dstSurf = dest->getCubeMapSurface(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, true);
+
+ result = copyToRenderTarget(dstSurf, srcSurf, source->isManaged());
+
+ if (srcSurf) srcSurf->Release();
+ if (dstSurf) dstSurf->Release();
+
+ if (!result)
+ return false;
+ }
+ }
+ }
+
+ return result;
+}
+
D3DPOOL Renderer9::getBufferPool(DWORD usage) const
{
if (mD3d9Ex != NULL)
@@ -1086,4 +1140,42 @@
return D3DPOOL_DEFAULT;
}
+bool Renderer9::copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged)
+{
+ if (source && dest)
+ {
+ HRESULT result = D3DERR_OUTOFVIDEOMEMORY;
+ IDirect3DDevice9 *device = getDevice(); // D3D9_REPLACE
+
+ if (fromManaged)
+ {
+ D3DSURFACE_DESC desc;
+ source->GetDesc(&desc);
+
+ IDirect3DSurface9 *surf = 0;
+ result = device->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &surf, NULL);
+
+ if (SUCCEEDED(result))
+ {
+ gl::Image::CopyLockableSurfaces(surf, source);
+ result = device->UpdateSurface(surf, NULL, dest, NULL);
+ surf->Release();
+ }
+ }
+ else
+ {
+ endScene();
+ result = device->StretchRect(source, NULL, dest, NULL, D3DTEXF_NONE);
+ }
+
+ if (FAILED(result))
+ {
+ ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
+ return false;
+ }
+ }
+
+ return true;
+}
+
}
\ No newline at end of file
diff --git a/src/libGLESv2/renderer/Renderer9.h b/src/libGLESv2/renderer/Renderer9.h
index 100e096..89a6d3e 100644
--- a/src/libGLESv2/renderer/Renderer9.h
+++ b/src/libGLESv2/renderer/Renderer9.h
@@ -110,12 +110,17 @@
int getNearestSupportedSamples(D3DFORMAT format, int requested) const;
D3DFORMAT ConvertTextureInternalFormat(GLint internalformat);
+
+ virtual bool copyToRenderTarget(gl::TextureStorage2D *dest, gl::TextureStorage2D *source);
+ virtual bool copyToRenderTarget(gl::TextureStorageCubeMap *dest, gl::TextureStorageCubeMap *source);
+
D3DPOOL getTexturePool(DWORD usage) const;
private:
DISALLOW_COPY_AND_ASSIGN(Renderer9);
void getMultiSampleSupport(D3DFORMAT format, bool *multiSampleArray);
+ bool copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged);
D3DPOOL getBufferPool(DWORD usage) const;
diff --git a/src/libGLESv2/renderer/TextureStorage.cpp b/src/libGLESv2/renderer/TextureStorage.cpp
index f42deab..946707e 100644
--- a/src/libGLESv2/renderer/TextureStorage.cpp
+++ b/src/libGLESv2/renderer/TextureStorage.cpp
@@ -121,45 +121,6 @@
return getBaseTexture() ? getBaseTexture()->GetLevelCount() - getLodOffset() : 0;
}
-bool TextureStorage::copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged)
-{
- if (source && dest)
- {
- HRESULT result = D3DERR_OUTOFVIDEOMEMORY;
- rx::Renderer9 *renderer = getDisplay()->getRenderer9();
- IDirect3DDevice9 *device = renderer->getDevice(); // D3D9_REPLACE
-
- if (fromManaged)
- {
- D3DSURFACE_DESC desc;
- source->GetDesc(&desc);
-
- IDirect3DSurface9 *surf = 0;
- result = device->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &surf, NULL);
-
- if (SUCCEEDED(result))
- {
- Image::CopyLockableSurfaces(surf, source);
- result = device->UpdateSurface(surf, NULL, dest, NULL);
- surf->Release();
- }
- }
- else
- {
- renderer->endScene();
- result = device->StretchRect(source, NULL, dest, NULL, D3DTEXF_NONE);
- }
-
- if (FAILED(result))
- {
- ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
- return false;
- }
- }
-
- return true;
-}
-
TextureStorage2D::TextureStorage2D(rx::Renderer9 *renderer, rx::SwapChain *swapchain) : TextureStorage(renderer, D3DUSAGE_RENDERTARGET), mRenderTargetSerial(RenderbufferStorage::issueSerial())
{
IDirect3DTexture9 *surfaceTexture = swapchain->getOffscreenTexture();
@@ -196,31 +157,6 @@
}
}
-bool TextureStorage2D::copyToRenderTarget(TextureStorage2D *dest, TextureStorage2D *source)
-{
- bool result = false;
-
- if (source && dest)
- {
- int levels = source->levelCount();
- for (int i = 0; i < levels; ++i)
- {
- IDirect3DSurface9 *srcSurf = source->getSurfaceLevel(i, false);
- IDirect3DSurface9 *dstSurf = dest->getSurfaceLevel(i, false);
-
- result = TextureStorage::copyToRenderTarget(dstSurf, srcSurf, source->isManaged());
-
- if (srcSurf) srcSurf->Release();
- if (dstSurf) dstSurf->Release();
-
- if (!result)
- return false;
- }
- }
-
- return result;
-}
-
// Increments refcount on surface.
// caller must Release() the returned surface
IDirect3DSurface9 *TextureStorage2D::getSurfaceLevel(int level, bool dirty)
@@ -297,34 +233,6 @@
}
}
-bool TextureStorageCubeMap::copyToRenderTarget(TextureStorageCubeMap *dest, TextureStorageCubeMap *source)
-{
- bool result = false;
-
- if (source && dest)
- {
- int levels = source->levelCount();
- for (int f = 0; f < 6; f++)
- {
- for (int i = 0; i < levels; i++)
- {
- IDirect3DSurface9 *srcSurf = source->getCubeMapSurface(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, false);
- IDirect3DSurface9 *dstSurf = dest->getCubeMapSurface(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, true);
-
- result = TextureStorage::copyToRenderTarget(dstSurf, srcSurf, source->isManaged());
-
- if (srcSurf) srcSurf->Release();
- if (dstSurf) dstSurf->Release();
-
- if (!result)
- return false;
- }
- }
- }
-
- return result;
-}
-
// Increments refcount on surface.
// caller must Release() the returned surface
IDirect3DSurface9 *TextureStorageCubeMap::getCubeMapSurface(GLenum faceTarget, int level, bool dirty)
diff --git a/src/libGLESv2/renderer/TextureStorage.h b/src/libGLESv2/renderer/TextureStorage.h
index a3bb7e6..e17e882 100644
--- a/src/libGLESv2/renderer/TextureStorage.h
+++ b/src/libGLESv2/renderer/TextureStorage.h
@@ -49,8 +49,6 @@
int levelCount();
protected:
- static bool copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged);
-
int mLodOffset;
private:
@@ -75,8 +73,6 @@
virtual ~TextureStorage2D();
- static bool copyToRenderTarget(TextureStorage2D *dest, TextureStorage2D *source);
-
IDirect3DSurface9 *getSurfaceLevel(int level, bool dirty);
virtual IDirect3DBaseTexture9 *getBaseTexture() const;
void generateMipmap(int level);
@@ -97,8 +93,6 @@
virtual ~TextureStorageCubeMap();
- static bool copyToRenderTarget(TextureStorageCubeMap *dest, TextureStorageCubeMap *source);
-
IDirect3DSurface9 *getCubeMapSurface(GLenum faceTarget, int level, bool dirty);
virtual IDirect3DBaseTexture9 *getBaseTexture() const;
void generateMipmap(int face, int level);