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/aroundtheworld/AroundTheWorldRenderer.java
19 19

  
20 20
package org.distorted.examples.aroundtheworld;
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;
......
48 52

  
49 53
///////////////////////////////////////////////////////////////////////////////////////////////////
50 54

  
51
class AroundTheWorldRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
55
class AroundTheWorldRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
52 56
{
53
   private GLSurfaceView mView;
54
   private DistortedEffects mEffects;
57
   private final GLSurfaceView mView;
58
   private final Resources mResources;
59
   private final DistortedEffects mEffects;
60
   private final DistortedScreen mScreen;
61
   private final AroundTheWorldEffectsManager mManager;
62
   private final Static3D mScaleMatrix, mScaleVertex;
63

  
55 64
   private DistortedTexture mTexture;
56
   private DistortedScreen mScreen;
57 65
   private MeshSquare mMesh;
58
   private AroundTheWorldEffectsManager mManager;
59
   private Static3D mScaleMatrix, mScaleVertex;
60 66

  
61 67
///////////////////////////////////////////////////////////////////////////////////////////////////
62 68

  
63 69
   AroundTheWorldRenderer(GLSurfaceView view)
64 70
      {
71
      mView = view;
72
      mResources = view.getResources();
73

  
65 74
      mScaleMatrix= new Static3D(1,1,1);
66 75
      mScaleVertex= new Static3D(1,1,1);
67 76

  
68
      mView = view;
69 77
      mManager = new AroundTheWorldEffectsManager();
70 78
      mEffects = new DistortedEffects();
71 79
      mEffects.apply(new MatrixEffectScale(mScaleMatrix));
......
119 127
          {
120 128
          is.close();
121 129
          }
122
        catch(IOException e) { }
130
        catch(IOException ignored) { }
123 131
        }
124 132

  
125 133
      int objWidth = bitmap.getWidth();
......
145 153
      FragmentEffectChroma.enable();
146 154
      FragmentEffectContrast.enable();
147 155

  
148
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this);
156
      DistortedLibrary.onSurfaceCreated(this);
149 157
      }
150 158

  
151 159
///////////////////////////////////////////////////////////////////////////////////////////////////
......
154 162
      {
155 163
      android.util.Log.e("AroundTheWorld", ex.getMessage() );
156 164
      }
165

  
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

  
168
    public int openGlVersion()
169
      {
170
      Context context = mView.getContext();
171
      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
172
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
173
      int glESversion = configurationInfo.reqGlEsVersion;
174
      int major = glESversion >> 16;
175
      int minor = glESversion & 0xff;
176

  
177
      return 100*major + 10*minor;
178
      }
179

  
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181

  
182
    public InputStream localFile(int fileID)
183
      {
184
      return mResources.openRawResource(fileID);
185
      }
186

  
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

  
189
    public void logMessage(String message)
190
      {
191
      android.util.Log.e("AroundTheWorld", message );
192
      }
157 193
}

Also available in: Unified diff