Project

General

Profile

« Previous | Next » 

Revision d0ad3964

Added by Leszek Koltunski over 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
}
src/main/java/org/distorted/bandaged/BandagedPlayRenderer.java
9 9

  
10 10
package org.distorted.bandaged;
11 11

  
12
import android.app.ActivityManager;
13
import android.content.Context;
14
import android.content.pm.ConfigurationInfo;
15
import android.content.res.Resources;
12 16
import android.opengl.GLSurfaceView;
13 17

  
14 18
import org.distorted.library.effect.EffectType;
......
20 24
import org.distorted.objectlib.effects.BaseEffect;
21 25
import org.distorted.objectlib.scrambling.ScrambleStateBandagedCuboid;
22 26

  
27
import java.io.InputStream;
28

  
23 29
import javax.microedition.khronos.egl.EGLConfig;
24 30
import javax.microedition.khronos.opengles.GL10;
25 31

  
26 32
///////////////////////////////////////////////////////////////////////////////////////////////////
27 33

  
28
public class BandagedPlayRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
34
public class BandagedPlayRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
29 35
{
30 36
   private final BandagedPlayView mView;
37
   private final Resources mResources;
31 38
   private final DistortedScreen mScreen;
32 39

  
33 40
///////////////////////////////////////////////////////////////////////////////////////////////////
......
37 44
     final float BRIGHTNESS = 0.333f;
38 45

  
39 46
     mView = v;
47
     mResources = v.getResources();
40 48
     mScreen = new DistortedScreen();
41 49
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
42 50
     }
......
60 68
      mView.setScreenSize(width,height);
61 69
      }
62 70

  
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

  
73
   DistortedScreen getScreen()
74
     {
75
     return mScreen;
76
     }
77

  
63 78
///////////////////////////////////////////////////////////////////////////////////////////////////
64 79

  
65 80
   @Override
......
74 89
      VertexEffectQuaternion.enable();
75 90
      BaseEffect.Type.enableEffects();
76 91

  
77
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
92
      DistortedLibrary.onSurfaceCreated(this,1);
78 93
      DistortedLibrary.setCull(true);
79 94
      }
80 95

  
......
87 102

  
88 103
///////////////////////////////////////////////////////////////////////////////////////////////////
89 104

  
90
   DistortedScreen getScreen()
91
     {
92
     return mScreen;
93
     }
105
   public int openGlVersion()
106
      {
107
      Context context = mView.getContext();
108
      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
109
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
110
      int glESversion = configurationInfo.reqGlEsVersion;
111
      int major = glESversion >> 16;
112
      int minor = glESversion & 0xff;
113

  
114
      return 100*major + 10*minor;
115
      }
116

  
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

  
119
   public InputStream localFile(int fileID)
120
      {
121
      return mResources.openRawResource(fileID);
122
      }
123

  
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

  
126
   public void logMessage(String message)
127
      {
128
      android.util.Log.e("BandagedPlay", message );
129
      }
94 130
}
src/main/java/org/distorted/config/ConfigRenderer.java
9 9

  
10 10
package org.distorted.config;
11 11

  
12
import android.app.ActivityManager;
13
import android.content.Context;
14
import android.content.pm.ConfigurationInfo;
15
import android.content.res.Resources;
12 16
import android.opengl.GLSurfaceView;
13 17

  
14 18
import org.distorted.library.effect.EffectType;
......
19 23
import org.distorted.objectlib.effects.BaseEffect;
20 24
import org.distorted.objectlib.main.ObjectControl;
21 25

  
26
import java.io.InputStream;
27

  
22 28
import javax.microedition.khronos.egl.EGLConfig;
23 29
import javax.microedition.khronos.opengles.GL10;
24 30

  
25 31
///////////////////////////////////////////////////////////////////////////////////////////////////
26 32

  
27
public class ConfigRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
33
public class ConfigRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
28 34
{
29 35
   private final ConfigSurfaceView mView;
36
   private final Resources mResources;
30 37
   private final DistortedScreen mScreen;
31 38

  
32 39
///////////////////////////////////////////////////////////////////////////////////////////////////
......
36 43
     final float BRIGHTNESS = 0.333f;
37 44

  
38 45
     mView = v;
46
     mResources = v.getResources();
39 47
     mScreen = new DistortedScreen();
40 48
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
41 49
     }
