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

« back to all changes in this revision

Viewing changes to libri2rib/dictionary.cpp

  • 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
//
 
6
// This library is free software; you can redistribute it and/or
 
7
// modify it under the terms of the GNU Lesser General Public
 
8
// License as published by the Free Software Foundation; either
 
9
// version 2.1 of the License, or (at your option) any later version.
 
10
//
 
11
// This library is distributed in the hope that it will be useful,
 
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
// General Public License for more details.
 
15
//
 
16
// You should have received a copy of the GNU General Public
 
17
// License along with this library; if not, write to the Free Software
 
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 
 
20
/** \file
 
21
 *  \brief This dictionary can handle inline declaration as described in RiSpec V3.2
 
22
 *  \author Lionel J. Lacour (intuition01@online.fr)
 
23
 */
 
24
 
 
25
#ifdef DEBUG
 
26
#include <iostream.h>
 
27
#include <iomanip.h>
 
28
#endif
 
29
#include "dictionary.h"
 
30
#include "inlineparse.h"
 
31
#include "error.h"
 
32
 
 
33
USING_NAMESPACE( libri2rib );
 
34
 
 
35
#ifdef DEBUG
 
36
using std::cout;
 
37
using std::endl;
 
38
 
 
39
void SqTokenEntry::printClassType ()
 
40
{
 
41
    cout << setw( 9 );
 
42
    switch ( tclass )
 
43
    {
 
44
    case CONSTANT: cout << "CONSTANT"; break;
 
45
    case UNIFORM: cout << "UNIFORM"; break;
 
46
    case VARYING: cout << "VARYING"; break;
 
47
    case VERTEX: cout << "VERTEX"; break;
 
48
        case FACEVARYING: cout <<"FACEVARYING";
 
49
    }
 
50
    cout << setw( 8 );
 
51
    switch ( ttype )
 
52
    {
 
53
    case HPOINT: cout << "HPOINT"; break;
 
54
    case MATRIX: cout << "MATRIX"; break;
 
55
    case NORMAL: cout << "NORMAL"; break;
 
56
    case VECTOR: cout << "VECTOR"; break;
 
57
    case FLOAT: cout << "FLOAT"; break;
 
58
    case INTEGER: cout << "INTEGER"; break;
 
59
    case STRING: cout << "STRING"; break;
 
60
    case POINT: cout << "POINT"; break;
 
61
    case COLOR: cout << "COLOR";
 
62
    }
 
63
}
 
64
#endif
 
65
 
 
66
 
 
67
 
 
68
CqDictionary::CqDictionary()
 
