18 #include <osg/GLExtensions>
19 #include <osg/StateSet>
21 #include <osg/Uniform>
22 #include <osg/BufferObject>
23 #include <osg/Observer>
26 #include <osg/ShaderComposer>
27 #include <osg/FrameStamp>
28 #include <osg/DisplaySettings>
29 #include <osg/Polytope>
30 #include <osg/Viewport>
31 #include <osg/GLBeginEndAdapter>
32 #include <osg/ArrayDispatchers>
33 #include <osg/GraphicsCostEstimator>
41 #ifndef GL_FOG_COORDINATE_ARRAY
42 #ifdef GL_FOG_COORDINATE_ARRAY_EXT
43 #define GL_FOG_COORDINATE_ARRAY GL_FOG_COORDINATE_ARRAY_EXT
45 #define GL_FOG_COORDINATE_ARRAY 0x8457
49 #ifndef GL_SECONDARY_COLOR_ARRAY
50 #ifdef GL_SECONDARY_COLOR_ARRAY_EXT
51 #define GL_SECONDARY_COLOR_ARRAY GL_SECONDARY_COLOR_ARRAY_EXT
53 #define GL_SECONDARY_COLOR_ARRAY 0x845E
61 #define OSG_GL_DEBUG(message) \
62 if (state.getFineGrainedErrorDetection()) \
64 GLenum errorNo = glGetError(); \
65 if (errorNo!=GL_NO_ERROR) \
67 osg::notify(WARN)<<"Warning: detected OpenGL error '"<<gluErrorString(errorNo)<<" "<<message<<endl; \
73 class GraphicsContext;
87 VertexAttribAlias(GLuint location,
const std::string glName,
const std::string osgName,
const std::string& declaration):
148 inline void setContextID(
unsigned int contextID) { _contextID=contextID; }
155 typedef std::map<const std::type_info*, osg::ref_ptr<osg::Referenced> >
ExtensionMap;
163 const std::type_info* id(&
typeid(T));
167 ptr =
new T(_contextID);
169 return static_cast<T*
>(ptr.
get());
178 const std::type_info* id(&
typeid(T));
179 ExtensionMap::const_iterator itr = _extensionMap.find(
id);
180 if (itr==_extensionMap.end())
return 0;
181 else return itr->second.get();
207 up.first =
const_cast<Uniform*
>(uniform);
213 void pushStateSet(
const StateSet* dstate);
220 void popAllStateSets();
223 void insertStateSet(
unsigned int pos,
const StateSet* dstate);
226 void removeStateSet(
unsigned int pos);
241 void captureCurrentState(
StateSet& stateset)
const;
244 void releaseGLObjects();
272 void updateModelViewAndProjectionMatrixUniforms();
274 void applyModelViewAndProjectionUniformsIfRequired();
291 void resetVertexAttributeAlias(
bool compactAliasing=
true,
unsigned int numTextureUnits=8);
321 bool convertVertexShaderSourceToOsgBuiltIns(std::string& source)
const;
334 void applyShaderComposition();
360 return _modeMap[mode].global_default_value;
377 return applyMode(mode,enabled,ms);
382 ModeMap& modeMap = getOrCreateTextureModeMap(unit);
389 ModeMap& modeMap = getOrCreateTextureModeMap(unit);
396 ModeMap& modeMap = getOrCreateTextureModeMap(unit);
399 return applyModeOnTexUnit(unit,mode,enabled,ms);
419 return applyAttribute(attribute,as);
424 AttributeMap& attributeMap = getOrCreateTextureAttributeMap(unit);
431 AttributeMap& attributeMap = getOrCreateTextureAttributeMap(unit);
439 AttributeMap& attributeMap = getOrCreateTextureAttributeMap(unit);
442 return applyAttributeOnTexUnit(unit,attribute,as);
478 void haveAppliedTextureAttribute(
unsigned int unit,
const StateAttribute* attribute);
497 void dirtyAllModes();
500 void dirtyAllAttributes();
503 void disableAllVertexArrays();
506 void dirtyAllVertexArrays();
513 if (vbo == _currentVBO)
return;
521 if (!_currentVBO)
return;
531 if (ebo == _currentEBO)
return;
539 if (!_currentEBO)
return;
549 if (pbo == _currentPBO)
return;
559 if (!_currentPBO)
return;
566 IndicesGLushort _quadIndicesGLushort[4];
569 IndicesGLuint _quadIndicesGLuint[4];
571 void drawQuads(GLint first, GLsizei count, GLsizei primCount=0);
575 if (primcount>=1 && _glDrawArraysInstanced!=0) _glDrawArraysInstanced(mode, first, count, primcount);
576 else glDrawArrays(mode, first, count);
581 if (primcount>=1 && _glDrawElementsInstanced!=0) _glDrawElementsInstanced(mode, count, type, indices, primcount);
582 else glDrawElements(mode, count, type, indices);
588 #if defined(OSG_GL_VERTEX_FUNCS_AVAILABLE) && !defined(OSG_GLES1_AVAILABLE)
589 if (_useVertexAttributeAliasing) _glVertexAttrib4f( _vertexAlias._location, x,y,z,
w);
590 else glVertex4f(x,y,z,
w);
592 _glVertexAttrib4f( _vertexAlias._location, x,y,z,
w);
596 inline void Color(
float r,
float g,
float b,
float a=1.0f)
598 #ifdef OSG_GL_VERTEX_FUNCS_AVAILABLE
599 if (_useVertexAttributeAliasing) _glVertexAttrib4f( _colorAlias._location, r,g,b,a);
600 else glColor4f(r,g,b,a);
602 _glVertexAttrib4f( _colorAlias._location, r,g,b,a);
608 #ifdef OSG_GL_VERTEX_FUNCS_AVAILABLE
609 if (_useVertexAttributeAliasing) _glVertexAttrib4f( _normalAlias._location, x,y,z,0.0);
610 else glNormal3f(x,y,z);
612 _glVertexAttrib4f( _normalAlias._location, x,y,z,0.0);
618 #if !defined(OSG_GLES1_AVAILABLE)
619 #ifdef OSG_GL_VERTEX_FUNCS_AVAILABLE
620 if (_useVertexAttributeAliasing) _glVertexAttrib4f( _texCoordAliasList[0]._location, x,
y,
z,
w);
621 else glTexCoord4f(x,
y,
z,
w);
623 _glVertexAttrib4f( _texCoordAliasList[0]._location, x,
y,
z,
w);
630 #if !defined(OSG_GLES1_AVAILABLE)
631 #ifdef OSG_GL_VERTEX_FUNCS_AVAILABLE
632 if (_useVertexAttributeAliasing) _glVertexAttrib4f( _texCoordAliasList[unit]._location, x,
y,
z,
w);
635 _glVertexAttrib4f( _texCoordAliasList[unit]._location, x,
y,
z,
w);
640 void VerteAttrib(
unsigned int location,
float x,
float y=0.0f,
float z=0.0f,
float w=0.0f)
642 _glVertexAttrib4f( location, x,
y,
z,
w);
647 void lazyDisablingOfVertexAttributes();
650 void applyDisablingOfVertexAttributes();
655 void setInterleavedArrays( GLenum
format, GLsizei stride,
const GLvoid* pointer);
665 bindVertexBufferObject(vbo);
670 unbindVertexBufferObject();
681 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
682 if (_useVertexAttributeAliasing)
684 setVertexAttribPointer(_vertexAlias._location, size, type,
normalized, stride, ptr);
688 if (!_vertexArray._enabled || _vertexArray._dirty)
690 _vertexArray._enabled =
true;
691 glEnableClientState(GL_VERTEX_ARRAY);
695 _vertexArray._pointer=ptr;
696 glVertexPointer( size, type, stride, ptr );
698 _vertexArray._lazy_disable =
false;
699 _vertexArray._dirty =
false;
703 setVertexAttribPointer(_vertexAlias._location, size, type,
normalized, stride, ptr);
711 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
712 if (_useVertexAttributeAliasing)
714 disableVertexAttribPointer(_vertexAlias._location);
718 if (_vertexArray._enabled || _vertexArray._dirty)
720 _vertexArray._lazy_disable =
false;
721 _vertexArray._enabled =
false;
722 _vertexArray._dirty =
false;
723 glDisableClientState(GL_VERTEX_ARRAY);
727 disableVertexAttribPointer(_vertexAlias._location);
733 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
734 if (_useVertexAttributeAliasing)
736 dirtyVertexAttribPointer(_vertexAlias._location);
740 _vertexArray._pointer = 0;
741 _vertexArray._dirty =
true;
744 dirtyVertexAttribPointer(_vertexAlias._location);
757 bindVertexBufferObject(vbo);
762 unbindVertexBufferObject();
771 const GLvoid *ptr, GLboolean
normalized=GL_FALSE )
773 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
774 if (_useVertexAttributeAliasing)
776 setVertexAttribPointer(_normalAlias._location, 3, type,
normalized, stride, ptr);
780 if (!_normalArray._enabled || _normalArray._dirty)
782 _normalArray._enabled =
true;
783 glEnableClientState(GL_NORMAL_ARRAY);
787 _normalArray._pointer=ptr;
788 glNormalPointer( type, stride, ptr );
790 _normalArray._lazy_disable =
false;
791 _normalArray._dirty =
false;
795 setVertexAttribPointer(_normalAlias._location, 3, type,
normalized, stride, ptr);
803 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
804 if (_useVertexAttributeAliasing)
806 disableVertexAttribPointer(_normalAlias._location);
810 if (_normalArray._enabled || _normalArray._dirty)
812 _normalArray._lazy_disable =
false;
813 _normalArray._enabled =
false;
814 _normalArray._dirty =
false;
815 glDisableClientState(GL_NORMAL_ARRAY);
819 disableVertexAttribPointer(_normalAlias._location);
825 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
826 if (_useVertexAttributeAliasing)
828 dirtyVertexAttribPointer(_normalAlias._location);
832 _normalArray._pointer = 0;
833 _normalArray._dirty =
true;
836 dirtyVertexAttribPointer(_normalAlias._location);
848 bindVertexBufferObject(vbo);
853 unbindVertexBufferObject();
865 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
866 if (_useVertexAttributeAliasing)
868 setVertexAttribPointer(_colorAlias._location, size, type,
normalized, stride, ptr);
872 if (!_colorArray._enabled || _colorArray._dirty)
874 _colorArray._enabled =
true;
875 glEnableClientState(GL_COLOR_ARRAY);
879 _colorArray._pointer=ptr;
880 glColorPointer( size, type, stride, ptr );
882 _colorArray._lazy_disable =
false;
883 _colorArray._dirty =
false;
887 setVertexAttribPointer(_colorAlias._location, size, type,
normalized, stride, ptr);
895 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
896 if (_useVertexAttributeAliasing)
898 disableVertexAttribPointer(_colorAlias._location);
902 if (_colorArray._enabled || _colorArray._dirty)
904 _colorArray._lazy_disable =
false;
905 _colorArray._enabled =
false;
906 _colorArray._dirty =
false;
907 glDisableClientState(GL_COLOR_ARRAY);
911 disableVertexAttribPointer(_colorAlias._location);
917 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
918 if (_useVertexAttributeAliasing)
920 dirtyVertexAttribPointer(_colorAlias._location);
924 _colorArray._pointer = 0;
925 _colorArray._dirty =
true;
928 dirtyVertexAttribPointer(_colorAlias._location);
933 inline bool isSecondaryColorSupported()
const {
return _isSecondaryColorSupportResolved?_isSecondaryColorSupported:computeSecondaryColorSupported(); }
944 bindVertexBufferObject(vbo);
949 unbindVertexBufferObject();
957 void setSecondaryColorPointer( GLint size, GLenum
type, GLsizei stride,
const GLvoid *ptr, GLboolean normalized=GL_TRUE );
963 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
964 if (_useVertexAttributeAliasing)
966 disableVertexAttribPointer(_secondaryColorAlias._location);
970 if (_secondaryColorArray._enabled || _secondaryColorArray._dirty)
972 _secondaryColorArray._lazy_disable =
false;
973 _secondaryColorArray._enabled =
false;
974 _secondaryColorArray._dirty =
false;
979 disableVertexAttribPointer(_secondaryColorAlias._location);
985 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
986 if (_useVertexAttributeAliasing)
988 dirtyVertexAttribPointer(_secondaryColorAlias._location);
992 _secondaryColorArray._pointer = 0;
993 _secondaryColorArray._dirty =
true;
996 dirtyVertexAttribPointer(_secondaryColorAlias._location);
1000 inline bool isFogCoordSupported()
const {
return _isFogCoordSupportResolved?_isFogCoordSupported:computeFogCoordSupported(); }
1011 bindVertexBufferObject(vbo);
1016 unbindVertexBufferObject();
1025 void setFogCoordPointer( GLenum
type, GLsizei stride,
const GLvoid *ptr, GLboolean normalized=GL_FALSE );
1031 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
1032 if (_useVertexAttributeAliasing)
1034 disableVertexAttribPointer(_fogCoordAlias._location);
1038 if (_fogArray._enabled || _fogArray._dirty)
1040 _fogArray._lazy_disable =
false;
1041 _fogArray._enabled =
false;
1042 _fogArray._dirty =
false;
1047 disableVertexAttribPointer(_fogCoordAlias._location);
1053 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
1054 if (_useVertexAttributeAliasing)
1056 dirtyVertexAttribPointer(_fogCoordAlias._location);
1060 _fogArray._pointer = 0;
1061 _fogArray._dirty =
true;
1064 dirtyVertexAttribPointer(_fogCoordAlias._location);
1078 bindVertexBufferObject(vbo);
1083 unbindVertexBufferObject();
1092 GLint size, GLenum
type,
1095 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
1096 if (_useVertexAttributeAliasing)
1098 setVertexAttribPointer(_texCoordAliasList[unit]._location, size, type,
normalized, stride, ptr);
1102 if (setClientActiveTextureUnit(unit))
1104 if ( unit >= _texCoordArrayList.size()) _texCoordArrayList.resize(unit+1);
1110 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1114 glTexCoordPointer( size, type, stride, ptr );
1123 setVertexAttribPointer(_texCoordAliasList[unit]._location, size, type,
normalized, stride, ptr);
1131 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
1132 if (_useVertexAttributeAliasing)
1134 disableVertexAttribPointer(_texCoordAliasList[unit]._location);
1138 if ( unit >= _texCoordArrayList.size()) _texCoordArrayList.resize(unit+1);
1143 if(setClientActiveTextureUnit(unit))
1148 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1153 disableVertexAttribPointer(_texCoordAliasList[unit]._location);
1159 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
1160 if (_useVertexAttributeAliasing)
1162 dirtyVertexAttribPointer(_texCoordAliasList[unit]._location);
1166 if ( unit >= _texCoordArrayList.size())
return;
1172 dirtyVertexAttribPointer(_texCoordAliasList[unit]._location);
1179 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
1180 if (_useVertexAttributeAliasing)
1182 disableVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location);
1186 while (unit<_texCoordArrayList.size())
1191 if (setClientActiveTextureUnit(unit))
1196 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1203 disableVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location);
1209 #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
1210 if (_useVertexAttributeAliasing)
1212 dirtyVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location);
1216 while (unit<_texCoordArrayList.size())
1225 dirtyVertexAttribPointersAboveAndIncluding(_texCoordAliasList[unit]._location);
1240 inline bool setActiveTextureUnit(
unsigned int unit );
1248 bool setClientActiveTextureUnit(
unsigned int unit );
1261 bindVertexBufferObject(vbo);
1266 unbindVertexBufferObject();
1280 bindVertexBufferObject(vbo);
1285 unbindVertexBufferObject();
1299 bindVertexBufferObject(vbo);
1304 unbindVertexBufferObject();
1312 void setVertexAttribPointer(
unsigned int index,
1313 GLint size, GLenum
type, GLboolean normalized,
1314 GLsizei stride,
const GLvoid *ptr );
1318 void setVertexAttribIPointer(
unsigned int index,
1319 GLint size, GLenum
type,
1320 GLsizei stride,
const GLvoid *ptr );
1324 void setVertexAttribLPointer(
unsigned int index,
1325 GLint size, GLenum
type,
1326 GLsizei stride,
const GLvoid *ptr );
1330 void disableVertexAttribPointer(
unsigned int index );
1332 void disableVertexAttribPointersAboveAndIncluding(
unsigned int index );
1336 if (index<_vertexAttribArrayList.size())
1346 while (index<_vertexAttribArrayList.size())
1360 if (_lastAppliedProgramObject!=program)
1362 _lastAppliedProgramObject = program;
1367 inline GLint
getUniformLocation(
unsigned int uniformNameID )
const {
return _lastAppliedProgramObject ? _lastAppliedProgramObject->getUniformLocation(uniformNameID) : -1; }
1376 inline GLint
getUniformLocation(
const std::string & uniformName )
const {
return _lastAppliedProgramObject ? _lastAppliedProgramObject->getUniformLocation(uniformName) : -1; }
1377 inline GLint
getAttribLocation(
const std::string& name )
const {
return _lastAppliedProgramObject ? _lastAppliedProgramObject->getAttribLocation(name) : -1; }
1379 typedef std::pair<const StateAttribute*,StateAttribute::OverrideValue>
AttributePair;
1430 if (_dynamicObjectCount != count)
1432 _dynamicObjectCount = count;
1433 if (_dynamicObjectCount==0 && callCallbackOnZero && _completeDynamicObjectRenderingCallback.valid())
1435 _completeDynamicObjectRenderingCallback->completed(
this);
1447 --_dynamicObjectCount;
1448 if (_dynamicObjectCount==0 && _completeDynamicObjectRenderingCallback.valid())
1450 _completeDynamicObjectRenderingCallback->completed(
this);
1454 void setMaxTexturePoolSize(
unsigned int size);
1457 void setMaxBufferObjectPoolSize(
unsigned int size);
1482 bool checkGLErrors(
const char* str)
const;
1487 void print(std::ostream& fout)
const;
1490 void initializeExtensionProcs();
1527 _gpuTimestamp = timestamp;
1533 virtual void frameCompleted();
1538 typedef std::vector<StateAttribute::GLModeValue>
ValueVec;
1544 last_applied_value =
false;
1545 global_default_value =
false;
1548 void print(std::ostream& fout)
const;
1562 last_applied_attribute = 0L;
1563 last_applied_shadercomponent = 0L;
1564 global_default_attribute = 0L;
1568 void print(std::ostream& fout)
const;
1581 typedef std::pair<const Uniform*,StateAttribute::OverrideValue>
UniformPair;
1586 void print(std::ostream& fout)
const;
1598 void print(std::ostream& fout)
const;
1614 bool updateCurrentDefines();
1618 typedef std::map<StateAttribute::GLMode,ModeStack>
ModeMap;
1621 typedef std::map<StateAttribute::TypeMemberPair,AttributeStack>
AttributeMap;
1639 bool supportsShaderRequirement(
const std::string& shaderRequirement);
1686 void setUpVertexAttribAlias(
VertexAttribAlias& alias, GLuint location,
const std::string glName,
const std::string osgName,
const std::string& declaration);
1702 if (enabled) glEnable(mode);
1703 else glDisable(mode);
1705 if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors(mode);
1717 if (setActiveTextureUnit(unit))
1721 if (enabled) glEnable(mode);
1722 else glDisable(mode);
1724 if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors(mode);
1743 attribute->
apply(*
this);
1749 _shaderCompositionDirty =
true;
1752 if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors(attribute);
1764 if (setActiveTextureUnit(unit))
1769 attribute->
apply(*
this);
1775 _shaderCompositionDirty =
true;
1778 if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors(attribute);
1802 _shaderCompositionDirty =
true;
1817 if (setActiveTextureUnit(unit))
1827 _shaderCompositionDirty =
true;
1858 EnabledArrayPair():_lazy_disable(false),_dirty(true),_enabled(false),_normalized(0),_pointer(0) {}
1859 EnabledArrayPair(
const EnabledArrayPair& eap):_lazy_disable(eap._lazy_disable),_dirty(eap._dirty), _enabled(eap._enabled),_normalized(eap._normalized),_pointer(eap._pointer) {}
1889 if (unit>=_textureModeMapList.size()) _textureModeMapList.resize(unit+1);
1890 return _textureModeMapList[unit];
1896 if (unit>=_textureAttributeMapList.size()) _textureAttributeMapList.resize(unit+1);
1897 return _textureAttributeMapList[unit];
1915 inline void applyModeMap(ModeMap& modeMap);
1916 inline void applyAttributeMap(AttributeMap& attributeMap);
1917 inline void applyUniformMap(UniformMap& uniformMap);
1919 inline void applyModeListOnTexUnit(
unsigned int unit,ModeMap& modeMap,
const StateSet::ModeList& modeList);
1920 inline void applyAttributeListOnTexUnit(
unsigned int unit,AttributeMap& attributeMap,
const StateSet::AttributeList& attributeList);
1922 inline void applyModeMapOnTexUnit(
unsigned int unit,ModeMap& modeMap);
1923 inline void applyAttributeMapOnTexUnit(
unsigned int unit,AttributeMap& attributeMap);
1927 void haveAppliedAttribute(AttributeMap& attributeMap,
const StateAttribute* attribute);
1932 void loadModelViewMatrix();
1937 bool computeSecondaryColorSupported()
const;
1941 bool computeFogCoordSupported()
const;
1945 bool computeVertexBufferObjectSupported()
const;
1951 typedef void (
GL_APIENTRY * VertexAttrib4fProc)(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat
w);
1960 typedef void (
GL_APIENTRY * DrawArraysInstancedProc)( GLenum mode, GLint first, GLsizei count, GLsizei primcount );
1961 typedef void (
GL_APIENTRY * DrawElementsInstancedProc)( GLenum mode, GLsizei count, GLenum
type,
const GLvoid *indices, GLsizei primcount );
2000 for(StateSet::ModeList::const_iterator mitr=modeList.begin();
2001 mitr!=modeList.end();
2009 ms.
valueVec.push_back(mitr->second);
2019 ms.
valueVec.push_back(mitr->second);
2027 for(StateSet::AttributeList::const_iterator aitr=attributeList.begin();
2028 aitr!=attributeList.end();
2037 AttributePair(aitr->second.first.get(),aitr->second.second));
2048 AttributePair(aitr->second.first.get(),aitr->second.second));
2057 for(StateSet::UniformList::const_iterator aitr=uniformList.begin();
2058 aitr!=uniformList.end();
2085 for(StateSet::DefineList::const_iterator aitr=defineList.begin();
2086 aitr!=defineList.end();
2111 bool changed = (dv[dv.size()-2].first==dv[dv.size()-1].first);
2123 for(StateSet::ModeList::const_iterator mitr=modeList.begin();
2124 mitr!=modeList.end();
2139 for(StateSet::AttributeList::const_iterator aitr=attributeList.begin();
2140 aitr!=attributeList.end();
2155 for(StateSet::UniformList::const_iterator aitr=uniformList.begin();
2156 aitr!=uniformList.end();
2170 for(StateSet::DefineList::const_iterator aitr=defineList.begin();
2171 aitr!=defineList.end();
2180 if ((dv.size()<2) || (dv[dv.size()-2].first!=dv.back().first))
2192 StateSet::ModeList::const_iterator ds_mitr = modeList.begin();
2193 ModeMap::iterator this_mitr=modeMap.begin();
2195 while (this_mitr!=modeMap.end() && ds_mitr!=modeList.end())
2197 if (this_mitr->first<ds_mitr->first)
2208 applyMode(this_mitr->first,new_value,ms);
2222 else if (ds_mitr->first<this_mitr->first)
2227 ModeStack& ms = modeMap[ds_mitr->first];
2253 applyMode(this_mitr->first,new_value,ms);
2261 if (
applyMode(ds_mitr->first,new_value,ms))
2274 this_mitr!=modeMap.end();
2285 applyMode(this_mitr->first,new_value,ms);
2299 ds_mitr!=modeList.end();
2302 ModeStack& ms = modeMap[ds_mitr->first];
2314 StateSet::ModeList::const_iterator ds_mitr = modeList.begin();
2315 ModeMap::iterator this_mitr=modeMap.begin();
2317 while (this_mitr!=modeMap.end() && ds_mitr!=modeList.end())
2319 if (this_mitr->first<ds_mitr->first)
2344 else if (ds_mitr->first<this_mitr->first)
2349 ModeStack& ms = modeMap[ds_mitr->first];
2396 this_mitr!=modeMap.end();
2421 ds_mitr!=modeList.end();
2424 ModeStack& ms = modeMap[ds_mitr->first];
2436 StateSet::AttributeList::const_iterator ds_aitr=attributeList.begin();
2438 AttributeMap::iterator this_aitr=attributeMap.begin();
2440 while (this_aitr!=attributeMap.end() && ds_aitr!=attributeList.end())
2442 if (this_aitr->first<ds_aitr->first)
2464 else if (ds_aitr->first<this_aitr->first)
2514 this_aitr!=attributeMap.end();
2536 ds_aitr!=attributeList.end();
2554 StateSet::AttributeList::const_iterator ds_aitr=attributeList.begin();
2556 AttributeMap::iterator this_aitr=attributeMap.begin();
2558 while (this_aitr!=attributeMap.end() && ds_aitr!=attributeList.end())
2560 if (this_aitr->first<ds_aitr->first)
2582 else if (ds_aitr->first<this_aitr->first)
2632 this_aitr!=attributeMap.end();
2654 ds_aitr!=attributeList.end();
2674 StateSet::UniformList::const_iterator ds_aitr=uniformList.begin();
2676 UniformMap::iterator this_aitr=uniformMap.begin();
2678 while (this_aitr!=uniformMap.end() && ds_aitr!=uniformList.end())
2680 if (this_aitr->first<ds_aitr->first)
2692 else if (ds_aitr->first<this_aitr->first)
2723 this_aitr!=uniformMap.end();
2736 ds_aitr!=uniformList.end();
2746 StateSet::DefineList::const_iterator dl_itr = defineList.begin();
2747 DefineMap::DefineStackMap::iterator dm_itr = defineMap.
map.begin();
2752 while (dm_itr!=defineMap.
map.end() && dl_itr!=defineList.end())
2754 if (dm_itr->first<dl_itr->first)
2762 else if (dl_itr->first<dm_itr->first)
2794 dm_itr!=defineMap.
map.end();
2805 dl_itr!=defineList.end();
2814 for(ModeMap::iterator mitr=modeMap.begin();
2815 mitr!=modeMap.end();
2840 for(ModeMap::iterator mitr=modeMap.begin();
2841 mitr!=modeMap.end();
2866 for(AttributeMap::iterator aitr=attributeMap.begin();
2867 aitr!=attributeMap.end();
2890 for(AttributeMap::iterator aitr=attributeMap.begin();
2891 aitr!=attributeMap.end();
2916 for(UniformMap::iterator aitr=uniformMap.begin();
2917 aitr!=uniformMap.end();
2946 template<>
inline GLExtensions* State::get<GLExtensions>() {
return _glExtensions.get(); }
2947 template<>
inline const GLExtensions* State::get<GLExtensions>()
const {
return _glExtensions.get(); }
void setGlobalDefaultTextureModeValue(unsigned int unit, StateAttribute::GLMode mode, bool enabled)
void applyUniformList(UniformMap &uniformMap, const StateSet::UniformList &uniformList)
const VertexAttribAlias & getSecondaryColorAlias()
void setColorAlias(const VertexAttribAlias &alias)
void applyDefineList(DefineMap &uniformMap, const StateSet::DefineList &defineList)
std::vector< StateAttribute::GLModeValue > ValueVec
void disableColorPointer()
StateSetStack & getStateSetStack()
GLint getAttribLocation(const std::string &name) const
SecondaryColorPointerProc _glSecondaryColorPointer
void setTexCoordPointer(unsigned int unit, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE)
virtual void apply(State &) const
void apply(const Uniform &uniform) const
GLint getDataSize() const
TypeMemberPair getTypeMemberPair() const
void setVertexAttribPointer(unsigned int unit, const Array *array)
void applyAttributeMapOnTexUnit(unsigned int unit, AttributeMap &attributeMap)
void disableNormalPointer()
GLfloat GLfloat GLfloat GLfloat w
#define GL_PIXEL_UNPACK_BUFFER_ARB
AttributeMap _attributeMap
void setTexCoordAliasList(const VertexAttribAliasList &aliasList)
VertexAttribPointerProc _glVertexAttribPointer
void Color(float r, float g, float b, float a=1.0f)
void setGraphicsCostEstimator(GraphicsCostEstimator *gce)
std::vector< const StateSet * > StateSetStack
StateSetStack _stateStateStack
VertexAttrib4fvProc _glVertexAttrib4fv
GLint _glMaxTextureCoords
VertexAttribIPointerProc _glVertexAttribIPointer
bool * _abortRenderingPtr
void setNormalAlias(const VertexAttribAlias &alias)
virtual Object * cloneType() const =0
EnabledArrayPair(const EnabledArrayPair &eap)
const VertexAttribAlias & getNormalAlias()
#define GL_FOG_COORDINATE_ARRAY
void setVertexAttribLPointer(unsigned int unit, const Array *array)
bool getAbortRendering() const
std::map< std::string, UniformStack > UniformMap
bool global_default_value
bool applyModeOnTexUnit(unsigned int unit, StateAttribute::GLMode mode, bool enabled, ModeStack &ms)
void applyModeMapOnTexUnit(unsigned int unit, ModeMap &modeMap)
const VertexAttribAlias & getFogCoordAlias()
VertexAttribAlias _colorAlias
void TexCoord(float x, float y=0.0f, float z=0.0f, float w=1.0f)
void pushAttributeList(AttributeMap &attributeMap, const StateSet::AttributeList &attributeList)
ref_ptr< FrameStamp > _frameStamp
std::pair< const StateAttribute *, StateAttribute::OverrideValue > AttributePair
void setVertexPointer(const Array *array)
unsigned int getMaxBufferObjectPoolSize() const
const FrameStamp * getFrameStamp() const
StateSet::DefineList currentDefines
ref_ptr< Uniform > _modelViewMatrixUniform
ref_ptr< DisplaySettings > _displaySettings
void applyAttributeListOnTexUnit(unsigned int unit, AttributeMap &attributeMap, const StateSet::AttributeList &attributeList)
FrameStamp * getFrameStamp()
unsigned int _maxTexturePoolSize
bool _useModelViewAndProjectionUniforms
StateSet::UniformList & getCurrentShaderCompositionUniformList()
bool getModeValidity(StateAttribute::GLMode mode)
Program::AttribBindingList _attributeBindingList
bool _extensionProcsInitialized
FogCoordPointerProc _glFogCoordPointer
void setTexCoordPointer(unsigned int unit, const Array *array)
void setCurrentPixelBufferObject(osg::GLBufferObject *pbo)
const AttributeMap & getAttributeMap() const
AttributeMap & getOrCreateTextureAttributeMap(unsigned int unit)
void unbindPixelBufferObject()
CheckForGLErrors getCheckForGLErrors() const
void setLastAppliedProgramObject(const Program::PerContextProgram *program)
void setCheckForGLErrors(CheckForGLErrors check)
void setFogCoordPointer(const Array *array)
VertexAttribAlias _normalAlias
ArrayDispatchers & getArrayDispatchers()
double delta_s(Timer_t t1, Timer_t t2) const
void setGlobalDefaultAttribute(const StateAttribute *attribute)
const StateAttribute * last_applied_attribute
GLint getUniformLocation(const std::string &uniformName) const
void applyAttributeMap(AttributeMap &attributeMap)
void setDisplaySettings(DisplaySettings *vs)
bool getGlobalDefaultTextureModeValue(unsigned int unit, StateAttribute::GLMode mode)
GraphicsContext * _graphicsContext
bool _isVertexBufferObjectSupported
void dirtyTexCoordPointersAboveAndIncluding(unsigned int unit)
void dirtySecondaryColorPointer()
ref_ptr< Uniform > _projectionMatrixUniform
void dirtyVertexAttribPointersAboveAndIncluding(unsigned int index)
bool getUseModelViewAndProjectionUniforms() const
EnabledVertexAttribArrayList _vertexAttribArrayList
bool _isSecondaryColorSupportResolved
VertexAttribLPointerProc _glVertexAttribLPointer
unsigned int _currentActiveTextureUnit
osg::ref_ptr< DynamicObjectRenderingCompletedCallback > _completeDynamicObjectRenderingCallback
DefineMap & getDefineMap()
const TextureModeMapList & getTextureModeMapList() const
std::set< std::string > ShaderDefines
ref_ptr< const RefMatrix > _identity
std::pair< ref_ptr< Uniform >, StateAttribute::OverrideValue > RefUniformPair
std::map< std::string, DefinePair > DefineList
Timer_t getGpuTick() const
ref_ptr< const RefMatrix > _modelView
bool applyGlobalDefaultAttributeOnTexUnit(unsigned int unit, AttributeStack &as)
void glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
const osg::Matrix & getProjectionMatrix() const
void Vertex(float x, float y, float z, float w=1.0f)
std::map< StateAttribute::GLMode, StateAttribute::GLModeValue > ModeList
EnabledArrayPair _secondaryColorArray
ShaderComposer * getShaderComposer()
const Program::PerContextProgram * getLastAppliedProgramObject() const
bool _shaderCompositionEnabled
void setShaderComposer(ShaderComposer *sc)
osg::Uniform * getProjectionMatrixUniform()
bool applyMode(StateAttribute::GLMode mode, bool enabled, ModeStack &ms)
VertexAttribAlias(const VertexAttribAlias &rhs)
const osg::Matrix & getModelViewMatrix() const
std::vector< AttributePair > AttributeVec
void applyAttributeList(AttributeMap &attributeMap, const StateSet::AttributeList &attributeList)
std::vector< StateSet::DefinePair > DefineVec
const osg::Matrix & getInitialViewMatrix() const
ShaderComponent * getShaderComponent()
osg::Program * _currentShaderCompositionProgram
ref_ptr< const RefMatrix > _projection
bool applyMode(StateAttribute::GLMode mode, bool enabled)
unsigned long long Timer_t
void VerteAttrib(unsigned int location, float x, float y=0.0f, float z=0.0f, float w=0.0f)
StateSet::UniformList _currentShaderCompositionUniformList
const UniformMap & getUniformMap() const
void setTimestampBits(int bits)
VertexAttrib4fProc _glVertexAttrib4f
GraphicsCostEstimator * getGraphicsCostEstimator()
const Program::AttribBindingList & getAttributeBindingList()
EnableVertexAttribProc _glEnableVertexAttribArray
const VertexAttribAlias & getVertexAlias()
void setColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_TRUE)
TextureAttributeMapList _textureAttributeMapList
unsigned int OverrideValue
void popAttributeList(AttributeMap &attributeMap, const StateSet::AttributeList &attributeList)
osg::ref_ptr< ShaderComposer > _shaderComposer
static Timer * instance()
std::vector< AttributeMap > TextureAttributeMapList
DrawElementsInstancedProc _glDrawElementsInstanced
std::map< StateAttribute::TypeMemberPair, RefAttributePair > AttributeList
void popStateSetStackToSize(unsigned int size)
void dirtyNormalPointer()
int getTimestampBits() const
unsigned int getDynamicObjectCount() const
VertexAttribAlias _vertexAlias
void setVertexAlias(const VertexAttribAlias &alias)
const TextureAttributeMapList & getTextureAttributeMapList() const
unsigned int getActiveTextureUnit() const
#define GL_ARRAY_BUFFER_ARB
AttributeVec & getAttributeVec(const osg::StateAttribute *attribute)
void applyShaderCompositionUniform(const osg::Uniform *uniform, StateAttribute::OverrideValue value=StateAttribute::ON)
void setGraphicsContext(GraphicsContext *context)
bool applyAttributeOnTexUnit(unsigned int unit, const StateAttribute *attribute, AttributeStack &as)
const GraphicsContext * getGraphicsContext() const
bool _isSecondaryColorSupported
void pushUniformList(UniformMap &uniformMap, const StateSet::UniformList &uniformList)
bool isVertexBufferObjectSupported() const
TextureModeMapList _textureModeMapList
const DisplaySettings * getDisplaySettings() const
std::vector< GLuint > IndicesGLuint
void setSecondaryColorPointer(const Array *array)
const StateAttribute * getGlobalDefaultAttribute(StateAttribute::Type type, unsigned int member=0)
typedef void(GL_APIENTRY *GLTexImage3DProc)(GLenum target
#define GL_ELEMENT_ARRAY_BUFFER_ARB
GLBufferObject * _currentPBO
GLsizeiptr getOffset(unsigned int i) const
unsigned int getBufferIndex() const
std::vector< EnabledArrayPair > EnabledTexCoordArrayList
const std::string & getName() const
osg::Uniform * getModelViewMatrixUniform()
bool isSecondaryColorSupported() const
GraphicsContext * getGraphicsContext()
const DefineMap & getDefineMap() const
GLint getMaxTextureUnits() const
For GL>=2.0 uses GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, for GL<2 uses GL_MAX_TEXTURE_UNITS.
void setFrameStamp(FrameStamp *fs)
const osg::Matrix & getInitialInverseViewMatrix() const
void applyUniformMap(UniformMap &uniformMap)
DynamicObjectRenderingCompletedCallback * getDynamicObjectRenderingCompletedCallback()
const GLBufferObject * getCurrentElementBufferObject()
const ShaderComposer * getShaderComposer() const
ActiveTextureProc _glClientActiveTexture
bool applyTextureAttribute(unsigned int unit, const StateAttribute *attribute)
bool applyTextureMode(unsigned int unit, StateAttribute::GLMode mode, bool enabled)
void disableTexCoordPointersAboveAndIncluding(unsigned int unit)
const VertexAttribAlias & getColorAlias()
EnabledArrayPair _fogArray
GLint getMaxTextureCoords() const
For GL>=2.0 uses GL_MAX_TEXTURE_COORDS, for GL<2 uses GL_MAX_TEXTURE_UNITS.
void setColorPointer(const Array *array)
double getGpuTime() const
void dirtyTexCoordPointer(unsigned int unit)
unsigned int getContextID() const
void applyModeListOnTexUnit(unsigned int unit, ModeMap &modeMap, const StateSet::ModeList &modeList)
osg::Uniform * getNormalMatrixUniform()
const VertexAttribAliasList & getTexCoordAliasList()
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
std::map< std::string, DefineStack > DefineStackMap
GLenum getDataType() const
const Viewport * getCurrentViewport() const
void setCurrentElementBufferObject(osg::GLBufferObject *ebo)
bool _shaderCompositionDirty
bool _isVertexBufferObjectSupportResolved
AttributeVec attributeVec
GLBufferObject * getOrCreateGLBufferObject(unsigned int contextID) const
void setUseModelViewAndProjectionUniforms(bool flag)
GLint getUniformLocation(unsigned int uniformNameID) const
ExtensionMap _extensionMap
void setFogCoordAlias(const VertexAttribAlias &alias)
std::vector< EnabledArrayPair > EnabledVertexAttribArrayList
void setCurrentVertexBufferObject(osg::GLBufferObject *vbo)
void setVertexAttribIPointer(unsigned int unit, const Array *array)
GLBufferObject * _currentEBO
std::vector< VertexAttribAlias > VertexAttribAliasList
GLuint64 getGpuTimestamp() const
std::vector< GLushort > IndicesGLushort
void MultiTexCoord(unsigned int unit, float x, float y=0.0f, float z=0.0f, float w=1.0f)
void setUseVertexAttributeAliasing(bool flag)
osg::ref_ptr< GraphicsCostEstimator > _graphicsCostEstimator
EnabledArrayPair _normalArray
void pushDefineList(DefineMap &defineMap, const StateSet::DefineList &defineList)
std::map< std::string, GLuint > AttribBindingList
void disableSecondaryColorPointer()
ref_ptr< const RefMatrix > _initialViewMatrix
bool getGlobalDefaultModeValue(StateAttribute::GLMode mode)
unsigned int _currentClientActiveTextureUnit
const Program::PerContextProgram * _lastAppliedProgramObject
void bindElementBufferObject(osg::GLBufferObject *ebo)
GLBeginEndAdapter & getGLBeginEndAdapter()
bool applyAttribute(const StateAttribute *attribute)
VertexAttribAlias _secondaryColorAlias
std::map< StateAttribute::GLMode, ModeStack > ModeMap
ref_ptr< Uniform > _modelViewProjectionMatrixUniform
bool _isFogCoordSupportResolved
osg::ref_ptr< GLExtensions > _glExtensions
const GLBufferObject * getCurrentVertexBufferObject()
void setGlobalDefaultModeValue(StateAttribute::GLMode mode, bool enabled)
const ShaderComponent * last_applied_shadercomponent
DrawArraysInstancedProc _glDrawArraysInstanced
void unbindVertexBufferObject()
void dirtyVertexPointer()
void setAbortRenderingPtr(bool *abortPtr)
void disableTexCoordPointer(unsigned int unit)
std::map< std::string, RefUniformPair > UniformList
GLfloat GLfloat GLfloat z
void setAttributeBindingList(const Program::AttribBindingList &attribBindingList)
bool _useVertexAttributeAliasing
void applyModeList(ModeMap &modeMap, const StateSet::ModeList &modeList)
void setShaderCompositionEnabled(bool flag)
ModeMap & getOrCreateTextureModeMap(unsigned int unit)
EnabledTexCoordArrayList _texCoordArrayList
ref_ptr< const StateAttribute > global_default_attribute
unsigned int _dynamicObjectCount
void disableVertexPointer()
bool isFogCoordSupported() const
GLBeginEndAdapter _glBeginEndAdapter
void setGlobalDefaultTextureAttribute(unsigned int unit, const StateAttribute *attribute)
void setContextID(unsigned int contextID)
unsigned int getStateSetStackSize()
void popModeList(ModeMap &modeMap, const StateSet::ModeList &modeList)
CheckForGLErrors _checkGLErrors
void setNormalPointer(const Array *array)
std::pair< std::string, StateAttribute::OverrideValue > DefinePair
bool setActiveTextureUnit(unsigned int unit)
void setDynamicObjectRenderingCompletedCallback(DynamicObjectRenderingCompletedCallback *cb)
void unbindElementBufferObject()
bool _isFogCoordSupported
void dirtyFogCoordPointer()
bool applyGlobalDefaultAttribute(AttributeStack &as)
bool getShaderCompositionEnabled() const
void setDynamicObjectCount(unsigned int count, bool callCallbackOnZero=false)
void setNormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE)
std::map< const std::type_info *, osg::ref_ptr< osg::Referenced > > ExtensionMap
ref_ptr< Uniform > _normalMatrixUniform
void decrementDynamicObjectCount()
GLBufferObject * _currentVBO
bool getUseVertexAttributeAliasing() const
DisableVertexAttribProc _glDisableVertexAttribArray
BindBufferProc _glBindBuffer
std::map< StateAttribute::TypeMemberPair, AttributeStack > AttributeMap
void setSecondaryColorAlias(const VertexAttribAlias &alias)
bool applyAttribute(const StateAttribute *attribute, AttributeStack &as)
void popDefineList(DefineMap &uniformMap, const StateSet::DefineList &defineList)
std::vector< ref_ptr< const Matrix > > MatrixStack
const GLBufferObject * getCurrentPixelBufferObject()
void pushModeList(ModeMap &modeMap, const StateSet::ModeList &modeList)
EnabledArrayPair _colorArray
unsigned int _maxBufferObjectPoolSize
void bindPixelBufferObject(osg::GLBufferObject *pbo)
void Normal(float x, float y, float z)
osg::Uniform * getModelViewProjectionMatrixUniform()
void bindVertexBufferObject(osg::GLBufferObject *vbo)
ArrayDispatchers _arrayDispatchers
virtual const GLvoid * getDataPointer() const =0
const StateAttribute * getGlobalDefaultTextureAttribute(unsigned int unit, StateAttribute::Type type, unsigned int member=0)
VertexAttribAlias(GLuint location, const std::string glName, const std::string osgName, const std::string &declaration)
void applyModeMap(ModeMap &modeMap)
const GraphicsCostEstimator * getGraphicsCostEstimator() const
VertexAttribAliasList _texCoordAliasList
void glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
void setGpuTimestamp(Timer_t tick, GLuint64 timestamp)
ActiveTextureProc _glActiveTexture
GLsizei const GLvoid * pointer
const ModeMap & getModeMap() const
void popUniformList(UniformMap &uniformMap, const StateSet::UniformList &uniformList)
VertexAttribAlias _fogCoordAlias
unsigned int getMaxTexturePoolSize() const
Matrix _initialInverseViewMatrix
EnabledArrayPair _vertexArray
void setVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized=GL_FALSE)
void setModeValidity(StateAttribute::GLMode mode, bool valid)
Timer_t getStartTick() const
std::pair< Type, unsigned int > TypeMemberPair
unsigned int getClientActiveTextureUnit() const
void disableFogCoordPointer()
bool getNormalize() const
MultiTexCoord4fProc _glMultiTexCoord4f
void dirtyVertexAttribPointer(unsigned int index)
void setStartTick(Timer_t tick)
#define GL_SECONDARY_COLOR_ARRAY
ref_ptr< RefMatrix > _modelViewCache
std::vector< ModeMap > TextureModeMapList
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format