source: OGRE/trunk/ogrenew/Docs/src/texturesource.inc @ 657

Revision 657, 6.2 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1@node External Texture Sources
2@chapter External Texture Sources
3
4@heading Introduction
5
6This tutorial will provide a brief introduction of ExternalTextureSource and ExternalTextureSourceManager classes, their relationship, and how the PlugIns work. For those interested in developing a Texture Source Plugin or maybe just wanting to know more about this system, take a look the ffmpegVideoSystem plugin, which you can find more about on the OGRE forums.
7
8@heading What Is An External Texture Source?
9What is a texture source? Well, a texture source could be anything - png, bmp, jpeg, etc. However, loading textures from traditional bitmap files is already handled by another part OGRE. There are, however, other types of sources to get texture data from - ie. mpeg/avi/etc movie files, flash, run-time generated source, user defined, etc.@*@*
10
11How do external texture source plugins benifit OGRE? Well, the main answer is: addding support for any type of texture source does not require changing OGRE to support it... all that is involved is writting a new plugin. Additionally, because the manager uses the StringInterface class to issue commands/params, no change to the material script reader is needs to be made. As a result, if a plugin needs a special parameter set, it just creates a new command in it's Parameter Dictionary. - see ffmpegVideoSystem plugin for an example. To make this work, two classes have been added to OGRE: ExternalTextureSource & ExternalTextureSourceManager.
12
13
14@heading ExternalTextureSource Class
15The ExternalTextureSource class is the base class that Texture Source PlugIns must be derived from. It provides a generic framework (via StringInterface class) with a very limited amount of functionality. The most common of parameters can be set through the TexturePlugInSource class interface or via the StringInterface commands contained within this class. While this may seem like duplication of code, it is not. By using the string command interface, it becomes extremly easy for derived plugins to add any new types of parameters that it may need.@*@*
16
17Default Command Parameters defined in ExternalTextureSource base class are:
18@itemize @bullet
19@item Parameter Name: "filename" Argument Type: Ogre::String
20Sets a filename plugin will read from
21@item Parameter Name: "play_mode" Argument Type: Ogre::String
22Sets initial play mode to be used by the plugin - "play", "loop", "pause"
23@item Parameter Name: "set_T_P_S" Argument Type: Ogre::String
24Used to set the technique, pass, and texture unit level to apply this texture to. As an example: To set a technique level of 1, a pass level of 2, and a texture unit level of 3, send this string "1 2 3".
25@item Parameter Name: "frames_per_second" Argument Type: Ogre::String
26Set a Frames per second update speed. (Integer Values only)
27@end itemize
28
29@heading ExternalTextureSourceManager Class
30ExternalTextureSourceManager is responsible for keeping track of loaded Texture Source PlugIns. It also aids in the creation of texture source textures from scripts. It also is the interface you should use when dealing with texture source plugins.@*@*
31
32Note: The function prototypes shown below are mockups - param names are simplified to better illustrate purpose here...
33Steps needed to create a new texture via ExternalTextureSourceManager:
34
35@itemize @bullet
36@item  Obviously, the first step is to have the desired plugin included in plugin.cfg for it to be loaded.
37@item Set the desired PlugIn as Active via AdvancedTextureManager::getSingleton().SetCurrentPlugIn( String Type ); -- type is whatever the plugin registers as handling (eg. "video", "flash", "whatever", etc).
38@item Note: Consult Desired PlugIn to see what params it needs/expects.
39Set params/value pairs via AdvancedTextureManager::getSingleton().getCurrentPlugIn()->setParameter( String Param, String Value );
40@item After required params are set, a simple call to AdvancedTextureManager::getSingleton().getCurrentPlugIn()->createDefinedTexture( sMaterialName ); will create a texture to the material name given.
41@end itemize
42@*@*
43
44The manager also provides a method for deleting a texture source material: AdvancedTextureManager::DestroyAdvancedTexture( String sTextureName ); The destroy method works by broadcasting the material name to all loaded TextureSourcePlugIns, and the PlugIn who actually created the material is responsible for the deletion, while other PlugIns will just ignore the request. What this means is that you do not need to worry about which PlugIn created the material, or activating the PlugIn yourself. Just call the manager method to remove the material. Also, all texture plugins should handle cleanup when they are shutdown.
45
46@heading Texture Source Material Script
47As mentioned earlier, the process of defining/creating texture sources can be done within material script file. Here is an example of a material script definition - Note: This example is based off the ffmpegVideoSystem plugin parameters.
48@example
49material Example/MyVideoExample
50{
51        technique
52        {
53                pass
54                {
55                        texture_unit
56                        {
57                                texture_source video
58                                {
59                                        filename mymovie.mpeg
60                                        play_mode play
61                                        sound_mode on
62                                }
63                        }
64                }
65        }               
66}
67@end example
68Notice that the first two param/value pairs are defined in the ExternalTextureSource base class and that the third parameter/value pair is not defined in the base class... That parameter is added to the param dictionary by the ffmpegVideoPlugin... This shows that extending the functionality with the plugins is extremely easy. Also, pay particular attention to the line: texture_source video. This line identifies that this texture unit will come from a texture source plugin. It requires one parameter that determines which texture plugin will be used. In the example shown, the plugin requested is one that registered with "video" name.
69
70@heading Simplified Diagram of Process
71
72This diagram uses ffmpegVideoPlugin as example, but all plug ins will work the same in how they are registered/used here. Also note that TextureSource Plugins are loaded/registered before scripts are parsed. This does not mean that they are initialized... Plugins are not initialized until they are set active! This is to ensure that a rendersystem is setup before the plugins might make a call the rendersystem.
73
74@image{images/TextureSource}
Note: See TracBrowser for help on using the repository browser.