Search in sources :

Example 1 with RenderScriptGL

use of android.renderscript.RenderScriptGL in project android_frameworks_base by ParanoidAndroid.

the class SceneManager method getDefaultVS.

// Provides the folowing inputs to fragment shader
// Assigned by default if nothing is present
// vec3 varWorldPos;
// vec3 varWorldNormal;
// vec2 varTex0;
public static VertexShader getDefaultVS() {
    if (sSceneManager == null) {
        return null;
    }
    if (sSceneManager.mDefaultVertex == null) {
        RenderScriptGL rs = getRS();
        Element.Builder b = new Element.Builder(rs);
        b.add(Element.MATRIX_4X4(rs), "model");
        Type.Builder objConstBuilder = new Type.Builder(rs, b.create());
        b = new Element.Builder(rs);
        b.add(Element.MATRIX_4X4(rs), "viewProj");
        Type.Builder shaderConstBuilder = new Type.Builder(rs, b.create());
        b = new Element.Builder(rs);
        b.add(Element.F32_4(rs), "position");
        b.add(Element.F32_2(rs), "texture0");
        b.add(Element.F32_3(rs), "normal");
        Element defaultIn = b.create();
        final String code = "\n" + "varying vec3 varWorldPos;\n" + "varying vec3 varWorldNormal;\n" + "varying vec2 varTex0;\n" + "void main() {" + "   vec4 objPos = ATTRIB_position;\n" + "   vec4 worldPos = UNI_model * objPos;\n" + "   gl_Position = UNI_viewProj * worldPos;\n" + "   mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);\n" + "   vec3 worldNorm = model3 * ATTRIB_normal;\n" + "   varWorldPos = worldPos.xyz;\n" + "   varWorldNormal = worldNorm;\n" + "   varTex0 = ATTRIB_texture0;\n" + "}\n";
        VertexShader.Builder sb = new VertexShader.Builder(rs);
        sb.addInput(defaultIn);
        sb.setObjectConst(objConstBuilder.setX(1).create());
        sb.setShaderConst(shaderConstBuilder.setX(1).create());
        sb.setShader(code);
        sSceneManager.mDefaultVertex = sb.create();
    }
    return sSceneManager.mDefaultVertex;
}
Also used : VertexShader(com.android.scenegraph.VertexShader) RenderScriptGL(android.renderscript.RenderScriptGL)

Example 2 with RenderScriptGL

use of android.renderscript.RenderScriptGL in project android_frameworks_base by ParanoidAndroid.

the class SceneManager method getDefault.

private static Allocation getDefault(boolean isCube) {
    final int dimension = 4;
    final int bytesPerPixel = 4;
    int arraySize = dimension * dimension * bytesPerPixel;
    RenderScriptGL rs = sSceneManager.mRS;
    Type.Builder b = new Type.Builder(rs, Element.RGBA_8888(rs));
    b.setX(dimension).setY(dimension);
    if (isCube) {
        b.setFaces(true);
        arraySize *= 6;
    }
    Type bitmapType = b.create();
    Allocation.MipmapControl mip = Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE;
    int usage = Allocation.USAGE_GRAPHICS_TEXTURE;
    Allocation defaultImage = Allocation.createTyped(rs, bitmapType, mip, usage);
    byte[] imageData = new byte[arraySize];
    defaultImage.copyFrom(imageData);
    return defaultImage;
}
Also used : MipmapControl(android.renderscript.Allocation.MipmapControl) RenderScriptGL(android.renderscript.RenderScriptGL)

Example 3 with RenderScriptGL

use of android.renderscript.RenderScriptGL in project android_frameworks_base by ParanoidAndroid.

the class SceneManager method getColorFS.

