Project

General

Profile

« Previous | Next » 

Revision 5d5ed376

Added by Leszek Koltunski over 2 years ago

On OpenGL ES 3.0, some drivers are veeeery slow linking a program which includes transform feedback - and such program is needed to apply vertex effects to meshes - which is needed to round corners of puzzle cubits.

Thus on 3.0 we switch off rounding corners of the meshes in the Creator mode, otherwise we'd need to wait about 24 seconds for the screen to appear!

View differences:

src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
100 100
   private final BandagedCreatorView mView;
101 101
   private final DistortedScreen mScreen;
102 102
   private final Static3D mScale;
103
   private final BandagedCubit[] mCubits;
104 103
   private final Static4D mQuatT, mQuatA;
105 104

  
105
   private BandagedCubit[] mCubits;
106 106
   private boolean mInitialPhase;
107 107
   private long mStartTime;
108 108
   private float mScaleValue;
......
130 130
     mScreen = new DistortedScreen();
131 131
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
132 132
     mScale = new Static3D(1,1,1);
133
     mCubits= createCubits();
134 133
     }
135 134

  
136 135
///////////////////////////////////////////////////////////////////////////////////////////////////
......
157 156

  
158 157
   private BandagedCubit[] createCubits()
159 158
     {
159
     boolean roundCorners = DistortedLibrary.getGLSL()>300;
160 160
     int len = POSITIONS.length;
161 161
     BandagedCubit[] cubits = new BandagedCubit[len];
162 162

  
163 163
     for(int c=0; c<len; c++)
164 164
       {
165
       cubits[c] = new BandagedCubit(POSITIONS[c],mQuatT,mQuatA,mScale,COLOR_DEFAULT);
165
       cubits[c] = new BandagedCubit(POSITIONS[c],mQuatT,mQuatA,mScale,COLOR_DEFAULT,roundCorners);
166 166
       }
167 167

  
168 168
     return cubits;
......
284 284

  
285 285
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
286 286
      DistortedLibrary.setCull(true);
287

  
288
      mCubits= createCubits();
289
      mView.setCubits(mCubits);
287 290
      }
288 291

  
289 292
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/bandaged/BandagedCreatorTouchControl.java
32 32
  private static final float DIST2D = 0.5f;
33 33

  
34 34
  private final Static4D CAMERA_POINT;
35
  private final BandagedCubit[] mCubits;
36
  private final int mNumCubits;
37 35
  private final float[] mPoint, mCamera, mTouch, mPos;
38 36
  private final float[] mPoint2D;
39 37
  private float mObjectRatio;
40
  private int mLastTouchedFace;
41 38
  private final Static3D[] mFaceAxis;
42 39

  
40
  private BandagedCubit[] mCubits;
41
  private int mNumCubits;
42
  private int mLastTouchedFace;
43

  
43 44
///////////////////////////////////////////////////////////////////////////////////////////////////
44 45

  
45 46
  private boolean isInsideFace(float[] p)
......
207 208
// PUBLIC API
208 209
///////////////////////////////////////////////////////////////////////////////////////////////////
209 210

  
210
  public BandagedCreatorTouchControl(BandagedCubit[] cubits, float ratio, float fov)
211
  public BandagedCreatorTouchControl(float ratio, float fov)
211 212
    {
212
    mCubits = cubits;
213
    mNumCubits = cubits.length;
214 213
    mPoint = new float[3];
215 214
    mCamera= new float[3];
216 215
    mTouch = new float[3];
......
226 225
    CAMERA_POINT = new Static4D(0,0,dist,0);
227 226
    }
228 227

  
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

  
230
  public void setCubits(BandagedCubit[] cubits)
231
    {
232
    mCubits = cubits;
233
    mNumCubits = cubits.length;
234
    }
235

  
229 236
///////////////////////////////////////////////////////////////////////////////////////////////////
230 237

  
231 238
  public void setObjectRatio(float ratio)
