Project

General

Profile

« Previous | Next » 

Revision 22e60fba

Added by Leszek Koltunski about 4 years ago

Fix MeshBase.join()
Only upload Mesh Buffers to GPU when we actually use them.

View differences:

src/main/java/org/distorted/library/main/InternalBuffer.java
21 21

  
22 22
import android.opengl.GLES31;
23 23
import java.nio.Buffer;
24
import java.nio.ByteBuffer;
25
import java.nio.ByteOrder;
26
import java.nio.FloatBuffer;
24 27

  
25 28
///////////////////////////////////////////////////////////////////////////////////////////////////
26 29
/**
......
33 36
 */
34 37
public class InternalBuffer extends InternalObject
35 38
  {
36
  public int[] mIndex;
39
  public final int[] mIndex;
37 40

  
38 41
  private int mTarget, mSize, mUsage;
39 42
  private Buffer mBuffer;
......
54 57
    }
55 58

  
56 59
///////////////////////////////////////////////////////////////////////////////////////////////////
57
// mark for creation only now, when we do have all data ready, in order to avoid the situation
58
// when create() would be called before this.
60
// must be called from a thread holding OpenGL Context.
59 61

  
60
  public void setData(int size, Buffer buffer)
62
  public void createImmediately(int size, float[] buffer)
61 63
    {
62
    mSize   = size;
63
    mBuffer = buffer;
64
    if( mIndex[0]<0 )
65
      {
66
      mSize= size;
67

  
68
      if( buffer!=null )
69
        {
70
        FloatBuffer buf = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()).asFloatBuffer();
71
        buf.put(buffer).position(0);
72
        mBuffer = buf;
73
        }
74
      else
75
        {
76
        mBuffer = null;
77
        }
78

  
79
      GLES31.glGenBuffers( 1, mIndex, 0);
80
      GLES31.glBindBuffer( mTarget, mIndex[0]);
81
      GLES31.glBufferData( mTarget, mSize, mBuffer, mUsage);
82
      GLES31.glBindBuffer( mTarget, 0);
64 83

  
65
    markForCreation();
84
      markWasCreatedImmediately();
85
      }
86
    }
87

  
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

  
90
  public void invalidate()
91
    {
92
    recreate();
66 93
    }
67 94

  
68 95
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff