Cafu Engine
TextureMap.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 /*******************/
8 /*** Texture Map ***/
9 /*******************/
10 
11 #ifndef CAFU_MATSYS_TEXTUREMAP_HPP_INCLUDED
12 #define CAFU_MATSYS_TEXTUREMAP_HPP_INCLUDED
13 
14 
15 struct BitmapT;
16 class MapCompositionT;
17 
18 
19 namespace MatSys
20 {
21  /// This is an interface to a texture-map.
22  /// Texture maps are only ever created by the texture map manager.
24  {
25  public:
26 
27  // Needed by some user code for computing the texture s/t-coords.
28  // REALLY? Shouln't the user code simply get the X/Y dims somehow directly from the *material*?!?
29  virtual unsigned int GetSizeX()=0;
30  virtual unsigned int GetSizeY()=0;
31 
32  virtual ~TextureMapI() { };
33  };
34 
35 
36  /// This is an interface to the texture-map manager.
37  /// The interface is specified as ABC in order to share the texture-map manager across exe/dll boundaries.
39  {
40  public:
41 
42  /// Sets the maximum side length to which textures should be scaled down before they are employed for rendering.
43  /// The unscaled data is kept in memory, though, even if the TextureMapManager is the owner of the texture data.
44  /// The value that is set here is only effective when a texture must be re-initialized for rendering
45  /// (e.g. after an OpenGL rendering-context change) and normally has no effect at other times.
46  virtual void SetMaxTextureSize(unsigned long MaxSize)=0;
47 
48  /// Returns the currently set maximum texture size.
49  virtual unsigned long GetMaxTextureSize() const=0;
50 
51  /// Creates a 2D texture-map by a texture-map composition. The function never fails.
52  /// Calling this multiple times with the same MapComp will return identical pointers.
53  /// The maximum texture size value is respected, unless the "NoScaleDown" property is set in the MapComp.
54  virtual TextureMapI* GetTextureMap2D(const MapCompositionT& MapComp)=0;
55 
56  /// Creates a 2D texture-map from a pointer. The function never fails.
57  /// Calling this multiple times with identical paramaters will each time return a different pointer!
58  /// If MakePrivateCopy=true, the function makes a private copy of the data pointed to by Data. The caller can then free the original data.
59  /// If MakePrivateCopy=false, the function relies on the Data being valid and available during the entire lifetime of the returned texture map.
60  /// SizeX and SizeY MUST be powers of 2, and BytesPerPixel MUST be 3 or 4!
61  /// Moreover, all rows must be aligned on 4-byte boundaries! (See e.g. OpenGL Programming Guide (Red Book), p. 311.)
62  /// The maximum texture size value is NOT respected - no scaling is performed even if SizeX or SizeY exceed this value!
63  virtual TextureMapI* GetTextureMap2D(char* Data, unsigned long SizeX, unsigned long SizeY, char BytesPerPixel, bool MakePrivateCopy, const MapCompositionT& McForFiltersAndWrapping)=0;
64 
65  /// Creates a 2D texture-map from a BitmapT. The function never fails.
66  /// Calling this multiple times with identical paramaters will each time return a different pointer!
67  /// If MakePrivateCopy=true, the function makes a private copy of the data pointed to by Data. The caller can then free the original data.
68  /// If MakePrivateCopy=false, the function relies on the Bitmap being valid and available during the entire lifetime of the returned texture map.
69  /// The maximum texture size value is respected, unless the "NoScaleDown" property is set in the McForFiltersAndWrapping.
70  virtual TextureMapI* GetTextureMap2D(BitmapT* Bitmap, bool MakePrivateCopy, const MapCompositionT& McForFiltersAndWrapping)=0;
71 
72  /// Releases the texture map from the texture manager, and releases all of its resources.
73  virtual void FreeTextureMap(TextureMapI* TM)=0;
74 
75  /// Virtual destructor, so that nothing can go wrong and even g++ is happy.
76  virtual ~TextureMapManagerI() { }
77  };
78 
79 
80  /// A global pointer to the current texture-map manager, for common access by all modules that use the MatSys.
81  /// Just set this after you loaded the desired renderer DLL to the pointer returned by the DLLs GetTextureMapManager() function.
82  /// (And NULL it on unloading the DLL.)
83  /// An analogous object exists for the Renderer interface, see Renderer.hpp.
84  extern TextureMapManagerI* TextureMapManager;
85 }
86 
87 #endif
virtual ~TextureMapManagerI()
Virtual destructor, so that nothing can go wrong and even g++ is happy.
Definition: TextureMap.hpp:76
This class represents a RGBA bitmap.
Definition: Bitmap.hpp:20
virtual void SetMaxTextureSize(unsigned long MaxSize)=0
Sets the maximum side length to which textures should be scaled down before they are employed for ren...
virtual unsigned long GetMaxTextureSize() const =0
Returns the currently set maximum texture size.
This is an interface to the texture-map manager.
Definition: TextureMap.hpp:38
virtual TextureMapI * GetTextureMap2D(const MapCompositionT &MapComp)=0
Creates a 2D texture-map by a texture-map composition.
This is an interface to a texture-map.
Definition: TextureMap.hpp:23
virtual void FreeTextureMap(TextureMapI *TM)=0
Releases the texture map from the texture manager, and releases all of its resources.
A MapCompositionT is a description of how a SINGLE texture map image is composited from several sourc...
Definition: MapComposition.hpp:18