Project

General

Profile

« Previous | Next » 

Revision 07206c71

Added by Leszek Koltunski almost 4 years ago

First attempt at Deferred Mesh Jobs.
Only apply(VertexEffect) supported for now.

View differences:

src/main/java/org/distorted/library/mesh/MeshBase.java
24 24

  
25 25
import org.distorted.library.effect.VertexEffect;
26 26
import org.distorted.library.effectqueue.EffectQueue;
27
import org.distorted.library.effectqueue.EffectQueueVertex;
28
import org.distorted.library.main.DistortedLibrary;
29 27
import org.distorted.library.main.InternalBuffer;
30 28
import org.distorted.library.program.DistortedProgram;
31 29
import org.distorted.library.type.Static4D;
32 30

  
33
import java.io.InputStream;
34
import java.io.OutputStream;
35 31
import java.nio.ByteBuffer;
36 32
import java.nio.ByteOrder;
37 33
import java.nio.FloatBuffer;
......
47 43
public abstract class MeshBase
48 44
   {
49 45
   private static final int MAX_COMPONENTS= 100;
50
   static final int DEFAULT_ASSOCIATION = 0xffffffff;
46
   private static final int DEFAULT_ASSOCIATION = 0xffffffff;
51 47

  
52 48
   // sizes of attributes of an individual vertex.
53 49
   private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z
......
84 80
   private float[] mVertAttribs1;             // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ
85 81
   private float[] mVertAttribs2;             // packed: TexS,TexT, Component
86 82
   private float mInflate;
87
   private boolean[] mNeedsAdjustment;
88 83
   private int[] mAssociation;
89 84

  
85
   DeferredJobs.JobNode mJobNode;
86

  
90 87
   private static int[] mComponentAssociationH = new int[EffectQueue.MAIN_VARIANTS];
91
   private EffectQueueVertex mQueue;
92 88

  
93 89
   private static class Component
94 90
     {
......
130 126

  
131 127
     for(int i=0; i<MAX_COMPONENTS; i++) mAssociation[i] = DEFAULT_ASSOCIATION;
132 128

  
133
     mNeedsAdjustment = new boolean[1];
134
     mQueue = new EffectQueueVertex();
135

  
136 129
     mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
137 130
     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
138 131
     mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
......
149 142

  
150 143
     int size = original.mComponent.size();
151 144
     mComponent = new ArrayList<>();
152
     mQueue = new EffectQueueVertex(original.mQueue);
153 145

  
154 146
     for(int i=0; i<size; i++)
155 147
       {
......
162 154

  
163 155
     if( deep )
164 156
       {
165
       mNeedsAdjustment = new boolean[1];
166
       mNeedsAdjustment[0] = original.mNeedsAdjustment[0];
157
       if( original.mJobNode!=null )
158
         {
159
         mJobNode = new DeferredJobs.JobNode(original.mJobNode);
160
         }
167 161

  
168 162
       mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
169 163
       mVertAttribs1= new float[mNumVertices*VERT1_ATTRIBS];
......
172 166
       }
173 167
     else
174 168
       {
175
       mNeedsAdjustment = original.mNeedsAdjustment;
169
       mJobNode         = original.mJobNode;
176 170
       mVBO1            = original.mVBO1;
177 171
       mVertAttribs1    = original.mVertAttribs1;
178 172
       }
......
362 356
       }
363 357

  
364 358
     GLES30.glUnmapBuffer(GLES30.GL_TRANSFORM_FEEDBACK);
365

  
366
     mQueue.removeAll(false);
367
     }
368

  
369
///////////////////////////////////////////////////////////////////////////////////////////////////
370
/**
371
 * Not part of public API, do not document (public only because has to be used from the main package)
372
 *
373
 * @y.exclude
374
 */
375
   public void computeQueue()
376
     {
377
     mQueue.compute(1);
378
     }
379

  
380
///////////////////////////////////////////////////////////////////////////////////////////////////
381
/**
382
 * Not part of public API, do not document (public only because has to be used from the main package)
383
 *
384
 * @y.exclude
385
 */
386
   public void sendQueue()
387
     {
388
     mQueue.send(0.0f,3);
389 359
     }
390 360

  
391 361
///////////////////////////////////////////////////////////////////////////////////////////////////
......
429 399
 */
430 400
   public void bindVertexAttribs(DistortedProgram program)
431 401
     {
432
     if( mNeedsAdjustment[0] )
402
     if( mJobNode!=null )
433 403
       {
434
       mNeedsAdjustment[0] = false;
435
       DistortedLibrary.adjustVertices(this);
404
       mJobNode.execute();  // this will set itself to null
436 405
       }
437 406

  
438 407
     int index1 = mVBO1.createImmediately(mNumVertices*VERT1_SIZE, mVertAttribs1);
......
485 454
     return mInflate;
486 455
     }
487 456

  
488
///////////////////////////////////////////////////////////////////////////////////////////////////
489
/**
490
 * Read this mesh from a InputStream.
491
 */
492
  void read(final InputStream stream)
493
    {
494

  
495
    }
496

  
497 457
///////////////////////////////////////////////////////////////////////////////////////////////////
498 458
// PUBLIC API
499 459
///////////////////////////////////////////////////////////////////////////////////////////////////
500
/**
501
 * Save the Mesh to a OutputStream.
502
 */
503
  public void save(final OutputStream stream)
504
    {
505

  
506
    }
507

  
508
///////////////////////////////////////////////////////////////////////////////////////////////////
509

  
510 460
/**
511 461
 * When rendering this Mesh, do we want to render the Normal vectors as well?
512 462
 * <p>
......
558 508
 */
559 509
   public void apply(VertexEffect effect)
560 510
     {
561
     mQueue.add(effect);
562
     mNeedsAdjustment[0] = true;
511
     mJobNode = DeferredJobs.vertex(this,effect);
563 512
     }
564 513

  
565 514
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff