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/blur/BlurRenderer.java
19 19

  
20 20
package org.distorted.examples.blur;
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 BlurRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
52
class BlurRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
49 53
{
50 54
    private final static int SIZE = 500;
51 55
    private final static float PART = 0.5f;
52 56

  
53
    private GLSurfaceView mView;
57
    private final GLSurfaceView mView;
58
    private final Resources mResources;
59
    private final DistortedEffects mEffects, mBufferEffects;
60
    private final DistortedScreen mScreen;
61
    private final DistortedFramebuffer mBuffer;
62
    private final MeshSquare mMesh, mMeshBuffer;
63
    private final Static2D mHaloRadiusSta;
64
    private final Static3D mMove, mScale, mBufferScale;
65

  
54 66
    private DistortedTexture mTexture;
55
    private DistortedEffects mEffects, mBufferEffects;
56
    private DistortedScreen mScreen;
57
    private DistortedFramebuffer mBuffer;
58
    private MeshSquare mMesh, mMeshBuffer;
59
    private Static2D mHaloRadiusSta;
60
    private Static3D mMove, mScale, mBufferScale;
61 67

  
62 68
///////////////////////////////////////////////////////////////////////////////////////////////////
63 69

  
64 70
   BlurRenderer(GLSurfaceView v)
65 71
      {
66
      mView       = v;
72
      mView = v;
73
      mResources = v.getResources();
74

  
67 75
      mMesh       = new MeshSquare(1,1);
68 76
      mMeshBuffer = new MeshSquare(1,1);
69 77
      mScreen     = new DistortedScreen();
......
156 164
         {
157 165
         is.close();
158 166
         }
159
       catch(IOException e) { }
167
       catch(IOException ignored) { }
160 168
       }
161 169

  
162 170
     if( mTexture==null ) mTexture = new DistortedTexture();
......
170 178

  
171 179
     PostprocessEffectBlur.enable();
172 180

  
173
     DistortedLibrary.onSurfaceCreated(mView.getContext(),this);
181
     DistortedLibrary.onSurfaceCreated(this);
174 182
     }
175 183

  
176 184
///////////////////////////////////////////////////////////////////////////////////////////////////
......
179 187
     {
180 188
     android.util.Log.e("Blur", ex.getMessage() );
181 189
     }
190

  
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

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

  
202
     return 100*major + 10*minor;
203
     }
204

  
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206

  
207
   public InputStream localFile(int fileID)
208
     {
209
     return mResources.openRawResource(fileID);
210
     }
211

  
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

  
214
   public void logMessage(String message)
215
     {
216
     android.util.Log.e("Blur", message );
217
     }
182 218
}

Also available in: Unified diff