Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

12046 Posts in 1593 Topics- by 596 Members - Latest Member: meoiwcmo

21. May 2013, 06:53:43 am
Xith3D CommunityXith3D InternalsDeveloper discussion (Moderators: Marvin Fröhlich, 'n ddrylliog)Buffer slicing int ShapeAtomPeer
Pages: [1]
Print
Author Topic: Buffer slicing int ShapeAtomPeer  (Read 1841 times)
Mathias 'cylab' Henze
Fierce Warrior
****
Offline Offline

Posts: 540

1064620
View Profile WWW
« on: 16. May 2008, 06:44:54 pm »

In the ShapeAtomPeers around line 630 there is a buffer splicing I don't get.

LWJGLs ShapeAtomPeer (624):
Code:
    IntBuffer subBuffer = ( (IntBuffer)igsa.getIndexData().getBuffer().position( i0 ) ).slice();
    subBuffer.limit( stripVertexCounts[ s ] ); // added to fix the strange triangles in the terrain test
    GL11.glDrawElements( mode, subBuffer );

I added the new limit there to fix the triangle test, but before that, the slice was completely unaltered.

If a slice at all, shouldn't this be
Code:
    IntBuffer subBuffer = ( (IntBuffer)igsa.getIndexData().getBuffer()).slice();
    subBuffer.position( i0 )
    subBuffer.limit( stripVertexCounts[ s ] );
    GL11.glDrawElements( mode, subBuffer );

to make sense?

But afaik a slice call creates a new (shared) Buffer erverytime, so wouldn't be
Code:
    IntBuffer buffer = (IntBuffer) igsa.getIndexData().getBuffer();
    int position = buffer.position();
    int limit = buffer.limit();
    buffer.position( i0 );
    buffer.limit( stripVertexCounts[s] );
    GL11.glDrawElements( mode, buffer );
    buffer.limit( limit );
    buffer.position( position );

a more effective implementation? It seems to be working, but maybe I am missing something, so I did not commit this yet.

Any Feedback? (Marvin? Wink)
Logged

Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4403


May the 4th, be with you...


View Profile
« Reply #1 on: 16. May 2008, 08:01:17 pm »

Actually I was never happy with the way, index-buffers are used. I am very aware of the ugly, GC-expensive slice method. But I never found a way to avoid it. Certainly this is because I didn't understand the nio Buffers completely. I was just too lazy to read the documentation Tongue. I messed around a lot with ByteBuffers during the last days and finally understood them Smiley.

Please go ahead and fix that. It looks good. Without having the code with me I can try to blue-print my current thought of how I would implement that today.
Code:
IntBuffer buffer = (IntBuffer)igsa.getIndexData().getBuffer();
buffer.position( i0 );
buffer.limit( i0 + stripVertexCounts[ s ] );
GL11.glDrawElements( mode, buffer );

But if my code is nonsense, just forget it and fix it the way, you explained above.

Marvin
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4403


May the 4th, be with you...


View Profile
« Reply #2 on: 16. May 2008, 09:42:41 pm »

Hey

I saw your changes and they still create a new IntBuffer because of the slice() method. I checked, if my code above would work and I am confident, that it will. And it doesn't create any garbage and should be preferred. Don't you agree? Could you maybe check it?

Marvin
Logged
Mathias 'cylab' Henze
Fierce Warrior
****
Offline Offline

Posts: 540

1064620
View Profile WWW
« Reply #3 on: 16. May 2008, 10:17:11 pm »

The version you saw was just the limit() change to fix the terrain test with the LWJGL renderer. I just checked in the full version.
Logged

Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4403


May the 4th, be with you...


View Profile
« Reply #4 on: 18. May 2008, 04:20:57 pm »

The version you saw was just the limit() change to fix the terrain test with the LWJGL renderer. I just checked in the full version.

Ah, ok. I saw it now. It is perfect. Thanks a lot.

Marvin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic