Visualization Library 2.1.0

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
RenderStateSet.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 
34 #include <vlGraphics/GLSL.hpp>
35 
36 using namespace vl;
37 
38 //------------------------------------------------------------------------------
40 {
42  for(size_t i=0; i<mRenderStates.size(); ++i)
43  mRenderStates[i].mRS = mRenderStates[i].mRS->clone();
44  return *this;
45 }
46 //------------------------------------------------------------------------------
47 void RenderStateSet::setRenderState(RenderState* renderstate, int index)
48 {
49  if (renderstate)
50  {
51  if (renderstate->type() == RS_GLSLProgram)
52  mGLSLProgram = static_cast<GLSLProgram*>(renderstate);
53  for(unsigned i=0; i<mRenderStates.size(); ++i)
54  {
55  if (mRenderStates[i].mRS->type() == renderstate->type() && mRenderStates[i].mIndex == index)
56  {
57  mRenderStates[i].mRS = renderstate;
58  // mRenderStates[i].mIndex = index;
59  return;
60  }
61  }
62  mRenderStates.push_back( RenderStateSlot(renderstate, index) );
63  }
64 }
65 //------------------------------------------------------------------------------
67 {
68  for(unsigned i=0; i<mRenderStates.size(); ++i)
69  if (mRenderStates[i].mRS->type() == type && mRenderStates[i].mIndex == index)
70  return mRenderStates[i].mRS.get();
71  return NULL;
72 }
73 //------------------------------------------------------------------------------
74 const RenderState* RenderStateSet::renderState( ERenderState type, int index ) const
75 {
76  for(unsigned i=0; i<mRenderStates.size(); ++i)
77  if (mRenderStates[i].mRS->type() == type && mRenderStates[i].mIndex == index)
78  return mRenderStates[i].mRS.get();
79  return NULL;
80 }
81 //------------------------------------------------------------------------------
83 {
84  if (type == RS_GLSLProgram)
86  for(unsigned i=0; i<mRenderStates.size(); ++i)
87  {
88  if (mRenderStates[i].mRS->type() == type && (index == mRenderStates[i].mIndex || index == -1))
89  {
90  mRenderStates.erase(mRenderStates.begin() + i);
91  if (index == -1)
92  continue; // just for clarity
93  else
94  return;
95  }
96  }
97 }
98 //------------------------------------------------------------------------------
std::vector< RenderStateSlot > mRenderStates
GLSLProgram * mGLSLProgram
ERenderState
RenderState * renderState(ERenderState type, int index=-1)
Visualization Library main namespace.
Base class for most of the OpenGL render state wrapper classes.
Definition: RenderState.hpp:50
RenderStateSet & deepCopyFrom(const RenderStateSet &other)
void eraseRenderState(ERenderState type, int index)
If index == -1 all the renderstates of the given type are removed regardless of their binding index...
#define NULL
Definition: OpenGLDefs.hpp:81
A set of RenderState objects managed by a Shader.
void setRenderState(RenderState *renderstate, int index)
virtual ERenderState type() const
Definition: RenderState.hpp:59