Float4Param.java revision dd1da451159578d865230ceada3e1f0058e3c18e
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.RenderScriptGL; 23import android.renderscript.Float4; 24import android.renderscript.Matrix4f; 25import android.renderscript.ProgramFragment; 26import android.renderscript.ProgramStore; 27import android.renderscript.ProgramVertex; 28import android.renderscript.Element; 29import android.util.Log; 30 31/** 32 * @hide 33 */ 34public class Float4Param extends ShaderParam { 35 36 Float4 mValue; 37 Camera mCamera; 38 LightBase mLight; 39 int mVecSize; 40 41 public Float4Param(String name) { 42 super(name); 43 mValue = new Float4(); 44 } 45 46 public void setValue(Float4 v) { 47 mValue = v; 48 } 49 50 public Float4 getValue() { 51 return mValue; 52 } 53 54 public void setVecSize(int vecSize) { 55 mVecSize = vecSize; 56 } 57 58 public void setCamera(Camera c) { 59 mCamera = c; 60 } 61 62 public void setLight(LightBase l) { 63 mLight = l; 64 } 65 66 int getTypeFromName() { 67 int paramType = FLOAT4_DATA; 68 if (mParamName.equalsIgnoreCase(cameraPos)) { 69 paramType = FLOAT4_CAMERA_POS; 70 } else if(mParamName.equalsIgnoreCase(cameraDir)) { 71 paramType = FLOAT4_CAMERA_DIR; 72 } else if(mParamName.equalsIgnoreCase(lightColor)) { 73 paramType = FLOAT4_LIGHT_COLOR; 74 } else if(mParamName.equalsIgnoreCase(lightPos)) { 75 paramType = FLOAT4_LIGHT_POS; 76 } else if(mParamName.equalsIgnoreCase(lightDir)) { 77 paramType = FLOAT4_LIGHT_DIR; 78 } 79 return paramType; 80 } 81 82 void initLocalData(RenderScriptGL rs) { 83 mRsFieldItem.type = getTypeFromName(); 84 mRsFieldItem.bufferOffset = mOffset; 85 mRsFieldItem.float_value = mValue; 86 mRsFieldItem.float_vecSize = mVecSize; 87 if (mCamera != null) { 88 mRsFieldItem.camera = mCamera.getRSData(rs).getAllocation(); 89 } 90 if (mLight != null) { 91 mRsFieldItem.light = mLight.getRSData(rs).getAllocation(); 92 } 93 } 94} 95 96 97 98 99 100