00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027 #ifndef SHSYNTAX_HPP
00028 #define SHSYNTAX_HPP
00029
00030 #include "ShDllExport.hpp"
00031 #include "ShProgram.hpp"
00032 #include "ShUtility.hpp"
00033
00038
00039
00040 #define SH_PUSH_ARG_QUEUE ::SH::shPushArgQueue()
00041 #define SH_PUSH_ARG ::SH::shPushArg()
00042 #define SH_PROCESS_ARG(arg, internal_cond) ::SH::shProcessArg(arg, internal_cond)
00043
00044
00046
00047
00053 #define SH_BEGIN_PROGRAM(target) ::SH::shBeginShader(target);
00054
00062 #define SH_END_PROGRAM ::SH::shEndShader();
00063
00064
00065 #define SH_END SH_END_PROGRAM
00066
00067 #define SH_BEGIN_VERTEX_PROGRAM ::SH::shBeginShader("gpu:vertex");
00068 #define SH_BEGIN_FRAGMENT_PROGRAM ::SH::shBeginShader("gpu:fragment");
00069
00071
00072
00077 #define SH_IF(cond) { \
00078 bool sh__internal_cond; \
00079 ::SH::shIf(SH_PUSH_ARG_QUEUE && SH_PUSH_ARG && SH_PROCESS_ARG(cond, &sh__internal_cond)); \
00080 if (ShContext::current()->parsing() || sh__internal_cond) {{
00081
00086 #define SH_ELSE \
00087 }} \
00088 ::SH::shElse(); \
00089 if (ShContext::current()->parsing() || !sh__internal_cond) {{
00090
00095 #define SH_ENDIF \
00096 }} \
00097 ::SH::shEndIf(); \
00098 }
00099
00100
00102
00103
00107 #define SH_WHILE(cond) { \
00108 bool sh__internal_cond; \
00109 ::SH::shWhile(SH_PUSH_ARG_QUEUE && SH_PUSH_ARG && SH_PROCESS_ARG(cond, &sh__internal_cond)); \
00110 bool sh__internal_firsttime = true; \
00111 while ((sh__internal_firsttime && (ShContext::current()->parsing() || sh__internal_cond)) \
00112 || (!ShContext::current()->parsing() && ::SH::shEvaluateCondition(cond))) {{{
00113
00117 #define SH_ENDWHILE \
00118 sh__internal_firsttime = false; \
00119 }}} \
00120 ::SH::shEndWhile(); \
00121 }
00122
00123
00125
00126
00130 #define SH_DO { \
00131 ::SH::shDo(); \
00132 do {{{{
00133
00137 #define SH_UNTIL(cond) \
00138 }}}} while (!ShContext::current()->parsing() && ::SH::shEvaluateCondition(cond)); \
00139 if (ShContext::current()->parsing()) ::SH::shUntil(SH_PUSH_ARG_QUEUE && SH_PUSH_ARG && SH_PROCESS_ARG(cond, 0)); }
00140
00141
00143
00144
00150
00151 #define SH_FOR(init,cond,update) { \
00152 if (ShContext::current()->parsing()) \
00153 ::SH::shFor(SH_PUSH_ARG_QUEUE \
00154 && SH_PUSH_ARG && SH_PROCESS_ARG(init, 0) \
00155 && SH_PUSH_ARG && SH_PROCESS_ARG(cond, 0) \
00156 && SH_PUSH_ARG && SH_PROCESS_ARG(update, 0)); \
00157 if (!ShContext::current()->parsing()) init; \
00158 bool sh__internal_first_time = true; \
00159 while (1) {{{{{ \
00160 if (!ShContext::current()->parsing()) { \
00161 if (!sh__internal_first_time) { update; } \
00162 else { sh__internal_first_time = false; } \
00163 if (!shEvaluateCondition(cond)) break; \
00164 }
00165
00169 #define SH_ENDFOR \
00170 if (ShContext::current()->parsing()) break; \
00171 }}}}} \
00172 ::SH::shEndFor(); \
00173 }
00174
00175
00177
00178
00185 #define SH_BREAK if (!ShContext::current()->parsing()) { break; } else { ::SH::shBreak(); }
00186
00193 #define SH_CONTINUE if (!ShContext::current()->parsing()) { continue; } else { ::SH::shBreak(); }
00194
00195
00197
00198
00204 #define SH_NAME(var) do { var.name( # var); } while (0)
00205
00215 #define SH_DECL(var) var; var.name( # var ); ::SH::ShIgnore() & var
00216
00225 #define SH_NAMEDECL(var, varName) var; var.name( varName ); ::SH::ShIgnore() & var
00226
00227
00228 namespace SH {
00229
00231 SH_DLLEXPORT
00232 bool shProcessArg(const ShVariable& arg, bool* internal_cond);
00233
00235 SH_DLLEXPORT
00236 bool shPushArg();
00237
00239 SH_DLLEXPORT
00240 bool shPushArgQueue();
00241
00243 SH_DLLEXPORT
00244 bool shEvaluateCondition(const ShVariable& arg);
00245
00247 SH_DLLEXPORT
00248 ShProgram shBeginShader(const std::string& kind = "");
00250 SH_DLLEXPORT
00251 void shEndShader();
00252
00254 SH_DLLEXPORT
00255 void shCompile(ShProgram& prg);
00257 SH_DLLEXPORT
00258 void shCompile(ShProgram& prg, const std::string& target);
00259
00261 SH_DLLEXPORT
00262 void shCompileShader(ShProgram& prg);
00264 SH_DLLEXPORT
00265 void shCompileShader(ShProgram& prg, const std::string& target);
00266
00268 SH_DLLEXPORT
00269 void shBind(ShProgram& prg);
00271 SH_DLLEXPORT
00272 void shBind(const std::string& target, ShProgram& shader);
00273
00275 SH_DLLEXPORT
00276 void shBindShader(ShProgram& shader);
00278 SH_DLLEXPORT
00279 void shBindShader(const std::string& target, ShProgram& shader);
00280
00284 SH_DLLEXPORT
00285 void shUpdate();
00286
00288 SH_DLLEXPORT
00289 bool shSetBackend(const std::string& name);
00290
00291
00297 SH_DLLEXPORT
00298 void shInit();
00299
00301 SH_DLLEXPORT
00302 void shIf(bool);
00304 SH_DLLEXPORT
00305 void shElse();
00307 SH_DLLEXPORT
00308 void shEndIf();
00309
00311 SH_DLLEXPORT
00312 void shWhile(bool);
00314 SH_DLLEXPORT
00315 void shEndWhile();
00316
00318 SH_DLLEXPORT
00319 void shDo();
00321 SH_DLLEXPORT
00322 void shUntil(bool);
00323
00325 SH_DLLEXPORT
00326 void shFor(bool);
00328 SH_DLLEXPORT
00329 void shEndFor();
00330
00332 SH_DLLEXPORT
00333 void shBreak();
00335 SH_DLLEXPORT
00336 void shContinue();
00337
00338 }
00339
00340 #endif