source: NonGTP/FCollada/FCDocument/FCDEffectParameterSurface.h @ 964

Revision 964, 17.6 KB checked in by igarcia, 18 years ago (diff)
Line 
1/*
2        Copyright (C) 2006 Feeling Software Inc.
3        MIT License: http://www.opensource.org/licenses/mit-license.php
4*/
5
6/**
7        @file FCDEffectParameterSurface.h
8        This file contains the FCDEffectParameterSurface class,
9        the FCDEffectParameterSurfaceInit interface and its derivate classes.
10*/
11
12#ifndef _FCD_EFFECT_PARAMETER_SURFACE_H_
13#define _FCD_EFFECT_PARAMETER_SURFACE_H_
14
15#include "FCDocument/FCDEffectParameter.h"
16
17class FCDEffectParameterSurfaceInit;
18
19/** A dynamically-sized array of COLLADA images */
20typedef vector<FCDImage*> FCDImageList;
21
22/**
23        A COLLADA surface parameter.
24        This parameters hold the texture loading information. The texture
25        placement information should be held by the sampler parameter.
26
27        @see FCDEffectParameterSampler
28
29        @ingroup FCDEffect
30*/
31class FCOLLADA_EXPORT FCDEffectParameterSurface : public FCDEffectParameter
32{
33private:
34        DeclareObjectType;
35        StringList names;
36        FCDImageList images;
37        FCDEffectParameterSurfaceInit* initMethod;
38        FMVector3 size;
39        float viewportRatio;
40        uint16 mipLevelCount;
41        bool generateMipmaps;
42
43public:
44        /** Constructor: do not use directly.
45                Instead, use the FCDEffectParameterList::AddParameter function.
46                @param document The COLLADA document that owns the effect parameter. */
47        FCDEffectParameterSurface(FCDocument* document);
48
49        /** Destructor: do not use directly.
50                Instead, use the FCDEffectParameterList::ReleaseParameter function.
51                When released, the effect parameter list will also release all
52                its parameters, if it owns them. */
53        virtual ~FCDEffectParameterSurface();
54       
55        /** Retrieves the type of effect parameter class.
56                @return The parameter class type: SURFACE. */
57        virtual Type GetType() const { return SURFACE; }
58
59        /** Retrieves the initialization method for the surface parameter.
60                The initialization method is a powerful method of describing how
61                to build complex textures, such as cube maps, from one or
62                multiple image files.
63                @return The surface initialization method. This pointer will be NULL,
64                        if no initialization method is provided. */
65        FCDEffectParameterSurfaceInit* GetInitMethod() { return initMethod; }
66        const FCDEffectParameterSurfaceInit* GetInitMethod() const { return initMethod; } /**< See above. */
67
68        /** Sets the initialization method for the surface parameter.
69                The initialization method is a powerful method of describing how
70                to build complex textures, such as cube maps, from one or
71                multiple image files.
72                @param method The new initialization method.
73                        The old initialization method will be released.
74                        You should create a new initialization method
75                        for each surface parameter. */
76        void SetInitMethod(FCDEffectParameterSurfaceInit* method);
77
78        /** Retrieves the number of COLLADA images that make up this surface.
79                There should never be more than six images to build a surface.
80                In the large majority of cases, expect one image.
81                @return The number of images. */
82        size_t GetImageCount() const { return images.size(); }
83
84        /** Retrieves the list of images that make up this surface.
85                There should never be more than six images to build a surface.
86                In the large majority of cases, expect one image.
87                @return The     list of images. */
88        FCDImageList& GetImages() { return images; }
89        const FCDImageList& GetImages() const { return images; } /**< See above. */
90
91        /** Retrieves a specific image.
92                @param index The index of the image.
93                @return The image. This pointer will be NULL if the index is out-of-bounds. */
94        FCDImage* GetImage(size_t index = 0) { return index < images.size() ? images.at(index) : NULL; }
95        const FCDImage* GetImage(size_t index = 0) const { return index < images.size() ? images.at(index) : NULL; } /**< See above. */
96
97        /** Retrieves the index that matches the given image.
98                @param image The image to match.
99                @return The index within the list for this image.
100                        This index may be -1 if no match was found. */
101        size_t FindImage(const FCDImage* image) const;
102
103        /** Adds an image to the list.
104                The initialization method indexes the images from this list.
105                This function will verify that this image does not already exist within the list,
106                so use the returned index.
107                @param image The new image.
108                @return The index of the image within the list. */
109        size_t AddImage(FCDImage* image);
110
111        /** Removes an image from the list.
112                The initialization method indexes the images from this list.
113                This function will shift all the indexes in the initialization method
114                so that they continue matching the correct image.
115                @param image The image to remove. Its memory is not released. */
116        void RemoveImage(FCDImage* image);
117
118        /** Retrieves the wanted dimensions of the surface.
119                This parameter is optional and may contain all zeroes to indicate
120                that you should read the surface dimensions from the image file(s).
121                @return The wanted dimensions. */
122        const FMVector3& GetSize() const { return size; }
123
124        /** Sets the wanted dimensions of the surface.
125                This parameter is optional and can contain all zeroes to indicate
126                that you should read the surface dimensions from the image file(s).
127                @param dimensions The wanted dimensions. */
128        void SetSize(const FMVector3& dimensions) { size = dimensions; }
129
130        /** Retrieves the viewport ratio to use when the surface is a render target.
131                @return The viewport ratio. */
132        float GetViewportRatio() const { return viewportRatio; }
133
134        /** Sets the viewport ratio to use when the surface is a render target.
135                @param ratio The viewport ratio. */
136        void SetViewportRatio(float ratio) { viewportRatio = ratio; }
137
138        /** Retrieves the wanted number of mip-levels.
139                This parameter is optional and may be zero to indicate that you should
140                retrieve the mip-levels from the image file(s) or generate a full
141                mip-chain, depending on the mip-map generate flag.
142                @see GetMipMapGenerate
143                @return The wanted number of mip-levels. */
144        uint16 GetMipLevelCount() const { return mipLevelCount; }
145
146        /** Sets the wanted number of mip-levels.
147                This parameter is optional and can be zero to indicate that you should
148                retrieve the mip-levels from the image file(s) or generate a full
149                mip-chain, depending on the mip-map generate flag.
150                @param levelCount The wanted number of mip-levels. */
151        void SetMipLevelCount(uint16 levelCount) { mipLevelCount = levelCount; }
152       
153        /** Retrieves whether to generate the mip-map levels on load.
154                The alternative is to load the mip-map levels from the image files.
155                @return Whether to generate the mip-map levels on load. */
156        bool IsGenerateMipMaps() const { return generateMipmaps; }
157
158        /** Sets whether to generate the mip-map levels of load.
159                The alternative is to load the mip-map levels from the image files.
160                @param _generateMipmaps Whether to generate the mip-map levels on load. */
161        void SetGenerateMipMaps(bool _generateMipmaps) { generateMipmaps = _generateMipmaps; }
162
163        /** Retrieves a specific sub-id.
164                @todo I'm not too sure of the implications of the names,
165                        at this level of abstraction: once I'm clear why they exists, add the
166                        necessary interface to access/pull/push items from/to the list.
167                @param index The sub-id index.
168                @return The sub-id. This pointer will be NULL if the index is out-of-bounds. */
169        const char* GetName(size_t index = 0) const { return (index < names.size()) ? names[index].c_str() : NULL; }
170
171        /** Creates a full copy of the effect parameter.
172                @todo The cloning does not clone the initialization method correctly.
173                @return The cloned effect parameter. You will need to delete this pointer. */
174        virtual FCDEffectParameter* Clone();
175
176        /** [INTERNAL] Overwrites the target parameter with this parameter.
177                This function is used during the flattening of materials.
178                @param target The target parameter to overwrite. */
179        virtual void Overwrite(FCDEffectParameter* target);
180
181        /** [INTERNAL] Reads in the effect parameter from a given COLLADA XML tree node.
182                @param parameterNode The COLLADA XML tree node.
183                @return The status of the import. If the status is not successful,
184                        it may be dangerous to extract information from the parameter.*/
185        virtual FUStatus LoadFromXML(xmlNode* parameterNode);
186
187        /** [INTERNAL] Writes out the effect parameter to the given COLLADA XML tree node.
188                @param parentNode The COLLADA XML parent node in which to insert the parameter.
189                @return The created element XML tree node. */
190        virtual xmlNode* WriteToXML(xmlNode* parentNode) const;
191};
192
193
194/**
195        [INTERNAL] The factory for COLLADA effect parameter surface initialization.
196
197        @ingroup FCDEffect
198*/
199class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitFactory
200{
201private:
202        // Never instantiate: this is a static class
203        FCDEffectParameterSurfaceInitFactory() {}
204
205public:
206
207        /** The supported initialization types. */
208        enum InitType
209        {
210                FROM, /**< Loads a surface from one simple image file. @see FCDEffectParameterSurfaceInitFrom */
211                AS_NULL, /**< No initialization. This surface may be initialized by some future effect parameter override. */
212                AS_TARGET, /**< Initializes an engine-specific render target for offscreen rendering. In this case, the dimensions should be provided by the surface effect parameter. */
213                CUBE, /**< Loads a cube-map from one complex image file or six simple image files. @see FCDEffectParameterSurfaceInitCube */
214                VOLUME, /**< Loads a 3D images for one image file. @see FCDEffectParameterSurfaceInitVolume */
215                PLANAR /**< Loads a surface from one simple image file. */
216        };
217
218        /** [INTERNAL] Creates a new effect surface initialization parameter, given a type.
219                @param type The type of initialization parameter to create.*/
220        static FCDEffectParameterSurfaceInit* Create(InitType type);
221};
222
223
224/**
225        A surface initialization method.
226        In COLLADA 1.4.1, this information was added to support complex surface types.
227        There are six types of initialization methods, described in the InitType enumerated type.
228        Expect the FROM initialization type in the large majority of cases.
229
230        @ingroup FCDEffect
231*/
232class FCOLLADA_EXPORT FCDEffectParameterSurfaceInit
233{
234public:
235        /** Constructor: builds a new surface initialization method. */
236        FCDEffectParameterSurfaceInit() {}
237
238        /** Destructor. */
239        virtual ~FCDEffectParameterSurfaceInit() {}
240
241        /** Retrieves the initialization type. You cannot modify this value.
242                To change the initialization type of a surface parameter, create a new
243                surface initialization structure of the correct type.
244                @return The initialization type. */
245        virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const = 0;
246
247        /** Copies all member variables into clone.
248                @param clone a valid pointer to a FCDEffectParameterSurfaceInit object*/
249        void Clone(FCDEffectParameterSurfaceInit* clone);
250
251        /** Creates a full copy of the surface initialization parameter.
252                @return The surface initialization parameter. You will need to delete this pointer. */
253        virtual FCDEffectParameterSurfaceInit* Clone() = 0;
254};
255
256/**
257        A cube-map surface initialization method.
258*/
259class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitCube : public FCDEffectParameterSurfaceInit
260{
261public:
262        /** The types of cube-map initializations. */
263        enum CubeType
264        {
265                ALL, /** Load all the mip-levels of all the cube-map faces from one image file. */
266                PRIMARY, /** Load the first mip-level of all the cube-map faces from one image file. */
267                FACE /** Load all the cube-map faces from separate image files. */
268        };
269
270public:
271        /** Constructor: builds a new cube-map initialization method. */
272        FCDEffectParameterSurfaceInitCube();
273
274        /** Destructor. */
275        virtual ~FCDEffectParameterSurfaceInitCube() {}
276
277        /** Retrieves the initialization type. You cannot modify this value.
278                To change the initialization type of a surface parameter, create a new
279                surface initialization structure of the correct type.
280                @return The initialization type. */
281        virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::CUBE;}
282
283        /** Creates a full copy of the surface initialization parameter.
284                @return The surface initialization parameter. You will need to delete this pointer. */
285        virtual FCDEffectParameterSurfaceInit* Clone();
286
287        /** The type of cube-map initialization. */
288        CubeType cubeType;
289       
290        /** The list of image indices.
291                The images are contained within the surface effect parameter.
292                This is used only for the FACE cube-map initialization type and indicates
293                how to match the faces of faces of the cube-map with the images in the surface effect parameter. */
294        UInt16List order;
295};
296
297/**
298        A volumetric surface initialization method.
299*/
300class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitVolume : public FCDEffectParameterSurfaceInit
301{
302public:
303        /** The types of volumetric surfaces initialization. */
304        enum VolumeType
305        {
306                ALL, /** Load all the mip-levels from the image file. */
307                PRIMARY /** Load the first mip-level from the image file. */
308        };
309
310public:
311        /** Constructor: builds a new volumetric surface initialization method. */
312        FCDEffectParameterSurfaceInitVolume();
313
314        /** Destructor. */
315        virtual ~FCDEffectParameterSurfaceInitVolume() {}
316
317        /** Retrieves the initialization type. You cannot modify this value.
318                To change the initialization type of a surface parameter, create a new
319                surface initialization structure of the correct type.
320                @return The initialization type. */
321        virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::VOLUME;}
322
323        /** Creates a full copy of the surface initialization parameter.
324                @return The surface initialization parameter. You will need to delete this pointer. */
325        virtual FCDEffectParameterSurfaceInit* Clone();
326
327        /** The type of volumetric initialization. */
328        VolumeType volumeType;
329};
330
331/**
332        A simple file surface initialization method.
333        This is the method used for backward-compatibility.
334*/
335class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitFrom : public FCDEffectParameterSurfaceInit
336{
337public:
338        /** Constructor: builds a new file surface initialization method. */
339        FCDEffectParameterSurfaceInitFrom() {}
340
341        /** Destructor. */
342        virtual ~FCDEffectParameterSurfaceInitFrom() {}
343
344        /** Retrieves the initialization type. You cannot modify this value.
345                To change the initialization type of a surface parameter, create a new
346                surface initialization structure of the correct type.
347                @return The initialization type. */
348        virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::FROM;}
349
350        /** Creates a full copy of the surface initialization parameter.
351                @return The surface initialization parameter. You will need to delete this pointer. */
352        virtual FCDEffectParameterSurfaceInit* Clone();
353
354        /** The list of mip levels. */
355        StringList mip;
356
357        /** The list of matching slices. */
358        StringList slice;
359
360        /** The list of matching faces. */
361        StringList face;
362};
363
364/**
365        This method allows to initialize the surface at a later point.
366*/
367class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitAsNull : public FCDEffectParameterSurfaceInit
368{
369public:
370        /** Constructor: builds a new file surface initialization method. */
371        FCDEffectParameterSurfaceInitAsNull() {}
372
373        /** Destructor. */
374        virtual ~FCDEffectParameterSurfaceInitAsNull() {}
375
376        /** Retrieves the initialization type. You cannot modify this value.
377                To change the initialization type of a surface parameter, create a new
378                surface initialization structure of the correct type.
379                @return The initialization type. */
380        virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::AS_NULL;}
381
382        /** Creates a full copy of the surface initialization parameter.
383                @return The surface initialization parameter. You will need to delete this pointer. */
384        virtual FCDEffectParameterSurfaceInit* Clone();
385};
386
387/**
388        This method allows to initialize the surface as a rendering target.
389*/
390class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitAsTarget : public FCDEffectParameterSurfaceInit
391{
392public:
393        /** Constructor: builds a new file surface initialization method. */
394        FCDEffectParameterSurfaceInitAsTarget() {};
395
396        /** Destructor. */
397        virtual ~FCDEffectParameterSurfaceInitAsTarget() {}
398
399        /** Retrieves the initialization type. You cannot modify this value.
400                To change the initialization type of a surface parameter, create a new
401                surface initialization structure of the correct type.
402                @return The initialization type. */
403        virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::AS_TARGET;}
404
405        /** Creates a full copy of the surface initialization parameter.
406                @return The surface initialization parameter. You will need to delete this pointer. */
407        virtual FCDEffectParameterSurfaceInit* Clone();
408};
409
410/**
411        This method allows to initialize the surface as planar.
412*/
413class FCOLLADA_EXPORT FCDEffectParameterSurfaceInitPlanar : public FCDEffectParameterSurfaceInit
414{
415public:
416        /** Constructor: builds a new file surface initialization method. */
417        FCDEffectParameterSurfaceInitPlanar() {};
418
419        /** Destructor. */
420        virtual ~FCDEffectParameterSurfaceInitPlanar() {}
421
422        /** Retrieves the initialization type. You cannot modify this value.
423                To change the initialization type of a surface parameter, create a new
424                surface initialization structure of the correct type.
425                @return The initialization type. */
426        virtual FCDEffectParameterSurfaceInitFactory::InitType GetInitType() const {return FCDEffectParameterSurfaceInitFactory::PLANAR;}
427
428        /** Creates a full copy of the surface initialization parameter.
429                @return The surface initialization parameter. You will need to delete this pointer. */
430        virtual FCDEffectParameterSurfaceInit* Clone();
431};
432
433
434
435#endif // _FCD_EFFECT_PARAMETER_SURFACE_H_
Note: See TracBrowser for help on using the repository browser.