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/olimpic/OlimpicRenderer.java
41 41
import org.distorted.library.type.Static1D;
42 42
import org.distorted.library.main.DistortedTexture;
43 43

  
44
import android.app.ActivityManager;
45
import android.content.Context;
46
import android.content.pm.ConfigurationInfo;
47
import android.content.res.Resources;
44 48
import android.graphics.Bitmap;
45 49
import android.graphics.BitmapFactory;
46 50
import android.opengl.GLSurfaceView;
47 51

  
48 52
///////////////////////////////////////////////////////////////////////////////////////////////////
49 53

  
50
class OlimpicRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
54
class OlimpicRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
51 55
{
52 56
   private static final int LEAF_SIZE = 100;
53 57
   private static final int NUM_CIRCLES = 5;
54 58
   static final int NUM_LEAVES  = 8;
55 59
   
56
   private GLSurfaceView mView;
57
   private DistortedNode mRoot;
58
   private DistortedTexture mLeaf;
59
   private DistortedScreen mScreen;
60
   private MeshQuad mLeafMesh;
61
   private int mPrevRendered, mCurrRendered;
62
   private Static3D mScale;
60
   private final GLSurfaceView mView;
61
   private final DistortedNode mRoot;
62
   private final DistortedTexture mLeaf;
63
   private final DistortedScreen mScreen;
64
   private final MeshQuad mLeafMesh;
65
   private final Static3D mScale;
66
   private final DistortedNode[] mCircleNode = new DistortedNode[NUM_CIRCLES];
67
   private final DistortedEffects[] mEffects = new DistortedEffects[NUM_LEAVES];
68
   private final Resources mResources;
63 69

  
64
   private DistortedNode[] mCircleNode = new DistortedNode[NUM_CIRCLES];
65
   private DistortedEffects[] mEffects = new DistortedEffects[NUM_LEAVES];
70
   private int mPrevRendered, mCurrRendered;
66 71

  
67 72
///////////////////////////////////////////////////////////////////////////////////////////////////
68 73

  
......
88 93
   OlimpicRenderer(GLSurfaceView v)
89 94
      {     
90 95
      mView = v;
96
      mResources = v.getResources();
91 97

  
92 98
      mPrevRendered = -1;
93 99
      mCurrRendered = -1;
......
177 183
     {
178 184
     float horiRatio = (float)width ;
179 185
     float vertRatio = (float)height;
180
     float factor    = horiRatio > vertRatio ? vertRatio : horiRatio;
186
     float factor    = Math.min(horiRatio,vertRatio);
181 187

  
182 188
     mScale.set(factor,factor,factor);
183 189
     mScreen.resize(width, height);
......
200 206
         {
201 207
         is.close();
202 208
         }
203
       catch(IOException e) { }
209
       catch(IOException ignored) { }
204 210
       }
205 211
      
206 212
     mLeaf.setTexture(leaf);
207 213

  
208 214
     FragmentEffectChroma.enable();
209 215

  
210
     DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
216
     DistortedLibrary.onSurfaceCreated(this);
211 217
     }
212 218

  
213 219
///////////////////////////////////////////////////////////////////////////////////////////////////
......
216 222
     {
217 223
     android.util.Log.e("Olympic", ex.getMessage() );
218 224
     }
225

  
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

  
228
   public int openGlVersion()
229
     {
230
     Context context = mView.getContext();
231
     final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
232
     final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
233
     int glESversion = configurationInfo.reqGlEsVersion;
234
     int major = glESversion >> 16;
235
     int minor = glESversion & 0xff;
236

  
237
     return 100*major + 10*minor;
238
     }
239

  
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241

  
242
   public InputStream localFile(int fileID)
243
     {
244
     return mResources.openRawResource(fileID);
245
     }
246

  
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248

  
249
   public void logMessage(String message)
250
     {
251
     android.util.Log.e("Olympic", message );
252
     }
219 253
}

Also available in: Unified diff