Home | History | Annotate | Download | only in scenegraph
      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 import java.util.ArrayList;
     21 import java.util.HashMap;
     22 
     23 import com.android.scenegraph.SceneGraphBase;
     24 import com.android.scenegraph.ShaderParam;
     25 
     26 import android.renderscript.*;
     27 import android.renderscript.ProgramFragment.Builder;
     28 import android.util.Log;
     29 
     30 /**
     31  * @hide
     32  */
     33 public abstract class Shader extends SceneGraphBase {
     34     protected Type mPerObjConstants;
     35     protected Type mPerShaderConstants;
     36 
     37     protected HashMap<String, ShaderParam> mSourceParams;
     38     protected ArrayList<String> mShaderTextureNames;
     39     protected ArrayList<Program.TextureType > mShaderTextureTypes;
     40     protected ArrayList<String> mTextureNames;
     41     protected ArrayList<Program.TextureType > mTextureTypes;
     42 
     43     protected Allocation mConstantBuffer;
     44     protected ScriptField_ShaderParam_s mConstantBufferParams;
     45 
     46     public Shader() {
     47         mSourceParams = new HashMap<String, ShaderParam>();
     48         mShaderTextureNames = new ArrayList<String>();
     49         mShaderTextureTypes = new ArrayList<Program.TextureType>();
     50         mTextureNames = new ArrayList<String>();
     51         mTextureTypes = new ArrayList<Program.TextureType>();
     52     }
     53 
     54     public void appendSourceParams(ShaderParam p) {
     55         mSourceParams.put(p.getParamName(), p);
     56     }
     57 
     58     public Type getObjectConstants() {
     59         return mPerObjConstants;
     60     }
     61 
     62     public Type getShaderConstants() {
     63         return mPerObjConstants;
     64     }
     65 
     66     void linkConstants(RenderScriptGL rs) {
     67         if (mPerShaderConstants == null) {
     68             return;
     69         }
     70 
     71         Element constElem = mPerShaderConstants.getElement();
     72         mConstantBufferParams  = ShaderParam.fillInParams(constElem, mSourceParams, null);
     73 
     74         mConstantBuffer = Allocation.createTyped(rs, mPerShaderConstants);
     75     }
     76 }
     77