~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to libshadervm/dsoshadeops.h

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
Import upstream version 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Aqsis
 
2
// Copyright � 1997 - 2001, Paul C. Gregory
 
3
//
 
4
// Contact: pgregory@aqsis.com
 
5
// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public // License as published by the Free Software Foundation; either
 
6
// version 2 of the License, or (at your option) any later version.  // // This library is distributed in the hope that it will be useful,
 
7
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
8
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
9
// General Public License for more details.
 
10
//
 
11
// You should have received a copy of the GNU General Public
 
12
// License along with this library; if not, write to the Free Software
 
13
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
14
 
 
15
 
 
16
/** \file
 
17
                \brief  Classes and structures for supporting DSOs
 
18
                \author Tristan Colgate <tristan@inuxtech.co.uk>
 
19
*/
 
20
 
 
21
#ifndef DSOSHADEOPS_H
 
22
#define DSOSHADEOPS_H
 
23
 
 
24
#include        "aqsis.h"
 
25
 
 
26
#include        <stack>
 
27
#include        <vector>
 
28
#include        <list>
 
29
#include        <map>
 
30
 
 
31
#include        "vector3d.h"
 
32
#include        "vector4d.h"
 
33
#include        "color.h"
 
34
#include        "sstring.h"
 
35
#include        "matrix.h"
 
36
#include        "ishaderdata.h"
 
37
#include        "bitvector.h"
 
38
#include        "shadervariable.h"
 
39
 
 
40
#include        "ishaderdata.h"
 
41
#include        "plugins.h"
 
42
#include        "idsoshadeops.h"
 
43
#include        "shadeop.h"
 
44
 
 
45
START_NAMESPACE( Aqsis )
 
46
 
 
47
//---------------------------------------------------------------------
 
48
/**   CqDSORepository: This class is responsible for searching for shader
 
49
 * operations in extrnal shared libraries. 
 
50
 */
 
51
class CqDSORepository: public IqDSORepository, private CqPluginBase{
 
52
 
 
53
private:
 
54
    //
 
55
    //---------------------------------------------------------------------
 
56
    /** Mapping of type names and ID's that we can handle in DSO's. The type
 
57
     * ID's are as presented from the SL compiler, the type names are those that 
 
58
     * may be used by DSO shadeop table function prototypes.
 
59
     */
 
60
    void BuildTypeMaps(void)
 
61
    {
 
62
        m_TypeNameMap["invalid"] = type_invalid;
 
63
        m_TypeIdMap['@'] = type_invalid;
 
64
        m_TypeNameMap["integer"] = type_integer;
 
65
        m_TypeIdMap['i'] = type_integer;
 
66
        m_TypeNameMap["float"] = type_float;
 
67
        m_TypeIdMap['f'] = type_float;
 
68
        m_TypeNameMap["point"] = type_point;
 
69
        m_TypeIdMap['p'] = type_point;
 
70
        m_TypeNameMap["string"] = type_string;
 
71
        m_TypeIdMap['s'] = type_string;
 
72
        m_TypeNameMap["color"] = type_color;
 
73
        m_TypeIdMap['c'] = type_color;
 
74
        m_TypeNameMap["triple"] = type_triple;
 
75
        m_TypeIdMap['t'] = type_triple;
 
76
        m_TypeNameMap["hpoint"] = type_hpoint;
 
77
        m_TypeIdMap['h'] = type_hpoint;
 
78
        m_TypeNameMap["normal"] = type_normal;
 
79
        m_TypeIdMap['n'] = type_normal;
 
80
        m_TypeNameMap["vector"] = type_vector;
 
81
        m_TypeIdMap['v'] = type_vector;
 
82
        m_TypeNameMap["void"] = type_void;
 
83
        m_TypeIdMap['x'] = type_void;
 
84
        m_TypeNameMap["matrix"] = type_matrix;
 
85
        m_TypeIdMap['m'] = type_matrix;
 
86
        m_TypeNameMap["hextuple"] = type_sixteentuple; // ??
 
87
        m_TypeIdMap['w'] = type_sixteentuple;
 
88
    };
 
89
 
 
90
public:
 
91
    virtual void SetDSOPath(const CqString*);
 
92
    CqString strPrototype(CqString*, SqDSOExternalCall*);
 
93
 
 
94
    CqDSORepository(CqString *searchpath): CqPluginBase()
 
95
    {
 
96
        BuildTypeMaps();
 
97
        SetDSOPath(searchpath);
 
98
    };
 
99
 
 
100
    CqDSORepository(): CqPluginBase()
 
101
    {
 
102
        BuildTypeMaps();
 
103
    };
 
104
 
 
105
 
 
106
    //---------------------------------------------------------------------
 
107
    /**   The Destructor handles the calling of shutdown on any previously
 
108
     * initialised DSO shadeops.
 
109
     */
 
110
    virtual ~CqDSORepository()
 
111
    {
 
112
        // We should call shutdown for all init'd functions
 
113
        while( ( m_itActiveDSOMap = m_ActiveDSOMap.begin() ) != m_ActiveDSOMap.end()){
 
114
 
 
115
            std::list<SqDSOExternalCall *> *list = (*m_itActiveDSOMap).second;
 
116
 
 
117
            while( !list->empty() )
 
118
            {
 
119
                SqDSOExternalCall *item = list->front();
 
120
 
 
121
                if(item->shutdown != NULL &&
 
122
                        item->initialised)
 
123
                    item->shutdown(item->initData);
 
124
 
 
125
                delete item;
 
126
                list->pop_front();
 
127
            };
 
128
            delete list;
 
129
            m_ActiveDSOMap.erase(m_itActiveDSOMap);
 
130
        };
 
131
    };
 
132
 
 
133
    // Utility to provide a formatted function prototype
 
134
    CqString strPtototype(SqDSOExternalCall*);
 
135
 
 
136
protected:
 
137
    //A maps and iterators for the Type name/id mappings
 
138
    std::map<CqString,EqVariableType> m_TypeNameMap ;
 
139
    std::map<CqString,EqVariableType>::iterator m_itTypeNameMap ;
 
140
    std::map<TqChar,EqVariableType> m_TypeIdMap ;
 
141
    std::map<TqChar,EqVariableType>::iterator m_itTypeIdMap ;
 
142
 
 
143
    // A list of files (possibly also directories in future) to be searched for shadeops
 
144
    std::list<CqString*> m_pDSOPathList;
 
145
    // This is a map of shadeop names to descriptors of shadeop implementations that we
 
146
    // have already found, its for efficiency and to allow us to track initiliased shadeops
 
147
    // to be shutdown later.
 
148
    std::map<CqString,std::list<SqDSOExternalCall*> *> m_ActiveDSOMap;
 
149
    std::map<CqString,std::list<SqDSOExternalCall*> *>::iterator m_itActiveDSOMap;
 
150
 
 
151
    // Get Array of DSO entry points for a specific shadeop
 
152
    std::list<SqDSOExternalCall*>* getShadeOpMethods(CqString*);
 
153
 
 
154
    // Parse a single DSO SHADEOP_TABLE rntry
 
155
    SqDSOExternalCall* parseShadeOpTableEntry(void*, SqShadeOp*);
 
156
};
 
157
 
 
158
END_NAMESPACE( Aqsis )
 
159
 
 
160
#endif  // DSOSHADEOPS_H