FileDocCategorySizeDatePackage
FountainFboRS.javaAPI DocAndroid 5.1 API3488Thu Mar 12 22:22:44 GMT 2015com.example.android.rs.fountainfbo

FountainFboRS

public class FountainFboRS extends Object

Fields Summary
public static final int
PART_COUNT
private android.content.res.Resources
mRes
private android.renderscript.RenderScriptGL
mRS
private ScriptC_fountainfbo
mScript
private android.renderscript.Allocation
mColorBuffer
private android.renderscript.ProgramFragment
mProgramFragment
private android.renderscript.ProgramFragment
mTextureProgramFragment
boolean[]
holdingColor
Constructors Summary
public FountainFboRS()


      
    
Methods Summary
public voidinit(android.renderscript.RenderScriptGL rs, android.content.res.Resources res)

      mRS = rs;
      mRes = res;

      ScriptField_Point points = new ScriptField_Point(mRS, PART_COUNT);

      Mesh.AllocationBuilder smb = new Mesh.AllocationBuilder(mRS);
      smb.addVertexAllocation(points.getAllocation());
      smb.addIndexSetType(Mesh.Primitive.POINT);
      Mesh sm = smb.create();

      mScript = new ScriptC_fountainfbo(mRS, mRes, R.raw.fountainfbo);
      mScript.set_partMesh(sm);
      mScript.bind_point(points);

      ProgramFragmentFixedFunction.Builder pfb = new ProgramFragmentFixedFunction.Builder(rs);
      pfb.setVaryingColor(true);
      mProgramFragment = pfb.create();
      mScript.set_gProgramFragment(mProgramFragment);

      /* Second fragment shader to use a texture (framebuffer object) to draw with */
      pfb.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
          ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);

      /* Set the fragment shader in the Renderscript runtime */
      mTextureProgramFragment = pfb.create();
      mScript.set_gTextureProgramFragment(mTextureProgramFragment);

      /* Create the allocation for the color buffer */
      Type.Builder colorBuilder = new Type.Builder(mRS, Element.RGBA_8888(mRS));
      colorBuilder.setX(256).setY(256);
      mColorBuffer = Allocation.createTyped(mRS, colorBuilder.create(),
      Allocation.USAGE_GRAPHICS_TEXTURE |
      Allocation.USAGE_GRAPHICS_RENDER_TARGET);

      /* Set the allocation in the Renderscript runtime */
      mScript.set_gColorBuffer(mColorBuffer);

      mRS.bindRootScript(mScript);
  
public voidnewTouchPosition(float x, float y, float pressure, int id)

              
        if (id >= holdingColor.length) {
            return;
        }
        int rate = (int)(pressure * pressure * 500.f);
        if (rate > 500) {
            rate = 500;
        }
        if (rate > 0) {
            mScript.invoke_addParticles(rate, x, y, id, !holdingColor[id]);
            holdingColor[id] = true;
        } else {
            holdingColor[id] = false;
        }