Project

General

Profile

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

examples / src / main / java / org / distorted / examples / effectqueue / EffectQueueSurfaceView.java @ d218d64e

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 41a81a14 Leszek Koltunski
import android.app.ActivityManager;
23 427ab7bf Leszek Koltunski
import android.content.Context;
24 41a81a14 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 e763f1ee Leszek Koltunski
import org.distorted.library.EffectNames;
30
import org.distorted.library.EffectTypes;
31 59759251 Leszek Koltunski
import org.distorted.library.type.Dynamic1D;
32
import org.distorted.library.type.Static1D;
33 7589635e Leszek Koltunski
import org.distorted.library.type.Static3D;
34
import org.distorted.library.type.Static4D;
35
import org.distorted.library.type.Dynamic3D;
36 427ab7bf Leszek Koltunski
37 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
38 427ab7bf Leszek Koltunski
39 758303a3 Leszek Koltunski
public class EffectQueueSurfaceView extends GLSurfaceView
40 bc0a685b Leszek Koltunski
  {
41 758303a3 Leszek Koltunski
  private EffectQueueRenderer mRenderer;
42 3f07bedc Leszek Koltunski
  private int mCurrentEffect;
43
  private int mScrW, mScrH;
44 427ab7bf Leszek Koltunski
    
45 3f07bedc Leszek Koltunski
  private Static4D mRegionV, mRegionF;
46 334c13fa Leszek Koltunski
  private Static3D mPoint;
47 3f07bedc Leszek Koltunski
  private Dynamic1D mInterA, mInterB, mInterC, mInterS;
48
  private Dynamic3D mInterD;
49 f9afbbf3 Leszek Koltunski
50
  private final static Static3D mRED = new Static3D(1,0,0);
51
52 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
53 427ab7bf Leszek Koltunski
    
54 41a81a14 Leszek Koltunski
  public EffectQueueSurfaceView(Context context, AttributeSet attrs)
55 bc0a685b Leszek Koltunski
    {
56 41a81a14 Leszek Koltunski
    super(context, attrs);
57 427ab7bf Leszek Koltunski
      
58 3f07bedc Leszek Koltunski
    int duration = 10000;
59
    float count  = 1.0f;
60 59759251 Leszek Koltunski
    int h = 30;
61
    int r = 20;
62
63 3f07bedc Leszek Koltunski
    mInterD = new Dynamic3D(duration,count);
64 59759251 Leszek Koltunski
65 3f07bedc Leszek Koltunski
    mInterD.add(new Static3D( 0, r, h ));
66
    mInterD.add(new Static3D(-r, 0, h ));
67
    mInterD.add(new Static3D( 0,-r, h ));
68
    mInterD.add(new Static3D( r, 0, h ));
69 59759251 Leszek Koltunski
70 3f07bedc Leszek Koltunski
    mInterA = new Dynamic1D(duration,count);
71 59759251 Leszek Koltunski
    mInterA.add(new Static1D(1));
72
    mInterA.add(new Static1D(0));
73
74 3f07bedc Leszek Koltunski
    mInterS = new Dynamic1D(duration,count);
75 b5cc7760 Leszek Koltunski
    mInterS.add(new Static1D(1.0f));
76
    mInterS.add(new Static1D(0.3f));
77
78 3f07bedc Leszek Koltunski
    mInterC = new Dynamic1D(duration,count);
79 f9afbbf3 Leszek Koltunski
    mInterC.add(new Static1D(1));
80
    mInterC.add(new Static1D(0));
81 59759251 Leszek Koltunski
82 3f07bedc Leszek Koltunski
    mInterB = new Dynamic1D(duration,count);
83 bdfec906 Leszek Koltunski
    mInterB.add(new Static1D(0));
84
    mInterB.add(new Static1D(1));
85 427ab7bf Leszek Koltunski
86 bc0a685b Leszek Koltunski
    if(!isInEditMode())
87
      {
88
      setFocusable(true);
89
      setFocusableInTouchMode(true);
90 41a81a14 Leszek Koltunski
      final ActivityManager activityManager     = (android.app.ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
91
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
92
      android.util.Log.e("View", "Using OpenGL ES "+configurationInfo.getGlEsVersion());
93
      setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
94 525699f4 Leszek Koltunski
95 758303a3 Leszek Koltunski
      mRenderer = new EffectQueueRenderer(this);
96 bc0a685b Leszek Koltunski
      setRenderer(mRenderer);
97 af225332 Leszek Koltunski
98 334c13fa Leszek Koltunski
      mPoint  = new Static3D(0,0,0);
99 3f07bedc Leszek Koltunski
      mRegionV= new Static4D(0,0,60,60);
100
      mRegionF= new Static4D(0,0,60,60);
101 427ab7bf Leszek Koltunski
        
102 bc0a685b Leszek Koltunski
      setEffect(0);  
103 427ab7bf Leszek Koltunski
      }
104 bc0a685b Leszek Koltunski
    }
105 427ab7bf Leszek Koltunski
106 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
107 427ab7bf Leszek Koltunski
108 758303a3 Leszek Koltunski
  EffectQueueRenderer getRenderer()
109 3f07bedc Leszek Koltunski
    {
110
    return mRenderer;
111
    }
112
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114
115
  public void setScreenSize(int width, int height)
116 bc0a685b Leszek Koltunski
    {
117
    mScrW = width;
118
    mScrH = height;
119
    }
120 427ab7bf Leszek Koltunski
121 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
122 427ab7bf Leszek Koltunski
123 3f07bedc Leszek Koltunski
  public void setEffect(int effect)
124 bc0a685b Leszek Koltunski
    {
125
    mCurrentEffect = effect;
126
    }
127 427ab7bf Leszek Koltunski
128 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
129 427ab7bf Leszek Koltunski
    
130 bc0a685b Leszek Koltunski
  @Override public boolean onTouchEvent(MotionEvent event) 
131
    {
132
    int action = event.getAction();
133
    int x, y;
134 84dd0d8f Leszek Koltunski
    long id;
135 af225332 Leszek Koltunski
136 bc0a685b Leszek Koltunski
    switch(action)
137 427ab7bf Leszek Koltunski
      {
138 3f07bedc Leszek Koltunski
      case MotionEvent.ACTION_DOWN: x = (int)event.getX()* mRenderer.BWID/mScrW;
139
                                    y = (int)event.getY()* mRenderer.BHEI/mScrH;
140 334c13fa Leszek Koltunski
                                    mPoint.set(x,y,0);
141 3f07bedc Leszek Koltunski
                                    mRegionF.set(x,y,60,60);
142 758303a3 Leszek Koltunski
                                    EffectQueueActivity act = (EffectQueueActivity)getContext();
143 59759251 Leszek Koltunski
144 427ab7bf Leszek Koltunski
                                    switch(mCurrentEffect)
145
                                      {
146 d04a4886 Leszek Koltunski
                                      case 0: id = mRenderer.getEffects().distort(mInterD, mPoint, mRegionV);
147 e763f1ee Leszek Koltunski
                                              act.effectAdded(id, EffectNames.DISTORT, EffectTypes.VERTEX);
148
                                              break;
149 d04a4886 Leszek Koltunski
                                      case 1: id = mRenderer.getEffects().sink(mInterS, mPoint, mRegionV);
150 e763f1ee Leszek Koltunski
                                              act.effectAdded(id, EffectNames.SINK, EffectTypes.VERTEX);
151
                                              break;
152 d04a4886 Leszek Koltunski
                                      case 2: id = mRenderer.getEffects().alpha(mInterA, mRegionF, true);
153 e763f1ee Leszek Koltunski
                                              act.effectAdded(id, EffectNames.ALPHA, EffectTypes.FRAGMENT);
154
                                              break;
155 d04a4886 Leszek Koltunski
                                      case 3: id = mRenderer.getEffects().saturation(mInterB, mRegionF, false);
156 63fc1eaf Leszek Koltunski
                                              act.effectAdded(id, EffectNames.SATURATION, EffectTypes.FRAGMENT);
157 e763f1ee Leszek Koltunski
                                              break;
158 d04a4886 Leszek Koltunski
                                      case 4: id = mRenderer.getEffects().chroma(mInterC, mRED, mRegionF, true);
159 e763f1ee Leszek Koltunski
                                              act.effectAdded(id, EffectNames.CHROMA, EffectTypes.FRAGMENT);
160
                                              break;
161 427ab7bf Leszek Koltunski
                                      }
162 af225332 Leszek Koltunski
163 427ab7bf Leszek Koltunski
                                    break;
164
      }
165 af225332 Leszek Koltunski
166 bc0a685b Leszek Koltunski
    return true;
167
    }
168 af225332 Leszek Koltunski
169 427ab7bf Leszek Koltunski
  }