Пример #1
0
  private boolean initProgram(GL4 gl4) {

    boolean validated = true;

    try {

      if (validated) {

        String[] vertexSourceContent =
            new String[] {
              new Scanner(new File(SHADERS_ROOT + "/" + SHADERS_SOURCE + ".vert"))
                  .useDelimiter("\\A")
                  .next()
            };
        programName[Program.VERT.ordinal()] =
            gl4.glCreateShaderProgramv(GL_VERTEX_SHADER, 1, vertexSourceContent);
      }

      if (validated) {

        String[] fragmentSourceContent =
            new String[] {
              new Scanner(new File(SHADERS_ROOT + "/" + SHADERS_SOURCE + ".frag"))
                  .useDelimiter("\\A")
                  .next()
            };
        programName[Program.FRAG.ordinal()] =
            gl4.glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, fragmentSourceContent);
      }

      if (validated) {

        validated = validated && checkProgram(gl4, programName[Program.VERT.ordinal()]);
        validated = validated && checkProgram(gl4, programName[Program.FRAG.ordinal()]);
      }

      if (validated) {

        uniformMvp = gl4.glGetUniformLocation(programName[Program.VERT.ordinal()], "mvp");
        uniformDiffuse = gl4.glGetUniformLocation(programName[Program.FRAG.ordinal()], "diffuse");
      }

      if (validated) {

        gl4.glGenProgramPipelines(1, pipelineName, 0);
        gl4.glBindProgramPipeline(pipelineName[0]);
        gl4.glUseProgramStages(
            pipelineName[0], GL_VERTEX_SHADER_BIT, programName[Program.VERT.ordinal()]);
        gl4.glUseProgramStages(
            pipelineName[0], GL_FRAGMENT_SHADER_BIT, programName[Program.FRAG.ordinal()]);
      }

    } catch (FileNotFoundException ex) {
      Logger.getLogger(Gl_410_program_64.class.getName()).log(Level.SEVERE, null, ex);
    }

    return validated && checkError(gl4, "initProgram");
  }
  private boolean initProgram(GL4 gl4) {

    boolean validated = true;

    // Create program
    if (validated) {

      ShaderCode vertShaderCode =
          ShaderCode.create(
              gl4,
              GL_VERTEX_SHADER,
              this.getClass(),
              SHADERS_ROOT,
              null,
              SHADERS_SOURCE,
              "vert",
              null,
              true);
      ShaderCode fragShaderCode =
          ShaderCode.create(
              gl4,
              GL_FRAGMENT_SHADER,
              this.getClass(),
              SHADERS_ROOT,
              null,
              SHADERS_SOURCE,
              "frag",
              null,
              true);

      ShaderProgram shaderProgram = new ShaderProgram();
      shaderProgram.init(gl4);
      programName[Program.VERTEX] = shaderProgram.program();
      gl4.glProgramParameteri(programName[Program.VERTEX], GL_PROGRAM_SEPARABLE, GL_TRUE);
      shaderProgram.add(vertShaderCode);
      shaderProgram.link(gl4, System.out);

      shaderProgram = new ShaderProgram();
      shaderProgram.init(gl4);
      programName[Program.FRAGMENT] = shaderProgram.program();
      gl4.glProgramParameteri(programName[Program.FRAGMENT], GL_PROGRAM_SEPARABLE, GL_TRUE);
      shaderProgram.add(fragShaderCode);
      shaderProgram.link(gl4, System.out);
    }

    if (validated) {

      gl4.glGenProgramPipelines(1, pipelineName);
      gl4.glUseProgramStages(
          pipelineName.get(0), GL_VERTEX_SHADER_BIT, programName[Program.VERTEX]);
      gl4.glUseProgramStages(
          pipelineName.get(0), GL_FRAGMENT_SHADER_BIT, programName[Program.FRAGMENT]);
    }

    return validated & checkError(gl4, "initProgram");
  }