Archived

This topic is now archived and is closed to further replies.

cody

casting arrays in c#?

Recommended Posts

im playing around with c# and opengl using tao opengl. my problem is this: when i want to use the opengl vertex array functions i dont know how to fill that buffer. in c++ i had a vertexbuffer class that has a void* pointer to a memory block in system or video memory. i could cast that into MYVERTEXFORMAT* and it was easy to use. but in c# and its strong type system i cant just cast different arrays. i declare a byte[] array and how should i make a MYVERTEXFORMAT[] from it? declaring it as MYVERTEXFORMAT[] would not be smart as my renderer should work with different formats without writing much code. i looked at the d3d9 managed api and found that the DrawUserPrimitive function takes a object as the vertex data. so how does the function get the pointer from that object? any ideas?

Share this post


Link to post
Share on other sites
You could have an array of System.Object types. Since all types inherit from System.Object this array could be a bunch of bytes, a bunch of ints, or a bunch of MyVertexType's. An Array I believe is an instance of something like System.ArrayList (or something that inherits from it) which itself inherits from System.Object, hence the parameter type in DrawUserPrimitive().

[edited by - Optikal on October 15, 2003 11:10:04 AM]

Share this post


Link to post
Share on other sites
just curious, but isn''t the ArrayList type within System.Collections and type Array is found with System? also, contiguous memory of any strong type can be defined using the bracket operator, e.g.
someType[] foos = (someType[])anotherType.ToArray(typeof(someType)); 


this should be tested, however.

..:: mirirom ::..

Share this post


Link to post
Share on other sites
damn i still cant get it to work

the ToArray function copys an array object by object, this is not what i need.
also when i define a render function like this:

void RenderSomething(object vertices)

i cant get a pointer or something usefull from the object type.
perhaps this is only possible in managed c++? if so i cant use it on linux anymore because i dont think mono can compile c++.

is it really so damn complicated in c# to deal with such memory blocks?
and are there any articles on this topic? i didnt find something useful.

Share this post


Link to post
Share on other sites