public static FragmentShader getColorFS() {
    if (sSceneManager == null) {
        return null;
    }
    if (sSceneManager.mColor == null) {
        RenderScriptGL rs = getRS();
        Element.Builder b = new Element.Builder(rs);
        b.add(Element.F32_4(rs), "color");
        Type.Builder objConstBuilder = new Type.Builder(rs, b.create());
        final String code = "\n" + "varying vec2 varTex0;\n" + "void main() {\n" + "   lowp vec4 col = UNI_color;\n" + "   gl_FragColor = col;\n" + "}\n";
        FragmentShader.Builder fb = new FragmentShader.Builder(rs);
        fb.setShader(code);
        fb.setObjectConst(objConstBuilder.create());
        sSceneManager.mColor = fb.create();
    }
    return sSceneManager.mColor;
}
Also used : FragmentShader(com.android.scenegraph.FragmentShader) RenderScriptGL(android.renderscript.RenderScriptGL)

Example 4 with RenderScriptGL

use of android.renderscript.RenderScriptGL in project android_frameworks_base by ParanoidAndroid.

the class ShaderParam method fillInParams.

static ScriptField_ShaderParam_s fillInParams(Element constantElem, HashMap<String, ShaderParam> sourceParams, Transform transform) {
    RenderScriptGL rs = SceneManager.getRS();
    ArrayList<ScriptField_ShaderParam_s.Item> paramList;
    paramList = new ArrayList<ScriptField_ShaderParam_s.Item>();
    int subElemCount = constantElem.getSubElementCount();
    for (int i = 0; i < subElemCount; i++) {
        String inputName = constantElem.getSubElementName(i);
        int offset = constantElem.getSubElementOffsetBytes(i);
        ShaderParam matchingParam = sourceParams.get(inputName);
        Element subElem = constantElem.getSubElement(i);
        // Make one if it's not there
        if (matchingParam == null) {
            if (subElem.getDataType() == Element.DataType.FLOAT_32) {
                matchingParam = new Float4Param(inputName, 0.5f, 0.5f, 0.5f, 0.5f);
            } else if (subElem.getDataType() == Element.DataType.MATRIX_4X4) {
                TransformParam trParam = new TransformParam(inputName);
                trParam.setTransform(transform);
                matchingParam = trParam;
            }
        }
        ScriptField_ShaderParam_s.Item paramRS = new ScriptField_ShaderParam_s.Item();
        paramRS.bufferOffset = offset;
        paramRS.transformTimestamp = 0;
        paramRS.dataTimestamp = 0;
        paramRS.data = matchingParam.getRSData().getAllocation();
        if (subElem.getDataType() == Element.DataType.FLOAT_32) {
            paramRS.float_vecSize = subElem.getVectorSize();
        }
        paramList.add(paramRS);
    }
    ScriptField_ShaderParam_s rsParams = null;
    int paramCount = paramList.size();
    if (paramCount != 0) {
        rsParams = new ScriptField_ShaderParam_s(rs, paramCount);
        for (int i = 0; i < paramCount; i++) {
            rsParams.set(paramList.get(i), i, false);
        }
        rsParams.copyAll();
    }
    return rsParams;
}
Also used : Element(android.renderscript.Element) RenderScriptGL(android.renderscript.RenderScriptGL)

Example 5 with RenderScriptGL

use of android.renderscript.RenderScriptGL in project android_frameworks_base by ParanoidAndroid.

the class RenderState method getRSData.

public ScriptField_RenderState_s getRSData() {
    if (mField != null) {
        return mField;
    }
    RenderScriptGL rs = SceneManager.getRS();
    if (rs == null) {
        return null;
    }
    mField = new ScriptField_RenderState_s(rs, 1);
    updateRSData();
    return mField;
}
Also used : RenderScriptGL(android.renderscript.RenderScriptGL)

Aggregations

RenderScriptGL (android.renderscript.RenderScriptGL)13 FragmentShader (com.android.scenegraph.FragmentShader)2 MipmapControl (android.renderscript.Allocation.MipmapControl)1 Element (android.renderscript.Element)1 VertexShader (com.android.scenegraph.VertexShader)1