Jump to content
  • Advertisement
Sign in to follow this  
storage

[.net] Wrapping MDX?

This topic is 4349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Quick question, does anyone know a tutorial or something that deals with wrapping Managed DirecX (mainly Direct3D) in classes? I just can't seem to get it to work. My main problem is the Paint event, do I have to do all the rendering in there? Thanks in advance, storage.

Share this post


Link to post
Share on other sites
Advertisement
No, its not limited to onpaint only, it actually depends on how you have designed your application. Its possible to use "while" drawing loop in console mode for example. In loop just do Application.DoEvents() and then then all the rest, including scene rendering

Share this post


Link to post
Share on other sites
The way I did it was to set up a render queue. Basically I made a base class that handled device creation and such and inside that class made an ArrayList that would contain any objects that needed to be rendered. When it came time to render just loop through the ArrayList, test for a certain type of object, and then call it's apparopriate render function. Here is an example:



class MainRenderer
{
ArrayList renderQueue;
void Init()
{
//Initialise
}

void Render()
{
foreach (object o in renderQueue)
{
if (o is NameOfType)
{
NameOfType temp = (NameOfType)o;
temp.Render();
}

//Repeat for other types in the ArrayList
}
}
}




This way the only function you have to call is MainRenderer.Render() and it renders everything you've added to the ArrayList. The only downfall is that there is a lot of boxing and unboxing going on with this method. Hope that helps you out some.

-AJ

Share this post


Link to post
Share on other sites
Not to be nitpicky, but you can see a modest performance boost by using the as keyword instead of the cast. Since you already know that the object is of the desired type (via the is keyword) you can be reasonably sure that it will still be a valid type and not need to worry about catching (or having .NET) go through the process of setting up exception throwing for the cast operation.

class MainRenderer
{
ArrayList renderQueue;
void Init()
{
//Initialise
}

void Render()
{
foreach (object o in renderQueue)
{
if (o is NameOfType)
{
NameOfType temp = o as NameOfType;
temp.Render();
}

//Repeat for other types in the ArrayList
}
}
}

Just my two cents...
Vincent

Share this post


Link to post
Share on other sites
Thanks for the suggesstion. I hadn't thought about that. I will have to try that out and see what kind of results I get. [smile]

-AJ

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!