Example usage for org.lwjgl.opengl GL20 nglGetActiveAttrib

List of usage examples for org.lwjgl.opengl GL20 nglGetActiveAttrib

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL20 nglGetActiveAttrib.

Prototype

public static void nglGetActiveAttrib(int program, int index, int maxLength, long length, long size, long type,
        long name) 

Source Link

Document

Unsafe version of: #glGetActiveAttrib GetActiveAttrib

Usage

From source file:com.samrj.devil.gl.ShaderProgram.java

License:Open Source License

/**
 * Links this shader program, creating executables that may run on the GPU
 * and compiling a list of input attributes.
 * //from   ww  w  .ja v  a 2  s  .com
 * @return This shader program.
 */
public ShaderProgram link() {
    if (state != State.NEW)
        throw new IllegalStateException("Shader program must be new to link.");

    GL20.glLinkProgram(id);
    checkStatus(GL20.GL_LINK_STATUS);

    int numAttributes = GL20.glGetProgrami(id, GL20.GL_ACTIVE_ATTRIBUTES);
    ArrayList<Attribute> attList = new ArrayList<>(numAttributes);
    attMap = new HashMap<>(numAttributes);

    int attBytes = 4 + 4 + 4 + 32;
    long address = MemStack.push(attBytes);
    ByteBuffer buffer = MemoryUtil.memByteBuffer(address, attBytes);
    for (int index = 0; index < numAttributes; index++) {
        long nameAddress = address + 12;
        GL20.nglGetActiveAttrib(id, index, 31, address, address + 4, address + 8, nameAddress);

        buffer.rewind();
        buffer.getInt();
        int size = buffer.getInt();
        int type = buffer.getInt();
        String name = MemoryUtil.memASCII(nameAddress);
        int location = GL20.nglGetAttribLocation(id, nameAddress);

        Attribute att = new Attribute(name, type, size, location);
        attList.add(att);
        attMap.put(name, att);
    }
    MemStack.pop();
    attributes = Collections.unmodifiableList(attList);

    state = State.LINKED;
    return this;
}