List of usage examples for org.lwjgl.opengl GL20 glGetProgramInfoLog
@NativeType("void") public static String glGetProgramInfoLog(@NativeType("GLuint") int program, @NativeType("GLsizei") int maxLength)
From source file:com.flowpowered.caustic.lwjgl.gl20.GL20Program.java
License:MIT License
@Override public void link() { checkCreated();/* www. jav a 2s.com*/ // Add the attribute layouts to the program state final TObjectIntIterator<String> iterator = attributeLayouts.iterator(); while (iterator.hasNext()) { iterator.advance(); // Bind the index to the name GL20.glBindAttribLocation(id, iterator.value(), iterator.key()); } // Link program GL20.glLinkProgram(id); // Check program link status if (GL20.glGetProgrami(id, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) { throw new IllegalStateException("Program could not be linked\n" + GL20.glGetProgramInfoLog(id, 1000)); } if (CausticUtil.isDebugEnabled()) { // Validate program GL20.glValidateProgram(id); // Check program validation status if (GL20.glGetProgrami(id, GL20.GL_VALIDATE_STATUS) == GL11.GL_FALSE) { final Logger logger = CausticUtil.getCausticLogger(); logger.log(Level.WARNING, "Program validation failed. This doesn''t mean it won''t work, so you maybe able to ignore it\n{0}", GL20.glGetProgramInfoLog(id, 1000)); } } // Load uniforms uniforms.clear(); final int uniformCount = GL20.glGetProgrami(id, GL20.GL_ACTIVE_UNIFORMS); final int maxLength = GL20.glGetProgrami(id, GL20.GL_ACTIVE_UNIFORM_MAX_LENGTH); final IntBuffer lengthBuffer = CausticUtil.createIntBuffer(1); final IntBuffer ignored1 = CausticUtil.createIntBuffer(1); final IntBuffer ignored2 = CausticUtil.createIntBuffer(1); final ByteBuffer nameBuffer = CausticUtil.createByteBuffer(maxLength); final byte[] nameBytes = new byte[maxLength]; for (int i = 0; i < uniformCount; i++) { lengthBuffer.clear(); ignored1.clear(); ignored2.clear(); nameBuffer.clear(); GL20.glGetActiveUniform(id, i, lengthBuffer, ignored1, ignored2, nameBuffer); final int length = lengthBuffer.get(); nameBuffer.get(nameBytes, 0, length); // Simplify array names final String name = new String(nameBytes, 0, length).replaceFirst("\\[\\d+\\]", ""); uniforms.put(name, GL20.glGetUniformLocation(id, name)); uniformValues.put(name, UNSET); } // Check for errors LWJGLUtil.checkForGLError(); }
From source file:com.github.ryancwilliams.WJ3dPL.graphics.GLUtils.ShaderProgram.java
License:Apache License
/** * Creates a new shader program with the provided vertex and fragment * shader source code.// w w w . jav a 2 s . co m * The provided attributes are linked to this program. * @param vertexShaderSource the source code of the vertex shader. * @param fragmentShaderSource the source code of the fragment shader. * @param attributes The Vertex Attributes to bind to this shader program. * @throws LWJGLException If their is a issue compiling the shaders or * creating or binding the program. */ public ShaderProgram(String vertexShaderSource, String fragmentShaderSource, List<VertexAttribute> attributes) throws LWJGLException { //Check if any of the sourcecode paramaters are null if (fragmentShaderSource == null || fragmentShaderSource == null) { //If any of the sourcecode paramaters were null //throw a exception throw new IllegalArgumentException("Shader source may not be null"); } //Check if shaders are not supported if (!ShaderProgram.isSupported()) { //If shaders are not supported //throw a exception throw new LWJGLException("Shaders are not supported on this device"); } //Compile the shaders int vertexShader = ShaderProgram.compileShader(GL20.GL_VERTEX_SHADER, vertexShaderSource); int fragmentShader = ShaderProgram.compileShader(GL20.GL_FRAGMENT_SHADER, fragmentShaderSource); //Create the program this.program = GL20.glCreateProgram(); //Bind the attrib locations //Check if attributes were provided if (attributes != null) { //For each attribute for (VertexAttribute attribute : attributes) { //Check if the attribute is not null if (attribute != null) { //bind the attribute GL20.glBindAttribLocation(this.program, attribute.index, attribute.name); } } } //Attach the shaders GL20.glAttachShader(this.program, vertexShader); GL20.glAttachShader(this.program, fragmentShader); //Link the program GL20.glLinkProgram(this.program); //Get if the program link was good boolean programLink = GL20.glGetProgrami(this.program, GL20.GL_LINK_STATUS) == GL11.GL_TRUE; //Get the log String infoLog = GL20.glGetProgramInfoLog(this.program, GL20.glGetProgrami(this.program, GL20.GL_INFO_LOG_LENGTH)); //Log the log if a log is present if (infoLog != null && infoLog.trim().length() != 0) { Logger.getLogger(ShaderProgram.class.getName()).log(Level.FINEST, infoLog); } //Check if program link is bad if (programLink == false) { throw new LWJGLException("Failure in linking program. Error log:\n" + infoLog); } //detach and delete the shaders which are no longer needed GL20.glDetachShader(this.program, vertexShader); GL20.glDetachShader(this.program, fragmentShader); GL20.glDeleteShader(vertexShader); GL20.glDeleteShader(fragmentShader); }
From source file:com.kauridev.lunarfever.graphics.ShaderProgram.java
License:Open Source License
private void linkProgram(List<VertexAttribute> attribLocations) { if (!isValid()) { throw new RuntimeException(); }/* w w w. jav a2 s . com*/ if (attribLocations != null) { for (VertexAttribute a : attribLocations) { if (a != null) { GL20.glBindAttribLocation(program, a.location, a.name); } } } attachShaders(); GL20.glLinkProgram(program); int comp = GL20.glGetProgrami(program, GL20.GL_LINK_STATUS); int len = GL20.glGetProgrami(program, GL20.GL_INFO_LOG_LENGTH); if (comp == GL11.GL_FALSE) { throw new RuntimeException(GL20.glGetProgramInfoLog(program, len)); } }
From source file:com.opengrave.og.resources.ShaderProgram.java
License:Open Source License
public void compile() { Util.checkErr();/*w w w .j a v a 2s. c om*/ PID = GL20.glCreateProgram(); Util.checkErr(); vert = loadShader(sfv.getSource(), GL20.GL_VERTEX_SHADER); Util.checkErr(); frag = loadShader(sff.getSource(), GL20.GL_FRAGMENT_SHADER); Util.checkErr(); GL20.glAttachShader(PID, vert); Util.checkErr(); GL20.glAttachShader(PID, frag); Util.checkErr(); GL20.glLinkProgram(PID); Util.checkErr(); System.out.println(GL20.glGetProgramInfoLog(PID, 2000)); Util.checkErr(); GL20.glValidateProgram(PID); Util.checkErr(); // System.out.println("Compiled " + label + " as number " + PID); if (GL20.glGetProgrami(PID, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) { new DebugExceptionHandler(new Exception(), label, GL20.glGetShaderInfoLog(PID, 2000), GL20.glGetProgramInfoLog(PID, 2000)); // System.out.println("Failed to link " + label); // System.out.println(sfv.getSource()); // System.out.println(sff.getSource()); // Util.checkErr(); // printShaderLogs(); } Util.checkErr(); GL20.glDetachShader(PID, vert); Util.checkErr(); GL20.glDetachShader(PID, frag); GL20.glDeleteShader(vert); Util.checkErr(); GL20.glDeleteShader(frag); Util.checkErr(); }
From source file:com.runescape.client.revised.client.lwjgl.Shader.java
License:Open Source License
@SuppressWarnings("deprecation") public void compileShader() { GL20.glLinkProgram(this.getProgram()); if (GL20.glGetProgram(this.getProgram(), GL20.GL_LINK_STATUS) == 0) { System.out.println(GL20.glGetProgramInfoLog(this.getProgram(), 1024)); System.exit(0);//w w w .j a v a2 s. c o m } GL20.glValidateProgram(this.getProgram()); if (GL20.glGetProgram(this.getProgram(), GL20.GL_VALIDATE_STATUS) == 0) { System.out.println(GL20.glGetProgramInfoLog(this.getProgram(), 1024)); System.exit(0); } }
From source file:com.samrj.devil.gl.ShaderProgram.java
License:Open Source License
private void checkStatus(int type) { if (GL20.glGetProgrami(id, type) != GL11.GL_TRUE) { int logLength = GL20.glGetProgrami(id, GL20.GL_INFO_LOG_LENGTH); String log = GL20.glGetProgramInfoLog(id, logLength); throw new ShaderException(log); }/* w w w.j ava2 s .co m*/ }
From source file:com.xrbpowered.gl.res.shaders.Shader.java
License:Open Source License
public Shader(VertexInfo info, String pathVS, String pathFS) { // System.out.println("Compile: "+pathVS+", "+pathFS); this.info = info; int vsId = loadShader(pathVS, GL20.GL_VERTEX_SHADER); int fsId = loadShader(pathFS, GL20.GL_FRAGMENT_SHADER); pId = GL20.glCreateProgram();//from w w w .ja va 2s. c o m if (vsId > 0) GL20.glAttachShader(pId, vsId); if (fsId > 0) GL20.glAttachShader(pId, fsId); bindAttribLocations(); // System.out.println("Link: "+pathVS+", "+pathFS); GL20.glLinkProgram(pId); if (GL20.glGetProgrami(pId, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) { System.err.println("Could not link program " + pathVS + ", " + pathFS); System.err.println(GL20.glGetProgramInfoLog(pId, 8000)); System.exit(-1); } GL20.glValidateProgram(pId); storeUniformLocations(); Client.checkError(); // System.out.println("Done: "+pathVS+", "+pathFS+"\n"); }
From source file:cuchaz.jfxgl.prism.JFXGLContext.java
License:Open Source License
@Override public int createProgram(int vertexShaderId, int[] fragmentShaderIds, String[] attrs, int[] indices) { // build the shader program int id = GL20.glCreateProgram(); GL20.glAttachShader(id, vertexShaderId); for (int fragmentShaderId : fragmentShaderIds) { GL20.glAttachShader(id, fragmentShaderId); }//from w ww .j a v a 2 s. c om assert (attrs.length == indices.length); for (int i = 0; i < attrs.length; i++) { GL20.glBindAttribLocation(id, indices[i], attrs[i]); } GL20.glLinkProgram(id); boolean isSuccess = GL20.glGetProgrami(id, GL20.GL_LINK_STATUS) == GL11.GL_TRUE; if (!isSuccess) { throw new RuntimeException("Shader program did not link:\n" + GL20.glGetProgramInfoLog(id, 4096)); } GL20.glValidateProgram(id); isSuccess = GL20.glGetProgrami(id, GL20.GL_VALIDATE_STATUS) == GL11.GL_TRUE; if (!isSuccess) { throw new RuntimeException("Shader program did not validate:\n" + GL20.glGetProgramInfoLog(id, 4096)); } return id; }
From source file:de.ikosa.mars.viewer.glviewer.engine.GLHardcodedShader.java
License:Open Source License
private static void validateLinkage(int programId) { int linkStatus = GL20.glGetProgrami(programId, GL20.GL_LINK_STATUS); int error = GL11.glGetError(); if (error != GL11.GL_NO_ERROR) { ML.f(String.format("Error getting link status: 0x%x", error)); } else if (linkStatus == GL11.GL_FALSE) { int logLength = GL20.glGetProgrami(programId, GL20.GL_INFO_LOG_LENGTH); String log = GL20.glGetProgramInfoLog(programId, logLength); ML.f(String.format("Error linking program: %s", log)); }/*from w w w . j a v a 2s. co m*/ }
From source file:de.ikosa.mars.viewer.glviewer.engine.GLShaderBuilder.java
License:Open Source License
private void validateLinkage(int programId) { int linkStatus = GL20.glGetProgrami(programId, GL20.GL_LINK_STATUS); int error = GL11.glGetError(); if (error != GL11.GL_NO_ERROR) { ML.f(String.format("Error getting link status: 0x%x", error)); } else if (linkStatus == GL11.GL_FALSE) { int logLength = GL20.glGetProgrami(programId, GL20.GL_INFO_LOG_LENGTH); String log = GL20.glGetProgramInfoLog(programId, logLength); ML.f(String.format("Error linking program: %s", log)); }// ww w .j ava 2 s .c om }