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/quaternion/QuaternionRenderer.java
40 40
import org.distorted.library.type.Static4D;
41 41
import org.distorted.library.type.Static3D;
42 42

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

  
47 51
///////////////////////////////////////////////////////////////////////////////////////////////////
48 52

  
49
class QuaternionRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
53
class QuaternionRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
50 54
  {
51 55
  private static final int NUM_QUATERNIONS = 5;
52 56

  
53
  private GLSurfaceView mView;
54
  private DistortedTexture mTexture;
55
  private DistortedScreen mScreen;
56
  private Static3D mScale;
57
  private final GLSurfaceView mView;
58
  private final Resources mResources;
59
  private final DistortedTexture mTexture;
60
  private final DistortedScreen mScreen;
61
  private final Static3D mScale;
57 62

  
58 63
///////////////////////////////////////////////////////////////////////////////////////////////////
59 64

  
60 65
  QuaternionRenderer(GLSurfaceView v)
61 66
    {
62
    mView    = v;
67
    mView = v;
68
    mResources = v.getResources();
69

  
63 70
    mTexture = new DistortedTexture();
64 71

  
65 72
    DistortedEffects effects = new DistortedEffects();
......
127 134
        {
128 135
        is.close();
129 136
        } 
130
      catch(IOException e) { }
137
      catch(IOException ignored) { }
131 138
      }  
132 139
      
133 140
    mTexture.setTexture(bitmap);
134 141

  
135
    DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
142
    DistortedLibrary.onSurfaceCreated(this);
136 143
    }
137 144

  
138 145
///////////////////////////////////////////////////////////////////////////////////////////////////
......
141 148
    {
142 149
    android.util.Log.e("Quaternion", ex.getMessage() );
143 150
    }
151

  
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

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

  
163
    return 100*major + 10*minor;
164
    }
165

  
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

  
168
  public InputStream localFile(int fileID)
169
    {
170
    return mResources.openRawResource(fileID);
171
    }
172

  
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

  
175
  public void logMessage(String message)
176
    {
177
    android.util.Log.e("Quaternion", message );
178
    }
144 179
  }

Also available in: Unified diff