Jump to content
  • Advertisement
Sign in to follow this  
AfroFire

Texture Manager

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

Anyone have a recommendation on how to write a descent texture manager class for an engine? So far I'm looking at the Singleton, but for some reason I'm scowling at the idea thinking that there has to be a better way (not that anything is wrong with a Singleton, something just feels wrong about it... I'm sure you understand.) Simple question, that is all :) Thanks guys.

Share this post


Link to post
Share on other sites
Advertisement
Just curious. Does singleton in this context mean there can only be one instance of the class or no matter how many instances of the class there is only logically one manager?

Share this post


Link to post
Share on other sites
I have to disagree with everyone else here, and say that I think a singleton is a bad idea. There are a few cases where multiple texture managers could be a good idea, lets say we have a Renderer class, and a texture manager singleton class. The texture manager needs a pointer to some internal data in the Renderer class because some of the textures should be stored in VidMem and D3D or OGL is needed to do this, there is no problem when we have a single renderer, but imagine we have two renderers. The first renderer renders to a 1600x1200 computer monitor and the other renders to another computer monitor, which is 340x280, both monitors have there own seperate graphic cards so we don't know what internal data to pass to the texture manager. In this case it would be a good idea for each graphic card to have their own texture manager, and each renderer could just have the texture manager as a private or protected member (assuming C++ or C#).

You might say that such a situation is very unlikely, but lets say you are testing a GameBoy game on the 340x280 monitor and you figured out you needed a tool to see what is happening in the AI of you creatures, this would require is to have two renderers pointing at two screens, which might have different graphic cards and one is fullscreen(the game) while the other is windowed(AI tool).

Share this post


Link to post
Share on other sites
lets stay on the carpet

yes its unlikely, normally we need one renderer. show me a hobby programmer who uses two screens for programming

Share this post


Link to post
Share on other sites
Quote:
Original post by Red_falcon
lets stay on the carpet

yes its unlikely, normally we need one renderer. show me a hobby programmer who uses two screens for programming


I dont see why that is unlikely, I'm still very new to game programming and haven't completed anything, but when I will write the AI part of my engine I expect to provide a way to see the state of FSM, Fuzzy Logic, Networks etc. I will most likely give the user an option to start a new window which show all this information. Such a tool would be pretty hard to use on a single screen since the game will most likely require most of the screen space.

I plan to buy a 17" screen after christmas and use that when programming.

EDIT: Also, OT:
I would create a TextureManager class, it should be able to give you an ID (handle) which you could pass around when refering to a texture, when someone who have a handle need to actually get some data it sends the ID to a function in the texture manager. This would be the basic idea of how I would design a texture manager, of course there is lots of things I have left out.

Share this post


Link to post
Share on other sites
and for such a thing you need to use second renderer?

i saw some reports of idustry developers and they use for that command line output or normal windows window with text output or/and gdi for drawings to represent diagrams

Share this post


Link to post
Share on other sites
Quote:
Original post by Red_falcon
and for such a thing you need to use second renderer?

i saw some reports of idustry developers and they use for that command line output or normal windows window with text output or/and gdi for drawings to represent diagrams


Depending on what you are going to do in your tools, you might, you can in most cases create the application with standard Win32 controls and GDI, so it might not have been a very good example. Then imagine we have a FPS and we want to have two cameras, one mounted on the player (the standard camera) and one mounted on the AI player, or following the AI player. In this case you could use split-screen, but it would probably be a better idea with a monitor for each camera since if you have split-screen you will see less and you might not notice that the AI ignores players until they are 30 % into the screen.

If you are just doing a simple game and don't need a lot of functionality a singleton is probably fine, but the I have mainly chosen a non-singleton approach because of two things I can see lots of ways it can help me balance the game, observe what is happening and debugging, also I might later on figure out I need another screen for something which I haven't thought about and then I need to change a lot of code and if some people using my engine had already written code they would have to re-write it. Also I'm writing an engine I'm planning on making available online (open source) and I can never know what the users will need.

I think you should use a singleton, when you see NO cases where you might need multiple instances. You might say I will never NEED two instances, it is possible, but I will never need it, then when you have been working on the game (engine) for a year you find out that you do need two instances, or some other person using your code might need two instances.

Share this post


Link to post
Share on other sites
I'm working on my engine since a couple of months. I had tried many times before and used also multiple instances of whatever(renderer, window, texture manager), but nowaday i stick to singletons. For second cam i will use PIP(picture in picture). But that only my 2 cent opinion.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!