Project

General

Profile

« Previous | Next » 

Revision 96e3b88a

Added by Leszek Koltunski over 3 years ago

Introducing UBO to Effect Queues: step 1.

View differences:

src/main/java/org/distorted/library/effectqueue/EffectQueue.java
24 24
import org.distorted.library.effect.EffectType;
25 25
import org.distorted.library.main.DistortedLibrary;
26 26
import org.distorted.library.main.InternalMaster;
27
import org.distorted.library.mesh.MeshBase;
28 27

  
29 28
import java.util.ArrayList;
30 29
import java.util.HashMap;
......
44 43
  private static final int DETACH = 2;
45 44
  private static final int DETALL = 3;
46 45

  
46
  long mTime;
47 47
  int mNumEffects;              // 'ToBe' will be more than mNumEffects if doWork() hasn't
48 48
  private int mNumEffectsToBe;  // added them yet (or less if it hasn't removed some yet)
49
  float[] mUniforms;
50
  private int mNumUniforms;
49
  private int mNumFloatUniforms, mNumIntUniforms;
51 50
  Effect[] mEffects;
52
  int[] mName;
53
  int[] mAndAssociation;
54
  int[] mEquAssociation;
55
  long mTime;
56 51

  
57
  private static int[] mMax = new int[EffectType.LENGTH];
52
  float[] mFloatUniforms;
53
  int[] mIntUniforms;
54

  
55
  static int[] mMax = new int[EffectType.LENGTH];
58 56
  private static long mNextID;
59 57
  private static HashMap<ArrayList<Long>,Long> mMapID = new HashMap<>(); // maps lists of Effect IDs (longs) to a
60 58
                                                                         // single long - the queue ID.
......
65 63
  private static class Job
