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/sink/SinkRenderer.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 SinkRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
51
class SinkRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
48 52
  {
49 53
  private final GLSurfaceView mView;
54
  private final Resources mResources;
50 55
  private final DistortedEffects mEffects;
51 56
  private final DistortedScreen mScreen;
52 57
  private final DistortedTexture mTexture;
......
60 65

  
61 66
  SinkRenderer(GLSurfaceView v)
62 67
    { 
63
    mView    = v;
68
    mView = v;
69
    mResources = v.getResources();
70

  
64 71
    mTexture = new DistortedTexture();
65 72
    mEffects = new DistortedEffects();
66 73
    mScreen  = new DistortedScreen();
......
135 142
    mScreen.attach(mTexture,mEffects,mMesh);
136 143

  
137 144
    VertexEffectSink.enable();
138
    DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
145
    DistortedLibrary.onSurfaceCreated(this);
139 146
    }
140 147

  
141 148
///////////////////////////////////////////////////////////////////////////////////////////////////
......
144 151
    {
145 152
    android.util.Log.e("Sink", ex.getMessage() );
146 153
    }
147
  }
154

  
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

  
157
  public int openGlVersion()
158
    {
159
    Context context = mView.getContext();
160
    final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
161
    final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
162
    int glESversion = configurationInfo.reqGlEsVersion;
163
    int major = glESversion >> 16;
164
    int minor = glESversion & 0xff;
165

  
166
    return 100*major + 10*minor;
167
    }
168

  
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

  
171
  public InputStream localFile(int fileID)
172
    {
173
    return mResources.openRawResource(fileID);
174
    }
175

  
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177

  
178
  public void logMessage(String message)
179
    {
180
    android.util.Log.e("Sink", message );
181
    }
182
}

Also available in: Unified diff