Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1eb4c26a authored by Alex Sakhartchouk's avatar Alex Sakhartchouk Committed by Android (Google) Code Review
Browse files

Merge "Adding a very simple all-code scenegraph example."

parents 5489e4af 57fc7109
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -11,6 +11,13 @@
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="SimpleApp"
                  android:label="SimpleSceneGraph">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="FileSelector"
                  android:label="FileSelector"
                  android:hardwareAccelerated="true">
+3 −3
Original line number Diff line number Diff line
@@ -248,17 +248,17 @@ public class ColladaParser {
                String description = field.getAttribute("sid");
                if (fieldName.equals("translate")) {
                    Float3 value = getFloat3(field);
                    current.addComponent(new TranslateComponent(description, value));
                    current.addTranslate(description, value);
                    //Log.v(TAG, indent + " translate " + description + toString(value));
                } else if (fieldName.equals("rotate")) {
                    Float4 value = getFloat4(field);
                    //Log.v(TAG, indent + " rotate " + description + toString(value));
                    Float3 axis = new Float3(value.x, value.y, value.z);
                    current.addComponent(new RotateComponent(description, axis, value.w));
                    current.addRotate(description, axis, value.w);
                } else if (fieldName.equals("scale")) {
                    Float3 value = getFloat3(field);
                    //Log.v(TAG, indent + " scale " + description + toString(value));
                    current.addComponent(new ScaleComponent(description, value));
                    current.addScale(description, value);
                } else if (fieldName.equals("instance_geometry")) {
                    getRenderable(field, current);
                } else if (fieldName.equals("instance_light")) {
+18 −0
Original line number Diff line number Diff line
@@ -134,6 +134,24 @@ public class CompoundTransform extends Transform {
        mTransformComponents = new ArrayList<Component>();
    }

    public TranslateComponent addTranslate(String name, Float3 translate) {
        TranslateComponent c = new TranslateComponent(name, translate);
        addComponent(c);
        return c;
    }

    public RotateComponent addRotate(String name, Float3 axis, float angle) {
        RotateComponent c = new RotateComponent(name, axis, angle);
        addComponent(c);
        return c;
    }

    public ScaleComponent addScale(String name, Float3 scale) {
        ScaleComponent c = new ScaleComponent(name, scale);
        addComponent(c);
        return c;
    }

    public void addComponent(Component c) {
        if (c.mParent != null) {
            throw new IllegalArgumentException("Transform components may not be shared");
+21 −16
Original line number Diff line number Diff line
@@ -248,6 +248,7 @@ public class Scene extends SceneGraphBase {
    }

    private void addShaders(RenderScriptGL rs, Resources res, SceneManager sceneManager) {
        if (mVertexShaders.size() > 0) {
            Allocation shaderData = Allocation.createSized(rs, Element.ALLOCATION(rs),
                                                           mVertexShaders.size());
            Allocation[] shaderAllocs = new Allocation[mVertexShaders.size()];
@@ -257,9 +258,12 @@ public class Scene extends SceneGraphBase {
            }
            shaderData.copyFrom(shaderAllocs);
            sceneManager.mRenderLoop.set_gVertexShaders(shaderData);
        }

        shaderData = Allocation.createSized(rs, Element.ALLOCATION(rs), mFragmentShaders.size());
        shaderAllocs = new Allocation[mFragmentShaders.size()];
        if (mFragmentShaders.size() > 0) {
            Allocation shaderData = Allocation.createSized(rs, Element.ALLOCATION(rs),
                                                           mFragmentShaders.size());
            Allocation[] shaderAllocs = new Allocation[mFragmentShaders.size()];
            for (int i = 0; i < mFragmentShaders.size(); i ++) {
                FragmentShader sI = mFragmentShaders.get(i);
                shaderAllocs[i] = sI.getRSData().getAllocation();
@@ -267,6 +271,7 @@ public class Scene extends SceneGraphBase {
            shaderData.copyFrom(shaderAllocs);
            sceneManager.mRenderLoop.set_gFragmentShaders(shaderData);
        }
    }

    public void initRS() {
        SceneManager sceneManager = SceneManager.getInstance();
+8 −13
Original line number Diff line number Diff line
@@ -342,7 +342,7 @@ public class SceneManager extends SceneGraphBase {
            final String code = "\n" +
                "varying vec2 varTex0;\n" +
                "void main() {\n" +
                "   lowp vec4 col = texture2D(UNI_Tex0, varTex0).rgba;\n" +
                "   lowp vec4 col = UNI_color;\n" +
                "   gl_FragColor = col;\n" +
                "}\n";
            FragmentShader.Builder fb = new FragmentShader.Builder(rs);
@@ -360,12 +360,14 @@ public class SceneManager extends SceneGraphBase {
        }
        if (sSceneManager.mTexture == null) {
            RenderScriptGL rs = getRS();

            final String code = "\n" +
                "varying vec2 varTex0;\n" +
                "void main() {\n" +
                "   lowp vec4 col = UNI_color;\n" +
                "   lowp vec4 col = texture2D(UNI_Tex0, varTex0).rgba;\n" +
                "   gl_FragColor = col;\n" +
                "}\n";

            FragmentShader.Builder fb = new FragmentShader.Builder(rs);
            fb.setShader(code);
            fb.addTexture(Program.TextureType.TEXTURE_2D, "Tex0");
@@ -408,17 +410,10 @@ public class SceneManager extends SceneGraphBase {
        Mesh.TriangleMeshBuilder tmb = new Mesh.TriangleMeshBuilder(mRS,
                                           3, Mesh.TriangleMeshBuilder.TEXTURE_0);

        tmb.setTexture(0.0f, 1.0f);
        tmb.addVertex(-1.0f, 1.0f, 1.0f);

        tmb.setTexture(0.0f, 0.0f);
        tmb.addVertex(-1.0f, -1.0f, 1.0f);

        tmb.setTexture(1.0f, 0.0f);
        tmb.addVertex(1.0f, -1.0f, 1.0f);

        tmb.setTexture(1.0f, 1.0f);
        tmb.addVertex(1.0f, 1.0f, 1.0f);
        tmb.setTexture(0.0f, 1.0f).addVertex(-1.0f, 1.0f, 1.0f);
        tmb.setTexture(0.0f, 0.0f).addVertex(-1.0f, -1.0f, 1.0f);
        tmb.setTexture(1.0f, 0.0f).addVertex(1.0f, -1.0f, 1.0f);
        tmb.setTexture(1.0f, 1.0f).addVertex(1.0f, 1.0f, 1.0f);

        tmb.addTriangle(0, 1, 2);
        tmb.addTriangle(2, 3, 0);
Loading