Hi,
I try to implement Vertex Buffer Objects, but get some troubles with it.
class Object{
private FloatBuffer tfb = null;
private ByteBuffer mapped_buffer = null;
private FloatBuffer mapped_float_buffer = null;
...
...
/**
* Initialize VBO
* t2 = Float Array
*/
tfb = ByteBuffer.allocateDirect(t2.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
tfb.put(t2).flip();
if ( !GLContext.getCapabilities().GL_ARB_vertex_buffer_object ) {
System.out.println("ARB VBO not supported!");
System.exit(1);
}
VertexBuffer.bufferData(VBO_ID, tfb);
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, VBO_ID);
GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);
}
public void renderVBO(){
// GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glPushMatrix();
ByteBuffer new_mapped_buffer = ARBBufferObject.glMapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB,
ARBBufferObject.GL_READ_ONLY_ARB,
tfb.capacity()*4,
mapped_buffer);
if ( new_mapped_buffer != mapped_buffer )
mapped_float_buffer = new_mapped_buffer.order(ByteOrder.nativeOrder()).asFloatBuffer();
mapped_buffer = new_mapped_buffer;
mapped_float_buffer.rewind();
tfb.rewind();
mapped_float_buffer.put(tfb);
if ( ARBBufferObject.glUnmapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB) ){
GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, tfb.capacity()/3);
}
GL11.glPopMatrix();
}
I used up some code from the demo. I can render one Object correct, when i initialize a second one the first Object Buffer will be overwriten or an EXCEPTION_ACCESS_VIOLATION will be fired...
Thanks.
Ok, when i comment this out, no more Exception will Fired there
// mapped_float_buffer.rewind();
// tfb.rewind();
Ah ea i STREAM the vbo... (maybe thats the Prob?)
Thats the VM Log
Quote#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x77c172e3, pid=3316, tid=236
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode)
# Problematic frame:
# C [MSVCRT.dll+0x372e3]
#
--------------- T H R E A D ---------------
Current thread (0x0accc780): JavaThread "AWT-EventQueue-0" [_thread_in_vm, id=236]
siginfo: ExceptionCode=0xc0000005, writing address 0x0b4fb000
Registers:
EAX=0x0fcb1000, EBX=0x06aff8c8, ECX=0x0001b400, EDX=0x00000000
ESP=0x0afbf608, EBP=0x0afbf610, ESI=0x0fc44000, EDI=0x0b4fb000
EIP=0x77c172e3, EFLAGS=0x00010212
Top of Stack: (sp=0x0afbf608)
0x0afbf608: 0accc780 0accc780 0afbf628 6d78443f
0x0afbf618: 0b4d8000 0fc21000 00090000 06aff8c8
0x0afbf628: 0afbf66c 00a7826f 0accc840 0afbf694
0x0afbf638: 0fc21000 00000000 0b4d8000 00000000
0x0afbf648: 00090000 00000000 0afbf650 00000000
0x0afbf658: 0afbf694 06b00d00 00000000 06aff8c8
0x0afbf668: 0afbf67c 0afbf6b4 00a72923 00000000
0x0afbf678: 00a76449 00090000 00000000 0b4d8000
Instructions: (pc=0x77c172e3)
0x77c172d3: 00 00 00 75 14 c1 e9 02 83 e2 03 83 f9 08 72 29
0x77c172e3: f3 a5 ff 24 95 f8 73 c1 77 8b c7 ba 03 00 00 00
Stack: [0x0af80000,0x0afc0000), sp=0x0afbf608, free space=253k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [MSVCRT.dll+0x372e3]
V [jvm.dll+0x11443f]
j sun.misc.Unsafe.copyMemory(JJJ)V+0
j java.nio.DirectFloatBufferU.put(Ljava/nio/FloatBuffer;)Ljava/nio/FloatBuffer;+157
j Nurb.NURBSObject.renderVBO()V+87
j GUI.Viewer.MainViewer.renderScene()V+35
j GUI.AWTOpenGLCanvas.paintGL()V+169
j org.lwjgl.opengl.AWTGLCanvas.paint(Ljava/awt/Graphics;)V+111
j org.lwjgl.opengl.AWTGLCanvas.update(Ljava/awt/Graphics;)V+2
j sun.awt.RepaintArea.updateComponent(Ljava/awt/Component;Ljava/awt/Graphics;)V+6
j sun.awt.RepaintArea.paint(Ljava/lang/Object;Z)V+263
j sun.awt.windows.WComponentPeer.handleEvent(Ljava/awt/AWTEvent;)V+63
j java.awt.Component.dispatchEventImpl(Ljava/awt/AWTEvent;)V+765
j java.awt.Component.dispatchEvent(Ljava/awt/AWTEvent;)V+2
j java.awt.EventQueue.dispatchEvent(Ljava/awt/AWTEvent;)V+46
j java.awt.EventDispatchThread.pumpOneEventForHierarchy(ILjava/awt/Component;)Z+233
j java.awt.EventDispatchThread.pumpEventsForHierarchy(ILjava/awt/Conditional;Ljava/awt/Component;)V+26
j java.awt.EventDispatchThread.pumpEvents(ILjava/awt/Conditional;)V+4
j java.awt.EventDispatchThread.pumpEvents(Ljava/awt/Conditional;)V+3
j java.awt.EventDispatchThread.run()V+9
v ~StubRoutines::call_stub
V [jvm.dll+0x845a9]
V [jvm.dll+0xd9317]
V [jvm.dll+0x8447a]
V [jvm.dll+0x841d7]
V [jvm.dll+0x9ed69]
V [jvm.dll+0x109fe3]
V [jvm.dll+0x109fb1]
C [MSVCRT.dll+0x2a3b0]
C [kernel32.dll+0xb50b]
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j sun.misc.Unsafe.copyMemory(JJJ)V+0
j java.nio.DirectFloatBufferU.put(Ljava/nio/FloatBuffer;)Ljava/nio/FloatBuffer;+157
j Nurb.NURBSObject.renderVBO()V+87
j GUI.Viewer.MainViewer.renderScene()V+35
j GUI.AWTOpenGLCanvas.paintGL()V+169
j org.lwjgl.opengl.AWTGLCanvas.paint(Ljava/awt/Graphics;)V+111
j org.lwjgl.opengl.AWTGLCanvas.update(Ljava/awt/Graphics;)V+2
j sun.awt.RepaintArea.updateComponent(Ljava/awt/Component;Ljava/awt/Graphics;)V+6
j sun.awt.RepaintArea.paint(Ljava/lang/Object;Z)V+263
j sun.awt.windows.WComponentPeer.handleEvent(Ljava/awt/AWTEvent;)V+63
j java.awt.Component.dispatchEventImpl(Ljava/awt/AWTEvent;)V+765
j java.awt.Component.dispatchEvent(Ljava/awt/AWTEvent;)V+2
j java.awt.EventQueue.dispatchEvent(Ljava/awt/AWTEvent;)V+46
j java.awt.EventDispatchThread.pumpOneEventForHierarchy(ILjava/awt/Component;)Z+233
j java.awt.EventDispatchThread.pumpEventsForHierarchy(ILjava/awt/Conditional;Ljava/awt/Component;)V+26
j java.awt.EventDispatchThread.pumpEvents(ILjava/awt/Conditional;)V+4
j java.awt.EventDispatchThread.pumpEvents(Ljava/awt/Conditional;)V+3
j java.awt.EventDispatchThread.run()V+9
v ~StubRoutines::call_stub
--------------- P R O C E S S ---------------
Java Threads: ( => current thread )
0x0ada3e70 JavaThread "Thread-2" [_thread_blocked, id=2184]
0x00356100 JavaThread "DestroyJavaVM" [_thread_blocked, id=3432]
=>0x0accc780 JavaThread "AWT-EventQueue-0" [_thread_in_vm, id=236]
0x00a67768 JavaThread "AWT-Windows" daemon [_thread_in_native, id=3684]
0x00a67410 JavaThread "AWT-Shutdown" [_thread_blocked, id=3892]
0x0acb7238 JavaThread "Java2D Disposer" daemon [_thread_blocked, id=736]
0x00a2bf08 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=3548]
0x00a2aad8 JavaThread "CompilerThread0" daemon [_thread_blocked, id=4020]
0x00a29e58 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=464]
0x00a20f18 JavaThread "Finalizer" daemon [_thread_blocked, id=276]
0x00a1fa80 JavaThread "Reference Handler" daemon [_thread_blocked, id=4036]
Other Threads:
0x00a1b8e0 VMThread [id=3464]
0x00a2d0e8 WatcherThread [id=2068]
VM state:not at safepoint (normal execution)
VM Mutex/Monitor currently owned by a thread: None
Heap
def new generation total 640K, used 460K [0x02a70000, 0x02b20000, 0x02f50000)
eden space 576K, 68% used [0x02a70000, 0x02ad3278, 0x02b00000)
from space 64K, 100% used [0x02b00000, 0x02b10000, 0x02b10000)
to space 64K, 0% used [0x02b10000, 0x02b10000, 0x02b20000)
tenured generation total 8244K, used 5798K [0x02f50000, 0x0375d000, 0x06a70000)
the space 8244K, 70% used [0x02f50000, 0x034f99c8, 0x034f9a00, 0x0375d000)
compacting perm gen total 8704K, used 8629K [0x06a70000, 0x072f0000, 0x0aa70000)
the space 8704K, 99% used [0x06a70000, 0x072dd598, 0x072dd600, 0x072f0000)
No shared spaces configured.
Dynamic libraries:
0x00400000 - 0x0040c000 C:\Programme\Java\jre1.5.0_06\bin\javaw.exe
0x7c910000 - 0x7c9c7000 C:\WINDOWS\system32\ntdll.dll
0x7c800000 - 0x7c906000 C:\WINDOWS\system32\kernel32.dll
0x77da0000 - 0x77e4a000 C:\WINDOWS\system32\ADVAPI32.dll
0x77e50000 - 0x77ee1000 C:\WINDOWS\system32\RPCRT4.dll
0x77d10000 - 0x77da0000 C:\WINDOWS\system32\USER32.dll
0x77ef0000 - 0x77f37000 C:\WINDOWS\system32\GDI32.dll
0x77be0000 - 0x77c38000 C:\WINDOWS\system32\MSVCRT.dll
0x6d670000 - 0x6d804000 C:\Programme\Java\jre1.5.0_06\bin\client\jvm.dll
0x76af0000 - 0x76b1e000 C:\WINDOWS\system32\WINMM.dll
0x6d280000 - 0x6d288000 C:\Programme\Java\jre1.5.0_06\bin\hpi.dll
0x76bb0000 - 0x76bbb000 C:\WINDOWS\system32\PSAPI.DLL
0x6d640000 - 0x6d64c000 C:\Programme\Java\jre1.5.0_06\bin\verify.dll
0x6d300000 - 0x6d31d000 C:\Programme\Java\jre1.5.0_06\bin\java.dll
0x6d660000 - 0x6d66f000 C:\Programme\Java\jre1.5.0_06\bin\zip.dll
0x6d000000 - 0x6d167000 C:\Programme\Java\jre1.5.0_06\bin\awt.dll
0x72f70000 - 0x72f96000 C:\WINDOWS\system32\WINSPOOL.DRV
0x76330000 - 0x7634d000 C:\WINDOWS\system32\IMM32.dll
0x774b0000 - 0x775ed000 C:\WINDOWS\system32\ole32.dll
0x5b0f0000 - 0x5b128000 C:\WINDOWS\system32\uxtheme.dll
0x736d0000 - 0x73719000 C:\WINDOWS\system32\ddraw.dll
0x73b30000 - 0x73b36000 C:\WINDOWS\system32\DCIMAN32.dll
0x738b0000 - 0x73980000 C:\WINDOWS\system32\D3DIM700.DLL
0x6d240000 - 0x6d27d000 C:\Programme\Java\jre1.5.0_06\bin\fontmanager.dll
0x7c9d0000 - 0x7d1ef000 C:\WINDOWS\system32\shell32.dll
0x77f40000 - 0x77fb6000 C:\WINDOWS\system32\SHLWAPI.dll
0x773a0000 - 0x774a2000 C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll
0x5d450000 - 0x5d4e7000 C:\WINDOWS\system32\comctl32.dll
0x6d4c0000 - 0x6d4d3000 C:\Programme\Java\jre1.5.0_06\bin\net.dll
0x71a10000 - 0x71a27000 C:\WINDOWS\system32\WS2_32.dll
0x71a00000 - 0x71a08000 C:\WINDOWS\system32\WS2HELP.dll
0x6d4e0000 - 0x6d4e9000 C:\Programme\Java\jre1.5.0_06\bin\nio.dll
0x10000000 - 0x10043000 C:\Programme\Java\jre1.5.0_06\bin\lwjgl.dll
0x72210000 - 0x7223b000 C:\WINDOWS\system32\DINPUT.dll
0x5f0d0000 - 0x5f19c000 C:\WINDOWS\system32\OPENGL32.dll
0x68fc0000 - 0x68fe0000 C:\WINDOWS\system32\GLU32.dll
0x77bd0000 - 0x77bd8000 C:\WINDOWS\system32\VERSION.dll
0x6d360000 - 0x6d366000 C:\Programme\Java\jre1.5.0_06\bin\jawt.dll
0x0afd0000 - 0x0afea000 C:\Programme\Java\jre1.5.0_06\bin\lwjgl-devil.dll
0x0b000000 - 0x0b18f000 C:\Programme\Java\jre1.5.0_06\bin\DevIL.dll
0x0b190000 - 0x0b1a8000 C:\Programme\Java\jre1.5.0_06\bin\ILU.dll
0x69000000 - 0x695d2000 C:\WINDOWS\system32\atioglxx.dll
VM Arguments:
java_command: test
Launcher Type: SUN_STANDARD
Environment Variables:
CLASSPATH=C:\Programme\QuickTime\QTSystem\QTJava.zip;C:\Programme\Borland\InterBase\InterClient\interclient.jar
PATH="C:\Programme\Microsoft DirectX SDK (December 2005)\Utilities\Bin\x86";C:\PROGRA~1\Borland\CBUILD~1\Bin;C:\PROGRA~1\Borland\CBUILD~1\Projects\Bpl;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Programme\ATI Technologies\ATI Control Panel;C:\Programme\QuickTime\QTSystem\;C:\BC5\BIN;
USERNAME=Hans-Peter Herion
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 6 Model 9 Stepping 5, GenuineIntel
--------------- S Y S T E M ---------------
OS: Windows XP Build 2600 Service Pack 2
CPU:total 1 family 6, cmov, cx8, fxsr, mmx, sse, sse2
Memory: 4k page, physical 523632k(88192k free), swap 1277756k(728716k free)
vm_info: Java HotSpot(TM) Client VM (1.5.0_06-b05) for windows-x86, built on Nov 10 2005 11:12:14 by "java_re" with MS VC++ 6.0
Ok i think the Problem is "solved" (is it??) I can render different VBOs i kick out the old render method and write
public void renderVBO(){
GL11.glPushMatrix();
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, VBO_ID);
GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, tfb.capacity()/3);
GL11.glPopMatrix();
}
But how does this work with mapped buffer
This ought to help....
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.ARBBufferObject;
import org.lwjgl.opengl.ARBVertexBufferObject;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.opengl.glu.GLU;
public class VRVBO {
public static boolean EXIT_APP = false;
public static String WINDOW_TITLE = "VBO Test By Crash0veride007";
public static DisplayMode displayMode;
public static int WINDOW_WIDTH = 1280;
public static int WINDOW_HEIGHT = 1024;
public static int WINDOW_DEPTH = 32;
public float FOVY = 80.0f;
public float NEAR_VIEW_DISTANCE = 0.1f;
public float FAR_VIEW_DISTANCE = 3500.0f;
public float EYE_X = 0.0f;
public float EYE_Y = 25.0f;
public float EYE_Z = 100.0f;
public float AT_X = 0.0f;
public float AT_Y = 0.0f;
public float AT_Z = 0.0f;
public float UP_X = 0.0f;
public float UP_Y = 1.0f;
public float UP_Z = 0.0f;
public float angle = 0.0f;
float rand_R = 0.0f;
float rand_G = 0.0f;
float rand_B = 0.0f;
public int vxsize = 128;
public int vysize = 128;
public int vzsize = 128;
public int coordinatesize = vxsize*vysize*vzsize;
public int volumesize = coordinatesize*3;
public float [] vertices = new float[volumesize];
public FloatBuffer volume = BufferUtils.createFloatBuffer(vertices.length);
public int VBO_ID=0;
public static void main(String[] args){
VRVBO vrvbo = new VRVBO();
vrvbo.run();
}
public void run() {
long startTime = System.currentTimeMillis() + 5000;
long fps = 0;
float mbs =0;
try {
init();
while (!EXIT_APP) {
MainLoop();
Display.update();
if (startTime > System.currentTimeMillis()) {
fps++;
} else {
long timeUsed = 5000 + (startTime - System.currentTimeMillis());
startTime = System.currentTimeMillis() + 5000;
String outdata = fps + " frames in " + (float) (timeUsed / 1000f) + " seconds = "+ (fps / (timeUsed / 1000f))+" FPS";
System.out.println( outdata );
mbs = (fps / (timeUsed / 1000f)) * volumesize * 4 /1000000;
System.out.println(mbs+" MB/s"+" Shoved down the pipeline");
Display.setTitle(WINDOW_TITLE + " " + outdata);
fps = 0;
}
}
cleanup();
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
public void MainLoop() {
if(Display.isCloseRequested()) {
EXIT_APP = true;
}
rendershit();
}
public void createWindow() throws Exception {
DisplayMode modes[] = Display.getAvailableDisplayModes();
for (int i = 0; i < modes.length; i++) {
if (modes.getWidth() == WINDOW_WIDTH
&& modes.getHeight() == WINDOW_HEIGHT
&& modes.getBitsPerPixel() == WINDOW_DEPTH) {
displayMode = modes;
break;
}
}
Display.setDisplayMode(displayMode);
Display.setTitle(WINDOW_TITLE);
Display.create();
}
public void init() throws Exception {
createWindow();
checkext();
initGL();
populatevolume();
VBO_ID=createVBOID();
bufferData(VBO_ID, volume);
}
public void checkext() {
if (!GLContext.getCapabilities().GL_ARB_vertex_buffer_object ) {
System.out.println("ARB VBO not supported!");
System.exit(1);
}
}
public void initGL() {
Display.setVSyncEnabled(false);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glClearDepth(1.0);
//GL11.glEnable(GL11.GL_DEPTH_TEST);
//GL11.glDepthFunc(GL11.GL_LEQUAL);
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GLU.gluPerspective(FOVY,(float) displayMode.getWidth() / (float) displayMode.getHeight(),NEAR_VIEW_DISTANCE,FAR_VIEW_DISTANCE);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
GLU.gluLookAt(EYE_X, EYE_Y, EYE_Z, AT_X, AT_Y, AT_Z, UP_X, UP_Y, UP_Z);
}
public void populatevolume() {
int loc = 0;
for (float x =0.0f; x < vxsize; x+=1.0f) {
for (float y =0.0f; y < vysize; y+=1.0f) {
for (float z =0.0f; z < vzsize; z+=1.0f) {
vertices[loc]=x;
vertices[loc+1]=y;
vertices[loc+2]=z;
//System.out.println(vertices[loc]+","+vertices[loc+1]+","+vertices[loc+2]);
loc+=3;
}
}
}
volume.put(vertices).rewind();
}
public int createVBOID() {
IntBuffer buffer = BufferUtils.createIntBuffer(1);
ARBVertexBufferObject.glGenBuffersARB(buffer);
return buffer.get(0);
}
public static void bufferData(int id, FloatBuffer buffer) {
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, id);
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, buffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);
}
public void rendershit() {
rand_R =(float)Math.random();
rand_G =(float)Math.random();
rand_B =(float)Math.random();
GL11.glColor3f(rand_R, rand_G, rand_B);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glRotatef(angle+1.0f,0.0f,1.0f,0.0f);
GL11.glPushMatrix();
GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);
GL11.glDrawArrays(GL11.GL_POINTS, 0, coordinatesize);
GL11.glPopMatrix();
}
public void cleanup() {
IntBuffer del_vbo_id = BufferUtils.createIntBuffer(1);
del_vbo_id.put(0, VBO_ID);
ARBBufferObject.glDeleteBuffersARB(del_vbo_id);
Display.destroy();
}
}