List of usage examples for org.lwjgl.opengl GL20 nglShaderSource
public static void nglShaderSource(int shader, int count, long strings, long length)
From source file:com.samrj.devil.gl.Shader.java
/** * Loads shader sources from the given input stream and then compiles this * shader. Buffers the source in native memory. * //from w ww . j a v a 2s . c o m * @param in The input stream to load sources from. * @return This shader. * @throws IOException If an I/O error occurs. */ public Shader source(InputStream in) throws IOException { if (state != State.NEW) throw new IllegalStateException("Shader must be new."); //Source to memory int sourceLength = in.available(); Memory sourceBlock = new Memory(sourceLength); ByteBuffer sourceBuffer = sourceBlock.buffer; for (int i = 0; i < sourceLength; i++) sourceBuffer.put((byte) in.read()); //Pointer to pointer to memory long pointer = MemStack.wrapl(sourceBlock.address); //Pointer to length of memory long length = MemStack.wrapi(sourceLength); //Load shader source GL20.nglShaderSource(id, 1, pointer, length); //Free allocated memory MemStack.pop(2); sourceBlock.free(); //Compile GL20.glCompileShader(id); //Check for errors if (GL20.glGetShaderi(id, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) { int logLength = GL20.glGetShaderi(id, GL20.GL_INFO_LOG_LENGTH); String log = GL20.glGetShaderInfoLog(id, logLength); throw new ShaderException(path != null ? path + " " + log : log); } state = State.COMPILED; return this; }