src/main/java/org/distorted/bandaged/BandagedCreatorView.java
61 61
        {
62 62
        BandagedCreatorActivity act = (BandagedCreatorActivity)context;
63 63
        mRenderer = new BandagedCreatorRenderer(this);
64
        BandagedCubit[] cubits = mRenderer.getCubits();
65 64
        DistortedScreen screen = mRenderer.getScreen();
66
        mTouchControl = new BandagedCreatorTouchControl(cubits, BandagedCreatorRenderer.SCREEN_RATIO, screen.getFOV() );
65
        mTouchControl = new BandagedCreatorTouchControl(BandagedCreatorRenderer.SCREEN_RATIO, screen.getFOV() );
67 66

  
68 67
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
69 68

  
......
107 106
      return mRenderer;
108 107
      }
109 108

  
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

  
111
    public void setCubits(BandagedCubit[] cubits)
112
      {
113
      mTouchControl.setCubits(cubits);
114
      }
115

  
110 116
///////////////////////////////////////////////////////////////////////////////////////////////////
111 117

  
112 118
    public void resetCubits()
src/main/java/org/distorted/bandaged/BandagedCubit.java
38 38

  
39 39
    private final DistortedNode mNode;
40 40
    private final DistortedTexture mTexture;
41
    private final DistortedEffects mEffects;
42 41
    private final Static3D mMove;
42
    private final boolean mRoundCorners;
43 43

  
44 44
    private float mUnscaledX, mUnscaledY, mUnscaledZ;
45 45
    private float[] mPosition;
......
70 70
// PUBLIC API
71 71
///////////////////////////////////////////////////////////////////////////////////////////////////
72 72

  
73
    public BandagedCubit(float[] position, Static4D quat1, Static4D quat2, Static3D scale, int color)
73
    public BandagedCubit(float[] position, Static4D quat1, Static4D quat2, Static3D scale, int color, boolean roundCorners)
74 74
      {
75
      mRoundCorners = roundCorners;
75 76
      mPosition = position;
76 77
      mIsAttached = true;
77 78

  
......
79 80
      mMove = new Static3D(0,0,0);
80 81

  
81 82
      FactoryBandaged3x3Cubit factory = FactoryBandaged3x3Cubit.getInstance();
82
      MeshBase mesh = factory.createMesh(mPosition,false);
83
      MeshBase mesh = factory.createMesh(mPosition,false,mRoundCorners);
83 84

  
84 85
      mTexture = new DistortedTexture();
85 86
      mTexture.setColorARGB(color);
......
89 90
      MatrixEffectQuaternion quat2Effect = new MatrixEffectQuaternion(quat2, CENTER);
90 91
      MatrixEffectMove moveEffect = new MatrixEffectMove(mMove);
91 92

  
92
      mEffects = new DistortedEffects();
93
      mEffects.apply(scaleEffect);
94
      mEffects.apply(moveEffect);
95
      mEffects.apply(quat2Effect);
96
      mEffects.apply(quat1Effect);
93
      DistortedEffects effects = new DistortedEffects();
94
      effects.apply(scaleEffect);
95
      effects.apply(moveEffect);
96
      effects.apply(quat2Effect);
97
      effects.apply(quat1Effect);
97 98

  
98
      mNode = new DistortedNode(mTexture,mEffects,mesh);
99
      mNode = new DistortedNode(mTexture,effects,mesh);
99 100
      }
100 101

  
101 102
///////////////////////////////////////////////////////////////////////////////////////////////////
......
114 115
      mPosition = tmpPosition;
115 116

  
116 117
      FactoryBandaged3x3Cubit factory = FactoryBandaged3x3Cubit.getInstance();
117
      MeshBase mesh = factory.createMesh(mPosition,false);
118
      MeshBase mesh = factory.createMesh(mPosition,false,mRoundCorners);
118 119
      mNode.setMesh(mesh);
119 120
      mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ);
120 121
      }
......
135 136
      computeMove(mPosition);
136 137

  
137 138
      FactoryBandaged3x3Cubit factory = FactoryBandaged3x3Cubit.getInstance();
138
      MeshBase mesh = factory.createMesh(mPosition,false);
139
      MeshBase mesh = factory.createMesh(mPosition,false,mRoundCorners);
139 140
      mNode.setMesh(mesh);
140 141
      mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ);
141 142
      }
