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