Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm writing a small graphics class for direct3d 9 and have some OOP problems.

 

CGraphics contains the d3d device and initialization/drawing code. It also contains CTextureManager as public.

 

I figured there's nothing wrong with typing something like:

 

Graphics.TextureManager.AddTexture(FilePath)

 

Another option is to wrap the texture manager methods in the graphics class like:

 

Sub CGraphics.AddTexture(FilePath)
   TextureManager.AddTexture(FilePath)
End Sub

Graphics.AddTexture(FilePath)

 

Which way is best and why?

 

Now my problem is the texture manager needs access to the d3d device in order to load textures. How should I set up my scope and structure in a professional way?

 

I could get around this by making the Device a public property and typing:

 

TextureManager.Device = Graphics.Device

 

but that would be sloppy and I know there's a better way.

 

If my whole approach isn't right, I'd be happy to be shown a better structure.

  • *Experts*
Posted

For your first question. I would say a better approach is the first one. Since the instance of the TextureLoader is public, why not let it handle its own business. You don't want one class to handle everything just by setting up methods that simply forward to another method.

 

You could padd the device through a constructor to the TextureLoader. That is how a lot of Direct3D objects get a reference to a device when they need it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...