コード例 #1
0
ファイル: Shaders.java プロジェクト: semfreak/mcpatcher
  private static int createVertShader(String filename) {
    int vertShader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
    if (vertShader == 0) {
      return 0;
    }
    String vertexCode = "";
    String line;

    BufferedReader reader;
    try {
      reader =
          new BufferedReader(new InputStreamReader((Shaders.class).getResourceAsStream(filename)));
    } catch (Exception e) {
      try {
        reader = new BufferedReader(new FileReader(new File(filename)));
      } catch (Exception e2) {
        System.out.println("Couldn't open " + filename + "!");
        glDeleteObjectARB(vertShader);
        return 0;
      }
    }

    try {
      while ((line = reader.readLine()) != null) {
        vertexCode += line + "\n";
        if (line.matches("attribute [_a-zA-Z0-9]+ mc_Entity.*")) {
          entityAttrib = 10;
        }
      }
    } catch (Exception e) {
      System.out.println("Couldn't read " + filename + "!");
      glDeleteObjectARB(vertShader);
      return 0;
    }

    glShaderSourceARB(vertShader, vertexCode);
    glCompileShaderARB(vertShader);
    printLogInfo(vertShader);
    return vertShader;
  }
コード例 #2
0
ファイル: Shaders.java プロジェクト: semfreak/mcpatcher
  private static int createFragShader(String filename) {
    int fragShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
    if (fragShader == 0) {
      return 0;
    }
    String fragCode = "";
    String line;

    BufferedReader reader;
    try {
      reader =
          new BufferedReader(new InputStreamReader((Shaders.class).getResourceAsStream(filename)));
    } catch (Exception e) {
      try {
        reader = new BufferedReader(new FileReader(new File(filename)));
      } catch (Exception e2) {
        System.out.println("Couldn't open " + filename + "!");
        glDeleteObjectARB(fragShader);
        return 0;
      }
    }

    try {
      while ((line = reader.readLine()) != null) {
        fragCode += line + "\n";
        if (colorAttachments < 5 && line.matches("uniform [ _a-zA-Z0-9]+ gaux1;.*")) {
          colorAttachments = 5;
        } else if (colorAttachments < 6 && line.matches("uniform [ _a-zA-Z0-9]+ gaux2;.*")) {
          colorAttachments = 6;
        } else if (colorAttachments < 7 && line.matches("uniform [ _a-zA-Z0-9]+ gaux3;.*")) {
          colorAttachments = 7;
        } else if (colorAttachments < 8 && line.matches("uniform [ _a-zA-Z0-9]+ shadow;.*")) {
          shadowPassInterval = 1;
          colorAttachments = 8;
        } else if (line.matches("/\\* SHADOWRES:[0-9]+ \\*/.*")) {
          String[] parts = line.split("(:| )", 4);
          System.out.println("Shadow map resolution: " + parts[2]);
          shadowMapWidth = shadowMapHeight = Integer.parseInt(parts[2]);
        } else if (line.matches("/\\* SHADOWFOV:[0-9\\.]+ \\*/.*")) {
          String[] parts = line.split("(:| )", 4);
          System.out.println("Shadow map field of view: " + parts[2]);
          shadowMapFOV = Float.parseFloat(parts[2]);
          shadowMapIsOrtho = false;
        } else if (line.matches("/\\* SHADOWHPL:[0-9\\.]+ \\*/.*")) {
          String[] parts = line.split("(:| )", 4);
          System.out.println("Shadow map half-plane: " + parts[2]);
          shadowMapHalfPlane = Float.parseFloat(parts[2]);
          shadowMapIsOrtho = true;
        }
      }
    } catch (Exception e) {
      System.out.println("Couldn't read " + filename + "!");
      glDeleteObjectARB(fragShader);
      return 0;
    }

    glShaderSourceARB(fragShader, fragCode);
    glCompileShaderARB(fragShader);
    printLogInfo(fragShader);
    return fragShader;
  }