passing Device device in all drawing functions directx9 c#
Posted on 2004-11-11
I am programming some dx9 project. The device parameter anyone must use for drawing functions is created in the GraphicsSample class as protected and passed to the GraphicsClass at the default SDK projects.
Everytime I make a class where something must be drawn the Device parameter seems to end up in the constructor because there is something like the following code happening: (in short there are things to be loaded into device)
eg. class SimpleSprite
public SimpleSprite(Device device)
texture = TextureLoader.FromFile(device, filename);
using (Surface s = texture.GetSurfaceLevel(0))
SurfaceDescription desc = s.Description;
textureSize = new Rectangle(0, 0, desc.Width, desc.Height);
sprite = new Sprite(device);
This is getting pretty annoying because if I have a "one to many" relationship I seem to make functions with always the device as parameter (hope at least some of the problem is clear).
Q: How can I get rid of the device parameter? Is it just passed by all graphics classes when anything is drawn. Can't I just make it a global parameter or can I make a base class that contain a child class with the device parameter present.