Project

General

Profile

« Previous | Next » 

Revision b4cbe056

Added by Leszek Koltunski about 2 years ago

Disable writing DEPTH and STENCIL to the Screen from both the TwistyObjectNode and the Overlay Node.

View differences:

src/main/java/org/distorted/main/RubikRenderer.java
13 13
import android.opengl.GLES30;
14 14
import android.opengl.GLSurfaceView;
15 15

  
16
import org.distorted.library.main.InternalOutputSurface;
16 17
import org.distorted.objectlib.effects.BaseEffect;
17 18
import org.distorted.library.effect.EffectType;
18 19
import org.distorted.library.effect.VertexEffectQuaternion;
......
22 23
import org.distorted.library.mesh.MeshBase;
23 24
import org.distorted.external.RubikNetwork;
24 25
import org.distorted.objectlib.main.ObjectControl;
26
import org.distorted.overlays.OverlayGeneric;
25 27

  
26 28
import javax.microedition.khronos.egl.EGLConfig;
27 29
import javax.microedition.khronos.opengles.GL10;
......
89 91
     mFPS = new Fps();
90 92
     mScreen = new DistortedScreen();
91 93
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
94
     mScreen.enableDepthStencil(InternalOutputSurface.DEPTH_NO_STENCIL);
92 95
     }
93 96

  
94 97
///////////////////////////////////////////////////////////////////////////////////////////////////
......
124 127
      VertexEffectRotate.enable();
125 128
      VertexEffectQuaternion.enable();
126 129
      BaseEffect.Type.enableEffects();
130
      OverlayGeneric.enableEffects();
127 131

  
128 132
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
129 133
      DistortedLibrary.setCull(true);
src/main/java/org/distorted/main/RubikSurfaceView.java
47 47
        mCreated = true;
48 48
        mObjectController.createNode(width,height);
49 49
        TwistyObjectNode objectNode = mObjectController.getNode();
50
        objectNode.glDepthMask(false);
51
        objectNode.glStencilMask(0);
50 52
        mRenderer.getScreen().attach(objectNode);
51 53
        }
52 54
      }
