Implements support for renderable floating point textures.

TRAC #12909 Signed-off-by: Daniel Koch Author: Shannon Woods git-svn-id: https://angleproject.googlecode.com/svn/trunk@409 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 0db0d6c8
......@@ -498,46 +498,60 @@ bool Display::getCompressedTextureSupport()
return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT1));
}
bool Display::getFloatTextureSupport(bool *filtering)
bool Display::getFloatTextureSupport(bool *filtering, bool *renderable)
{
D3DDISPLAYMODE currentDisplayMode;
mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
if (SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER,
D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)))
{
*filtering = true;
return true;
}
else
*filtering = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER,
D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)) &&
SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER,
D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F));
*renderable = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET,
D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F))&&
SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET,
D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F));
if (!filtering && !renderable)
{
*filtering = false;
return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0,
D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)) &&
SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0,
D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F));
}
else
{
return true;
}
}
bool Display::getHalfFloatTextureSupport(bool *filtering)
bool Display::getHalfFloatTextureSupport(bool *filtering, bool *renderable)
{
D3DDISPLAYMODE currentDisplayMode;
mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
if (SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER,
D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)))
{
*filtering = true;
return true;
}
else
*filtering = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER,
D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) &&
SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER,
D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F));
*renderable = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET,
D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) &&
SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET,
D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F));
if (!filtering && !renderable)
{
*filtering = false;
return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0,
D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) &&
SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0,
D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F));
}
else
{
return true;
}
}
bool Display::getEventQuerySupport()
......
......@@ -61,9 +61,9 @@ class Display
virtual D3DCAPS9 getDeviceCaps();
virtual void getMultiSampleSupport(D3DFORMAT format, bool *multiSampleArray);
virtual bool getCompressedTextureSupport();
virtual bool getFloatTextureSupport(bool *filtering);
virtual bool getHalfFloatTextureSupport(bool *filtering);
virtual bool getEventQuerySupport();
virtual bool getFloatTextureSupport(bool *filtering, bool *renderable);
virtual bool getHalfFloatTextureSupport(bool *filtering, bool *renderable);
private:
DISALLOW_COPY_AND_ASSIGN(Display);
......
......@@ -275,8 +275,8 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
mSupportsEventQueries = display->getEventQuerySupport();
mSupportsCompressedTextures = display->getCompressedTextureSupport();
mSupportsFloatTextures = display->getFloatTextureSupport(&mSupportsFloatLinearFilter);
mSupportsHalfFloatTextures = display->getHalfFloatTextureSupport(&mSupportsHalfFloatLinearFilter);
mSupportsFloatTextures = display->getFloatTextureSupport(&mSupportsFloatLinearFilter, &mSupportsFloatRenderableTextures);
mSupportsHalfFloatTextures = display->getHalfFloatTextureSupport(&mSupportsHalfFloatLinearFilter, &mSupportsHalfFloatRenderableTextures);
initExtensionString();
......@@ -2256,6 +2256,28 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum
r = (argb & 0x3FF00000) * (1.0f / 0x3FF00000);
}
break;
case D3DFMT_A32B32G32R32F:
{
// float formats in D3D are stored rgba, rather than the other way round
r = *((float*)(source + 16 * i + j * lock.Pitch) + 0);
g = *((float*)(source + 16 * i + j * lock.Pitch) + 1);
b = *((float*)(source + 16 * i + j * lock.Pitch) + 2);
a = *((float*)(source + 16 * i + j * lock.Pitch) + 3);
}
break;
case D3DFMT_A16B16G16R16F:
{
// float formats in D3D are stored rgba, rather than the other way round
float abgr[4];
D3DXFloat16To32Array(abgr, (D3DXFLOAT16*)(source + 8 * i + j * lock.Pitch), 4);
a = abgr[3];
b = abgr[2];
g = abgr[1];
r = abgr[0];
}
break;
default:
UNIMPLEMENTED(); // FIXME
UNREACHABLE();
......@@ -2878,6 +2900,11 @@ bool Context::supportsFloatLinearFilter() const
return mSupportsFloatLinearFilter;
}
bool Context::supportsFloatRenderableTextures() const
{
return mSupportsFloatRenderableTextures;
}
bool Context::supportsHalfFloatTextures() const
{
return mSupportsHalfFloatTextures;
......@@ -2888,6 +2915,11 @@ bool Context::supportsHalfFloatLinearFilter() const
return mSupportsHalfFloatLinearFilter;
}
bool Context::supportsHalfFloatRenderableTextures() const
{
return mSupportsHalfFloatRenderableTextures;
}
void Context::detachBuffer(GLuint buffer)
{
// [OpenGL ES 2.0.24] section 2.9 page 22:
......
......@@ -387,8 +387,10 @@ class Context
bool supportsCompressedTextures() const;
bool supportsFloatTextures() const;
bool supportsFloatLinearFilter() const;
bool supportsFloatRenderableTextures() const;
bool supportsHalfFloatTextures() const;
bool supportsHalfFloatLinearFilter() const;
bool supportsHalfFloatRenderableTextures() const;
void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
......@@ -461,8 +463,10 @@ class Context
bool mSupportsCompressedTextures;
bool mSupportsFloatTextures;
bool mSupportsFloatLinearFilter;
bool mSupportsFloatRenderableTextures;
bool mSupportsHalfFloatTextures;
bool mSupportsHalfFloatLinearFilter;
bool mSupportsHalfFloatRenderableTextures;
// state caching flags
bool mClearStateDirty;
......
......@@ -311,6 +311,12 @@ GLenum Framebuffer::completeness()
{
return GL_FRAMEBUFFER_UNSUPPORTED;
}
if (colorbuffer->isFloatingPoint() && (!getContext()->supportsFloatRenderableTextures() ||
!getContext()->supportsHalfFloatRenderableTextures()))
{
return GL_FRAMEBUFFER_UNSUPPORTED;
}
}
width = colorbuffer->getWidth();
......
......@@ -141,6 +141,11 @@ GLenum RenderbufferStorage::getFormat() const
return mFormat;
}
bool RenderbufferStorage::isFloatingPoint() const
{
return false; // no floating point renderbuffers
}
D3DFORMAT RenderbufferStorage::getD3DFormat() const
{
return mD3DFormat;
......
......@@ -42,6 +42,7 @@ class RenderbufferStorage
virtual int getWidth() const;
virtual int getHeight() const;
virtual GLenum getFormat() const;
virtual bool isFloatingPoint() const;
D3DFORMAT getD3DFormat() const;
GLsizei getSamples() const;
unsigned int getSerial() const;
......
......@@ -2073,4 +2073,9 @@ GLenum Texture::TextureColorbufferProxy::getFormat() const
return mTexture->getFormat();
}
bool Texture::TextureColorbufferProxy::isFloatingPoint() const
{
return mTexture->isFloatingPoint();
}
}
......@@ -86,6 +86,7 @@ class Texture : public RefCountObject
virtual int getWidth() const;
virtual int getHeight() const;
virtual GLenum getFormat() const;
virtual bool isFloatingPoint() const;
private:
Texture *mTexture;
......
......@@ -226,6 +226,18 @@ bool IsCompressed(GLenum format)
}
}
bool IsFloatingPoint(GLenum type)
{
if (type == GL_FLOAT || type == GL_HALF_FLOAT_OES)
{
return true;
}
else
{
return false;
}
}
// Returns the size, in bytes, of a single texel in an Image
int ComputePixelSize(GLenum format, GLenum type)
{
......@@ -545,6 +557,10 @@ unsigned int GetAlphaSize(D3DFORMAT colorFormat)
{
switch (colorFormat)
{
case D3DFMT_A16B16G16R16F:
return 16;
case D3DFMT_A32B32G32R32F:
return 32;
case D3DFMT_A2R10G10B10:
return 2;
case D3DFMT_A8R8G8B8:
......@@ -564,6 +580,10 @@ unsigned int GetRedSize(D3DFORMAT colorFormat)
{
switch (colorFormat)
{
case D3DFMT_A16B16G16R16F:
return 16;
case D3DFMT_A32B32G32R32F:
return 32;
case D3DFMT_A2R10G10B10:
return 10;
case D3DFMT_A8R8G8B8:
......@@ -582,6 +602,10 @@ unsigned int GetGreenSize(D3DFORMAT colorFormat)
{
switch (colorFormat)
{
case D3DFMT_A16B16G16R16F:
return 16;
case D3DFMT_A32B32G32R32F:
return 32;
case D3DFMT_A2R10G10B10:
return 10;
case D3DFMT_A8R8G8B8:
......@@ -601,6 +625,10 @@ unsigned int GetBlueSize(D3DFORMAT colorFormat)
{
switch (colorFormat)
{
case D3DFMT_A16B16G16R16F:
return 16;
case D3DFMT_A32B32G32R32F:
return 32;
case D3DFMT_A2R10G10B10:
return 10;
case D3DFMT_A8R8G8B8:
......
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