зеркало из https://github.com/AvaloniaUI/angle.git
Default textures to non-renderable.
TRAC #11309 * Lift getRenderTarget() into base class Texture. * Add pure virtual convertToRenderTarget() and getSurface(). Author: Andrew Lewycky Signed-off-by: Shannon Woods Signed-off-by: Daniel Koch git-svn-id: https://angleproject.googlecode.com/svn/trunk@54 736b8ea6-26fd-11df-bfd4-992fa37f6226
This commit is contained in:
Родитель
842f7a4ebf
Коммит
7051b97e76
|
@ -15,6 +15,7 @@
|
|||
#include "main.h"
|
||||
#include "mathutil.h"
|
||||
#include "debug.h"
|
||||
#include "utilities.h"
|
||||
|
||||
namespace gl
|
||||
{
|
||||
|
@ -354,6 +355,31 @@ IDirect3DBaseTexture9 *Texture::getTexture()
|
|||
return mBaseTexture;
|
||||
}
|
||||
|
||||
// Returns the top-level texture surface as a render target
|
||||
IDirect3DSurface9 *Texture::getRenderTarget(GLenum target)
|
||||
{
|
||||
if (mDirtyMetaData && mRenderTarget)
|
||||
{
|
||||
mRenderTarget->Release();
|
||||
mRenderTarget = NULL;
|
||||
}
|
||||
|
||||
if (!mRenderTarget)
|
||||
{
|
||||
mBaseTexture = convertToRenderTarget();
|
||||
mRenderTarget = getSurface(target);
|
||||
}
|
||||
|
||||
if (dirtyImageData())
|
||||
{
|
||||
updateTexture();
|
||||
}
|
||||
|
||||
mDirtyMetaData = false;
|
||||
|
||||
return mRenderTarget;
|
||||
}
|
||||
|
||||
Texture2D::Texture2D()
|
||||
{
|
||||
mTexture = NULL;
|
||||
|
@ -391,8 +417,12 @@ void Texture2D::commitRect(GLint level, GLint xoffset, GLint yoffset, GLsizei wi
|
|||
if (mTexture != NULL)
|
||||
{
|
||||
IDirect3DSurface9 *destLevel = NULL;
|
||||
mTexture->GetSurfaceLevel(level, &destLevel);
|
||||
HRESULT result = mTexture->GetSurfaceLevel(level, &destLevel);
|
||||
|
||||
ASSERT(SUCCEEDED(result));
|
||||
|
||||
if (SUCCEEDED(result))
|
||||
{
|
||||
Image *img = &mImageArray[level];
|
||||
|
||||
RECT sourceRect;
|
||||
|
@ -405,13 +435,15 @@ void Texture2D::commitRect(GLint level, GLint xoffset, GLint yoffset, GLsizei wi
|
|||
destPoint.x = xoffset;
|
||||
destPoint.y = yoffset;
|
||||
|
||||
getDevice()->UpdateSurface(img->surface, &sourceRect, destLevel, &destPoint);
|
||||
result = getDevice()->UpdateSurface(img->surface, &sourceRect, destLevel, &destPoint);
|
||||
ASSERT(SUCCEEDED(result));
|
||||
|
||||
destLevel->Release();
|
||||
|
||||
img->dirty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Texture2D::subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels)
|
||||
{
|
||||
|
@ -480,10 +512,11 @@ IDirect3DBaseTexture9 *Texture2D::createTexture()
|
|||
IDirect3DDevice9 *device = getDevice();
|
||||
D3DFORMAT format = selectFormat(mImageArray[0].format);
|
||||
|
||||
HRESULT result = device->CreateTexture(mWidth, mHeight, 0, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &texture, NULL);
|
||||
HRESULT result = device->CreateTexture(mWidth, mHeight, 0, 0, format, D3DPOOL_DEFAULT, &texture, NULL);
|
||||
|
||||
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
|
||||
if (FAILED(result))
|
||||
{
|
||||
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
|
||||
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
|
||||
}
|
||||
|
||||
|
@ -503,9 +536,14 @@ void Texture2D::updateTexture()
|
|||
if (mImageArray[level].dirty)
|
||||
{
|
||||
IDirect3DSurface9 *levelSurface = NULL;
|
||||
mTexture->GetSurfaceLevel(level, &levelSurface);
|
||||
HRESULT result = mTexture->GetSurfaceLevel(level, &levelSurface);
|
||||
|
||||
device->UpdateSurface(mImageArray[level].surface, NULL, levelSurface, NULL);
|
||||
ASSERT(SUCCEEDED(result));
|
||||
|
||||
if (SUCCEEDED(result))
|
||||
{
|
||||
result = device->UpdateSurface(mImageArray[level].surface, NULL, levelSurface, NULL);
|
||||
ASSERT(SUCCEEDED(result));
|
||||
|
||||
levelSurface->Release();
|
||||
|
||||
|
@ -513,22 +551,87 @@ void Texture2D::updateTexture()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the top-level texture surface as a render target
|
||||
IDirect3DSurface9 *Texture2D::getRenderTarget()
|
||||
{
|
||||
if (mDirtyMetaData && mRenderTarget)
|
||||
{
|
||||
mRenderTarget->Release();
|
||||
mRenderTarget = NULL;
|
||||
}
|
||||
|
||||
if (!mRenderTarget && getTexture()) // FIXME: getTexture fails for incomplete textures. Check spec.
|
||||
IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget()
|
||||
{
|
||||
mTexture->GetSurfaceLevel(0, &mRenderTarget);
|
||||
IDirect3DTexture9 *texture;
|
||||
|
||||
IDirect3DDevice9 *device = getDevice();
|
||||
D3DFORMAT format = selectFormat(mImageArray[0].format);
|
||||
|
||||
HRESULT result = device->CreateTexture(mWidth, mHeight, 0, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &texture, NULL);
|
||||
|
||||
if (FAILED(result))
|
||||
{
|
||||
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
|
||||
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
|
||||
}
|
||||
|
||||
return mRenderTarget;
|
||||
if (mTexture != NULL)
|
||||
{
|
||||
int levels = texture->GetLevelCount();
|
||||
for (int i = 0; i < levels; i++)
|
||||
{
|
||||
IDirect3DSurface9 *source;
|
||||
result = mTexture->GetSurfaceLevel(i, &source);
|
||||
|
||||
if (FAILED(result))
|
||||
{
|
||||
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
|
||||
|
||||
texture->Release();
|
||||
|
||||
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
|
||||
}
|
||||
|
||||
IDirect3DSurface9 *dest;
|
||||
result = texture->GetSurfaceLevel(i, &dest);
|
||||
|
||||
if (FAILED(result))
|
||||
{
|
||||
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
|
||||
|
||||
texture->Release();
|
||||
source->Release();
|
||||
|
||||
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
|
||||
}
|
||||
|
||||
result = device->StretchRect(source, NULL, dest, NULL, D3DTEXF_NONE);
|
||||
|
||||
if (FAILED(result))
|
||||
{
|
||||
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
|
||||
|
||||
texture->Release();
|
||||
source->Release();
|
||||
dest->Release();
|
||||
|
||||
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
|
||||
}
|
||||
|
||||
source->Release();
|
||||
dest->Release();
|
||||
}
|
||||
|
||||
mTexture->Release();
|
||||
}
|
||||
|
||||
mTexture = texture;
|
||||
return mTexture;
|
||||
}
|
||||
|
||||
IDirect3DSurface9 *Texture2D::getSurface(GLenum target)
|
||||
{
|
||||
ASSERT(target == GL_TEXTURE_2D);
|
||||
|
||||
IDirect3DSurface9 *surface = NULL;
|
||||
HRESULT result = mTexture->GetSurfaceLevel(0, &surface);
|
||||
|
||||
ASSERT(SUCCEEDED(result));
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
bool Texture2D::dirtyImageData() const
|
||||
|
@ -601,8 +704,12 @@ void TextureCubeMap::commitRect(GLenum faceTarget, GLint level, GLint xoffset, G
|
|||
if (mTexture != NULL)
|
||||
{
|
||||
IDirect3DSurface9 *destLevel = NULL;
|
||||
mTexture->GetCubeMapSurface(static_cast<D3DCUBEMAP_FACES>(face), level, &destLevel);
|
||||
HRESULT result = mTexture->GetCubeMapSurface(static_cast<D3DCUBEMAP_FACES>(face), level, &destLevel);
|
||||
|
||||
ASSERT(SUCCEEDED(result));
|
||||
|
||||
if (SUCCEEDED(result))
|
||||
{
|
||||
Image *img = &mImageArray[face][level];
|
||||
|
||||
RECT sourceRect;
|
||||
|
@ -615,13 +722,15 @@ void TextureCubeMap::commitRect(GLenum faceTarget, GLint level, GLint xoffset, G
|
|||
destPoint.x = xoffset;
|
||||
destPoint.y = yoffset;
|
||||
|
||||
getDevice()->UpdateSurface(img->surface, &sourceRect, destLevel, &destPoint);
|
||||
result = getDevice()->UpdateSurface(img->surface, &sourceRect, destLevel, &destPoint);
|
||||
ASSERT(SUCCEEDED(result));
|
||||
|
||||
destLevel->Release();
|
||||
|
||||
img->dirty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextureCubeMap::subImage(GLenum face, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels)
|
||||
{
|
||||
|
@ -699,10 +808,11 @@ IDirect3DBaseTexture9 *TextureCubeMap::createTexture()
|
|||
|
||||
IDirect3DCubeTexture9 *texture;
|
||||
|
||||
HRESULT result = device->CreateCubeTexture(mWidth, 0, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &texture, NULL);
|
||||
HRESULT result = device->CreateCubeTexture(mWidth, 0, 0, format, D3DPOOL_DEFAULT, &texture, NULL);
|
||||
|
||||
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
|
||||
if (FAILED(result))
|
||||
{
|
||||
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
|
||||
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
|
||||
}
|
||||
|
||||
|
@ -724,10 +834,15 @@ void TextureCubeMap::updateTexture()
|
|||
|
||||
if (img->dirty)
|
||||
{
|
||||
IDirect3DSurface9 *levelSurface = NULL;
|
||||
mTexture->GetCubeMapSurface(static_cast<D3DCUBEMAP_FACES>(face), level, &levelSurface);
|
||||
IDirect3DSurface9 *levelSurface;
|
||||
HRESULT result = mTexture->GetCubeMapSurface(static_cast<D3DCUBEMAP_FACES>(face), level, &levelSurface);
|
||||
|
||||
device->UpdateSurface(img->surface, NULL, levelSurface, NULL);
|
||||
ASSERT(SUCCEEDED(result));
|
||||
|
||||
if (SUCCEEDED(result))
|
||||
{
|
||||
result = device->UpdateSurface(img->surface, NULL, levelSurface, NULL);
|
||||
ASSERT(SUCCEEDED(result));
|
||||
|
||||
levelSurface->Release();
|
||||
|
||||
|
@ -736,6 +851,86 @@ void TextureCubeMap::updateTexture()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget()
|
||||
{
|
||||
IDirect3DCubeTexture9 *texture;
|
||||
|
||||
IDirect3DDevice9 *device = getDevice();
|
||||
D3DFORMAT format = selectFormat(mImageArray[0][0].format);
|
||||
|
||||
HRESULT result = device->CreateCubeTexture(mWidth, 0, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &texture, NULL);
|
||||
|
||||
if (FAILED(result))
|
||||
{
|
||||
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
|
||||
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
|
||||
}
|
||||
|
||||
if (mTexture != NULL)
|
||||
{
|
||||
int levels = texture->GetLevelCount();
|
||||
for (int f = 0; f < 6; f++)
|
||||
{
|
||||
for (int i = 0; i < levels; i++)
|
||||
{
|
||||
IDirect3DSurface9 *source;
|
||||
result = mTexture->GetCubeMapSurface(static_cast<D3DCUBEMAP_FACES>(f), i, &source);
|
||||
|
||||
if (FAILED(result))
|
||||
{
|
||||
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
|
||||
|
||||
texture->Release();
|
||||
|
||||
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
|
||||
}
|
||||
|
||||
IDirect3DSurface9 *dest;
|
||||
result = texture->GetCubeMapSurface(static_cast<D3DCUBEMAP_FACES>(f), i, &dest);
|
||||
|
||||
if (FAILED(result))
|
||||
{
|
||||
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
|
||||
|
||||
texture->Release();
|
||||
source->Release();
|
||||
|
||||
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
|
||||
}
|
||||
|
||||
result = device->StretchRect(source, NULL, dest, NULL, D3DTEXF_NONE);
|
||||
|
||||
if (FAILED(result))
|
||||
{
|
||||
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
|
||||
|
||||
texture->Release();
|
||||
source->Release();
|
||||
dest->Release();
|
||||
|
||||
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mTexture->Release();
|
||||
}
|
||||
|
||||
mTexture = texture;
|
||||
return mTexture;
|
||||
}
|
||||
|
||||
IDirect3DSurface9 *TextureCubeMap::getSurface(GLenum target)
|
||||
{
|
||||
ASSERT(es2dx::IsCubemapTextureTarget(target));
|
||||
|
||||
IDirect3DSurface9 *surface = NULL;
|
||||
HRESULT result = mTexture->GetCubeMapSurface(static_cast<D3DCUBEMAP_FACES>(faceIndex(target)), 0, &surface);
|
||||
ASSERT(SUCCEEDED(result));
|
||||
return surface;
|
||||
}
|
||||
|
||||
void TextureCubeMap::setImage(int face, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels)
|
||||
{
|
||||
|
|
|
@ -49,7 +49,10 @@ class Texture : public Colorbuffer
|
|||
GLenum getWrapT() const;
|
||||
|
||||
virtual bool isComplete() const = 0;
|
||||
|
||||
IDirect3DBaseTexture9 *getTexture();
|
||||
IDirect3DSurface9 *getRenderTarget(GLenum target);
|
||||
IDirect3DSurface9 *getRenderTarget() { return getRenderTarget(GL_TEXTURE_2D); } // FIXME: to be removed once FBO rendering is completed.
|
||||
|
||||
protected:
|
||||
// Helper structure representing a single image layer
|
||||
|
@ -82,16 +85,18 @@ class Texture : public Colorbuffer
|
|||
// The pointer returned is weak and it is assumed the derived class will keep a strong pointer until the next createTexture() call.
|
||||
virtual IDirect3DBaseTexture9 *createTexture() = 0;
|
||||
virtual void updateTexture() = 0;
|
||||
virtual IDirect3DBaseTexture9 *convertToRenderTarget() = 0;
|
||||
virtual IDirect3DSurface9 *getSurface(GLenum target) = 0;
|
||||
|
||||
virtual bool dirtyImageData() const = 0;
|
||||
|
||||
bool mDirtyMetaData; // FIXME: would be private but getRenderTarget is still implemented through the derived classes and they need it.
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(Texture);
|
||||
|
||||
IDirect3DBaseTexture9 *mBaseTexture; // This is a weak pointer. The derived class is assumed to own a strong pointer.
|
||||
|
||||
bool mDirtyMetaData;
|
||||
|
||||
void loadImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type,
|
||||
const void *input, std::size_t outputPitch, void *output) const;
|
||||
};
|
||||
|
@ -109,13 +114,14 @@ class Texture2D : public Texture
|
|||
void subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
|
||||
|
||||
bool isComplete() const;
|
||||
IDirect3DSurface9 *getRenderTarget();
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(Texture2D);
|
||||
|
||||
virtual IDirect3DBaseTexture9 *createTexture();
|
||||
virtual void updateTexture();
|
||||
virtual IDirect3DBaseTexture9 *convertToRenderTarget();
|
||||
virtual IDirect3DSurface9 *getSurface(GLenum target);
|
||||
|
||||
virtual bool dirtyImageData() const;
|
||||
|
||||
|
@ -151,6 +157,8 @@ class TextureCubeMap : public Texture
|
|||
|
||||
virtual IDirect3DBaseTexture9 *createTexture();
|
||||
virtual void updateTexture();
|
||||
virtual IDirect3DBaseTexture9 *convertToRenderTarget();
|
||||
virtual IDirect3DSurface9 *getSurface(GLenum target);
|
||||
|
||||
virtual bool dirtyImageData() const;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче