Project

General

Profile

« Previous | Next » 

Revision 26671ef8

Added by Leszek Koltunski over 4 years ago

Library: make setEffectAssociation a deferred job (because we do copy the uniforms during join!)
SingleMesh App: almost finished.

View differences:

src/main/java/org/distorted/library/mesh/DeferredJobs.java
44 44
  private static final int JOB_TYPE_JOIN     = 4;
45 45
  private static final int JOB_TYPE_COPY     = 5;
46 46
  private static final int JOB_TYPE_TEXTURE  = 6;
47
  private static final int JOB_TYPE_ASSOC    = 7;
47 48

  
48 49
  private static ArrayList<JobNode> mJobs = new ArrayList<>();
49 50

  
......
57 58
    private EffectQueueVertex mVertexEffects;
58 59
    private MatrixEffect mMatrixEffect;
59 60
    private Static4D[] mMaps;
60
    private int mAndAssoc, mEcuAssoc;
61
    private int mComp, mAndAssoc, mEquAssoc;
61 62

  
62
    Job(int type, MeshBase target, MeshBase[] source, VertexEffect vEff, MatrixEffect mEff, Static4D[] maps, int and, int ecu)
63
    Job(int type, MeshBase target, MeshBase[] source, VertexEffect vEff, MatrixEffect mEff, Static4D[] maps, int comp, int and, int equ)
63 64
      {
64 65
      mType     = type;
65 66
      mTarget   = target;
66 67
      mSource   = source;
67 68
      mMaps     = maps;
69
      mComp     = comp;
68 70
      mAndAssoc = and;
69
      mEcuAssoc = ecu;
71
      mEquAssoc = equ;
70 72

  
71 73
      if( vEff!=null )
72 74
        {
......
88 90
        {
89 91
        case JOB_TYPE_VERTEX   : DistortedLibrary.adjustVertices(mTarget, mVertexEffects);
90 92
                                 break;
91
        case JOB_TYPE_MATRIX   : mTarget.applyMatrix(mMatrixEffect,mAndAssoc,mEcuAssoc);
93
        case JOB_TYPE_MATRIX   : mTarget.applyMatrix(mMatrixEffect,mAndAssoc,mEquAssoc);
92 94
                                 break;
93 95
        case JOB_TYPE_MERGE_TEX: mTarget.mergeTexComponentsNow();
94 96
                                 break;
......
100 102
                                 break;
101 103
        case JOB_TYPE_TEXTURE  : mTarget.textureMap(mMaps);
102 104
                                 break;
105
        case JOB_TYPE_ASSOC    : mTarget.setEffectAssociationNow(mComp,mAndAssoc,mEquAssoc);
106
                                 break;
103 107
        }
104 108
/*
105 109
      Log.e("jobs", "executing "+print()+" job");
......
123 127
        case JOB_TYPE_JOIN     : return "JOIN";
124 128
        case JOB_TYPE_COPY     : return "COPY";
125 129
        case JOB_TYPE_TEXTURE  : return "TEXTURE";
130
        case JOB_TYPE_ASSOC    : return "ASSOC";
126 131
        }
127 132

  
128 133
      return null;
......
226 231

  
227 232
    if( jn==null )
228 233
      {
229
      Job job = new Job(JOB_TYPE_VERTEX,target,null,effect,null,null,0,0);
234
      Job job = new Job(JOB_TYPE_VERTEX,target,null,effect,null,null,0,0,0);
230 235
      JobNode node = new JobNode(job);
231 236
      mJobs.add(node);
232 237
      return node;
......
240 245
        }
241 246
      else
242 247
        {
243
        Job job = new Job(JOB_TYPE_VERTEX,target,null,effect,null,null,0,0);
248
        Job job = new Job(JOB_TYPE_VERTEX,target,null,effect,null,null,0,0,0);
244 249
        JobNode node = new JobNode(job);
245 250
        node.mPrevJobs.add(jn);
246 251
        jn.mNextJobs.add(node);
......
255 260
  static JobNode matrix(MeshBase target, MatrixEffect effect, int andAssoc, int ecuAssoc)
256 261
    {
257 262
    JobNode jn = target.mJobNode[0];
258
    Job job = new Job(JOB_TYPE_MATRIX,target,null,null,effect,null,andAssoc,ecuAssoc);
263
    Job job = new Job(JOB_TYPE_MATRIX,target,null,null,effect,null,0,andAssoc,ecuAssoc);
259 264
    JobNode node = new JobNode(job);
260 265
    node.mPrevJobs.add(jn);
261 266
    jn.mNextJobs.add(node);
......
268 273
  static JobNode mergeTex(MeshBase target)
269 274
    {
270 275
    JobNode jn = target.mJobNode[0];
271
    Job job = new Job(JOB_TYPE_MERGE_TEX,target,null,null,null,null,0,0);
276
    Job job = new Job(JOB_TYPE_MERGE_TEX,target,null,null,null,null,0,0,0);
272 277
    JobNode node = new JobNode(job);
273 278
    node.mPrevJobs.add(jn);
274 279
    jn.mNextJobs.add(node);
......
281 286
  static JobNode mergeEff(MeshBase target)
282 287
    {
283 288
    JobNode jn = target.mJobNode[0];
284
    Job job = new Job(JOB_TYPE_MERGE_EFF,target,null,null,null,null,0,0);
289
    Job job = new Job(JOB_TYPE_MERGE_EFF,target,null,null,null,null,0,0,0);
285 290
    JobNode node = new JobNode(job);
286 291
    node.mPrevJobs.add(jn);
287 292
    jn.mNextJobs.add(node);
......
295 300
    {
296 301
    JobNode jn;
297 302

  
298
    Job job = new Job(JOB_TYPE_JOIN,target,meshes,null,null,null,0,0);
303
    Job job = new Job(JOB_TYPE_JOIN,target,meshes,null,null,null,0,0,0);
299 304
    JobNode node = new JobNode(job);
300 305

  
301 306
    for (MeshBase mesh : meshes)
......
320 325
    JobNode jn = mesh.mJobNode[0];
321 326
    MeshBase[] meshes = new MeshBase[1];
322 327
    meshes[0] = mesh;
323
    Job job = new Job(JOB_TYPE_COPY,target,meshes,null,null,null,0,0);
328
    Job job = new Job(JOB_TYPE_COPY,target,meshes,null,null,null,0,0,0);
324 329
    JobNode node = new JobNode(job);
325 330
    node.mPrevJobs.add(jn);
326 331
    jn.mNextJobs.add(node);
......
333 338
  static JobNode textureMap(MeshBase target, Static4D[] maps)
334 339
    {
335 340
    JobNode jn = target.mJobNode[0];
336
    Job job = new Job(JOB_TYPE_TEXTURE,target,null,null,null,maps,0,0);
341
    Job job = new Job(JOB_TYPE_TEXTURE,target,null,null,null,maps,0,0,0);
342
    JobNode node = new JobNode(job);
343
    node.mPrevJobs.add(jn);
344
    jn.mNextJobs.add(node);
345
    mJobs.add(node);
346
    return node;
347
    }
348

  
349
///////////////////////////////////////////////////////////////////////////////////////////////////
350

  
351
  static JobNode effectAssoc(MeshBase target, int comp, int andAssoc, int equAssoc)
352
    {
353
    JobNode jn = target.mJobNode[0];
354
    Job job = new Job(JOB_TYPE_ASSOC,target,null,null,null,null,comp,andAssoc,equAssoc);
337 355
    JobNode node = new JobNode(job);
338 356
    node.mPrevJobs.add(jn);
339 357
    jn.mNextJobs.add(node);
src/main/java/org/distorted/library/mesh/MeshBase.java
306 306
       }
307 307
     }
308 308

  
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

  
311
   void setEffectAssociationNow(int component, int andAssociation, int equAssociation)
312
     {
313
     mAndAssociation[component] = andAssociation;
314
     mEquAssociation[component] = equAssociation;
315
     }
316

  
309 317
///////////////////////////////////////////////////////////////////////////////////////////////////
310 318

  
311 319
   int numTexComponents()
......
344 352
     TexComponent comp;
345 353
     int numMeshes = meshes.length;
346 354
     int numVertices,origVertices = mNumVertices;
347
     int origTexComponents=0,numTexComponents;
355
     int origTexComponents,numTexComponents;
348 356
     int origEffComponents=0,numEffComponents;
349 357

  
350 358
     if( origVertices>0 )
......
591 599
 */
592 600
   public void print()
593 601
     {
594
     StringBuffer sb = new StringBuffer();
602
     StringBuilder sb = new StringBuilder();
595 603

  
596 604
     for(int i=0; i<mNumVertices; i++)
597 605
       {
......
604 612
       sb.append(") ");
605 613
       }
606 614

  
607
     StringBuffer sb2 = new StringBuffer();
615
     StringBuilder sb2 = new StringBuilder();
608 616

  
609 617
     for(int i=0; i<mNumVertices; i++)
610 618
       {
......
884 892
 * The point: this way we can configure the system so that each Vertex Effect acts only on a certain
885 893
 * subset of a Mesh, thus potentially significantly reducing the number of render calls.
886 894
 */
887
  public void setEffectAssociation(int component, int andAssociation, int equAssociation)
888
    {
889
    if( component>=0 && component<MAX_EFFECT_COMPONENTS )
890
      {
891
      mAndAssociation[component] = andAssociation;
892
      mEquAssociation[component] = equAssociation;
893
      }
894
    }
895
   public void setEffectAssociation(int component, int andAssociation, int equAssociation)
896
     {
897
     if( component>=0 && component<MAX_EFFECT_COMPONENTS )
898
       {
899
       if( mJobNode[0]==null )
900
         {
901
         setEffectAssociationNow(component, andAssociation, equAssociation);
902
         }
903
       else
904
         {
905
         mJobNode[0] = DeferredJobs.effectAssoc(this,component,andAssociation,equAssociation);
906
         }
907
       }
908
     }
895 909

  
896 910
///////////////////////////////////////////////////////////////////////////////////////////////////
897 911
/**

Also available in: Unified diff