Merge change 2668
* changes: Add sampler support
This commit is contained in:
@@ -52,6 +52,7 @@ public class FountainView extends RSSurfaceView {
|
||||
private RenderScript.ProgramFragment mPF;
|
||||
private RenderScript.ProgramFragment mPF2;
|
||||
private RenderScript.Allocation mTexture;
|
||||
private RenderScript.Sampler mSampler;
|
||||
|
||||
private Bitmap mBackground;
|
||||
|
||||
@@ -83,6 +84,12 @@ public class FountainView extends RSSurfaceView {
|
||||
mPFS = mRS.programFragmentStoreCreate();
|
||||
mRS.contextBindProgramFragmentStore(mPFS);
|
||||
|
||||
mRS.samplerBegin();
|
||||
mRS.samplerSet(RenderScript.SamplerParam.FILTER_MAG, RenderScript.SamplerValue.LINEAR);
|
||||
mRS.samplerSet(RenderScript.SamplerParam.FILTER_MIN, RenderScript.SamplerValue.LINEAR);
|
||||
mSampler = mRS.samplerCreate();
|
||||
|
||||
|
||||
mRS.programFragmentBegin(null, null);
|
||||
mPF = mRS.programFragmentCreate();
|
||||
//mRS.contextBindProgramFragment(mPF);
|
||||
@@ -92,6 +99,7 @@ public class FountainView extends RSSurfaceView {
|
||||
mPF2 = mRS.programFragmentCreate();
|
||||
mRS.contextBindProgramFragment(mPF2);
|
||||
mPF2.bindTexture(mTexture, 0);
|
||||
mPF2.bindSampler(mSampler, 0);
|
||||
|
||||
mParams[0] = 0;
|
||||
mParams[1] = partCount;
|
||||
|
||||
@@ -38,7 +38,7 @@ public class RenderScript {
|
||||
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
* We use a class initializer to allow the native code to cache some
|
||||
* field offsets.
|
||||
*/
|
||||
@@ -49,9 +49,7 @@ public class RenderScript {
|
||||
sInitialized = false;
|
||||
try {
|
||||
System.loadLibrary("RS_jni");
|
||||
Log.e(LOG_TAG, "*** Renderscript INIT");
|
||||
_nInit();
|
||||
Log.e(LOG_TAG, "*** Renderscript INIT 3");
|
||||
sInitialized = true;
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
Log.d(LOG_TAG, "RenderScript JNI library not found!");
|
||||
@@ -126,6 +124,10 @@ public class RenderScript {
|
||||
native private void nScriptCSetScript(byte[] script, int offset, int length);
|
||||
native private int nScriptCCreate();
|
||||
|
||||
native private void nSamplerDestroy(int sampler);
|
||||
native private void nSamplerBegin();
|
||||
native private void nSamplerSet(int param, int value);
|
||||
native private int nSamplerCreate();
|
||||
|
||||
native private void nProgramFragmentStoreBegin(int in, int out);
|
||||
native private void nProgramFragmentStoreDepthFunc(int func);
|
||||
@@ -307,6 +309,34 @@ public class RenderScript {
|
||||
}
|
||||
}
|
||||
|
||||
public enum SamplerParam {
|
||||
FILTER_MIN (0),
|
||||
FILTER_MAG (1),
|
||||
WRAP_MODE_S (2),
|
||||
WRAP_MODE_T (3),
|
||||
WRAP_MODE_R (4);
|
||||
|
||||
int mID;
|
||||
SamplerParam(int id) {
|
||||
mID = id;
|
||||
}
|
||||
}
|
||||
|
||||
public enum SamplerValue {
|
||||
NEAREST (0),
|
||||
LINEAR (1),
|
||||
LINEAR_MIP_LINEAR (2),
|
||||
WRAP (3),
|
||||
CLAMP (4);
|
||||
|
||||
int mID;
|
||||
SamplerValue(int id) {
|
||||
mID = id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class Element extends BaseObj {
|
||||
Element(int id) {
|
||||
mID = id;
|
||||
@@ -727,9 +757,9 @@ public class RenderScript {
|
||||
nProgramFragmentBindTexture(mID, slot, va.mID);
|
||||
}
|
||||
|
||||
//public void bindSampler(Sampler vs, int slot) {
|
||||
//nProgramFragmentBindSampler(mID, slot, vs.mID);
|
||||
//}
|
||||
public void bindSampler(Sampler vs, int slot) {
|
||||
nProgramFragmentBindSampler(mID, slot, vs.mID);
|
||||
}
|
||||
}
|
||||
|
||||
public void programFragmentBegin(Element in, Element out) {
|
||||
@@ -761,6 +791,33 @@ public class RenderScript {
|
||||
return new ProgramFragment(id);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// Sampler
|
||||
|
||||
public class Sampler extends BaseObj {
|
||||
Sampler(int id) {
|
||||
mID = id;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
nSamplerDestroy(mID);
|
||||
mID = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void samplerBegin() {
|
||||
nSamplerBegin();
|
||||
}
|
||||
|
||||
public void samplerSet(SamplerParam p, SamplerValue v) {
|
||||
nSamplerSet(p.mID, v.mID);
|
||||
}
|
||||
|
||||
public Sampler samplerCreate() {
|
||||
int id = nSamplerCreate();
|
||||
return new Sampler(id);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Root state
|
||||
|
||||
@@ -717,14 +717,6 @@ nContextBindRootScript(JNIEnv *_env, jobject _this, jint script)
|
||||
rsContextBindRootScript((RsScript)script);
|
||||
}
|
||||
|
||||
static void
|
||||
nContextBindSampler(JNIEnv *_env, jobject _this, jint sampler, jint slot)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nContextBindSampler, con(%p), sampler(%p), slot(%i)", con, (RsSampler)sampler, slot);
|
||||
rsContextBindSampler(slot, (RsSampler)sampler);
|
||||
}
|
||||
|
||||
static void
|
||||
nContextBindProgramFragmentStore(JNIEnv *_env, jobject _this, jint pfs)
|
||||
{
|
||||
@@ -741,6 +733,40 @@ nContextBindProgramFragment(JNIEnv *_env, jobject _this, jint pf)
|
||||
rsContextBindProgramFragment((RsProgramFragment)pf);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static void
|
||||
nSamplerDestroy(JNIEnv *_env, jobject _this, jint s)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nSamplerDestroy, con(%p), sampler(%p)", con, (RsSampler)s);
|
||||
rsSamplerDestroy((RsSampler)s);
|
||||
}
|
||||
|
||||
static void
|
||||
nSamplerBegin(JNIEnv *_env, jobject _this)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nSamplerBegin, con(%p)", con);
|
||||
rsSamplerBegin();
|
||||
}
|
||||
|
||||
static void
|
||||
nSamplerSet(JNIEnv *_env, jobject _this, jint p, jint v)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nSamplerSet, con(%p), param(%i), value(%i)", con, p, v);
|
||||
rsSamplerSet((RsSamplerParam)p, (RsSamplerValue)v);
|
||||
}
|
||||
|
||||
static jint
|
||||
nSamplerCreate(JNIEnv *_env, jobject _this)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nSamplerCreate, con(%p), script(%p)", con, (RsScript)script);
|
||||
return (jint)rsSamplerCreate();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -825,10 +851,14 @@ static JNINativeMethod methods[] = {
|
||||
{"nProgramFragmentCreate", "()I", (void*)nProgramFragmentCreate },
|
||||
|
||||
{"nContextBindRootScript", "(I)V", (void*)nContextBindRootScript },
|
||||
//{"nContextBindSampler", "(II)V", (void*)nContextBindSampler },
|
||||
{"nContextBindProgramFragmentStore","(I)V", (void*)nContextBindProgramFragmentStore },
|
||||
{"nContextBindProgramFragment", "(I)V", (void*)nContextBindProgramFragment },
|
||||
|
||||
{"nSamplerDestroy", "(I)V", (void*)nSamplerDestroy },
|
||||
{"nSamplerBegin", "()V", (void*)nSamplerBegin },
|
||||
{"nSamplerSet", "(II)V", (void*)nSamplerSet },
|
||||
{"nSamplerCreate", "()I", (void*)nSamplerCreate },
|
||||
|
||||
};
|
||||
|
||||
static int registerFuncs(JNIEnv *_env)
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
|
||||
|
||||
ContextBindSampler {
|
||||
param uint32_t slot
|
||||
param RsSampler sampler
|
||||
}
|
||||
|
||||
ContextBindRootScript {
|
||||
param RsScript sampler
|
||||
}
|
||||
@@ -212,6 +207,9 @@ SamplerCreate {
|
||||
ret RsSampler
|
||||
}
|
||||
|
||||
SamplerDestroy {
|
||||
param RsSampler s
|
||||
}
|
||||
|
||||
TriangleMeshBegin {
|
||||
param RsElement vertex
|
||||
|
||||
@@ -62,14 +62,14 @@ void ProgramFragment::setupGL()
|
||||
break;
|
||||
}
|
||||
|
||||
// if (mSamplers[ct].get()) {
|
||||
//mSamplers[ct]->setupGL();
|
||||
// } else {
|
||||
if (mSamplers[ct].get()) {
|
||||
mSamplers[ct]->setupGL();
|
||||
} else {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
//}
|
||||
}
|
||||
}
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,21 @@ Sampler::~Sampler()
|
||||
|
||||
void Sampler::setupGL()
|
||||
{
|
||||
GLenum translate[] = {
|
||||
GL_NEAREST, //RS_SAMPLER_NEAREST,
|
||||
GL_LINEAR, //RS_SAMPLER_LINEAR,
|
||||
GL_LINEAR_MIP_LINEAR, //RS_SAMPLER_LINEAR_MIP_LINEAR,
|
||||
GL_WRAP, //RS_SAMPLER_WRAP,
|
||||
GL_CLAMP_TO_EDGS, //RS_SAMPLER_CLAMP
|
||||
|
||||
}
|
||||
|
||||
|
||||
//LOGE("setup gl");
|
||||
switch(mMagFilter) {
|
||||
case RS_SAMPLER_
|
||||
}
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
@@ -76,7 +90,7 @@ void Sampler::unbindFromContext(SamplerState *ss)
|
||||
|
||||
void SamplerState::setupGL()
|
||||
{
|
||||
for (uint32_t ct=0; ct < 1/*RS_MAX_SAMPLER_SLOT*/; ct++) {
|
||||
for (uint32_t ct=0; ct < RS_MAX_SAMPLER_SLOT; ct++) {
|
||||
Sampler *s = mSamplers[ct].get();
|
||||
if (s) {
|
||||
s->setupGL();
|
||||
@@ -140,4 +154,12 @@ RsSampler rsi_SamplerCreate(Context *rsc)
|
||||
return s;
|
||||
}
|
||||
|
||||
void rsi_SamplerDestroy(Context *rsc, RsSampler vs)
|
||||
{
|
||||
Sampler * s = static_cast<Sampler *>(vs);
|
||||
s->decRef();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user