1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
48 #include "OSGSimpleSHLVariableChunk.h"
50 #include "OSGShaderVariables.h"
54 // Documentation for this class is emitted in the
55 // OSGSimpleSHLVariableChunkBase.cpp file.
56 // To modify it, please change the .fcd file (OSGSimpleSHLVariableChunk.fcd) and
57 // regenerate the base file.
59 /***************************************************************************\
61 \***************************************************************************/
64 volatile UInt16
SimpleSHLVariableChunk::_uiChunkCounter
= 1;
67 /***************************************************************************\
69 \***************************************************************************/
71 void SimpleSHLVariableChunk::initMethod(InitPhase ePhase
)
73 Inherited::initMethod(ePhase
);
75 if(ePhase
== TypeObject::SystemPost
)
81 /***************************************************************************\
83 \***************************************************************************/
85 /*-------------------------------------------------------------------------*\
87 \*-------------------------------------------------------------------------*/
89 /*----------------------- constructors & destructors ----------------------*/
91 SimpleSHLVariableChunk::SimpleSHLVariableChunk(void) :
97 SimpleSHLVariableChunk::SimpleSHLVariableChunk(
98 const SimpleSHLVariableChunk
&source
) :
105 SimpleSHLVariableChunk::~SimpleSHLVariableChunk(void)
109 void SimpleSHLVariableChunk::onCreate(const SimpleSHLVariableChunk
*source
)
111 Inherited::onCreate(source
);
113 if(GlobalSystemState
== Startup
)
116 _uiChunkId
= ShaderExecutableVarChunk::_uiChunkCounter
++;
119 void SimpleSHLVariableChunk::onCreateAspect(
120 const SimpleSHLVariableChunk
*createAspect
,
121 const SimpleSHLVariableChunk
*source
)
123 Inherited::onCreateAspect(createAspect
, source
);
125 _uiChunkId
= createAspect
->_uiChunkId
;
128 const StateChunkClass
*SimpleSHLVariableChunk::getClass(void) const
130 return ShaderExecutableVarChunk::getStaticClass();
133 UInt16
SimpleSHLVariableChunk::getChunkId(void)
138 /*----------------------------- class specific ----------------------------*/
140 void SimpleSHLVariableChunk::changed(ConstFieldMaskArg whichField
,
144 if(0x0000 != (whichField
& VariablesFieldMask
))
146 ShaderProgramVariables
*pVars
= _sfVariables
.getValue();
150 if(details
== 0x0001)
152 // be save reset all locations
154 if(pVars
->getMFVariables()->size() == 0)
156 editMFVariableLocations()->clear();
160 editMFVariableLocations()->resize(
161 pVars
->getMFVariables()->size(),
164 std::fill(editMFVariableLocations()->begin(),
165 editMFVariableLocations()->end (),
172 Inherited::changed(whichField
, origin
, details
);
175 bool SimpleSHLVariableChunk::subUniformVariable(const Char8
*name
)
177 if(_sfVariables
.getValue() != NULL
)
179 return _sfVariables
.getValue()->subUniformVariable(name
, NULL
, NULL
);
187 void SimpleSHLVariableChunk::clearUniformVariables(void)
189 if(_sfVariables
.getValue() == NULL
)
191 _sfVariables
.getValue()->clearUniformVariables();
195 void SimpleSHLVariableChunk::dump( UInt32
,
196 const BitVector
) const
198 SLOG
<< "Dump SimpleSHLVariableChunk NI" << std::endl
;
201 void SimpleSHLVariableChunk::activate(DrawEnv
*pEnv
, UInt32
)
203 updateVariables(pEnv
);
206 void SimpleSHLVariableChunk::changeFrom(DrawEnv
*pEnv
,
210 SimpleSHLVariableChunk
*pOld
=
211 dynamic_cast<SimpleSHLVariableChunk
*>(pOther
);
215 FWARNING(( "SimpleSHLChunk::changeFrom: caught non-SHLChunk!\n"));
219 // SimpleSHLChunk didn't change so do nothing.
223 updateVariables(pEnv
);
226 void SimpleSHLVariableChunk::deactivate(DrawEnv
*, UInt32
)
230 void SimpleSHLVariableChunk::updateVariables(DrawEnv
*pEnv
)
232 UInt32 uiProgram
= pEnv
->getActiveShader();
237 const ShaderProgramVariables::MFVariablesType
*pMFVars
= NULL
;
239 if(_sfVariables
.getValue() != NULL
)
241 pMFVars
= _sfVariables
.getValue()->getMFVariables();
244 if(pMFVars
== NULL
|| pMFVars
->size() == 0)
249 MFInt32
&vVarLocations
= *this->editMFVariableLocations();
251 OSG_ASSERT(pMFVars
->size() == vVarLocations
.size());
253 MFInt32::iterator mLocIt
= vVarLocations
.begin();
255 ShaderProgramVariables::MFVariablesType::const_iterator mVarIt
=
257 ShaderProgramVariables::MFVariablesType::const_iterator mVarEnd
=
260 bool warnUnknown
= true;
262 for(; mVarIt
!= mVarEnd
; ++mVarIt
, ++mLocIt
)
264 ShaderVariable
*pVar
= *mVarIt
;
269 osgUniformShaderVariableSwitch(pEnv
, pVar
,
270 *mLocIt
, uiProgram
, warnUnknown
);