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/triblur/TriblurRenderer.java
19 19

  
20 20
package org.distorted.examples.triblur;
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;
......
40 44
import org.distorted.library.main.DistortedNode;
41 45
import org.distorted.library.main.DistortedScreen;
42 46
import org.distorted.library.main.DistortedTexture;
43
import org.distorted.library.mesh.MeshBase;
44 47
import org.distorted.library.mesh.MeshCubes;
45 48
import org.distorted.library.type.Static1D;
46 49
import org.distorted.library.type.Static2D;
......
55 58

  
56 59
///////////////////////////////////////////////////////////////////////////////////////////////////
57 60

  
58
class TriblurRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
61
class TriblurRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
59 62
{
60 63
    private static final int[][] OBJECTS =
61 64
        {
......
68 71
    private static final int OBJ_SIZE    = 100;
69 72

  
70 73
    private final GLSurfaceView mView;
74
    private final Resources mResources;
71 75
    private final DistortedTexture mTex;
72 76
    private final DistortedNode[] mNode;
73 77
    private final Static2D[] mEffectHaloRadius;
......
89 93
    TriblurRenderer(GLSurfaceView v)
90 94
      {
91 95
      mView = v;
96
      mResources = v.getResources();
92 97

  
93 98
      MeshCubes mesh = new MeshCubes(1,1,1);
94 99

  
......
222 227
      FragmentEffectChroma.enable();
223 228
      Effect.enableEffects(EffectType.POSTPROCESS);
224 229

  
225
      DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
226
      }
227

  
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

  
230
    public void distortedException(Exception ex)
231
      {
232
      android.util.Log.e("Triblur", ex.getMessage() );
230
      DistortedLibrary.onSurfaceCreated(this);
233 231
      }
234 232

  
235 233
///////////////////////////////////////////////////////////////////////////////////////////////////
......
271 269
        android.util.Log.e("renderer", "Error, number: "+object+" effect: "+effect );
272 270
        }
273 271
      }
272

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

  
275
    public void distortedException(Exception ex)
276
      {
277
      android.util.Log.e("Triblur", ex.getMessage() );
278
      }
279

  
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281

  
282
    public int openGlVersion()
283
      {
284
      Context context = mView.getContext();
285
      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
286
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
287
      int glESversion = configurationInfo.reqGlEsVersion;
288
      int major = glESversion >> 16;
289
      int minor = glESversion & 0xff;
290

  
291
      return 100*major + 10*minor;
292
      }
293

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

  
296
    public InputStream localFile(int fileID)
297
      {
298
      return mResources.openRawResource(fileID);
299
      }
300

  
301
///////////////////////////////////////////////////////////////////////////////////////////////////
302

  
303
    public void logMessage(String message)
304
      {
305
      android.util.Log.e("Triblur", message );
306
      }
274 307
}

Also available in: Unified diff