......
59 67
      mView.setScreenSize(width,height);
60 68
      }
61 69

  
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

  
72
   DistortedScreen getScreen()
73
     {
74
     return mScreen;
75
     }
76

  
62 77
///////////////////////////////////////////////////////////////////////////////////////////////////
63 78

  
64 79
   @Override
......
69 84
      VertexEffectQuaternion.enable();
70 85
      BaseEffect.Type.enableEffects();
71 86

  
72
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
87
      DistortedLibrary.onSurfaceCreated(this,1);
73 88
      DistortedLibrary.setCull(true);
74 89
      }
75 90

  
......
77 92

  
78 93
   public void distortedException(Exception ex)
79 94
     {
80
     android.util.Log.e("CONFIG", "unexpected exception: "+ex.getMessage() );
95
     android.util.Log.e("Config", "unexpected exception: "+ex.getMessage() );
81 96
     }
82 97

  
83 98
///////////////////////////////////////////////////////////////////////////////////////////////////
84 99

  
85
   DistortedScreen getScreen()
86
     {
87
     return mScreen;
88
     }
100
   public int openGlVersion()
101
      {
102
      Context context = mView.getContext();
103
      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
104
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
105
      int glESversion = configurationInfo.reqGlEsVersion;
106
      int major = glESversion >> 16;
107
      int minor = glESversion & 0xff;
108

  
109
      return 100*major + 10*minor;
110
      }
111

  
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

  
114
   public InputStream localFile(int fileID)
115
      {
116
      return mResources.openRawResource(fileID);
117
      }
118

  
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

  
121
   public void logMessage(String message)
122
      {
123
      android.util.Log.e("Config", message );
124
      }
