/usr/include/crystalspace-2.0/csgfx/shaderexp.h is in libcrystalspace-dev 2.0+dfsg-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | /*
Copyright (C) 2003 by Andrew Topp <designa@users.sourceforge.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CS_GFX_SHADEREXP_H__
#define __CS_GFX_SHADEREXP_H__
/**\file
* An evaluable expression attached to a shader variable.
*/
#include "csextern.h"
#include "csutil/strhash.h"
#include "csutil/array.h"
#include "csutil/leakguard.h"
#include "csgeom/vector4.h"
#include "csgfx/shadervarnameparser.h"
#include "ivideo/shader/shader.h"
struct iObjectRegistry;
class csShaderVariable;
struct iShaderVariableContext;
struct iStringSet;
struct iDocumentNode;
struct cons;
/**
* An evaluable expression attached to a shader variable.
*/
class CS_CRYSTALSPACE_EXPORT csShaderExpression
{
public:
CS_LEAKGUARD_DECLARE (csShaderExpression);
struct oper_arg
{
uint8 type;
struct SvVarValue
{
CS::StringIDValue id;
size_t* indices;
};
union
{
float num;
SvVarValue var;
// Illegal outside of a cons cell
int oper;
cons* cell;
// Special internal values
int acc;
};
csVector4 vec4;
CS::Math::Matrix4 matrix;
};
struct oper
{
uint8 opcode, acc;
oper_arg arg1, arg2;
};
typedef csArray<oper> oper_array;
typedef csArray<oper_arg> arg_array;
private:
iObjectRegistry* obj_reg;
/// Variables used for evaluation
csShaderVariableStack* stack;
/// String set for producing String IDs
csRef<iShaderVarStringSet> strset;
/// Storage for SV sub-indices
csMemoryPool svIndicesScratch;
/// Compiled array of opcodes for evaluation
oper_array opcodes;
/**
* Used during compilation, set to the maximum allocated dimensions of
* the accstack.
*/
int accstack_max;
/**
* The accumulator stack.
* Set to a static size after compilation, to save on allocation costs,
* according to accstack_max.
*/
arg_array accstack;
/// Parse an XML X-expression
bool parse_xml (cons*, iDocumentNode*);
/// Parse a single X-expression data atom
bool parse_xml_atom (oper_arg&, csStringID, const char*, const char*);
/// Parse a Lisplike S-expression
bool parse_sexp (cons*, iDocumentNode*);
/** Parse an S-expression form
Used to recurse down the S-expression's nested lists. */
bool parse_sexp_form (const char*& text, cons*);
/// Parse an S-expression atom
bool parse_sexp_atom (const char*& text, cons*);
/// Parse a numerical atom for either XEXP or SEXP
bool parse_num_atom (const char*& text, oper_arg&);
/// Compile a cons list into the oper_array.
bool compile_cons (const cons*, int& acc_top);
/// Compile a MAKE-VECTOR pseudo-op
bool compile_make_vector (const cons*, int& acc_top, int acc);
/// Compile an IF pseudo-op
bool compile_if (const cons*, int& acc_top, int acc);
/// Evaluate away constant values
bool eval_const (cons*&);
/// Evaluate an operator and 2 arguments
bool eval_oper (int oper, oper_arg arg1, oper_arg arg2, oper_arg& output);
/// Evaluate an operator with a single argument
bool eval_oper (int oper, oper_arg arg1, oper_arg& output);
/// Evaluate an operator without any arguments
bool eval_oper (int oper, oper_arg& output);
/// Add operator
bool eval_add (const oper_arg& arg1, const oper_arg& arg2,
oper_arg& output) const;
/// Subtraction operator
bool eval_sub (const oper_arg& arg1, const oper_arg& arg2,
oper_arg& output) const;
/// Multiplication operator
bool eval_mul (const oper_arg& arg1, const oper_arg& arg2,
oper_arg& output) const;
/// Division operator
bool eval_div (const oper_arg& arg1, const oper_arg& arg2,
oper_arg& output) const;
/// Element1 operator
bool eval_elt1 (const oper_arg& arg1, oper_arg& output) const;
/// Element2 operator
bool eval_elt2 (const oper_arg& arg1, oper_arg& output) const;
/// Element3 operator
bool eval_elt3 (const oper_arg& arg1, oper_arg& output) const;
/// Element4 operator
bool eval_elt4 (const oper_arg& arg1, oper_arg& output) const;
/// Sine operator
bool eval_sin (const oper_arg& arg1, oper_arg& output) const;
/// Cosine operator
bool eval_cos (const oper_arg& arg1, oper_arg& output) const;
/// Tangent operator
bool eval_tan (const oper_arg& arg1, oper_arg& output) const;
bool eval_arcsin (const oper_arg& arg1, oper_arg& output) const;
bool eval_arccos (const oper_arg& arg1, oper_arg& output) const;
bool eval_arctan (const oper_arg& arg1, oper_arg& output) const;
bool eval_dot (const oper_arg& arg1, const oper_arg& arg2,
oper_arg& output) const;
bool eval_cross (const oper_arg& arg1, const oper_arg& arg2,
oper_arg& output) const;
bool eval_vec_len (const oper_arg& arg1, oper_arg& output) const;
bool eval_normal (const oper_arg& arg1, oper_arg& output) const;
/// Floor operator
bool eval_floor (const oper_arg& arg1, oper_arg& output) const;
bool eval_pow (const oper_arg& arg1, const oper_arg& arg2,
oper_arg& output) const;
bool eval_min (const oper_arg& arg1, const oper_arg& arg2,
oper_arg& output) const;
bool eval_max (const oper_arg& arg1, const oper_arg& arg2,
oper_arg& output) const;
/// Time function
bool eval_time (oper_arg& output) const;
/// Frame function
bool eval_frame (oper_arg& output) const;
template<typename Comparator>
bool eval_compare (const Comparator& cmp, const oper_arg& arg1,
const oper_arg& arg2, oper_arg& output) const;
bool eval_matrix_column (const oper_arg& arg1, const oper_arg& arg2,
oper_arg& output) const;
bool eval_matrix_row (const oper_arg& arg1, const oper_arg& arg2,
oper_arg& output) const;
bool eval_matrix2gl (const oper_arg& arg1, oper_arg& output) const;
bool eval_matrix_transp (const oper_arg& arg1, oper_arg& output) const;
bool eval_matrix_inv (const oper_arg& arg1, oper_arg& output) const;
/// Internal set vector element 1 and 2
bool eval_selt12 (const oper_arg& arg1, const oper_arg& arg2,
oper_arg & output) const;
/// Internal set vector element 3 and 4
bool eval_selt34 (const oper_arg & arg1, const oper_arg & arg2,
oper_arg& output) const;
/// Internal load operator
bool eval_load (const oper_arg& arg1, oper_arg& output) const;
/// Internal select operator
bool eval_select (const oper_arg& arg1, const oper_arg& arg2,
oper_arg& output) const;
/// Evaluate a variable into an oper_arg
bool eval_variable (csShaderVariable*, oper_arg& out);
/// Evaluate an oper_arg into a variable
bool eval_argument (const oper_arg&, csShaderVariable*);
/// Free all the memory used by a cons list
void destruct_cons (cons*) const;
/// Dump the contents of a cons list
void print_cons (const cons*) const;
/// Dump the opcode list
void print_ops (const oper_array&) const;
/// Dump the result of an operation
void print_result (const oper_arg&) const;
/*inline*/static const char* GetTypeName (unsigned int id)/* const*/;
/*{
return xmltypes.Request(id);
}*/
static const char* GetOperName (unsigned int id);
static csStringID GetCommonTokenOp (const char* token);
static csStringID GetXmlTokenOp (const char* token);
static csStringID GetSexpTokenOp (const char* token);
static csStringID GetXmlType (const char* token);
/// Helper to allocate a number of SV sub-indices from the mem pool
size_t* AllocSVIndices (const CS::Graphics::ShaderVarNameParser& parser);
csShaderVariable* ResolveVar (const oper_arg::SvVarValue& var);
mutable csString errorMsg;
void ParseError (const char* message, ...) const;
void EvalError (const char* message, ...) const;
public:
csShaderExpression (iObjectRegistry*);
~csShaderExpression ();
/// Parse in the XML in the context of a symbol table.
bool Parse (iDocumentNode*);
//@{
/**
* Evaluate this expression into a variable.
* It will use the symbol table it was initialized with.
*/
bool Evaluate (csShaderVariable*, csShaderVariableStack& stacks);
//@}
/// Retrieve the error message if the evaluation or parsing failed.
const char* GetError () const { return errorMsg; }
};
#endif
|