Project

General

Profile

« Previous | Next » 

Revision 7691a39f

Added by Leszek Koltunski about 7 years ago

- workaround for the issue with flashing in StarWars
- return number of objects rendered from OutputSurface.render() and use this in Olympic
- rework tree isomorphism so that it now works even if we don't render the whole tree (and also we don't have to reset() the Tree anymore!)
- current a buf with tree isomorphism: Leaf Nodes have the same NodeData only if they agree in Surface AND Effects!

View differences:

src/main/java/org/distorted/library/Distorted.java
30 30
 */
31 31
public class Distorted 
32 32
  {
33
  /**
34
   * When creating an instance of a DistortedTexture (or Tree) from another instance, do not clone anything.
35
   * Used in the copy constructor.
36
   */
37
  public static final int CLONE_NOTHING = 0x0;
38 33
  /**
39 34
   * When creating an instance of a DistortedTexture from another instance, clone the Bitmap that's
40 35
   * backing up our DistortedTexture.
......
121 116
    DistortedEffects.createProgram(resources);
122 117
    EffectQueuePostprocess.createProgram(resources);
123 118

  
124
    DistortedNode.reset();
125 119
    EffectMessageSender.startSending();
126 120

  
127 121
    mInitialized = true;
src/main/java/org/distorted/library/DistortedNode.java
52 52
    {
53 53
    long ID;
54 54
    int numPointingNodes;
55
    int numRendered;
55
    int numRender;
56 56
    ArrayList<Long> key;
57 57
    DistortedFramebuffer mFBO;
58 58

  
......
61 61
      ID              = id;
62 62
      key             = k;
63 63
      numPointingNodes= 1;
64
      numRendered     = 0;
64
      numRender       =-1;
65 65
      mFBO            = null;
66 66
      }
67 67
    }
......
81 81
    ArrayList<Long> ret = new ArrayList<>();
82 82
     
83 83
    ret.add( mSurface.getID() );
84

  
85
    if( mNumChildren[0]==0 )
86
      {
87
      ret.add(-mEffects.getID());
88
      }
89

  
84 90
    DistortedNode node;
85 91
   
86 92
    for(int i=0; i<mNumChildren[0]; i++)
......
92 98
    return ret;
93 99
    }
94 100

  
95
///////////////////////////////////////////////////////////////////////////////////////////////////  
96
// this will be called on startup and every time OpenGL context has been lost
97

  
98
  static void reset()
99
    {
100
    NodeData tmp;   
101
     
102
    for(ArrayList<Long> key: mMapNodeID.keySet())
103
      {
104
      tmp = mMapNodeID.get(key);
105
          
106
      if( tmp.mFBO != null ) tmp.numRendered = 0;
107
      }
108
    }
109

  
110 101
///////////////////////////////////////////////////////////////////////////////////////////////////
111 102
// Debug - print all the Node IDs
112 103

  
......
208 199
    }
209 200

  
210 201
///////////////////////////////////////////////////////////////////////////////////////////////////
202
// return the total number of render calls issued
211 203

  
212
  void drawRecursive(long currTime, DistortedOutputSurface surface)
204
  int drawRecursive(int render, long currTime, DistortedOutputSurface surface)
213 205
    {
206
    int ret = 0;
214 207
    float halfX = mSurface.getWidth()/2.0f;
215 208
    float halfY = mSurface.getHeight()/2.0f;
216 209

  
......
220 213
      }
221 214
    else
222 215
      {
223
      if( mData.numRendered==0 )
216
      if( mData.numRender!=render )
224 217
        {
218
        mData.numRender = render;
225 219
        mData.mFBO.setAsOutput();
226 220

  
227 221
        GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
228 222
        GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
229 223

  
230 224
        if( mSurface.setAsInput() )
231
          DistortedEffects.drawNoEffectsPriv(halfX, halfY, mMesh, mData.mFBO );
225
          {
226
          ret++;
227
          DistortedEffects.drawNoEffectsPriv(halfX, halfY, mMesh, mData.mFBO);
228
          }
232 229

  
233 230
        for(int i=0; i<mNumChildren[0]; i++)
234 231
          {
235
          mChildren.get(i).drawRecursive(currTime, mData.mFBO);
232
          ret += mChildren.get(i).drawRecursive(render, currTime, mData.mFBO);
236 233
          }
237 234
        }
238 235

  
239
      mData.numRendered++;
240
      mData.numRendered %= mData.numPointingNodes;
241 236
      mData.mFBO.setAsInput();
242 237
      }
243 238

  
244 239
    mEffects.drawPriv(halfX, halfY, mMesh, surface, currTime);
240

  
241
    return ret+1;
245 242
    }
246 243

  
247 244
///////////////////////////////////////////////////////////////////////////////////////////////////
......
265 262
   
266 263
    ArrayList<Long> list = new ArrayList<>();
267 264
    list.add(mSurface.getID());
265
    list.add(-mEffects.getID());
268 266

  
269 267
    mData = mMapNodeID.get(list);
270 268
   
src/main/java/org/distorted/library/DistortedOutputSurface.java
27 27

  
28 28
abstract class DistortedOutputSurface extends DistortedSurface implements DistortedAttacheable
29 29
{
30
  private static int mRender = 0;
31

  
30 32
  private ArrayList<DistortedNode> mChildren;
31 33
  private int mNumChildren;   // ==mChildren.length(), but we only create mChildren if the first one gets added
32 34

  
......
105 107
 * Must be called from a thread holding OpenGL Context.
106 108
 *
107 109
 * @param time Current time, in milliseconds. This will be passed to all the Effects stored in the children Nodes.
110
 * @return Number of objects rendered.
108 111
 */
109
  public void render(long time)
112
  public int render(long time)
110 113
    {
114
    mRender++;
115

  
111 116
    // change tree topology (attach and detach children)
112 117
    // create and delete all underlying OpenGL resources
113 118
    // Watch out: FIRST change topology, only then deal
......
125 130
        mChildren.get(i).debug(0);
126 131
        }
127 132

  
128
      //DistortedNode.debugMap();
133
      DistortedNode.debugMap();
129 134
      }
130 135

  
131 136
    toDo();
......
135 140
      DistortedSurface.debugLists();
136 141
      }
137 142

  
143
    int numRenders = 0;
144

  
138 145
    for(int i=0; i<mNumChildren; i++)
139 146
      {
140
      mChildren.get(i).drawRecursive(time,this);
147
      numRenders += mChildren.get(i).drawRecursive(mRender,time,this);
141 148
      }
149

  
150
    return numRenders;
142 151
    }
143 152

  
144 153
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff