Example usage for org.lwjgl.opengl GL20 glValidateProgram

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

Introduction

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

Prototype

public static void glValidateProgram(@NativeType("GLuint") int program) 

Source Link

Document

Validates a program object.

Usage

From source file:de.ikosa.mars.viewer.glviewer.engine.GLHardcodedShader.java

License:Open Source License

private static GLShader createFlatShader() {
    int vertexShaderId = compileShader(flatVertexShaderSource, GL20.GL_VERTEX_SHADER);
    int fragmentShaderId = compileShader(flatFragmentShaderSource, GL20.GL_FRAGMENT_SHADER);

    int programId = GL20.glCreateProgram();
    GL20.glAttachShader(programId, vertexShaderId);
    GL20.glAttachShader(programId, fragmentShaderId);

    // Bind Attrib Location...
    GL20.glBindAttribLocation(programId, 0, "in_Position");
    GL20.glBindAttribLocation(programId, 1, "in_Normal");

    GL20.glLinkProgram(programId);//from w w  w .ja v  a 2s. c  o  m

    validateLinkage(programId);

    GL20.glValidateProgram(programId);

    return new GLShader(programId, vertexShaderId, fragmentShaderId);
}

From source file:de.ikosa.mars.viewer.glviewer.engine.GLShaderBuilder.java

License:Open Source License

public GLShader createShader(GLResources resourceManager) {
    int vertexShaderId = compileShader(vertexSource, GL20.GL_VERTEX_SHADER);
    int fragmentShaderId = compileShader(fragmentSource, GL20.GL_FRAGMENT_SHADER);

    int programId = GL20.glCreateProgram();
    GL20.glAttachShader(programId, vertexShaderId);
    GL20.glAttachShader(programId, fragmentShaderId);

    // Bind attribute locations
    GL20.glBindAttribLocation(programId, 0, "in_Position");

    if (vertexSource.contains("in_Normal"))
        GL20.glBindAttribLocation(programId, 1, "in_Normal");
    if (vertexSource.contains("in_TexCoord"))
        GL20.glBindAttribLocation(programId, 2, "in_TexCoord");

    GL20.glLinkProgram(programId);//from  ww w.  j a  v  a2  s.c  o m

    validateLinkage(programId);

    GL20.glValidateProgram(programId);

    return new GLShader(programId, vertexShaderId, fragmentShaderId);
}

From source file:fr.guillaume.prive.viper.core.graphic.GraphicMotor.java

private static void setupShaders() {
    int vsId = GraphicMotor.loadShader("resources/shader/ship.vert", GL20.GL_VERTEX_SHADER);
    int fsId = GraphicMotor.loadShader("resources/shader/ship.frag", GL20.GL_FRAGMENT_SHADER);

    instance.shipShaderId = GL20.glCreateProgram();
    GL20.glAttachShader(instance.shipShaderId, vsId);
    GL20.glAttachShader(instance.shipShaderId, fsId);
    GL20.glBindAttribLocation(instance.shipShaderId, 0, "in_Position");
    GL20.glBindAttribLocation(instance.shipShaderId, 1, "Normal");
    GL20.glBindAttribLocation(instance.shipShaderId, 2, "in_Color");
    GL20.glBindAttribLocation(instance.shipShaderId, 3, "in_TextureCoord");

    GL20.glLinkProgram(instance.shipShaderId);
    GL20.glValidateProgram(instance.shipShaderId);

    instance.projectionMatrixLocation = GL20.glGetUniformLocation(instance.shipShaderId, "projectionMatrix");
    instance.viewMatrixLocation = GL20.glGetUniformLocation(instance.shipShaderId, "viewMatrix");
    instance.modelMatrixLocation = GL20.glGetUniformLocation(instance.shipShaderId, "modelMatrix");

    instance.useTextureLocation = GL20.glGetUniformLocation(instance.shipShaderId, "use_texture");

    GraphicMotor.exitOnGLError("setupShaders");
}

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

License:Apache License

public static void glValidateProgram(int program) {
    GL20.glValidateProgram(program);
}

From source file:ivorius.ivtoolkit.rendering.IvOpenGLHelper.java

License:Apache License

