dwmkerr / sharpgl

Use OpenGL in .NET applications. SharpGL wraps all modern OpenGL features and offers a powerful scene graph to aid development.
MIT License
770 stars 300 forks source link

IndexBuffer() with int32 instead of ushort #136

Open laurentchougrani opened 7 years ago

laurentchougrani commented 7 years ago

Hello I've been working and playing with this project, it is great. I need to use large meshes (more than 2^16 indexes), and i have encontered the limit of IndexBuffer wich needs only ushort... I would thus need to use int32 or uint. Does anyone know how to process to get uint ou int32 in the IndexBuffer?

wo80 commented 7 years ago

You could use an extension method, like

public static void SetData(this IndexBuffer buffer, OpenGL gl, uint[] rawData)
{
    // Get handle to raw data.
    var hData = GCHandle.Alloc(rawData, GCHandleType.Pinned);

    int size = sizeof(uint) * rawData.Length;

    gl.BufferData(OpenGL.GL_ELEMENT_ARRAY_BUFFER, size, hData.AddrOfPinnedObject(), OpenGL.GL_STATIC_DRAW);

    // Free handle.
    hData.Free();
}
laurentchougrani commented 7 years ago

Thank you. I have already managed to do so, I can now load large meshes with just a little drop of FPS (about 10). This should be integrated in SharpGL sources I guess. Here is an example of a large mesh I have loaded thank to my update. [image: Images intégrées 1] FPS: 40. Indices: 1817004 Triangles : 605668 Load time : about 3-4sec

have a nice day

2017-09-04 14:25 GMT+02:00 wo80 notifications@github.com:

You could use an extension method, like

public static void SetData(this IndexBuffer buffer, OpenGL gl, uint[] rawData) { // Get handle to raw data. var hData = GCHandle.Alloc(rawData, GCHandleType.Pinned);

int size = sizeof(uint) * rawData.Length;

gl.BufferData(OpenGL.GL_ELEMENT_ARRAY_BUFFER, size, hData.AddrOfPinnedObject(), OpenGL.GL_STATIC_DRAW);

// Free handle. hData.Free(); }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dwmkerr/sharpgl/issues/136#issuecomment-326950350, or mute the thread https://github.com/notifications/unsubscribe-auth/AFxOjJlniSXmKPCcgFIfAGoltV_XAm5qks5se-w3gaJpZM4PHhpS .

-- Laurent Chougrani Ingénieur Arts & Métiers Doctorant Arts & Métiers, Laboratoire LSIS 0659361935