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/surfaceview/RenderThread.java
19 19

  
20 20
package org.distorted.examples.surfaceview;
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.EGL14;
......
47 51

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

  
50
class RenderThread extends Thread implements DistortedLibrary.ExceptionListener
54
class RenderThread extends Thread implements DistortedLibrary.LibraryUser
51 55
  {
52 56
  private static final String TAG = "RenderThread";
53 57

  
......
58 62

  
59 63
  // Used to wait for the thread to start.
60 64
  private final Object mStartLock = new Object();
61
  private boolean mReady = false;
62
  private volatile SurfaceHolder mSurfaceHolder;  // may be updated by UI thread
65
  private final Static3D mScale;
66
  private final DistortedEffects mEffects;
67
  private final DistortedScreen mScreen;
68
  private final SurfaceView mView;
69
  private final Resources mResources;
70

  
63 71
  private EglCore eglCore;
64 72
  private EGLSurface eglSurface;
65

  
66
  private DistortedEffects mEffects;
67 73
  private DistortedTexture mTexture;
68 74
  private MeshSquare mMesh;
69
  private DistortedScreen mScreen;
70
  private SurfaceView mView;
71
  private static boolean resourcesCreated = false;
72
  private Static3D mScale;
75
  private volatile SurfaceHolder mSurfaceHolder;  // may be updated by UI thread
73 76
  private float mBmpRatio;
77
  private boolean mReady = false;
78

  
79
  private static boolean resourcesCreated = false;
74 80

  
75 81
///////////////////////////////////////////////////////////////////////////////////////////////////
76 82

  
......
78 84
    {
79 85
    mSurfaceHolder = holder;
80 86
    mView = view;
87
    mResources = view.getResources();
81 88

  
82 89
    Static3D pLeft = new Static3D( ( 90-320*0.5f)/320.0f, (108-366*0.5f)/366.0f, 0);
83 90
    Static3D pRight= new Static3D( (176-320*0.5f)/320.0f, (111-366*0.5f)/366.0f, 0);
......
174 181
          {
175 182
          mStartLock.wait();
176 183
          }
177
        catch (InterruptedException ie) {  }
184
        catch (InterruptedException ignored) {  }
178 185
        }
179 186
      }
180 187
    }
......
239 246
        {
240 247
        is.close();
241 248
        }
242
      catch(IOException io) {}
249
      catch(IOException ignored) {}
243 250
      }
244 251

  
245 252
    mBmpRatio = (float)bmp.getHeight()/bmp.getWidth();
......
253 260
    mScreen.attach(mTexture,mEffects,mMesh);
254 261

  
255 262
    VertexEffectDistort.enable();
256
    DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
257
    }
258

  
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260

  
261
  public void distortedException(Exception ex)
262
    {
263
    android.util.Log.e("SurfaceView", ex.getMessage() );
263
    DistortedLibrary.onSurfaceCreated(this);
264 264
    }
265 265

  
266 266
///////////////////////////////////////////////////////////////////////////////////////////////////
......
287 287
    eglCore.swapBuffers(eglSurface);
288 288
    }
289 289

  
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291

  
292
  public void distortedException(Exception ex)
293
    {
294
    android.util.Log.e("SurfaceView", ex.getMessage() );
295
    }
296

  
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298

  
299
  public int openGlVersion()
300
    {
301
    Context context = mView.getContext();
302
    final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
303
    final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
304
    int glESversion = configurationInfo.reqGlEsVersion;
305
    int major = glESversion >> 16;
306
    int minor = glESversion & 0xff;
307

  
308
    return 100*major + 10*minor;
309
    }
310

  
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312

  
313
  public InputStream localFile(int fileID)
314
    {
315
    return mResources.openRawResource(fileID);
316
    }
317

  
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319

  
320
  public void logMessage(String message)
321
    {
322
    android.util.Log.e("SurfaceView", message );
323
    }
290 324
  }

Also available in: Unified diff