Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGShaderParameterAccess.inl

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *               Copyright (C) 2000-2002 by the OpenSG Forum                 *
00006  *                                                                           *
00007  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00008  *                                                                           *
00009 \*---------------------------------------------------------------------------*/
00010 /*---------------------------------------------------------------------------*\
00011  *                                License                                    *
00012  *                                                                           *
00013  * This library is free software; you can redistribute it and/or modify it   *
00014  * under the terms of the GNU Library General Public License as published    *
00015  * by the Free Software Foundation, version 2.                               *
00016  *                                                                           *
00017  * This library is distributed in the hope that it will be useful, but       *
00018  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00020  * Library General Public License for more details.                          *
00021  *                                                                           *
00022  * You should have received a copy of the GNU Library General Public         *
00023  * License along with this library; if not, write to the Free Software       *
00024  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00025  *                                                                           *
00026 \*---------------------------------------------------------------------------*/
00027 /*---------------------------------------------------------------------------*\
00028  *                                Changes                                    *
00029  *                                                                           *
00030  *                                                                           *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035 \*---------------------------------------------------------------------------*/
00036 
00037 //---------------------------------------------------------------------------
00038 //  Includes
00039 //---------------------------------------------------------------------------
00040 
00041 #include <OSGConfig.h>
00042 
00043 OSG_BEGIN_NAMESPACE
00044 
00045 template<class ParameterType, class ValueType> inline
00046 bool ShaderParameterAccess::setParameter(const char *name, const ValueType &value)
00047 {
00048     if(name == NULL)
00049         return false;
00050 
00051     updateMap();
00052 
00053     parameterIt it = _parametermap.find(name);
00054     
00055     if(it != _parametermap.end())
00056     {
00057         //ParameterType::Ptr p = ParameterType::Ptr::dcast(_parameters[(*it).second]);
00058         FCPtr<ShaderParameterPtr, ParameterType> p = FCPtr<ShaderParameterPtr, ParameterType>::dcast(_parameters[(*it).second]);
00059         if(p == NullFC)
00060         {
00061             FWARNING(("ShaderParameterAccess::setParameter : Parameter '%s' has wrong type!\n", name));
00062             return false;
00063         }
00064         beginEditCP(p, ParameterType::ValueFieldMask);
00065             p->setValue(value);
00066         endEditCP(p, ParameterType::ValueFieldMask);
00067     }
00068     else
00069     {
00070         //ParameterType::Ptr p = ParameterType::create();
00071         FCPtr<ShaderParameterPtr, ParameterType> p = ParameterType::create();
00072         if(p != NullFC)
00073         {
00074             beginEditCP(p);
00075                 p->setName(name);
00076                 p->setValue(value);
00077             endEditCP(p);
00078             _parameters.push_back(p);
00079             _parametermap.insert(std::pair<std::string, UInt32>(name, _parameters.size()-1));
00080             _mapsize = _parameters.size();
00081         }
00082     }
00083     return true;
00084 }
00085 
00086 template<class ParameterType, class ValueType> inline
00087 bool ShaderParameterAccess::getParameter(const char *name, ValueType &value)
00088 {
00089     if(name == NULL)
00090         return false;
00091 
00092     updateMap();
00093 
00094     parameterIt it = _parametermap.find(name);
00095     
00096     if(it != _parametermap.end())
00097     {
00098         //ParameterType::Ptr p = ParameterType::Ptr::dcast(_parameters[(*it).second]);
00099         FCPtr<ShaderParameterPtr, ParameterType> p = FCPtr<ShaderParameterPtr, ParameterType>::dcast(_parameters[(*it).second]);
00100         if(p == NullFC)
00101         {
00102             FWARNING(("ShaderParameterAccess::getParameter : Parameter '%s' has wrong type!\n", name));
00103             return false;
00104         }
00105         value = p->getValue();
00106     }
00107     else
00108     {
00109         FINFO(("ShaderParameterAccess::getParameter : Parameter '%s' doesn't exist!\n", name));
00110         return false;
00111     }
00112     return true;
00113 }
00114 
00115 OSG_END_NAMESPACE
00116 
00117 #define OSGSHADERPARAMETERACCESS_INLINE_CVSID "@(#)$Id: OSGShaderParameterAccess.inl,v 1.10 2005/06/09 09:48:43 a-m-z Exp $"

Generated on Thu Aug 25 04:09:13 2005 for OpenSG by  doxygen 1.4.3