Removing Lights from LightCollection? (MDX - C#)

Started by
1 comment, last by TheUnbeliever 17 years, 4 months ago
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).
[TheUnbeliever]
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 :)
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Great, thanks. :) Just wasn't quite sure if I was going about that the right way. ;)
[TheUnbeliever]

This topic is closed to new replies.

Advertisement