[3] | 1 | #ifdef _WIN32 |
---|
| 2 | # include <windows.h> |
---|
| 3 | #else |
---|
| 4 | #include <stdarg.h> |
---|
| 5 | #define strnicmp strncasecmp |
---|
| 6 | #endif |
---|
| 7 | |
---|
| 8 | #include <stdio.h> |
---|
| 9 | |
---|
| 10 | #if defined(__APPLE__) && defined(__GNUC__) |
---|
| 11 | #include <OpenGL/glu.h> |
---|
| 12 | #else |
---|
| 13 | #include <GL/glu.h> |
---|
| 14 | #endif |
---|
| 15 | |
---|
| 16 | #include <string> |
---|
| 17 | #include <vector> |
---|
| 18 | |
---|
| 19 | #include "nvparse.h" |
---|
| 20 | #include "nvparse_errors.h" |
---|
| 21 | |
---|
| 22 | //void yyinit(char*); |
---|
| 23 | //int yyparse(void); |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | // RC1.0 -- register combiners 1.0 configuration |
---|
| 27 | bool rc10_init(char *); |
---|
| 28 | int rc10_parse(); |
---|
| 29 | bool is_rc10(const char *); |
---|
| 30 | |
---|
| 31 | // TS1.0 -- texture shader 1.0 configuration |
---|
| 32 | bool ts10_init(char *); |
---|
| 33 | int ts10_parse(); |
---|
| 34 | bool is_ts10(const char *); |
---|
| 35 | |
---|
| 36 | // ARBvp1.0 -- ARB vertex program |
---|
| 37 | bool avp10_init(char *); |
---|
| 38 | int avp10_parse(); |
---|
| 39 | bool is_avp10(const char *); |
---|
| 40 | |
---|
| 41 | #if !defined(__APPLE__) |
---|
| 42 | // VP1.0 -- vertex program |
---|
| 43 | bool vp10_init(char *); |
---|
| 44 | int vp10_parse(); |
---|
| 45 | bool is_vp10(const char *); |
---|
| 46 | |
---|
| 47 | // VSP1.0 -- vertex state program |
---|
| 48 | bool vsp10_init(char *); |
---|
| 49 | int vsp10_parse(int vspid); |
---|
| 50 | bool is_vsp10(const char *); |
---|
| 51 | |
---|
| 52 | // VCP1.0 -- vertex constant program |
---|
| 53 | bool vcp10_init(char *); |
---|
| 54 | int vcp10_parse(); |
---|
| 55 | bool is_vcp10(const char *); |
---|
| 56 | |
---|
| 57 | // DX8 stuff |
---|
| 58 | |
---|
| 59 | // PS1.0 -- DX8 Pixel Shader 1.0 configuration |
---|
| 60 | bool ps10_init(char *); |
---|
| 61 | int ps10_parse(); |
---|
| 62 | bool ps10_set_map(const std::vector<int>& argv); |
---|
| 63 | bool is_ps10(const char *); |
---|
| 64 | const int* ps10_get_info(int* pcount); |
---|
| 65 | |
---|
| 66 | // VS1.0 -- DX8 Vertex Shader 1.0 |
---|
| 67 | bool vs10_init(char *); |
---|
| 68 | int vs10_parse(); |
---|
| 69 | bool is_vs10(const char *); |
---|
| 70 | void vs10_load_program(); |
---|
| 71 | #endif |
---|
| 72 | |
---|
| 73 | nvparse_errors errors; |
---|
| 74 | int line_number; |
---|
| 75 | char * myin = 0; |
---|
| 76 | |
---|
| 77 | void nvparse(const char * input_string, int argc /* = 0 */,...) |
---|
| 78 | { |
---|
| 79 | if (NULL == input_string) |
---|
| 80 | { |
---|
| 81 | errors.set("NULL string passed to nvparse"); |
---|
| 82 | return; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | char * instring = strdup(input_string); |
---|
| 86 | |
---|
| 87 | // register combiners (1 and 2) |
---|
| 88 | if(is_rc10(instring)) |
---|
| 89 | { |
---|
| 90 | if(rc10_init(instring)) |
---|
| 91 | { |
---|
| 92 | rc10_parse(); |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | // texture shader |
---|
| 97 | else if(is_ts10(instring)) |
---|
| 98 | { |
---|
| 99 | if(ts10_init(instring)) |
---|
| 100 | { |
---|
| 101 | ts10_parse(); |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | // vertex program |
---|
| 106 | else if(is_avp10(instring)) |
---|
| 107 | { |
---|
| 108 | if(avp10_init(instring)) |
---|
| 109 | { |
---|
| 110 | avp10_parse(); |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | #if !defined(__APPLE__) |
---|
| 115 | // vertex constant program |
---|
| 116 | else if(is_vcp10(instring)) |
---|
| 117 | { |
---|
| 118 | if(vcp10_init(instring)) |
---|
| 119 | { |
---|
| 120 | vcp10_parse(); |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | // vertex state program |
---|
| 125 | else if(is_vsp10(instring)) |
---|
| 126 | { |
---|
| 127 | if(vsp10_init(instring)) |
---|
| 128 | { |
---|
| 129 | vsp10_parse(argc); |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | // vertex program |
---|
| 134 | else if(is_vp10(instring)) |
---|
| 135 | { |
---|
| 136 | if(vp10_init(instring)) |
---|
| 137 | { |
---|
| 138 | vp10_parse(); |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | // DX8 vertex shader |
---|
| 143 | else if ( is_vs10(instring) ) |
---|
| 144 | { |
---|
| 145 | if(vs10_init(instring)) |
---|
| 146 | { |
---|
| 147 | vs10_parse(); |
---|
| 148 | vs10_load_program(); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | } |
---|
| 152 | else if (is_ps10(instring)) |
---|
| 153 | { |
---|
| 154 | if(ps10_init(instring)) |
---|
| 155 | { |
---|
| 156 | va_list ap; |
---|
| 157 | std::vector<int> argv; |
---|
| 158 | va_start(ap,argc); |
---|
| 159 | for (int i=0;i<argc;++i) |
---|
| 160 | { |
---|
| 161 | int arg = va_arg(ap,int); |
---|
| 162 | argv.push_back(arg); |
---|
| 163 | } |
---|
| 164 | va_end(ap); |
---|
| 165 | if (!ps10_set_map(argv)) |
---|
| 166 | return; |
---|
| 167 | ps10_parse(); |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | #endif |
---|
| 171 | else |
---|
| 172 | { |
---|
| 173 | errors.set("invalid string.\n " |
---|
| 174 | "first characters must be: !!ARBvp1.0 or !!VP1.0 or !!VSP1.0 or !!RC1.0 or !!TS1.0\n " |
---|
| 175 | "or it must be a valid DirectX 8.0 Vertex Shader"); |
---|
| 176 | } |
---|
| 177 | free(instring); |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | char * const * const nvparse_get_errors() |
---|
| 181 | { |
---|
| 182 | return errors.get_errors(); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | char * const * const nvparse_print_errors(FILE * errfp) |
---|
| 186 | { |
---|
| 187 | for (char * const * ep = nvparse_get_errors(); *ep; ep++) |
---|
| 188 | { |
---|
| 189 | const char * errstr = *ep; |
---|
| 190 | fprintf(errfp, "%s\n", errstr); |
---|
| 191 | } |
---|
| 192 | return nvparse_get_errors(); |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | |
---|
| 196 | const int* nvparse_get_info(const char* input_string, int* pcount) |
---|
| 197 | { |
---|
| 198 | #if !defined(__APPLE__) |
---|
| 199 | if (NULL == input_string) |
---|
| 200 | { |
---|
| 201 | errors.set("NULL string passed to nvparse_get_info"); |
---|
| 202 | return 0; |
---|
| 203 | } |
---|
| 204 | if (is_ps10(input_string)) |
---|
| 205 | { |
---|
| 206 | return ps10_get_info(pcount); |
---|
| 207 | } |
---|
| 208 | #endif |
---|
| 209 | return 0; |
---|
| 210 | } |
---|