Example usage for org.lwjgl.opengl GL20 glGetProgramInfoLog

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

Introduction

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

Prototype

@NativeType("void")
public static String glGetProgramInfoLog(@NativeType("GLuint") int program,
        @NativeType("GLsizei") int maxLength) 

Source Link

Document

Returns the information log for a program object.

Usage

From source file:eu.over9000.veya.rendering.Program.java

License:Open Source License

private static void checkValidation(final int programID) {
    final int error = GL20.glGetProgrami(programID, GL20.GL_VALIDATE_STATUS);
    if (error == GL11.GL_FALSE) {
        throw new OpenGLException(
                GL20.glGetProgramInfoLog(programID, GL20.glGetProgrami(programID, GL20.GL_INFO_LOG_LENGTH)));
    } else {/*w w w . j  av a  2  s .  co  m*/
        System.out.println("Shader Validation OK");
    }
}

From source file:eu.over9000.veya.rendering.Program.java

License:Open Source License

private static void checkLinkage(final int programID) {
    final int error = GL20.glGetProgrami(programID, GL20.GL_LINK_STATUS);
    if (error == GL11.GL_FALSE) {
        throw new OpenGLException(
                GL20.glGetProgramInfoLog(programID, GL20.glGetProgrami(programID, GL20.GL_INFO_LOG_LENGTH)));
    } else {//from  w ww  .j a v a 2 s  .  c  o m
        System.out.println("Shader Linkage OK");
    }
}

From source file:io.root.gfx.glutils.GL.java

License:Apache License

public static String glGetProgramInfoLog(int program, int maxLength) {
    return GL20.glGetProgramInfoLog(program, maxLength);
}

From source file:jpcsp.graphics.RE.RenderingEngineLwjgl.java

License:Open Source License

@Override
public String getProgramInfoLog(int program) {
    int infoLogLength = GL20.glGetProgram(program, GL20.GL_INFO_LOG_LENGTH);

    if (infoLogLength <= 1) {
        return null;
    }//from   w ww .  jav a 2 s .co  m

    String infoLog = GL20.glGetProgramInfoLog(program, infoLogLength);

    // Remove ending '\0' byte(s)
    while (infoLog.length() > 0 && infoLog.charAt(infoLog.length() - 1) == '\0') {
        infoLog = infoLog.substring(0, infoLog.length() - 1);
    }

    return infoLog;
}

From source file:lessur.util.shader.ShaderManager.java

License:GNU General Public License

/**
 * Gets the program info log/*from  ww  w.j  a v a  2s . c  om*/
 * @param shaderID
 * @return The program info log or an empty string if it cannot be found
 */
private String getProgramInfoLog(int programID) {
    if (has_opengl2) {
        return GL20.glGetProgramInfoLog(programID, logging).trim();
    } else if (has_arb) {
        return ARBShaderObjects.glGetInfoLogARB(programID, logging).trim(); // TODO
    }
    return "";
}

From source file:me.thehutch.fusion.engine.render.opengl.gl20.OpenGL20Program.java

License:Open Source License

@Override
public void link() {
    ensureCreated("Program must be created to link.");
    // Link the program
    GL20.glLinkProgram(id);//from  w  w w  .ja  v a2s .c  om
    // Check program link success
    if (GL20.glGetProgrami(id, GL_LINK_STATUS) == GL_FALSE) {
        final int logLength = GL20.glGetProgrami(id, GL_INFO_LOG_LENGTH);
        throw new IllegalStateException(
                "Program could not be linked\n" + GL20.glGetProgramInfoLog(id, logLength));
    }
    // Check for errors
    RenderUtil.checkGLError();

    // Validate the program
    GL20.glValidateProgram(id);
    // Check program validation success
    if (GL20.glGetProgrami(id, GL_VALIDATE_STATUS) == GL_FALSE) {
        final int logLength = GL20.glGetProgrami(id, GL_INFO_LOG_LENGTH);
        System.err.println("Program validation failed:\n" + GL20.glGetProgramInfoLog(id, logLength));
    }
    // Check for errors
    RenderUtil.checkGLError();

    /*
     * Load the program uniforms
     */
    // Get the maximum uniform name length
    final int maxNameLength = GL20.glGetProgrami(id, GL_ACTIVE_UNIFORM_MAX_LENGTH);
    // Create a buffer to store the name of the uniform
    final ByteBuffer nameBuffer = BufferUtils.createByteBuffer(maxNameLength);
    // Create a buffer to store the length of the uniform name
    final IntBuffer lengthBuffer = BufferUtils.createIntBuffer(1);
    // Create a buffer to store the uniform size
    final IntBuffer sizeBuffer = BufferUtils.createIntBuffer(1);
    // Create a buffer to stroe the uniform type
    final IntBuffer typeBuffer = BufferUtils.createIntBuffer(1);
    // Create a byte array to store the name in
    final byte[] nameBytes = new byte[maxNameLength];
    int textureUnit = 0;

    final int uniformCount = GL20.glGetProgrami(id, GL_ACTIVE_UNIFORMS);
    for (int i = 0; i < uniformCount; ++i) {
        // Retrieve the attributes of the uniform (length, size, type and name)
        GL20.glGetActiveUniform(id, i, lengthBuffer, sizeBuffer, typeBuffer, nameBuffer);

        // Get the length of the uniform name
        final int length = lengthBuffer.get();

        // Get the name from the buffer and put it in the byte[]
        nameBuffer.get(nameBytes, 0, length);

        final String name = new String(nameBytes, 0, length);

        // Convert the name buffer to a String
        this.uniforms.put(name, GL20.glGetUniformLocation(id, name));

        // Check if the uniform is a texture/sampler
        switch (typeBuffer.get()) {
        case GL_SAMPLER_2D:
        case GL_SAMPLER_CUBE:
            this.textures.put(textureUnit++, name);
            break;
        default:
            break;
        }

        // Clear the buffers
        lengthBuffer.clear();
        sizeBuffer.clear();
        typeBuffer.clear();
        nameBuffer.clear();
    }
    // Check for errors
    RenderUtil.checkGLError();
}

