Texture2D.java revision e8bb420a687598be9801e7ff4a0d114fa72ac5bc
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; 20 21import com.android.scenegraph.SceneManager; 22 23import android.content.res.Resources; 24import android.renderscript.*; 25import android.util.Log; 26 27/** 28 * @hide 29 */ 30public class Texture2D extends TextureBase { 31 String mFileName; 32 String mFileDir; 33 34 public Texture2D() { 35 super(ScriptC_export.const_TextureType_TEXTURE_2D); 36 } 37 38 public Texture2D(Allocation tex) { 39 super(ScriptC_export.const_TextureType_TEXTURE_2D); 40 setTexture(tex); 41 } 42 43 public void setFileDir(String dir) { 44 mFileDir = dir; 45 } 46 47 public void setFileName(String file) { 48 mFileName = file; 49 } 50 51 public String getFileName() { 52 return mFileName; 53 } 54 55 public void setTexture(Allocation tex) { 56 mData.texture = tex; 57 if (mField != null) { 58 mField.set_texture(0, mData.texture, true); 59 } 60 } 61 62 void load() { 63 RenderScriptGL rs = SceneManager.getRS(); 64 Resources res = SceneManager.getRes(); 65 String shortName = mFileName.substring(mFileName.lastIndexOf('/') + 1); 66 setTexture(SceneManager.loadTexture2D(mFileDir + shortName, rs, res)); 67 } 68 69 ScriptField_Texture_s getRsData(boolean loadNow) { 70 if (mField != null) { 71 return mField; 72 } 73 74 RenderScriptGL rs = SceneManager.getRS(); 75 Resources res = SceneManager.getRes(); 76 if (rs == null || res == null) { 77 return null; 78 } 79 80 mField = new ScriptField_Texture_s(rs, 1); 81 82 if (loadNow) { 83 load(); 84 } else { 85 mData.texture = SceneManager.getDefaultTex2D(); 86 new SingleImageLoaderTask().execute(this); 87 } 88 89 mField.set(mData, 0, true); 90 return mField; 91 } 92} 93 94 95 96 97 98