src/main/java/org/distorted/dialogs/RubikDialogAbout.java
104 104
      {
105 105
      text4.setVisibility(View.GONE);
106 106
      /*
107
      text4.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
108 107
      String version = DistortedLibrary.getDriverVersion();
109
      text4.setText(version);
108
      String vendor  = DistortedLibrary.getDriverVendor();
109
      String renderer= DistortedLibrary.getDriverRenderer();
110

  
111
      String mess = "Version: " + version + "\nVendor: "+vendor+"\nRenderer: "+renderer;
112
      text4.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
113
      text4.setText(mess);
110 114
      */
111 115
      }
112 116

  
src/main/java/org/distorted/screens/RubikScreenPlay.java
66 66
  public static final int NUM_COLUMNS  = 5;
67 67
  public static final int LEVELS_SHOWN = 10;
68 68

  
69
  private static final int[] BUTTON_LABELS_FULL = { R.string.scores,
70
                                                    R.string.patterns,
71
                                                    R.string.solver,
72
                                                    R.string.tutorials,
73
                                                    R.string.bandaged,
74
                                                    R.string.about };
75

  
76
  private static final int[] BUTTON_LABELS_LEAN = { R.string.scores,
77
                                                    R.string.patterns,
78
                                                    R.string.solver,
79
                                                    R.string.tutorials,
80
                                                    R.string.about };
69
  private static final int[] BUTTON_LABELS = { R.string.scores,
70
                                               R.string.patterns,
71
                                               R.string.solver,
72
                                               R.string.tutorials,
73
                                               R.string.bandaged,
74
                                               R.string.about };
75
  private static final int NUM_BUTTONS = BUTTON_LABELS.length;
81 76

  
82 77
  private static final float LAST_BUTTON = 1.5f;
83 78
  private static final int[] mLocation = new int[2];
......
96 91
  private int mBottomHeight;
97 92
  private float mScreenWidth;
98 93
  private WeakReference<RubikActivity> mWeakAct;
99
  private boolean mDisplayBandaged;
100
  private int mNumButtons;
101 94

  
102 95
///////////////////////////////////////////////////////////////////////////////////////////////////
103 96

  
......
110 103

  
111 104
  void enterScreen(final RubikActivity act)
112 105
    {
113
    mDisplayBandaged = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
114
    mNumButtons = mDisplayBandaged ? BUTTON_LABELS_FULL.length : BUTTON_LABELS_LEAN.length;
115

  
116 106
    mWeakAct = new WeakReference<>(act);
117 107
    int numObjects = RubikObjectList.getNumObjects();
118 108
    mScreenWidth = act.getScreenWidthInPixels();
......
403 393
    int padding = (int)(width*RubikActivity.PADDING);
404 394

  
405 395
    mMenuLayoutWidth = (int)(width/2);
406
    mMenuLayoutHeight= (int)(2*margin + mNumButtons*(mMenuItemSize+margin));
396
    mMenuLayoutHeight= (int)(2*margin + NUM_BUTTONS*(mMenuItemSize+margin));
407 397

  
408 398
    LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
409 399

  
410
    int[] labels = mDisplayBandaged ? BUTTON_LABELS_FULL : BUTTON_LABELS_LEAN;
411

  
412
    for(int i=0; i<mNumButtons; i++)
400
    for(int i=0; i<NUM_BUTTONS; i++)
413 401
      {
414 402
      final int but = i;
415 403
      Button button = new Button(act);
416 404
      button.setLayoutParams(p);
417
      button.setText(labels[i]);
405
      button.setText(BUTTON_LABELS[i]);
418 406
      button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
419 407

  
420 408
      button.setOnClickListener( new View.OnClickListener()
......
470 458
      case 3: RubikDialogTutorial tDiag = new RubikDialogTutorial();
471 459
              tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
472 460
              break;
473
      case 4: if( mDisplayBandaged )
474
                {
475
                act.switchToBandagedCreator();
476
                break;
477
                }
461
      case 4: act.switchToBandagedCreator();
462
              break;
478 463
      case 5: RubikDialogAbout aDiag = new RubikDialogAbout();
479 464
              aDiag.show(act.getSupportFragmentManager(), null);
480 465
              break;

Also available in: Unified diff