ts1.0_inst_list.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include "ts1.0_inst_list.h"
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "nvparse_errors.h"
  6. #include "nvparse_externs.h"
  7. using namespace CamelotEngine;
  8. const int instListInc = 4;
  9. InstList::InstList()
  10. {
  11. size = 0;
  12. max = instListInc;
  13. list = (InstPtr)malloc(sizeof(Inst) * max);
  14. }
  15. InstList::~InstList()
  16. {
  17. free(list);
  18. }
  19. int InstList::Size()
  20. {
  21. return size;
  22. }
  23. InstList& InstList::operator+=(InstPtr t)
  24. {
  25. if (size == max) {
  26. /* Extend list size by instListInc amount */
  27. max += instListInc;
  28. list = (InstPtr)realloc(list, sizeof(Inst) * max);
  29. }
  30. list[size++] = *t;
  31. return *this;
  32. }
  33. void InstList::Invoke()
  34. {
  35. int i;
  36. for (i = 0; i < size; i++) {
  37. // set active texture
  38. glActiveTextureARB(GL_TEXTURE0_ARB + i);
  39. list[i].Invoke();
  40. }
  41. // Reset active texture to unit 0
  42. // Could do a glGet to figure out what the initial active texunit was,
  43. // and reset to that, but the glGet would not behave well within
  44. // a display list...
  45. glActiveTextureARB(GL_TEXTURE0_ARB);
  46. }
  47. void InstList::Validate()
  48. {
  49. if (size > TSP_NUM_TEXTURE_UNITS)
  50. errors.set("too many instructions");
  51. int i;
  52. for (i = 0; i < size; i++) {
  53. int stage = list[i].opcode.bits.stage;
  54. if (stage > i)
  55. errors.set("prior stage missing");
  56. if (list[i].opcode.bits.instruction != list[i - stage].opcode.bits.instruction)
  57. errors.set("stage mismatch");
  58. if (list[i].opcode.bits.dependent) {
  59. int previousTexture = (int)list[i].args[0];
  60. if (previousTexture >= i - stage)
  61. errors.set("invalid texture reference");
  62. if (list[previousTexture].opcode.bits.noOutput)
  63. errors.set("no output on referenced texture");
  64. }
  65. }
  66. // Assign remaining undesignated texture units to nop
  67. for (; i < TSP_NUM_TEXTURE_UNITS; i++) {
  68. InstPtr nopInst = new Inst(TSP_NOP);
  69. *this += nopInst;
  70. delete nopInst;
  71. }
  72. }
  73. bool is_ts10(const char * s)
  74. {
  75. return ! strncmp(s, "!!TS1.0", 7);
  76. }
  77. bool ts10_init_more()
  78. {
  79. static bool tsinit = false;
  80. if (tsinit == false )
  81. {
  82. /*
  83. if(! glh_init_extensions( "GL_NV_texture_shader " "GL_ARB_multitexture " ))
  84. {
  85. errors.set("unable to initialize GL_NV_texture_shader\n");
  86. return false;
  87. }
  88. else
  89. {
  90. */
  91. tsinit = true;
  92. /*
  93. }
  94. */
  95. }
  96. errors.reset();
  97. line_number = 1;
  98. return true;
  99. }
  100. /*
  101. else if(!strncmp(instring, "!!TS1.0", 7))
  102. {
  103. if (tsinit == 0 )
  104. {
  105. if(! glh_init_extensions( "GL_NV_texture_shader " "GL_ARB_multitexture " ))
  106. {
  107. errors.set("unable to initialize GL_NV_texture_shader\n");
  108. free(instring);
  109. return;
  110. }
  111. else
  112. {
  113. tsinit = 1;
  114. }
  115. }
  116. errors.reset();
  117. line_number = 1;
  118. ts10_init(instring+7);
  119. ts10_parse();
  120. }
  121. */