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