From f5b3510c706ed1f7611760dff0c94f2111531c68 Mon Sep 17 00:00:00 2001 From: Alex Sakhartchouk Date: Thu, 30 Sep 2010 11:36:37 -0700 Subject: Adding anisotropic filtering and related samples. Change-Id: Idb173274417feb5e25bfd64c5e9fa2492a23a17e --- libs/rs/rsSampler.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'libs/rs/rsSampler.cpp') diff --git a/libs/rs/rsSampler.cpp b/libs/rs/rsSampler.cpp index c6a848c..180d78e 100644 --- a/libs/rs/rsSampler.cpp +++ b/libs/rs/rsSampler.cpp @@ -44,7 +44,8 @@ Sampler::Sampler(Context *rsc, RsSamplerValue minFilter, RsSamplerValue wrapS, RsSamplerValue wrapT, - RsSamplerValue wrapR) : ObjectBase(rsc) + RsSamplerValue wrapR, + float aniso) : ObjectBase(rsc) { mAllocFile = __FILE__; mAllocLine = __LINE__; @@ -53,6 +54,7 @@ Sampler::Sampler(Context *rsc, mWrapS = wrapS; mWrapT = wrapT; mWrapR = wrapR; + mAniso = aniso; } Sampler::~Sampler() @@ -93,6 +95,11 @@ void Sampler::setupGL(const Context *rsc, const Allocation *tex) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, trans[mWrapT]); } + float anisoValue = rsMin(rsc->ext_texture_max_aniso(), mAniso); + if(rsc->ext_texture_max_aniso() > 1.0f) { + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisoValue); + } + rsc->checkError("Sampler::setupGL2 tex env"); } @@ -147,6 +154,7 @@ void rsi_SamplerBegin(Context *rsc) ss->mWrapS = RS_SAMPLER_WRAP; ss->mWrapT = RS_SAMPLER_WRAP; ss->mWrapR = RS_SAMPLER_WRAP; + ss->mAniso = 1.0f; } void rsi_SamplerSet(Context *rsc, RsSamplerParam param, RsSamplerValue value) @@ -169,21 +177,37 @@ void rsi_SamplerSet(Context *rsc, RsSamplerParam param, RsSamplerValue value) case RS_SAMPLER_WRAP_R: ss->mWrapR = value; break; + default: + LOGE("Attempting to set invalid value on sampler"); + break; } +} + +void rsi_SamplerSet2(Context *rsc, RsSamplerParam param, float value) +{ + SamplerState * ss = &rsc->mStateSampler; + switch(param) { + case RS_SAMPLER_ANISO: + ss->mAniso = value; + break; + default: + LOGE("Attempting to set invalid value on sampler"); + break; + } } RsSampler rsi_SamplerCreate(Context *rsc) { SamplerState * ss = &rsc->mStateSampler; - Sampler * s = new Sampler(rsc, ss->mMagFilter, ss->mMinFilter, ss->mWrapS, ss->mWrapT, - ss->mWrapR); + ss->mWrapR, + ss->mAniso); s->incUserRef(); return s; } -- cgit v1.1