public StringBuilder toString(StringBuilder sb, boolean alsoUnlocated) { if (null == sb) { sb = new StringBuilder(); } sb.append("ShaderState[ "); sb.append(Platform.getNewline()).append(" "); if (null != shaderProgram) { shaderProgram.toString(sb); } else { sb.append("ShaderProgram: null"); } sb.append(Platform.getNewline()).append(" enabledAttributes ["); { Iterator<String> names = activedAttribEnabledMap.keySet().iterator(); Iterator<Boolean> values = activedAttribEnabledMap.values().iterator(); while (names.hasNext()) { sb.append(Platform.getNewline()) .append(" ") .append(names.next()) .append(": ") .append(values.next()); } } sb.append(Platform.getNewline()).append(" ],").append(" activeAttributes ["); for (Iterator<GLArrayData> iter = activeAttribDataMap.values().iterator(); iter.hasNext(); ) { final GLArrayData ad = iter.next(); if (alsoUnlocated || 0 <= ad.getLocation()) { sb.append(Platform.getNewline()).append(" ").append(ad); } } sb.append(Platform.getNewline()).append(" ],").append(" managedAttributes ["); for (Iterator<GLArrayData> iter = managedAttributes.iterator(); iter.hasNext(); ) { final GLArrayData ad = iter.next(); if (alsoUnlocated || 0 <= ad.getLocation()) { sb.append(Platform.getNewline()).append(" ").append(ad); } } sb.append(Platform.getNewline()).append(" ],").append(" activeUniforms ["); for (Iterator<GLUniformData> iter = activeUniformDataMap.values().iterator(); iter.hasNext(); ) { final GLUniformData ud = iter.next(); if (alsoUnlocated || 0 <= ud.getLocation()) { sb.append(Platform.getNewline()).append(" ").append(ud); } } sb.append(Platform.getNewline()).append(" ],").append(" managedUniforms ["); for (Iterator<GLUniformData> iter = managedUniforms.iterator(); iter.hasNext(); ) { final GLUniformData ud = iter.next(); if (alsoUnlocated || 0 <= ud.getLocation()) { sb.append(Platform.getNewline()).append(" ").append(ud); } } sb.append(Platform.getNewline()).append(" ]").append(Platform.getNewline()).append("]"); return sb; }
/** * Enables a vertex attribute array, usually invoked by {@link * GLArrayDataEditable#enableBuffer(GL, boolean)}. * * <p>This method uses the {@link GLArrayData}'s location if set and is the preferred alternative * to {@link #enableVertexAttribArray(GL2ES2, String)}. If data location is unset it will be * retrieved via {@link #getAttribLocation(GL2ES2, GLArrayData)} set and cached in this state. * * <p>Even if the attribute is not found in the current shader, it is marked enabled in this * state. * * @return false, if the name is not found, otherwise true * @throws GLException if the program is not linked and no location was cached. * @see #glEnableVertexAttribArray * @see #glDisableVertexAttribArray * @see #glVertexAttribPointer * @see #getVertexAttribPointer * @see GLArrayDataEditable#enableBuffer(GL, boolean) */ public boolean enableVertexAttribArray(GL2ES2 gl, GLArrayData data) { if (0 > data.getLocation()) { getAttribLocation(gl, data); } else { // ensure data is the current bound one activeAttribDataMap.put(data.getName(), data); } return enableVertexAttribArray(gl, data.getName(), data.getLocation()); }
/** * Set the {@link GLArrayData} vertex attribute data. * * <p>This method uses the {@link GLArrayData}'s location if set. If data location is unset it * will be retrieved via {@link #getAttribLocation(GL2ES2, GLArrayData)}, set and cached in this * state. * * @return false, if the location could not be determined, otherwise true * @throws GLException if no program is attached * @throws GLException if the program is not linked and no location was cached. * @see #glEnableVertexAttribArray * @see #glDisableVertexAttribArray * @see #glVertexAttribPointer * @see #getVertexAttribPointer */ public boolean vertexAttribPointer(GL2ES2 gl, GLArrayData data) { int location = data.getLocation(); if (0 > location) { location = getAttribLocation(gl, data); } if (0 <= location) { // only pass the data, if the attribute exists in the current shader if (DEBUG) { System.err.println("ShaderState: glVertexAttribPointer: " + data); } gl.glVertexAttribPointer(data); return true; } return false; }
private final void setAttribute(GL2ES2 gl, GLArrayData attribute) { // get new location .. final String name = attribute.getName(); final int loc = attribute.getLocation(); if (0 <= loc) { bindAttribLocation(gl, loc, name); if (isVertexAttribArrayEnabled(name)) { // enable attrib, VBO and pass location/data gl.glEnableVertexAttribArray(loc); } if (attribute.isVBO()) { gl.glBindBuffer(GL.GL_ARRAY_BUFFER, attribute.getVBOName()); gl.glVertexAttribPointer(attribute); gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); } else { gl.glVertexAttribPointer(attribute); } } }
/** * Disables a vertex attribute array * * <p>This method uses the {@link GLArrayData}'s location if set and is the preferred alternative * to {@link #disableVertexAttribArray(GL2ES2, String)}. If data location is unset it will be * retrieved via {@link #getAttribLocation(GL2ES2, GLArrayData)} set and cached in this state. * * <p>Even if the attribute is not found in the current shader, it is removed from this state * enabled list. * * @return false, if the name is not found, otherwise true * @throws GLException if no program is attached * @throws GLException if the program is not linked and no location was cached. * @see #glEnableVertexAttribArray * @see #glDisableVertexAttribArray * @see #glVertexAttribPointer * @see #getVertexAttribPointer */ public boolean disableVertexAttribArray(GL2ES2 gl, GLArrayData data) { if (0 > data.getLocation()) { getAttribLocation(gl, data); } return disableVertexAttribArray(gl, data.getName(), data.getLocation()); }