Merge change 20032
* changes: Split ProgramFragment and ProgramStore from RenderScript.java. Update Element and Type to new cached builder for easier app developement.
This commit is contained in:
@@ -146,58 +146,75 @@ public class Element extends BaseObj {
|
||||
|
||||
public static class Builder {
|
||||
RenderScript mRS;
|
||||
boolean mActive = true;
|
||||
Entry[] mEntries;
|
||||
int mEntryCount;
|
||||
|
||||
Builder(RenderScript rs) {
|
||||
private class Entry {
|
||||
Element mElement;
|
||||
Element.DataType mType;
|
||||
Element.DataKind mKind;
|
||||
boolean mIsNormalized;
|
||||
int mBits;
|
||||
}
|
||||
|
||||
public Builder(RenderScript rs) {
|
||||
mRS = rs;
|
||||
mEntryCount = 0;
|
||||
mEntries = new Entry[8];
|
||||
}
|
||||
|
||||
void begin() throws IllegalStateException {
|
||||
if (mActive) {
|
||||
throw new IllegalStateException("Element builder already active.");
|
||||
void addEntry(Entry e) {
|
||||
if(mEntries.length >= mEntryCount) {
|
||||
Entry[] en = new Entry[mEntryCount + 8];
|
||||
for(int ct=0; ct < mEntries.length; ct++) {
|
||||
en[ct] = mEntries[ct];
|
||||
}
|
||||
mEntries = en;
|
||||
}
|
||||
mRS.nElementBegin();
|
||||
mActive = true;
|
||||
mEntries[mEntryCount] = e;
|
||||
mEntryCount++;
|
||||
}
|
||||
|
||||
public Builder add(Element e) throws IllegalArgumentException, IllegalStateException {
|
||||
if(!mActive) {
|
||||
throw new IllegalStateException("Element builder not active.");
|
||||
}
|
||||
public Builder add(Element e) throws IllegalArgumentException {
|
||||
if(!e.mIsPredefined) {
|
||||
throw new IllegalArgumentException("add requires a predefined Element.");
|
||||
}
|
||||
mRS.nElementAddPredefined(e.mID);
|
||||
Entry en = new Entry();
|
||||
en.mElement = e;
|
||||
addEntry(en);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits)
|
||||
throws IllegalStateException {
|
||||
if(!mActive) {
|
||||
throw new IllegalStateException("Element builder not active.");
|
||||
}
|
||||
int norm = 0;
|
||||
if (isNormalized) {
|
||||
norm = 1;
|
||||
}
|
||||
mRS.nElementAdd(dt.mID, dk.mID, norm, bits);
|
||||
public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits) {
|
||||
Entry en = new Entry();
|
||||
en.mType = dt;
|
||||
en.mKind = dk;
|
||||
en.mIsNormalized = isNormalized;
|
||||
en.mBits = bits;
|
||||
addEntry(en);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void abort() throws IllegalStateException {
|
||||
if(!mActive) {
|
||||
throw new IllegalStateException("Element builder not active.");
|
||||
static synchronized Element internalCreate(RenderScript rs, Builder b) {
|
||||
rs.nElementBegin();
|
||||
for (int ct=0; ct < b.mEntryCount; ct++) {
|
||||
Entry en = b.mEntries[ct];
|
||||
if(en.mElement != null) {
|
||||
rs.nElementAddPredefined(en.mElement.mPredefinedID);
|
||||
} else {
|
||||
int norm = 0;
|
||||
if (en.mIsNormalized) {
|
||||
norm = 1;
|
||||
}
|
||||
rs.nElementAdd(en.mType.mID, en.mKind.mID, norm, en.mBits);
|
||||
}
|
||||
}
|
||||
mActive = false;
|
||||
int id = rs.nElementCreate();
|
||||
return new Element(id, rs);
|
||||
}
|
||||
|
||||
public Element create() throws IllegalStateException {
|
||||
if(!mActive) {
|
||||
throw new IllegalStateException("Element builder not active.");
|
||||
}
|
||||
int id = mRS.nElementCreate();
|
||||
mActive = false;
|
||||
return new Element(id, mRS);
|
||||
public Element create() {
|
||||
return internalCreate(mRS, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
150
graphics/java/android/renderscript/ProgramFragment.java
Normal file
150
graphics/java/android/renderscript/ProgramFragment.java
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.renderscript;
|
||||
|
||||
|
||||
import android.util.Config;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*
|
||||
**/
|
||||
public class ProgramFragment extends BaseObj {
|
||||
public enum EnvMode {
|
||||
REPLACE (0),
|
||||
MODULATE (1),
|
||||
DECAL (2);
|
||||
|
||||
int mID;
|
||||
EnvMode(int id) {
|
||||
mID = id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ProgramFragment(int id, RenderScript rs) {
|
||||
super(rs);
|
||||
mID = id;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
mRS.nProgramFragmentStoreDestroy(mID);
|
||||
mID = 0;
|
||||
}
|
||||
|
||||
public void bindTexture(Allocation va, int slot) {
|
||||
mRS.nProgramFragmentBindTexture(mID, slot, va.mID);
|
||||
}
|
||||
|
||||
public void bindSampler(RenderScript.Sampler vs, int slot) {
|
||||
mRS.nProgramFragmentBindSampler(mID, slot, vs.mID);
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
public static final int MAX_SLOT = 2;
|
||||
RenderScript mRS;
|
||||
Element mIn;
|
||||
Element mOut;
|
||||
|
||||
private class Slot {
|
||||
Type mType;
|
||||
EnvMode mEnv;
|
||||
boolean mTexEnable;
|
||||
|
||||
Slot() {
|
||||
mTexEnable = false;
|
||||
}
|
||||
}
|
||||
Slot[] mSlots;
|
||||
|
||||
public Builder(RenderScript rs, Element in, Element out) {
|
||||
mRS = rs;
|
||||
mIn = in;
|
||||
mOut = out;
|
||||
mSlots = new Slot[MAX_SLOT];
|
||||
for(int ct=0; ct < MAX_SLOT; ct++) {
|
||||
mSlots[ct] = new Slot();
|
||||
}
|
||||
}
|
||||
|
||||
public void setType(int slot, Type t)
|
||||
throws IllegalArgumentException {
|
||||
if((slot < 0) || (slot >= MAX_SLOT)) {
|
||||
throw new IllegalArgumentException("Slot ID out of range.");
|
||||
}
|
||||
|
||||
mSlots[slot].mType = t;
|
||||
}
|
||||
|
||||
public void setTexEnable(boolean enable, int slot)
|
||||
throws IllegalArgumentException {
|
||||
if((slot < 0) || (slot >= MAX_SLOT)) {
|
||||
throw new IllegalArgumentException("Slot ID out of range.");
|
||||
}
|
||||
|
||||
mSlots[slot].mTexEnable = enable;
|
||||
}
|
||||
|
||||
public void setTexEnvMode(EnvMode env, int slot)
|
||||
throws IllegalArgumentException {
|
||||
if((slot < 0) || (slot >= MAX_SLOT)) {
|
||||
throw new IllegalArgumentException("Slot ID out of range.");
|
||||
}
|
||||
|
||||
mSlots[slot].mEnv = env;
|
||||
}
|
||||
|
||||
|
||||
static synchronized ProgramFragment internalCreate(RenderScript rs, Builder b) {
|
||||
int inID = 0;
|
||||
int outID = 0;
|
||||
if (b.mIn != null) {
|
||||
inID = b.mIn.mID;
|
||||
}
|
||||
if (b.mOut != null) {
|
||||
outID = b.mOut.mID;
|
||||
}
|
||||
rs.nProgramFragmentBegin(inID, outID);
|
||||
for(int ct=0; ct < MAX_SLOT; ct++) {
|
||||
if(b.mSlots[ct].mTexEnable) {
|
||||
Slot s = b.mSlots[ct];
|
||||
if(s.mType != null) {
|
||||
rs.nProgramFragmentSetType(ct, s.mType.mID);
|
||||
}
|
||||
rs.nProgramFragmentSetTexEnable(ct, true);
|
||||
if(s.mEnv != null) {
|
||||
rs.nProgramFragmentSetEnvMode(ct, s.mEnv.mID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int id = rs.nProgramFragmentCreate();
|
||||
return new ProgramFragment(id, rs);
|
||||
}
|
||||
|
||||
public ProgramFragment create() {
|
||||
return internalCreate(mRS, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
178
graphics/java/android/renderscript/ProgramStore.java
Normal file
178
graphics/java/android/renderscript/ProgramStore.java
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.renderscript;
|
||||
|
||||
|
||||
import android.util.Config;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*
|
||||
**/
|
||||
public class ProgramStore extends BaseObj {
|
||||
public enum DepthFunc {
|
||||
ALWAYS (0),
|
||||
LESS (1),
|
||||
LEQUAL (2),
|
||||
GREATER (3),
|
||||
GEQUAL (4),
|
||||
EQUAL (5),
|
||||
NOTEQUAL (6);
|
||||
|
||||
int mID;
|
||||
DepthFunc(int id) {
|
||||
mID = id;
|
||||
}
|
||||
}
|
||||
|
||||
public enum BlendSrcFunc {
|
||||
ZERO (0),
|
||||
ONE (1),
|
||||
DST_COLOR (2),
|
||||
ONE_MINUS_DST_COLOR (3),
|
||||
SRC_ALPHA (4),
|
||||
ONE_MINUS_SRC_ALPHA (5),
|
||||
DST_ALPHA (6),
|
||||
ONE_MINUS_DST_ALPA (7),
|
||||
SRC_ALPHA_SATURATE (8);
|
||||
|
||||
int mID;
|
||||
BlendSrcFunc(int id) {
|
||||
mID = id;
|
||||
}
|
||||
}
|
||||
|
||||
public enum BlendDstFunc {
|
||||
ZERO (0),
|
||||
ONE (1),
|
||||
SRC_COLOR (2),
|
||||
ONE_MINUS_SRC_COLOR (3),
|
||||
SRC_ALPHA (4),
|
||||
ONE_MINUS_SRC_ALPHA (5),
|
||||
DST_ALPHA (6),
|
||||
ONE_MINUS_DST_ALPA (7);
|
||||
|
||||
int mID;
|
||||
BlendDstFunc(int id) {
|
||||
mID = id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ProgramStore(int id, RenderScript rs) {
|
||||
super(rs);
|
||||
mID = id;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
mRS.nProgramFragmentStoreDestroy(mID);
|
||||
mID = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class Builder {
|
||||
RenderScript mRS;
|
||||
Element mIn;
|
||||
Element mOut;
|
||||
DepthFunc mDepthFunc;
|
||||
boolean mDepthMask;
|
||||
boolean mColorMaskR;
|
||||
boolean mColorMaskG;
|
||||
boolean mColorMaskB;
|
||||
boolean mColorMaskA;
|
||||
BlendSrcFunc mBlendSrc;
|
||||
BlendDstFunc mBlendDst;
|
||||
boolean mDither;
|
||||
|
||||
|
||||
|
||||
public Builder(RenderScript rs, Element in, Element out) {
|
||||
mRS = rs;
|
||||
mIn = in;
|
||||
mOut = out;
|
||||
mDepthFunc = DepthFunc.ALWAYS;
|
||||
mDepthMask = false;
|
||||
mColorMaskR = true;
|
||||
mColorMaskG = true;
|
||||
mColorMaskB = true;
|
||||
mColorMaskA = true;
|
||||
mBlendSrc = BlendSrcFunc.ONE;
|
||||
mBlendDst = BlendDstFunc.ZERO;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void setDepthFunc(DepthFunc func) {
|
||||
mDepthFunc = func;
|
||||
}
|
||||
|
||||
public void setDepthMask(boolean enable) {
|
||||
mDepthMask = enable;
|
||||
}
|
||||
|
||||
public void setColorMask(boolean r, boolean g, boolean b, boolean a) {
|
||||
mColorMaskR = r;
|
||||
mColorMaskG = g;
|
||||
mColorMaskB = b;
|
||||
mColorMaskA = a;
|
||||
}
|
||||
|
||||
public void setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) {
|
||||
mBlendSrc = src;
|
||||
mBlendDst = dst;
|
||||
}
|
||||
|
||||
public void setDitherEnable(boolean enable) {
|
||||
mDither = enable;
|
||||
}
|
||||
|
||||
static synchronized ProgramStore internalCreate(RenderScript rs, Builder b) {
|
||||
int inID = 0;
|
||||
int outID = 0;
|
||||
if (b.mIn != null) {
|
||||
inID = b.mIn.mID;
|
||||
}
|
||||
if (b.mOut != null) {
|
||||
outID = b.mOut.mID;
|
||||
}
|
||||
rs.nProgramFragmentStoreBegin(inID, outID);
|
||||
rs.nProgramFragmentStoreDepthFunc(b.mDepthFunc.mID);
|
||||
rs.nProgramFragmentStoreDepthMask(b.mDepthMask);
|
||||
rs.nProgramFragmentStoreColorMask(b.mColorMaskR,
|
||||
b.mColorMaskG,
|
||||
b.mColorMaskB,
|
||||
b.mColorMaskA);
|
||||
rs.nProgramFragmentStoreBlendFunc(b.mBlendSrc.mID, b.mBlendDst.mID);
|
||||
rs.nProgramFragmentStoreDither(b.mDither);
|
||||
|
||||
int id = rs.nProgramFragmentStoreCreate();
|
||||
return new ProgramStore(id, rs);
|
||||
}
|
||||
|
||||
public ProgramStore create() {
|
||||
return internalCreate(mRS, this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -128,12 +128,13 @@ public class RenderScript {
|
||||
native int nAdapter2DCreate();
|
||||
|
||||
native void nScriptDestroy(int script);
|
||||
native void nScriptBindAllocation(int vtm, int alloc, int slot);
|
||||
native void nScriptBindAllocation(int script, int alloc, int slot);
|
||||
native void nScriptSetClearColor(int script, float r, float g, float b, float a);
|
||||
native void nScriptSetClearDepth(int script, float depth);
|
||||
native void nScriptSetClearStencil(int script, int stencil);
|
||||
native void nScriptSetTimeZone(int script, byte[] timeZone);
|
||||
|
||||
native void nScriptCBegin();
|
||||
native void nScriptCSetClearColor(float r, float g, float b, float a);
|
||||
native void nScriptCSetClearDepth(float depth);
|
||||
native void nScriptCSetClearStencil(int stencil);
|
||||
native void nScriptCSetTimeZone(byte[] timeZone);
|
||||
native void nScriptCAddType(int type);
|
||||
native void nScriptCSetRoot(boolean isRoot);
|
||||
native void nScriptCSetScript(byte[] script, int offset, int length);
|
||||
@@ -203,77 +204,6 @@ public class RenderScript {
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// Element
|
||||
|
||||
Element.Builder mElementBuilder = new Element.Builder(this);
|
||||
public Element.Builder elementBuilderCreate() throws IllegalStateException {
|
||||
mElementBuilder.begin();
|
||||
return mElementBuilder;
|
||||
}
|
||||
|
||||
Type.Builder mTypeBuilder = new Type.Builder(this);
|
||||
public Type.Builder typeBuilderCreate(Element e) throws IllegalStateException {
|
||||
mTypeBuilder.begin(e);
|
||||
return mTypeBuilder;
|
||||
}
|
||||
|
||||
|
||||
public enum DepthFunc {
|
||||
ALWAYS (0),
|
||||
LESS (1),
|
||||
LEQUAL (2),
|
||||
GREATER (3),
|
||||
GEQUAL (4),
|
||||
EQUAL (5),
|
||||
NOTEQUAL (6);
|
||||
|
||||
int mID;
|
||||
DepthFunc(int id) {
|
||||
mID = id;
|
||||
}
|
||||
}
|
||||
|
||||
public enum BlendSrcFunc {
|
||||
ZERO (0),
|
||||
ONE (1),
|
||||
DST_COLOR (2),
|
||||
ONE_MINUS_DST_COLOR (3),
|
||||
SRC_ALPHA (4),
|
||||
ONE_MINUS_SRC_ALPHA (5),
|
||||
DST_ALPHA (6),
|
||||
ONE_MINUS_DST_ALPA (7),
|
||||
SRC_ALPHA_SATURATE (8);
|
||||
|
||||
int mID;
|
||||
BlendSrcFunc(int id) {
|
||||
mID = id;
|
||||
}
|
||||
}
|
||||
|
||||
public enum BlendDstFunc {
|
||||
ZERO (0),
|
||||
ONE (1),
|
||||
SRC_COLOR (2),
|
||||
ONE_MINUS_SRC_COLOR (3),
|
||||
SRC_ALPHA (4),
|
||||
ONE_MINUS_SRC_ALPHA (5),
|
||||
DST_ALPHA (6),
|
||||
ONE_MINUS_DST_ALPA (7);
|
||||
|
||||
int mID;
|
||||
BlendDstFunc(int id) {
|
||||
mID = id;
|
||||
}
|
||||
}
|
||||
|
||||
public enum EnvMode {
|
||||
REPLACE (0),
|
||||
MODULATE (1),
|
||||
DECAL (2);
|
||||
|
||||
int mID;
|
||||
EnvMode(int id) {
|
||||
mID = id;
|
||||
}
|
||||
}
|
||||
|
||||
public enum SamplerParam {
|
||||
FILTER_MIN (0),
|
||||
@@ -402,111 +332,9 @@ public class RenderScript {
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// ProgramFragmentStore
|
||||
|
||||
public class ProgramFragmentStore extends BaseObj {
|
||||
ProgramFragmentStore(int id) {
|
||||
super(RenderScript.this);
|
||||
mID = id;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
nProgramFragmentStoreDestroy(mID);
|
||||
mID = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void programFragmentStoreBegin(Element in, Element out) {
|
||||
int inID = 0;
|
||||
int outID = 0;
|
||||
if (in != null) {
|
||||
inID = in.mID;
|
||||
}
|
||||
if (out != null) {
|
||||
outID = out.mID;
|
||||
}
|
||||
nProgramFragmentStoreBegin(inID, outID);
|
||||
}
|
||||
|
||||
public void programFragmentStoreDepthFunc(DepthFunc func) {
|
||||
nProgramFragmentStoreDepthFunc(func.mID);
|
||||
}
|
||||
|
||||
public void programFragmentStoreDepthMask(boolean enable) {
|
||||
nProgramFragmentStoreDepthMask(enable);
|
||||
}
|
||||
|
||||
public void programFragmentStoreColorMask(boolean r, boolean g, boolean b, boolean a) {
|
||||
nProgramFragmentStoreColorMask(r,g,b,a);
|
||||
}
|
||||
|
||||
public void programFragmentStoreBlendFunc(BlendSrcFunc src, BlendDstFunc dst) {
|
||||
nProgramFragmentStoreBlendFunc(src.mID, dst.mID);
|
||||
}
|
||||
|
||||
public void programFragmentStoreDitherEnable(boolean enable) {
|
||||
nProgramFragmentStoreDither(enable);
|
||||
}
|
||||
|
||||
public ProgramFragmentStore programFragmentStoreCreate() {
|
||||
int id = nProgramFragmentStoreCreate();
|
||||
return new ProgramFragmentStore(id);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// ProgramFragment
|
||||
|
||||
public class ProgramFragment extends BaseObj {
|
||||
ProgramFragment(int id) {
|
||||
super(RenderScript.this);
|
||||
mID = id;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
nProgramFragmentDestroy(mID);
|
||||
mID = 0;
|
||||
}
|
||||
|
||||
public void bindTexture(Allocation va, int slot) {
|
||||
nProgramFragmentBindTexture(mID, slot, va.mID);
|
||||
}
|
||||
|
||||
public void bindSampler(Sampler vs, int slot) {
|
||||
nProgramFragmentBindSampler(mID, slot, vs.mID);
|
||||
}
|
||||
}
|
||||
|
||||
public void programFragmentBegin(Element in, Element out) {
|
||||
int inID = 0;
|
||||
int outID = 0;
|
||||
if (in != null) {
|
||||
inID = in.mID;
|
||||
}
|
||||
if (out != null) {
|
||||
outID = out.mID;
|
||||
}
|
||||
nProgramFragmentBegin(inID, outID);
|
||||
}
|
||||
|
||||
public void programFragmentSetType(int slot, Type t) {
|
||||
nProgramFragmentSetType(slot, t.mID);
|
||||
}
|
||||
|
||||
public void programFragmentSetType(int slot, EnvMode t) {
|
||||
nProgramFragmentSetEnvMode(slot, t.mID);
|
||||
}
|
||||
|
||||
public void programFragmentSetTexEnable(int slot, boolean enable) {
|
||||
nProgramFragmentSetTexEnable(slot, enable);
|
||||
}
|
||||
|
||||
public void programFragmentSetTexEnvMode(int slot, EnvMode env) {
|
||||
nProgramFragmentSetEnvMode(slot, env.mID);
|
||||
}
|
||||
|
||||
public ProgramFragment programFragmentCreate() {
|
||||
int id = nProgramFragmentCreate();
|
||||
return new ProgramFragment(id);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// Sampler
|
||||
|
||||
@@ -617,7 +445,7 @@ public class RenderScript {
|
||||
//nContextBindSampler(s.mID);
|
||||
//}
|
||||
|
||||
public void contextBindProgramFragmentStore(ProgramFragmentStore pfs) {
|
||||
public void contextBindProgramFragmentStore(ProgramStore pfs) {
|
||||
nContextBindProgramFragmentStore(pfs.mID);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,22 +37,28 @@ public class Script extends BaseObj {
|
||||
}
|
||||
|
||||
public void setClearColor(float r, float g, float b, float a) {
|
||||
//mRS.nScriptCSetClearColor(r, g, b, a);
|
||||
mRS.nScriptSetClearColor(mID, r, g, b, a);
|
||||
}
|
||||
|
||||
public void setClearDepth(float d) {
|
||||
//mRS.nScriptCSetClearDepth(d);
|
||||
mRS.nScriptSetClearDepth(mID, d);
|
||||
}
|
||||
|
||||
public void setClearStencil(int stencil) {
|
||||
//mRS.nScriptCSetClearStencil(stencil);
|
||||
mRS.nScriptSetClearStencil(mID, stencil);
|
||||
}
|
||||
|
||||
public void setTimeZone(String timeZone) {
|
||||
try {
|
||||
mRS.nScriptSetTimeZone(mID, timeZone.getBytes("UTF-8"));
|
||||
} catch (java.io.UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
RenderScript mRS;
|
||||
boolean mIsRoot = false;
|
||||
byte[] mTimeZone;
|
||||
|
||||
Builder(RenderScript rs) {
|
||||
mRS = rs;
|
||||
@@ -63,9 +69,6 @@ public class Script extends BaseObj {
|
||||
}
|
||||
|
||||
void transferCreate() {
|
||||
if(mTimeZone != null) {
|
||||
mRS.nScriptCSetTimeZone(mTimeZone);
|
||||
}
|
||||
mRS.nScriptCSetRoot(mIsRoot);
|
||||
}
|
||||
|
||||
@@ -73,14 +76,6 @@ public class Script extends BaseObj {
|
||||
s.mIsRoot = mIsRoot;
|
||||
}
|
||||
|
||||
public void setTimeZone(String timeZone) {
|
||||
try {
|
||||
mTimeZone = timeZone.getBytes("UTF-8");
|
||||
} catch (java.io.UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRoot(boolean r) {
|
||||
mIsRoot = r;
|
||||
}
|
||||
|
||||
@@ -45,23 +45,47 @@ public class Type extends BaseObj {
|
||||
|
||||
public static class Builder {
|
||||
RenderScript mRS;
|
||||
boolean mActive = true;
|
||||
Entry[] mEntries;
|
||||
int mEntryCount;
|
||||
Element mElement;
|
||||
|
||||
Builder(RenderScript rs) {
|
||||
mRS = rs;
|
||||
class Entry {
|
||||
Dimension mDim;
|
||||
int mValue;
|
||||
}
|
||||
|
||||
public void begin(Element e) {
|
||||
mRS.nTypeBegin(e.mID);
|
||||
public Builder(RenderScript rs, Element e) {
|
||||
mRS = rs;
|
||||
mEntries = new Entry[4];
|
||||
mElement = e;
|
||||
}
|
||||
|
||||
public void add(Dimension d, int value) {
|
||||
mRS.nTypeAdd(d.mID, value);
|
||||
if(mEntries.length >= mEntryCount) {
|
||||
Entry[] en = new Entry[mEntryCount + 8];
|
||||
for(int ct=0; ct < mEntries.length; ct++) {
|
||||
en[ct] = mEntries[ct];
|
||||
}
|
||||
mEntries = en;
|
||||
}
|
||||
mEntries[mEntryCount] = new Entry();
|
||||
mEntries[mEntryCount].mDim = d;
|
||||
mEntries[mEntryCount].mValue = value;
|
||||
mEntryCount++;
|
||||
}
|
||||
|
||||
static synchronized Type internalCreate(RenderScript rs, Builder b) {
|
||||
rs.nTypeBegin(b.mElement.mID);
|
||||
for (int ct=0; ct < b.mEntryCount; ct++) {
|
||||
Entry en = b.mEntries[ct];
|
||||
rs.nTypeAdd(en.mDim.mID, en.mValue);
|
||||
}
|
||||
int id = rs.nTypeCreate();
|
||||
return new Type(id, rs);
|
||||
}
|
||||
|
||||
public Type create() {
|
||||
int id = mRS.nTypeCreate();
|
||||
return new Type(id, mRS);
|
||||
return internalCreate(mRS, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -647,54 +647,56 @@ nScriptBindAllocation(JNIEnv *_env, jobject _this, jint script, jint alloc, jint
|
||||
}
|
||||
|
||||
static void
|
||||
nScriptCBegin(JNIEnv *_env, jobject _this)
|
||||
nScriptSetClearColor(JNIEnv *_env, jobject _this, jint script, jfloat r, jfloat g, jfloat b, jfloat a)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nScriptCBegin, con(%p)", con);
|
||||
rsScriptCBegin();
|
||||
LOG_API("nScriptSetClearColor, con(%p), s(%p), r(%f), g(%f), b(%f), a(%f)", con, script, r, g, b, a);
|
||||
rsScriptSetClearColor((RsScript)script, r, g, b, a);
|
||||
}
|
||||
|
||||
static void
|
||||
nScriptCSetClearColor(JNIEnv *_env, jobject _this, jfloat r, jfloat g, jfloat b, jfloat a)
|
||||
nScriptSetClearDepth(JNIEnv *_env, jobject _this, jint script, jfloat d)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nScriptCSetClearColor, con(%p), r(%f), g(%f), b(%f), a(%f)", con, r, g, b, a);
|
||||
rsScriptCSetClearColor(r, g, b, a);
|
||||
LOG_API("nScriptCSetClearDepth, con(%p), s(%p), depth(%f)", con, script, d);
|
||||
rsScriptSetClearDepth((RsScript)script, d);
|
||||
}
|
||||
|
||||
static void
|
||||
nScriptCSetClearDepth(JNIEnv *_env, jobject _this, jfloat d)
|
||||
nScriptSetClearStencil(JNIEnv *_env, jobject _this, jint script, jint stencil)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nScriptCSetClearDepth, con(%p), depth(%f)", con, d);
|
||||
rsScriptCSetClearDepth(d);
|
||||
LOG_API("nScriptCSetClearStencil, con(%p), s(%p), stencil(%i)", con, script, stencil);
|
||||
rsScriptSetClearStencil((RsScript)script, stencil);
|
||||
}
|
||||
|
||||
static void
|
||||
nScriptCSetClearStencil(JNIEnv *_env, jobject _this, jint stencil)
|
||||
nScriptSetTimeZone(JNIEnv *_env, jobject _this, jint script, jbyteArray timeZone)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nScriptCSetClearStencil, con(%p), stencil(%i)", con, stencil);
|
||||
rsScriptCSetClearStencil(stencil);
|
||||
}
|
||||
|
||||
static void
|
||||
nScriptCSetTimeZone(JNIEnv *_env, jobject _this, jbyteArray timeZone)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nScriptCSetTimeZone, con(%p), timeZone(%s)", con, timeZone);
|
||||
LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, script, timeZone);
|
||||
|
||||
jint length = _env->GetArrayLength(timeZone);
|
||||
jbyte* timeZone_ptr;
|
||||
timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
|
||||
|
||||
rsScriptCSetTimeZone((const char *)timeZone_ptr, length);
|
||||
rsScriptSetTimeZone((RsScript)script, (const char *)timeZone_ptr, length);
|
||||
|
||||
if (timeZone_ptr) {
|
||||
_env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
|
||||
static void
|
||||
nScriptCBegin(JNIEnv *_env, jobject _this)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nScriptCBegin, con(%p)", con);
|
||||
rsScriptCBegin();
|
||||
}
|
||||
|
||||
static void
|
||||
nScriptCAddType(JNIEnv *_env, jobject _this, jint type)
|
||||
{
|
||||
@@ -1154,11 +1156,12 @@ static JNINativeMethod methods[] = {
|
||||
|
||||
{"nScriptDestroy", "(I)V", (void*)nScriptDestroy },
|
||||
{"nScriptBindAllocation", "(III)V", (void*)nScriptBindAllocation },
|
||||
{"nScriptSetClearColor", "(IFFFF)V", (void*)nScriptSetClearColor },
|
||||
{"nScriptSetClearDepth", "(IF)V", (void*)nScriptSetClearDepth },
|
||||
{"nScriptSetClearStencil", "(II)V", (void*)nScriptSetClearStencil },
|
||||
{"nScriptSetTimeZone", "(I[B)V", (void*)nScriptSetTimeZone },
|
||||
|
||||
{"nScriptCBegin", "()V", (void*)nScriptCBegin },
|
||||
{"nScriptCSetClearColor", "(FFFF)V", (void*)nScriptCSetClearColor },
|
||||
{"nScriptCSetClearDepth", "(F)V", (void*)nScriptCSetClearDepth },
|
||||
{"nScriptCSetClearStencil", "(I)V", (void*)nScriptCSetClearStencil },
|
||||
{"nScriptCSetTimeZone", "([B)V", (void*)nScriptCSetTimeZone },
|
||||
{"nScriptCAddType", "(I)V", (void*)nScriptCAddType },
|
||||
{"nScriptCSetRoot", "(Z)V", (void*)nScriptCSetRoot },
|
||||
{"nScriptCSetScript", "([BII)V", (void*)nScriptCSetScript },
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#pragma version(1)
|
||||
#pragma stateVertex(PVBackground)
|
||||
#pragma stateFragment(PFBackground)
|
||||
#pragma stateFragmentStore(PFSBackground)
|
||||
#pragma stateFragmentStore(PSBackground)
|
||||
|
||||
/*
|
||||
typedef struct FilmScriptUserEnvRec {
|
||||
@@ -29,16 +29,15 @@ typedef struct FilmScriptUserEnvRec {
|
||||
|
||||
int main(int index)
|
||||
{
|
||||
int f1,f2,f3,f4, f5,f6,f7,f8, f9,f10,f11,f12, f13,f14,f15,f16;
|
||||
int g1,g2,g3,g4, g5,g6,g7,g8, g9,g10,g11,g12, g13,g14,g15,g16;
|
||||
float mat1[16];
|
||||
|
||||
float trans = loadF(1, POS_TRANSLATE);
|
||||
float rot = loadF(1, POS_ROTATE);
|
||||
matrixLoadScale(&f16, 2.f, 2.f, 2.f);
|
||||
matrixTranslate(&f16, 0.f, 0.f, trans);
|
||||
matrixRotate(&f16, 90.f, 0.f, 0.f, 1.f);
|
||||
matrixRotate(&f16, rot, 1.f, 0.f, 0.f);
|
||||
storeMatrix(3, 0, &f16);
|
||||
matrixLoadScale(mat1, 2.f, 2.f, 2.f);
|
||||
matrixTranslate(mat1, 0.f, 0.f, trans);
|
||||
matrixRotate(mat1, 90.f, 0.f, 0.f, 1.f);
|
||||
matrixRotate(mat1, rot, 1.f, 0.f, 0.f);
|
||||
storeMatrix(3, 0, mat1);
|
||||
|
||||
//materialDiffuse(con, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||
//materialSpecular(con, 0.5f, 0.5f, 0.5f, 0.5f);
|
||||
@@ -47,7 +46,7 @@ int main(int index)
|
||||
|
||||
|
||||
// Start of images.
|
||||
bindProgramFragmentStore(NAMED_PFSImages);
|
||||
bindProgramFragmentStore(NAMED_PSImages);
|
||||
bindProgramFragment(NAMED_PFImages);
|
||||
bindProgramVertex(NAMED_PVImages);
|
||||
|
||||
@@ -108,8 +107,8 @@ int main(int index)
|
||||
}
|
||||
|
||||
bindTexture(NAMED_PFImages, 0, loadI32(0, imgId - 1));
|
||||
matrixLoadTranslate(&f16, -pos - loadF(5, triangleOffsetsCount / 2), 0, 0);
|
||||
vpLoadTextureMatrix(&f16);
|
||||
matrixLoadTranslate(mat1, -pos - loadF(5, triangleOffsetsCount / 2), 0, 0);
|
||||
vpLoadTextureMatrix(mat1);
|
||||
drawTriangleMeshRange(NAMED_mesh, loadI32(4, start), loadI32(4, end) - loadI32(4, start));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ import android.renderscript.Allocation;
|
||||
import android.renderscript.Dimension;
|
||||
import android.renderscript.ScriptC;
|
||||
import android.renderscript.Script;
|
||||
import android.renderscript.ProgramFragment;
|
||||
import android.renderscript.ProgramStore;
|
||||
|
||||
public class FilmRS {
|
||||
private final int POS_TRANSLATE = 0;
|
||||
@@ -73,10 +75,10 @@ public class FilmRS {
|
||||
private Element mElementVertex;
|
||||
private Element mElementIndex;
|
||||
private RenderScript.Sampler mSampler;
|
||||
private RenderScript.ProgramFragmentStore mPFSBackground;
|
||||
private RenderScript.ProgramFragmentStore mPFSImages;
|
||||
private RenderScript.ProgramFragment mPFBackground;
|
||||
private RenderScript.ProgramFragment mPFImages;
|
||||
private ProgramStore mPSBackground;
|
||||
private ProgramStore mPSImages;
|
||||
private ProgramFragment mPFBackground;
|
||||
private ProgramFragment mPFImages;
|
||||
private RenderScript.ProgramVertex mPVBackground;
|
||||
private RenderScript.ProgramVertex mPVImages;
|
||||
private ProgramVertexAlloc mPVA;
|
||||
@@ -99,21 +101,21 @@ public class FilmRS {
|
||||
private int[] mBufferState;
|
||||
|
||||
private void initPFS() {
|
||||
mRS.programFragmentStoreBegin(null, null);
|
||||
mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.LESS);
|
||||
mRS.programFragmentStoreDitherEnable(true);
|
||||
mRS.programFragmentStoreDepthMask(true);
|
||||
mPFSBackground = mRS.programFragmentStoreCreate();
|
||||
mPFSBackground.setName("PFSBackground");
|
||||
ProgramStore.Builder b = new ProgramStore.Builder(mRS, null, null);
|
||||
|
||||
mRS.programFragmentStoreBegin(null, null);
|
||||
mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.EQUAL);
|
||||
mRS.programFragmentStoreDitherEnable(false);
|
||||
mRS.programFragmentStoreDepthMask(false);
|
||||
mRS.programFragmentStoreBlendFunc(RenderScript.BlendSrcFunc.ONE,
|
||||
RenderScript.BlendDstFunc.ONE);
|
||||
mPFSImages = mRS.programFragmentStoreCreate();
|
||||
mPFSImages.setName("PFSImages");
|
||||
b.setDepthFunc(ProgramStore.DepthFunc.LESS);
|
||||
b.setDitherEnable(true);
|
||||
b.setDepthMask(true);
|
||||
mPSBackground = b.create();
|
||||
mPSBackground.setName("PSBackground");
|
||||
|
||||
b.setDepthFunc(ProgramStore.DepthFunc.EQUAL);
|
||||
b.setDitherEnable(false);
|
||||
b.setDepthMask(false);
|
||||
b.setBlendFunc(ProgramStore.BlendSrcFunc.ONE,
|
||||
ProgramStore.BlendDstFunc.ONE);
|
||||
mPSImages = b.create();
|
||||
mPSImages.setName("PSImages");
|
||||
}
|
||||
|
||||
private void initPF() {
|
||||
@@ -128,15 +130,14 @@ public class FilmRS {
|
||||
RenderScript.SamplerValue.WRAP);
|
||||
mSampler = mRS.samplerCreate();
|
||||
|
||||
ProgramFragment.Builder b = new ProgramFragment.Builder(mRS, null, null);
|
||||
|
||||
mRS.programFragmentBegin(null, null);
|
||||
mPFBackground = mRS.programFragmentCreate();
|
||||
mPFBackground = b.create();
|
||||
mPFBackground.setName("PFBackground");
|
||||
|
||||
mRS.programFragmentBegin(null, null);
|
||||
mRS.programFragmentSetTexEnable(0, true);
|
||||
mRS.programFragmentSetTexEnvMode(0, RenderScript.EnvMode.REPLACE);
|
||||
mPFImages = mRS.programFragmentCreate();
|
||||
b.setTexEnable(true, 0);
|
||||
b.setTexEnvMode(ProgramFragment.EnvMode.REPLACE, 0);
|
||||
mPFImages = b.create();
|
||||
mPFImages.bindSampler(mSampler, 0);
|
||||
mPFImages.setName("PFImages");
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ import android.renderscript.Element;
|
||||
import android.renderscript.Allocation;
|
||||
import android.renderscript.Script;
|
||||
import android.renderscript.ScriptC;
|
||||
import android.renderscript.ProgramFragment;
|
||||
import android.renderscript.ProgramStore;
|
||||
|
||||
public class FountainRS {
|
||||
|
||||
@@ -60,8 +62,8 @@ public class FountainRS {
|
||||
private Allocation mPartAlloc;
|
||||
private Allocation mVertAlloc;
|
||||
private Script mScript;
|
||||
private RenderScript.ProgramFragmentStore mPFS;
|
||||
private RenderScript.ProgramFragment mPF;
|
||||
private ProgramStore mPFS;
|
||||
private ProgramFragment mPF;
|
||||
|
||||
private Bitmap mBackground;
|
||||
|
||||
@@ -75,16 +77,16 @@ public class FountainRS {
|
||||
mPartAlloc.setName("PartBuffer");
|
||||
mVertAlloc = Allocation.createSized(mRS, Element.USER_I32, partCount * 5 + 1);
|
||||
|
||||
mRS.programFragmentStoreBegin(null, null);
|
||||
mRS.programFragmentStoreBlendFunc(RenderScript.BlendSrcFunc.SRC_ALPHA, RenderScript.BlendDstFunc.ONE);
|
||||
mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.ALWAYS);
|
||||
mRS.programFragmentStoreDepthMask(false);
|
||||
mRS.programFragmentStoreDitherEnable(false);
|
||||
mPFS = mRS.programFragmentStoreCreate();
|
||||
ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null);
|
||||
bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, ProgramStore.BlendDstFunc.ONE);
|
||||
bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
|
||||
bs.setDepthMask(false);
|
||||
bs.setDitherEnable(false);
|
||||
mPFS = bs.create();
|
||||
mPFS.setName("PFSBlend");
|
||||
|
||||
mRS.programFragmentBegin(null, null);
|
||||
mPF = mRS.programFragmentCreate();
|
||||
ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null);
|
||||
mPF = bf.create();
|
||||
mPF.setName("PgmFragParts");
|
||||
|
||||
mParams[0] = 0;
|
||||
|
||||
@@ -19,11 +19,13 @@ package com.android.grass.rs;
|
||||
import android.content.res.Resources;
|
||||
import static android.renderscript.RenderScript.SamplerParam.*;
|
||||
import static android.renderscript.RenderScript.SamplerValue.*;
|
||||
import static android.renderscript.RenderScript.EnvMode.*;
|
||||
import static android.renderscript.RenderScript.DepthFunc.*;
|
||||
import static android.renderscript.RenderScript.BlendSrcFunc;
|
||||
import static android.renderscript.RenderScript.BlendDstFunc;
|
||||
import static android.renderscript.ProgramFragment.EnvMode.*;
|
||||
import static android.renderscript.ProgramStore.DepthFunc.*;
|
||||
import static android.renderscript.ProgramStore.BlendSrcFunc;
|
||||
import static android.renderscript.ProgramStore.BlendDstFunc;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.ProgramFragment;
|
||||
import android.renderscript.ProgramStore;
|
||||
import android.renderscript.Allocation;
|
||||
import android.renderscript.ProgramVertexAlloc;
|
||||
import static android.renderscript.Element.*;
|
||||
@@ -72,9 +74,9 @@ class GrassRS {
|
||||
@SuppressWarnings({"FieldCanBeLocal"})
|
||||
private RenderScript.Sampler mSampler;
|
||||
@SuppressWarnings({"FieldCanBeLocal"})
|
||||
private RenderScript.ProgramFragment mPfBackground;
|
||||
private ProgramFragment mPfBackground;
|
||||
@SuppressWarnings({"FieldCanBeLocal"})
|
||||
private RenderScript.ProgramFragmentStore mPfsBackground;
|
||||
private ProgramStore mPfsBackground;
|
||||
@SuppressWarnings({"FieldCanBeLocal"})
|
||||
private RenderScript.ProgramVertex mPvBackground;
|
||||
@SuppressWarnings({"FieldCanBeLocal"})
|
||||
@@ -91,9 +93,9 @@ class GrassRS {
|
||||
@SuppressWarnings({"FieldCanBeLocal"})
|
||||
private Allocation mBlades;
|
||||
@SuppressWarnings({"FieldCanBeLocal"})
|
||||
private RenderScript.ProgramFragment mPfGrass;
|
||||
private ProgramFragment mPfGrass;
|
||||
@SuppressWarnings({"FieldCanBeLocal"})
|
||||
private RenderScript.ProgramFragmentStore mPfsGrass;
|
||||
private ProgramStore mPfsGrass;
|
||||
|
||||
public GrassRS(int width, int height) {
|
||||
mWidth = width;
|
||||
@@ -116,10 +118,10 @@ class GrassRS {
|
||||
|
||||
ScriptC.Builder sb = new ScriptC.Builder(mRS);
|
||||
sb.setScript(mResources, R.raw.grass);
|
||||
sb.setTimeZone(TimeZone.getDefault().getID());
|
||||
sb.setRoot(true);
|
||||
mScript = sb.create();
|
||||
mScript.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
mScript.setTimeZone(TimeZone.getDefault().getID());
|
||||
|
||||
loadSkyTextures();
|
||||
mScript.bindAllocation(mState, RSID_STATE);
|
||||
@@ -210,36 +212,33 @@ class GrassRS {
|
||||
mRS.samplerSet(WRAP_MODE_T, CLAMP);
|
||||
mSampler = mRS.samplerCreate();
|
||||
|
||||
mRS.programFragmentBegin(null, null);
|
||||
mRS.programFragmentSetTexEnable(0, true);
|
||||
mRS.programFragmentSetTexEnvMode(0, REPLACE);
|
||||
mPfBackground = mRS.programFragmentCreate();
|
||||
ProgramFragment.Builder b;
|
||||
b = new ProgramFragment.Builder(mRS, null, null);
|
||||
b.setTexEnable(true, 0);
|
||||
b.setTexEnvMode(REPLACE, 0);
|
||||
mPfBackground = b.create();
|
||||
mPfBackground.setName("PFBackground");
|
||||
mPfBackground.bindSampler(mSampler, 0);
|
||||
|
||||
mRS.programFragmentBegin(null, null);
|
||||
mRS.programFragmentSetTexEnable(0, true);
|
||||
mRS.programFragmentSetTexEnvMode(0, MODULATE);
|
||||
mPfGrass = mRS.programFragmentCreate();
|
||||
b.setTexEnvMode(MODULATE, 0);
|
||||
mPfGrass = b.create();
|
||||
mPfGrass.setName("PFGrass");
|
||||
mPfGrass.bindSampler(mSampler, 0);
|
||||
}
|
||||
|
||||
private void createProgramFragmentStore() {
|
||||
mRS.programFragmentStoreBegin(null, null);
|
||||
mRS.programFragmentStoreDepthFunc(ALWAYS);
|
||||
mRS.programFragmentStoreBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
|
||||
mRS.programFragmentStoreDitherEnable(true);
|
||||
mRS.programFragmentStoreDepthMask(false);
|
||||
mPfsBackground = mRS.programFragmentStoreCreate();
|
||||
ProgramStore.Builder b;
|
||||
b = new ProgramStore.Builder(mRS, null, null);
|
||||
|
||||
b.setDepthFunc(ALWAYS);
|
||||
b.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
|
||||
b.setDitherEnable(true);
|
||||
b.setDepthMask(false);
|
||||
mPfsBackground = b.create();
|
||||
mPfsBackground.setName("PFSBackground");
|
||||
|
||||
mRS.programFragmentStoreBegin(null, null);
|
||||
mRS.programFragmentStoreDepthFunc(ALWAYS);
|
||||
mRS.programFragmentStoreBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
|
||||
mRS.programFragmentStoreDitherEnable(true);
|
||||
mRS.programFragmentStoreDepthMask(false);
|
||||
mPfsGrass = mRS.programFragmentStoreCreate();
|
||||
b.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
|
||||
mPfsGrass = b.create();
|
||||
mPfsGrass.setName("PFSGrass");
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ import android.renderscript.Element;
|
||||
import android.renderscript.Allocation;
|
||||
import android.renderscript.Script;
|
||||
import android.renderscript.ScriptC;
|
||||
import android.renderscript.ProgramFragment;
|
||||
import android.renderscript.ProgramStore;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
@@ -95,10 +97,10 @@ public class RolloRS {
|
||||
private Script mScript;
|
||||
private RenderScript.Sampler mSampler;
|
||||
private RenderScript.Sampler mSamplerText;
|
||||
private RenderScript.ProgramFragmentStore mPFSBackground;
|
||||
private RenderScript.ProgramFragmentStore mPFSText;
|
||||
private RenderScript.ProgramFragment mPFImages;
|
||||
private RenderScript.ProgramFragment mPFText;
|
||||
private ProgramStore mPSBackground;
|
||||
private ProgramStore mPSText;
|
||||
private ProgramFragment mPFImages;
|
||||
private ProgramFragment mPFText;
|
||||
private RenderScript.ProgramVertex mPV;
|
||||
private ProgramVertexAlloc mPVAlloc;
|
||||
private RenderScript.ProgramVertex mPVOrtho;
|
||||
@@ -142,37 +144,33 @@ public class RolloRS {
|
||||
mSamplerText = mRS.samplerCreate();
|
||||
|
||||
|
||||
mRS.programFragmentBegin(null, null);
|
||||
mRS.programFragmentSetTexEnable(0, true);
|
||||
mRS.programFragmentSetTexEnvMode(0, RenderScript.EnvMode.MODULATE);
|
||||
mPFImages = mRS.programFragmentCreate();
|
||||
ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null);
|
||||
bf.setTexEnable(true, 0);
|
||||
bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0);
|
||||
mPFImages = bf.create();
|
||||
mPFImages.setName("PF");
|
||||
mPFImages.bindSampler(mSampler, 0);
|
||||
|
||||
mRS.programFragmentBegin(null, null);
|
||||
mRS.programFragmentSetTexEnable(0, true);
|
||||
mRS.programFragmentSetTexEnvMode(0, RenderScript.EnvMode.MODULATE);
|
||||
mPFText = mRS.programFragmentCreate();
|
||||
bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0);
|
||||
mPFText = bf.create();
|
||||
mPFText.setName("PFText");
|
||||
mPFText.bindSampler(mSamplerText, 0);
|
||||
|
||||
mRS.programFragmentStoreBegin(null, null);
|
||||
mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.LESS);
|
||||
mRS.programFragmentStoreDitherEnable(false);
|
||||
mRS.programFragmentStoreDepthMask(true);
|
||||
mRS.programFragmentStoreBlendFunc(RenderScript.BlendSrcFunc.SRC_ALPHA,
|
||||
RenderScript.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
|
||||
mPFSBackground = mRS.programFragmentStoreCreate();
|
||||
mPFSBackground.setName("PFS");
|
||||
ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null);
|
||||
bs.setDepthFunc(ProgramStore.DepthFunc.LESS);
|
||||
bs.setDitherEnable(false);
|
||||
bs.setDepthMask(true);
|
||||
bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
|
||||
ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
|
||||
mPSBackground = bs.create();
|
||||
mPSBackground.setName("PFS");
|
||||
|
||||
mRS.programFragmentStoreBegin(null, null);
|
||||
mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.ALWAYS);
|
||||
mRS.programFragmentStoreDitherEnable(false);
|
||||
mRS.programFragmentStoreDepthMask(false);
|
||||
mRS.programFragmentStoreBlendFunc(RenderScript.BlendSrcFunc.SRC_ALPHA,
|
||||
RenderScript.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
|
||||
mPFSText = mRS.programFragmentStoreCreate();
|
||||
mPFSText.setName("PFSText");
|
||||
bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
|
||||
bs.setDepthMask(false);
|
||||
bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
|
||||
ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
|
||||
mPSText = bs.create();
|
||||
mPSText.setName("PFSText");
|
||||
|
||||
mPVAlloc = new ProgramVertexAlloc(mRS);
|
||||
mRS.programVertexBegin(null, null);
|
||||
|
||||
@@ -127,14 +127,14 @@ AllocationDestroy {
|
||||
AllocationData {
|
||||
param RsAllocation va
|
||||
param const void * data
|
||||
}
|
||||
}
|
||||
|
||||
Allocation1DSubData {
|
||||
param RsAllocation va
|
||||
param uint32_t xoff
|
||||
param uint32_t count
|
||||
param const void *data
|
||||
}
|
||||
}
|
||||
|
||||
Allocation2DSubData {
|
||||
param RsAllocation va
|
||||
@@ -168,14 +168,14 @@ Adapter1DSetConstraint {
|
||||
Adapter1DData {
|
||||
param RsAdapter1D adapter
|
||||
param const void * data
|
||||
}
|
||||
}
|
||||
|
||||
Adapter1DSubData {
|
||||
param RsAdapter1D adapter
|
||||
param uint32_t xoff
|
||||
param uint32_t count
|
||||
param const void *data
|
||||
}
|
||||
}
|
||||
|
||||
Adapter2DCreate {
|
||||
ret RsAdapter2D
|
||||
@@ -199,7 +199,7 @@ Adapter2DSetConstraint {
|
||||
Adapter2DData {
|
||||
param RsAdapter2D adapter
|
||||
param const void *data
|
||||
}
|
||||
}
|
||||
|
||||
Adapter2DSubData {
|
||||
param RsAdapter2D adapter
|
||||
@@ -273,23 +273,27 @@ ScriptBindAllocation {
|
||||
ScriptCBegin {
|
||||
}
|
||||
|
||||
ScriptCSetClearColor {
|
||||
ScriptSetClearColor {
|
||||
param RsScript s
|
||||
param float r
|
||||
param float g
|
||||
param float b
|
||||
param float a
|
||||
}
|
||||
|
||||
ScriptCSetTimeZone {
|
||||
ScriptSetTimeZone {
|
||||
param RsScript s
|
||||
param const char * timeZone
|
||||
param uint32_t length
|
||||
}
|
||||
|
||||
ScriptCSetClearDepth {
|
||||
ScriptSetClearDepth {
|
||||
param RsScript s
|
||||
param float depth
|
||||
}
|
||||
|
||||
ScriptCSetClearStencil {
|
||||
ScriptSetClearStencil {
|
||||
param RsScript s
|
||||
param uint32_t stencil
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,32 @@ void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint3
|
||||
s->mSlots[slot].set(static_cast<Allocation *>(va));
|
||||
}
|
||||
|
||||
void rsi_ScriptSetClearColor(Context * rsc, RsScript vs, float r, float g, float b, float a)
|
||||
{
|
||||
Script *s = static_cast<Script *>(vs);
|
||||
s->mEnviroment.mClearColor[0] = r;
|
||||
s->mEnviroment.mClearColor[1] = g;
|
||||
s->mEnviroment.mClearColor[2] = b;
|
||||
s->mEnviroment.mClearColor[3] = a;
|
||||
}
|
||||
|
||||
void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, uint32_t length)
|
||||
{
|
||||
Script *s = static_cast<Script *>(vs);
|
||||
s->mEnviroment.mTimeZone = timeZone;
|
||||
}
|
||||
|
||||
void rsi_ScriptSetClearDepth(Context * rsc, RsScript vs, float v)
|
||||
{
|
||||
Script *s = static_cast<Script *>(vs);
|
||||
s->mEnviroment.mClearDepth = v;
|
||||
}
|
||||
|
||||
void rsi_ScriptSetClearStencil(Context * rsc, RsScript vs, uint32_t v)
|
||||
{
|
||||
Script *s = static_cast<Script *>(vs);
|
||||
s->mEnviroment.mClearStencil = v;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ ScriptC::~ScriptC()
|
||||
|
||||
bool ScriptC::run(Context *rsc, uint32_t launchIndex)
|
||||
{
|
||||
Context::ScriptTLSStruct * tls =
|
||||
Context::ScriptTLSStruct * tls =
|
||||
(Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey);
|
||||
|
||||
if (mEnviroment.mFragmentStore.get()) {
|
||||
@@ -100,7 +100,7 @@ void ScriptCState::clear()
|
||||
|
||||
}
|
||||
|
||||
static ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name)
|
||||
static ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name)
|
||||
{
|
||||
const ScriptCState::SymbolTable_t *sym = ScriptCState::lookupSymbol(name);
|
||||
if (sym) {
|
||||
@@ -194,7 +194,7 @@ void ScriptCState::runCompiler(Context *rsc)
|
||||
mEnviroment.mFragmentStore.clear();
|
||||
continue;
|
||||
}
|
||||
ProgramFragmentStore * pfs =
|
||||
ProgramFragmentStore * pfs =
|
||||
(ProgramFragmentStore *)rsc->lookupName(str[ct+1]);
|
||||
if (pfs != NULL) {
|
||||
mEnviroment.mFragmentStore.set(pfs);
|
||||
@@ -205,7 +205,7 @@ void ScriptCState::runCompiler(Context *rsc)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
// Deal with an error.
|
||||
}
|
||||
@@ -221,33 +221,6 @@ void rsi_ScriptCBegin(Context * rsc)
|
||||
ss->clear();
|
||||
}
|
||||
|
||||
void rsi_ScriptCSetClearColor(Context * rsc, float r, float g, float b, float a)
|
||||
{
|
||||
ScriptCState *ss = &rsc->mScriptC;
|
||||
ss->mEnviroment.mClearColor[0] = r;
|
||||
ss->mEnviroment.mClearColor[1] = g;
|
||||
ss->mEnviroment.mClearColor[2] = b;
|
||||
ss->mEnviroment.mClearColor[3] = a;
|
||||
}
|
||||
|
||||
void rsi_ScriptCSetTimeZone(Context * rsc, const char * timeZone, uint32_t length)
|
||||
{
|
||||
ScriptCState *ss = &rsc->mScriptC;
|
||||
ss->mEnviroment.mTimeZone = timeZone;
|
||||
}
|
||||
|
||||
void rsi_ScriptCSetClearDepth(Context * rsc, float v)
|
||||
{
|
||||
ScriptCState *ss = &rsc->mScriptC;
|
||||
ss->mEnviroment.mClearDepth = v;
|
||||
}
|
||||
|
||||
void rsi_ScriptCSetClearStencil(Context * rsc, uint32_t v)
|
||||
{
|
||||
ScriptCState *ss = &rsc->mScriptC;
|
||||
ss->mEnviroment.mClearStencil = v;
|
||||
}
|
||||
|
||||
void rsi_ScriptCAddType(Context * rsc, RsType vt)
|
||||
{
|
||||
ScriptCState *ss = &rsc->mScriptC;
|
||||
|
||||
Reference in New Issue
Block a user