| 1 | #include "osg/TexEnvCombine" |
|---|
| 2 | #include <osg/io_utils> |
|---|
| 3 | |
|---|
| 4 | #include "osgDB/Registry" |
|---|
| 5 | #include "osgDB/Input" |
|---|
| 6 | #include "osgDB/Output" |
|---|
| 7 | |
|---|
| 8 | #include <string.h> |
|---|
| 9 | |
|---|
| 10 | using namespace osg; |
|---|
| 11 | using namespace osgDB; |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | bool TexEnvCombine_readLocalData(Object& obj, Input& fr); |
|---|
| 15 | bool TexEnvCombine_writeLocalData(const Object& obj, Output& fw); |
|---|
| 16 | |
|---|
| 17 | bool TexEnvCombine_matchCombineParamStr(const char* str,GLint& value); |
|---|
| 18 | const char* TexEnvCombine_getCombineParamStr(GLint value); |
|---|
| 19 | |
|---|
| 20 | bool TexEnvCombine_matchSourceParamStr(const char* str,GLint& value); |
|---|
| 21 | const char* TexEnvCombine_getSourceParamStr(GLint value); |
|---|
| 22 | |
|---|
| 23 | bool TexEnvCombine_matchOperandParamStr(const char* str,GLint& value); |
|---|
| 24 | const char* TexEnvCombine_getOperandParamStr(GLint value); |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | REGISTER_DOTOSGWRAPPER(TexEnvCombine) |
|---|
| 28 | ( |
|---|
| 29 | new osg::TexEnvCombine, |
|---|
| 30 | "TexEnvCombine", |
|---|
| 31 | "Object StateAttribute TexEnvCombine", |
|---|
| 32 | &TexEnvCombine_readLocalData, |
|---|
| 33 | &TexEnvCombine_writeLocalData |
|---|
| 34 | ); |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | bool TexEnvCombine_readLocalData(Object& obj, Input& fr) |
|---|
| 38 | { |
|---|
| 39 | bool iteratorAdvanced = false; |
|---|
| 40 | |
|---|
| 41 | TexEnvCombine& texenv = static_cast<TexEnvCombine&>(obj); |
|---|
| 42 | |
|---|
| 43 | GLint value; |
|---|
| 44 | if (fr[0].matchWord("combine_RGB") && TexEnvCombine_matchCombineParamStr(fr[1].getStr(),value)) |
|---|
| 45 | { |
|---|
| 46 | texenv.setCombine_RGB(value); |
|---|
| 47 | fr+=2; |
|---|
| 48 | iteratorAdvanced = true; |
|---|
| 49 | } |
|---|
| 50 | if (fr[0].matchWord("combine_Alpha") && TexEnvCombine_matchCombineParamStr(fr[1].getStr(),value)) |
|---|
| 51 | { |
|---|
| 52 | texenv.setCombine_Alpha(value); |
|---|
| 53 | fr+=2; |
|---|
| 54 | iteratorAdvanced = true; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | if (fr[0].matchWord("source0_RGB") && TexEnvCombine_matchSourceParamStr(fr[1].getStr(),value)) |
|---|
| 59 | { |
|---|
| 60 | texenv.setSource0_RGB(value); |
|---|
| 61 | fr+=2; |
|---|
| 62 | iteratorAdvanced = true; |
|---|
| 63 | } |
|---|
| 64 | if (fr[0].matchWord("source1_RGB") && TexEnvCombine_matchSourceParamStr(fr[1].getStr(),value)) |
|---|
| 65 | { |
|---|
| 66 | texenv.setSource1_RGB(value); |
|---|
| 67 | fr+=2; |
|---|
| 68 | iteratorAdvanced = true; |
|---|
| 69 | } |
|---|
| 70 | if (fr[0].matchWord("source2_RGB") && TexEnvCombine_matchSourceParamStr(fr[1].getStr(),value)) |
|---|
| 71 | { |
|---|
| 72 | texenv.setSource2_RGB(value); |
|---|
| 73 | fr+=2; |
|---|
| 74 | iteratorAdvanced = true; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | if (fr[0].matchWord("source0_Alpha") && TexEnvCombine_matchSourceParamStr(fr[1].getStr(),value)) |
|---|
| 78 | { |
|---|
| 79 | texenv.setSource0_Alpha(value); |
|---|
| 80 | fr+=2; |
|---|
| 81 | iteratorAdvanced = true; |
|---|
| 82 | } |
|---|
| 83 | if (fr[0].matchWord("source1_Alpha") && TexEnvCombine_matchSourceParamStr(fr[1].getStr(),value)) |
|---|
| 84 | { |
|---|
| 85 | texenv.setSource1_Alpha(value); |
|---|
| 86 | fr+=2; |
|---|
| 87 | iteratorAdvanced = true; |
|---|
| 88 | } |
|---|
| 89 | if (fr[0].matchWord("source2_Alpha") && TexEnvCombine_matchSourceParamStr(fr[1].getStr(),value)) |
|---|
| 90 | { |
|---|
| 91 | texenv.setSource2_Alpha(value); |
|---|
| 92 | fr+=2; |
|---|
| 93 | iteratorAdvanced = true; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | if (fr[0].matchWord("operand0_RGB") && TexEnvCombine_matchOperandParamStr(fr[1].getStr(),value)) |
|---|
| 99 | { |
|---|
| 100 | texenv.setOperand0_RGB(value); |
|---|
| 101 | fr+=2; |
|---|
| 102 | iteratorAdvanced = true; |
|---|
| 103 | } |
|---|
| 104 | if (fr[0].matchWord("operand1_RGB") && TexEnvCombine_matchOperandParamStr(fr[1].getStr(),value)) |
|---|
| 105 | { |
|---|
| 106 | texenv.setOperand1_RGB(value); |
|---|
| 107 | fr+=2; |
|---|
| 108 | iteratorAdvanced = true; |
|---|
| 109 | } |
|---|
| 110 | if (fr[0].matchWord("operand2_RGB") && TexEnvCombine_matchOperandParamStr(fr[1].getStr(),value)) |
|---|
| 111 | { |
|---|
| 112 | texenv.setOperand2_RGB(value); |
|---|
| 113 | fr+=2; |
|---|
| 114 | iteratorAdvanced = true; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | if (fr[0].matchWord("operand0_Alpha") && TexEnvCombine_matchOperandParamStr(fr[1].getStr(),value)) |
|---|
| 118 | { |
|---|
| 119 | texenv.setOperand0_Alpha(value); |
|---|
| 120 | fr+=2; |
|---|
| 121 | iteratorAdvanced = true; |
|---|
| 122 | } |
|---|
| 123 | if (fr[0].matchWord("operand1_Alpha") && TexEnvCombine_matchOperandParamStr(fr[1].getStr(),value)) |
|---|
| 124 | { |
|---|
| 125 | texenv.setOperand1_Alpha(value); |
|---|
| 126 | fr+=2; |
|---|
| 127 | iteratorAdvanced = true; |
|---|
| 128 | } |
|---|
| 129 | if (fr[0].matchWord("operand2_Alpha") && TexEnvCombine_matchOperandParamStr(fr[1].getStr(),value)) |
|---|
| 130 | { |
|---|
| 131 | texenv.setOperand2_Alpha(value); |
|---|
| 132 | fr+=2; |
|---|
| 133 | iteratorAdvanced = true; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | float scale; |
|---|
| 137 | if (fr[0].matchWord("scale_RGB") && fr[1].getFloat(scale)) |
|---|
| 138 | { |
|---|
| 139 | texenv.setScale_RGB(scale); |
|---|
| 140 | fr+=2; |
|---|
| 141 | iteratorAdvanced = true; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | if (fr[0].matchWord("scale_Alpha") && fr[1].getFloat(scale)) |
|---|
| 145 | { |
|---|
| 146 | texenv.setScale_Alpha(scale); |
|---|
| 147 | fr+=2; |
|---|
| 148 | iteratorAdvanced = true; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | if (fr.matchSequence("constantColor %f %f %f %f")) |
|---|
| 152 | { |
|---|
| 153 | osg::Vec4 color; |
|---|
| 154 | fr[1].getFloat(color[0]); |
|---|
| 155 | fr[2].getFloat(color[1]); |
|---|
| 156 | fr[3].getFloat(color[2]); |
|---|
| 157 | fr[4].getFloat(color[3]); |
|---|
| 158 | |
|---|
| 159 | texenv.setConstantColor(color); |
|---|
| 160 | |
|---|
| 161 | fr+=5; |
|---|
| 162 | iteratorAdvanced = true; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | return iteratorAdvanced; |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | bool TexEnvCombine_writeLocalData(const Object& obj, Output& fw) |
|---|
| 169 | { |
|---|
| 170 | const TexEnvCombine& texenv = static_cast<const TexEnvCombine&>(obj); |
|---|
| 171 | |
|---|
| 172 | fw.indent() << "combine_RGB " << TexEnvCombine_getCombineParamStr(texenv.getCombine_RGB()) << std::endl; |
|---|
| 173 | fw.indent() << "combine_Alpha " << TexEnvCombine_getCombineParamStr(texenv.getCombine_Alpha()) << std::endl; |
|---|
| 174 | |
|---|
| 175 | fw.indent() << "source0_RGB " << TexEnvCombine_getSourceParamStr(texenv.getSource0_RGB()) << std::endl; |
|---|
| 176 | fw.indent() << "source1_RGB " << TexEnvCombine_getSourceParamStr(texenv.getSource1_RGB()) << std::endl; |
|---|
| 177 | fw.indent() << "source2_RGB " << TexEnvCombine_getSourceParamStr(texenv.getSource2_RGB()) << std::endl; |
|---|
| 178 | |
|---|
| 179 | fw.indent() << "source0_Alpha " << TexEnvCombine_getSourceParamStr(texenv.getSource0_Alpha()) << std::endl; |
|---|
| 180 | fw.indent() << "source1_Alpha " << TexEnvCombine_getSourceParamStr(texenv.getSource1_Alpha()) << std::endl; |
|---|
| 181 | fw.indent() << "source2_Alpha " << TexEnvCombine_getSourceParamStr(texenv.getSource2_Alpha()) << std::endl; |
|---|
| 182 | |
|---|
| 183 | fw.indent() << "operand0_RGB " << TexEnvCombine_getOperandParamStr(texenv.getOperand0_RGB()) << std::endl; |
|---|
| 184 | fw.indent() << "operand1_RGB " << TexEnvCombine_getOperandParamStr(texenv.getOperand1_RGB()) << std::endl; |
|---|
| 185 | fw.indent() << "operand2_RGB " << TexEnvCombine_getOperandParamStr(texenv.getOperand2_RGB()) << std::endl; |
|---|
| 186 | |
|---|
| 187 | fw.indent() << "operand0_Alpha " << TexEnvCombine_getOperandParamStr(texenv.getOperand0_Alpha()) << std::endl; |
|---|
| 188 | fw.indent() << "operand1_Alpha " << TexEnvCombine_getOperandParamStr(texenv.getOperand1_Alpha()) << std::endl; |
|---|
| 189 | fw.indent() << "operand2_Alpha " << TexEnvCombine_getOperandParamStr(texenv.getOperand2_Alpha()) << std::endl; |
|---|
| 190 | |
|---|
| 191 | fw.indent() << "scale_RGB " << texenv.getScale_RGB() << std::endl; |
|---|
| 192 | fw.indent() << "scale_Alpha " << texenv.getScale_Alpha() << std::endl; |
|---|
| 193 | |
|---|
| 194 | fw.indent() << "constantColor " << texenv.getConstantColor() << std::endl; |
|---|
| 195 | |
|---|
| 196 | return true; |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | bool TexEnvCombine_matchCombineParamStr(const char* str,GLint& value) |
|---|
| 201 | { |
|---|
| 202 | if (strcmp(str,"REPLACE")==0) value = TexEnvCombine::REPLACE; |
|---|
| 203 | else if (strcmp(str,"MODULATE")==0) value = TexEnvCombine::MODULATE; |
|---|
| 204 | else if (strcmp(str,"ADD")==0) value = TexEnvCombine::ADD; |
|---|
| 205 | else if (strcmp(str,"ADD_SIGNED")==0) value = TexEnvCombine::ADD_SIGNED; |
|---|
| 206 | else if (strcmp(str,"INTERPOLATE")==0) value = TexEnvCombine::INTERPOLATE; |
|---|
| 207 | else if (strcmp(str,"SUBTRACT")==0) value = TexEnvCombine::SUBTRACT; |
|---|
| 208 | else if (strcmp(str,"DOT3_RGB")==0) value = TexEnvCombine::DOT3_RGB; |
|---|
| 209 | else if (strcmp(str,"DOT3_RGBA")==0) value = TexEnvCombine::DOT3_RGBA; |
|---|
| 210 | else return false; |
|---|
| 211 | return true; |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | const char* TexEnvCombine_getCombineParamStr(GLint value) |
|---|
| 215 | { |
|---|
| 216 | switch(value) |
|---|
| 217 | { |
|---|
| 218 | case(TexEnvCombine::REPLACE): return "REPLACE"; |
|---|
| 219 | case(TexEnvCombine::MODULATE): return "MODULATE"; |
|---|
| 220 | case(TexEnvCombine::ADD): return "ADD"; |
|---|
| 221 | case(TexEnvCombine::ADD_SIGNED): return "ADD_SIGNED"; |
|---|
| 222 | case(TexEnvCombine::INTERPOLATE): return "INTERPOLATE"; |
|---|
| 223 | case(TexEnvCombine::SUBTRACT): return "SUBTRACT"; |
|---|
| 224 | case(TexEnvCombine::DOT3_RGB): return "DOT3_RGB"; |
|---|
| 225 | case(TexEnvCombine::DOT3_RGBA): return "DOT3_RGBA"; |
|---|
| 226 | } |
|---|
| 227 | return ""; |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | bool TexEnvCombine_matchSourceParamStr(const char* str,GLint& value) |
|---|
| 231 | { |
|---|
| 232 | if (strcmp(str,"CONSTANT")==0) value = TexEnvCombine::CONSTANT; |
|---|
| 233 | else if (strcmp(str,"PRIMARY_COLOR")==0) value = TexEnvCombine::PRIMARY_COLOR; |
|---|
| 234 | else if (strcmp(str,"PREVIOUS")==0) value = TexEnvCombine::PREVIOUS; |
|---|
| 235 | else if (strcmp(str,"TEXTURE")==0) value = TexEnvCombine::TEXTURE; |
|---|
| 236 | else if (strcmp(str,"TEXTURE0")==0) value = TexEnvCombine::TEXTURE0; |
|---|
| 237 | else if (strcmp(str,"TEXTURE1")==0) value = TexEnvCombine::TEXTURE1; |
|---|
| 238 | else if (strcmp(str,"TEXTURE2")==0) value = TexEnvCombine::TEXTURE2; |
|---|
| 239 | else if (strcmp(str,"TEXTURE3")==0) value = TexEnvCombine::TEXTURE3; |
|---|
| 240 | else if (strcmp(str,"TEXTURE4")==0) value = TexEnvCombine::TEXTURE4; |
|---|
| 241 | else if (strcmp(str,"TEXTURE5")==0) value = TexEnvCombine::TEXTURE5; |
|---|
| 242 | else if (strcmp(str,"TEXTURE6")==0) value = TexEnvCombine::TEXTURE6; |
|---|
| 243 | else if (strcmp(str,"TEXTURE7")==0) value = TexEnvCombine::TEXTURE7; |
|---|
| 244 | else return false; |
|---|
| 245 | return true; |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | const char* TexEnvCombine_getSourceParamStr(GLint value) |
|---|
| 249 | { |
|---|
| 250 | switch(value) |
|---|
| 251 | { |
|---|
| 252 | case(TexEnvCombine::CONSTANT): return "CONSTANT"; |
|---|
| 253 | case(TexEnvCombine::PRIMARY_COLOR): return "PRIMARY_COLOR"; |
|---|
| 254 | case(TexEnvCombine::PREVIOUS): return "PREVIOUS"; |
|---|
| 255 | case(TexEnvCombine::TEXTURE): return "TEXTURE"; |
|---|
| 256 | case(TexEnvCombine::TEXTURE0): return "TEXTURE0"; |
|---|
| 257 | case(TexEnvCombine::TEXTURE1): return "TEXTURE1"; |
|---|
| 258 | case(TexEnvCombine::TEXTURE2): return "TEXTURE2"; |
|---|
| 259 | case(TexEnvCombine::TEXTURE3): return "TEXTURE3"; |
|---|
| 260 | case(TexEnvCombine::TEXTURE4): return "TEXTURE4"; |
|---|
| 261 | case(TexEnvCombine::TEXTURE5): return "TEXTURE5"; |
|---|
| 262 | case(TexEnvCombine::TEXTURE6): return "TEXTURE6"; |
|---|
| 263 | case(TexEnvCombine::TEXTURE7): return "TEXTURE7"; |
|---|
| 264 | } |
|---|
| 265 | return ""; |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | bool TexEnvCombine_matchOperandParamStr(const char* str,GLint& value) |
|---|
| 269 | { |
|---|
| 270 | if (strcmp(str,"SRC_COLOR")==0) value = TexEnvCombine::SRC_COLOR; |
|---|
| 271 | else if (strcmp(str,"ONE_MINUS_SRC_COLOR")==0) value = TexEnvCombine::ONE_MINUS_SRC_COLOR; |
|---|
| 272 | else if (strcmp(str,"SRC_ALPHA")==0) value = TexEnvCombine::SRC_ALPHA; |
|---|
| 273 | else if (strcmp(str,"ONE_MINUS_SRC_ALPHA")==0) value = TexEnvCombine::ONE_MINUS_SRC_ALPHA; |
|---|
| 274 | else return false; |
|---|
| 275 | return true; |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | const char* TexEnvCombine_getOperandParamStr(GLint value) |
|---|
| 279 | { |
|---|
| 280 | switch(value) |
|---|
| 281 | { |
|---|
| 282 | case(TexEnvCombine::SRC_COLOR): return "SRC_COLOR"; |
|---|
| 283 | case(TexEnvCombine::ONE_MINUS_SRC_COLOR): return "ONE_MINUS_SRC_COLOR"; |
|---|
| 284 | case(TexEnvCombine::SRC_ALPHA): return "SRC_ALPHA"; |
|---|
| 285 | case(TexEnvCombine::ONE_MINUS_SRC_ALPHA): return "ONE_MINUS_SRC_ALPHA"; |
|---|
| 286 | } |
|---|
| 287 | return ""; |
|---|
| 288 | } |
|---|