Example usage for org.lwjgl.opengl ARBShaderObjects glShaderSourceARB

List of usage examples for org.lwjgl.opengl ARBShaderObjects glShaderSourceARB

Introduction

In this page you can find the example usage for org.lwjgl.opengl ARBShaderObjects glShaderSourceARB.

Prototype

public static void glShaderSourceARB(@NativeType("GLhandleARB") int shaderObj,
        @NativeType("GLcharARB const **") CharSequence string) 

Source Link

Document

Sets the source code for the specified shader object shaderObj to the text strings in the string array.

Usage

From source file:com.a2client.corex.Shader.java

License:Open Source License

public void attach(int shader_type, String src) {
    int obj = ARBShaderObjects.glCreateShaderObjectARB(shader_type);
    ARBShaderObjects.glShaderSourceARB(obj, src);
    ARBShaderObjects.glCompileShaderARB(obj);

    if (ARBShaderObjects.glGetObjectParameteriARB(obj,
            ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE)
        throw new RuntimeException("Error creating shader: " + getLogInfo(obj));

    shaders.add(obj);/*from w ww . j  av  a 2s.  c  o  m*/
}

From source file:com.ardor3d.scene.state.lwjgl.LwjglShaderObjectsStateUtil.java

License:Open Source License

protected static void sendToGL(final GLSLShaderObjectsState state, final ContextCapabilities caps) {
    if (state.getVertexShader() == null && state.getFragmentShader() == null) {
        logger.warning("Could not find shader resources!" + "(both inputbuffers are null)");
        state._needSendShader = false;//from  w ww  .  j  av  a2s .  c o  m
        return;
    }

    if (state._programID == -1) {
        state._programID = ARBShaderObjects.glCreateProgramObjectARB();
    }

    if (state.getVertexShader() != null) {
        if (state._vertexShaderID != -1) {
            removeVertShader(state);
        }

        state._vertexShaderID = ARBShaderObjects.glCreateShaderObjectARB(ARBVertexShader.GL_VERTEX_SHADER_ARB);

        // Create the sources
        ARBShaderObjects.glShaderSourceARB(state._vertexShaderID, state.getVertexShader());

        // Compile the vertex shader
        final IntBuffer compiled = BufferUtils.createIntBuffer(1);
        ARBShaderObjects.glCompileShaderARB(state._vertexShaderID);
        ARBShaderObjects.glGetObjectParameterARB(state._vertexShaderID,
                ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB, compiled);
        checkProgramError(compiled, state._vertexShaderID, state._vertexShaderName);

        // Attach the program
        ARBShaderObjects.glAttachObjectARB(state._programID, state._vertexShaderID);
    } else if (state._vertexShaderID != -1) {
        removeVertShader(state);
        state._vertexShaderID = -1;
    }

    if (state.getFragmentShader() != null) {
        if (state._fragmentShaderID != -1) {
            removeFragShader(state);
        }

        state._fragmentShaderID = ARBShaderObjects
                .glCreateShaderObjectARB(ARBFragmentShader.GL_FRAGMENT_SHADER_ARB);

        // Create the sources
        ARBShaderObjects.glShaderSourceARB(state._fragmentShaderID, state.getFragmentShader());

        // Compile the fragment shader
        final IntBuffer compiled = BufferUtils.createIntBuffer(1);
        ARBShaderObjects.glCompileShaderARB(state._fragmentShaderID);
        ARBShaderObjects.glGetObjectParameterARB(state._fragmentShaderID,
                ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB, compiled);
        checkProgramError(compiled, state._fragmentShaderID, state._fragmentShaderName);

        // Attach the program
        ARBShaderObjects.glAttachObjectARB(state._programID, state._fragmentShaderID);
    } else if (state._fragmentShaderID != -1) {
        removeFragShader(state);
        state._fragmentShaderID = -1;
    }

    if (caps.isGeometryShader4Supported()) {
        if (state.getGeometryShader() != null) {
            if (state._geometryShaderID != -1) {
                removeGeomShader(state);
            }

            state._geometryShaderID = ARBShaderObjects
                    .glCreateShaderObjectARB(ARBGeometryShader4.GL_GEOMETRY_SHADER_ARB);

            // Create the sources
            ARBShaderObjects.glShaderSourceARB(state._geometryShaderID, state.getGeometryShader());

            // Compile the fragment shader
            final IntBuffer compiled = BufferUtils.createIntBuffer(1);
            ARBShaderObjects.glCompileShaderARB(state._geometryShaderID);
            ARBShaderObjects.glGetObjectParameterARB(state._geometryShaderID,
                    ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB, compiled);
            checkProgramError(compiled, state._geometryShaderID, state._geometryShaderName);

            // Attach the program
            ARBShaderObjects.glAttachObjectARB(state._programID, state._geometryShaderID);
        } else if (state._geometryShaderID != -1) {
            removeGeomShader(state);
            state._geometryShaderID = -1;
        }
    }

    if (caps.isTessellationShadersSupported()) {
        if (state.getTessellationControlShader() != null) {
            if (state._tessellationControlShaderID != -1) {
                removeTessControlShader(state);
            }

            state._tessellationControlShaderID = ARBShaderObjects
                    .glCreateShaderObjectARB(ARBTessellationShader.GL_TESS_CONTROL_SHADER);

            // Create the sources
            ARBShaderObjects.glShaderSourceARB(state._tessellationControlShaderID,
                    state.getTessellationControlShader());

            // Compile the tessellation control shader
            final IntBuffer compiled = BufferUtils.createIntBuffer(1);
            ARBShaderObjects.glCompileShaderARB(state._tessellationControlShaderID);
            ARBShaderObjects.glGetObjectParameterARB(state._tessellationControlShaderID,
                    ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB, compiled);
            checkProgramError(compiled, state._tessellationControlShaderID,
                    state._tessellationControlShaderName);

            // Attach the program
            ARBShaderObjects.glAttachObjectARB(state._programID, state._tessellationControlShaderID);
        } else if (state._tessellationControlShaderID != -1) {
            removeTessControlShader(state);
            state._tessellationControlShaderID = -1;
        }

        if (state.getTessellationEvaluationShader() != null) {
            if (state._tessellationEvaluationShaderID != -1) {
                removeTessEvalShader(state);
            }

            state._tessellationEvaluationShaderID = ARBShaderObjects
                    .glCreateShaderObjectARB(ARBTessellationShader.GL_TESS_CONTROL_SHADER);

            // Create the sources
            ARBShaderObjects.glShaderSourceARB(state._tessellationEvaluationShaderID,
                    state.getTessellationEvaluationShader());

            // Compile the tessellation control shader
            final IntBuffer compiled = BufferUtils.createIntBuffer(1);
            ARBShaderObjects.glCompileShaderARB(state._tessellationEvaluationShaderID);
            ARBShaderObjects.glGetObjectParameterARB(state._tessellationEvaluationShaderID,
                    ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB, compiled);
            checkProgramError(compiled, state._tessellationEvaluationShaderID,
                    state._tessellationEvaluationShaderName);

            // Attach the program
            ARBShaderObjects.glAttachObjectARB(state._programID, state._tessellationEvaluationShaderID);
        } else if (state._tessellationEvaluationShaderID != -1) {
            removeTessEvalShader(state);
            state._tessellationEvaluationShaderID = -1;
        }
    }

    ARBShaderObjects.glLinkProgramARB(state._programID);
    checkLinkError(state._programID);
    state.setNeedsRefresh(true);
    state._needSendShader = false;
}

From source file:com.drazisil.opengl3demo.OpenGL3Demo.java

License:Apache License

private int createShader(String filename, int shaderType) throws Exception {
    int shader = 0;
    try {//from w w  w .j  av  a  2 s  .  c o m
        shader = ARBShaderObjects.glCreateShaderObjectARB(shaderType);

        if (shader == 0)
            return 0;

        ARBShaderObjects.glShaderSourceARB(shader, readFileAsString(filename));
        ARBShaderObjects.glCompileShaderARB(shader);

        if (ARBShaderObjects.glGetObjectParameteriARB(shader,
                ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE)
            throw new RuntimeException("Error creating shader: " + getLogInfo(shader));

        return shader;
    } catch (Exception exc) {
        ARBShaderObjects.glDeleteObjectARB(shader);
        throw exc;
    }
}

From source file:com.github.atomicblom.nullplayerexception.client.render.ShaderHelper.java

License:Open Source License

private static int createShader(String filename, int shaderType) {
    int shader = 0;
    try {/*from   www  . ja v  a2  s  . c  o m*/
        shader = ARBShaderObjects.glCreateShaderObjectARB(shaderType);

        if (shader == 0)
            return 0;

        ARBShaderObjects.glShaderSourceARB(shader, readFileAsString(filename));
        ARBShaderObjects.glCompileShaderARB(shader);

        if (ARBShaderObjects.glGetObjectParameteriARB(shader,
                ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE)
            throw new RuntimeException("Error creating shader: " + getLogInfo(shader));

        return shader;
    } catch (Exception e) {
        ARBShaderObjects.glDeleteObjectARB(shader);
        e.printStackTrace();
        return -1;
    }
}

From source file:com.runescape.client.revised.editor.modelviewer.Viewport.java

License:Open Source License

private int createShader(final String filename, final int shaderType) throws Exception {
    int shader = 0;
    try {/*from   www  .j av  a  2  s .  co  m*/
        shader = ARBShaderObjects.glCreateShaderObjectARB(shaderType);

        if (shader == 0) {
            return 0;
        }

        ARBShaderObjects.glShaderSourceARB(shader, this.readFileAsString(filename));
        ARBShaderObjects.glCompileShaderARB(shader);
        if (ARBShaderObjects.glGetObjectParameteriARB(shader,
                ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE) {
            throw new RuntimeException("Error creating shader: " + this.getLogInfo(shader));
        }
        return shader;
    } catch (final Exception exc) {
        ARBShaderObjects.glDeleteObjectARB(shader);
        throw exc;
    }
}

From source file:com.wuest.prefab.Structures.Render.ShaderHelper.java

License:Open Source License

private static int createShader(String filename, int shaderType) {
    int shader = 0;

    try {//from  w w  w  .  jav a 2 s  .  co m
        shader = ARBShaderObjects.glCreateShaderObjectARB(shaderType);

        if (shader == 0) {
            return 0;
        }

        ARBShaderObjects.glShaderSourceARB(shader, readFileAsString(filename));
        ARBShaderObjects.glCompileShaderARB(shader);

        if (ARBShaderObjects.glGetObjectParameteriARB(shader,
                ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE) {
            throw new RuntimeException("Error creating shader: " + getLogInfo(shader));
        }

        return shader;
    } catch (Exception e) {
        ARBShaderObjects.glDeleteObjectARB(shader);
        e.printStackTrace();
        return -1;
    }
}

From source file:de.sanandrew.mods.turretmod.client.util.ShaderHelper.java

License:Open Source License

private static int createShader(ResourceLocation file, int shaderType) {
    int shader = 0;
    try {/*from w w  w.  j  a  v  a2  s .c  om*/
        shader = ARBShaderObjects.glCreateShaderObjectARB(shaderType);

        if (shader == 0) {
            return 0;
        }

        ARBShaderObjects.glShaderSourceARB(shader, readFileAsString(file));
        ARBShaderObjects.glCompileShaderARB(shader);

        if (ARBShaderObjects.glGetObjectParameteriARB(shader,
                ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE) {
            throw new RuntimeException("Error creating shader: " + getLogInfo(shader));
        }

        return shader;
    } catch (IOException | NullPointerException e) {
        ARBShaderObjects.glDeleteObjectARB(shader);
        TmrConstants.LOG.log(Level.ERROR, "Cannot create Shader!", e);
        return -1;
    }
}

From source file:flash.display.Shader.java

License:Open Source License

protected void compileShader() {
    System.out.println("Compiling shader ...");
    final String vertexShader = vertexShader();
    final String fragmentShader = fragmentShader();

    System.out.println("Vertex shader:");
    System.out.println(vertexShader);
    System.out.println("Fragment shader:");
    System.out.println(fragmentShader);

    _vertexShaderId = ARBShaderObjects.glCreateShaderObjectARB(ARBVertexShader.GL_VERTEX_SHADER_ARB);
    ARBShaderObjects.glShaderSourceARB(_vertexShaderId, vertexShader);
    ARBShaderObjects.glCompileShaderARB(_vertexShaderId);
    System.out.println("VertexShader Info: " + ARBShaderObjects.glGetInfoLogARB(_vertexShaderId, 8192));

    _fragmentShaderId = ARBShaderObjects.glCreateShaderObjectARB(ARBFragmentShader.GL_FRAGMENT_SHADER_ARB);
    ARBShaderObjects.glShaderSourceARB(_fragmentShaderId, fragmentShader);
    ARBShaderObjects.glCompileShaderARB(_fragmentShaderId);
    System.out.println("FragmentShader Info: " + ARBShaderObjects.glGetInfoLogARB(_fragmentShaderId, 8192));

    _programId = ARBShaderObjects.glCreateProgramObjectARB();
    ARBShaderObjects.glAttachObjectARB(_programId, _vertexShaderId);
    ARBShaderObjects.glAttachObjectARB(_programId, _fragmentShaderId);
    ARBShaderObjects.glLinkProgramARB(_programId);
    System.out.println("Program Info: " + ARBShaderObjects.glGetInfoLogARB(_programId, 8192));
}

From source file:fox.spiteful.ridiculous.client.shaders.ShaderHelper.java

License:Creative Commons License

private static int createShader(String filename, int shaderType) {
    int shader = 0;
    try {//ww  w  . java2  s.  co m
        shader = ARBShaderObjects.glCreateShaderObjectARB(shaderType);
        if (shader == 0)
            return 0;
        ARBShaderObjects.glShaderSourceARB(shader, readFileAsString(filename));
        ARBShaderObjects.glCompileShaderARB(shader);
        if (ARBShaderObjects.glGetObjectParameteriARB(shader,
                ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE)
            throw new RuntimeException("Error creating shader: " + getLogInfo(shader));
        return shader;
    } catch (Exception e) {
        ARBShaderObjects.glDeleteObjectARB(shader);
        e.printStackTrace();
        return -1;
    }
}

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

License:GNU General Public License

/**
 * Fetches a shader id for a given fragment shader, generating
 * a new id if necessary/*w w  w .j  a  v  a  2s. co  m*/
 * @param fragmentShaderFilePath The path to the fragment shader
 * @returns shaderID for a given fragment shader
 */
public int getFragmentShaderID(String fragmentShaderFilePath) throws Exception {
    Integer id = shaderMap.get(fragmentShaderFilePath);
    if (id == null) {
        if (has_opengl2) {
            id = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER);
            GL20.glShaderSource(id, getProgramCode(fragmentShaderFilePath));
            GL20.glCompileShader(id);
            shaderMap.put(fragmentShaderFilePath, id);
        } else if (has_arb) {
            id = ARBShaderObjects.glCreateShaderObjectARB(ARBFragmentShader.GL_FRAGMENT_SHADER_ARB);
            ARBShaderObjects.glShaderSourceARB(id, getProgramCode(fragmentShaderFilePath));
            ARBShaderObjects.glCompileShaderARB(id);
            shaderMap.put(fragmentShaderFilePath, id);
        }
        StringBuilder errorMessage = new StringBuilder();
        //Check for errors with shader
        if (!compiledSuccessfully(id)) {
            errorMessage.append("Fragment Shader ");
            errorMessage.append(fragmentShaderFilePath);
            errorMessage.append(" failed to compile.\n");
            errorMessage.append(getShaderInfoLog(id));
            errorMessage.append("\n\n");
            errorMessage.insert(0, "Could not compile shader.\n");
            throw new Exception(errorMessage.toString());
        }
    }
    return id;
}