Project

General

Profile

« Previous | Next » 

Revision 0bd9f644

Added by Leszek Koltunski over 3 years ago

Introduce an UBO to the vertex shader holding info about mesh effect associations.

View differences:

src/main/java/org/distorted/library/main/InternalBuffer.java
20 20
package org.distorted.library.main;
21 21

  
22 22
import android.opengl.GLES30;
23

  
24
import java.nio.Buffer;
23 25
import java.nio.ByteBuffer;
24 26
import java.nio.ByteOrder;
25 27
import java.nio.FloatBuffer;
28
import java.nio.IntBuffer;
26 29

  
27 30
///////////////////////////////////////////////////////////////////////////////////////////////////
28 31
/**
......
37 40
  {
38 41
  private final int[] mIndex;
39 42
  private int mTarget, mSize, mUsage;
40
  private FloatBuffer mBuffer;
43
  private Buffer mBuffer;
41 44

  
42 45
///////////////////////////////////////////////////////////////////////////////////////////////////
43 46

  
......
57 60
///////////////////////////////////////////////////////////////////////////////////////////////////
58 61
// must be called from a thread holding OpenGL Context.
59 62

  
60
  public int createImmediately(int size, float[] buffer)
63
  public int createImmediatelyFloat(int size, float[] buffer)
61 64
    {
62 65
    if( mIndex[0]<0 )
63 66
      {
......
85 88
    return mIndex[0];
86 89
    }
87 90

  
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92
// must be called from a thread holding OpenGL Context.
93

  
94
  public int createImmediatelyInt(int size, int[] buffer)
95
    {
96
    if( mIndex[0]<0 )
97
      {
98
      mSize= size;
99

  
100
      if( buffer!=null )
101
        {
102
        IntBuffer buf = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()).asIntBuffer();
103
        buf.put(buffer).position(0);
104
        mBuffer = buf;
105
        }
106
      else
107
        {
108
        mBuffer = null;
109
        }
110

  
111
      GLES30.glGenBuffers( 1, mIndex, 0);
112
      GLES30.glBindBuffer( mTarget,  mIndex[0]);
113
      GLES30.glBufferData( mTarget, mSize, mBuffer, mUsage);
114
      GLES30.glBindBuffer( mTarget,  0);
115

  
116
      markWasCreatedImmediately();
117
      }
118

  
119
    return mIndex[0];
120
    }
121

  
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123
// buffer non-null!!
124

  
125
  public void updateFloat(float[] buffer)
126
    {
127
    ((FloatBuffer)mBuffer).put(buffer).position(0);
128

  
129
    GLES30.glBindBuffer( mTarget, mIndex[0]);
130
    GLES30.glBufferData( mTarget, mSize, mBuffer, mUsage);
131
    GLES30.glBindBuffer( mTarget, 0);
132
    }
133

  
88 134
///////////////////////////////////////////////////////////////////////////////////////////////////
89 135
// buffer non-null!!
90 136

  
91
  public void update(float[] buffer)
137
  public void updateInt(int[] buffer)
92 138
    {
93
    mBuffer.put(buffer).position(0);
139
    ((IntBuffer)mBuffer).put(buffer).position(0);
94 140

  
95 141
    GLES30.glBindBuffer( mTarget, mIndex[0]);
96 142
    GLES30.glBufferData( mTarget, mSize, mBuffer, mUsage);

Also available in: Unified diff