Loading libs/rs/java/Grass/res/raw/grass.c +18 −19 Original line number Diff line number Diff line Loading @@ -72,42 +72,43 @@ void alpha(float a) { } void drawNight(int width, int height) { bindTexture(NAMED_PFBackground, 0, loadI32(RSID_TEXTURES, RSID_SKY_TEXTURE_NIGHT)); bindTexture(NAMED_PFBackground, 0, NAMED_TNight); drawRect(width - 512.0f, -32.0f, width, 1024.0f - 32.0f, 0.0f); } void drawSunrise(int width, int height) { bindTexture(NAMED_PFBackground, 0, loadI32(RSID_TEXTURES, RSID_SKY_TEXTURE_SUNRISE)); bindTexture(NAMED_PFBackground, 0, NAMED_TSunrise); drawRect(0.0f, 0.0f, width, height, 0.0f); } void drawNoon(int width, int height) { bindTexture(NAMED_PFBackground, 0, loadI32(RSID_TEXTURES, RSID_SKY_TEXTURE_NOON)); bindTexture(NAMED_PFBackground, 0, NAMED_TSky); drawRect(0.0f, 0.0f, width, height, 0.0f); } void drawSunset(int width, int height) { bindTexture(NAMED_PFBackground, 0, loadI32(RSID_TEXTURES, RSID_SKY_TEXTURE_SUNSET)); bindTexture(NAMED_PFBackground, 0, NAMED_TSunset); drawRect(0.0f, 0.0f, width, height, 0.0f); } void drawBlade(int index, float now, int frameCount) { float offset = loadF(RSID_BLADES, index + BLADE_STRUCT_OFFSET); float scale = loadF(RSID_BLADES, index + BLADE_STRUCT_SCALE); float angle = loadF(RSID_BLADES, index + BLADE_STRUCT_ANGLE); float hardness = loadF(RSID_BLADES, index + BLADE_STRUCT_HARDNESS); float *bladeStruct = loadArrayF(RSID_BLADES, index); float offset = bladeStruct[BLADE_STRUCT_OFFSET]; float scale = bladeStruct[BLADE_STRUCT_SCALE]; float angle = bladeStruct[BLADE_STRUCT_ANGLE]; float hardness = bladeStruct[BLADE_STRUCT_HARDNESS]; float xpos = loadF(RSID_BLADES, index + BLADE_STRUCT_XPOS); float ypos = loadF(RSID_BLADES, index + BLADE_STRUCT_YPOS); float xpos = bladeStruct[BLADE_STRUCT_XPOS]; float ypos = bladeStruct[BLADE_STRUCT_YPOS]; float lengthX = loadF(RSID_BLADES, index + BLADE_STRUCT_LENGTHX); float lengthY = loadF(RSID_BLADES, index + BLADE_STRUCT_LENGTHY); float lengthX = bladeStruct[BLADE_STRUCT_LENGTHX]; float lengthY = bladeStruct[BLADE_STRUCT_LENGTHY]; int size = loadF(RSID_BLADES, index + BLADE_STRUCT_SIZE); int size = bladeStruct[BLADE_STRUCT_SIZE]; float h = loadF(RSID_BLADES, index + BLADE_STRUCT_H); float s = loadF(RSID_BLADES, index + BLADE_STRUCT_S); float b = loadF(RSID_BLADES, index + BLADE_STRUCT_B); float h = bladeStruct[BLADE_STRUCT_H]; float s = bladeStruct[BLADE_STRUCT_S]; float b = bladeStruct[BLADE_STRUCT_B]; float newB = 1.0f; if (now >= MIDNIGHT && now < MORNING) { Loading Loading @@ -162,9 +163,7 @@ void drawBlade(int index, float now, int frameCount) { void drawBlades(float now, int frameCount) { // For anti-aliasing bindProgramFragmentStore(NAMED_PFSGrass); bindProgramFragment(NAMED_PFGrass); bindTexture(NAMED_PFGrass, 0, loadI32(RSID_TEXTURES, RSID_GRASS_TEXTURE)); bindTexture(NAMED_PFBackground, 0, NAMED_TAa); int bladesCount = loadI32(RSID_STATE, RSID_BLADES_COUNT); int count = bladesCount * BLADE_STRUCT_FIELDS_COUNT; Loading libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java +6 −22 Original line number Diff line number Diff line Loading @@ -29,8 +29,6 @@ import android.renderscript.Allocation; import android.renderscript.ProgramVertex; import static android.renderscript.Element.*; import static android.util.MathUtils.*; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.renderscript.ScriptC; import android.renderscript.Type; import android.renderscript.Dimension; Loading Loading @@ -84,9 +82,6 @@ class GrassRS { private Allocation mState; private Allocation mBlades; private ProgramFragment mPfGrass; private ProgramStore mPfsGrass; public GrassRS(int width, int height) { mWidth = width; mHeight = height; Loading @@ -111,8 +106,6 @@ class GrassRS { } mState.destroy(); mBlades.destroy(); mPfGrass.destroy(); mPfsGrass.destroy(); mTextureBufferIDs = null; } Loading @@ -130,6 +123,7 @@ class GrassRS { createProgramFragmentStore(); createProgramFragment(); createScriptStructures(); loadSkyTextures(); ScriptC.Builder sb = new ScriptC.Builder(mRS); sb.setScript(mResources, R.raw.grass); Loading @@ -138,7 +132,6 @@ class GrassRS { mScript.setClearColor(0.0f, 0.0f, 0.0f, 1.0f); mScript.setTimeZone(TimeZone.getDefault().getID()); loadSkyTextures(); mScript.bindAllocation(mState, RSID_STATE); mScript.bindAllocation(mTexturesIDs, RSID_TEXTURES); mScript.bindAllocation(mBlades, RSID_BLADES); Loading Loading @@ -185,11 +178,11 @@ class GrassRS { mTexturesIDs = Allocation.createSized(mRS, USER_FLOAT, TEXTURES_COUNT); final Allocation[] textures = mTextures; textures[0] = loadTexture(R.drawable.night, "night"); textures[1] = loadTexture(R.drawable.sunrise, "sunrise"); textures[2] = loadTexture(R.drawable.sky, "sky"); textures[3] = loadTexture(R.drawable.sunset, "sunset"); textures[4] = generateTextureAlpha(4, 1, new int[] { 0x00FFFF00 }, "aa"); textures[0] = loadTexture(R.drawable.night, "TNight"); textures[1] = loadTexture(R.drawable.sunrise, "TSunrise"); textures[2] = loadTexture(R.drawable.sky, "TSky"); textures[3] = loadTexture(R.drawable.sunset, "TSunset"); textures[4] = generateTextureAlpha(4, 1, new int[] { 0x00FFFF00 }, "TAa"); final int[] bufferIds = mTextureBufferIDs; final int count = textures.length; Loading Loading @@ -236,11 +229,6 @@ class GrassRS { mPfBackground = b.create(); mPfBackground.setName("PFBackground"); mPfBackground.bindSampler(mSampler, 0); b.setTexEnvMode(REPLACE, 0); mPfGrass = b.create(); mPfGrass.setName("PFGrass"); mPfGrass.bindSampler(mSampler, 0); } private void createProgramFragmentStore() { Loading @@ -253,10 +241,6 @@ class GrassRS { b.setDepthMask(false); mPfsBackground = b.create(); mPfsBackground.setName("PFSBackground"); b.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA); mPfsGrass = b.create(); mPfsGrass.setName("PFSGrass"); } private void createProgramVertex() { Loading libs/rs/rsScriptC_Lib.cpp +7 −6 Original line number Diff line number Diff line Loading @@ -59,22 +59,23 @@ static int32_t SC_loadI32(uint32_t bank, uint32_t offset) return i[offset]; } static float* SC_loadArrayF(uint32_t bank) static float* SC_loadArrayF(uint32_t bank, uint32_t offset) { GET_TLS(); void *vp = sc->mSlots[bank]->getPtr(); float *f = static_cast<float *>(vp); return f; return f + offset; } static int32_t* SC_loadArrayI32(uint32_t bank) static int32_t* SC_loadArrayI32(uint32_t bank, uint32_t offset) { GET_TLS(); void *vp = sc->mSlots[bank]->getPtr(); int32_t *i = static_cast<int32_t *>(vp); return i; return i + offset; } static uint32_t SC_loadU32(uint32_t bank, uint32_t offset) { GET_TLS(); Loading Loading @@ -695,9 +696,9 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = { { "loadF", (void *)&SC_loadF, "float", "(int, int)" }, { "loadArrayF", (void *)&SC_loadArrayF, "float*", "(int)" }, "float*", "(int, int)" }, { "loadArrayI32", (void *)&SC_loadArrayI32, "int*", "(int)" }, "int*", "(int, int)" }, { "loadVec4", (void *)&SC_loadVec4, "void", "(int, int, float *)" }, { "loadMatrix", (void *)&SC_loadMatrix, Loading Loading
libs/rs/java/Grass/res/raw/grass.c +18 −19 Original line number Diff line number Diff line Loading @@ -72,42 +72,43 @@ void alpha(float a) { } void drawNight(int width, int height) { bindTexture(NAMED_PFBackground, 0, loadI32(RSID_TEXTURES, RSID_SKY_TEXTURE_NIGHT)); bindTexture(NAMED_PFBackground, 0, NAMED_TNight); drawRect(width - 512.0f, -32.0f, width, 1024.0f - 32.0f, 0.0f); } void drawSunrise(int width, int height) { bindTexture(NAMED_PFBackground, 0, loadI32(RSID_TEXTURES, RSID_SKY_TEXTURE_SUNRISE)); bindTexture(NAMED_PFBackground, 0, NAMED_TSunrise); drawRect(0.0f, 0.0f, width, height, 0.0f); } void drawNoon(int width, int height) { bindTexture(NAMED_PFBackground, 0, loadI32(RSID_TEXTURES, RSID_SKY_TEXTURE_NOON)); bindTexture(NAMED_PFBackground, 0, NAMED_TSky); drawRect(0.0f, 0.0f, width, height, 0.0f); } void drawSunset(int width, int height) { bindTexture(NAMED_PFBackground, 0, loadI32(RSID_TEXTURES, RSID_SKY_TEXTURE_SUNSET)); bindTexture(NAMED_PFBackground, 0, NAMED_TSunset); drawRect(0.0f, 0.0f, width, height, 0.0f); } void drawBlade(int index, float now, int frameCount) { float offset = loadF(RSID_BLADES, index + BLADE_STRUCT_OFFSET); float scale = loadF(RSID_BLADES, index + BLADE_STRUCT_SCALE); float angle = loadF(RSID_BLADES, index + BLADE_STRUCT_ANGLE); float hardness = loadF(RSID_BLADES, index + BLADE_STRUCT_HARDNESS); float *bladeStruct = loadArrayF(RSID_BLADES, index); float offset = bladeStruct[BLADE_STRUCT_OFFSET]; float scale = bladeStruct[BLADE_STRUCT_SCALE]; float angle = bladeStruct[BLADE_STRUCT_ANGLE]; float hardness = bladeStruct[BLADE_STRUCT_HARDNESS]; float xpos = loadF(RSID_BLADES, index + BLADE_STRUCT_XPOS); float ypos = loadF(RSID_BLADES, index + BLADE_STRUCT_YPOS); float xpos = bladeStruct[BLADE_STRUCT_XPOS]; float ypos = bladeStruct[BLADE_STRUCT_YPOS]; float lengthX = loadF(RSID_BLADES, index + BLADE_STRUCT_LENGTHX); float lengthY = loadF(RSID_BLADES, index + BLADE_STRUCT_LENGTHY); float lengthX = bladeStruct[BLADE_STRUCT_LENGTHX]; float lengthY = bladeStruct[BLADE_STRUCT_LENGTHY]; int size = loadF(RSID_BLADES, index + BLADE_STRUCT_SIZE); int size = bladeStruct[BLADE_STRUCT_SIZE]; float h = loadF(RSID_BLADES, index + BLADE_STRUCT_H); float s = loadF(RSID_BLADES, index + BLADE_STRUCT_S); float b = loadF(RSID_BLADES, index + BLADE_STRUCT_B); float h = bladeStruct[BLADE_STRUCT_H]; float s = bladeStruct[BLADE_STRUCT_S]; float b = bladeStruct[BLADE_STRUCT_B]; float newB = 1.0f; if (now >= MIDNIGHT && now < MORNING) { Loading Loading @@ -162,9 +163,7 @@ void drawBlade(int index, float now, int frameCount) { void drawBlades(float now, int frameCount) { // For anti-aliasing bindProgramFragmentStore(NAMED_PFSGrass); bindProgramFragment(NAMED_PFGrass); bindTexture(NAMED_PFGrass, 0, loadI32(RSID_TEXTURES, RSID_GRASS_TEXTURE)); bindTexture(NAMED_PFBackground, 0, NAMED_TAa); int bladesCount = loadI32(RSID_STATE, RSID_BLADES_COUNT); int count = bladesCount * BLADE_STRUCT_FIELDS_COUNT; Loading
libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java +6 −22 Original line number Diff line number Diff line Loading @@ -29,8 +29,6 @@ import android.renderscript.Allocation; import android.renderscript.ProgramVertex; import static android.renderscript.Element.*; import static android.util.MathUtils.*; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.renderscript.ScriptC; import android.renderscript.Type; import android.renderscript.Dimension; Loading Loading @@ -84,9 +82,6 @@ class GrassRS { private Allocation mState; private Allocation mBlades; private ProgramFragment mPfGrass; private ProgramStore mPfsGrass; public GrassRS(int width, int height) { mWidth = width; mHeight = height; Loading @@ -111,8 +106,6 @@ class GrassRS { } mState.destroy(); mBlades.destroy(); mPfGrass.destroy(); mPfsGrass.destroy(); mTextureBufferIDs = null; } Loading @@ -130,6 +123,7 @@ class GrassRS { createProgramFragmentStore(); createProgramFragment(); createScriptStructures(); loadSkyTextures(); ScriptC.Builder sb = new ScriptC.Builder(mRS); sb.setScript(mResources, R.raw.grass); Loading @@ -138,7 +132,6 @@ class GrassRS { mScript.setClearColor(0.0f, 0.0f, 0.0f, 1.0f); mScript.setTimeZone(TimeZone.getDefault().getID()); loadSkyTextures(); mScript.bindAllocation(mState, RSID_STATE); mScript.bindAllocation(mTexturesIDs, RSID_TEXTURES); mScript.bindAllocation(mBlades, RSID_BLADES); Loading Loading @@ -185,11 +178,11 @@ class GrassRS { mTexturesIDs = Allocation.createSized(mRS, USER_FLOAT, TEXTURES_COUNT); final Allocation[] textures = mTextures; textures[0] = loadTexture(R.drawable.night, "night"); textures[1] = loadTexture(R.drawable.sunrise, "sunrise"); textures[2] = loadTexture(R.drawable.sky, "sky"); textures[3] = loadTexture(R.drawable.sunset, "sunset"); textures[4] = generateTextureAlpha(4, 1, new int[] { 0x00FFFF00 }, "aa"); textures[0] = loadTexture(R.drawable.night, "TNight"); textures[1] = loadTexture(R.drawable.sunrise, "TSunrise"); textures[2] = loadTexture(R.drawable.sky, "TSky"); textures[3] = loadTexture(R.drawable.sunset, "TSunset"); textures[4] = generateTextureAlpha(4, 1, new int[] { 0x00FFFF00 }, "TAa"); final int[] bufferIds = mTextureBufferIDs; final int count = textures.length; Loading Loading @@ -236,11 +229,6 @@ class GrassRS { mPfBackground = b.create(); mPfBackground.setName("PFBackground"); mPfBackground.bindSampler(mSampler, 0); b.setTexEnvMode(REPLACE, 0); mPfGrass = b.create(); mPfGrass.setName("PFGrass"); mPfGrass.bindSampler(mSampler, 0); } private void createProgramFragmentStore() { Loading @@ -253,10 +241,6 @@ class GrassRS { b.setDepthMask(false); mPfsBackground = b.create(); mPfsBackground.setName("PFSBackground"); b.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA); mPfsGrass = b.create(); mPfsGrass.setName("PFSGrass"); } private void createProgramVertex() { Loading
libs/rs/rsScriptC_Lib.cpp +7 −6 Original line number Diff line number Diff line Loading @@ -59,22 +59,23 @@ static int32_t SC_loadI32(uint32_t bank, uint32_t offset) return i[offset]; } static float* SC_loadArrayF(uint32_t bank) static float* SC_loadArrayF(uint32_t bank, uint32_t offset) { GET_TLS(); void *vp = sc->mSlots[bank]->getPtr(); float *f = static_cast<float *>(vp); return f; return f + offset; } static int32_t* SC_loadArrayI32(uint32_t bank) static int32_t* SC_loadArrayI32(uint32_t bank, uint32_t offset) { GET_TLS(); void *vp = sc->mSlots[bank]->getPtr(); int32_t *i = static_cast<int32_t *>(vp); return i; return i + offset; } static uint32_t SC_loadU32(uint32_t bank, uint32_t offset) { GET_TLS(); Loading Loading @@ -695,9 +696,9 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = { { "loadF", (void *)&SC_loadF, "float", "(int, int)" }, { "loadArrayF", (void *)&SC_loadArrayF, "float*", "(int)" }, "float*", "(int, int)" }, { "loadArrayI32", (void *)&SC_loadArrayI32, "int*", "(int)" }, "int*", "(int, int)" }, { "loadVec4", (void *)&SC_loadVec4, "void", "(int, int, float *)" }, { "loadMatrix", (void *)&SC_loadMatrix, Loading