89 125
}
src/main/java/org/distorted/main/RubikRenderer.java
10 10
package org.distorted.main;
11 11

  
12 12
import android.app.Activity;
13
import android.app.ActivityManager;
14
import android.content.Context;
15
import android.content.pm.ConfigurationInfo;
16
import android.content.res.Resources;
13 17
import android.opengl.GLES30;
14 18
import android.opengl.GLSurfaceView;
15 19

  
......
30 34

  
31 35
import com.google.firebase.crashlytics.FirebaseCrashlytics;
32 36

  
37
import java.io.InputStream;
38

  
33 39
///////////////////////////////////////////////////////////////////////////////////////////////////
34 40

  
35
public class RubikRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
41
public class RubikRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
36 42
{
37 43
   public static final float BRIGHTNESS = 0.30f;
38 44

  
39 45
   private final RubikSurfaceView mView;
46
   private final Resources mResources;
40 47
   private final DistortedScreen mScreen;
41 48
   private final ObjectControl mControl;
42 49
   private final Fps mFPS;
......
85 92

  
86 93
   RubikRenderer(RubikSurfaceView v)
87 94
     {
88
     mErrorShown = false;
89 95
     mView = v;
96
     mResources = v.getResources();
97

  
98
     mErrorShown = false;
90 99
     mControl = v.getObjectControl();
91 100
     mFPS = new Fps();
92 101
     mScreen = new DistortedScreen();
......
94 103
     mScreen.enableDepthStencil(InternalOutputSurface.DEPTH_NO_STENCIL);
95 104
     }
96 105

  
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

  
108
   float getFPS()
109
     {
110
     return mFPS.getFPS();
111
     }
112

  
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

  
115
   DistortedScreen getScreen()
116
     {
117
     return mScreen;
118
     }
119

  
97 120
///////////////////////////////////////////////////////////////////////////////////////////////////
98 121
// various things are done here delayed, 'after the next render' as not to be done mid-render and
99 122
// cause artifacts.
......
129 152
      BaseEffect.Type.enableEffects();
130 153
      OverlayGeneric.enableEffects();
131 154

  
132
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
155
      DistortedLibrary.onSurfaceCreated(this,1);
133 156
      DistortedLibrary.setCull(true);
134 157

  
135 158
      if( !mDebugSent )
......
184 207

  
185 208
///////////////////////////////////////////////////////////////////////////////////////////////////
186 209

  
187
   float getFPS()
210
   public int openGlVersion()
188 211
     {
189
     return mFPS.getFPS();
212
     Context context = mView.getContext();
213
     final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
214
     final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
215
     int glESversion = configurationInfo.reqGlEsVersion;
216
     int major = glESversion >> 16;
217
     int minor = glESversion & 0xff;
218

  
219
     return 100*major + 10*minor;
190 220
     }
191 221

  
192 222
///////////////////////////////////////////////////////////////////////////////////////////////////
193 223

  
194
   DistortedScreen getScreen()
224
   public InputStream localFile(int fileID)
195 225
     {
196
     return mScreen;
226
     return mResources.openRawResource(fileID);
227
     }
228

  
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230

  
231
   public void logMessage(String message)
232
     {
233
     android.util.Log.e("Rubik", message );
197 234
     }
198 235
}
src/main/java/org/distorted/purchase/PurchaseRenderer.java
9 9

  
10 10
package org.distorted.purchase;
11 11

  
12
import android.app.ActivityManager;
13
import android.content.Context;
14
import android.content.pm.ConfigurationInfo;
15
import android.content.res.Resources;
12 16
import android.opengl.GLSurfaceView;
13 17

  
14 18
import org.distorted.library.effect.EffectType;
......
21 25
import org.distorted.objectlib.main.ObjectControl;
22 26
import org.distorted.overlays.OverlayGeneric;
23 27

  
28
import java.io.InputStream;
29

  
24 30
import javax.microedition.khronos.egl.EGLConfig;
25 31
import javax.microedition.khronos.opengles.GL10;
26 32

  
27 33
///////////////////////////////////////////////////////////////////////////////////////////////////
28 34

  
29
public class PurchaseRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
35
public class PurchaseRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
30 36
{
31 37
   private static final int NUM_SCRAMBLES = 5;
32 38
   private static final int DURATION = NUM_SCRAMBLES*2*1000;
33 39

  
34 40
   private final PurchaseSurfaceView mView;
41
   private final Resources mResources;
35 42
   private final DistortedScreen mScreen;
36 43

  
37 44
   private boolean mFirstRender;
......
42 49
     {
43 50
     final float BRIGHTNESS = 0.333f;
44 51

  
45
     mFirstRender = true;
46 52
     mView = v;
53
     mResources = v.getResources();
54

  
55
     mFirstRender = true;
47 56
     mScreen = new DistortedScreen();
48 57
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
49 58
     }
......
73 82
      mView.setScreenSize(width,height);
74 83
      }
75 84

  
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

  
87
   DistortedScreen getScreen()
88
     {
89
     return mScreen;
90
     }
91

  
76 92
///////////////////////////////////////////////////////////////////////////////////////////////////
77 93

  
78 94
   @Override
......
86 102
      BaseEffect.Type.enableEffects();
87 103
      OverlayGeneric.enableEffects();
88 104

  
89
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
105
      DistortedLibrary.onSurfaceCreated(this,1);
90 106
      DistortedLibrary.setCull(true);
91 107
      }
92 108

  
......
94 110

  
95 111
   public void distortedException(Exception ex)
96 112
     {
97
     android.util.Log.e("PURCHASE", "unexpected exception: "+ex.getMessage() );
113
     android.util.Log.e("Purchase", "unexpected exception: "+ex.getMessage() );
98 114
     }
