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/transparency/TransparencyRenderer.java
19 19

  
20 20
package org.distorted.examples.transparency;
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.opengl.GLSurfaceView;
23 27

  
24 28
import org.distorted.library.effect.FragmentEffectAlpha;
......
38 42
import org.distorted.library.type.Static3D;
39 43
import org.distorted.library.type.Static4D;
40 44

  
45
import java.io.InputStream;
46

  
41 47
import javax.microedition.khronos.egl.EGLConfig;
42 48
import javax.microedition.khronos.opengles.GL10;
43 49

  
44 50
///////////////////////////////////////////////////////////////////////////////////////////////////
45 51

  
46
class TransparencyRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
52
class TransparencyRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
47 53
{
48 54
    private static final int NUM = 4; // 4 ints (x,y,z, argb) each describe 1 object below
49 55

  
......
56 62
    private static final int NUM_OBJECTS = OBJECTS.length/NUM;
57 63
    private static final int OBJ_SIZE    = 100;
58 64

  
59
    private GLSurfaceView mView;
60
    private DistortedNode[] mNode;
61
    private DistortedTexture[] mTex;
62
    private Static3D[]  mMoveVector;
63
    private Static1D[]  mAlphaVector;
64
    private DistortedScreen mScreen;
65
    private Static3D mScale;
66
    private PostprocessEffectBlur[] mBlur;
67
    private boolean[] mBlurApplied;
68
    private DistortedEffects[] mEffects;
65
    private final GLSurfaceView mView;
66
    private final Resources mResources;
67
    private final DistortedNode[] mNode;
68
    private final DistortedTexture[] mTex;
69
    private final Static3D[]  mMoveVector;
70
    private final Static1D[]  mAlphaVector;
71
    private final DistortedScreen mScreen;
72
    private final Static3D mScale;
73
    private final PostprocessEffectBlur[] mBlur;
74
    private final boolean[] mBlurApplied;
75
    private final DistortedEffects[] mEffects;
69 76

  
70 77
    Static4D mQuat1, mQuat2;
71 78
    int mScreenMin;
......
75 82
    TransparencyRenderer(GLSurfaceView v)
76 83
      {
77 84
      mView = v;
85
      mResources = v.getResources();
78 86

  
79 87
      MeshSquare mesh = new MeshSquare(1,1);
80 88

  
......
215 223
      VertexEffectScale.enable();
216 224
      PostprocessEffectBlur.enable();
217 225
      FragmentEffectAlpha.enable();
218
      DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
226
      DistortedLibrary.onSurfaceCreated(this);
219 227
      }
220 228

  
221 229
///////////////////////////////////////////////////////////////////////////////////////////////////
......
224 232
      {
225 233
      android.util.Log.e("Transparency", ex.getMessage() );
226 234
      }
235

  
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

  
238
    public int openGlVersion()
239
      {
240
      Context context = mView.getContext();
241
      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
242
      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
243
      int glESversion = configurationInfo.reqGlEsVersion;
244
      int major = glESversion >> 16;
245
      int minor = glESversion & 0xff;
246

  
247
      return 100*major + 10*minor;
248
      }
249

  
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251

  
252
    public InputStream localFile(int fileID)
253
      {
254
      return mResources.openRawResource(fileID);
255
      }
256

  
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258

  
259
    public void logMessage(String message)
260
      {
261
      android.util.Log.e("Transparency", message );
262
      }
227 263
}

Also available in: Unified diff