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.util.Log;
23
24import android.renderscript.*;
25import android.content.res.Resources;
26
27/**
28 * @hide
29 */
30public class RenderPass extends SceneGraphBase {
31
32    TextureRenderTarget mColorTarget;
33    Float4 mClearColor;
34    boolean mShouldClearColor;
35
36    TextureRenderTarget mDepthTarget;
37    float mClearDepth;
38    boolean mShouldClearDepth;
39
40    ArrayList<RenderableBase> mObjectsToDraw;
41
42    Camera mCamera;
43
44    ScriptField_RenderPass_s.Item mRsField;
45
46    public RenderPass() {
47        mObjectsToDraw = new ArrayList<RenderableBase>();
48        mClearColor = new Float4(0.0f, 0.0f, 0.0f, 0.0f);
49        mShouldClearColor = true;
50        mClearDepth = 1.0f;
51        mShouldClearDepth = true;
52    }
53
54    public void appendRenderable(Renderable d) {
55        mObjectsToDraw.add(d);
56    }
57
58    public void setCamera(Camera c) {
59        mCamera = c;
60    }
61
62    public void setColorTarget(TextureRenderTarget colorTarget) {
63        mColorTarget = colorTarget;
64    }
65    public void setClearColor(Float4 clearColor) {
66        mClearColor = clearColor;
67    }
68    public void setShouldClearColor(boolean shouldClearColor) {
69        mShouldClearColor = shouldClearColor;
70    }
71
72    public void setDepthTarget(TextureRenderTarget depthTarget) {
73        mDepthTarget = depthTarget;
74    }
75    public void setClearDepth(float clearDepth) {
76        mClearDepth = clearDepth;
77    }
78    public void setShouldClearDepth(boolean shouldClearDepth) {
79        mShouldClearDepth = shouldClearDepth;
80    }
81
82    public ArrayList<RenderableBase> getRenderables() {
83        return mObjectsToDraw;
84    }
85
86    ScriptField_RenderPass_s.Item getRsField(RenderScriptGL rs, Resources res) {
87        if (mRsField != null) {
88            return mRsField;
89        }
90
91        mRsField = new ScriptField_RenderPass_s.Item();
92        if (mColorTarget != null) {
93            mRsField.color_target = mColorTarget.getRsData(true).get_texture(0);
94        }
95        if (mColorTarget != null) {
96            mRsField.depth_target = mDepthTarget.getRsData(true).get_texture(0);
97        }
98        mRsField.camera = mCamera != null ? mCamera.getRSData().getAllocation() : null;
99
100        if (mObjectsToDraw.size() != 0) {
101            Allocation drawableData = Allocation.createSized(rs,
102                                                              Element.ALLOCATION(rs),
103                                                              mObjectsToDraw.size());
104            Allocation[] drawableAllocs = new Allocation[mObjectsToDraw.size()];
105            for (int i = 0; i < mObjectsToDraw.size(); i ++) {
106                Renderable dI = (Renderable)mObjectsToDraw.get(i);
107                drawableAllocs[i] = dI.getRsField(rs, res).getAllocation();
108            }
109            drawableData.copyFrom(drawableAllocs);
110            mRsField.objects = drawableData;
111        }
112
113        mRsField.clear_color = mClearColor;
114        mRsField.clear_depth = mClearDepth;
115        mRsField.should_clear_color = mShouldClearColor;
116        mRsField.should_clear_depth = mShouldClearDepth;
117        return mRsField;
118    }
119}
120
121
122
123
124
125