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:com.mtbs3d.minecrift.VRRenderer.java

License:LGPL

private boolean setupFBOs() {
    try {/*from   ww  w.  j a  v a2 s  .c o  m*/
        if (this.mc.displayFBWidth != _previousDisplayWidth || this.mc.displayFBHeight != _previousDisplayHeight
                || !_FBOInitialised) {
            _FBOInitialised = false;

            _previousDisplayWidth = this.mc.displayFBWidth;
            _previousDisplayHeight = this.mc.displayFBHeight;

            _DistortionShader_DistortionMapUniform = -1;
            _DistortionShader_RenderTextureUniform = -1;
            _DistortionShader_half_screenWidthUniform = -1;
            _DistortionShader_LeftLensCenterUniform = -1;
            _DistortionShader_RightLensCenterUniform = -1;
            _DistortionShader_LeftScreenCenterUniform = -1;
            _DistortionShader_RightScreenCenterUniform = -1;
            _DistortionShader_ScaleUniform = -1;
            _DistortionShader_ScaleInUniform = -1;
            _DistortionShader_HmdWarpParamUniform = -1;
            _DistortionShader_ChromAbParamUniform = -1;

            if (preDistortionFBO != null)
                preDistortionFBO.delete();
            preDistortionFBO = null;

            if (guiFBO != null)
                guiFBO.delete();
            guiFBO = null;

            if (fxaaFBO != null)
                fxaaFBO.delete();
            fxaaFBO = null;

            if (postDistortionFBO != null)
                postDistortionFBO.delete();
            postDistortionFBO = null;

            if (postSuperSampleFBO != null)
                postSuperSampleFBO.delete();
            postSuperSampleFBO = null;

            _LanczosShader_texelWidthOffsetUniform = -1;
            _LanczosShader_texelHeightOffsetUniform = -1;
            _LanczosShader_inputImageTextureUniform = -1;

            if (distortParams != null)
                distortParams.delete();
        }

        if (!_FBOInitialised) {
            float distance = this.farPlaneDistance * 2.0F;
            if (distance < 128.0F) {
                distance = 128.0F;
            }

            //Setup eye render params
            if (this.mc.vrSettings.useSupersample) {
                eyeRenderParams = mc.hmdInfo.getEyeRenderParams(0, 0,
                        (int) ceil(this.mc.displayFBWidth * this.mc.vrSettings.superSampleScaleFactor),
                        (int) ceil(this.mc.displayFBHeight * this.mc.vrSettings.superSampleScaleFactor), 0.05F,
                        distance, this.mc.vrSettings.fovScaleFactor,
                        this.mc.vrSettings.lensSeparationScaleFactor, getDistortionFitX(), getDistortionFitY(),
                        this.mc.vrSettings.getAspectRatioCorrectionMode());
            } else {
                eyeRenderParams = mc.hmdInfo.getEyeRenderParams(0, 0, this.mc.displayFBWidth,
                        this.mc.displayFBHeight, 0.05F, distance, this.mc.vrSettings.fovScaleFactor,
                        this.mc.vrSettings.lensSeparationScaleFactor, getDistortionFitX(), getDistortionFitY(),
                        this.mc.vrSettings.getAspectRatioCorrectionMode());
            }

            System.out.println("[Minecrift] INITIALISE Display");
            System.out.println("[Minecrift] Distortion: " + (this.mc.vrSettings.useDistortion ? "ON" : "OFF"));
            System.out.println(
                    "[Minecrift] Display w: " + this.mc.displayFBWidth + ", h: " + this.mc.displayFBHeight);
            System.out.println("[Minecrift] Renderscale: " + eyeRenderParams._renderScale);
            if (this.mc.vrSettings.useSupersample)
                System.out.println("[Minecrift] FSAA Scale: " + this.mc.vrSettings.superSampleScaleFactor);
            else
                System.out.println("[Minecrift] FSAA OFF");

            if (this.mc.vrSettings.useSupersample) {
                preDistortionFBO = new FBOParams("preDistortionFBO (SS)", GL11.GL_TEXTURE_2D, GL11.GL_RGBA8,
                        GL11.GL_RGBA, GL11.GL_INT,
                        (int) ceil(this.mc.displayFBWidth * eyeRenderParams._renderScale
                                * this.mc.vrSettings.superSampleScaleFactor),
                        (int) ceil(this.mc.displayFBHeight * eyeRenderParams._renderScale
                                * this.mc.vrSettings.superSampleScaleFactor));
            } else {
                preDistortionFBO = new FBOParams("preDistortionFBO", GL11.GL_TEXTURE_2D, GL11.GL_RGBA8,
                        GL11.GL_RGBA, GL11.GL_INT,
                        (int) ceil(this.mc.displayFBWidth * eyeRenderParams._renderScale),
                        (int) ceil(this.mc.displayFBHeight * eyeRenderParams._renderScale));
            }
            mc.checkGLError("FBO create");

            if (this.mc.vrSettings.useDistortionTextureLookupOptimisation) {
                if (this.mc.vrSettings.useChromaticAbCorrection) {
                    _Distortion_shaderProgramId = ShaderHelper.initShaders(BASIC_VERTEX_SHADER,
                            OCULUS_DISTORTION_FRAGMENT_SHADER_WITH_CHROMATIC_ABERRATION_CORRECTION_DIST_MAP,
                            false);
                } else {
                    _Distortion_shaderProgramId = ShaderHelper.initShaders(BASIC_VERTEX_SHADER,
                            OCULUS_DISTORTION_FRAGMENT_SHADER_NO_CHROMATIC_ABERRATION_CORRECTION_DIST_MAP,
                            false);
                }
            } else {
                if (this.mc.vrSettings.useChromaticAbCorrection) {
                    _Distortion_shaderProgramId = ShaderHelper.initShaders(BASIC_VERTEX_SHADER,
                            OCULUS_DISTORTION_FRAGMENT_SHADER_WITH_CHROMATIC_ABERRATION_CORRECTION, false);
                } else {
                    _Distortion_shaderProgramId = ShaderHelper.initShaders(BASIC_VERTEX_SHADER,
                            OCULUS_DISTORTION_FRAGMENT_SHADER_NO_CHROMATIC_ABERRATION_CORRECTION, false);
                }
            }

            // Setup uniform IDs
            _DistortionShader_DistortionMapUniform = ARBShaderObjects
                    .glGetUniformLocationARB(_Distortion_shaderProgramId, "distortionMap");
            _DistortionShader_RenderTextureUniform = ARBShaderObjects
                    .glGetUniformLocationARB(_Distortion_shaderProgramId, "bgl_RenderTexture");
            _DistortionShader_half_screenWidthUniform = ARBShaderObjects
                    .glGetUniformLocationARB(_Distortion_shaderProgramId, "half_screenWidth");
            _DistortionShader_LeftLensCenterUniform = ARBShaderObjects
                    .glGetUniformLocationARB(_Distortion_shaderProgramId, "LeftLensCenter");
            _DistortionShader_RightLensCenterUniform = ARBShaderObjects
                    .glGetUniformLocationARB(_Distortion_shaderProgramId, "RightLensCenter");
            _DistortionShader_LeftScreenCenterUniform = ARBShaderObjects
                    .glGetUniformLocationARB(_Distortion_shaderProgramId, "LeftScreenCenter");
            _DistortionShader_RightScreenCenterUniform = ARBShaderObjects
                    .glGetUniformLocationARB(_Distortion_shaderProgramId, "RightScreenCenter");
            _DistortionShader_ScaleUniform = ARBShaderObjects
                    .glGetUniformLocationARB(_Distortion_shaderProgramId, "Scale");
            _DistortionShader_ScaleInUniform = ARBShaderObjects
                    .glGetUniformLocationARB(_Distortion_shaderProgramId, "ScaleIn");
            _DistortionShader_HmdWarpParamUniform = ARBShaderObjects
                    .glGetUniformLocationARB(_Distortion_shaderProgramId, "HmdWarpParam");
            _DistortionShader_ChromAbParamUniform = ARBShaderObjects
                    .glGetUniformLocationARB(_Distortion_shaderProgramId, "ChromAbParam");

            ShaderHelper.checkGLError("FBO init shader");

            // GUI FBO
            guiFBO = new FBOParams("guiFBO", GL11.GL_TEXTURE_2D, GL11.GL_RGBA8, GL11.GL_RGBA, GL11.GL_INT,
                    this.mc.displayWidth, this.mc.displayHeight);

            // FXAA FBO
            if (this.mc.vrSettings.useFXAA) {
                // Shader init
                _FXAA_shaderProgramId = ShaderHelper.initShaders(BASIC_VERTEX_SHADER, FXAA_FRAGMENT_SHADER,
                        false);

                _FXAA_RenderTextureUniform = ARBShaderObjects.glGetUniformLocationARB(_FXAA_shaderProgramId,
                        "sampler0");
                _FXAA_RenderedTextureSizeUniform = ARBShaderObjects
                        .glGetUniformLocationARB(_FXAA_shaderProgramId, "resolution");

                if (this.mc.vrSettings.useSupersample) {
                    fxaaFBO = new FBOParams("fxaaFBO", GL11.GL_TEXTURE_2D, GL11.GL_RGBA8, GL11.GL_RGBA,
                            GL11.GL_INT,
                            (int) ceil(this.mc.displayFBWidth * this.mc.vrSettings.superSampleScaleFactor),
                            (int) ceil(this.mc.displayFBHeight * this.mc.vrSettings.superSampleScaleFactor));
                } else {
                    fxaaFBO = new FBOParams("fxaaFBO", GL11.GL_TEXTURE_2D, GL11.GL_RGBA8, GL11.GL_RGBA,
                            GL11.GL_INT, this.mc.displayFBWidth, this.mc.displayFBHeight);
                }

                ShaderHelper.checkGLError("Init FXAA");
            }

            if (this.mc.vrSettings.useSupersample) {
                // Lanczos downsample FBOs
                postDistortionFBO = new FBOParams("postDistortionFBO (SS)", GL11.GL_TEXTURE_2D, GL11.GL_RGBA8,
                        GL11.GL_RGBA, GL11.GL_INT,
                        (int) ceil(this.mc.displayFBWidth * this.mc.vrSettings.superSampleScaleFactor),
                        (int) ceil(this.mc.displayFBHeight * this.mc.vrSettings.superSampleScaleFactor));
                postSuperSampleFBO = new FBOParams("postSuperSampleFBO (SS)", GL11.GL_TEXTURE_2D, GL11.GL_RGBA8,
                        GL11.GL_RGBA, GL11.GL_INT, (int) ceil(this.mc.displayFBWidth),
                        (int) ceil(this.mc.displayFBHeight * this.mc.vrSettings.superSampleScaleFactor));

                mc.checkGLError("Lanczos FBO create");

                _Lanczos_shaderProgramId = ShaderHelper.initShaders(LANCZOS_SAMPLER_VERTEX_SHADER,
                        LANCZOS_SAMPLER_FRAGMENT_SHADER, true);

                ShaderHelper.checkGLError("@1");
                GL20.glValidateProgram(_Lanczos_shaderProgramId);

                // Setup uniform IDs
                _LanczosShader_texelWidthOffsetUniform = ARBShaderObjects
                        .glGetUniformLocationARB(_Lanczos_shaderProgramId, "texelWidthOffset");
                _LanczosShader_texelHeightOffsetUniform = ARBShaderObjects
                        .glGetUniformLocationARB(_Lanczos_shaderProgramId, "texelHeightOffset");
                _LanczosShader_inputImageTextureUniform = ARBShaderObjects
                        .glGetUniformLocationARB(_Lanczos_shaderProgramId, "inputImageTexture");

                ShaderHelper.checkGLError("FBO init Lanczos shader");
            } else {
                _Lanczos_shaderProgramId = -1;
                _LanczosShader_texelWidthOffsetUniform = -1;
                _LanczosShader_texelHeightOffsetUniform = -1;
                _LanczosShader_inputImageTextureUniform = -1;
            }

            // Pre-calculate distortion map
            distortParams = new DistortionParams(this.mc.hmdInfo.getHMDInfo(), this.eyeRenderParams,
                    this.mc.displayFBWidth, this.mc.displayFBHeight,
                    this.mc.vrSettings.useChromaticAbCorrection, this.mc.vrSettings.useSupersample,
                    this.mc.vrSettings.superSampleScaleFactor);

            // Get our refresh period
            int Hz = Display.getDisplayMode().getFrequency();
            if (Hz != 0)
                vsyncPeriodNanos = 1000000000L / Hz;
            else
                vsyncPeriodNanos = 0;

            _FBOInitialised = true;
        }
    } catch (Exception ex) {
        // We had an issue. Set the usual suspects to defaults...
        this.mc.vrSettings.useSupersample = false;
        this.mc.vrSettings.superSampleScaleFactor = 2.0f;
        this.mc.vrSettings.saveOptions();
        return false;
    }

    return true;
}

