interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

/home/tetron/hack/vos/libs/vos/metaobjects/a3dl/texture.hh

Go to the documentation of this file.
00001 /*
00002     This file is part of the Virtual Object System of
00003     the Interreality project (http://interreality.org).
00004 
00005     Copyright (C) 2001, 2002 Peter Amstutz
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 
00021     Peter Amstutz <http://www.interreality.org>
00022 */
00023 #ifndef _TEXTURE_HH_
00024 #define _TEXTURE_HH_
00025 
00026 #include "a3dldefs.hh"
00027 #include <vos/vos/vos.hh>
00028 #include <vos/metaobjects/a3dl/material.hh>
00029 
00030 #ifndef A3DL_EXPORTS
00031 IMPORT_METAOBJECT_FACTORIES(A3DL_Texture)
00032 #endif
00033 
00034 
00035 namespace A3DL
00036 {
00037 
00038     /** @class Texture texture.hh vos/metaobjects/a3dl/texture.hh
00039      *  @ingroup libmetaobject_a3dl
00040      *
00041      *  Represents a texture layer in a 3D object's Material.
00042      *
00043      */
00044     class A3DL_API Texture : public VOS::MetaObject
00045     {
00046     public:
00047         Texture(VOS::VobjectBase* superobject);
00048         virtual ~Texture();
00049 
00050         static MetaObject* new_Texture(VOS::VobjectBase* superobject, const std::string& type);
00051         virtual const std::string getVOSType();
00052 
00053         virtual VUtil::vRef<VOS::Property> getImage();
00054         virtual void setImage(VOS::Property* p);
00055 
00056         /** Set a file backend for the image for this texture (using
00057          * FileProperty).
00058          * @see FileProperty
00059          * @throw FileAccessError if there is an error opening the file
00060          */
00061         virtual void setImageToFile(const std::string& filename, const std::string& datatype);
00062 
00063         /** Set image data */
00064         virtual void setImageData(const std::string& data, const std::string& datatype);
00065 
00066         /** Set special blend mode.
00067          *  These blend modes determine how the background
00068          *  affects the object's material.
00069          */
00070         virtual void setBlendMode(Material::BlendMode mode);
00071 
00072         /** Get special blend mode.
00073          *  These blend modes determine how the background affects the
00074          *  object's material.
00075          *  @throws Vobject::NoSuchObjectError if there is no "a3dl:blend-mode"
00076          *  property.
00077          */
00078         virtual Material::BlendMode getBlendMode();
00079 
00080         /** Get blend mode property object. */
00081         virtual VUtil::vRef<VOS::Property> getBlendModeObj();
00082 
00083         /** Set blend mode property object. */
00084         virtual void setBlendModeObj(VOS::Property* p);
00085 
00086         /** Set alpha transparency of the texture.
00087             @param a    A value between 0 (fully transparency) and 1 (no
00088                         transparency). Some renderers may round to certain
00089                         values (e.g. 1.0, 0.75, 0.5, 0.25, 0.0)
00090                         If a is > 1, 1 will be used. If a < 0, 0 will be
00091                         used.
00092         */
00093         virtual void setAlpha(double a);
00094 
00095         /** Get alpha transparency. Will be between 0 (fully transparent) and
00096             1 (no transparency)
00097          */
00098         virtual double getAlpha();
00099 
00100         /** Get alpha property. */
00101         virtual VUtil::vRef<VOS::Property> getAlphaObj();
00102 
00103         /** Set alpha property object */
00104         virtual void setAlphaObj(VOS::Property* obj);
00105 
00106         /** Set whether this layer should have shading. */
00107         virtual void setShaded(bool s);
00108 
00109         /** Get whether this layer should have shading or not.
00110          */
00111         virtual bool getShaded();
00112 
00113         /** Get shaded property object
00114          *  @throws Vobject::NoSuchObjectError if there is no "a3dl:shaded" object
00115          */
00116         virtual VUtil::vRef<VOS::Property> getShadedObj();
00117 
00118         /** Set shaded property object */
00119         virtual void setShadedObj(VOS::Property* obj);
00120 
00121         /** Set a color in the texture to be rendered transparent */
00122         virtual void setTransparentKeycolor(float r, float g, float b);
00123 
00124         /** Get the color in the texture that is rendered as transparent
00125          *  If there is no property, sets (r, g, b) to (0, 0, 0)
00126          *  @todo Throw NoSuchObjectError if there is no object-- need to
00127          *     disable keycolor if the texture image has an alpha channel.
00128          */
00129         virtual void getTransparentKeycolor(float& r, float& g, float& b);
00130 
00131         virtual void setUVScaleAndShift(float uscale, float vscale, float ushift, float vshift);
00132         virtual void getUVScaleAndShift(float& uscale, float& vscale, float& ushift, float& vshift);
00133     };
00134 
00135 }
00136 
00137 namespace VUtil {
00138     template<> inline void iteratorReleaseItem(A3DL::Texture** v)
00139     {
00140         (*v)->release();
00141     }
00142 }
00143 
00144 namespace A3DL {
00145     class TextureIterator : public VUtil::Iterator<Texture*>
00146     {
00147     public:
00148         TextureIterator() : VUtil::Iterator<Texture*>() { }
00149         TextureIterator(const TextureIterator& i) : VUtil::Iterator<Texture*>(i) { }
00150         TextureIterator(std::vector<Texture*>& vec) {
00151             items->resize(vec.size());
00152             int c = 0;
00153             for(std::vector<Texture*>::const_iterator i = vec.begin();
00154                 i != vec.end();
00155                 i++)
00156             {
00157                 (*i)->acquire();
00158                 (*items)[c] = (*i);
00159                 c++;
00160             }
00161         }
00162         VUtil::vRef<Texture> operator*() {
00163             if(pos < items->size()) return VUtil::vRef<Texture>((*items)[pos], true);
00164             else return VUtil::vRef<Texture>();
00165         }
00166     };
00167 }
00168 
00169 #endif