2004-11-25 23:20:45 +01:00
/ *
2004-06-12 22:28:34 +02:00
* Copyright ( c ) 2002 - 2004 LWJGL Project
2004-03-29 18:55:27 +02:00
* All rights reserved .
2004-11-25 23:20:45 +01:00
*
2004-03-29 18:55:27 +02:00
* Redistribution and use in source and binary forms , with or without
2004-11-25 23:20:45 +01:00
* modification , are permitted provided that the following conditions are
2004-03-29 18:55:27 +02:00
* met :
2004-11-25 23:20:45 +01:00
*
* * Redistributions of source code must retain the above copyright
2004-03-29 18:55:27 +02:00
* notice , this list of conditions and the following disclaimer .
*
* * Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
*
2004-11-25 23:20:45 +01:00
* * Neither the name of ' LWJGL ' nor the names of
* its contributors may be used to endorse or promote products derived
2004-03-29 18:55:27 +02:00
* from this software without specific prior written permission .
2004-11-25 23:20:45 +01:00
*
2004-03-29 18:55:27 +02:00
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* " AS IS " AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED
* TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2004-11-25 23:20:45 +01:00
* PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL ,
* EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED TO ,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR
2004-03-29 18:55:27 +02:00
* PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF
2004-11-25 23:20:45 +01:00
* LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING
2004-03-29 18:55:27 +02:00
* NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
* /
package org.lwjgl.opengl ;
2004-07-29 13:20:43 +02:00
import org.lwjgl.BufferChecks ;
2005-01-13 03:17:42 +01:00
import org.lwjgl.LWJGLException ;
import java.nio.* ;
2004-07-04 15:14:06 +02:00
2004-07-31 11:34:09 +02:00
public abstract class ARBBufferObject {
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
/ *
* Accepted by the < usage > parameter of BufferDataARB :
* /
2004-11-25 23:20:45 +01:00
public static final int GL_STREAM_DRAW_ARB = 0x88E0 ;
public static final int GL_STREAM_READ_ARB = 0x88E1 ;
public static final int GL_STREAM_COPY_ARB = 0x88E2 ;
public static final int GL_STATIC_DRAW_ARB = 0x88E4 ;
public static final int GL_STATIC_READ_ARB = 0x88E5 ;
public static final int GL_STATIC_COPY_ARB = 0x88E6 ;
public static final int GL_DYNAMIC_DRAW_ARB = 0x88E8 ;
public static final int GL_DYNAMIC_READ_ARB = 0x88E9 ;
public static final int GL_DYNAMIC_COPY_ARB = 0x88EA ;
2004-03-29 18:55:27 +02:00
/ *
* Accepted by the < access > parameter of MapBufferARB :
* /
2004-11-25 23:20:45 +01:00
public static final int GL_READ_ONLY_ARB = 0x88B8 ;
public static final int GL_WRITE_ONLY_ARB = 0x88B9 ;
public static final int GL_READ_WRITE_ARB = 0x88BA ;
2004-03-29 18:55:27 +02:00
/ *
* Accepted by the < pname > parameter of GetBufferParameterivARB :
* /
2004-11-25 23:20:45 +01:00
public static final int GL_BUFFER_SIZE_ARB = 0x8764 ;
public static final int GL_BUFFER_USAGE_ARB = 0x8765 ;
public static final int GL_BUFFER_ACCESS_ARB = 0x88BB ;
public static final int GL_BUFFER_MAPPED_ARB = 0x88BC ;
public static final int GL_BUFFER_MAP_POINTER_ARB = 0x88BD ;
2004-03-29 18:55:27 +02:00
2004-07-04 15:14:06 +02:00
static native void initNativeStubs ( ) throws LWJGLException ;
2004-07-03 23:12:33 +02:00
2004-03-29 18:55:27 +02:00
public static void glBindBufferARB ( int target , int buffer ) {
2004-11-25 23:20:45 +01:00
switch ( target ) {
2005-01-13 03:17:42 +01:00
case ARBVertexBufferObject . GL_ARRAY_BUFFER_ARB :
2005-01-13 21:32:31 +01:00
BufferObjectTracker . getVBOArrayStack ( ) . setState ( buffer ) ;
2005-01-13 03:17:42 +01:00
break ;
2004-03-29 18:55:27 +02:00
case ARBVertexBufferObject . GL_ELEMENT_ARRAY_BUFFER_ARB :
2005-01-13 21:32:31 +01:00
BufferObjectTracker . getVBOElementStack ( ) . setState ( buffer ) ;
2004-03-29 18:55:27 +02:00
break ;
2005-01-13 03:17:42 +01:00
case ARBPixelBufferObject . GL_PIXEL_PACK_BUFFER_ARB :
2005-01-13 21:32:31 +01:00
BufferObjectTracker . getPBOPackStack ( ) . setState ( buffer ) ;
2005-01-13 03:17:42 +01:00
break ;
case ARBPixelBufferObject . GL_PIXEL_UNPACK_BUFFER_ARB :
2005-01-13 21:32:31 +01:00
BufferObjectTracker . getPBOUnpackStack ( ) . setState ( buffer ) ;
2004-03-29 18:55:27 +02:00
break ;
2004-11-25 23:20:45 +01:00
default :
throw new IllegalArgumentException ( " Unsupported VBO target " + target ) ;
2004-03-29 18:55:27 +02:00
}
nglBindBufferARB ( target , buffer ) ;
}
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
private static native void nglBindBufferARB ( int target , int buffer ) ;
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
public static void glDeleteBuffersARB ( IntBuffer buffers ) {
2004-11-25 23:20:45 +01:00
for ( int i = buffers . position ( ) ; i < buffers . limit ( ) ; i + + ) {
2004-03-29 18:55:27 +02:00
int buffer_handle = buffers . get ( i ) ;
2005-01-13 21:32:31 +01:00
if ( BufferObjectTracker . getVBOArrayStack ( ) . getState ( ) = = buffer_handle )
BufferObjectTracker . getVBOArrayStack ( ) . setState ( 0 ) ;
if ( BufferObjectTracker . getVBOElementStack ( ) . getState ( ) = = buffer_handle )
BufferObjectTracker . getVBOElementStack ( ) . setState ( 0 ) ;
if ( BufferObjectTracker . getPBOPackStack ( ) . getState ( ) = = buffer_handle )
BufferObjectTracker . getPBOPackStack ( ) . setState ( 0 ) ;
if ( BufferObjectTracker . getPBOUnpackStack ( ) . getState ( ) = = buffer_handle )
BufferObjectTracker . getPBOUnpackStack ( ) . setState ( 0 ) ;
2004-03-29 18:55:27 +02:00
}
2004-07-26 15:36:04 +02:00
BufferChecks . checkDirect ( buffers ) ;
2004-03-29 18:55:27 +02:00
nglDeleteBuffersARB ( buffers . remaining ( ) , buffers , buffers . position ( ) ) ;
}
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
private static native void nglDeleteBuffersARB ( int n , IntBuffer buffers , int buffers_offset ) ;
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
public static void glGenBuffersARB ( IntBuffer buffers ) {
2004-07-26 15:36:04 +02:00
BufferChecks . checkDirect ( buffers ) ;
2004-03-29 18:55:27 +02:00
nglGenBuffersARB ( buffers . remaining ( ) , buffers , buffers . position ( ) ) ;
}
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
private static native void nglGenBuffersARB ( int n , IntBuffer buffers , int buffers_offset ) ;
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
public static native boolean glIsBufferARB ( int buffer ) ;
2004-11-25 23:20:45 +01:00
2005-01-30 00:13:00 +01:00
public static void glBufferDataARB ( int target , int size , int usage ) {
nglBufferDataARB ( target , size , null , 0 , usage ) ;
2004-03-29 18:55:27 +02:00
}
2004-11-25 23:20:45 +01:00
2005-01-30 00:13:00 +01:00
public static void glBufferDataARB ( int target , ByteBuffer data , int usage ) {
BufferChecks . checkDirect ( data ) ;
nglBufferDataARB ( target , data . remaining ( ) , data , data . position ( ) , usage ) ;
}
public static void glBufferDataARB ( int target , ShortBuffer data , int usage ) {
BufferChecks . checkDirect ( data ) ;
nglBufferDataARB ( target , data . remaining ( ) < < 1 , data , data . position ( ) < < 1 , usage ) ;
2004-03-29 18:55:27 +02:00
}
2004-11-25 23:20:45 +01:00
2005-01-30 00:13:00 +01:00
public static void glBufferDataARB ( int target , FloatBuffer data , int usage ) {
2004-07-26 15:36:04 +02:00
BufferChecks . checkDirectOrNull ( data ) ;
2005-01-30 00:13:00 +01:00
nglBufferDataARB ( target , data . remaining ( ) < < 2 , data , data . position ( ) < < 2 , usage ) ;
2004-03-29 18:55:27 +02:00
}
2004-11-25 23:20:45 +01:00
2005-01-30 00:13:00 +01:00
public static void glBufferDataARB ( int target , IntBuffer data , int usage ) {
2004-07-26 15:36:04 +02:00
BufferChecks . checkDirectOrNull ( data ) ;
2005-01-30 00:13:00 +01:00
nglBufferDataARB ( target , data . remaining ( ) < < 2 , data , data . position ( ) < < 2 , usage ) ;
2004-03-29 18:55:27 +02:00
}
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
private static native void nglBufferDataARB ( int target , int size , Buffer data , int data_offset , int usage ) ;
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
public static void glBufferSubDataARB ( int target , int offset , ByteBuffer data ) {
2004-07-26 15:36:04 +02:00
BufferChecks . checkDirect ( data ) ;
2004-03-29 18:55:27 +02:00
nglBufferSubDataARB ( target , offset , data . remaining ( ) , data , data . position ( ) ) ;
}
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
public static void glBufferSubDataARB ( int target , int offset , ShortBuffer data ) {
2004-07-26 15:36:04 +02:00
BufferChecks . checkDirect ( data ) ;
2004-11-25 23:20:45 +01:00
nglBufferSubDataARB ( target , offset , data . remaining ( ) < < 1 , data , data . position ( ) < < 1 ) ;
2004-03-29 18:55:27 +02:00
}
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
public static void glBufferSubDataARB ( int target , int offset , FloatBuffer data ) {
2004-07-26 15:36:04 +02:00
BufferChecks . checkDirect ( data ) ;
2004-11-25 23:20:45 +01:00
nglBufferSubDataARB ( target , offset , data . remaining ( ) < < 2 , data , data . position ( ) < < 2 ) ;
2004-03-29 18:55:27 +02:00
}
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
public static void glBufferSubDataARB ( int target , int offset , IntBuffer data ) {
2004-07-26 15:36:04 +02:00
BufferChecks . checkDirect ( data ) ;
2004-11-25 23:20:45 +01:00
nglBufferSubDataARB ( target , offset , data . remaining ( ) < < 2 , data , data . position ( ) < < 2 ) ;
2004-03-29 18:55:27 +02:00
}
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
private static native void nglBufferSubDataARB ( int target , int offset , int size , Buffer data , int data_offset ) ;
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
public static void glGetBufferSubDataARB ( int target , int offset , ByteBuffer data ) {
2004-07-26 15:36:04 +02:00
BufferChecks . checkDirect ( data ) ;
2004-03-29 18:55:27 +02:00
nglGetBufferSubDataARB ( target , offset , data . remaining ( ) , data , data . position ( ) ) ;
}
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
public static void glGetBufferSubDataARB ( int target , int offset , ShortBuffer data ) {
2004-07-26 15:36:04 +02:00
BufferChecks . checkDirect ( data ) ;
2004-11-25 23:20:45 +01:00
nglGetBufferSubDataARB ( target , offset , data . remaining ( ) < < 1 , data , data . position ( ) < < 1 ) ;
2004-03-29 18:55:27 +02:00
}
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
public static void glGetBufferSubDataARB ( int target , int offset , IntBuffer data ) {
2004-07-26 15:36:04 +02:00
BufferChecks . checkDirect ( data ) ;
2004-11-25 23:20:45 +01:00
nglGetBufferSubDataARB ( target , offset , data . remaining ( ) < < 2 , data , data . position ( ) < < 2 ) ;
2004-03-29 18:55:27 +02:00
}
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
public static void glGetBufferSubDataARB ( int target , int offset , FloatBuffer data ) {
2004-07-26 15:36:04 +02:00
BufferChecks . checkDirect ( data ) ;
2004-11-25 23:20:45 +01:00
nglGetBufferSubDataARB ( target , offset , data . remaining ( ) < < 2 , data , data . position ( ) < < 2 ) ;
2004-03-29 18:55:27 +02:00
}
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
private static native void nglGetBufferSubDataARB ( int target , int offset , int size , Buffer data , int data_offset ) ;
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
/ * *
2005-01-13 03:17:42 +01:00
* glMapBufferARB maps a gl vertex buffer buffer to a ByteBuffer . The oldBuffer argument can be null ,
* in which case a new ByteBuffer will be created , pointing to the returned memory . If oldBuffer is non - null ,
* it will be returned if it points to the same mapped memory , otherwise a new ByteBuffer is created . That
* way , an application will normally use glMapBufferARB like this :
2004-11-25 23:20:45 +01:00
* < p / >
* ByteBuffer mapped_buffer ; mapped_buffer = glMapBufferARB ( . . . , . . . , . . . , null ) ; . . . // Another map on the same buffer mapped_buffer = glMapBufferARB(..., ..., ..., mapped_buffer);
2004-03-29 18:55:27 +02:00
*
2004-11-25 23:20:45 +01:00
* @param size The size of the buffer area .
* @param oldBuffer A ByteBuffer . If this argument points to the same address as the new mapping , it will be returned and no new buffer will be created . In that case , size is ignored .
2004-03-29 18:55:27 +02:00
*
* @return A ByteBuffer representing the mapped buffer memory .
* /
public static native ByteBuffer glMapBufferARB ( int target , int access , int size , ByteBuffer oldBuffer ) ;
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
public static native boolean glUnmapBufferARB ( int target ) ;
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
public static void glGetBufferParameterARB ( int target , int pname , IntBuffer params ) {
BufferChecks . checkBuffer ( params ) ;
nglGetBufferParameterivARB ( target , pname , params , params . position ( ) ) ;
}
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
private static native void nglGetBufferParameterivARB ( int target , int pname , IntBuffer params , int params_offset ) ;
2004-11-25 23:20:45 +01:00
2004-03-29 18:55:27 +02:00
public static native ByteBuffer glGetBufferPointerARB ( int target , int pname , int size ) ;
}