Soundbomber's picture

T2 structure

I have just changed to version 0.9.8 and am having a couple of problems.
When passing data to my buffers the BufferData command which worked fine before is throwing errors.

oGL.BufferData(BufferTarget.ArrayBuffer, oObject.oSolidVertices.Length * 12 * _
      Marshal.SizeOf(GetType(UInteger)), oObject.oSolidVertices, BufferUsageHint.DynamicDraw)

The data argument seems to be expecting data in the T2 structure format.
What is the T2 structure? I am currently passing in a custom Vertex structure - can I still do this?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Yes, as long as Vertex is a struct, not a class:

struct Vertex { ... }

You can either pass a reference to a single struct or arrays of structures. How is oObject.SolidVertices defined?

Soundbomber's picture
Public oSolidVertices() As Vertex
 
Public Structure Vertex
 
        ' Mimic InterleavedArrayFormat.T2fC4fN3fV3f
 
        Public Texture As Vector2
        Public Color As Color4
        Public Normal As Vector3
        Public Position As Vector3
 
End Structure
objarni's picture

Is this for VBO objects..? I'm new to these, do you have to declare you own structure to use them properly?

Soundbomber's picture

Yes I'm using VBO's. As far as I am aware you can use any custom structure as long as you set the pointers correctly. I have been using this method successfully in v 0.9.5.

objarni's picture

Thanks. I'll be asking you for guidence when I come to the point of using VBOs in my "Builder"-object idea.

Soundbomber's picture

I'm still new to OpenGL, but I will gladly assist if I can. It has been a (sometimes) painful learning curve getting to grips with VBO's and OpenGL in general (not having any experience in 3D graphics), but well worth it.

the Fiddler's picture

Your code should work. What is the error message?

T2 is the name of a generic parameter - the compiler should infer that the actual type is Vertex. This should not be necessary, but you can try to write:

oGL.BufferData(Of Vertex)(BufferTarget.ArrayBuffer, oObject.oSolidVertices.Length * 12 * _
      Marshal.SizeOf(GetType(UInteger)), oObject.oSolidVertices, BufferUsageHint.DynamicDraw)
Soundbomber's picture

Using (Of Vertex) for the ArrayBuffer and (Of UShort) for the ElementArrayBuffer did the trick.
I also had to declare the size as an IntPtr object first and then pass that into the argument thus:

        For Each oObject As Model_3DObject In Me.o3DModelObjects
            Dim oVertexSize As IntPtr = oObject.oSolidVertices.Length * 12 * _
                   Marshal.SizeOf(GetType(UInteger))
            Dim oIndexSize As IntPtr = oObject.oSolidIndices.Length * Marshal.SizeOf(GetType(UShort))
            If Not oObject.oSolidVertices Is Nothing And Not oObject.oSolidIndices Is Nothing Then
                oGL.BindBuffer(BufferTarget.ArrayBuffer, Me.oBuffers(iCount))
                oGL.BufferData(Of Vertex)(BufferTarget.ArrayBuffer, oVertexSize, _
                    oObject.oSolidVertices, BufferUsageHint.DynamicDraw)
                iCount += 1
                oGL.BindBuffer(BufferTarget.ElementArrayBuffer, Me.oBuffers(iCount))
                oGL.BufferData(Of UShort)(BufferTarget.ElementArrayBuffer, oIndexSize, _
                    oObject.oSolidIndices, BufferUsageHint.DynamicDraw)
                iCount += 1
            End If
            oVertexSize = oObject.oWireVertices.Length * 12 * Marshal.SizeOf(GetType(UInteger))
            oIndexSize = oObject.oWireLineIndices.Length * Marshal.SizeOf(GetType(UShort))
            If Not oObject.oWireVertices Is Nothing And Not oObject.oWireLineIndices Is Nothing Then
                oGL.BindBuffer(BufferTarget.ArrayBuffer, Me.oBuffers(iCount))
                oGL.BufferData(Of Vertex)(BufferTarget.ArrayBuffer, oVertexSize, oObject.oWireVertices, _
                    BufferUsageHint.DynamicDraw)
                iCount += 1
                oGL.BindBuffer(BufferTarget.ElementArrayBuffer, Me.oBuffers(iCount))
                oGL.BufferData(Of UShort)(BufferTarget.ElementArrayBuffer, oIndexSize, _
                    oObject.oWireLineIndices, BufferUsageHint.DynamicDraw)
                iCount += 1
            End If
        Next

Thank you for the help.