From source file:net.neilcsmith.praxis.video.opengl.internal.ShaderProgram.java

License:Apache License

/** @return the log info for the shader compilation and program linking stage. The shader needs to be bound for this method to
 *         have an effect. *//*  w  ww  .  j  a v  a  2  s  .c o  m*/
public String getLog() {
    if (isCompiled) {
        GL20.glGetProgram(program, GL20.GL_INFO_LOG_LENGTH, intbuf);
        int infoLogLength = intbuf.get(0);
        if (infoLogLength > 1)
            log = GL20.glGetProgramInfoLog(program, infoLogLength);
        return log;
    } else {
        return log;
    }
}

From source file:org.bonsaimind.badgersvoyage.tools.planetstudio.Studio.java

License:Open Source License

public Studio(String title, int width, int height) throws LWJGLException {
    PixelFormat pixelFormat = new PixelFormat();
    ContextAttribs contextAttribs = new ContextAttribs(3, 2);
    contextAttribs.withForwardCompatible(true);
    contextAttribs.withProfileCore(true);

    Display.setDisplayMode(new DisplayMode(width, height));
    Display.setTitle(title);/*  w  w w .  ja  v a2 s . co  m*/
    Display.create(pixelFormat, contextAttribs);

    ErrorChecker.exitOnOpenGlError("Display creation.");

    programId = GL20.glCreateProgram();
    ErrorChecker.exitOnOpenGlError("Program creation.");

    int shaderId = GL20.glCreateShader(GL20.GL_VERTEX_SHADER);
    //      GL20.glShaderSource(shaderId, "void main {\n"
    //            + "   gl_Normal = gl_NormalMatrix * gl_Normal; //Note that you can perform operations on matrices and vectors as if they were\n"
    //            + "                                                //primitive types. This is useful for simple, readable code like this.\n"
    //            + "    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; //The order in which you times matrices and vertices is IMPORTANT.\n"
    //            + "    gl_FrontColor = gl_Color;   //These lines just pass on the colour value to the fragment shader.\n"
    //            + "    gl_BackColor = gl_Color;\n"
    //            + "}");
    GL20.glShaderSource(shaderId, "void main(void){gl_Position = ftransform();}");
    //      GL20.glShaderSource(shaderId, "#version 140\n"
    //            + "\n"
    //            + "uniform Transformation {\n"
    //            + "    mat4 projectionMatrix;\n"
    //            + "    mat4 viewMatrix;\n"
    //            + "    mat4 modelMatrix;\n"
    //            + "};\n"
    //            + "in vec4 in_Position;\n"
    //            + "\n"
    //            + "in vec3 vertex;\n"
    //            + "\n"
    //            + "void main() {\n"
    //            + "    gl_Position = projectionMatrix * viewMatrix * modelMatrix * in_Position;\n"
    //            + "}");
    //      GL20.glShaderSource(shaderId, "#version 150 core\n"
    //            + "\n"
    //            + "uniform mat4 projectionMatrix;\n"
    //            + "uniform mat4 viewMatrix;\n"
    //            + "uniform mat4 modelMatrix;\n"
    //            + "\n"
    //            + "in vec4 in_Position;\n"
    //            + "in vec4 in_Color;\n"
    //            + "in vec2 in_TextureCoord;\n"
    //            + "\n"
    //            + "out vec4 pass_Color;\n"
    //            + "out vec2 pass_TextureCoord;\n"
    //            + "\n"
    //            + "void main(void) {\n"
    //            + "   gl_Position = in_Position;\n"
    //            + "   gl_Position = projectionMatrix * viewMatrix * modelMatrix * in_Position;\n"
    //            + "\n"
    //            + "   pass_Color = in_Color;\n"
    //            + "   pass_TextureCoord = in_TextureCoord;\n"
    //            + "}");
    GL20.glCompileShader(shaderId);
    GL20.glAttachShader(programId, shaderId);

    //      int shaderId2 = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER);
    //      GL20.glShaderSource(shaderId2, "#version 150 core\n"
    //            + "\n"
    //            + "uniform sampler2D texture_diffuse;\n"
    //            + "\n"
    //            + "in vec4 pass_Color;\n"
    //            + "in vec2 pass_TextureCoord;\n"
    //            + "\n"
    //            + "out vec4 out_Color;\n"
    //            + "\n"
    //            + "void main(void) {\n"
    //            + "   out_Color = pass_Color;\n"
    //            + "   // Override out_Color with our texture pixel\n"
    //            + "   out_Color = vec4(0.5, 0.5, 0.5, 1); //texture2D(texture_diffuse, pass_TextureCoord);\n"
    //            + "}");
    //      GL20.glCompileShader(shaderId2);
    //      GL20.glAttachShader(programId, shaderId2);

    GL20.glLinkProgram(programId);

    ErrorChecker.exitOnOpenGlError("Program linking.");

    System.err.println(GL20.glGetProgramInfoLog(programId, 255));
    System.err.println();

    GL20.glValidateProgram(programId);
    ErrorChecker.exitOnOpenGlError("Program validation.");

    camera = new Camera(width / (float) height, new Vector3f(0, 0, 2.5f), 100f, 60f, 0.1f, programId);
    ErrorChecker.exitOnOpenGlError("Camera creation.");

    sphere = new Sphere(60, 0.5f);
    sphere.create(programId);
    ErrorChecker.exitOnOpenGlError("Sphere creation.");
}

