Move texture sampler state into a separate sampler state structure.

Trac #21727 Conflicts: src/libGLESv2/Texture.cpp git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1335 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent f112217a
...@@ -2438,25 +2438,22 @@ void Context::applyTextures(SamplerType type) ...@@ -2438,25 +2438,22 @@ void Context::applyTextures(SamplerType type)
{ {
if (appliedTextureSerial[samplerIndex] != texSerial || texture->hasDirtyParameters()) if (appliedTextureSerial[samplerIndex] != texSerial || texture->hasDirtyParameters())
{ {
GLenum wrapS = texture->getWrapS(); SamplerState samplerState;
GLenum wrapT = texture->getWrapT(); texture->getSamplerState(&samplerState);
GLenum minFilter = texture->getMinFilter();
GLenum magFilter = texture->getMagFilter();
float maxAnisotropy = texture->getMaxAnisotropy();
mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSU, es2dx::ConvertTextureWrap(wrapS)); mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSU, es2dx::ConvertTextureWrap(samplerState.wrapS));
mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSV, es2dx::ConvertTextureWrap(wrapT)); mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSV, es2dx::ConvertTextureWrap(samplerState.wrapT));
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAGFILTER, es2dx::ConvertMagFilter(magFilter, maxAnisotropy)); mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAGFILTER, es2dx::ConvertMagFilter(samplerState.magFilter, samplerState.maxAnisotropy));
D3DTEXTUREFILTERTYPE d3dMinFilter, d3dMipFilter; D3DTEXTUREFILTERTYPE d3dMinFilter, d3dMipFilter;
es2dx::ConvertMinFilter(minFilter, &d3dMinFilter, &d3dMipFilter, maxAnisotropy); es2dx::ConvertMinFilter(samplerState.minFilter, &d3dMinFilter, &d3dMipFilter, samplerState.maxAnisotropy);
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MINFILTER, d3dMinFilter); mDevice->SetSamplerState(d3dSampler, D3DSAMP_MINFILTER, d3dMinFilter);
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MIPFILTER, d3dMipFilter); mDevice->SetSamplerState(d3dSampler, D3DSAMP_MIPFILTER, d3dMipFilter);
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXMIPLEVEL, texture->getLodOffset()); mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXMIPLEVEL, samplerState.lodOffset);
if (supportsTextureFilterAnisotropy()) if (supportsTextureFilterAnisotropy())
{ {
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXANISOTROPY, (DWORD)maxAnisotropy); mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXANISOTROPY, (DWORD)samplerState.maxAnisotropy);
} }
} }
......
...@@ -1317,13 +1317,14 @@ int TextureStorage::getLodOffset() const ...@@ -1317,13 +1317,14 @@ int TextureStorage::getLodOffset() const
Texture::Texture(GLuint id) : RefCountObject(id) Texture::Texture(GLuint id) : RefCountObject(id)
{ {
mMinFilter = GL_NEAREST_MIPMAP_LINEAR; mSamplerState.minFilter = GL_NEAREST_MIPMAP_LINEAR;
mMagFilter = GL_LINEAR; mSamplerState.magFilter = GL_LINEAR;
mWrapS = GL_REPEAT; mSamplerState.wrapS = GL_REPEAT;
mWrapT = GL_REPEAT; mSamplerState.wrapT = GL_REPEAT;
mSamplerState.maxAnisotropy = 1.0f;
mSamplerState.lodOffset = 0;
mDirtyParameters = true; mDirtyParameters = true;
mUsage = GL_NONE; mUsage = GL_NONE;
mMaxAnisotropy = 1.0f;
mDirtyImages = true; mDirtyImages = true;
...@@ -1346,9 +1347,9 @@ bool Texture::setMinFilter(GLenum filter) ...@@ -1346,9 +1347,9 @@ bool Texture::setMinFilter(GLenum filter)
case GL_NEAREST_MIPMAP_LINEAR: case GL_NEAREST_MIPMAP_LINEAR:
case GL_LINEAR_MIPMAP_LINEAR: case GL_LINEAR_MIPMAP_LINEAR:
{ {
if (mMinFilter != filter) if (mSamplerState.minFilter != filter)
{ {
mMinFilter = filter; mSamplerState.minFilter = filter;
mDirtyParameters = true; mDirtyParameters = true;
} }
return true; return true;
...@@ -1366,9 +1367,9 @@ bool Texture::setMagFilter(GLenum filter) ...@@ -1366,9 +1367,9 @@ bool Texture::setMagFilter(GLenum filter)
case GL_NEAREST: case GL_NEAREST:
case GL_LINEAR: case GL_LINEAR:
{ {
if (mMagFilter != filter) if (mSamplerState.magFilter != filter)
{ {
mMagFilter = filter; mSamplerState.magFilter = filter;
mDirtyParameters = true; mDirtyParameters = true;
} }
return true; return true;
...@@ -1387,9 +1388,9 @@ bool Texture::setWrapS(GLenum wrap) ...@@ -1387,9 +1388,9 @@ bool Texture::setWrapS(GLenum wrap)
case GL_CLAMP_TO_EDGE: case GL_CLAMP_TO_EDGE:
case GL_MIRRORED_REPEAT: case GL_MIRRORED_REPEAT:
{ {
if (mWrapS != wrap) if (mSamplerState.wrapS != wrap)
{ {
mWrapS = wrap; mSamplerState.wrapS = wrap;
mDirtyParameters = true; mDirtyParameters = true;
} }
return true; return true;
...@@ -1408,9 +1409,9 @@ bool Texture::setWrapT(GLenum wrap) ...@@ -1408,9 +1409,9 @@ bool Texture::setWrapT(GLenum wrap)
case GL_CLAMP_TO_EDGE: case GL_CLAMP_TO_EDGE:
case GL_MIRRORED_REPEAT: case GL_MIRRORED_REPEAT:
{ {
if (mWrapT != wrap) if (mSamplerState.wrapT != wrap)
{ {
mWrapT = wrap; mSamplerState.wrapT = wrap;
mDirtyParameters = true; mDirtyParameters = true;
} }
return true; return true;
...@@ -1428,9 +1429,9 @@ bool Texture::setMaxAnisotropy(float textureMaxAnisotropy, float contextMaxAniso ...@@ -1428,9 +1429,9 @@ bool Texture::setMaxAnisotropy(float textureMaxAnisotropy, float contextMaxAniso
{ {
return false; return false;
} }
if (mMaxAnisotropy != textureMaxAnisotropy) if (mSamplerState.maxAnisotropy != textureMaxAnisotropy)
{ {
mMaxAnisotropy = textureMaxAnisotropy; mSamplerState.maxAnisotropy = textureMaxAnisotropy;
mDirtyParameters = true; mDirtyParameters = true;
} }
return true; return true;
...@@ -1452,27 +1453,39 @@ bool Texture::setUsage(GLenum usage) ...@@ -1452,27 +1453,39 @@ bool Texture::setUsage(GLenum usage)
GLenum Texture::getMinFilter() const GLenum Texture::getMinFilter() const
{ {
return mMinFilter; return mSamplerState.minFilter;
} }
GLenum Texture::getMagFilter() const GLenum Texture::getMagFilter() const
{ {
return mMagFilter; return mSamplerState.magFilter;
} }
GLenum Texture::getWrapS() const GLenum Texture::getWrapS() const
{ {
return mWrapS; return mSamplerState.wrapS;
} }
GLenum Texture::getWrapT() const GLenum Texture::getWrapT() const
{ {
return mWrapT; return mSamplerState.wrapT;
} }
float Texture::getMaxAnisotropy() const float Texture::getMaxAnisotropy() const
{ {
return mMaxAnisotropy; return mSamplerState.maxAnisotropy;
}
int Texture::getLodOffset()
{
TextureStorage *texture = getStorage(false);
return texture ? texture->getLodOffset() : 0;
}
void Texture::getSamplerState(SamplerState *sampler)
{
*sampler = mSamplerState;
sampler->lodOffset = getLodOffset();
} }
GLenum Texture::getUsage() const GLenum Texture::getUsage() const
...@@ -1482,7 +1495,7 @@ GLenum Texture::getUsage() const ...@@ -1482,7 +1495,7 @@ GLenum Texture::getUsage() const
bool Texture::isMipmapFiltered() const bool Texture::isMipmapFiltered() const
{ {
switch (mMinFilter) switch (mSamplerState.minFilter)
{ {
case GL_NEAREST: case GL_NEAREST:
case GL_LINEAR: case GL_LINEAR:
...@@ -1588,12 +1601,6 @@ bool Texture::isImmutable() const ...@@ -1588,12 +1601,6 @@ bool Texture::isImmutable() const
return mImmutable; return mImmutable;
} }
int Texture::getLodOffset()
{
TextureStorage *texture = getStorage(false);
return texture ? texture->getLodOffset() : 0;
}
GLint Texture::creationLevels(GLsizei width, GLsizei height) const GLint Texture::creationLevels(GLsizei width, GLsizei height) const
{ {
if ((isPow2(width) && isPow2(height)) || getContext()->supportsNonPower2Texture()) if ((isPow2(width) && isPow2(height)) || getContext()->supportsNonPower2Texture())
...@@ -2071,7 +2078,8 @@ bool Texture2D::isSamplerComplete() const ...@@ -2071,7 +2078,8 @@ bool Texture2D::isSamplerComplete() const
if ((IsFloat32Format(getInternalFormat(0)) && !getContext()->supportsFloat32LinearFilter()) || if ((IsFloat32Format(getInternalFormat(0)) && !getContext()->supportsFloat32LinearFilter()) ||
(IsFloat16Format(getInternalFormat(0)) && !getContext()->supportsFloat16LinearFilter())) (IsFloat16Format(getInternalFormat(0)) && !getContext()->supportsFloat16LinearFilter()))
{ {
if (mMagFilter != GL_NEAREST || (mMinFilter != GL_NEAREST && mMinFilter != GL_NEAREST_MIPMAP_NEAREST)) if (mSamplerState.magFilter != GL_NEAREST ||
(mSamplerState.minFilter != GL_NEAREST && mSamplerState.minFilter != GL_NEAREST_MIPMAP_NEAREST))
{ {
return false; return false;
} }
...@@ -2081,8 +2089,8 @@ bool Texture2D::isSamplerComplete() const ...@@ -2081,8 +2089,8 @@ bool Texture2D::isSamplerComplete() const
if (!npotSupport) if (!npotSupport)
{ {
if ((getWrapS() != GL_CLAMP_TO_EDGE && !isPow2(width)) || if ((mSamplerState.wrapS != GL_CLAMP_TO_EDGE && !isPow2(width)) ||
(getWrapT() != GL_CLAMP_TO_EDGE && !isPow2(height))) (mSamplerState.wrapT != GL_CLAMP_TO_EDGE && !isPow2(height)))
{ {
return false; return false;
} }
...@@ -2611,7 +2619,8 @@ bool TextureCubeMap::isSamplerComplete() const ...@@ -2611,7 +2619,8 @@ bool TextureCubeMap::isSamplerComplete() const
if ((gl::ExtractType(getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)) == GL_FLOAT && !getContext()->supportsFloat32LinearFilter()) || if ((gl::ExtractType(getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)) == GL_FLOAT && !getContext()->supportsFloat32LinearFilter()) ||
(gl::ExtractType(getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0) == GL_HALF_FLOAT_OES) && !getContext()->supportsFloat16LinearFilter())) (gl::ExtractType(getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0) == GL_HALF_FLOAT_OES) && !getContext()->supportsFloat16LinearFilter()))
{ {
if (mMagFilter != GL_NEAREST || (mMinFilter != GL_NEAREST && mMinFilter != GL_NEAREST_MIPMAP_NEAREST)) if (mSamplerState.magFilter != GL_NEAREST ||
(mSamplerState.minFilter != GL_NEAREST && mSamplerState.minFilter != GL_NEAREST_MIPMAP_NEAREST))
{ {
return false; return false;
} }
...@@ -2619,7 +2628,7 @@ bool TextureCubeMap::isSamplerComplete() const ...@@ -2619,7 +2628,7 @@ bool TextureCubeMap::isSamplerComplete() const
if (!isPow2(size) && !getContext()->supportsNonPower2Texture()) if (!isPow2(size) && !getContext()->supportsNonPower2Texture())
{ {
if (getWrapS() != GL_CLAMP_TO_EDGE || getWrapT() != GL_CLAMP_TO_EDGE || mipmapping) if (mSamplerState.wrapS != GL_CLAMP_TO_EDGE || mSamplerState.wrapT != GL_CLAMP_TO_EDGE || mipmapping)
{ {
return false; return false;
} }
......
...@@ -43,6 +43,16 @@ enum ...@@ -43,6 +43,16 @@ enum
IMPLEMENTATION_MAX_TEXTURE_LEVELS = 15 // 1+log2 of MAX_TEXTURE_SIZE IMPLEMENTATION_MAX_TEXTURE_LEVELS = 15 // 1+log2 of MAX_TEXTURE_SIZE
}; };
struct SamplerState
{
GLenum minFilter;
GLenum magFilter;
GLenum wrapS;
GLenum wrapT;
float maxAnisotropy;
int lodOffset;
};
class Image class Image
{ {
public: public:
...@@ -189,6 +199,8 @@ class Texture : public RefCountObject ...@@ -189,6 +199,8 @@ class Texture : public RefCountObject
GLenum getWrapS() const; GLenum getWrapS() const;
GLenum getWrapT() const; GLenum getWrapT() const;
float getMaxAnisotropy() const; float getMaxAnisotropy() const;
int getLodOffset();
void getSamplerState(SamplerState *sampler);
GLenum getUsage() const; GLenum getUsage() const;
bool isMipmapFiltered() const; bool isMipmapFiltered() const;
...@@ -207,7 +219,6 @@ class Texture : public RefCountObject ...@@ -207,7 +219,6 @@ class Texture : public RefCountObject
unsigned int getRenderTargetSerial(GLenum target); unsigned int getRenderTargetSerial(GLenum target);
bool isImmutable() const; bool isImmutable() const;
int getLodOffset();
static const GLuint INCOMPLETE_TEXTURE_ID = static_cast<GLuint>(-1); // Every texture takes an id at creation time. The value is arbitrary because it is never registered with the resource manager. static const GLuint INCOMPLETE_TEXTURE_ID = static_cast<GLuint>(-1); // Every texture takes an id at creation time. The value is arbitrary because it is never registered with the resource manager.
...@@ -231,11 +242,7 @@ class Texture : public RefCountObject ...@@ -231,11 +242,7 @@ class Texture : public RefCountObject
static Blit *getBlitter(); static Blit *getBlitter();
static bool copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged); static bool copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged);
GLenum mMinFilter; SamplerState mSamplerState;
GLenum mMagFilter;
GLenum mWrapS;
GLenum mWrapT;
float mMaxAnisotropy;
bool mDirtyParameters; bool mDirtyParameters;
GLenum mUsage; GLenum mUsage;
......
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