69
{
 
70
    addToken( RI_KA, UNIFORM, FLOAT );
 
71
    addToken( RI_KD, UNIFORM, FLOAT );
 
72
    addToken( RI_KS, UNIFORM, FLOAT );
 
73
    addToken( RI_KR, UNIFORM, FLOAT );
 
74
    addToken( RI_ROUGHNESS, UNIFORM, FLOAT );
 
75
    addToken( RI_TEXTURENAME, UNIFORM, STRING );
 
76
    addToken( RI_SPECULARCOLOR, UNIFORM, COLOR );
 
77
    addToken( RI_INTENSITY, UNIFORM, FLOAT );
 
78
    addToken( RI_LIGHTCOLOR, UNIFORM, COLOR );
 
79
    addToken( RI_FROM, UNIFORM, POINT );
 
80
    addToken( RI_TO, UNIFORM, POINT );
 
81
    addToken( RI_CONEANGLE, UNIFORM, FLOAT );
 
82
    addToken( RI_CONEDELTAANGLE, UNIFORM, FLOAT );
 
83
    addToken( RI_BEAMDISTRIBUTION, UNIFORM, FLOAT );
 
84
    addToken( RI_MINDISTANCE, UNIFORM, FLOAT );
 
85
    addToken( RI_MAXDISTANCE, UNIFORM, FLOAT );
 
86
    addToken( RI_DISTANCE, UNIFORM, FLOAT );
 
87
    addToken( RI_BACKGROUND, UNIFORM, COLOR );
 
88
    addToken( RI_FOV, UNIFORM, FLOAT );
 
89
    addToken( RI_P, VERTEX, POINT );
 
90
    addToken( RI_PZ, VERTEX, POINT );
 
91
    addToken( RI_PW, VERTEX, HPOINT );
 
92
    addToken( RI_N, VARYING, NORMAL );
 
93
    addToken( RI_NP, UNIFORM, NORMAL );
 
94
    addToken( RI_CS, VARYING, COLOR );
 
95
    addToken( RI_OS, VARYING, COLOR );
 
96
    addToken( RI_S, VARYING, FLOAT );
 
97
    addToken( RI_T, VARYING, FLOAT );
 
98
    addToken( RI_ST, VARYING, FLOAT, 2 );
 
99
 
 
100
    addToken ( RI_AMPLITUDE, UNIFORM, FLOAT );
 
101
    addToken ( RI_WIDTH, VARYING, FLOAT );
 
102
    addToken ( RI_CONSTANTWIDTH, CONSTANT, FLOAT );
 
103
 
 
104
    addToken( "gridsize", UNIFORM, INTEGER );
 
105
    addToken( "texturememory", UNIFORM, INTEGER );
 
106
    addToken( "bucketsize", UNIFORM, INTEGER, 2 );
 
107
    addToken( "eyesplits", UNIFORM, INTEGER );
 
108
    addToken( RI_SHADER, UNIFORM, STRING );
 
109
    addToken( "archive", UNIFORM, STRING );
 
110
    addToken( "texture", UNIFORM, STRING );
 
111
    addToken( "display", UNIFORM, STRING );
 
112
    addToken( "auto_shadows", UNIFORM, STRING );
 
113
    addToken( "endofframe", UNIFORM, INTEGER );
 
114
    addToken( "sphere", UNIFORM, FLOAT );
 
115
    addToken( "coordinatesystem", UNIFORM, STRING );
 
116
    addToken( "shadows", UNIFORM, STRING );
 
117
    addToken( "shadowmapsize", UNIFORM, INTEGER, 2 );
 
118
    addToken( "shadowangle", UNIFORM, FLOAT );
 
119
    addToken( "shadowmapname", UNIFORM, STRING );
 
120
    addToken( "shadow_shadingrate", UNIFORM, FLOAT );
 
121
    addToken( RI_NAME, UNIFORM, STRING );
 
122
    addToken( "shadinggroup", UNIFORM, STRING );
 
123
    addToken( "sense", UNIFORM, STRING );
 
124
    addToken( "compression", UNIFORM, STRING );
 
125
    addToken( "quality", UNIFORM, INTEGER );
 
126
    addToken( "bias0", UNIFORM, FLOAT );
 
127
    addToken( "bias1", UNIFORM, FLOAT );
 
128
        addToken( "jitter", UNIFORM, INTEGER );
 
129
        addToken( "depthfilter", UNIFORM, STRING );
 
130
}
 
131
 
 
132
 
 
133
// If the token already exists, addToken() return the corresponding id
 
134
TqTokenId CqDictionary::addToken ( std::string n, EqTokenClass tc, EqTokenType tt, TqUint qnt, TqBool inln )
 
135
{
 
136
    std::vector<SqTokenEntry>::iterator first = te.begin();
 
137
    TqTokenId i;
 
138
 
 
139
    for ( i = 1;first != te.end();first++, i++ )
 
140
    {
 
141
        if ( ( n == first->name ) &&
 
142
                ( tc == first->tclass ) &&
 
143
                ( tt == first->ttype ) &&
 
144
                ( qnt == first->quantity ) )
 
145
            return i;
 
146
    }
 
147
 
 
148
    te.push_back( SqTokenEntry ( n, tc, tt, qnt, inln ) );
 
149
    return i;
 
150
}
 
151
 
 
152
// If the token given as input is in fact an inline definition,
 
153
// getTokenId() will add it to the dictionary.
 
154
TqTokenId CqDictionary::getTokenId ( std::string n )
 
155
{
 
156
    CqInlineParse ip;
 
157
    TqTokenId i, j = 0;
 
158
 
 
159
    ip.parse( n );
 
160
    if ( ip.isInline() == TqTrue )
 
161
    {
 
162
        j = addToken ( ip.getIdentifier(), ip.getClass(), ip.getType(), ip.getQuantity(), TqTrue );
 
163
    }
 
164
    else
 
165
    {
 
166
        std::vector<SqTokenEntry>::iterator first = te.begin();
 
167
 
 
168
        for ( i = 1;first != te.end();first++, i++ )
 
169
        {
 
170
            if ( ( n == first->name ) && ( first->in_line == TqFalse ) )
 
171
                j = i;
 
172
        }
 
173
        if ( j == 0 )
 
174
        {
 
175
            std::string st( "Token not declared: " );
 
176
            st += n;
 
177
            throw CqError( RIE_ILLSTATE, RIE_ERROR, st, TqFalse );
 
178
        }
 
179
    }
 
180
    return j;
 
181
}
 
