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/mirror/MirrorRenderer.java
19 19

  
20 20
package org.distorted.examples.mirror;
21 21

  
22
import android.app.ActivityManager;
23
import android.content.Context;
24
import android.content.pm.ConfigurationInfo;
25
import android.content.res.Resources;
22 26
import android.graphics.Bitmap;
23 27
import android.graphics.BitmapFactory;
24 28
import android.opengl.GLSurfaceView;
......
45 49

  
46 50
///////////////////////////////////////////////////////////////////////////////////////////////////
47 51

  
48
class MirrorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
52
class MirrorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
49 53
{
50 54
   private static final float MIRROR_SCALE     =0.70f;  // each next mirror will be 70% of the size or the previous
51 55
   private static final float HEAD_SCALE       =0.30f;  // Head's height will be 30% of the height of the mirror
......
56 60
   private static final float MIRROR_MOVE_V    =0.22f;  // Move the mirror up
57 61

  
58 62
   private final GLSurfaceView mView;
63
   private final Resources mResources;
59 64
   private final DistortedEffects mEffectsMirror, mEffectsHead, mEffectsScreen;
60 65
   private final DistortedEffects mEffectsOffscreen1, mEffectsOffscreen2;
61 66
   private final DistortedScreen mScreen;
......
74 79

  
75 80
   MirrorRenderer(GLSurfaceView view)
76 81
      { 
77
      mView    = view;
78
      mScreen  = new DistortedScreen();
82
      mView     = view;
83
      mResources= view.getResources();
84
      mScreen   = new DistortedScreen();
79 85

  
80 86
      mQuad1     = new MeshQuad();
81 87
      mQuad2     = new MeshQuad();
......
220 226
      VertexEffectScale.enable();
221 227
      FragmentEffectBrightness.enable();
222 228

  
223
      DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
229
      DistortedLibrary.onSurfaceCreated(this);
224 230
      }
225 231

  
226 232
///////////////////////////////////////////////////////////////////////////////////////////////////
......
229 235
      {
230 236
      android.util.Log.e("Mirror", ex.getMessage() );
231 237
      }
238

  
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240

  
241
    public int openGlVersion()
242
      {
243
      Context context = mView.getContext();
244
      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
245
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
246
      int glESversion = configurationInfo.reqGlEsVersion;
247
      int major = glESversion >> 16;
248
      int minor = glESversion & 0xff;
249

  
250
      return 100*major + 10*minor;
251
      }
252

  
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254

  
255
    public InputStream localFile(int fileID)
256
      {
257
      return mResources.openRawResource(fileID);
258
      }
259

  
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261

  
262
    public void logMessage(String message)
263
      {
264
      android.util.Log.e("Mirror", message );
265
      }
232 266
}

Also available in: Unified diff