Project

General

Profile

« Previous | Next » 

Revision c40df162

Added by Leszek Koltunski over 5 years ago

Improve the Triblur app to be able to switch objects into 1 of 3 states: no postprocessing, blur, glow.

View differences:

src/main/java/org/distorted/examples/triblur/TriblurActivity.java
37 37

  
38 38
public class TriblurActivity extends Activity implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener
39 39
{
40
    private static final int NONE0 = 0;
41
    private static final int NONE1 = 1;
42
    private static final int NONE2 = 2;
43
    private static final int BLUR0 = 3;
44
    private static final int BLUR1 = 4;
45
    private static final int BLUR2 = 5;
46
    private static final int GLOW0 = 6;
47
    private static final int GLOW1 = 7;
48
    private static final int GLOW2 = 8;
49

  
40 50
    private int mQuality;
41 51
    private int mBackground;
42 52

  
......
64 74

  
65 75
        privateQuality(1);
66 76
        privateBackgroundColor(1);
77
        privateEffect(BLUR0);
78
        privateEffect(BLUR1);
79
        privateEffect(BLUR2);
67 80
        }
68 81

  
69 82
      Spinner typeSpinner  = findViewById(R.id.triblur_spinnerQuality);
......
146 159
      TriblurSurfaceView view = this.findViewById(R.id.triblurSurfaceView);
147 160
      TriblurRenderer renderer = view.getRenderer();
148 161

  
149
      savedInstanceState.putBooleanArray("checkboxes", renderer.getChecked() );
162
      savedInstanceState.putIntArray("effects", renderer.getEffects() );
150 163
      savedInstanceState.putInt("quality", mQuality);
151 164
      savedInstanceState.putInt("background", mBackground);
152 165
      }
