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/inflate/InflateRenderer.java
36 36
import org.distorted.library.type.Static4D;
37 37
import org.distorted.library.type.Static3D;
38 38

  
39
import android.app.ActivityManager;
40
import android.content.Context;
41
import android.content.pm.ConfigurationInfo;
42
import android.content.res.Resources;
39 43
import android.opengl.GLSurfaceView;
40 44

  
45
import java.io.InputStream;
46

  
41 47
///////////////////////////////////////////////////////////////////////////////////////////////////
42 48

  
43
class InflateRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
49
class InflateRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
44 50
{
45 51
    private static final float FOV = 30.0f;
46 52
    private static final float NEAR = 0.1f;
47 53

  
48
    private GLSurfaceView mView;
49
    private DistortedTexture mTexture;
50
    private DistortedEffects mEffects;
51
    private MeshBase mMesh;
52
    private DistortedScreen mScreen;
53
    private float mObjWidth, mObjHeight, mObjDepth;
54
    private Static3D mScale;
55
    private Static1D mAlpha;
54
    private final GLSurfaceView mView;
55
    private final Resources mResources;
56
    private final DistortedTexture mTexture;
57
    private final DistortedEffects mEffects;
58
    private final MeshBase mMesh;
59
    private final DistortedScreen mScreen;
60
    private final float mObjWidth, mObjHeight, mObjDepth;
61
    private final Static3D mScale;
62
    private final Static1D mAlpha;
56 63

  
57 64
    Static4D mQuat1, mQuat2;
58 65
    int mScreenMin;
......
62 69
    InflateRenderer(GLSurfaceView v)
63 70
      {
64 71
      mView = v;
72
      mResources = v.getResources();
65 73

  
66 74
      mAlpha = new Static1D(1.0f);
67 75
      mScale= new Static3D(1,1,1);
......
154 162
      VertexEffectScale.enable();
155 163
      FragmentEffectAlpha.enable();
156 164

  
157
      DistortedLibrary.onSurfaceCreated(act,this);
165
      DistortedLibrary.onSurfaceCreated(this);
158 166
      }
159 167

  
160 168
///////////////////////////////////////////////////////////////////////////////////////////////////
......
163 171
      {
164 172
      android.util.Log.e("Inflate", ex.getMessage() );
165 173
      }
174

  
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

  
177
    public int openGlVersion()
178
      {
179
      Context context = mView.getContext();
180
      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
181
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
182
      int glESversion = configurationInfo.reqGlEsVersion;
183
      int major = glESversion >> 16;
184
      int minor = glESversion & 0xff;
185

  
186
      return 100*major + 10*minor;
187
      }
188

  
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

  
191
    public InputStream localFile(int fileID)
192
      {
193
      return mResources.openRawResource(fileID);
194
      }
195

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

  
198
    public void logMessage(String message)
199
      {
200
      android.util.Log.e("Inflate", message );
201
      }
166 202
}

Also available in: Unified diff