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 #include "ArbReg.hpp"
00028 #include <iostream>
00029 #include <string>
00030 #include "Arb.hpp"
00031
00032 namespace shgl {
00033
00036 struct {
00037 char* name;
00038 char* estName;
00039 } arbRegTypeInfo[] = {
00040 {"ATTRIB", "i"},
00041 {"PARAM", "u"},
00042 {"TEMP", "t"},
00043 {"HALFTEMP", "h"},
00044 {"ADDRESS", "a"},
00045 {"OUTPUT", "o"},
00046 {"PARAM", "c"},
00047 {"<texture>", "<texture>"}
00048 };
00049
00052 struct {
00053 ArbRegType type;
00054 char* name;
00055 bool indexed;
00056 } arbRegBindingInfo[] = {
00057 {SH_ARB_REG_PARAM, "program.local", true},
00058 {SH_ARB_REG_PARAM, "program.env", true},
00059 {SH_ARB_REG_PARAM, "<nil>", true},
00060 {SH_ARB_REG_OUTPUT, "result.color", false},
00061
00062 {SH_ARB_REG_ATTRIB, "vertex.position", false},
00063 {SH_ARB_REG_ATTRIB, "vertex.weight", true},
00064 {SH_ARB_REG_ATTRIB, "vertex.normal", false},
00065 {SH_ARB_REG_ATTRIB, "vertex.color", false},
00066 {SH_ARB_REG_ATTRIB, "vertex.fogcoord", false},
00067 {SH_ARB_REG_ATTRIB, "vertex.texcoord", true},
00068 {SH_ARB_REG_ATTRIB, "vertex.matrixindex", true},
00069 {SH_ARB_REG_ATTRIB, "vertex.attrib", true},
00070 {SH_ARB_REG_OUTPUT, "result.position", false},
00071 {SH_ARB_REG_OUTPUT, "result.fogcoord", false},
00072 {SH_ARB_REG_OUTPUT, "result.pointsize", false},
00073 {SH_ARB_REG_OUTPUT, "result.texcoord", true},
00074
00075 {SH_ARB_REG_ATTRIB, "fragment.color", false},
00076 {SH_ARB_REG_ATTRIB, "fragment.texcoord", true},
00077 {SH_ARB_REG_ATTRIB, "fragment.fogcoord", false},
00078 {SH_ARB_REG_ATTRIB, "fragment.position", false},
00079 {SH_ARB_REG_OUTPUT, "result.depth", false},
00080
00081 {SH_ARB_REG_ATTRIB, "<nil>", false},
00082 };
00083
00084 ArbReg::ArbReg()
00085 : type(SH_ARB_REG_TEMP), index(-1), name("")
00086 {
00087 binding.type = SH_ARB_REG_NONE;
00088 binding.index = -1;
00089 binding.count = 1;
00090 }
00091
00092 ArbReg::ArbReg(ArbRegType type, int index, std::string name)
00093 : type(type), index(index), name(name)
00094 {
00095 binding.type = SH_ARB_REG_NONE;
00096 binding.index = -1;
00097 binding.count = 1;
00098 }
00099
00100
00101 std::ostream& ArbReg::printDecl(std::ostream& out) const
00102 {
00103 out << arbRegTypeInfo[type].name << " " << *this;
00104 if (type == SH_ARB_REG_CONST) {
00105 out << " = " << "{";
00106 for (int i = 0; i < 4; i++) {
00107 if (i) out << ", ";
00108 out << binding.values[i];
00109 }
00110 out << "}";
00111 } else if (binding.type != SH_ARB_REG_NONE) {
00112 if (binding.type == SH_ARB_REG_STATE)
00113 {
00114 out << " = " << binding.name;
00115 }
00116 else
00117 {
00118 if (binding.count > 1) {
00119 out << "[" << binding.count << "]";
00120 }
00121 out << " = ";
00122 if (binding.count > 1) out << "{ ";
00123 out << arbRegBindingInfo[binding.type].name;
00124 if (arbRegBindingInfo[binding.type].indexed) {
00125 out << "[" << binding.index;
00126 if (binding.count > 1) {
00127 out << " .. " << (binding.index + binding.count - 1);
00128 }
00129 out << "]";
00130 }
00131 if (binding.count > 1) out << " }";
00132 }
00133 }
00134 out << ";";
00135 if(!name.empty() && type != SH_ARB_REG_CONST) out << " # " << name;
00136 return out;
00137 }
00138
00141 std::ostream& operator<<(std::ostream& out, const ArbReg& reg)
00142 {
00143 out << arbRegTypeInfo[reg.type].estName << reg.index;
00144 return out;
00145 }
00146
00147 }