Retrieve the D3D texture format per image.

TRAC #16118 Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@597 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent d976b584
...@@ -39,6 +39,62 @@ Texture::Image::~Image() ...@@ -39,6 +39,62 @@ Texture::Image::~Image()
} }
} }
bool Texture::Image::isRenderable() const
{
switch(getD3DFormat())
{
case D3DFMT_L8:
case D3DFMT_A8L8:
case D3DFMT_DXT1:
return false;
case D3DFMT_A8R8G8B8:
case D3DFMT_X8R8G8B8:
case D3DFMT_A16B16G16R16F:
case D3DFMT_A32B32G32R32F:
return true;
default:
UNREACHABLE();
}
return false;
}
D3DFORMAT Texture::Image::getD3DFormat() const
{
if (format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
{
return D3DFMT_DXT1;
}
else if (type == GL_FLOAT)
{
return D3DFMT_A32B32G32R32F;
}
else if (type == GL_HALF_FLOAT_OES)
{
return D3DFMT_A16B16G16R16F;
}
else if (type == GL_UNSIGNED_BYTE)
{
if (format == GL_LUMINANCE && getContext()->supportsLuminanceTextures())
{
return D3DFMT_L8;
}
else if (format == GL_LUMINANCE_ALPHA && getContext()->supportsLuminanceAlphaTextures())
{
return D3DFMT_A8L8;
}
else if (format == GL_RGB)
{
return D3DFMT_X8R8G8B8;
}
return D3DFMT_A8R8G8B8;
}
return D3DFMT_A8R8G8B8;
}
Texture::Texture(GLuint id) : RefCountObject(id), mSerial(issueSerial()) Texture::Texture(GLuint id) : RefCountObject(id), mSerial(issueSerial())
{ {
mMinFilter = GL_NEAREST_MIPMAP_LINEAR; mMinFilter = GL_NEAREST_MIPMAP_LINEAR;
...@@ -168,65 +224,6 @@ GLenum Texture::getWrapT() const ...@@ -168,65 +224,6 @@ GLenum Texture::getWrapT() const
return mWrapT; return mWrapT;
} }
bool Texture::isRenderableFormat() const
{
D3DFORMAT format = getD3DFormat();
switch(format)
{
case D3DFMT_L8:
case D3DFMT_A8L8:
case D3DFMT_DXT1:
return false;
case D3DFMT_A8R8G8B8:
case D3DFMT_X8R8G8B8:
case D3DFMT_A16B16G16R16F:
case D3DFMT_A32B32G32R32F:
return true;
default:
UNREACHABLE();
}
return false;
}
// Selects an internal Direct3D 9 format for storing an Image
D3DFORMAT Texture::selectFormat(GLenum format, GLenum type)
{
if (format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
{
return D3DFMT_DXT1;
}
else if (type == GL_FLOAT)
{
return D3DFMT_A32B32G32R32F;
}
else if (type == GL_HALF_FLOAT_OES)
{
return D3DFMT_A16B16G16R16F;
}
else if (type == GL_UNSIGNED_BYTE)
{
if (format == GL_LUMINANCE && getContext()->supportsLuminanceTextures())
{
return D3DFMT_L8;
}
else if (format == GL_LUMINANCE_ALPHA && getContext()->supportsLuminanceAlphaTextures())
{
return D3DFMT_A8L8;
}
else if (format == GL_RGB)
{
return D3DFMT_X8R8G8B8;
}
return D3DFMT_A8R8G8B8;
}
return D3DFMT_A8R8G8B8;
}
// Store the pixel rectangle designated by xoffset,yoffset,width,height with pixels stored as format/type at input // Store the pixel rectangle designated by xoffset,yoffset,width,height with pixels stored as format/type at input
// into the target pixel rectangle at output with outputPitch bytes in between each line. // into the target pixel rectangle at output with outputPitch bytes in between each line.
void Texture::loadImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, void Texture::loadImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type,
...@@ -807,7 +804,7 @@ void Texture::createSurface(Image *image) ...@@ -807,7 +804,7 @@ void Texture::createSurface(Image *image)
levelToFetch = upsampleCount; levelToFetch = upsampleCount;
} }
HRESULT result = getDevice()->CreateTexture(requestWidth, requestHeight, levelToFetch + 1, NULL, selectFormat(image->format, image->type), HRESULT result = getDevice()->CreateTexture(requestWidth, requestHeight, levelToFetch + 1, NULL, image->getD3DFormat(),
D3DPOOL_SYSTEMMEM, &newTexture, NULL); D3DPOOL_SYSTEMMEM, &newTexture, NULL);
if (FAILED(result)) if (FAILED(result))
...@@ -961,7 +958,7 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL ...@@ -961,7 +958,7 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL
} }
// This implements glCopyTex[Sub]Image2D for non-renderable internal texture formats // This implements glCopyTex[Sub]Image2D for non-renderable internal texture formats
void Texture::copyNonRenderable(Image *image, GLenum format, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, IDirect3DSurface9 *renderTarget) void Texture::copyNonRenderable(Image *image, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, IDirect3DSurface9 *renderTarget)
{ {
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
IDirect3DSurface9 *surface = NULL; IDirect3DSurface9 *surface = NULL;
...@@ -1032,7 +1029,7 @@ void Texture::copyNonRenderable(Image *image, GLenum format, GLint xoffset, GLin ...@@ -1032,7 +1029,7 @@ void Texture::copyNonRenderable(Image *image, GLenum format, GLint xoffset, GLin
{ {
case D3DFMT_X8R8G8B8: case D3DFMT_X8R8G8B8:
case D3DFMT_A8R8G8B8: case D3DFMT_A8R8G8B8:
switch(getD3DFormat()) switch(image->getD3DFormat())
{ {
case D3DFMT_L8: case D3DFMT_L8:
for(int y = 0; y < height; y++) for(int y = 0; y < height; y++)
...@@ -1064,7 +1061,7 @@ void Texture::copyNonRenderable(Image *image, GLenum format, GLint xoffset, GLin ...@@ -1064,7 +1061,7 @@ void Texture::copyNonRenderable(Image *image, GLenum format, GLint xoffset, GLin
} }
break; break;
case D3DFMT_R5G6B5: case D3DFMT_R5G6B5:
switch(getD3DFormat()) switch(image->getD3DFormat())
{ {
case D3DFMT_L8: case D3DFMT_L8:
for(int y = 0; y < height; y++) for(int y = 0; y < height; y++)
...@@ -1084,7 +1081,7 @@ void Texture::copyNonRenderable(Image *image, GLenum format, GLint xoffset, GLin ...@@ -1084,7 +1081,7 @@ void Texture::copyNonRenderable(Image *image, GLenum format, GLint xoffset, GLin
} }
break; break;
case D3DFMT_A1R5G5B5: case D3DFMT_A1R5G5B5:
switch(getD3DFormat()) switch(image->getD3DFormat())
{ {
case D3DFMT_L8: case D3DFMT_L8:
for(int y = 0; y < height; y++) for(int y = 0; y < height; y++)
...@@ -1130,11 +1127,6 @@ void Texture::copyNonRenderable(Image *image, GLenum format, GLint xoffset, GLin ...@@ -1130,11 +1127,6 @@ void Texture::copyNonRenderable(Image *image, GLenum format, GLint xoffset, GLin
surface->Release(); surface->Release();
} }
D3DFORMAT Texture::getD3DFormat() const
{
return selectFormat(getInternalFormat(), getType());
}
IDirect3DBaseTexture9 *Texture::getTexture() IDirect3DBaseTexture9 *Texture::getTexture()
{ {
if (!isComplete()) if (!isComplete())
...@@ -1242,6 +1234,11 @@ GLenum Texture2D::getType() const ...@@ -1242,6 +1234,11 @@ GLenum Texture2D::getType() const
return mImageArray[0].type; return mImageArray[0].type;
} }
D3DFORMAT Texture2D::getD3DFormat() const
{
return mImageArray[0].getD3DFormat();
}
void Texture2D::redefineTexture(GLint level, GLenum format, GLsizei width, GLsizei height, GLenum type) void Texture2D::redefineTexture(GLint level, GLenum format, GLsizei width, GLsizei height, GLenum type)
{ {
GLsizei textureWidth = mImageArray[0].width; GLsizei textureWidth = mImageArray[0].width;
...@@ -1358,9 +1355,9 @@ void Texture2D::copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei ...@@ -1358,9 +1355,9 @@ void Texture2D::copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei
redefineTexture(level, format, width, height, GL_UNSIGNED_BYTE); redefineTexture(level, format, width, height, GL_UNSIGNED_BYTE);
if (!isRenderableFormat()) if (!mImageArray[level].isRenderable())
{ {
copyNonRenderable(&mImageArray[level], format, 0, 0, x, y, width, height, renderTarget); copyNonRenderable(&mImageArray[level], 0, 0, x, y, width, height, renderTarget);
} }
else else
{ {
...@@ -1403,11 +1400,11 @@ void Texture2D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yo ...@@ -1403,11 +1400,11 @@ void Texture2D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yo
return error(GL_OUT_OF_MEMORY); return error(GL_OUT_OF_MEMORY);
} }
redefineTexture(0, mImageArray[0].format, mImageArray[0].width, mImageArray[0].height, GL_UNSIGNED_BYTE); redefineTexture(level, mImageArray[level].format, mImageArray[level].width, mImageArray[level].height, GL_UNSIGNED_BYTE);
if (!isRenderableFormat() || (!mTexture && !isComplete())) if (!mImageArray[level].isRenderable() || (!mTexture && !isComplete()))
{ {
copyNonRenderable(&mImageArray[level], getInternalFormat(), xoffset, yoffset, x, y, width, height, renderTarget); copyNonRenderable(&mImageArray[level], xoffset, yoffset, x, y, width, height, renderTarget);
} }
else else
{ {
...@@ -1474,7 +1471,6 @@ bool Texture2D::isComplete() const ...@@ -1474,7 +1471,6 @@ bool Texture2D::isComplete() const
} }
} }
if ((getWrapS() != GL_CLAMP_TO_EDGE && !isPow2(width)) if ((getWrapS() != GL_CLAMP_TO_EDGE && !isPow2(width))
|| (getWrapT() != GL_CLAMP_TO_EDGE && !isPow2(height))) || (getWrapT() != GL_CLAMP_TO_EDGE && !isPow2(height)))
{ {
...@@ -1531,7 +1527,7 @@ IDirect3DBaseTexture9 *Texture2D::getBaseTexture() const ...@@ -1531,7 +1527,7 @@ IDirect3DBaseTexture9 *Texture2D::getBaseTexture() const
void Texture2D::createTexture() void Texture2D::createTexture()
{ {
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
D3DFORMAT format = selectFormat(mImageArray[0].format, mImageArray[0].type); D3DFORMAT format = mImageArray[0].getD3DFormat();
GLint levels = creationLevels(mImageArray[0].width, mImageArray[0].height, 0); GLint levels = creationLevels(mImageArray[0].width, mImageArray[0].height, 0);
IDirect3DTexture9 *texture = NULL; IDirect3DTexture9 *texture = NULL;
...@@ -1589,7 +1585,7 @@ void Texture2D::convertToRenderTarget() ...@@ -1589,7 +1585,7 @@ void Texture2D::convertToRenderTarget()
{ {
egl::Display *display = getDisplay(); egl::Display *display = getDisplay();
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
D3DFORMAT format = selectFormat(mImageArray[0].format, mImageArray[0].type); D3DFORMAT format = mImageArray[0].getD3DFormat();
GLint levels = creationLevels(mImageArray[0].width, mImageArray[0].height, 0); GLint levels = creationLevels(mImageArray[0].width, mImageArray[0].height, 0);
HRESULT result = device->CreateTexture(mImageArray[0].width, mImageArray[0].height, levels, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &texture, NULL); HRESULT result = device->CreateTexture(mImageArray[0].width, mImageArray[0].height, levels, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &texture, NULL);
...@@ -1812,6 +1808,11 @@ GLenum TextureCubeMap::getType() const ...@@ -1812,6 +1808,11 @@ GLenum TextureCubeMap::getType() const
return mImageArray[0][0].type; return mImageArray[0][0].type;
} }
D3DFORMAT TextureCubeMap::getD3DFormat() const
{
return mImageArray[0][0].getD3DFormat();
}
void TextureCubeMap::setImagePosX(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels) void TextureCubeMap::setImagePosX(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels)
{ {
setImage(0, level, width, height, format, type, unpackAlignment, pixels); setImage(0, level, width, height, format, type, unpackAlignment, pixels);
...@@ -1989,7 +1990,7 @@ IDirect3DBaseTexture9 *TextureCubeMap::getBaseTexture() const ...@@ -1989,7 +1990,7 @@ IDirect3DBaseTexture9 *TextureCubeMap::getBaseTexture() const
void TextureCubeMap::createTexture() void TextureCubeMap::createTexture()
{ {
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
D3DFORMAT format = selectFormat(mImageArray[0][0].format, mImageArray[0][0].type); D3DFORMAT format = mImageArray[0][0].getD3DFormat();
GLint levels = creationLevels(mImageArray[0][0].width, 0); GLint levels = creationLevels(mImageArray[0][0].width, 0);
IDirect3DCubeTexture9 *texture = NULL; IDirect3DCubeTexture9 *texture = NULL;
...@@ -2049,7 +2050,7 @@ void TextureCubeMap::convertToRenderTarget() ...@@ -2049,7 +2050,7 @@ void TextureCubeMap::convertToRenderTarget()
{ {
egl::Display *display = getDisplay(); egl::Display *display = getDisplay();
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
D3DFORMAT format = selectFormat(mImageArray[0][0].format, mImageArray[0][0].type); D3DFORMAT format = mImageArray[0][0].getD3DFormat();
GLint levels = creationLevels(mImageArray[0][0].width, 0); GLint levels = creationLevels(mImageArray[0][0].width, 0);
HRESULT result = device->CreateCubeTexture(mImageArray[0][0].width, levels, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &texture, NULL); HRESULT result = device->CreateCubeTexture(mImageArray[0][0].width, levels, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &texture, NULL);
...@@ -2196,9 +2197,9 @@ void TextureCubeMap::copyImage(GLenum target, GLint level, GLenum format, GLint ...@@ -2196,9 +2197,9 @@ void TextureCubeMap::copyImage(GLenum target, GLint level, GLenum format, GLint
unsigned int faceindex = faceIndex(target); unsigned int faceindex = faceIndex(target);
redefineTexture(faceindex, level, format, width, height, GL_UNSIGNED_BYTE); redefineTexture(faceindex, level, format, width, height, GL_UNSIGNED_BYTE);
if (!isRenderableFormat() || (!mTexture && !isComplete())) if (!mImageArray[faceindex][level].isRenderable())
{ {
copyNonRenderable(&mImageArray[faceindex][level], format, 0, 0, x, y, width, height, renderTarget); copyNonRenderable(&mImageArray[faceindex][level], 0, 0, x, y, width, height, renderTarget);
} }
else else
{ {
...@@ -2260,11 +2261,11 @@ void TextureCubeMap::copySubImage(GLenum target, GLint level, GLint xoffset, GLi ...@@ -2260,11 +2261,11 @@ void TextureCubeMap::copySubImage(GLenum target, GLint level, GLint xoffset, GLi
} }
unsigned int faceindex = faceIndex(target); unsigned int faceindex = faceIndex(target);
redefineTexture(0, 0, mImageArray[0][0].format, mImageArray[0][0].width, mImageArray[0][0].height, GL_UNSIGNED_BYTE); redefineTexture(faceindex, level, mImageArray[faceindex][level].format, mImageArray[faceindex][level].width, mImageArray[faceindex][level].height, GL_UNSIGNED_BYTE);
if (!isRenderableFormat()) if (!mImageArray[faceindex][level].isRenderable() || (!mTexture && !isComplete()))
{ {
copyNonRenderable(&mImageArray[faceindex][level], getInternalFormat(), 0, 0, x, y, width, height, renderTarget); copyNonRenderable(&mImageArray[faceindex][level], 0, 0, x, y, width, height, renderTarget);
} }
else else
{ {
......
...@@ -61,12 +61,11 @@ class Texture : public RefCountObject ...@@ -61,12 +61,11 @@ class Texture : public RefCountObject
virtual GLsizei getHeight() const = 0; virtual GLsizei getHeight() const = 0;
virtual GLenum getInternalFormat() const = 0; virtual GLenum getInternalFormat() const = 0;
virtual GLenum getType() const = 0; virtual GLenum getType() const = 0;
virtual D3DFORMAT getD3DFormat() const = 0;
virtual bool isComplete() const = 0; virtual bool isComplete() const = 0;
virtual bool isCompressed() const = 0; virtual bool isCompressed() const = 0;
bool isRenderableFormat() const;
D3DFORMAT getD3DFormat() const;
IDirect3DBaseTexture9 *getTexture(); IDirect3DBaseTexture9 *getTexture();
virtual Renderbuffer *getRenderbuffer(GLenum target) = 0; virtual Renderbuffer *getRenderbuffer(GLenum target) = 0;
...@@ -89,6 +88,9 @@ class Texture : public RefCountObject ...@@ -89,6 +88,9 @@ class Texture : public RefCountObject
Image(); Image();
~Image(); ~Image();
bool isRenderable() const;
D3DFORMAT getD3DFormat() const;
GLsizei width; GLsizei width;
GLsizei height; GLsizei height;
GLenum format; GLenum format;
...@@ -99,13 +101,11 @@ class Texture : public RefCountObject ...@@ -99,13 +101,11 @@ class Texture : public RefCountObject
IDirect3DSurface9 *surface; IDirect3DSurface9 *surface;
}; };
static D3DFORMAT selectFormat(GLenum format, GLenum type);
void setImage(GLint unpackAlignment, const void *pixels, Image *image); void setImage(GLint unpackAlignment, const void *pixels, Image *image);
bool subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, Image *image); bool subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, Image *image);
void setCompressedImage(GLsizei imageSize, const void *pixels, Image *image); void setCompressedImage(GLsizei imageSize, const void *pixels, Image *image);
bool subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels, Image *image); bool subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels, Image *image);
void copyNonRenderable(Image *image, GLenum format, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, IDirect3DSurface9 *renderTarget); void copyNonRenderable(Image *image, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, IDirect3DSurface9 *renderTarget);
GLint creationLevels(GLsizei width, GLsizei height, GLint maxlevel) const; GLint creationLevels(GLsizei width, GLsizei height, GLint maxlevel) const;
GLint creationLevels(GLsizei size, GLint maxlevel) const; GLint creationLevels(GLsizei size, GLint maxlevel) const;
...@@ -199,6 +199,7 @@ class Texture2D : public Texture ...@@ -199,6 +199,7 @@ class Texture2D : public Texture
virtual GLsizei getHeight() const; virtual GLsizei getHeight() const;
virtual GLenum getInternalFormat() const; virtual GLenum getInternalFormat() const;
virtual GLenum getType() const; virtual GLenum getType() const;
virtual D3DFORMAT getD3DFormat() const;
void setImage(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); void setImage(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels); void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
...@@ -246,6 +247,7 @@ class TextureCubeMap : public Texture ...@@ -246,6 +247,7 @@ class TextureCubeMap : public Texture
virtual GLsizei getHeight() const; virtual GLsizei getHeight() const;
virtual GLenum getInternalFormat() const; virtual GLenum getInternalFormat() const;
virtual GLenum getType() const; virtual GLenum getType() const;
virtual D3DFORMAT getD3DFormat() const;
void setImagePosX(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); void setImagePosX(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
void setImageNegX(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); void setImageNegX(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
......
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