66 64
    {
67 65
    int type;
68
    int num;
66
    int num1, num2;
69 67
    boolean notify;
70 68
    Effect effect;
71 69

  
72
    Job(int t, int m, boolean n, Effect e)
70
    Job(int t, int m1, int m2, boolean n, Effect e)
73 71
      {
74 72
      type  = t;
75
      num   = m;
73
      num1  = m1;
74
      num2  = m2;
76 75
      notify= n;
77 76
      effect= e;
78 77
      }
......
87 86
  
88 87
///////////////////////////////////////////////////////////////////////////////////////////////////
89 88
   
90
  EffectQueue(int numUniforms, int index)
89
  EffectQueue(int numFloatUniforms, int numIntUniforms, int index)
91 90
    {
92
    mCreated            = false;
93
    mTime               = 0;
94
    mID                 = 0;
95
    mNumEffects         = 0;
96
    mNumEffectsToBe     = 0;
97
    mIndex              = index;
98
    mNumUniforms        = numUniforms;
99

  
100
    mJobs.add(new Job(CREATE,numUniforms,false,null)); // create the stuff that depends on max number
101
    InternalMaster.newSlave(this);                     // of uniforms later, on first render.
91
    mCreated          = false;
92
    mTime             = 0;
93
    mID               = 0;
94
    mNumEffects       = 0;
95
    mNumEffectsToBe   = 0;
96
    mIndex            = index;
97
    mNumFloatUniforms = numFloatUniforms;
98
    mNumIntUniforms   = numIntUniforms;
99

  
100
    mJobs.add(new Job(CREATE,numFloatUniforms,numIntUniforms, false,null)); // create the stuff that depends on max number
101
    InternalMaster.newSlave(this);                                          // of uniforms later, on first render.
102 102
    }
103 103

  
104 104
///////////////////////////////////////////////////////////////////////////////////////////////////
......
108 108
    {
109 109
    if( !source.mCreated )
110 110
      {
111
      mCreated            = false;
112
      mTime               = 0;
113
      mID                 = 0;
114
      mNumEffects         = 0;
115
      mNumEffectsToBe     = 0;
116
      mIndex              = source.mIndex;
117
      mNumUniforms        = source.mNumUniforms;
111
      mCreated          = false;
112
      mTime             = 0;
113
      mID               = 0;
114
      mNumEffects       = 0;
115
      mNumEffectsToBe   = 0;
116
      mIndex            = source.mIndex;
117
      mNumFloatUniforms = source.mNumFloatUniforms;
118
      mNumIntUniforms   = source.mNumIntUniforms;
118 119

  
119 120
      int numJobs = source.mJobs.size();
120 121

  
......
128 129
      }
129 130
    else
130 131
      {
131
      mCreated            = true;
132
      mTime               = source.mTime;
133
      mID                 = source.mID;
134
      mNumEffects         = source.mNumEffects;
135
      mNumEffectsToBe     = source.mNumEffectsToBe;
136
      mIndex              = source.mIndex;
137
      mNumUniforms        = source.mNumUniforms;
132
      mCreated          = true;
133
      mTime             = source.mTime;
134
      mID               = source.mID;
135
      mNumEffects       = source.mNumEffects;
136
      mNumEffectsToBe   = source.mNumEffectsToBe;
137
      mIndex            = source.mIndex;
138
      mNumFloatUniforms = source.mNumFloatUniforms;
139
      mNumIntUniforms   = source.mNumIntUniforms;
138 140

  
139 141
      int max = mMax[mIndex];
140
      if( max>0 )
141
        {
142
        mUniforms        = new float[max*source.mNumUniforms];
143
        mEffects         = new Effect[max];
144
        mName            = new int[max];
145
        mAndAssociation  = new int[max];
146
        mEquAssociation  = new int[max];
147
        }
148 142

  
149
      for(int i=0; i<mNumEffects; i++ )
143
      if( max>0 )
150 144
        {
151
        mEffects[i]         = source.mEffects[i];
152
        mName[i]            = source.mName[i];
153
        mAndAssociation[i]  = source.mAndAssociation[i];
154
        mEquAssociation[i]  = source.mEquAssociation[i];
145
        mEffects       = new Effect[max];
146
        mFloatUniforms = new float[max*source.mNumFloatUniforms];
147
        mIntUniforms   = new int[max*source.mNumIntUniforms];
148

  
149
        if( mNumEffects>=0 )
150
          {
151
          System.arraycopy(source.mEffects, 0, mEffects, 0, mNumEffects);
152
          }
153

  
154
        if( mNumIntUniforms*mNumEffects>=0 )
155
          {
156
          System.arraycopy(source.mIntUniforms, 0, mIntUniforms, 0, mNumIntUniforms*mNumEffects);
157
          }
155 158
        }
156 159
      }
157 160
    }
......
268 271
    {
269 272
    mNumEffects--;
270 273

  
271
    for(int j=effect; j<mNumEffects; j++ )
274
    int max = mMax[mIndex];
275

  
276
    for(int i=effect; i<mNumEffects; i++ )
272 277
      {
273
      mEffects[j]         = mEffects[j+1];
274
      mName[j]            = mName[j+1];
275
      mAndAssociation[j]  = mAndAssociation[j+1];
276
      mEquAssociation[j]  = mEquAssociation[j+1];
278
      mEffects[i]= mEffects[i+1];
279

  
280
      for(int j=0; j<mNumIntUniforms; j++)
281
        {
282
        mIntUniforms[j*max + i] = mIntUniforms[j*max + i+1];
283
        }
277 284
      }
278 285

  
279 286
    mEffects[mNumEffects] = null;
......
289 296
      {
290 297
      if( mEffects[i].getName() == name )
291 298
        {
292
        mJobs.add(new Job(DETACH,0,true,mEffects[i]));
299
        mJobs.add(new Job(DETACH,0,0,true,mEffects[i]));
293 300
        ret++;
294 301
        }
295 302
      }
......
311 318
      {
312 319
      if( mEffects[i].getID() == id )
313 320
        {
314
        mJobs.add(new Job(DETACH,0,true,mEffects[i]));
321
        mJobs.add(new Job(DETACH,0,0,true,mEffects[i]));
315 322
        InternalMaster.newSlave(this);
316 323
        mNumEffectsToBe--;
317 324
        return 1;
......
329 336
      {
330 337
      if( mEffects[i]==effect )
331 338
        {
332
        mJobs.add(new Job(DETACH,0,true,mEffects[i]));
339
        mJobs.add(new Job(DETACH,0,0,true,mEffects[i]));
333 340
        InternalMaster.newSlave(this);
334 341
        mNumEffectsToBe--;
335 342
        return 1;
......
345 352

  
346 353
  public synchronized int removeAll(boolean notify)
347 354
    {
348
    mJobs.add(new Job(DETALL,0,notify,null));
355
    mJobs.add(new Job(DETALL,0,0,notify,null));
349 356
    InternalMaster.newSlave(this);
350 357
    mNumEffectsToBe = 0;
351 358
    return mNumEffects;
......
357 364
    {
358 365
    if( mMax[mIndex]>mNumEffectsToBe || !mCreated )
359 366
      {
360
      mJobs.add(new Job(ATTACH,-1,false,effect));
367
      mJobs.add(new Job(ATTACH,-1,0,false,effect));
361 368
      InternalMaster.newSlave(this);
362 369
      mNumEffectsToBe++;
363 370
      return true;
......
372 379
    {
373 380
    if( mMax[mIndex]>mNumEffectsToBe || !mCreated )
374 381
      {
375
      mJobs.add(new Job(ATTACH,position,false,effect));
382
      mJobs.add(new Job(ATTACH,position,0,false,effect));
376 383
      InternalMaster.newSlave(this);
377 384
      mNumEffectsToBe++;
378 385
      return true;
......
427 434
        case CREATE: int max = mMax[mIndex];
428 435
                     if( max>0 )
429 436
                       {
430
                       mUniforms        = new float[max*job.num];
431
                       mEffects         = new Effect[max];
432
                       mName            = new int[max];
433
                       mAndAssociation  = new int[max];
434
                       mEquAssociation  = new int[max];
437
                       mEffects       = new Effect[max];
438
                       mFloatUniforms = new float[max*job.num1];
439
                       mIntUniforms   = new int[max*job.num2];
435 440
                       }
436 441
                     mCreated = true;
437 442

  
438 443
                     break;
439 444
        case ATTACH: if( mMax[mIndex]>mNumEffects ) // it is possible that we have first
440 445
                       {                            // added effects and then lowered mMax
441
                       int position = job.num;
446
                       int position = job.num1;
442 447

  
443 448
                       if( position==-1 )
444 449
                         {
445
                         mEffects[mNumEffects]        = job.effect;
446
                         mName[mNumEffects]           = job.effect.getName().ordinal();
447
                         mAndAssociation[mNumEffects] = job.effect.getAndAssociation();
448
                         mEquAssociation[mNumEffects] = job.effect.getEquAssociation();
450
                         mEffects[mNumEffects]     = job.effect;
451
                         mIntUniforms[mNumEffects] = job.effect.getName().ordinal();
449 452

  
450 453
                         mNumEffects++;
451 454
                         changed = true;
......
454 457
                         {
455 458
                         for(int j=mNumEffects; j>position; j--)
456 459
                           {
457
                           mEffects[j]         = mEffects[j-1];
458
                           mName[j]            = mName[j-1];
459
                           mAndAssociation[j]  = mAndAssociation[j-1];
460
                           mEquAssociation[j]  = mEquAssociation[j-1];
460
                           mEffects[j]     = mEffects[j-1];
461
                           mIntUniforms[j] = mIntUniforms[j-1];
461 462
                           }
462 463

  
463
                         mEffects[position]        = job.effect;
464
                         mName[position]           = job.effect.getName().ordinal();
465
                         mAndAssociation[position] = job.effect.getAndAssociation();
466
                         mEquAssociation[position] = job.effect.getEquAssociation();
464
                         mEffects[position]     = job.effect;
465
                         mIntUniforms[position] = job.effect.getName().ordinal();
467 466

  
468 467
                         mNumEffects++;
469 468
                         changed = true;

Also available in: Unified diff