Example usage for org.lwjgl.opengl GL20 nglGetAttribLocation

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

Introduction

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

Prototype

public static int nglGetAttribLocation(int program, long name) 

Source Link

Document

Unsafe version of: #glGetAttribLocation GetAttribLocation

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.
 * /*  w w  w . java 2 s.  c o  m*/
 * @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;
}