FileDocCategorySizeDatePackage
Renderable.javaAPI DocAndroid 5.1 API7183Thu Mar 12 22:22:44 GMT 2015com.android.scenegraph

Renderable

public class Renderable extends RenderableBase
hide

Fields Summary
HashMap
mSourceParams
RenderState
mRenderState
Transform
mTransform
String
mMeshName
String
mMeshIndexName
public String
mMaterialName
ScriptField_Renderable_s
mField
ScriptField_Renderable_s.Item
mData
Constructors Summary
public Renderable()

        mSourceParams = new HashMap<String, ShaderParam>();
        mData = new ScriptField_Renderable_s.Item();
    
Methods Summary
public voidappendSourceParams(com.android.scenegraph.ShaderParam p)

        mSourceParams.put(p.getParamName(), p);
        // Possibly lift this restriction later
        if (mField != null) {
            throw new RuntimeException("Can't add source params to objects that are rendering");
        }
    
ScriptField_Renderable_sgetRsField(android.renderscript.RenderScriptGL rs, android.content.res.Resources res)

        if (mField != null) {
            return mField;
        }
        updateFieldItem(rs);
        updateTextures(rs);

        mField = new ScriptField_Renderable_s(rs, 1);
        mField.set(mData, 0, true);

        return mField;
    
public TransformgetTransform()

        return mTransform;
    
public voidresolveMeshData(android.renderscript.Mesh mesh)

        mData.mesh = mesh;
        if (mData.mesh == null) {
            Log.v("DRAWABLE: ", "*** NO MESH *** " + mMeshName);
            return;
        }
        int subIndexCount = mData.mesh.getPrimitiveCount();
        if (subIndexCount == 1 || mMeshIndexName == null) {
            mData.meshIndex = 0;
        } else {
            for (int i = 0; i < subIndexCount; i ++) {
                if (mData.mesh.getIndexSetAllocation(i).getName().equals(mMeshIndexName)) {
                    mData.meshIndex = i;
                    break;
                }
            }
        }
        if (mField != null) {
            mField.set(mData, 0, true);
        }
    
public voidsetCullType(int cull)

        mData.cullType = cull;
    
public voidsetMaterialName(java.lang.String name)

        mMaterialName = name;
    
public voidsetMesh(android.renderscript.Mesh mesh)

        mData.mesh = mesh;
        if (mField != null) {
            mField.set_mesh(0, mData.mesh, true);
        }
    
public voidsetMesh(java.lang.String mesh, java.lang.String indexName)

        mMeshName = mesh;
        mMeshIndexName = indexName;
    
public voidsetRenderState(RenderState renderState)

        mRenderState = renderState;
        if (mField != null) {
            RenderScriptGL rs = SceneManager.getRS();
            updateFieldItem(rs);
            mField.set(mData, 0, true);
        }
    
public voidsetTransform(Transform t)

        mTransform = t;
        if (mField != null) {
            RenderScriptGL rs = SceneManager.getRS();
            updateFieldItem(rs);
            mField.set(mData, 0, true);
        }
    
public voidsetVisible(boolean vis)

        mData.cullType = vis ? 0 : 2;
        if (mField != null) {
            mField.set_cullType(0, mData.cullType, true);
        }
    
voidupdateFieldItem(android.renderscript.RenderScriptGL rs)

        if (mRenderState == null) {
            mRenderState = SceneManager.getDefaultState();
        }
        if (mTransform == null) {
            mTransform = SceneManager.getDefaultTransform();
        }
        updateVertexConstants(rs);
        updateFragmentConstants(rs);

        mData.transformMatrix = mTransform.getRSData().getAllocation();

        mData.name = getNameAlloc(rs);
        mData.render_state = mRenderState.getRSData().getAllocation();
        mData.bVolInitialized = 0;
    
voidupdateFragmentConstants(android.renderscript.RenderScriptGL rs)

        Allocation pfParams = null, fragmentConstants = null;
        FragmentShader pf = mRenderState.mFragment;
        if (pf != null && pf.getObjectConstants() != null) {
            fragmentConstants = Allocation.createTyped(rs, pf.getObjectConstants());
            Element fragmentConst = fragmentConstants.getType().getElement();
            pfParams = ShaderParam.fillInParams(fragmentConst, mSourceParams,
                                                mTransform).getAllocation();
        }
        mData.pf_const = fragmentConstants;
        mData.pf_constParams = pfParams;
    
voidupdateTextures(android.renderscript.RenderScriptGL rs)

        Iterator<ShaderParam> allParamsIter = mSourceParams.values().iterator();
        int paramIndex = 0;
        while (allParamsIter.hasNext()) {
            ShaderParam sp = allParamsIter.next();
            if (sp instanceof TextureParam) {
                TextureParam p = (TextureParam)sp;
                TextureBase tex = p.getTexture();
                if (tex != null) {
                    mData.pf_textures[paramIndex++] = tex.getRsData(false).getAllocation();
                }
            }
        }
        ProgramFragment pf = mRenderState.mFragment.mProgram;
        mData.pf_num_textures = pf != null ? Math.min(pf.getTextureCount(), paramIndex) : 0;
        if (mField != null) {
            mField.set_pf_textures(0, mData.pf_textures, true);
            mField.set_pf_num_textures(0, mData.pf_num_textures, true);
        }
    
voidupdateVertexConstants(android.renderscript.RenderScriptGL rs)

        Allocation pvParams = null, vertexConstants = null;
        VertexShader pv = mRenderState.mVertex;
        if (pv != null && pv.getObjectConstants() != null) {
            vertexConstants = Allocation.createTyped(rs, pv.getObjectConstants());
            Element vertexConst = vertexConstants.getType().getElement();
            pvParams = ShaderParam.fillInParams(vertexConst, mSourceParams,
                                                mTransform).getAllocation();
        }
        mData.pv_const = vertexConstants;
        mData.pv_constParams = pvParams;