summaryrefslogtreecommitdiffstats
path: root/libs/rs/rsSampler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/rs/rsSampler.cpp')
-rw-r--r--libs/rs/rsSampler.cpp125
1 files changed, 75 insertions, 50 deletions
diff --git a/libs/rs/rsSampler.cpp b/libs/rs/rsSampler.cpp
index 71f508f..54282a8 100644
--- a/libs/rs/rsSampler.cpp
+++ b/libs/rs/rsSampler.cpp
@@ -14,10 +14,16 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include <GLES/gl.h>
#include <GLES/glext.h>
-
#include "rsContext.h"
+#else
+#include "rsContextHostStub.h"
+#include <OpenGL/gl.h>
+#include <OpenGL/glext.h>
+#endif //ANDROID_RS_BUILD_FOR_HOST
+
#include "rsSampler.h"
@@ -25,10 +31,7 @@ using namespace android;
using namespace android::renderscript;
-Sampler::Sampler(Context *rsc) : ObjectBase(rsc)
-{
- mAllocFile = __FILE__;
- mAllocLine = __LINE__;
+Sampler::Sampler(Context *rsc) : ObjectBase(rsc) {
// Should not get called.
rsAssert(0);
}
@@ -38,74 +41,84 @@ Sampler::Sampler(Context *rsc,
RsSamplerValue minFilter,
RsSamplerValue wrapS,
RsSamplerValue wrapT,
- RsSamplerValue wrapR) : ObjectBase(rsc)
-{
- mAllocFile = __FILE__;
- mAllocLine = __LINE__;
+ RsSamplerValue wrapR,
+ float aniso) : ObjectBase(rsc) {
mMagFilter = magFilter;
mMinFilter = minFilter;
mWrapS = wrapS;
mWrapT = wrapT;
mWrapR = wrapR;
+ mAniso = aniso;
}
-Sampler::~Sampler()
-{
+Sampler::~Sampler() {
}
-void Sampler::setupGL(const Context *rsc, bool npot)
-{
+void Sampler::setupGL(const Context *rsc, const Allocation *tex) {
GLenum trans[] = {
GL_NEAREST, //RS_SAMPLER_NEAREST,
GL_LINEAR, //RS_SAMPLER_LINEAR,
GL_LINEAR_MIPMAP_LINEAR, //RS_SAMPLER_LINEAR_MIP_LINEAR,
GL_REPEAT, //RS_SAMPLER_WRAP,
GL_CLAMP_TO_EDGE, //RS_SAMPLER_CLAMP
+ };
+ GLenum transNP[] = {
+ GL_NEAREST, //RS_SAMPLER_NEAREST,
+ GL_LINEAR, //RS_SAMPLER_LINEAR,
+ GL_LINEAR, //RS_SAMPLER_LINEAR_MIP_LINEAR,
+ GL_CLAMP_TO_EDGE, //RS_SAMPLER_WRAP,
+ GL_CLAMP_TO_EDGE, //RS_SAMPLER_CLAMP
};
- bool forceNonMip = false;
- if (!rsc->ext_OES_texture_npot() && npot) {
- forceNonMip = true;
- }
+ // This tells us the correct texture type
+ GLenum target = (GLenum)tex->getGLTarget();
- if ((mMinFilter == RS_SAMPLER_LINEAR_MIP_LINEAR) && forceNonMip) {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ if (!rsc->ext_OES_texture_npot() && tex->getType()->getIsNp2()) {
+ if (tex->getHasGraphicsMipmaps() && rsc->ext_GL_NV_texture_npot_2D_mipmap()) {
+ glTexParameteri(target, GL_TEXTURE_MIN_FILTER, trans[mMinFilter]);
+ } else {
+ glTexParameteri(target, GL_TEXTURE_MIN_FILTER, transNP[mMinFilter]);
+ }
+ glTexParameteri(target, GL_TEXTURE_MAG_FILTER, transNP[mMagFilter]);
+ glTexParameteri(target, GL_TEXTURE_WRAP_S, transNP[mWrapS]);
+ glTexParameteri(target, GL_TEXTURE_WRAP_T, transNP[mWrapT]);
} else {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, trans[mMinFilter]);
+ if (tex->getHasGraphicsMipmaps()) {
+ glTexParameteri(target, GL_TEXTURE_MIN_FILTER, trans[mMinFilter]);
+ } else {
+ glTexParameteri(target, GL_TEXTURE_MIN_FILTER, transNP[mMinFilter]);
+ }
+ glTexParameteri(target, GL_TEXTURE_MAG_FILTER, trans[mMagFilter]);
+ glTexParameteri(target, GL_TEXTURE_WRAP_S, trans[mWrapS]);
+ glTexParameteri(target, GL_TEXTURE_WRAP_T, trans[mWrapT]);
}
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, trans[mMagFilter]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, trans[mWrapS]);
- 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(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisoValue);
+ }
- rsc->checkError("ProgramFragment::setupGL2 tex env");
+ rsc->checkError("Sampler::setupGL2 tex env");
}
-void Sampler::bindToContext(SamplerState *ss, uint32_t slot)
-{
+void Sampler::bindToContext(SamplerState *ss, uint32_t slot) {
ss->mSamplers[slot].set(this);
mBoundSlot = slot;
}
-void Sampler::unbindFromContext(SamplerState *ss)
-{
+void Sampler::unbindFromContext(SamplerState *ss) {
int32_t slot = mBoundSlot;
mBoundSlot = -1;
ss->mSamplers[slot].clear();
}
-/*
-void SamplerState::setupGL()
-{
- for (uint32_t ct=0; ct < RS_MAX_SAMPLER_SLOT; ct++) {
- Sampler *s = mSamplers[ct].get();
- if (s) {
- s->setupGL(rsc);
- } else {
- glBindTexture(GL_TEXTURE_2D, 0);
- }
- }
-}*/
+
+void Sampler::serialize(OStream *stream) const {
+}
+
+Sampler *Sampler::createFromStream(Context *rsc, IStream *stream) {
+ return NULL;
+}
////////////////////////////////
@@ -113,8 +126,7 @@ namespace android {
namespace renderscript {
-void rsi_SamplerBegin(Context *rsc)
-{
+void rsi_SamplerBegin(Context *rsc) {
SamplerState * ss = &rsc->mStateSampler;
ss->mMagFilter = RS_SAMPLER_LINEAR;
@@ -122,13 +134,13 @@ 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)
-{
+void rsi_SamplerSet(Context *rsc, RsSamplerParam param, RsSamplerValue value) {
SamplerState * ss = &rsc->mStateSampler;
- switch(param) {
+ switch (param) {
case RS_SAMPLER_MAG_FILTER:
ss->mMagFilter = value;
break;
@@ -144,24 +156,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;
}
-
}
-RsSampler rsi_SamplerCreate(Context *rsc)
-{
+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;
}
-
}}