aboutsummaryrefslogtreecommitdiffstats
path: root/C2J/manual/gl-manualCodedImplJNI1-14.java
blob: 0fc04ce6e671be8c5907c049acaadcc2f5f39e00 (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
/**
 * @(#) GLFunc14JauJNI.java
 */


package gl4java;

import java.nio.*;
import gl4java.utils.DirectBufferCleanup;

/**
 * The default implementation class for OpenGL native function mapping
 *
 * @version 	2.00, 21. April 1999
 * @author      Sven Goethel
 */
public class GLFunc14JauJNI
	implements GLFunc14 
{

  //----------------------------------------------------------------------
  // Special-case routines requiring hand coding
  //

  /** Access to the underlying wglAllocateMemoryNV or
      glXAllocateMemoryNV routine, if present. Presence of this
      routine can be queried by calling GLContext.gljTestGLProc with
      the argument "glAllocateMemoryNV". */
  public ByteBuffer glAllocateMemoryNV(int size,
                                       float readFreq,
                                       float writeFreq,
                                       float priority) {
    long address = glAllocateMemoryNV0(size, readFreq, writeFreq, priority);
    if (address == 0) {
      throw new OutOfMemoryError();
    }
    ByteBuffer buf = newDirectByteBuffer(address, size);
    registerForCleanup(this, buf);
    return buf;
  }
  
  /** This delegates to either wglAllocateMemoryNV or
      glXAllocateMemoryNV in the native code, depending on the window
      system */
  private native long glAllocateMemoryNV0(int size, float readFreq, float writeFreq, float priority);

  /** This delegates to either wglFreeMemoryNV or glXFreeMemoryNV in
      the native code, depending on the window system */
  private native void glFreeMemoryNV0(long addr);

  /** Allocate a direct byte buffer pointing at an arbitrary memory
      address -- must be hidden for security reasons */
  private native ByteBuffer newDirectByteBuffer(long addr, int capacity);

  private static volatile DirectBufferCleanup cleanup;
  private static synchronized void registerForCleanup(final GLFunc14JauJNI gl, Buffer buf) {
    if (cleanup == null) {
      cleanup = new DirectBufferCleanup(new DirectBufferCleanup.Callback() {
          public void cleanup(long addr) {
            gl.glFreeMemoryNV0(addr);
          }
        });
    }
    cleanup.register(buf);
  }

  //----------------------------------------------------------------------
  // All other routines below are autogenerated
  //