Project

General

Profile

« Previous | Next » 

Revision dc10a48d

Added by Leszek Koltunski about 1 year ago

Decouple (to a large degree) the OpenGL Library from Android.

View differences:

src/main/java/org/distorted/examples/listener/ListenerRenderer.java
40 40
import org.distorted.library.type.Static4D;
41 41
import org.distorted.library.message.EffectListener;
42 42

  
43
import android.app.ActivityManager;
44
import android.content.Context;
45
import android.content.pm.ConfigurationInfo;
46
import android.content.res.Resources;
43 47
import android.graphics.Bitmap;
44 48
import android.graphics.BitmapFactory;
45 49
import android.opengl.GLSurfaceView;
......
47 51
///////////////////////////////////////////////////////////////////////////////////////////////////
48 52
// Show how to use the notifyWhenFinished / effectFinished APIs
49 53

  
50
class ListenerRenderer implements GLSurfaceView.Renderer, EffectListener, DistortedLibrary.ExceptionListener
54
class ListenerRenderer implements GLSurfaceView.Renderer, EffectListener, DistortedLibrary.LibraryUser
51 55
{
52 56
   private final int NUM_CONCURRENT_BUBBLES = 12;
53 57

  
54
   private GLSurfaceView mView;
55
   private DistortedEffects mEffects;
56
   private DistortedScreen mScreen;
57
   private DistortedTexture mTexture;
58
   private final GLSurfaceView mView;
59
   private final Resources mResources;
60
   private final DistortedEffects mEffects;
61
   private final DistortedScreen mScreen;
62
   private final DistortedTexture mTexture;
63
   private final Random mRnd;
64
   private final Static3D mScale;
65

  
58 66
   private MeshSquare mMesh;
59
   private Random mRnd;
60
   private Static3D mScale;
61 67
   private float mBmpRatio;
62 68

  
63 69
///////////////////////////////////////////////////////////////////////////////////////////////////
......
65 71
   ListenerRenderer(GLSurfaceView v)
66 72
      {
67 73
      mView = v;
74
      mResources = v.getResources();
68 75

  
69 76
      mTexture = new DistortedTexture();
70 77
      mScreen  = new DistortedScreen();
......
174 181

  
175 182
     VertexEffectDistort.enable();
176 183

  
177
     DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
184
     DistortedLibrary.onSurfaceCreated(this);
178 185
     }
179 186

  
180 187
///////////////////////////////////////////////////////////////////////////////////////////////////
......
183 190
     {
184 191
     android.util.Log.e("Listener", ex.getMessage() );
185 192
     }
193

  
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195

  
196
    public int openGlVersion()
197
      {
198
      Context context = mView.getContext();
199
      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
200
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
201
      int glESversion = configurationInfo.reqGlEsVersion;
202
      int major = glESversion >> 16;
203
      int minor = glESversion & 0xff;
204

  
205
      return 100*major + 10*minor;
206
      }
207

  
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209

  
210
    public InputStream localFile(int fileID)
211
      {
212
      return mResources.openRawResource(fileID);
213
      }
214

  
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

  
217
    public void logMessage(String message)
218
      {
219
      android.util.Log.e("Listener", message );
220
      }
186 221
}

Also available in: Unified diff