Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics
[Home] [Tutorials] [All Classes] [Grouped Classes]

X:/dropbox/visualizationlibrary/src/vlGraphics/UniformSet.cpp

Go to the documentation of this file.
00001 /**************************************************************************************/
00002 /*                                                                                    */
00003 /*  Visualization Library                                                             */
00004 /*  http://www.visualizationlibrary.org                                               */
00005 /*                                                                                    */
00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
00007 /*  All rights reserved.                                                              */
00008 /*                                                                                    */
00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
00010 /*  are permitted provided that the following conditions are met:                     */
00011 /*                                                                                    */
00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
00013 /*  list of conditions and the following disclaimer.                                  */
00014 /*                                                                                    */
00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
00017 /*  other materials provided with the distribution.                                   */
00018 /*                                                                                    */
00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
00029 /*                                                                                    */
00030 /**************************************************************************************/
00031 
00032 #include <vlGraphics/UniformSet.hpp>
00033 
00034 using namespace vl;
00035 
00036 //-----------------------------------------------------------------------------
00037 UniformSet& UniformSet::deepCopyFrom(const UniformSet& other)
00038 {
00039   mUniforms = other.mUniforms;
00040   for(size_t i=0; i<mUniforms.size(); ++i)
00041     mUniforms[i] = mUniforms[i]->clone();
00042   return *this;
00043 }
00044 //-----------------------------------------------------------------------------
00045 void UniformSet::setUniform(Uniform* uniform, bool check_for_doubles) 
00046 { 
00047   VL_CHECK(uniform)
00048   if (uniform == NULL)
00049     return;
00050   if ( check_for_doubles )
00051   {
00052     for(unsigned i=0; i<mUniforms.size(); ++i)
00053     {
00054       if (mUniforms[i]->name() == uniform->name())
00055       {
00056         mUniforms[i] = uniform;
00057         return;
00058       }
00059     }
00060   }
00061   mUniforms.push_back( uniform );
00062 }
00063 //-----------------------------------------------------------------------------
00064 void UniformSet::eraseUniform(const char* name) 
00065 { 
00066   for(unsigned i=0; i<mUniforms.size(); ++i)
00067     if (mUniforms[i]->name() == name)
00068     {
00069       mUniforms.erase( mUniforms.begin() + i );
00070       return;
00071     }
00072 }
00073 //-----------------------------------------------------------------------------
00074 void UniformSet::eraseUniform(const Uniform* uniform) 
00075 { 
00076   for(unsigned i=0; i<mUniforms.size(); ++i)
00077     if (mUniforms[i] == uniform)
00078     {
00079       mUniforms.erase( mUniforms.begin() + i );
00080       return;
00081     }
00082 }
00083 //-----------------------------------------------------------------------------
00084 Uniform* UniformSet::gocUniform(const char* name)
00085 { 
00086   for(unsigned i=0; i<mUniforms.size(); ++i)
00087     if (mUniforms[i]->name() == name)
00088       return mUniforms[i].get();
00089   ref<Uniform> uniform = new Uniform;
00090   uniform->setName( name );
00091   mUniforms.push_back(uniform);
00092   return uniform.get();
00093 }
00094 //-----------------------------------------------------------------------------
00095 Uniform* UniformSet::getUniform(const char* name)
00096 { 
00097   for(unsigned i=0; i<mUniforms.size(); ++i)
00098     if (mUniforms[i]->name() == name)
00099       return mUniforms[i].get();
00100   return NULL;
00101 }
00102 //-----------------------------------------------------------------------------
00103 const Uniform* UniformSet::getUniform(const char* name) const
00104 { 
00105   for(unsigned i=0; i<mUniforms.size(); ++i)
00106     if (mUniforms[i]->name() == name)
00107       return mUniforms[i].get();
00108   return NULL;
00109 }
00110 //-----------------------------------------------------------------------------

Visualization Library 2011.09.1160 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 2 2013 13:40:42.
Permission is granted to use this page to write and publish articles regarding Visualization Library.