Jump to content
  • Advertisement
Sign in to follow this  
TheUnbeliever

Removing Lights from LightCollection? (MDX - C#)

This topic is 4228 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

I'm writing a little renderer in C# to hone my DirectX skills (at the moment, it's little more than a way to allow realtime manipulation of various small elements). At the moment, if I want to remove a light from the scene, I just do
deviceRendering.Lights.Enabled = false;
(Slightly convoluted method of getting to that line, but the idea is there). However, the deviceRendering.Lights.Count value shows that this doesn't remove it as such - it just stops it from being taken into account for rendering. Is there a way to remove the light properly from the LightCollection? I can't seem to find one, which seems odd unless this is not how the lights are designed to be used (as otherwise, the lights will always consume MaximumNumberOfLightsAllocatedSoFar * sizeof(Light) regardless of how many lights are actively in use at that time (although this memory is reused if a light is added back in) - leaking memory).

Share this post


Link to post
Share on other sites
Advertisement
Disabling the light should be the way to go. The lights collection is a stub for working with the unmanaged SetLight() and is filled with some number of default light structs to make it easier to set up lighting. You can just use and reuse these default structs (so device.Lights[0] for example) by setting their properties and calling Update() on them to set them on the device. With this approach the number of lights stays constant, so no memory is leaked. I think this is how Managed lights are meant to be used, at least I've never had to allocate new lights myself.

Hope this helps :)

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!