File: VirtualProgram.h

package info (click to toggle)
openscenegraph 3.2.3%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 32,820 kB
  • ctags: 34,610
  • sloc: cpp: 370,040; ansic: 9,071; java: 1,020; yacc: 548; objc: 288; makefile: 285; xml: 155; lex: 151
file content (62 lines) | stat: -rw-r--r-- 2,418 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef _VIRTUAL_PROGRAM__
#define _VIRTUAL_PROGRAM__ 1

#include<string>
#include<map>
#include<osg/Shader>
#include<osg/Program>

////////////////////////////////////////////////////////////////////////////////
namespace osgCandidate {
////////////////////////////////////////////////////////////////////////////////
class VirtualProgram: public osg::Program
{
public: 
    VirtualProgram( unsigned int mask = 0xFFFFFFFFUL );

    virtual ~VirtualProgram( void );

    VirtualProgram( const VirtualProgram& VirtualProgram, 
                    const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY );

    META_StateAttribute( osgCandidate, VirtualProgram, Type( PROGRAM ) )

    /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
    virtual int compare(const StateAttribute& sa) const
    {
       // check the types are equal and then create the rhs variable
       // used by the COMPARE_StateAttribute_Parameter macros below.
       COMPARE_StateAttribute_Types(VirtualProgram,sa)

       // compare each parameter in turn against the rhs.
       COMPARE_StateAttribute_Parameter(_mask)
       COMPARE_StateAttribute_Parameter(_shaderMap)
       return 0; // passed all the above comparison macros, must be equal.
    }

    /** If enabled, activate our program in the GL pipeline,
     * performing any rebuild operations that might be pending. */
    virtual void  apply(osg::State& state) const;

    osg::Shader* getShader            ( const std::string & shaderSemantic,
                                        osg::Shader::Type type );
    
    osg::Shader* setShader            ( const std::string & shaderSemantic,
                                        osg::Shader * shader );

protected:
    typedef std::vector< osg::ref_ptr< osg::Shader > >            ShaderList;
    typedef std::pair< std::string, osg::Shader::Type >           ShaderSemantic;
    typedef std::map< ShaderSemantic, osg::ref_ptr<osg::Shader> > ShaderMap;
    typedef std::map< ShaderList, osg::ref_ptr<osg::Program> >    ProgramMap;

    mutable ProgramMap                   _programMap;
    ShaderMap                            _shaderMap;
    unsigned int                         _mask;
}; // class VirtualProgram
////////////////////////////////////////////////////////////////////////////////

} // namespace osgCandidate
////////////////////////////////////////////////////////////////////////////////
#endif