ARB vertex buffer object

Started by kramer, September 14, 2003, 04:49:35

Previous topic - Next topic

kramer

Hi All,

I've been lurking around for the past few months just learning the API and developing my OpenGL skills building the obligatory terrain engine.  I now want to speed it up a bit and am trying to use the ARB_vertex_buffer_objects.  I'm just trying to get a simple example that works initially but am having no luck.

I'm using:
lwjgl0.7,
Detonator 45.23 on Geforce 4 TI 4400
Win2k


// in declarations:
    private static IntBuffer buf;
    private static int data[] = { -1, 1, 0,
                               -1, -1, 0,
                                1, -1, 0 };

// in the init:
        GL.glEnableClientState(GL.GL_VERTEX_ARRAY);
        buf = ByteBuffer.allocateDirect(9*4).order(ByteOrder.nativeOrder()).asIntBuffer().put(data);
        GL.glGenBuffersARB(buf);
        GL.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, buf.get(0));
    GL.glBufferDataARB(GL.GL_ARRAY_BUFFER_ARB, 9*4, buf, GL.GL_STATIC_DRAW_ARB);    

// in the render loop:
        GL.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, buf.get(0));
   GL.glVertexPointer(3, 0, buf);      
   GL.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 3);



I get the following when i try to run it:

Setting display mode to 640 x 480 x 16 @75Hz
Created display.
Created OpenGL.
Timer resolution: 1193182
Number of texture units: 4
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x0
Function=[Unknown.]
Library=(N/A)
NOTE: We are unable to locate the function name symbol for the error
     just occurred. Please refer to release documentation for possible
     reason and solutions.
Current Java thread:
       at org.lwjgl.opengl.GL.nglGenBuffersARB(Native Method)
       at org.lwjgl.opengl.GL.glGenBuffersARB(GL.java:1511)
       at viewer.Test3.init(Test3.java:203)
       at viewer.Test3.main(Test3.java:106)
Dynamic libraries:
0x00400000 - 0x00406000         D:\j2sdk1.4.0\jre\bin\java.exe
0x77F80000 - 0x77FF9000         C:\WINNT\System32\ntdll.dll
0x77DB0000 - 0x77E0A000         C:\WINNT\system32\ADVAPI32.dll
0x77E80000 - 0x77F36000         C:\WINNT\system32\KERNEL32.DLL
0x77D40000 - 0x77DAF000         C:\WINNT\system32\RPCRT4.DLL
0x78000000 - 0x78046000         C:\WINNT\system32\MSVCRT.dll
0x6D330000 - 0x6D442000         D:\j2sdk1.4.0\jre\bin\client\jvm.dll
0x77E10000 - 0x77E75000         C:\WINNT\system32\USER32.dll
0x77F40000 - 0x77F7C000         C:\WINNT\system32\GDI32.DLL
0x77570000 - 0x775A0000         C:\WINNT\System32\WINMM.dll
0x6D1D0000 - 0x6D1D7000         D:\j2sdk1.4.0\jre\bin\hpi.dll
0x6D300000 - 0x6D30D000         D:\j2sdk1.4.0\jre\bin\verify.dll
0x6D210000 - 0x6D228000         D:\j2sdk1.4.0\jre\bin\java.dll
0x6D320000 - 0x6D32D000         D:\j2sdk1.4.0\jre\bin\zip.dll
0x10000000 - 0x10043000         D:\lwjgl-0.7\lwjgl.dll
0x5F580000 - 0x5F620000         C:\WINNT\System32\DINPUT.dll
0x69510000 - 0x695D7000         C:\WINNT\System32\OPENGL32.dll
0x6FAC0000 - 0x6FADF000         C:\WINNT\System32\GLU32.dll
0x51000000 - 0x5104D000         C:\WINNT\System32\DDRAW.dll
0x728A0000 - 0x728A6000         C:\WINNT\System32\DCIMAN32.dll
0x6E420000 - 0x6E426000         C:\WINNT\System32\INDICDLL.dll
0x75E60000 - 0x75E7A000         C:\WINNT\System32\IMM32.dll
0x6F9A0000 - 0x6F9A7000         C:\WINNT\System32\HID.DLL
0x77890000 - 0x7791D000         C:\WINNT\System32\SETUPAPI.DLL
0x77C10000 - 0x77C6D000         C:\WINNT\System32\USERENV.DLL
0x77B50000 - 0x77BDA000         C:\WINNT\system32\COMCTL32.dll
0x17FE0000 - 0x18342000         C:\WINNT\System32\nvoglnt.dll
0x77920000 - 0x77942000         C:\WINNT\system32\imagehlp.dll
0x72A00000 - 0x72A2D000         C:\WINNT\system32\DBGHELP.dll
0x690A0000 - 0x690AB000         C:\WINNT\System32\PSAPI.DLL
Local Time = Sun Sep 14 14:43:53 2003
Elapsed Time = 4
#
# The exception above was detected in native code outside the VM
#
# Java VM: Java HotSpot(TM) Client VM (1.4.0-b92 mixed mode)
#
# An error report file has been saved as hs_err_pid1400.log.
# Please refer to the file for further information.
#



Thanks to anyone who can help me with this...
Kramer

elias

Be very careful with LWJGL 0.7 - it uses the current postiion() of buffers, not just the base address. That means that

buf = ByteBuffer.allocateDirect(9*4).order(ByteOrder.nativeOrder()).asIntBuffer().put(data);
GL.glGenBuffersARB(buf);

is wrong, because the put(data) will position the buffer after the last element. The fix is:

buf = ByteBuffer.allocateDirect(9*4).order(ByteOrder.nativeOrder()).asIntBuffer().put(data);
buf.flip();
GL.glGenBuffersARB(buf);

In the future, LWJGL might check for these conditions.

EDIT: Thinking about it again tells me that that fix won't fix your problem after all. The fix is correct, but without it, gl will just allocate 0 buffers and won't reference your buffer, which shouldn't result in an access violation. So, are you sure your driver includes the ARB_vbo extension?

- elias

kramer

Thanks for getting back to me so quick elias.

That little buf.flip() actually helped me get a result with another problem i was having trying to get plain vertex arrays working. Thanks.

As you expected, it didn't help with the vertex buffer objects... I am using the latest Nvidia driver, and apparently ARB_vertex_buffer_object was made official in Feburary this year, so I'm *assuming* that it supports it.

elias

Don't assume :-)

Either check your extensions string or the GLcaps.ARB_vertex_buffer_object boolean. But IIRC, the newer Nvidia drivers does indeed support vertex buffer objects, so I'm not sure what goes wrong there. Does "VBOTest" from the LWJGL examples work for you?

- elias

kramer

Nope, VBOTest tells me it's not supported... so I guess NVidia's latest driver doesn't support it... I wonder if or when they will put it in.

kramer

Well, I ended up getting the 51.75 *beta* Detonator driver and ARB VBO is supported on it... so if anyone is running detonator 45.xx, then you  probably won't be able to use ARB vertex buffer objects.

princec

You ought to consider VAR and ATI Buffer Object support too, which will be available on a much greater number of machines.

And don't forget to use glDrawRangeElements.

And don't use glLockArraysEXT, which is broken on so many drivers.

Cas :)