Project

General

Profile

« Previous | Next » 

Revision 7e53a35f

Added by Leszek Koltunski over 4 years ago

Bugfixes in MeshBase:

1) improper buffer was being invalidated after apply and setTextureMap (TFO rather than VBO!)
2) setTextureMap would only work if all components were being set

View differences:

src/main/java/org/distorted/library/main/InternalBuffer.java
36 36
 */
37 37
public class InternalBuffer extends InternalObject
38 38
  {
39
  public final int[] mIndex;
40

  
39
  private final int[] mIndex;
41 40
  private int mTarget, mSize, mUsage;
42 41
  private Buffer mBuffer;
43 42

  
......
56 55
    recreate();
57 56
    }
58 57

  
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

  
60
  public int getIndex()
61
    {
62
    return mIndex[0];
63
    }
64

  
59 65
///////////////////////////////////////////////////////////////////////////////////////////////////
60 66
// must be called from a thread holding OpenGL Context.
61 67

  
62
  public void createImmediately(int size, float[] buffer)
68
  public int createImmediately(int size, float[] buffer)
63 69
    {
64 70
    if( mIndex[0]<0 )
65 71
      {
......
83 89

  
84 90
      markWasCreatedImmediately();
85 91
      }
92

  
93
    return mIndex[0];
86 94
    }
87 95

  
88 96
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/mesh/MeshBase.java
69 69
   private float mBoundingX, mBoundingY, mBoundingZ;
70 70
   private float mStretchX, mStretchY, mStretchZ;
71 71

  
72
   private class Component
72
   private static class Component
73 73
     {
74 74
     private int mEndIndex;
75 75
     private Static4D mTextureMap;
......
284 284
 */
285 285
   public int getTFO()
286 286
     {
287
     return mTFO.mIndex[0];
287
     return mTFO.getIndex();
288 288
     }
289 289

  
290 290
///////////////////////////////////////////////////////////////////////////////////////////////////
......
306 306
 */
307 307
   public void bindVertexAttribs(DistortedProgram program)
308 308
     {
309
     mVBO.createImmediately(mNumVertices*VERT_SIZE, mVertAttribs);
309
     int index = mVBO.createImmediately(mNumVertices*VERT_SIZE, mVertAttribs);
310 310

  
311
     GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mVBO.mIndex[0] );
311
     GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, index );
312 312
     GLES31.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES31.GL_FLOAT, false, VERT_SIZE, OFFSET_POS);
313 313
     GLES31.glVertexAttribPointer(program.mAttribute[1], NOR_DATA_SIZE, GLES31.GL_FLOAT, false, VERT_SIZE, OFFSET_NOR);
314 314
     GLES31.glVertexAttribPointer(program.mAttribute[2], INF_DATA_SIZE, GLES31.GL_FLOAT, false, VERT_SIZE, OFFSET_INF);
......
324 324
 */
325 325
   public void bindTransformAttribs(DistortedProgram program)
326 326
     {
327
     mTFO.createImmediately(mNumVertices*TRAN_SIZE, null);
327
     int index = mTFO.createImmediately(mNumVertices*TRAN_SIZE, null);
328 328

  
329
     GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mTFO.mIndex[0] );
329
     GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, index );
330 330
     GLES31.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES31.GL_FLOAT, false, 0, 0);
331 331
     GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
332 332
     }
......
453 453
         }
454 454
       }
455 455

  
456
     mTFO.invalidate();
456
     mVBO.invalidate();
457 457
     }
458 458

  
459 459
///////////////////////////////////////////////////////////////////////////////////////////////////
......
482 482
     int num_maps = maps.length;
483 483
     int min = Math.min(num_comp, num_maps);
484 484
     int vertex = 0;
485
     int index  = TEX_ATTRIB;
486 485
     Static4D newMap, oldMap;
487 486
     Component comp;
488 487
     float newW, newH, ratW, ratH, movX, movY;
......
490 489
     for(int i=0; i<min; i++)
491 490
       {
492 491
       newMap = maps[i];
492
       comp = mComponent.get(i);
493 493

  
494 494
       if( newMap!=null )
495 495
         {
......
498 498

  
499 499
         if( newW!=0.0f && newH!=0.0f )
500 500
           {
501
           comp = mComponent.get(i);
502 501
           oldMap = comp.mTextureMap;
503 502
           ratW = newW/oldMap.get2();
504 503
           ratH = newH/oldMap.get3();
505 504
           movX = newMap.get0() - ratW*oldMap.get0();
506 505
           movY = newMap.get1() - ratH*oldMap.get1();
507 506

  
508
           for( ; vertex<=comp.mEndIndex; vertex++, index+=VERT_ATTRIBS)
507
           for( int index=vertex*VERT_ATTRIBS+TEX_ATTRIB ; vertex<=comp.mEndIndex; vertex++, index+=VERT_ATTRIBS)
509 508
             {
510 509
             mVertAttribs[index  ] = ratW*mVertAttribs[index  ] + movX;
511 510
             mVertAttribs[index+1] = ratH*mVertAttribs[index+1] + movY;
......
513 512
           comp.setMap(newMap);
514 513
           }
515 514
         }
515

  
516
       vertex= comp.mEndIndex+1;
516 517
       }
517 518

  
518
     mTFO.invalidate();
519
     mVBO.invalidate();
519 520
     }
520 521

  
521 522
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff