RenderState.java revision 5121da171e0215f3bcd5d1fb0b147e7ed3c295a9
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.ProgramRaster; 27import android.renderscript.ProgramStore; 28import android.renderscript.ProgramVertex; 29import android.renderscript.RSRuntimeException; 30import android.renderscript.RenderScript; 31import android.renderscript.RenderScriptGL; 32import android.util.Log; 33 34/** 35 * @hide 36 */ 37public class RenderState extends SceneGraphBase { 38 VertexShader mVertex; 39 FragmentShader mFragment; 40 ProgramStore mStore; 41 ProgramRaster mRaster; 42 43 ScriptField_RenderState_s mField; 44 45 public RenderState(VertexShader pv, 46 FragmentShader pf, 47 ProgramStore ps, 48 ProgramRaster pr) { 49 mVertex = pv; 50 mFragment = pf; 51 mStore = ps; 52 mRaster = pr; 53 } 54 55 public RenderState(RenderState r) { 56 mVertex = r.mVertex; 57 mFragment = r.mFragment; 58 mStore = r.mStore; 59 mRaster = r.mRaster; 60 } 61 62 public void setProgramVertex(VertexShader pv) { 63 mVertex = pv; 64 } 65 66 public void setProgramFragment(FragmentShader pf) { 67 mFragment = pf; 68 } 69 70 public void setProgramStore(ProgramStore ps) { 71 mStore = ps; 72 } 73 74 public void setProgramRaster(ProgramRaster pr) { 75 mRaster = pr; 76 } 77 78 public ScriptField_RenderState_s getRSData(RenderScriptGL rs) { 79 if (mField != null) { 80 return mField; 81 } 82 83 ScriptField_RenderState_s.Item item = new ScriptField_RenderState_s.Item(); 84 item.pv = mVertex.getRSData(rs).getAllocation(); 85 item.pf = mFragment.getRSData(rs).getAllocation(); 86 item.ps = mStore; 87 item.pr = mRaster; 88 89 mField = new ScriptField_RenderState_s(rs, 1); 90 mField.set(item, 0, true); 91 return mField; 92 } 93} 94