......
158 171
      {
159 172
      super.onRestoreInstanceState(savedInstanceState);
160 173

  
161
      boolean[] checkboxes = savedInstanceState.getBooleanArray("checkboxes");
174
      int[] effects = savedInstanceState.getIntArray("effects");
162 175

  
163 176
      TriblurSurfaceView view = this.findViewById(R.id.triblurSurfaceView);
164 177
      TriblurRenderer renderer = view.getRenderer();
165 178

  
166
      if( checkboxes!=null )
179
      if( effects!=null )
167 180
        {
168
        for(int i=0; i<checkboxes.length; i++)
181
        for(int i=0; i<effects.length; i++)
169 182
          {
170
          renderer.setChecked(i,checkboxes[i]);
183
          renderer.setEffects(i,effects[i]);
171 184
          }
172 185
        }
173 186

  
......
206 219

  
207 220
///////////////////////////////////////////////////////////////////////////////////////////////////
208 221

  
209
  public void onClick(View view)
222
  public void effect(View v)
223
    {
224
    switch(v.getId())
225
      {
226
      case R.id.triblurRadioNone0: privateEffect(NONE0); break;
227
      case R.id.triblurRadioNone1: privateEffect(NONE1); break;
228
      case R.id.triblurRadioNone2: privateEffect(NONE2); break;
229
      case R.id.triblurRadioBlur0: privateEffect(BLUR0); break;
230
      case R.id.triblurRadioBlur1: privateEffect(BLUR1); break;
231
      case R.id.triblurRadioBlur2: privateEffect(BLUR2); break;
232
      case R.id.triblurRadioGlow0: privateEffect(GLOW0); break;
233
      case R.id.triblurRadioGlow1: privateEffect(GLOW1); break;
234
      case R.id.triblurRadioGlow2: privateEffect(GLOW2); break;
235
      }
236
    }
237

  
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

  
240
  private void privateEffect(int index)
210 241
    {
211
    CheckBox box = (CheckBox)view;
212
    boolean checked = box.isChecked();
213
    TriblurSurfaceView sView = this.findViewById(R.id.triblurSurfaceView);
242
    TriblurSurfaceView view = this.findViewById(R.id.triblurSurfaceView);
243
    TriblurRenderer renderer = view.getRenderer();
214 244

  
215
    switch(box.getId())
245
    switch(index)
216 246
      {
217
      case R.id.triblurCheckBox0  : sView.getRenderer().setChecked(0,checked); break;
218
      case R.id.triblurCheckBox1  : sView.getRenderer().setChecked(1,checked); break;
219
      case R.id.triblurCheckBox2  : sView.getRenderer().setChecked(2,checked); break;
247
      case NONE0: renderer.setEffects(0,0); break;
248
      case NONE1: renderer.setEffects(1,0); break;
249
      case NONE2: renderer.setEffects(2,0); break;
250
      case BLUR0: renderer.setEffects(0,1); break;
251
      case BLUR1: renderer.setEffects(1,1); break;
252
      case BLUR2: renderer.setEffects(2,1); break;
253
      case GLOW0: renderer.setEffects(0,2); break;
254
      case GLOW1: renderer.setEffects(1,2); break;
255
      case GLOW2: renderer.setEffects(2,2); break;
220 256
      }
221 257
    }
222 258

  
src/main/java/org/distorted/examples/triblur/TriblurRenderer.java
25 25

  
26 26
import org.distorted.examples.R;
27 27
import org.distorted.library.effect.EffectQuality;
28
import org.distorted.library.effect.EffectType;
28 29
import org.distorted.library.effect.FragmentEffectChroma;
29 30
import org.distorted.library.effect.MatrixEffectMove;
30 31
import org.distorted.library.effect.MatrixEffectQuaternion;
31 32
import org.distorted.library.effect.MatrixEffectScale;
32 33
import org.distorted.library.effect.PostprocessEffectBlur;
34
import org.distorted.library.effect.PostprocessEffectGlow;
33 35
import org.distorted.library.main.Distorted;
34 36
import org.distorted.library.main.DistortedEffects;
35 37
import org.distorted.library.main.DistortedNode;
......
65 67
    private GLSurfaceView mView;
66 68
    private DistortedTexture mTex;
67 69
    private DistortedNode[] mNode;
68
    private Static1D[]  mBlurVector;
70
    private Static1D[]  mEffectVector;
69 71
    private DistortedScreen mScreen;
70 72
    private PostprocessEffectBlur[] mBlur;
71
    private boolean[] mBlurStatus;
73
    private PostprocessEffectGlow[] mGlow;
74
    private int[] mEffectStatus;
72 75
    private Static3D mMove1, mMove2, mScale1, mScale2, mCenter;
73 76

  
74 77
    Static4D mQuat1, mQuat2;
......
90 93
      mScreen = new DistortedScreen();
91 94
      mScreen.showFPS();
92 95

  
93
      mBlurStatus   = new boolean[NUM_OBJECTS];
94
      mBlurVector   = new Static1D[NUM_OBJECTS];
96
      mEffectStatus = new int[NUM_OBJECTS];
97
      mEffectVector = new Static1D[NUM_OBJECTS];
95 98
      mNode         = new DistortedNode[NUM_OBJECTS];
96 99
      mBlur         = new PostprocessEffectBlur[NUM_OBJECTS];
100
      mGlow         = new PostprocessEffectGlow[NUM_OBJECTS];
97 101

  
98 102
      FragmentEffectChroma[] chroma= new FragmentEffectChroma[NUM_OBJECTS];
99 103
      Static3D[] chromaVector      = new Static3D[NUM_OBJECTS];
......
118 122
        {
119 123
        moveVector[i]    = new Static3D(OBJECTS[NUM*i  ], OBJECTS[NUM*i+1], OBJECTS[NUM*i+2]);
120 124
        chromaVector[i]  = new Static3D(OBJECTS[NUM*i+3], OBJECTS[NUM*i+4], OBJECTS[NUM*i+5]);
121
        mBlurVector[i]   = new Static1D(10);
122
        mBlur[i]         = new PostprocessEffectBlur(mBlurVector[i]);
125
        mEffectVector[i] = new Static1D(10);
126
        mBlur[i]         = new PostprocessEffectBlur(mEffectVector[i]);
127
        mGlow[i]         = new PostprocessEffectGlow(mEffectVector[i], new Static4D(1.0f,1.0f,1.0f,0.5f) );
123 128
        chroma[i]        = new FragmentEffectChroma( new Static1D(0.3f), chromaVector[i]);
124 129
        effects[i]       = new DistortedEffects();
125 130

  
......
131 136
        effects[i].apply(quatEffect2);
132 137
        effects[i].apply(new MatrixEffectMove(moveVector[i]));
133 138

  
134
        mBlurStatus[i] = true;
139
        mEffectStatus[i] = 1;
135 140
        mNode[i] = new DistortedNode(mTex, effects[i], mesh );
136 141
        mScreen.attach(mNode[i]);
137 142
        }
......
227 232
      {
228 233
      if( object>=0 && object<NUM_OBJECTS )
229 234
        {
230
        mBlurVector[object].set(range / 2);
235
        mEffectVector[object].set(range / 2);
231 236
        }
232 237
      }
233 238

  
234 239
///////////////////////////////////////////////////////////////////////////////////////////////////
235 240

  
236
    boolean[] getChecked()
241
    int[] getEffects()
237 242
     {
238
     return mBlurStatus;
243
     return mEffectStatus;
239 244
     }
240 245

  
241 246
///////////////////////////////////////////////////////////////////////////////////////////////////
242 247

  
243
    void setChecked(int object, boolean checked)
248
    void setEffects(int object, int effect)
244 249
      {
245 250
      if( object>=0 && object<NUM_OBJECTS )
246 251
        {
247
        if( checked && !mBlurStatus[object] )
252
        if( mEffectStatus[object] != effect )
248 253
          {
249
          mBlurStatus[object] = true;
250
          mNode[object].getEffects().apply(mBlur[object]);
251
          }
252
        if( !checked && mBlurStatus[object] )
253
          {
254
          mBlurStatus[object] = false;
255
          mNode[object].getEffects().abortEffect(mBlur[object]);
254
          mEffectStatus[object] = effect;
255
          mNode[object].getEffects().abortByType(EffectType.POSTPROCESS);
256

  
257
          if( effect==1 ) mNode[object].getEffects().apply(mBlur[object]);
258
          if( effect==2 ) mNode[object].getEffects().apply(mGlow[object]);
256 259
          }
257 260
        }
258 261
      else
259 262
        {
260
        android.util.Log.e("renderer", "Error, number: "+object+" checked: "+checked );
263
        android.util.Log.e("renderer", "Error, number: "+object+" effect: "+effect );
261 264
        }
262 265

  
263 266
      //android.util.Log.d("renderer", "setting box "+number+" BLUR state to "+checked);
src/main/res/layout/triblurlayout.xml
10 10
        android:layout_height="0dp"
11 11
        android:layout_weight="1" />
12 12

  
13

  
14 13
    <LinearLayout
15 14
        android:id="@+id/linearLayout3"
16 15
        android:layout_width="fill_parent"
......
35 34
    </LinearLayout>
36 35

  
37 36
    <LinearLayout
38
        android:orientation="horizontal"
39
        android:background="@color/red"
40 37
        android:layout_width="match_parent"
41
        android:layout_height="50dp"
42
        android:paddingBottom="10dp"
43
        android:paddingTop="10dp">
38
        android:layout_height="60dp"
39
        android:background="@color/red"
40
        android:orientation="horizontal"
41
        android:paddingTop="5dp">
44 42

  
45
        <CheckBox
46
            android:layout_height="fill_parent"
47
            android:layout_width="wrap_content"
48
            android:id="@+id/triblurCheckBox0"
49
            android:paddingLeft="10dp"
50
            android:onClick="onClick"
51
            android:checked="true"/>
43
        <RadioGroup
44
            android:id="@+id/triblurRadio0"
45
            android:layout_width="0dp"
46
            android:layout_height="wrap_content"
47
            android:layout_weight="0.6"
48
            android:orientation="horizontal">
49

  
50
            <RadioButton
51
                android:id="@+id/triblurRadioNone0"
52
                android:layout_width="match_parent"
53
                android:layout_height="wrap_content"
54
                android:layout_weight="1"
55
                android:onClick="effect"
56
                android:text="@string/none"
57
                android:textSize="14sp" />
58

  
59
            <RadioButton
60
                android:id="@+id/triblurRadioBlur0"
61
                android:layout_width="match_parent"
62
                android:layout_height="wrap_content"
63
                android:layout_weight="1"
64
                android:checked="true"
65
                android:onClick="effect"
66
                android:text="@string/blur"
67
                android:textSize="14sp" />
68

  
69
            <RadioButton
70
                android:id="@+id/triblurRadioGlow0"
71
                android:layout_width="match_parent"
72
                android:layout_height="wrap_content"
73
                android:layout_weight="1"
74
                android:onClick="effect"
75
                android:text="@string/glow"
76
                android:textSize="14sp" />
77

  
78
        </RadioGroup>
52 79

  
53 80
        <SeekBar
54 81
            android:id="@+id/triblurSeek0"
82
            android:layout_width="wrap_content"
55 83
            android:layout_height="fill_parent"
56
            android:layout_width="fill_parent"
57
            android:paddingLeft="10dp"
58
            android:paddingRight="10dp" />
84
            android:layout_weight="0.4"
85
            android:paddingLeft="5dp"
86
            android:paddingRight="5dp" />
59 87
    </LinearLayout>
60 88

  
61 89
    <LinearLayout
62
        android:orientation="horizontal"
63
        android:background="@color/yellow"
64 90
        android:layout_width="match_parent"
65
        android:layout_height="50dp"
66
        android:paddingBottom="10dp"
67
        android:paddingTop="10dp">
91
        android:layout_height="60dp"
92
        android:background="@color/yellow"
93
        android:orientation="horizontal"
94
        android:paddingTop="5dp">
68 95

  
69
        <CheckBox
70
            android:layout_height="fill_parent"
71
            android:layout_width="wrap_content"
72
            android:id="@+id/triblurCheckBox1"
73
            android:paddingLeft="10dp"
74
            android:onClick="onClick"
75
            android:checked="true"/>
96
        <RadioGroup
97
            android:id="@+id/triblurRadio1"
98
            android:layout_width="0dp"
99
            android:layout_height="wrap_content"
100
            android:layout_weight="0.6"
101
            android:orientation="horizontal">
102

  
103
            <RadioButton
104
                android:id="@+id/triblurRadioNone1"
105
                android:layout_width="match_parent"
106
                android:layout_height="wrap_content"
107
                android:layout_weight="1"
108
                android:onClick="effect"
109
                android:text="@string/none"
110
                android:textSize="14sp" />
111

  
112
            <RadioButton
113
                android:id="@+id/triblurRadioBlur1"
114
                android:layout_width="match_parent"
115
                android:layout_height="wrap_content"
116
                android:layout_weight="1"
117
                android:checked="true"
118
                android:onClick="effect"
119
                android:text="@string/blur"
120
                android:textSize="14sp" />
121

  
122
            <RadioButton
123
                android:id="@+id/triblurRadioGlow1"
124
                android:layout_width="match_parent"
125
                android:layout_height="wrap_content"
126
                android:layout_weight="1"
127
                android:onClick="effect"
128
                android:text="@string/glow"
129
                android:textSize="14sp" />
130

  
131
        </RadioGroup>
76 132

  
77 133
        <SeekBar
78 134
            android:id="@+id/triblurSeek1"
135
            android:layout_width="wrap_content"
79 136
            android:layout_height="fill_parent"
80
            android:layout_width="fill_parent"
81
            android:paddingLeft="10dp"
82
            android:paddingRight="10dp" />
137
            android:layout_weight="0.4"
138
            android:paddingLeft="5dp"
139
            android:paddingRight="5dp" />
83 140
    </LinearLayout>
84 141

  
85 142
    <LinearLayout
86
        android:orientation="horizontal"
87
        android:background="@color/green"
88 143
        android:layout_width="match_parent"
89
        android:layout_height="50dp"
90
        android:paddingBottom="10dp"
91
        android:paddingTop="10dp">
144
        android:layout_height="60dp"
145
        android:background="@color/green"
146
        android:orientation="horizontal"
147
        android:paddingTop="5dp">
92 148

  
93
        <CheckBox
94
            android:layout_height="fill_parent"
95
            android:layout_width="wrap_content"
96
            android:id="@+id/triblurCheckBox2"
97
            android:paddingLeft="10dp"
98
            android:onClick="onClick"
99
            android:checked="true"/>
149
        <RadioGroup
150
            android:id="@+id/triblurRadio2"
151
            android:layout_width="0dp"
152
            android:layout_height="wrap_content"
153
            android:layout_weight="0.6"
154
            android:orientation="horizontal">
155

  
156
            <RadioButton
157
                android:id="@+id/triblurRadioNone2"
158
                android:layout_width="match_parent"
159
                android:layout_height="wrap_content"
160
                android:layout_weight="1"
161
                android:onClick="effect"
162
                android:text="@string/none"
163
                android:textSize="14sp" />
164

  
165
            <RadioButton
166
                android:id="@+id/triblurRadioBlur2"
167
                android:layout_width="match_parent"
168
                android:layout_height="wrap_content"
169
                android:layout_weight="1"
170
                android:checked="true"
171
                android:onClick="effect"
172
                android:text="@string/blur"
173
                android:textSize="14sp" />
174

  
175
            <RadioButton
176
                android:id="@+id/triblurRadioGlow2"
177
                android:layout_width="match_parent"
178
                android:layout_height="wrap_content"
179
                android:layout_weight="1"
180
                android:onClick="effect"
181
                android:text="@string/glow"
182
                android:textSize="14sp" />
183

  
184
        </RadioGroup>
100 185

  
101 186
        <SeekBar
102 187
            android:id="@+id/triblurSeek2"
188
            android:layout_width="wrap_content"
103 189
            android:layout_height="fill_parent"
104
            android:layout_width="fill_parent"
105
            android:paddingLeft="10dp"
106
            android:paddingRight="10dp" />
190
            android:layout_weight="0.4"
191
            android:paddingLeft="5dp"
192
            android:paddingRight="5dp" />
107 193
    </LinearLayout>
108 194

  
109 195
    <LinearLayout
......
113 199
        android:gravity="center|fill_horizontal"
114 200
        android:orientation="horizontal"
115 201
        android:background="@color/cyan"
116
        android:paddingBottom="10dp"
117
        android:paddingTop="10dp" >
202
        android:paddingBottom="2dp"
203
        android:paddingTop="2dp" >
118 204

  
119 205
        <RadioGroup
120 206
            android:id="@+id/triblurRadioBackground"
src/main/res/values/strings.xml
14 14
    <string name="contrast">Contrast</string>
15 15
    <string name="swirl">Swirl</string>
16 16
    <string name="blur">Blur</string>
17
    <string name="glow">Glow</string>
17 18

  
18 19
    <string name="type_matrix">Matrix</string>
19 20
    <string name="type_vertex">Vertex</string>
......
76 77
    <string name="framebuffer">Framebuffer</string>
77 78
    <string name="matrixautomatic">Automatic Matrix Effects</string>
78 79
    <string name="inflate">Inflate</string>
80
    <string name="none">None</string>
79 81

  
80 82
    <string name="quality0">Highest</string>
81 83
    <string name="quality1">High</string>

Also available in: Unified diff