Project

General

Profile

« Previous | Next » 

Revision 78ff6ea9

Added by Leszek Koltunski over 3 years ago

Convert the Integer part (i.e. effect names and the two associations) of vertex and fragment shaders to Uniform Buffer Objects.
Next: convert the last part, i.e. the float effect parameters.

View differences:

src/main/java/org/distorted/library/effectqueue/EffectQueue.java
39 39
  {
40 40
  public static final int MAIN_VARIANTS = 4; // Number of Main program variants (ATM 4: MAIN, MAIN OIT, PREPROCESS, FULL)
41 41

  
42
  static final int PROP_VERT_UBO_BINDING = 5;
43
  static final int PROP_FRAG_UBO_BINDING = 6;
44

  
42 45
  private static final int CREATE = 0;
43 46
  private static final int ATTACH = 1;
44 47
  private static final int DETACH = 2;
......
47 50
  long mTime;
48 51
  int mNumEffects;              // 'ToBe' will be more than mNumEffects if doWork() hasn't
49 52
  private int mNumEffectsToBe;  // added them yet (or less if it hasn't removed some yet)
50
  private int mNumFloatUniforms, mNumIntUniforms;
53
  private final int mNumFloatUniforms;
51 54
  Effect[] mEffects;
52 55

  
53 56
  float[] mFloatUniforms;
54
  int[] mIntUniforms;
57
  UniformBlockProperties mUBP;
55 58

  
56 59
  private long mID;
57
  private int mIndex;
60
  private final int mIndex;
58 61
  private boolean mCreated;
59 62

  
60 63
  private static class Job
......
74 77
      }
75 78
    }
76 79

  
77
  private ArrayList<Job> mJobs = new ArrayList<>();
80
  private final ArrayList<Job> mJobs;
78 81

  
79 82
///////////////////////////////////////////////////////////////////////////////////////////////////
80 83
   
......
87 90
    mNumEffectsToBe   = 0;
88 91
    mIndex            = index;
89 92
    mNumFloatUniforms = numFloatUniforms;
90
    mNumIntUniforms   = numIntUniforms;
93

  
94
    mUBP  = new UniformBlockProperties(numIntUniforms);
95
    mJobs = new ArrayList<>();
91 96

  
92 97
    mJobs.add(new Job(CREATE,numFloatUniforms,numIntUniforms, false,null)); // create the stuff that depends on max number
93 98
    InternalMaster.newSlave(this);                                          // of uniforms later, on first render.
......
107 112
      mNumEffectsToBe   = 0;
108 113
      mIndex            = source.mIndex;
109 114
      mNumFloatUniforms = source.mNumFloatUniforms;
110
      mNumIntUniforms   = source.mNumIntUniforms;
115

  
116
      mUBP  = new UniformBlockProperties(source.mUBP);
117
      mJobs = new ArrayList<>();
111 118

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

  
......
128 135
      mNumEffectsToBe   = source.mNumEffectsToBe;
129 136
      mIndex            = source.mIndex;
130 137
      mNumFloatUniforms = source.mNumFloatUniforms;
131
      mNumIntUniforms   = source.mNumIntUniforms;
138

  
139
      mUBP  = new UniformBlockProperties(source.mUBP);
140
      mJobs = new ArrayList<>();
132 141

  
133 142
      int max = InternalStackFrameList.getMax(mIndex);
134 143

  
......
136 145
        {
137 146
        mEffects       = new Effect[max];
138 147
        mFloatUniforms = new float[max*source.mNumFloatUniforms];
139
        mIntUniforms   = new int[max*source.mNumIntUniforms];
140 148

  
141 149
        if( mNumEffects>=0 )
142 150
          {
143 151
          System.arraycopy(source.mEffects, 0, mEffects, 0, mNumEffects);
144 152
          }
145

  
146
        if( mNumIntUniforms*mNumEffects>=0 )
147
          {
148
          System.arraycopy(source.mIntUniforms, 0, mIntUniforms, 0, mNumIntUniforms*mNumEffects);
149
          }
150 153
        }
151 154
      }
152 155
    }
......
173 176

  
174 177
///////////////////////////////////////////////////////////////////////////////////////////////////
175 178

  
176
  public static void send(EffectQueue[] queues, float distance, float mipmap,
179
  public static void send(EffectQueue[] queues, int programH, float distance, float mipmap,
177 180
                          float[] projection, float inflate, int variant )
178 181
    {
179 182
    ((EffectQueueMatrix  )queues[0]).send(distance, mipmap, projection, variant);
180
    ((EffectQueueVertex  )queues[1]).send(inflate, variant);
181
    ((EffectQueueFragment)queues[2]).send(variant);
183
    ((EffectQueueVertex  )queues[1]).send(inflate, programH, variant);
184
    ((EffectQueueFragment)queues[2]).send(programH, variant);
182 185
    }
183 186

  
184 187
///////////////////////////////////////////////////////////////////////////////////////////////////
......
252 255
      mNumEffects--;
253 256
      mEffects[pos].remQueue(this);
254 257
      System.arraycopy(mEffects, pos+1, mEffects, pos, mNumEffects-pos);
255
      System.arraycopy(mIntUniforms, mNumIntUniforms*(pos+1), mIntUniforms, mNumIntUniforms*pos, mNumIntUniforms*(mNumEffects-pos) );
258
      mUBP.remove(pos, mNumEffects);
256 259
      mEffects[mNumEffects] = null;
257 260
      }
258 261
    }
......
261 264

  
262 265
  private void addNow(int pos, Effect effect)
263 266
    {
264
    mEffects[pos]                     = effect;
265
    mIntUniforms[mNumIntUniforms*pos] = effect.getName().ordinal();
266

  
267
    mEffects[pos] = effect;
268
    mUBP.addOrdinal(pos, effect.getName().ordinal() );
267 269
    effect.addQueue(this);
268 270

  
269 271
    if( mIndex==EffectType.VERTEX.ordinal() )
270 272
      {
271
      effect.writeAssociations(mIntUniforms, mNumIntUniforms*pos+1, mNumIntUniforms*pos+3);
273
      mUBP.addAssociations(pos,effect);
272 274
      }
273 275
    }
274 276

  
......
411 413
      {
412 414
      if (mEffects[j].getID() == effectID)
413 415
        {
414
        mEffects[j].writeAssociations(mIntUniforms, mNumIntUniforms*j+1, mNumIntUniforms*j+3);
416
        mUBP.addAssociations(j,mEffects[j]);
415 417
        }
416 418
      }
417 419
    }
......
435 437
                       {
436 438
                       mEffects       = new Effect[max];
437 439
                       mFloatUniforms = new float[max*job.num1];
438
                       mIntUniforms   = new int[max*job.num2];
440
                       mUBP           = new UniformBlockProperties(job.num2);
439 441
                       }
440 442
                     mCreated = true;
441 443

  
......
452 454
                         }
453 455
                       else if( position<=mNumEffects )
454 456
                         {
455
                         System.arraycopy(mEffects    , position, mEffects    , position+1, mNumEffects-position);
456
                         System.arraycopy(mIntUniforms, mNumIntUniforms*position, mIntUniforms, mNumIntUniforms*(position+1), mNumIntUniforms*(mNumEffects-position) );
457
                         System.arraycopy(mEffects, position, mEffects, position+1, mNumEffects-position);
458
                         mUBP.makeHole(position, mNumEffects);
457 459
                         addNow(position,job.effect);
458 460
                         mNumEffects++;
459 461
                         changed = true;

Also available in: Unified diff