Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ArbReg.cpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory
00004 // Project administrator: Michael D. McCool
00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa,
00006 //          Michael D. McCool
00007 // 
00008 // This software is provided 'as-is', without any express or implied
00009 // warranty. In no event will the authors be held liable for any damages
00010 // arising from the use of this software.
00011 // 
00012 // Permission is granted to anyone to use this software for any purpose,
00013 // including commercial applications, and to alter it and redistribute it
00014 // freely, subject to the following restrictions:
00015 // 
00016 // 1. The origin of this software must not be misrepresented; you must
00017 // not claim that you wrote the original software. If you use this
00018 // software in a product, an acknowledgment in the product documentation
00019 // would be appreciated but is not required.
00020 // 
00021 // 2. Altered source versions must be plainly marked as such, and must
00022 // not be misrepresented as being the original software.
00023 // 
00024 // 3. This notice may not be removed or altered from any source
00025 // distribution.
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}, // TODO: Special case?
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}, // TODO: Special case?
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}, // TODO: Special case?
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 }

Generated on Mon Jan 24 18:36:29 2005 for Sh by  doxygen 1.4.1