Visualization Library 2.0.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
UniformSet.cpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
33 
34 using namespace vl;
35 
36 //-----------------------------------------------------------------------------
38 {
39  mUniforms = other.mUniforms;
40  for(size_t i=0; i<mUniforms.size(); ++i)
41  mUniforms[i] = mUniforms[i]->clone();
42  return *this;
43 }
44 //-----------------------------------------------------------------------------
45 void UniformSet::setUniform(Uniform* uniform, bool check_for_doubles)
46 {
47  VL_CHECK(uniform)
48  if (uniform == NULL)
49  return;
50  if ( check_for_doubles )
51  {
52  for(unsigned i=0; i<mUniforms.size(); ++i)
53  {
54  if (mUniforms[i]->name() == uniform->name())
55  {
56  mUniforms[i] = uniform;
57  return;
58  }
59  }
60  }
61  mUniforms.push_back( uniform );
62 }
63 //-----------------------------------------------------------------------------
64 void UniformSet::eraseUniform(const char* name)
65 {
66  for(unsigned i=0; i<mUniforms.size(); ++i)
67  if (mUniforms[i]->name() == name)
68  {
69  mUniforms.erase( mUniforms.begin() + i );
70  return;
71  }
72 }
73 //-----------------------------------------------------------------------------
74 void UniformSet::eraseUniform(const Uniform* uniform)
75 {
76  for(unsigned i=0; i<mUniforms.size(); ++i)
77  if (mUniforms[i] == uniform)
78  {
79  mUniforms.erase( mUniforms.begin() + i );
80  return;
81  }
82 }
83 //-----------------------------------------------------------------------------
84 Uniform* UniformSet::gocUniform(const char* name)
85 {
86  for(unsigned i=0; i<mUniforms.size(); ++i)
87  if (mUniforms[i]->name() == name)
88  return mUniforms[i].get();
89  ref<Uniform> uniform = new Uniform;
90  uniform->setName( name );
91  mUniforms.push_back(uniform);
92  return uniform.get();
93 }
94 //-----------------------------------------------------------------------------
95 Uniform* UniformSet::getUniform(const char* name)
96 {
97  for(unsigned i=0; i<mUniforms.size(); ++i)
98  if (mUniforms[i]->name() == name)
99  return mUniforms[i].get();
100  return NULL;
101 }
102 //-----------------------------------------------------------------------------
103 const Uniform* UniformSet::getUniform(const char* name) const
104 {
105  for(unsigned i=0; i<mUniforms.size(); ++i)
106  if (mUniforms[i]->name() == name)
107  return mUniforms[i].get();
108  return NULL;
109 }
110 //-----------------------------------------------------------------------------
Wraps an OpenGL Shading Language uniform to be associated to a GLSLProgram (see vl::GLSLProgram docum...
Definition: Uniform.hpp:59
const T * get() const
Definition: Object.hpp:128
Uniform * gocUniform(const char *name)
Definition: UniformSet.cpp:84
void setUniform(Uniform *uniform, bool check_for_doubles=true)
Definition: UniformSet.cpp:45
void eraseUniform(const char *name)
Definition: UniformSet.cpp:64
Visualization Library main namespace.
std::vector< ref< Uniform > > mUniforms
Definition: UniformSet.hpp:85
const std::string & name() const
Returns the name of the uniform variable.
Definition: Uniform.hpp:86
#define NULL
Definition: OpenGLDefs.hpp:81
Uniform * getUniform(const char *name)
Definition: UniformSet.cpp:95
void setName(const char *name)
Sets the name of the uniform variable.
Definition: Uniform.hpp:92
A set of Uniform objects managed by a Shader.
Definition: UniformSet.hpp:50
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
UniformSet & deepCopyFrom(const UniformSet &other)
Definition: UniformSet.cpp:37
#define VL_CHECK(expr)
Definition: checks.hpp:73