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