Move sampler state setting to the Renderer

Trac #21727 git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1336 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent ebf139fe
......@@ -230,6 +230,7 @@
'libGLESv2/Context.h',
'libGLESv2/D3DConstantTable.cpp',
'libGLESv2/D3DConstantTable.h',
'libGLESv2/EnumTypes.h',
'libGLESv2/Fence.cpp',
'libGLESv2/Fence.h',
'libGLESv2/Float16ToFloat32.cpp',
......
......@@ -277,7 +277,7 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
mMaxCubeTextureDimension = std::min(mMaxTextureDimension, (int)gl::IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE);
mMaxRenderbufferDimension = mMaxTextureDimension;
mMaxTextureLevel = log2(mMaxTextureDimension) + 1;
mMaxTextureAnisotropy = mRenderer->getTextureFilterAnisotropySupport();
mMaxTextureAnisotropy = mRenderer->getTextureMaxAnisotropy();
TRACE("MaxTextureDimension=%d, MaxCubeTextureDimension=%d, MaxRenderbufferDimension=%d, MaxTextureLevel=%d, MaxTextureAnisotropy=%f",
mMaxTextureDimension, mMaxCubeTextureDimension, mMaxRenderbufferDimension, mMaxTextureLevel, mMaxTextureAnisotropy);
......@@ -317,7 +317,7 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
mSupportsLuminanceTextures = mRenderer->getLuminanceTextureSupport();
mSupportsLuminanceAlphaTextures = mRenderer->getLuminanceAlphaTextureSupport();
mSupportsDepthTextures = mRenderer->getDepthTextureSupport();
mSupportsTextureFilterAnisotropy = mMaxTextureAnisotropy >= 2.0f;
mSupportsTextureFilterAnisotropy = mRenderer->getTextureFilterAnisotropySupport();
mSupports32bitIndices = mDeviceCaps.MaxVertexIndex >= (1 << 16);
......@@ -2441,20 +2441,7 @@ void Context::applyTextures(SamplerType type)
SamplerState samplerState;
texture->getSamplerState(&samplerState);
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(samplerState.magFilter, samplerState.maxAnisotropy));
D3DTEXTUREFILTERTYPE d3dMinFilter, d3dMipFilter;
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, samplerState.lodOffset);
if (supportsTextureFilterAnisotropy())
{
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXANISOTROPY, (DWORD)samplerState.maxAnisotropy);
}
mRenderer->setSamplerState(type, samplerIndex, samplerState);
}
if (appliedTextureSerial[samplerIndex] != texSerial || texture->hasDirtyImages())
......
//
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// EnumTypes.h : Defines a variety of enum types that are used throughout libGLESv2
#ifndef LIBGLESV2_ENUMTYPES_H_
#define LIBGLESV2_ENUMTYPES_H_
namespace gl
{
enum TextureType
{
TEXTURE_2D,
TEXTURE_CUBE,
TEXTURE_TYPE_COUNT,
TEXTURE_UNKNOWN
};
enum SamplerType
{
SAMPLER_PIXEL,
SAMPLER_VERTEX
};
}
#endif // LIBGLESV2_ENUMTYPES_H_
......@@ -20,6 +20,7 @@
#endif
#include "common/angleutils.h"
#include "libGLESv2/EnumTypes.h"
#include "libGLESv2/HandleAllocator.h"
namespace gl
......@@ -30,21 +31,6 @@ class Program;
class Texture;
class Renderbuffer;
enum TextureType
{
TEXTURE_2D,
TEXTURE_CUBE,
TEXTURE_TYPE_COUNT,
TEXTURE_UNKNOWN
};
enum SamplerType
{
SAMPLER_PIXEL,
SAMPLER_VERTEX
};
class ResourceManager
{
public:
......
......@@ -259,6 +259,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClInclude Include="Buffer.h" />
<ClInclude Include="Context.h" />
<ClInclude Include="D3DConstantTable.h" />
<ClInclude Include="EnumTypes.h" />
<ClInclude Include="Fence.h" />
<ClInclude Include="Framebuffer.h" />
<ClInclude Include="..\..\include\GLES2\gl2.h" />
......
......@@ -168,6 +168,9 @@ EGLint Renderer::initialize()
!(mDeviceCaps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL) &&
!(getComparableOSVersion() < versionWindowsVista && mAdapterIdentifier.VendorId == VENDOR_ID_AMD);
// Must support a minimum of 2:1 anisotropy for max anisotropy to be considered supported, per the spec
mSupportsTextureFilterAnisotropy = ((mDeviceCaps.RasterCaps & D3DPRASTERCAPS_ANISOTROPY) && (mDeviceCaps.MaxAnisotropy >= 2));
static const TCHAR windowName[] = TEXT("AngleHiddenWindow");
static const TCHAR className[] = TEXT("STATIC");
......@@ -357,6 +360,27 @@ IDirect3DPixelShader9 *Renderer::createPixelShader(const DWORD *function, size_t
return mPixelShaderCache.create(function, length);
}
void Renderer::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState)
{
int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0;
int d3dSampler = index + d3dSamplerOffset;
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(samplerState.magFilter, samplerState.maxAnisotropy));
D3DTEXTUREFILTERTYPE d3dMinFilter, d3dMipFilter;
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, samplerState.lodOffset);
if (mSupportsTextureFilterAnisotropy)
{
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXANISOTROPY, (DWORD)samplerState.maxAnisotropy);
}
}
void Renderer::releaseDeviceResources()
{
while (!mEventQueryPool.empty())
......@@ -610,10 +634,14 @@ bool Renderer::getLuminanceAlphaTextureSupport()
return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8L8));
}
float Renderer::getTextureFilterAnisotropySupport() const
bool Renderer::getTextureFilterAnisotropySupport() const
{
// Must support a minimum of 2:1 anisotropy for max anisotropy to be considered supported, per the spec
if ((mDeviceCaps.RasterCaps & D3DPRASTERCAPS_ANISOTROPY) && (mDeviceCaps.MaxAnisotropy >= 2))
return mSupportsTextureFilterAnisotropy;
}
float Renderer::getTextureMaxAnisotropy() const
{
if (mSupportsTextureFilterAnisotropy)
{
return mDeviceCaps.MaxAnisotropy;
}
......
......@@ -23,6 +23,8 @@
#include "common/angleutils.h"
#include "libGLESv2/renderer/ShaderCache.h"
#include "libGLESv2/EnumTypes.h"
#include "libGLESv2/Texture.h"
const int versionWindowsVista = MAKEWORD(0x00, 0x06);
const int versionWindows7 = MAKEWORD(0x01, 0x06);
......@@ -78,6 +80,7 @@ class Renderer
virtual void applyRenderTargets();
virtual void applyState();
#endif
virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler);
// lost device
virtual void markDeviceLost();
......@@ -108,7 +111,8 @@ class Renderer
virtual bool getDepthTextureSupport() const;
virtual bool getOcclusionQuerySupport() const;
virtual bool getInstancingSupport() const;
virtual float getTextureFilterAnisotropySupport() const;
virtual bool getTextureFilterAnisotropySupport() const;
virtual float getTextureMaxAnisotropy() const;
virtual bool getShareHandleSupport() const;
virtual D3DPOOL getBufferPool(DWORD usage) const;
......@@ -140,6 +144,7 @@ class Renderer
bool mSceneStarted;
bool mSupportsNonPower2Textures;
bool mSupportsTextureFilterAnisotropy;
// A pool of event queries that are currently unused.
std::vector<IDirect3DQuery9*> mEventQueryPool;
......
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