182
 
 
183
 
 
184
TqUint CqDictionary::allocSize ( TqTokenId id, TqUint vertex, TqUint varying, TqUint uniform, TqUint facevarying )
 
185
{
 
186
    TqUint size;
 
187
    std::vector<SqTokenEntry>::iterator first = te.begin();
 
188
    first += id - 1;
 
189
    size = getTypeSize( first->ttype );
 
190
    switch ( first->tclass )
 
191
    {
 
192
    case VERTEX: size *= vertex;
 
193
        break;
 
194
    case VARYING: size *= varying;
 
195
        break;
 
196
    case UNIFORM: size *= uniform;
 
197
        break;
 
198
    case CONSTANT:
 
199
        break;
 
200
        case FACEVARYING: size *= facevarying;
 
201
                break;
 
202
    }
 
203
    size *= ( first->quantity );
 
204
    return size;
 
205
}
 
206
 
 
207
TqUint CqDictionary::getTypeSize ( EqTokenType t )
 
208
{
 
209
    switch ( t )
 
210
    {
 
211
    case FLOAT: return 1;
 
212
    case POINT: return 3;
 
213
    case VECTOR: return 3;
 
214
    case NORMAL: return 3;
 
215
    case COLOR: return 1;
 
216
    case STRING: return 1;
 
217
    case MATRIX: return 16;
 
218
    case HPOINT: return 4;
 
219
    case INTEGER: return 1;
 
220
    default :
 
221
        throw CqError( RIE_BUG, RIE_SEVERE,
 
222
                       "CqDictionary::getTypeSize(TokenType) --> Unknown token type", TqFalse );
 
223
    }
 
224
}
 
225
 
 
226
void CqDictionary::isValid ( TqTokenId id )
 
227
{
 
228
    if ( id > te.size() || id == 0 )
 
229
        throw CqError( RIE_BUG, RIE_SEVERE,
 
230
                       "CqDictionary::isValid(TokenId) --> Bad ID", TqFalse );
 
231
}
 
232
 
 
233
EqTokenType CqDictionary::getType ( TqTokenId id )
 
234
{
 
235
    isValid ( id );
 
236
    std::vector<SqTokenEntry>::iterator first = te.begin();
 
237
    return ( ( first + id - 1 ) ->ttype );
 
238
}
 
239
 
 
240
TqUint CqDictionary::getQuantity ( TqTokenId id )
 
241
{
 
242
    isValid ( id );
 
243
    std::vector<SqTokenEntry>::iterator first = te.begin();
 
244
    return ( ( first + id - 1 ) ->quantity );
 
245
}
 
246
 
 
247
#ifdef DEBUG
 
248
void CqDictionary::stats ()
 
249
{
 
250
    std::vector<SqTokenEntry>::iterator first = te.begin();
 
251
    TqTokenId i;
 
252
 
 
253
    cout << endl;
 
254
    cout << "Dictionary   Number of entries: " << te.size() << endl;
 
255
    cout << "------------------------------------------------------" << endl;
 
256
    cout << "NAME                  CLASS    TYPE   [SIZE] IS_INLINE" << endl;
 
257
    cout << "------------------------------------------------------" << endl;
 
258
 
 
259
    for ( i = 1;first != te.end();first++, i++ )
 
260
    {
 
261
        cout << std::setw( 20 ) << std::setfill ( ' ' );
 
262
        cout << std::setiosflags( ios::left ) << ( first->name ).c_str() << "  ";
 
263
        first->printClassType ();
 
264
        cout << "[" << getQuantity( i ) << "]  ";
 
265
        if ( ( first->in_line ) == TqTrue )
 
266
        {
 
267
            cout << " inline";
 
268
        }
 
269
        cout << endl;
 
270
    }
 
271
    cout << "------------------------------------------------------" << endl;
 
272
    cout << endl;
 
273
}
 
274
#endif