Resources are Objects, that can be loaded from a harddrive, and then used from memory. Because the loading process is quite Resource-dependable, the loading of each resource (e.g Texture, 3d-model etc.) should be made as little as possible.
For this Orxonox provides a Shared Resource System for these time-consuming processes.
- Resources that are loaded (like a Texture) always have a Data-type (like TextureData) where the data is stored.
- The Resources have a counted pointer to these Data, so if you copy one Texture to another one, only the pointer will be copied, and the reference-count of the pointer will be automatically increased
- To Finaly load a Resource from disc, and keep a constant version of the Data in check, the Resource functionality is finally used: for the Resource Texture the coresponding Resourcerer is ResourceTexture.
- locate Files on the disc in a Directoy of your joice
- store a copy of a ResourceData with a Key-Name.
In the following document ResourceTexture is only assumed as an Example. This also works with ResourceMD2, ResourceOBJ, ResourceSoundBuffer and so on.
- Share a Resource (assumes texutre has some data assigned to it):
#include "texture.h" ... Texture copy = texture;
Here you can see, that copy has _NO_ pointer type, so we can copy one Texture to another one, and both textures share the same data.
- Load a Texture from the disc with ResourceTexture
#include "texture.h" #include "resource_texture.h" ... Texture storeTex = ResourceTexture("orxonox.png", GL_TEXTURE_2D);
Behind the scenes
ResourceTexture is a Handler that is derived from Texture and Resource.
- The Texture part sais, how to load a Texture from a disc.
- The Resource part sais, where the Resource can be found, and to check if the Resource was already loaded