src/main/java/org/distorted/overlays/OverlayGeneric.java
11 11

  
12 12
import org.distorted.library.main.DistortedScreen;
13 13

  
14
import java.lang.reflect.Method;
15

  
14 16
///////////////////////////////////////////////////////////////////////////////////////////////////
15 17

  
16 18
public abstract class OverlayGeneric
17 19
{
20
   private enum Overlays
21
      {
22
      STARS ( OverlayStars.class )
23
      ;
24

  
25
      private final Class<? extends OverlayGeneric> mClass;
26

  
27
      Overlays(Class<? extends OverlayGeneric> clazz)
28
         {
29
         mClass = clazz;
30
         }
31
      }
32

  
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

  
35
   public static void enableEffects()
36
     {
37
     Method method;
38

  
39
     for(Overlays overlay: Overlays.values() )
40
        {
41
        try
42
          {
43
          method = overlay.mClass.getDeclaredMethod("enableEffects");
44
          }
45
        catch(NoSuchMethodException ex)
46
          {
47
          android.util.Log.e("OverlayGeneric", overlay.mClass.getSimpleName()+": exception getting method: "+ex.getMessage());
48
          method = null;
49
          }
50

  
51
        try
52
          {
53
          if( method!=null ) method.invoke(null);
54
          }
55
        catch(Exception ex)
56
          {
57
          android.util.Log.e("OverlayGeneric", overlay.mClass.getSimpleName()+": exception invoking method: "+ex.getMessage());
58
          }
59
        }
60
      }
61

  
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

  
18 64
   public abstract long startOverlay(DistortedScreen screen, ListenerOverlay listener, DataGeneric data);
19 65
}
src/main/java/org/distorted/overlays/OverlayStars.java
13 13
import android.graphics.Bitmap;
14 14
import android.graphics.BitmapFactory;
15 15

  
16
import org.distorted.library.effect.MatrixEffectMove;
17
import org.distorted.library.effect.MatrixEffectRotate;
18
import org.distorted.library.effect.MatrixEffectScale;
16
import org.distorted.library.effect.VertexEffectMove;
17
import org.distorted.library.effect.VertexEffectRotate;
18
import org.distorted.library.effect.VertexEffectScale;
19 19
import org.distorted.library.main.DistortedEffects;
20 20
import org.distorted.library.main.DistortedNode;
21 21
import org.distorted.library.main.DistortedScreen;
22 22
import org.distorted.library.main.DistortedTexture;
23
import org.distorted.library.main.InternalOutputSurface;
24
import org.distorted.library.mesh.MeshJoined;
23 25
import org.distorted.library.mesh.MeshQuad;
24 26
import org.distorted.library.message.EffectListener;
25 27
import org.distorted.library.type.Dynamic1D;
28
import org.distorted.library.type.Dynamic3D;
26 29
import org.distorted.library.type.Static1D;
27 30
import org.distorted.library.type.Static3D;
28 31
import org.distorted.main.R;
29 32

  
33
import java.util.Random;
34

  
30 35
///////////////////////////////////////////////////////////////////////////////////////////////////
31 36

  
32 37
public class OverlayStars extends OverlayGeneric implements EffectListener
33 38
{
39
   private static final int DUR_ALL = 10000;
40
   private static final int DUR_MOV =  5000;
41

  
34 42
   private ListenerOverlay mListener;
35 43
   private DistortedNode mNode;
36 44
   private DistortedScreen mScreen;
45
   private final Static3D mPointE = new Static3D(0,0,2);
46
   private float mWidth, mHeight;
47
   private Random mRandom;
48

  
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

  
51
   private Dynamic3D createRandomMove()
52
      {
53
      Dynamic3D move = new Dynamic3D();
54
      move.setDuration(DUR_MOV);
55
      move.setCount(0.5f);
56

  
57
      float widthS = (mRandom.nextFloat()-0.5f)*mWidth;
58
      float widthM = widthS + (mRandom.nextFloat()-0.5f)*mWidth*0.2f;
59

  
60
      Static3D pointS = new Static3D(widthS,mHeight/2,2);
61
      Static3D pointM = new Static3D(widthM,mHeight/4,2);
62

  
63
      move.add(pointS);
64
      move.add(pointM);
65
      move.add(mPointE);
66

  
67
      return move;
68
      }
37 69

  
38 70
///////////////////////////////////////////////////////////////////////////////////////////////////
39 71

  
40 72
   private DistortedNode createNode(Resources res, int totS, int newS)
41 73
      {
74
      // texture /////////////////////////////////////////////////////
42 75
      Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.star);
43 76
      DistortedTexture texture = new DistortedTexture();
44 77
      texture.setTexture(bmp);
45 78

  
46
      float scale = mScreen.getWidth()*0.3f;
79
      // mesh ////////////////////////////////////////////////////////
80

  
81
      MeshQuad[] mesh = new MeshQuad[newS+1];
82

  
83
      for(int i=0; i<newS+1; i++)
84
         {
85
         mesh[i] = new MeshQuad();
86
         mesh[i].setEffectAssociation(0,(i==0?0:1),i);
87
         }
47 88

  
48
      Static3D move     = new Static3D(0,0,1);
89
      MeshJoined wholeMesh = new MeshJoined(mesh);
90

  
91
      // effects: main ///////////////////////////////////////////////
92
      DistortedEffects effects = new DistortedEffects();
93

  
94
      float scaleM = mWidth*0.3f;
95
      float scaleP = mWidth*0.1f;
96

  
97
      Static3D moveM    = new Static3D(0,0,1);
49 98
      Static1D point0   = new Static1D(0);
50 99
      Static1D point360 = new Static1D(360);
51 100
      Dynamic1D angle   = new Dynamic1D();
52 101
      angle.add(point0);
53 102
      angle.add(point360);
54 103
      angle.setCount(0.5f);
55
      angle.setDuration(5000);
104
      angle.setDuration(DUR_ALL);
56 105
      Static3D axis = new Static3D(0,0,1);
57 106
      Static3D center = new Static3D(0,0,0);
58 107

  
59
      DistortedEffects effects = new DistortedEffects();
60
      MatrixEffectMove moveEffect = new MatrixEffectMove(move);
61
      MatrixEffectScale scaleEffect = new MatrixEffectScale(scale);
62
      MatrixEffectRotate rotateEffect = new MatrixEffectRotate(angle,axis,center);
63
      effects.apply(moveEffect);
64
      effects.apply(scaleEffect);
65
      effects.apply(rotateEffect);
66

  
67
      rotateEffect.notifyWhenFinished(this);
68

  
69
      MeshQuad mesh = new MeshQuad();
70

  
71
      return new DistortedNode(texture,effects,mesh);
108
      VertexEffectMove mainMove     = new VertexEffectMove(moveM);
109
      VertexEffectScale mainScale   = new VertexEffectScale(scaleM);
110
      VertexEffectRotate mainRotate = new VertexEffectRotate(angle,axis,center);
111
      mainMove.setMeshAssociation(2,0);
112
      mainScale.setMeshAssociation(2,0);
113
      mainRotate.setMeshAssociation(2,0);
114
      mainRotate.notifyWhenFinished(this);
115

  
116
      // effects: moving stars ///////////////////////////////////////
117
      VertexEffectScale scaleE = new VertexEffectScale(scaleP);
118
      scaleE.setMeshAssociation(1,-1);
119
      effects.apply(scaleE);
120

  
121
      for(int i=1; i<newS+1; i++)
122
        {
123
        Dynamic3D moveP = createRandomMove();
124
        VertexEffectMove moveE= new VertexEffectMove(moveP);
125
        moveE.setMeshAssociation(2,i);
126
        effects.apply(moveE);
127
        }
128

  
129
      // main effect queue ///////////////////////////////////////////
130
      effects.apply(mainMove);
131
      effects.apply(mainScale);
132
      effects.apply(mainRotate);
133

  
134
      return new DistortedNode(texture,effects,wholeMesh);
72 135
      }
73 136

  
74 137
///////////////////////////////////////////////////////////////////////////////////////////////////
75 138

  
76 139
   public long startOverlay(DistortedScreen screen, ListenerOverlay listener, DataGeneric data)
77 140
      {
141
      if( mRandom==null ) mRandom = new Random();
142

  
78 143
      mScreen = screen;
79 144
      mListener= listener;
80 145
      DataStars stars = (DataStars)data;
......
82 147
      int newS = stars.getNew();
83 148
      Resources res = stars.getResources();
84 149

  
150
      mWidth = mScreen.getWidth();
151
      mHeight= mScreen.getHeight();
152

  
85 153
      mNode = createNode(res,totS,newS);
154
      mNode.glDepthMask(false);
155
      mNode.glStencilMask(0);
156
      mNode.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
86 157
      mScreen.attach(mNode);
87 158

  
88 159
      return 0;
......
95 166
      mScreen.detach(mNode);
96 167
      mListener.overlayFinished(id);
97 168
      }
169

  
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

  
172
  @SuppressWarnings("unused")
173
  public static void enableEffects()
174
     {
175
     VertexEffectMove.enable();
176
     VertexEffectScale.enable();
177
     VertexEffectRotate.enable();
178
     }
98 179
}

Also available in: Unified diff