From source file:com.opengrave.og.resources.ShaderProgram.java

License:Open Source License

public void compile() {
    Util.checkErr();//  w w  w.  ja v  a 2  s  .  co m

    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.redthirddivision.quad.rendering.shaders.Shader.java

License:Apache License

public Shader(String file) {
    this.vertexID = loadVertex(file);
    this.fragmentID = loadFragment(file);
    this.programID = GL20.glCreateProgram();
    GL20.glAttachShader(programID, vertexID);
    GL20.glAttachShader(programID, fragmentID);

    bindAttributes();//from w w  w.  j  av a2  s .  c  o  m

    GL20.glLinkProgram(programID);
    GL20.glValidateProgram(programID);

    addUniforms();
}

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);/*  ww w. j ava2s  . c  om*/
    }
    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

/**
 * Validates this program, checking to see whether the executables contained
 * in this program can be executed in the current OpenGL state.
 * /*from   ww w .j a v  a  2s.  c  o m*/
 * @return This shader program.
 */
public ShaderProgram validate() {
    if (state != State.LINKED)
        throw new IllegalStateException("Shader program must be linked to validate.");

    GL20.glValidateProgram(id);
    checkStatus(GL20.GL_VALIDATE_STATUS);

    state = State.COMPLETE;
    return this;
}

