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/multiblur/MultiblurRenderer.java
19 19

  
20 20
package org.distorted.examples.multiblur;
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;
......
47 51

  
48 52
///////////////////////////////////////////////////////////////////////////////////////////////////
49 53

  
50
class MultiblurRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
54
class MultiblurRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
51 55
{
52 56
    private static final int[] MOVE_VEC =
53 57
        {
......
63 67

  
64 68
    private static final int NUM_OBJECTS = MOVE_VEC.length/3;
65 69

  
66
    private GLSurfaceView mView;
67
    private DistortedTexture mTex1, mTex2;
68
    private DistortedNode[] mNode;
69
    private Static3D[]  mMoveVector;
70
    private Static2D mBlurHaloRadius;
71
    private DistortedScreen mScreen;
72
    private PostprocessEffectBlur mBlur;
70
    private final GLSurfaceView mView;
71
    private final Resources mResources;
72
    private final DistortedTexture mTex1, mTex2;
73
    private final DistortedNode[] mNode;
74
    private final Static3D[]  mMoveVector;
75
    private final Static2D mBlurHaloRadius;
76
    private final DistortedScreen mScreen;
77
    private final PostprocessEffectBlur mBlur;
78
    private final boolean[] mBlurStatus;
79
    private final Static3D mScale;
80

  
73 81
    private int mDistance;
74
    private boolean[] mBlurStatus;
75
    private Static3D mScale;
76 82

  
77 83
    Static4D mQuat1, mQuat2;
78 84
    int mScreenMin;
......
82 88
    MultiblurRenderer(GLSurfaceView v)
83 89
      {
84 90
      mView = v;
91
      mResources = v.getResources();
85 92
      mDistance = -1;
86 93

  
87 94
      mBlurStatus = new boolean[NUM_OBJECTS];
......
188 195
          is1.close();
189 196
          is2.close();
190 197
          }
191
        catch(IOException e) { }
198
        catch(IOException ignored) { }
192 199
        }  
193 200

  
194 201
      mTex1.setTexture(bitmap1);
......
196 203

  
197 204
      PostprocessEffectBlur.enable();
198 205

  
199
      DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
200
      }
201

  
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

  
204
    public void distortedException(Exception ex)
205
      {
206
      android.util.Log.e("Multiblur", ex.getMessage() );
206
      DistortedLibrary.onSurfaceCreated(this);
207 207
      }
208 208

  
209 209
///////////////////////////////////////////////////////////////////////////////////////////////////
......
262 262
        android.util.Log.e("renderer", "Error, number: "+number+" checked: "+checked );
263 263
        }
264 264
      }
265

  
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267

  
268
    public void distortedException(Exception ex)
269
      {
270
      android.util.Log.e("Multiblur", ex.getMessage() );
271
      }
272

  
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274

  
275
    public int openGlVersion()
276
      {
277
      Context context = mView.getContext();
278
      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
279
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
280
      int glESversion = configurationInfo.reqGlEsVersion;
281
      int major = glESversion >> 16;
282
      int minor = glESversion & 0xff;
283

  
284
      return 100*major + 10*minor;
285
      }
286

  
287
///////////////////////////////////////////////////////////////////////////////////////////////////
288

  
289
    public InputStream localFile(int fileID)
290
      {
291
      return mResources.openRawResource(fileID);
292
      }
293

  
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

  
296
    public void logMessage(String message)
297
      {
298
      android.util.Log.e("Multiblur", message );
299
      }
265 300
}

Also available in: Unified diff