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/check/CheckRenderer.java
44 44
import org.distorted.library.type.Static4D;
45 45
import org.distorted.library.type.Dynamic1D;
46 46

  
47
import android.app.ActivityManager;
47 48
import android.app.AlertDialog;
48 49
import android.content.Context;
49 50
import android.content.DialogInterface;
51
import android.content.pm.ConfigurationInfo;
52
import android.content.res.Resources;
50 53
import android.graphics.Bitmap;
51 54
import android.graphics.BitmapFactory;
52 55
import android.opengl.GLES31;
......
55 58

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

  
58
class CheckRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
61
class CheckRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
59 62
{
60 63
    private static String compilationResult;
61 64
    private static String compilationTitle;
62 65

  
63
    private GLSurfaceView mView;
64
    private DistortedEffects mEffects;
66
    private final GLSurfaceView mView;
67
    private final Resources mResources;
68
    private final DistortedEffects mEffects;
69
    private final DistortedScreen mScreen;
70
    private final Static3D mScaleMatrix, mScaleVertex, mSwirl1, mSwirl2, mDeform1, mDeform2;
71
    private final Static1D mRadius;
72

  
65 73
    private DistortedTexture mTexture;
66 74
    private MeshSquare mMesh;
67
    private DistortedScreen mScreen;
68 75
    private int mObjHeight, mObjWidth;
69
    private Static3D mScaleMatrix, mScaleVertex, mSwirl1, mSwirl2, mDeform1, mDeform2;
70
    private Static1D mRadius;
71 76

  
72 77
///////////////////////////////////////////////////////////////////////////////////////////////////
73 78

  
74 79
    CheckRenderer(GLSurfaceView view)
75 80
      { 
76 81
      mView = view;
82
      mResources = view.getResources();
77 83

  
78 84
      CheckActivity act = (CheckActivity)mView.getContext();
79 85

  
......
180 186
          {
181 187
          is.close();
182 188
          } 
183
        catch(IOException e) { }
189
        catch(IOException ignored) { }
184 190
        }
185 191

  
186 192
      mObjHeight = bitmap.getHeight();
......
201 207
      mDeform1.set(           0,          0, 0);
202 208
      mDeform2.set(           0, mObjHeight, 0);
203 209

  
204
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this);
210
      DistortedLibrary.onSurfaceCreated(this);
205 211
      }
206 212
    
207 213
///////////////////////////////////////////////////////////////////////////////////////////////////
......
252 258
          }
253 259
        });
254 260
      }
261

  
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263

  
264
   public int openGlVersion()
265
      {
266
      Context context = mView.getContext();
267
      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
268
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
269
      int glESversion = configurationInfo.reqGlEsVersion;
270
      int major = glESversion >> 16;
271
      int minor = glESversion & 0xff;
272

  
273
      return 100*major + 10*minor;
274
      }
275

  
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

  
278
   public InputStream localFile(int fileID)
279
      {
280
      return mResources.openRawResource(fileID);
281
      }
282

  
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284

  
285
   public void logMessage(String message)
286
      {
287
      android.util.Log.e("Check", message );
288
      }
255 289
}

Also available in: Unified diff