From source file:com.timvisee.voxeltex.module.shader.raw.RawShader.java

License:Open Source License

@Override
public int compile() {
    // Show a status message
    System.out.print("Compiling shader... ");

    // Create a new OpenGL shader program
    int program = GL20.glCreateProgram();

    // Shader IDs
    int vertexId = 0;
    int fragmentId = 0;

    // Compile the vertex shader if available
    if (hasVertexShader()) {
        // Create the vertex shader
        vertexId = GL20.glCreateShader(GL20.GL_VERTEX_SHADER);

        // Attach the vertex shader source and compile it
        GL20.glShaderSource(vertexId, vertexSource);
        GL20.glCompileShader(vertexId);// w  w  w. j a  v a 2  s. c o m

        // Check for compiling errors
        if (GL20.glGetShaderi(vertexId, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
            // Show an error message
            System.out.println("FAIL\nFailed to compile the vertex shader");
            System.out.println(GL20.glGetShaderInfoLog(vertexId));

            // Delete the shader before returning
            GL20.glDeleteShader(vertexId);
            throw new RuntimeException("Failed to compile the vertex shader");
        }
    }

    // Compile the fragment shader if available
    if (hasFragmentShader()) {
        // Create the fragment shader
        fragmentId = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER);

        // Attach the fragment shader source and compile it
        GL20.glShaderSource(fragmentId, fragmentSource);
        GL20.glCompileShader(fragmentId);

        // Check for compiling errors
        if (GL20.glGetShaderi(fragmentId, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
            // Show an error message
            System.out.println("FAIL\nFailed to compile the fragment shader");
            System.out.println(GL20.glGetShaderInfoLog(fragmentId));

            // Delete the shader before returning
            GL20.glDeleteShader(fragmentId);
            throw new RuntimeException("Failed to compile the vertex shader");
        }
    }

    // Attach all compiled shaders
    if (hasVertexShader())
        GL20.glAttachShader(program, vertexId);
    if (hasFragmentShader())
        GL20.glAttachShader(program, fragmentId);

    // Link the shader program to OpenGL and link it
    GL20.glLinkProgram(program);
    GL20.glValidateProgram(program);

    // Shaders have been attached to the program, delete their compiled sources to save memory
    if (hasVertexShader())
        GL20.glDeleteShader(vertexId);
    if (hasFragmentShader())
        GL20.glDeleteShader(fragmentId);

    // Show a status message
    System.out.println("OK");

    // Return the created OpenGL shader program
    return program;
}

From source file:com.voxelplugineering.voxelsniper.render.RenderMain.java

License:Open Source License

private void setupShaders() {
    // Load the vertex shader
    int vsId = GLSLUtilities.loadShader("assets/shaders/vertex.glsl", GL20.GL_VERTEX_SHADER);
    // Load the fragment shader
    int fsId = GLSLUtilities.loadShader("assets/shaders/fragment.glsl", GL20.GL_FRAGMENT_SHADER);

    // Create a new shader program that links both shaders
    pId = GL20.glCreateProgram();//from www  . j a v  a 2s.c om
    GL20.glAttachShader(pId, vsId);
    GL20.glAttachShader(pId, fsId);

    GL20.glBindAttribLocation(pId, 0, "in_Position");
    GL20.glBindAttribLocation(pId, 1, "in_Color");
    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");

    OpenGLUtilities.checkGLError("setupShaders");
}

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 .  j  a v a  2s  .  c  om*/
    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   ww  w.jav  a  2 s  .  com*/

    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 GLShader createTexturedShader() {
    int vertexShaderId = compileShader(texturedVertexShaderSource, GL20.GL_VERTEX_SHADER);
    int fragmentShaderId = compileShader(texturedFragmentShaderSource, 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.glBindAttribLocation(programId, 2, "in_TexCoord");

    GL20.glLinkProgram(programId);/*from ww  w .  j  a va 2s .co  m*/

    validateLinkage(programId);

    GL20.glValidateProgram(programId);

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