Project

General

Profile

Download (7.67 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / effectqueue / EffectQueueSurfaceView.java @ 1585ba24

1 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 758303a3 Leszek Koltunski
package org.distorted.examples.effectqueue;
21 427ab7bf Leszek Koltunski
22 e4330c89 Leszek Koltunski
import android.app.ActivityManager;
23 427ab7bf Leszek Koltunski
import android.content.Context;
24 e4330c89 Leszek Koltunski
import android.content.pm.ConfigurationInfo;
25 427ab7bf Leszek Koltunski
import android.opengl.GLSurfaceView;
26
import android.view.MotionEvent;
27
import android.util.AttributeSet;
28
29 8dfa45c4 leszek
import org.distorted.library.effect.FragmentEffectAlpha;
30
import org.distorted.library.effect.FragmentEffectChroma;
31
import org.distorted.library.effect.FragmentEffectSaturation;
32
import org.distorted.library.effect.VertexEffectDistort;
33
import org.distorted.library.effect.VertexEffectSink;
34 59759251 Leszek Koltunski
import org.distorted.library.type.Dynamic1D;
35
import org.distorted.library.type.Static1D;
36 7589635e Leszek Koltunski
import org.distorted.library.type.Static3D;
37
import org.distorted.library.type.Static4D;
38
import org.distorted.library.type.Dynamic3D;
39 427ab7bf Leszek Koltunski
40 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
41 427ab7bf Leszek Koltunski
42 758303a3 Leszek Koltunski
public class EffectQueueSurfaceView extends GLSurfaceView
43 bc0a685b Leszek Koltunski
  {
44 1585ba24 Leszek Koltunski
  private static final int RADIUS = EffectQueueRenderer.BWID/6;
45 30c47368 Leszek Koltunski
46 758303a3 Leszek Koltunski
  private EffectQueueRenderer mRenderer;
47 3f07bedc Leszek Koltunski
  private int mCurrentEffect;
48
  private int mScrW, mScrH;
49 427ab7bf Leszek Koltunski
    
50 30c47368 Leszek Koltunski
  private Static4D mRegionV;
51 3f07bedc Leszek Koltunski
  private Dynamic1D mInterA, mInterB, mInterC, mInterS;
52
  private Dynamic3D mInterD;
53 f9afbbf3 Leszek Koltunski
54 1585ba24 Leszek Koltunski
  private final static Static3D mRED    = new Static3D(1,0,0);
55
  private final static Static3D mREGION = new Static3D(RADIUS,RADIUS,RADIUS);
56 f9afbbf3 Leszek Koltunski
57 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
58 427ab7bf Leszek Koltunski
    
59 41a81a14 Leszek Koltunski
  public EffectQueueSurfaceView(Context context, AttributeSet attrs)
60 bc0a685b Leszek Koltunski
    {
61 41a81a14 Leszek Koltunski
    super(context, attrs);
62 427ab7bf Leszek Koltunski
      
63 3f07bedc Leszek Koltunski
    int duration = 10000;
64
    float count  = 1.0f;
65 59759251 Leszek Koltunski
    int h = 30;
66
    int r = 20;
67
68 3f07bedc Leszek Koltunski
    mInterD = new Dynamic3D(duration,count);
69 59759251 Leszek Koltunski
70 3f07bedc Leszek Koltunski
    mInterD.add(new Static3D( 0, r, h ));
71
    mInterD.add(new Static3D(-r, 0, h ));
72
    mInterD.add(new Static3D( 0,-r, h ));
73
    mInterD.add(new Static3D( r, 0, h ));
74 59759251 Leszek Koltunski
75 3f07bedc Leszek Koltunski
    mInterA = new Dynamic1D(duration,count);
76 59759251 Leszek Koltunski
    mInterA.add(new Static1D(1));
77
    mInterA.add(new Static1D(0));
78
79 3f07bedc Leszek Koltunski
    mInterS = new Dynamic1D(duration,count);
80 b5cc7760 Leszek Koltunski
    mInterS.add(new Static1D(1.0f));
81
    mInterS.add(new Static1D(0.3f));
82
83 3f07bedc Leszek Koltunski
    mInterC = new Dynamic1D(duration,count);
84 f9afbbf3 Leszek Koltunski
    mInterC.add(new Static1D(1));
85
    mInterC.add(new Static1D(0));
86 59759251 Leszek Koltunski
87 3f07bedc Leszek Koltunski
    mInterB = new Dynamic1D(duration,count);
88 bdfec906 Leszek Koltunski
    mInterB.add(new Static1D(0));
89
    mInterB.add(new Static1D(1));
90 427ab7bf Leszek Koltunski
91 bc0a685b Leszek Koltunski
    if(!isInEditMode())
92
      {
93
      setFocusable(true);
94
      setFocusableInTouchMode(true);
95 758303a3 Leszek Koltunski
      mRenderer = new EffectQueueRenderer(this);
96 e4330c89 Leszek Koltunski
      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
97
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
98
      setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
99 bc0a685b Leszek Koltunski
      setRenderer(mRenderer);
100 9e7b6dbd Leszek Koltunski
      mRegionV= new Static4D(0,0,0,RADIUS);
101 bc0a685b Leszek Koltunski
      setEffect(0);  
102 427ab7bf Leszek Koltunski
      }
103 bc0a685b Leszek Koltunski
    }
104 427ab7bf Leszek Koltunski
105 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
106 427ab7bf Leszek Koltunski
107 758303a3 Leszek Koltunski
  EffectQueueRenderer getRenderer()
108 3f07bedc Leszek Koltunski
    {
109
    return mRenderer;
110
    }
111
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113
114
  public void setScreenSize(int width, int height)
115 bc0a685b Leszek Koltunski
    {
116
    mScrW = width;
117
    mScrH = height;
118
    }
119 427ab7bf Leszek Koltunski
120 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
121 427ab7bf Leszek Koltunski
122 3f07bedc Leszek Koltunski
  public void setEffect(int effect)
123 bc0a685b Leszek Koltunski
    {
124
    mCurrentEffect = effect;
125
    }
126 427ab7bf Leszek Koltunski
127 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
128 427ab7bf Leszek Koltunski
    
129 bc0a685b Leszek Koltunski
  @Override public boolean onTouchEvent(MotionEvent event) 
130
    {
131 8dfa45c4 leszek
    int x,y,action = event.getAction();
132
    boolean success;
133 af225332 Leszek Koltunski
134 bc0a685b Leszek Koltunski
    switch(action)
135 427ab7bf Leszek Koltunski
      {
136 3f07bedc Leszek Koltunski
      case MotionEvent.ACTION_DOWN: x = (int)event.getX()* mRenderer.BWID/mScrW;
137
                                    y = (int)event.getY()* mRenderer.BHEI/mScrH;
138 758303a3 Leszek Koltunski
                                    EffectQueueActivity act = (EffectQueueActivity)getContext();
139 59759251 Leszek Koltunski
140 427ab7bf Leszek Koltunski
                                    switch(mCurrentEffect)
141
                                      {
142 30c47368 Leszek Koltunski
                                      case 0: VertexEffectDistort distort = new VertexEffectDistort(mInterD, new Static3D(x,y,0), mRegionV);
143 8dfa45c4 leszek
                                              success = mRenderer.getEffects().apply(distort);
144
                                              act.effectAdded(success,distort);
145 e763f1ee Leszek Koltunski
                                              break;
146 30c47368 Leszek Koltunski
                                      case 1: VertexEffectSink sink = new VertexEffectSink(mInterS, new Static3D(x,y,0), mRegionV);
147 8dfa45c4 leszek
                                              success = mRenderer.getEffects().apply(sink);
148
                                              act.effectAdded(success,sink);
149 e763f1ee Leszek Koltunski
                                              break;
150 1585ba24 Leszek Koltunski
                                      case 2: FragmentEffectAlpha alpha = new FragmentEffectAlpha(mInterA, new Static3D(x,y,0), mREGION, true);
151 8dfa45c4 leszek
                                              success = mRenderer.getEffects().apply(alpha);
152
                                              act.effectAdded(success,alpha);
153 e763f1ee Leszek Koltunski
                                              break;
154 1585ba24 Leszek Koltunski
                                      case 3: FragmentEffectSaturation saturation = new FragmentEffectSaturation(mInterB, new Static3D(x,y,0), mREGION, false);
155 8dfa45c4 leszek
                                              success = mRenderer.getEffects().apply(saturation);
156
                                              act.effectAdded(success,saturation);
157 e763f1ee Leszek Koltunski
                                              break;
158 1585ba24 Leszek Koltunski
                                      case 4: FragmentEffectChroma chroma = new FragmentEffectChroma(mInterC, mRED, new Static3D(x,y,0), mREGION, true);
159 8dfa45c4 leszek
                                              success = mRenderer.getEffects().apply(chroma);
160
                                              act.effectAdded(success,chroma);
161 e763f1ee Leszek Koltunski
                                              break;
162 427ab7bf Leszek Koltunski
                                      }
163 af225332 Leszek Koltunski
164 427ab7bf Leszek Koltunski
                                    break;
165
      }
166 af225332 Leszek Koltunski
167 bc0a685b Leszek Koltunski
    return true;
168
    }
169 af225332 Leszek Koltunski
170 427ab7bf Leszek Koltunski
  }