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/bean/BeanRenderer.java
38 38
import org.distorted.library.type.Static3D;
39 39
import org.distorted.library.type.Static4D;
40 40

  
41
import android.app.ActivityManager;
42
import android.content.Context;
43
import android.content.pm.ConfigurationInfo;
44
import android.content.res.Resources;
41 45
import android.graphics.Bitmap;
42 46
import android.graphics.BitmapFactory;
43 47
import android.opengl.GLSurfaceView;
44 48

  
45 49
///////////////////////////////////////////////////////////////////////////////////////////////////
46 50

  
47
class BeanRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
51
class BeanRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
48 52
{
49
   private GLSurfaceView mView;
50
   private DistortedEffects mEffects;
51
   private DistortedScreen mScreen;
52
   private DistortedTexture mTexture;
53
   private final GLSurfaceView mView;
54
   private final Resources mResources;
55
   private final DistortedEffects mEffects;
56
   private final DistortedScreen mScreen;
57
   private final DistortedTexture mTexture;
58
   private final Static3D mScale;
59

  
53 60
   private MeshSquare mMesh;
54
   private Static3D mScale;
55 61
   private float mBmpRatio;
56 62

  
57 63
///////////////////////////////////////////////////////////////////////////////////////////////////
......
60 66
   BeanRenderer(GLSurfaceView v)
61 67
      {
62 68
      mView = v;
63
     
69
      mResources = v.getResources();
70

  
64 71
      Static3D pointLeft  = new Static3D(-85/366.0f,  57/480.0f, 0);
65 72
      Static3D pointRight = new Static3D( 50/366.0f, 100/480.0f, 0);
66 73
      Static4D regionLeft = new Static4D( -3/366.0f,  33/480.0f, 0, 47/400.0f);
......
162 169

  
163 170
     VertexEffectDistort.enable();
164 171

  
165
     DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
172
     DistortedLibrary.onSurfaceCreated(this);
166 173
     }
167 174

  
168 175
///////////////////////////////////////////////////////////////////////////////////////////////////
......
171 178
     {
172 179
     android.util.Log.e("Bean", ex.getMessage() );
173 180
     }
181

  
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

  
184
    public int openGlVersion()
185
      {
186
      Context context = mView.getContext();
187
      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
188
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
189
      int glESversion = configurationInfo.reqGlEsVersion;
190
      int major = glESversion >> 16;
191
      int minor = glESversion & 0xff;
192

  
193
      return 100*major + 10*minor;
194
      }
195

  
196
///////////////////////////////////////////////////////////////////////////////////////////////////
197

  
198
    public InputStream localFile(int fileID)
199
      {
200
      return mResources.openRawResource(fileID);
201
      }
202

  
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

  
205
    public void logMessage(String message)
206
      {
207
      android.util.Log.e("Bean", message );
208
      }
174 209
}

Also available in: Unified diff