SceneGraphBase.java revision a7a211b8a68a7d3f5ff4409aa286db07f96c0550
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.scenegraph;
18
19import java.lang.Math;
20import java.util.ArrayList;
21
22import android.renderscript.Allocation;
23import android.renderscript.Element;
24import android.renderscript.Matrix4f;
25import android.renderscript.ProgramFragment;
26import android.renderscript.ProgramStore;
27import android.renderscript.ProgramVertex;
28import android.renderscript.RenderScript;
29import android.renderscript.RSRuntimeException;
30
31import android.util.Log;
32
33/**
34 * @hide
35 */
36public abstract class SceneGraphBase {
37    String mName;
38    public void setName(String n) {
39        mName = n;
40    }
41
42    public String getName() {
43        return mName;
44    }
45
46    Allocation getStringAsAllocation(RenderScript rs, String str) {
47        if (str == null) {
48            return null;
49        }
50        if (str.length() == 0) {
51            return null;
52        }
53        byte[] allocArray = null;
54        byte[] nullChar = new byte[1];
55        nullChar[0] = 0;
56        try {
57            allocArray = str.getBytes("UTF-8");
58            Allocation alloc = Allocation.createSized(rs, Element.U8(rs),
59                                                      allocArray.length + 1,
60                                                      Allocation.USAGE_SCRIPT);
61            alloc.copy1DRangeFrom(0, allocArray.length, allocArray);
62            alloc.copy1DRangeFrom(allocArray.length, 1, nullChar);
63            return alloc;
64        }
65        catch (Exception e) {
66            throw new RSRuntimeException("Could not convert string to utf-8.");
67        }
68    }
69}
70
71
72
73
74
75