Project

General

Profile

« Previous | Next » 

Revision 02de77c9

Added by Leszek Koltunski over 7 years ago

Progress with multi-program rendering.

View differences:

src/main/java/org/distorted/library/program/DistortedProgram.java
23 23
import android.os.Build;
24 24

  
25 25
import org.distorted.library.DistortedEffects;
26
import org.distorted.library.EffectNames;
27
import org.distorted.library.EffectTypes;
28 26

  
29 27
import java.io.BufferedReader;
30 28
import java.io.IOException;
......
40 38
  private int mProgramHandle;
41 39

  
42 40
  private int mNumAttributes;
43
  private int[] mAttribute;
44 41
  private String[] mAttributeName;
45 42

  
43
  public final int[] mAttribute;
44

  
46 45
///////////////////////////////////////////////////////////////////////////////////////////////////
47 46

  
48 47
  private int createAndLinkProgram(final int vertexShaderHandle, final int fragmentShaderHandle, final String[] attributes)
......
168 167

  
169 168
    if( doAttributes )
170 169
      {
171
      mAttribute = new int[mNumAttributes];
172 170
      mAttributeName = attrList.split(" ");
173 171
      }
174 172

  
......
274 272
    final int fragmentShaderHandle = compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentHeader + fragmentShader);
275 273

  
276 274
    mProgramHandle = createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, mAttributeName);
277
    }
278 275

  
279
///////////////////////////////////////////////////////////////////////////////////////////////////
280
/**
281
 * Return the indexes off all attributes.
282
 */
283
  public int[] getAttributes()
284
    {
285
    return mAttribute;
286
    }
276
    mAttribute = new int[mNumAttributes];
287 277

  
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289
/**
290
 * Return the names of all vertex attributes.
291
 */
292
  public String[] getAttributeNames()
293
    {
294
    return mAttributeName;
278
    for(int i=0; i<mNumAttributes; i++)
279
      {
280
      mAttribute[i] = GLES20.glGetAttribLocation( mProgramHandle, mAttributeName[i]);
281
      }
295 282
    }
296 283

  
297 284
///////////////////////////////////////////////////////////////////////////////////////////////////
......
305 292

  
306 293
///////////////////////////////////////////////////////////////////////////////////////////////////
307 294
/**
308
 * Bind all vertex attributes and enable them.
309
 * <p>
310
 * This assumes Program is in use. Call glUseProgram first.
295
 * Use the program and enable all vertex attribute arrays.
296
 *
311 297
 * Needs to be called from a thread holding the OpenGL context.
312 298
 */
313

  
314
  public void bindAndEnableAttributes()
299
  public void useProgram()
315 300
    {
301
    GLES20.glUseProgram(mProgramHandle);
302

  
316 303
    for(int i=0; i<mNumAttributes; i++)
317
      {
318
      mAttribute[i] = GLES20.glGetAttribLocation( mProgramHandle, mAttributeName[i]);
319 304
      GLES20.glEnableVertexAttribArray(mAttribute[i]);
320
      }
321 305
    }
322 306
  }
307

  
308

  

Also available in: Unified diff