LWJGL, имеющий 2 шейдерных программы в одном классе шейдеров, связывает только 1 шейдер - PullRequest
0 голосов
/ 25 октября 2018

Я работаю над классом шейдеров, в котором мне нужно загрузить 2 шейдерные программы.(один для текстур и один без текстур).У меня есть шейдер, который загружен без текстур, чтобы связать, но тот, что для текстур, не связывает.Вот мой метод загрузки шейдеров для двух файлов шейдеров:

public void setupShader(String subPathBasic, String vertexFileBasic, String fragmentFileBasic, String subPathTextured) {
        this.vertexFileBasic = vertexFileBasic;
        this.fragmentFileBasic = fragmentFileBasic;
        this.vertexFileTextured = vertexFileBasic;
        this.fragmentFileTextured = fragmentFileBasic;
        //Get the ID's
        if(!getFileExtention(vertexFileBasic).equals("vs")) {
            ExceptionThrower.throwException(new ShaderIncompatableException(vertexFileBasic));
        }
        if(!getFileExtention(fragmentFileBasic).equals("fs")) {
            ExceptionThrower.throwException(new ShaderIncompatableException(fragmentFileBasic));
        }
        if(!getFileExtention(vertexFileTextured).equals("vs")) {
            ExceptionThrower.throwException(new ShaderIncompatableException(vertexFileTextured));
        }
        if(!getFileExtention(fragmentFileTextured).equals("fs")) {
            ExceptionThrower.throwException(new ShaderIncompatableException(fragmentFileTextured));
        }
        vertexShaderIDBasic = loadShader(this.vertexFileBasic, GL20.GL_VERTEX_SHADER, subPathBasic);
        fragmentShaderIDBasic = loadShader(this.fragmentFileBasic, GL20.GL_FRAGMENT_SHADER, subPathBasic);
        programIDBasic = GL20.glCreateProgram();

        vertexShaderIDTextured = loadShader(this.vertexFileTextured, GL20.GL_VERTEX_SHADER, subPathTextured);
        fragmentShaderIDTextured = loadShader(this.fragmentFileTextured, GL20.GL_FRAGMENT_SHADER, subPathTextured);
        programIDTextured = GL20.glCreateProgram();
        // attach shaders to program
        GL20.glAttachShader(programIDBasic, vertexShaderIDBasic);
        GL20.glAttachShader(programIDBasic, fragmentShaderIDBasic);

        GL20.glAttachShader(programIDTextured, vertexShaderIDTextured);
        GL20.glAttachShader(programIDTextured, fragmentShaderIDTextured);
        // Link the program.
        bindAttributes();
        GL20.glLinkProgram(programIDBasic);
        GL20.glLinkProgram(programIDTextured);
        // Validate the program. 
        GL20.glValidateProgram(programIDBasic);
        GL20.glValidateProgram(programIDTextured);

        getAllUniformLocations();

        int linkStatusBasic = GL20.glGetProgrami(programIDBasic, GL20.GL_LINK_STATUS);
        System.out.println("         Link status 1:   " + toString() + " : " +  linkStatusBasic);
        if(OptionHandler.getProperty(EngineOptions.DEBUGENABLED_KEY, OptionHandler.ENGINE_OPTION_ID).equals("true")) {
            System.out.println("         Loaded shader 1: " + toString() + " from subfolder: " + subPathBasic);
        }
        int linkStatusTextured = GL20.glGetProgrami(programIDTextured, GL20.GL_LINK_STATUS);
        System.out.println("         Link status 2:   " + toString() + " : " +  linkStatusTextured);
        if(OptionHandler.getProperty(EngineOptions.DEBUGENABLED_KEY, OptionHandler.ENGINE_OPTION_ID).equals("true")) {
            System.out.println("         Loaded shader 2: " + toString() + " from subfolder: " + subPathTextured);
        }

    }

protected static int loadShader(String file, int type, String subPath){
        //create a string builder.
        StringBuilder shaderSource = new StringBuilder();
        //read the file and store in shaderSource.
        try{
            BufferedReader reader = new BufferedReader(new FileReader(OptionHandler.getProperty(EngineOptions.PATHSHADERFILES_KEY, OptionHandler.ENGINE_OPTION_ID) + subPath + file));
            String line;
            while((line = reader.readLine())!=null){
                shaderSource.append(line).append("//\n");
            }
            reader.close();
        }catch(IOException e){
            System.out.println(OptionHandler.getProperty(EngineOptions.PATHSHADERFILES_KEY, OptionHandler.ENGINE_OPTION_ID) + subPath + file);
            ExceptionThrower.throwException(new InternalErrorException());
        }
        //get shader ID.
        int shaderID = GL20.glCreateShader(type);
        //create shader from source.
        GL20.glShaderSource(shaderID, shaderSource);
        //compile shader.
        GL20.glCompileShader(shaderID);
        //check for errors.
        if(GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS )== GL11.GL_FALSE){
            System.err.println("[ERROR]: Could not compile shader: " + file);
            System.out.println(GL20.glGetShaderInfoLog(shaderID, 500));
            ExceptionThrower.throwException(new InternalErrorException());
        }
        //Return shader ID.
        return shaderID;
}

Я печатаю вывод, который выглядит примерно так:

 Link status 1:   [vertexFile=VI.vs, fragmentFile=VI.fs] : 1
 Loaded shader 1: [vertexFile=VI.vs, fragmentFile=VI.fs] from subfolder: EntityShader/
 Link status 2:   [vertexFile=VI.vs, fragmentFile=VI.fs] : 0
 Loaded shader 2: [vertexFile=VI.vs, fragmentFile=VI.fs] from subfolder: TexturedEntityShader/

Что может быть причиной связывания 1 шейдераа другой, который загружается таким же образом, чтобы не ссылаться?

...