99 115

  
100 116
///////////////////////////////////////////////////////////////////////////////////////////////////
101 117

  
102
   DistortedScreen getScreen()
103
     {
104
     return mScreen;
105
     }
118
   public int openGlVersion()
119
      {
120
      Context context = mView.getContext();
121
      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
122
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
123
      int glESversion = configurationInfo.reqGlEsVersion;
124
      int major = glESversion >> 16;
125
      int minor = glESversion & 0xff;
126

  
127
      return 100*major + 10*minor;
128
      }
129

  
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

  
132
   public InputStream localFile(int fileID)
133
      {
134
      return mResources.openRawResource(fileID);
135
      }
136

  
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

  
139
   public void logMessage(String message)
140
      {
141
      android.util.Log.e("Purchase", message );
142
      }
106 143
}
src/main/java/org/distorted/tutorials/TutorialRenderer.java
12 12
import javax.microedition.khronos.egl.EGLConfig;
13 13
import javax.microedition.khronos.opengles.GL10;
14 14

  
15
import android.app.ActivityManager;
16
import android.content.Context;
17
import android.content.pm.ConfigurationInfo;
18
import android.content.res.Resources;
15 19
import android.opengl.GLSurfaceView;
16 20

  
17 21
import org.distorted.library.effect.EffectType;
......
24 28
import org.distorted.objectlib.effects.BaseEffect;
25 29
import org.distorted.objectlib.main.ObjectControl;
26 30

  
31
import java.io.InputStream;
32

  
27 33
///////////////////////////////////////////////////////////////////////////////////////////////////
28 34

  
29
public class TutorialRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
35
public class TutorialRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
30 36
{
31 37
   private final TutorialSurfaceView mView;
32 38
   private final DistortedScreen mScreen;
39
   private final Resources mResources;
33 40

  
34 41
///////////////////////////////////////////////////////////////////////////////////////////////////
35 42

  
......
38 45
     final float BRIGHTNESS = 0.30f;
39 46

  
40 47
     mView = v;
48
     mResources = v.getResources();
41 49
     mScreen = new DistortedScreen();
42 50
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
43 51
     }
44 52

  
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

  
55
   DistortedScreen getScreen()
56
     {
57
     return mScreen;
58
     }
59

  
45 60
///////////////////////////////////////////////////////////////////////////////////////////////////
46 61

  
47 62
   @Override
......
73 88
      VertexEffectQuaternion.enable();
74 89
      BaseEffect.Type.enableEffects();
75 90

  
76
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
91
      DistortedLibrary.onSurfaceCreated(this,1);
77 92
      DistortedLibrary.setCull(true);
78 93
      }
79 94

  
......
81 96

  
82 97
   public void distortedException(Exception ex)
83 98
     {
84
     android.util.Log.e("TUTORIAL", "unexpected exception: "+ex.getMessage() );
99
     android.util.Log.e("Tutorial", "unexpected exception: "+ex.getMessage() );
85 100
     }
86 101

  
87 102
///////////////////////////////////////////////////////////////////////////////////////////////////
88 103

  
89
   DistortedScreen getScreen()
104
   public int openGlVersion()
90 105
     {
91
     return mScreen;
106
     Context context = mView.getContext();
107
     final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
108
     final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
109
     int glESversion = configurationInfo.reqGlEsVersion;
110
     int major = glESversion >> 16;
111
     int minor = glESversion & 0xff;
112

  
113
     return 100*major + 10*minor;
114
     }
115

  
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

  
118
   public InputStream localFile(int fileID)
119
     {
120
     return mResources.openRawResource(fileID);
121
     }
122

  
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

  
125
   public void logMessage(String message)
126
     {
127
     android.util.Log.e("Tutorial", message );
92 128
     }
93 129
}

Also available in: Unified diff