Moves TextureStorage class to its own file in the Renderer directory

TRAC #21909 Author: Shannon Woods Signed-off-by: Daniel Koch git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1363 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent b9d7e6f8
...@@ -259,6 +259,8 @@ ...@@ -259,6 +259,8 @@
'libGLESv2/renderer/ShaderCache.h', 'libGLESv2/renderer/ShaderCache.h',
'libGLESv2/renderer/SwapChain.cpp', 'libGLESv2/renderer/SwapChain.cpp',
'libGLESv2/renderer/SwapChain.h', 'libGLESv2/renderer/SwapChain.h',
'libGLESv2/renderer/TextureStorage.cpp',
'libGLESv2/renderer/TextureStorage.h',
'libGLESv2/ResourceManager.cpp', 'libGLESv2/ResourceManager.cpp',
'libGLESv2/ResourceManager.h', 'libGLESv2/ResourceManager.h',
'libGLESv2/Shader.cpp', 'libGLESv2/Shader.cpp',
......
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
namespace gl namespace gl
{ {
unsigned int TextureStorage::mCurrentTextureSerial = 1;
static inline DWORD GetTextureUsage(D3DFORMAT d3dfmt, GLenum glusage, bool forceRenderable) static inline DWORD GetTextureUsage(D3DFORMAT d3dfmt, GLenum glusage, bool forceRenderable)
{ {
DWORD d3dusage = 0; DWORD d3dusage = 0;
...@@ -219,53 +217,6 @@ void GenerateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9 *sourceSurfac ...@@ -219,53 +217,6 @@ void GenerateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9 *sourceSurfac
} }
} }
TextureStorage::TextureStorage(DWORD usage)
: mD3DUsage(usage),
mD3DPool(getDisplay()->getRenderer()->getTexturePool(usage)), // D3D9_REPLACE
mTextureSerial(issueTextureSerial()),
mLodOffset(0)
{
}
TextureStorage::~TextureStorage()
{
}
bool TextureStorage::isRenderTarget() const
{
return (mD3DUsage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL)) != 0;
}
bool TextureStorage::isManaged() const
{
return (mD3DPool == D3DPOOL_MANAGED);
}
D3DPOOL TextureStorage::getPool() const
{
return mD3DPool;
}
DWORD TextureStorage::getUsage() const
{
return mD3DUsage;
}
unsigned int TextureStorage::getTextureSerial() const
{
return mTextureSerial;
}
unsigned int TextureStorage::issueTextureSerial()
{
return mCurrentTextureSerial++;
}
int TextureStorage::getLodOffset() const
{
return mLodOffset;
}
Texture::Texture(GLuint id) : RefCountObject(id) Texture::Texture(GLuint id) : RefCountObject(id)
{ {
mSamplerState.minFilter = GL_NEAREST_MIPMAP_LINEAR; mSamplerState.minFilter = GL_NEAREST_MIPMAP_LINEAR;
...@@ -689,70 +640,6 @@ bool Texture::copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *sou ...@@ -689,70 +640,6 @@ bool Texture::copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *sou
return true; return true;
} }
TextureStorage2D::TextureStorage2D(IDirect3DTexture9 *surfaceTexture) : TextureStorage(D3DUSAGE_RENDERTARGET), mRenderTargetSerial(RenderbufferStorage::issueSerial())
{
mTexture = surfaceTexture;
}
TextureStorage2D::TextureStorage2D(int levels, D3DFORMAT format, DWORD usage, int width, int height)
: TextureStorage(usage), mRenderTargetSerial(RenderbufferStorage::issueSerial())
{
mTexture = NULL;
// if the width or height is not positive this should be treated as an incomplete texture
// we handle that here by skipping the d3d texture creation
if (width > 0 && height > 0)
{
IDirect3DDevice9 *device = getDisplay()->getRenderer()->getDevice(); // D3D9_REPLACE
MakeValidSize(false, dx::IsCompressedFormat(format), &width, &height, &mLodOffset);
HRESULT result = device->CreateTexture(width, height, levels ? levels + mLodOffset : 0, getUsage(), format, getPool(), &mTexture, NULL);
if (FAILED(result))
{
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
error(GL_OUT_OF_MEMORY);
}
}
}
TextureStorage2D::~TextureStorage2D()
{
if (mTexture)
{
mTexture->Release();
}
}
// Increments refcount on surface.
// caller must Release() the returned surface
IDirect3DSurface9 *TextureStorage2D::getSurfaceLevel(int level, bool dirty)
{
IDirect3DSurface9 *surface = NULL;
if (mTexture)
{
HRESULT result = mTexture->GetSurfaceLevel(level + mLodOffset, &surface);
ASSERT(SUCCEEDED(result));
// With managed textures the driver needs to be informed of updates to the lower mipmap levels
if (level != 0 && isManaged() && dirty)
{
mTexture->AddDirtyRect(NULL);
}
}
return surface;
}
IDirect3DBaseTexture9 *TextureStorage2D::getBaseTexture() const
{
return mTexture;
}
unsigned int TextureStorage2D::getRenderTargetSerial(GLenum target) const
{
return mRenderTargetSerial;
}
Texture2D::Texture2D(GLuint id) : Texture(id) Texture2D::Texture2D(GLuint id) : Texture(id)
{ {
mTexStorage = NULL; mTexStorage = NULL;
...@@ -1394,67 +1281,6 @@ TextureStorage *Texture2D::getStorage(bool renderTarget) ...@@ -1394,67 +1281,6 @@ TextureStorage *Texture2D::getStorage(bool renderTarget)
return mTexStorage; return mTexStorage;
} }
TextureStorageCubeMap::TextureStorageCubeMap(int levels, D3DFORMAT format, DWORD usage, int size)
: TextureStorage(usage), mFirstRenderTargetSerial(RenderbufferStorage::issueCubeSerials())
{
mTexture = NULL;
// if the size is not positive this should be treated as an incomplete texture
// we handle that here by skipping the d3d texture creation
if (size > 0)
{
IDirect3DDevice9 *device = getDisplay()->getRenderer()->getDevice(); // D3D9_REPLACE
int height = size;
MakeValidSize(false, dx::IsCompressedFormat(format), &size, &height, &mLodOffset);
HRESULT result = device->CreateCubeTexture(size, levels ? levels + mLodOffset : 0, getUsage(), format, getPool(), &mTexture, NULL);
if (FAILED(result))
{
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
error(GL_OUT_OF_MEMORY);
}
}
}
TextureStorageCubeMap::~TextureStorageCubeMap()
{
if (mTexture)
{
mTexture->Release();
}
}
// Increments refcount on surface.
// caller must Release() the returned surface
IDirect3DSurface9 *TextureStorageCubeMap::getCubeMapSurface(GLenum faceTarget, int level, bool dirty)
{
IDirect3DSurface9 *surface = NULL;
if (mTexture)
{
D3DCUBEMAP_FACES face = es2dx::ConvertCubeFace(faceTarget);
HRESULT result = mTexture->GetCubeMapSurface(face, level + mLodOffset, &surface);
ASSERT(SUCCEEDED(result));
// With managed textures the driver needs to be informed of updates to the lower mipmap levels
if (level != 0 && isManaged() && dirty)
{
mTexture->AddDirtyRect(face, NULL);
}
}
return surface;
}
IDirect3DBaseTexture9 *TextureStorageCubeMap::getBaseTexture() const
{
return mTexture;
}
unsigned int TextureStorageCubeMap::getRenderTargetSerial(GLenum target) const
{
return mFirstRenderTargetSerial + TextureCubeMap::faceIndex(target);
}
TextureCubeMap::TextureCubeMap(GLuint id) : Texture(id) TextureCubeMap::TextureCubeMap(GLuint id) : Texture(id)
{ {
mTexStorage = NULL; mTexStorage = NULL;
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "common/debug.h" #include "common/debug.h"
#include "common/RefCountObject.h" #include "common/RefCountObject.h"
#include "libGLESv2/renderer/Image.h" #include "libGLESv2/renderer/Image.h"
#include "libGLESv2/renderer/TextureStorage.h"
#include "libGLESv2/Renderbuffer.h" #include "libGLESv2/Renderbuffer.h"
#include "libGLESv2/utilities.h" #include "libGLESv2/utilities.h"
...@@ -54,38 +55,6 @@ struct SamplerState ...@@ -54,38 +55,6 @@ struct SamplerState
int lodOffset; int lodOffset;
}; };
class TextureStorage
{
public:
explicit TextureStorage(DWORD usage);
virtual ~TextureStorage();
bool isRenderTarget() const;
bool isManaged() const;
D3DPOOL getPool() const;
DWORD getUsage() const;
unsigned int getTextureSerial() const;
virtual unsigned int getRenderTargetSerial(GLenum target) const = 0;
int getLodOffset() const;
protected:
int mLodOffset;
private:
DISALLOW_COPY_AND_ASSIGN(TextureStorage);
const DWORD mD3DUsage;
const D3DPOOL mD3DPool;
const unsigned int mTextureSerial;
static unsigned int issueTextureSerial();
static unsigned int mCurrentTextureSerial;
};
class Texture : public RefCountObject class Texture : public RefCountObject
{ {
public: public:
...@@ -170,26 +139,6 @@ class Texture : public RefCountObject ...@@ -170,26 +139,6 @@ class Texture : public RefCountObject
virtual TextureStorage *getStorage(bool renderTarget) = 0; virtual TextureStorage *getStorage(bool renderTarget) = 0;
}; };
class TextureStorage2D : public TextureStorage
{
public:
explicit TextureStorage2D(IDirect3DTexture9 *surfaceTexture);
TextureStorage2D(int levels, D3DFORMAT format, DWORD usage, int width, int height);
virtual ~TextureStorage2D();
IDirect3DSurface9 *getSurfaceLevel(int level, bool dirty);
IDirect3DBaseTexture9 *getBaseTexture() const;
virtual unsigned int getRenderTargetSerial(GLenum target) const;
private:
DISALLOW_COPY_AND_ASSIGN(TextureStorage2D);
IDirect3DTexture9 *mTexture;
const unsigned int mRenderTargetSerial;
};
class Texture2D : public Texture class Texture2D : public Texture
{ {
public: public:
...@@ -258,25 +207,6 @@ class Texture2D : public Texture ...@@ -258,25 +207,6 @@ class Texture2D : public Texture
unsigned int mProxyRefs; unsigned int mProxyRefs;
}; };
class TextureStorageCubeMap : public TextureStorage
{
public:
TextureStorageCubeMap(int levels, D3DFORMAT format, DWORD usage, int size);
virtual ~TextureStorageCubeMap();
IDirect3DSurface9 *getCubeMapSurface(GLenum faceTarget, int level, bool dirty);
IDirect3DBaseTexture9 *getBaseTexture() const;
virtual unsigned int getRenderTargetSerial(GLenum target) const;
private:
DISALLOW_COPY_AND_ASSIGN(TextureStorageCubeMap);
IDirect3DCubeTexture9 *mTexture;
const unsigned int mFirstRenderTargetSerial;
};
class TextureCubeMap : public Texture class TextureCubeMap : public Texture
{ {
public: public:
......
...@@ -248,6 +248,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -248,6 +248,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClCompile Include="renderer\Renderer9.cpp" /> <ClCompile Include="renderer\Renderer9.cpp" />
<ClCompile Include="renderer\Image.cpp" /> <ClCompile Include="renderer\Image.cpp" />
<ClCompile Include="renderer\SwapChain.cpp" /> <ClCompile Include="renderer\SwapChain.cpp" />
<ClCompile Include="renderer\TextureStorage.cpp" />
<ClCompile Include="ResourceManager.cpp" /> <ClCompile Include="ResourceManager.cpp" />
<ClCompile Include="Shader.cpp" /> <ClCompile Include="Shader.cpp" />
<ClCompile Include="Texture.cpp" /> <ClCompile Include="Texture.cpp" />
...@@ -281,6 +282,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -281,6 +282,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClInclude Include="renderer\Renderer9.h" /> <ClInclude Include="renderer\Renderer9.h" />
<ClInclude Include="renderer\ShaderCache.h" /> <ClInclude Include="renderer\ShaderCache.h" />
<ClInclude Include="renderer\SwapChain.h" /> <ClInclude Include="renderer\SwapChain.h" />
<ClInclude Include="renderer\TextureStorage.h" />
<ClInclude Include="resource.h" /> <ClInclude Include="resource.h" />
<ClInclude Include="ResourceManager.h" /> <ClInclude Include="ResourceManager.h" />
<ClInclude Include="Shader.h" /> <ClInclude Include="Shader.h" />
......
...@@ -92,6 +92,9 @@ ...@@ -92,6 +92,9 @@
<ClCompile Include="renderer\Image.cpp"> <ClCompile Include="renderer\Image.cpp">
<Filter>Renderer</Filter> <Filter>Renderer</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="renderer\TextureStorage.cpp">
<Filter>Renderer</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="BinaryStream.h"> <ClInclude Include="BinaryStream.h">
...@@ -191,6 +194,9 @@ ...@@ -191,6 +194,9 @@
<ClInclude Include="renderer\Image.h"> <ClInclude Include="renderer\Image.h">
<Filter>Renderer</Filter> <Filter>Renderer</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="renderer\TextureStorage.h">
<Filter>Renderer</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="libGLESv2.def"> <None Include="libGLESv2.def">
......
//
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// TextureStorage.cpp: Implements the abstract gl::TextureStorage class and its concrete derived
// classes TextureStorage2D and TextureStorageCubeMap, which act as the interface to the
// D3D-side texture.
#include "libGLESv2/main.h"
#include "libGLESv2/renderer/TextureStorage.h"
#include "common/debug.h"
namespace gl
{
unsigned int TextureStorage::mCurrentTextureSerial = 1;
TextureStorage::TextureStorage(DWORD usage)
: mD3DUsage(usage),
mD3DPool(getDisplay()->getRenderer()->getTexturePool(usage)), // D3D9_REPLACE
mTextureSerial(issueTextureSerial()),
mLodOffset(0)
{
}
TextureStorage::~TextureStorage()
{
}
bool TextureStorage::isRenderTarget() const
{
return (mD3DUsage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL)) != 0;
}
bool TextureStorage::isManaged() const
{
return (mD3DPool == D3DPOOL_MANAGED);
}
D3DPOOL TextureStorage::getPool() const
{
return mD3DPool;
}
DWORD TextureStorage::getUsage() const
{
return mD3DUsage;
}
unsigned int TextureStorage::getTextureSerial() const
{
return mTextureSerial;
}
unsigned int TextureStorage::issueTextureSerial()
{
return mCurrentTextureSerial++;
}
int TextureStorage::getLodOffset() const
{
return mLodOffset;
}
TextureStorage2D::TextureStorage2D(IDirect3DTexture9 *surfaceTexture) : TextureStorage(D3DUSAGE_RENDERTARGET), mRenderTargetSerial(RenderbufferStorage::issueSerial())
{
mTexture = surfaceTexture;
}
TextureStorage2D::TextureStorage2D(int levels, D3DFORMAT format, DWORD usage, int width, int height)
: TextureStorage(usage), mRenderTargetSerial(RenderbufferStorage::issueSerial())
{
mTexture = NULL;
// if the width or height is not positive this should be treated as an incomplete texture
// we handle that here by skipping the d3d texture creation
if (width > 0 && height > 0)
{
IDirect3DDevice9 *device = getDisplay()->getRenderer()->getDevice(); // D3D9_REPLACE
MakeValidSize(false, dx::IsCompressedFormat(format), &width, &height, &mLodOffset);
HRESULT result = device->CreateTexture(width, height, levels ? levels + mLodOffset : 0, getUsage(), format, getPool(), &mTexture, NULL);
if (FAILED(result))
{
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
error(GL_OUT_OF_MEMORY);
}
}
}
TextureStorage2D::~TextureStorage2D()
{
if (mTexture)
{
mTexture->Release();
}
}
// Increments refcount on surface.
// caller must Release() the returned surface
IDirect3DSurface9 *TextureStorage2D::getSurfaceLevel(int level, bool dirty)
{
IDirect3DSurface9 *surface = NULL;
if (mTexture)
{
HRESULT result = mTexture->GetSurfaceLevel(level + mLodOffset, &surface);
ASSERT(SUCCEEDED(result));
// With managed textures the driver needs to be informed of updates to the lower mipmap levels
if (level != 0 && isManaged() && dirty)
{
mTexture->AddDirtyRect(NULL);
}
}
return surface;
}
IDirect3DBaseTexture9 *TextureStorage2D::getBaseTexture() const
{
return mTexture;
}
unsigned int TextureStorage2D::getRenderTargetSerial(GLenum target) const
{
return mRenderTargetSerial;
}
TextureStorageCubeMap::TextureStorageCubeMap(int levels, D3DFORMAT format, DWORD usage, int size)
: TextureStorage(usage), mFirstRenderTargetSerial(RenderbufferStorage::issueCubeSerials())
{
mTexture = NULL;
// if the size is not positive this should be treated as an incomplete texture
// we handle that here by skipping the d3d texture creation
if (size > 0)
{
IDirect3DDevice9 *device = getDisplay()->getRenderer()->getDevice(); // D3D9_REPLACE
int height = size;
MakeValidSize(false, dx::IsCompressedFormat(format), &size, &height, &mLodOffset);
HRESULT result = device->CreateCubeTexture(size, levels ? levels + mLodOffset : 0, getUsage(), format, getPool(), &mTexture, NULL);
if (FAILED(result))
{
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
error(GL_OUT_OF_MEMORY);
}
}
}
TextureStorageCubeMap::~TextureStorageCubeMap()
{
if (mTexture)
{
mTexture->Release();
}
}
// Increments refcount on surface.
// caller must Release() the returned surface
IDirect3DSurface9 *TextureStorageCubeMap::getCubeMapSurface(GLenum faceTarget, int level, bool dirty)
{
IDirect3DSurface9 *surface = NULL;
if (mTexture)
{
D3DCUBEMAP_FACES face = es2dx::ConvertCubeFace(faceTarget);
HRESULT result = mTexture->GetCubeMapSurface(face, level + mLodOffset, &surface);
ASSERT(SUCCEEDED(result));
// With managed textures the driver needs to be informed of updates to the lower mipmap levels
if (level != 0 && isManaged() && dirty)
{
mTexture->AddDirtyRect(face, NULL);
}
}
return surface;
}
IDirect3DBaseTexture9 *TextureStorageCubeMap::getBaseTexture() const
{
return mTexture;
}
unsigned int TextureStorageCubeMap::getRenderTargetSerial(GLenum target) const
{
return mFirstRenderTargetSerial + TextureCubeMap::faceIndex(target);
}
}
\ No newline at end of file
//
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// TextureStorage.h: Defines the abstract gl::TextureStorage class and its concrete derived
// classes TextureStorage2D and TextureStorageCubeMap, which act as the interface to the
// D3D-side texture.
#ifndef LIBGLESV2_TEXTURESTORAGE_H_
#define LIBGLESV2_TEXTURESTORAGE_H_
#define GL_APICALL
#include <GLES2/gl2.h>
#include <d3d9.h>
#include "common/debug.h"
namespace gl
{
class TextureStorage
{
public:
explicit TextureStorage(DWORD usage);
virtual ~TextureStorage();
bool isRenderTarget() const;
bool isManaged() const;
D3DPOOL getPool() const;
DWORD getUsage() const;
unsigned int getTextureSerial() const;
virtual unsigned int getRenderTargetSerial(GLenum target) const = 0;
int getLodOffset() const;
protected:
int mLodOffset;
private:
DISALLOW_COPY_AND_ASSIGN(TextureStorage);
const DWORD mD3DUsage;
const D3DPOOL mD3DPool;
const unsigned int mTextureSerial;
static unsigned int issueTextureSerial();
static unsigned int mCurrentTextureSerial;
};
class TextureStorage2D : public TextureStorage
{
public:
explicit TextureStorage2D(IDirect3DTexture9 *surfaceTexture);
TextureStorage2D(int levels, D3DFORMAT format, DWORD usage, int width, int height);
virtual ~TextureStorage2D();
IDirect3DSurface9 *getSurfaceLevel(int level, bool dirty);
IDirect3DBaseTexture9 *getBaseTexture() const;
virtual unsigned int getRenderTargetSerial(GLenum target) const;
private:
DISALLOW_COPY_AND_ASSIGN(TextureStorage2D);
IDirect3DTexture9 *mTexture;
const unsigned int mRenderTargetSerial;
};
class TextureStorageCubeMap : public TextureStorage
{
public:
TextureStorageCubeMap(int levels, D3DFORMAT format, DWORD usage, int size);
virtual ~TextureStorageCubeMap();
IDirect3DSurface9 *getCubeMapSurface(GLenum faceTarget, int level, bool dirty);
IDirect3DBaseTexture9 *getBaseTexture() const;
virtual unsigned int getRenderTargetSerial(GLenum target) const;
private:
DISALLOW_COPY_AND_ASSIGN(TextureStorageCubeMap);
IDirect3DCubeTexture9 *mTexture;
const unsigned int mFirstRenderTargetSerial;
};
}
#endif // LIBGLESV2_TEXTURESTORAGE_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment