blob: da0b146ef0ba0afa06a0a9d5205b5fee1eed0b2c [file] [log] [blame]
Jason Sams2a1cc8f2009-06-15 19:04:56 -07001/*
2 * Copyright (C) 2008 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.rollo;
18
19import java.io.Writer;
20
21import android.renderscript.RenderScript;
22import android.renderscript.ProgramVertexAlloc;
23
24import android.content.Context;
25import android.content.res.Resources;
26import android.graphics.Bitmap;
27import android.graphics.drawable.BitmapDrawable;
28import android.graphics.drawable.Drawable;
29import android.os.Handler;
30import android.os.Message;
31import android.util.AttributeSet;
32import android.util.Log;
33import android.view.Surface;
34import android.view.SurfaceHolder;
35import android.view.SurfaceView;
36import android.view.KeyEvent;
37import android.view.MotionEvent;
38
39public class RolloRS {
40
41 public RolloRS() {
42 }
43
44 public void init(RenderScript rs, Resources res, int width, int height) {
45 mRS = rs;
46 mRes = res;
47 initNamed();
48 initRS();
49 }
50
51
52 private Resources mRes;
53 private RenderScript mRS;
54
55
56 private RenderScript.Script mScript;
57
58 private RenderScript.Sampler mSampler;
59 private RenderScript.ProgramFragmentStore mPFSBackground;
60 private RenderScript.ProgramFragmentStore mPFSImages;
61 private RenderScript.ProgramFragment mPFBackground;
62 private RenderScript.ProgramFragment mPFImages;
63 private RenderScript.ProgramVertex mPV;
64 private ProgramVertexAlloc mPVAlloc;
65
66 private RenderScript.Allocation mAllocEnv;
67 private RenderScript.Allocation mAllocPos;
68 private RenderScript.Allocation mAllocState;
69 //private RenderScript.Allocation mAllocPV;
70 private RenderScript.TriangleMesh mMeshCard;
71 private RenderScript.TriangleMesh mMeshTab;
72
73 private float[] mBufferPos;
74 //private float[] mBufferPV;
75
76 private void initNamed() {
Jason Sams56bc1af2009-06-16 17:49:58 -070077 mMeshTab = RolloMesh.createTab(mRS);
78 mMeshTab.setName("MeshTab");
Jason Sams2a1cc8f2009-06-15 19:04:56 -070079 mMeshCard = RolloMesh.createCard(mRS);
80 mMeshCard.setName("MeshCard");
81 Log.e("rs", "Done loading strips");
82
83 mRS.samplerBegin();
84 mRS.samplerSet(RenderScript.SamplerParam.FILTER_MIN,
85 RenderScript.SamplerValue.LINEAR_MIP_LINEAR);
86 mRS.samplerSet(RenderScript.SamplerParam.WRAP_MODE_S,
87 RenderScript.SamplerValue.CLAMP);
88 mRS.samplerSet(RenderScript.SamplerParam.WRAP_MODE_T,
89 RenderScript.SamplerValue.CLAMP);
90 mSampler = mRS.samplerCreate();
91
92
93 mRS.programFragmentBegin(null, null);
94 mRS.programFragmentSetTexEnable(0, true);
95 //mRS.programFragmentSetEnvMode(0, RS_TEX_ENV_MODE_REPLACE);
96 mPFImages = mRS.programFragmentCreate();
97 mPFImages.setName("PF");
98 mPFImages.bindSampler(mSampler, 0);
99
100 mRS.programFragmentStoreBegin(null, null);
101 mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.ALWAYS);
102 mRS.programFragmentStoreDitherEnable(true);
103 mPFSBackground = mRS.programFragmentStoreCreate();
104 mPFSBackground.setName("PFSBackground");
105
106 /*
107 mRS.programFragmentStoreBegin(null, null);
108 mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.EQUAL);
109 mRS.programFragmentStoreDitherEnable(false);
110 mRS.programFragmentStoreDepthMask(false);
111 mRS.programFragmentStoreBlendFunc(RenderScript.BlendSrcFunc.ONE,
112 RenderScript.BlendDstFunc.ONE);
113 mPFSImages = mRS.programFragmentStoreCreate();
114 mPFSImages.setName("PFSImages");
115*/
116
117
118 mPVAlloc = new ProgramVertexAlloc(mRS);
119 mRS.programVertexBegin(null, null);
Jason Sams2a1cc8f2009-06-15 19:04:56 -0700120 mRS.programVertexSetTextureMatrixEnable(true);
Jason Sams2a1cc8f2009-06-15 19:04:56 -0700121 mPV = mRS.programVertexCreate();
122 mPV.setName("PV");
123 mPV.bindAllocation(0, mPVAlloc.mAlloc);
124
125 mPVAlloc.setupProjectionNormalized(320, 480);
126 //mPVAlloc.setupOrthoNormalized(320, 480);
127 mRS.contextBindProgramVertex(mPV);
128
129
130 Log.e("rs", "Done loading named");
131 }
132
133
134 private void initRS() {
135 mRS.scriptCBegin();
136 mRS.scriptCSetClearColor(0.0f, 0.7f, 0.0f, 1.0f);
137 mRS.scriptCSetScript(mRes, R.raw.rollo);
138 mRS.scriptCSetRoot(true);
139 mScript = mRS.scriptCCreate();
140
141
142 mRS.contextBindRootScript(mScript);
143 }
144}
145
146
147