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
diff --git a/src/libGLESv2/Context.cpp b/src/libGLESv2/Context.cpp
index 2ad2ef1..d11ca66 100644
--- a/src/libGLESv2/Context.cpp
+++ b/src/libGLESv2/Context.cpp
@@ -2438,25 +2438,22 @@
{
if (appliedTextureSerial[samplerIndex] != texSerial || texture->hasDirtyParameters())
{
- GLenum wrapS = texture->getWrapS();
- GLenum wrapT = texture->getWrapT();
- GLenum minFilter = texture->getMinFilter();
- GLenum magFilter = texture->getMagFilter();
- float maxAnisotropy = texture->getMaxAnisotropy();
+ SamplerState samplerState;
+ texture->getSamplerState(&samplerState);
- mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSU, es2dx::ConvertTextureWrap(wrapS));
- mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSV, es2dx::ConvertTextureWrap(wrapT));
+ mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSU, es2dx::ConvertTextureWrap(samplerState.wrapS));
+ 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;
- es2dx::ConvertMinFilter(minFilter, &d3dMinFilter, &d3dMipFilter, maxAnisotropy);
+ es2dx::ConvertMinFilter(samplerState.minFilter, &d3dMinFilter, &d3dMipFilter, samplerState.maxAnisotropy);
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MINFILTER, d3dMinFilter);
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MIPFILTER, d3dMipFilter);
- mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXMIPLEVEL, texture->getLodOffset());
+ mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXMIPLEVEL, samplerState.lodOffset);
if (supportsTextureFilterAnisotropy())
{
- mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXANISOTROPY, (DWORD)maxAnisotropy);
+ mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXANISOTROPY, (DWORD)samplerState.maxAnisotropy);
}
}
diff --git a/src/libGLESv2/Texture.cpp b/src/libGLESv2/Texture.cpp
index d4d1c86..8a244ce 100644
--- a/src/libGLESv2/Texture.cpp
+++ b/src/libGLESv2/Texture.cpp
@@ -1317,13 +1317,14 @@
Texture::Texture(GLuint id) : RefCountObject(id)
{
- mMinFilter = GL_NEAREST_MIPMAP_LINEAR;
- mMagFilter = GL_LINEAR;
- mWrapS = GL_REPEAT;
- mWrapT = GL_REPEAT;
+ mSamplerState.minFilter = GL_NEAREST_MIPMAP_LINEAR;
+ mSamplerState.magFilter = GL_LINEAR;
+ mSamplerState.wrapS = GL_REPEAT;
+ mSamplerState.wrapT = GL_REPEAT;
+ mSamplerState.maxAnisotropy = 1.0f;
+ mSamplerState.lodOffset = 0;
mDirtyParameters = true;
mUsage = GL_NONE;
- mMaxAnisotropy = 1.0f;
mDirtyImages = true;
@@ -1346,9 +1347,9 @@
case GL_NEAREST_MIPMAP_LINEAR:
case GL_LINEAR_MIPMAP_LINEAR:
{
- if (mMinFilter != filter)
+ if (mSamplerState.minFilter != filter)
{
- mMinFilter = filter;
+ mSamplerState.minFilter = filter;
mDirtyParameters = true;
}
return true;
@@ -1366,9 +1367,9 @@
case GL_NEAREST:
case GL_LINEAR:
{
- if (mMagFilter != filter)
+ if (mSamplerState.magFilter != filter)
{
- mMagFilter = filter;
+ mSamplerState.magFilter = filter;
mDirtyParameters = true;
}
return true;
@@ -1387,9 +1388,9 @@
case GL_CLAMP_TO_EDGE:
case GL_MIRRORED_REPEAT:
{
- if (mWrapS != wrap)
+ if (mSamplerState.wrapS != wrap)
{
- mWrapS = wrap;
+ mSamplerState.wrapS = wrap;
mDirtyParameters = true;
}
return true;
@@ -1408,9 +1409,9 @@
case GL_CLAMP_TO_EDGE:
case GL_MIRRORED_REPEAT:
{
- if (mWrapT != wrap)
+ if (mSamplerState.wrapT != wrap)
{
- mWrapT = wrap;
+ mSamplerState.wrapT = wrap;
mDirtyParameters = true;
}
return true;
@@ -1428,9 +1429,9 @@
{
return false;
}
- if (mMaxAnisotropy != textureMaxAnisotropy)
+ if (mSamplerState.maxAnisotropy != textureMaxAnisotropy)
{
- mMaxAnisotropy = textureMaxAnisotropy;
+ mSamplerState.maxAnisotropy = textureMaxAnisotropy;
mDirtyParameters = true;
}
return true;
@@ -1452,27 +1453,39 @@
GLenum Texture::getMinFilter() const
{
- return mMinFilter;
+ return mSamplerState.minFilter;
}
GLenum Texture::getMagFilter() const
{
- return mMagFilter;
+ return mSamplerState.magFilter;
}
GLenum Texture::getWrapS() const
{
- return mWrapS;
+ return mSamplerState.wrapS;
}
GLenum Texture::getWrapT() const
{
- return mWrapT;
+ return mSamplerState.wrapT;
}
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
@@ -1482,7 +1495,7 @@
bool Texture::isMipmapFiltered() const
{
- switch (mMinFilter)
+ switch (mSamplerState.minFilter)
{
case GL_NEAREST:
case GL_LINEAR:
@@ -1588,12 +1601,6 @@
return mImmutable;
}
-int Texture::getLodOffset()
-{
- TextureStorage *texture = getStorage(false);
- return texture ? texture->getLodOffset() : 0;
-}
-
GLint Texture::creationLevels(GLsizei width, GLsizei height) const
{
if ((isPow2(width) && isPow2(height)) || getContext()->supportsNonPower2Texture())
@@ -2071,7 +2078,8 @@
if ((IsFloat32Format(getInternalFormat(0)) && !getContext()->supportsFloat32LinearFilter()) ||
(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;
}
@@ -2081,8 +2089,8 @@
if (!npotSupport)
{
- if ((getWrapS() != GL_CLAMP_TO_EDGE && !isPow2(width)) ||
- (getWrapT() != GL_CLAMP_TO_EDGE && !isPow2(height)))
+ if ((mSamplerState.wrapS != GL_CLAMP_TO_EDGE && !isPow2(width)) ||
+ (mSamplerState.wrapT != GL_CLAMP_TO_EDGE && !isPow2(height)))
{
return false;
}
@@ -2611,7 +2619,8 @@
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()))
{
- 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;
}
@@ -2619,7 +2628,7 @@
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;
}
diff --git a/src/libGLESv2/Texture.h b/src/libGLESv2/Texture.h
index deb2d05..27f2d75 100644
--- a/src/libGLESv2/Texture.h
+++ b/src/libGLESv2/Texture.h
@@ -43,6 +43,16 @@
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
{
public:
@@ -189,6 +199,8 @@
GLenum getWrapS() const;
GLenum getWrapT() const;
float getMaxAnisotropy() const;
+ int getLodOffset();
+ void getSamplerState(SamplerState *sampler);
GLenum getUsage() const;
bool isMipmapFiltered() const;
@@ -207,7 +219,6 @@
unsigned int getRenderTargetSerial(GLenum target);
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.
@@ -231,11 +242,7 @@
static Blit *getBlitter();
static bool copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged);
- GLenum mMinFilter;
- GLenum mMagFilter;
- GLenum mWrapS;
- GLenum mWrapT;
- float mMaxAnisotropy;
+ SamplerState mSamplerState;
bool mDirtyParameters;
GLenum mUsage;