From source file:org.spout.engine.renderer.shader.ClientShader.java

License:Open Source License

private void doCompileShader(String vsource, String fsource) {
    if (((Client) Spout.getEngine()).getRenderMode() == RenderMode.GL11) {
        return;//from ww  w.ja v a 2s .  com
    }

    //Create a new Shader object on the GPU
    program = GL20.glCreateProgram();

    int vShader = ShaderHelper.compileShader(vsource, GL20.GL_VERTEX_SHADER);
    GL20.glAttachShader(program, vShader);

    int fShader = ShaderHelper.compileShader(fsource, GL20.GL_FRAGMENT_SHADER);
    GL20.glAttachShader(program, fShader);

    GL20.glLinkProgram(program);

    int status = GL20.glGetProgram(program, GL20.GL_LINK_STATUS);
    if (status != GL11.GL_TRUE) {
        String error = GL20.glGetProgramInfoLog(program, 255);
        throw new ShaderCompileException("Link Error: " + error);
    }
    if (validateShader) {
        GL20.glValidateProgram(this.program);
        if (GL20.glGetProgram(program, GL20.GL_VALIDATE_STATUS) != GL11.GL_TRUE) {
            String info = GL20.glGetProgramInfoLog(program, 255);
            System.out.println("Validate Log: \n" + info);
        }

        System.out.println("Attached Shaders: " + GL20.glGetProgram(program, GL20.GL_ATTACHED_SHADERS));
        int activeAttributes = GL20.glGetProgram(program, GL20.GL_ACTIVE_ATTRIBUTES);
        System.out.println("Active Attributes: " + activeAttributes);
        int maxAttributeLength = GL20.glGetProgram(program, GL20.GL_ACTIVE_ATTRIBUTE_MAX_LENGTH);
        for (int i = 0; i < activeAttributes; i++) {
            System.out.println("\t" + GL20.glGetActiveAttrib(program, i, maxAttributeLength));
        }

        int activeUniforms = GL20.glGetProgram(program, GL20.GL_ACTIVE_UNIFORMS);
        System.out.println("Active Uniforms: " + activeUniforms);
        int maxUniformLength = GL20.glGetProgram(program, GL20.GL_ACTIVE_UNIFORM_MAX_LENGTH);
        for (int i = 0; i < activeUniforms; i++) {
            System.out.println("\t" + GL20.glGetActiveUniform(program, i, maxUniformLength));
        }
    }
    System.out.println("Compiled Shader with id: " + program);
}

From source file:org.spout.renderer.lwjgl.gl20.GL20Program.java

License:Open Source License

@Override
public void link() {
    checkCreated();//from w w  w .j ava2 s  .c o m
    // 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);
    for (int i = 0; i < uniformCount; i++) {
        final ByteBuffer nameBuffer = CausticUtil.createByteBuffer(256);
        GL20.glGetActiveUniform(id, i, CausticUtil.createIntBuffer(1), CausticUtil.createIntBuffer(1),
                CausticUtil.createIntBuffer(1), nameBuffer);
        nameBuffer.rewind();
        final byte[] nameBytes = new byte[256];
        nameBuffer.get(nameBytes);
        // Simplify array names
        final String name = new String(nameBytes).trim().replaceFirst("\\[\\d+\\]", "");
        uniforms.put(name, GL20.glGetUniformLocation(id, name));
    }
    // Check for errors
    LWJGLUtil.checkForGLError();
}