public static void glValidateProgram(int program) {
    Field useARBField = ReflectionHelper.findField(OpenGlHelper.class, "field_153214_y");
    useARBField.setAccessible(true);/*from   ww  w.  ja  va 2  s. c  om*/
    boolean useARB = false;

    try {
        useARB = useARBField.getBoolean(null);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    if (useARB)
        ARBShaderObjects.glValidateProgramARB(program);
    else
        GL20.glValidateProgram(program);
}

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

License:Open Source License

@Override
public boolean validateProgram(int program) {
    GL20.glValidateProgram(program);
    return GL20.glGetProgram(program, GL20.GL_VALIDATE_STATUS) == GL11.GL_TRUE;
}

From source file:main.java.com.YeAJG.game.entity.Entity.java

License:Open Source License

private void SetupShaders(String shaderPath, String fragPath) {
    // Load the vertex shader and fragment shader
    vsId = ShaderHandler.loadShader(shaderPath);
    fsId = ShaderHandler.loadFrag(fragPath);

    // Create a new shader program that links both shaders
    pId = GL20.glCreateProgram();//from  w w w. j  a  va2 s .  co m
    GL20.glAttachShader(pId, vsId);
    GL20.glAttachShader(pId, fsId);

    // Position information will be attribute 0
    GL20.glBindAttribLocation(pId, 0, "in_Position");
    // Color information will be attribute 1
    GL20.glBindAttribLocation(pId, 1, "in_Color");
    // Textute information will be attribute 2
    GL20.glBindAttribLocation(pId, 2, "in_TextureCoord");

    GL20.glLinkProgram(pId);
    GL20.glValidateProgram(pId);

    // Get matrices uniform locations
    projectionMatrixLocation = GL20.glGetUniformLocation(pId, "projectionMatrix");
    viewMatrixLocation = GL20.glGetUniformLocation(pId, "viewMatrix");
    modelMatrixLocation = GL20.glGetUniformLocation(pId, "modelMatrix");

    decayLocation = GL20.glGetUniformLocation(pId, "decay");

    Game.exitOnGLError("setupShaders");
}

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);//w w  w . j  a  va  2 s  .com
    // 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:model.ModelMD2.java

public void setupShader() {
    vsId = ShaderUtils.makeShader(ShaderUtils.loadText("Resources/shaders/animation.vert"),
            GL20.GL_VERTEX_SHADER);//w  w  w  .  j  av  a  2 s  . co m
    // Load the fragment shader
    fsId = ShaderUtils.makeShader(ShaderUtils.loadText("Resources/shaders/animation.frag"),
            GL20.GL_FRAGMENT_SHADER);

    // Create a new shader program that links both shaders
    shader_id = ShaderUtils.makeProgram(vsId, fsId);

    GL20.glBindAttribLocation(shader_id, 0, "in_Position_0");
    GL20.glBindAttribLocation(shader_id, 1, "in_TextureCoord_0");
    GL20.glBindAttribLocation(shader_id, 2, "in_Normal_0");

    GL20.glBindAttribLocation(shader_id, 3, "in_Position_1");
    GL20.glBindAttribLocation(shader_id, 4, "in_TextureCoord_1");
    GL20.glBindAttribLocation(shader_id, 5, "in_Normal_1");

    GL20.glValidateProgram(shader_id);
    GLUtil.cerror(getClass().getName() + " setupShader");
}

From source file:net.betabears.the2dlibrary.graphics.shader.ShaderProgram.java

@Override
public void init() {
    if (isLoaded && !isInited) {
        s0.createShader();//from w  w  w .  jav  a 2  s . co  m
        s1.createShader();

        id = GL20.glCreateProgram();
        GL20.glAttachShader(id, s0.getID());
        GL20.glAttachShader(id, s1.getID());
        GL20.glLinkProgram(id);
        GL20.glValidateProgram(id);

        int i;
        while ((i = GL11.glGetError()) != 0) {
            LOGGER.log(Level.WARNING, "Error happened during creation of ShaderProgram. GL error code: {0}", i);
        }
        isInited = true;
    } else {
        LOGGER.log(Level.WARNING, "load() wasn't called before init() or init() has been called already.");
    }
}