aboutsummaryrefslogtreecommitdiffstats
path: root/make/gl-impl-CustomJavaCode-gl2_es2.java
blob: dcc86eb2044e41c7b844db1a70179924fb5cb06d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74


  public void glShaderSource(int shader, java.lang.String[] source)
  {
    int count = (null!=source)?source.length:0;
    if(count<=0) {
        throw new GLException("Method \"glShaderSource\" called with invalid length of source: "+count);
    }
    int[] length = new int[count];
    for(int i=0; i<count; i++) {
        length[i]=source[i].length();
    }
    glShaderSource(shader, count, source, length, 0);
  }

  public void glShaderSource(IntBuffer shaders, java.lang.String[][] sources)
  {
    int sourceNum = (null!=sources)?sources.length:0;
    int shaderNum = (null!=shaders)?shaders.limit():0;
    if(shaderNum<=0 || sourceNum<=0 || shaderNum!=sourceNum) {
        throw new GLException("Method \"glShaderSource\" called with invalid number of shaders and/or sources: shaders="+
            shaderNum+", sources="+sourceNum);
    }
    for(int i=0; i<sourceNum; i++) {
        glShaderSource(shaders.get(i), sources[i]);
    }
  }

  public void glShaderBinary(IntBuffer shaders, int binFormat, java.nio.Buffer bin)
  {
    int shaderNum = shaders.limit();
    if(shaderNum<=0) {
        throw new GLException("Method \"glShaderBinary\" called with shaders number <= 0");
    }
    if(null==bin) {
        throw new GLException("Method \"glShaderBinary\" without binary (null)");
    }
    int binLength = bin.limit();
    if(0>=binLength) {
        throw new GLException("Method \"glShaderBinary\" without binary (limit == 0)");
    }
    try {
        glShaderBinary(shaderNum, shaders, binFormat, bin, binLength);
    } catch (Exception e) { }
  }

  /**
   * Wrapper for glShaderBinary and glShaderSource.
   * Tries binary first, if not null, then the source code, if not null.
   * The binary trial will fail in case no binary interface exist (GL2 profile),
   * hence the fallback to the source code.
   */
  public void glShaderBinaryOrSource(IntBuffer shaders, 
                                     int binFormat, java.nio.Buffer bin,
                                     java.lang.String[][] sources)
  {
    int shaderNum = shaders.limit();
    if(shaderNum<=0) {
        throw new GLException("Method \"glShaderBinaryOrSource\" called with shaders number <= 0");
    }
    if(null!=bin) {
        try {
            glShaderBinary(shaders, binFormat, bin);
            return; // done
        } catch (Exception e) { }
    }
    if(null!=sources) {
        glShaderSource(shaders, sources);
        return; // done
    }
    throw new GLException("Method \"glShaderBinaryOrSource\" without binary nor source");
  }