Project

General

Profile

« Previous | Next » 

Revision d0ad3964

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/bandaged/BandagedCreatorRenderer.java
12 12
import java.io.File;
13 13
import java.io.FileNotFoundException;
14 14
import java.io.IOException;
15
import java.io.InputStream;
15 16
import java.nio.ByteBuffer;
16 17
import java.nio.ByteOrder;
17 18

  
......
19 20
import javax.microedition.khronos.opengles.GL10;
20 21

  
21 22
import android.app.Activity;
23
import android.app.ActivityManager;
24
import android.content.Context;
25
import android.content.pm.ConfigurationInfo;
26
import android.content.res.Resources;
22 27
import android.opengl.GLES31;
23 28
import android.opengl.GLSurfaceView;
24 29
import android.widget.Toast;
......
46 51

  
47 52
///////////////////////////////////////////////////////////////////////////////////////////////////
48 53

  
49
public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
54
public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
50 55
{
51 56
   public static final float BRIGHTNESS = 0.333f;
52 57
   private static final int RESET_DURATION = 1000;
......
55 60
   private static final float INIT_RATIO = 0.5f;
56 61

  
57 62
   private final BandagedCreatorView mView;
63
   private final Resources mResources;
58 64
   private final DistortedScreen mScreen;
59 65
   private final Static3D mScale;
60 66
   private final Static4D mQuatT, mQuatA;
......
78 84

  
79 85
   BandagedCreatorRenderer(BandagedCreatorView v)
80 86
     {
87
     mView = v;
88
     mResources = v.getResources();
89

  
81 90
     mQuatT = new Static4D(0,0,0,1);
82 91
     mQuatA = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
83 92

  
84
     mView = v;
85

  
86 93
     mResetQuats       = false;
87 94
     mSetQuatT         = false;
88 95
     mResettingObject  = false;
......
303 310

  
304 311
      FragmentEffectBrightness.enable();
305 312

  
306
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
313
      DistortedLibrary.onSurfaceCreated(this,1);
307 314
      DistortedLibrary.setCull(true);
308 315

  
309 316
      if( mCubits==null )
......
320 327
      mHeight= 0;
321 328
      }
322 329

  
323
///////////////////////////////////////////////////////////////////////////////////////////////////
324

  
325
   public void distortedException(Exception ex)
326
     {
327
     android.util.Log.e("CREATOR", "unexpected exception: "+ex.getMessage() );
328
     }
329

  
330 330
///////////////////////////////////////////////////////////////////////////////////////////////////
331 331

  
332 332
   public DistortedScreen getScreen()
......
670 670
    {
671 671
    if( index>=0 && index<mNumCubits && mCubits[index]!=null ) mCubits[index].setUnmarked();
672 672
    }
673

  
674
///////////////////////////////////////////////////////////////////////////////////////////////////
675

  
676
  public void distortedException(Exception ex)
677
    {
678
    android.util.Log.e("BandagedCreator", "unexpected exception: "+ex.getMessage() );
679
    }
680

  
681
///////////////////////////////////////////////////////////////////////////////////////////////////
682

  
683
  public int openGlVersion()
684
    {
685
    Context context = mView.getContext();
686
    final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
687
    final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
688
    int glESversion = configurationInfo.reqGlEsVersion;
689
    int major = glESversion >> 16;
690
    int minor = glESversion & 0xff;
691

  
692
    return 100*major + 10*minor;
693
    }
694

  
695
///////////////////////////////////////////////////////////////////////////////////////////////////
696

  
697
  public InputStream localFile(int fileID)
698
    {
699
    return mResources.openRawResource(fileID);
700
    }
701

  
702
///////////////////////////////////////////////////////////////////////////////////////////////////
703

  
704
  public void logMessage(String message)
705
    {
706
    android.util.Log.e("BandagedCreator", message );
707
    }
673 708
}

Also available in: Unified diff