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

CcTexturesString.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This software is provided 'as-is', without any express or implied
00006 // warranty. In no event will the authors be held liable for any damages
00007 // arising from the use of this software.
00008 // 
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it
00011 // freely, subject to the following restrictions:
00012 // 
00013 // 1. The origin of this software must not be misrepresented; you must
00014 // not claim that you wrote the original software. If you use this
00015 // software in a product, an acknowledgment in the product documentation
00016 // would be appreciated but is not required.
00017 // 
00018 // 2. Altered source versions must be plainly marked as such, and must
00019 // not be misrepresented as being the original software.
00020 // 
00021 // 3. This notice may not be removed or altered from any source
00022 // distribution.
00024 const char* cc_texture_string[] = {
00025 "// Sh: A GPU metaprogramming language.\n",
00026 "//\n",
00027 "// Copyright 2003-2005 Serious Hack Inc.",
00028 "// \n",
00029 "// This software is provided 'as-is', without any express or implied\n",
00030 "// warranty. In no event will the authors be held liable for any damages\n",
00031 "// arising from the use of this software.\n",
00032 "// \n",
00033 "// Permission is granted to anyone to use this software for any purpose,\n",
00034 "// including commercial applications, and to alter it and redistribute it\n",
00035 "// freely, subject to the following restrictions:\n",
00036 "// \n",
00037 "// 1. The origin of this software must not be misrepresented; you must\n",
00038 "// not claim that you wrote the original software. If you use this\n",
00039 "// software in a product, an acknowledgment in the product documentation\n",
00040 "// would be appreciated but is not required.\n",
00041 "// \n",
00042 "// 2. Altered source versions must be plainly marked as such, and must\n",
00043 "// not be misrepresented as being the original software.\n",
00044 "// \n",
00045 "// 3. This notice may not be removed or altered from any source\n",
00046 "// distribution.\n",
00047 "
00048 "\n",
00049 "\n",
00063 "\n",
00064 "// @todo type\n",
00065 "// add casting code for when MemoryType is not equivalent to the type used in computation\n",
00066 "\n",
00067 "// floor and clamp to [0, max) for aninteger lookup\n",
00068 "template<typename T>\n",
00069 "inline int sh_cc_backend_nearest(T value)\n",
00070 "{\n",
00071 "  return (int)(floor(static_cast<double>(value))); \n",
00072 "}\n",
00073 "\n",
00074 "struct sh_gcc_backend_wrap_clamp\n",
00075 "{\n",
00076 "  static inline int wrap(int src, int Max) \n",
00077 "  {\n",
00078 "    return src >= Max ? Max - 1 : (src < 0 ? 0 : src);\n",
00079 "  }\n",
00080 "};\n",
00081 "\n",
00082 "struct sh_gcc_backend_wrap_repeat\n",
00083 "{\n",
00084 "  static int wrap(int src, int Max) \n",
00085 "  {\n",
00086 "    src %= Max;\n",
00087 "    if(src < 0) src += Max;\n",
00088 "    return src; \n",
00089 "  }\n",
00090 "};\n",
00091 "\n",
00092 "struct sh_gcc_backend_clamped\n",
00093 "{\n",
00094 "  template<typename T>\n",
00095 "  static inline T clamp(T dest) \n",
00096 "  {\n",
00097 "    return dest < 0 ? 0 : (dest > 1 ? 1 : dest);\n",
00098 "  }\n",
00099 "};\n",
00100 "\n",
00101 "struct sh_gcc_backend_unclamped\n",
00102 "{\n",
00103 "  template<typename T>\n",
00104 "  static inline T clamp(T dest) \n",
00105 "  {\n",
00106 "    return dest; \n",
00107 "  }\n",
00108 "};\n",
00109 "\n",
00110 "template<int TexDims, int TexSize, int TexWidth, int TexHeight, int TexDepth, typename TexType,\n",
00111 "  typename SrcWrap, typename DestClamp,\n",
00112 "  typename IndexType, typename MemoryType> \n",
00113 "void sh_cc_backend_lookupi(const void *texture, IndexType *src, MemoryType *dest)\n",
00114 "{\n",
00115 "  const TexType* data = reinterpret_cast<const TexType*>(texture);\n",
00116 "  int index = 0;\n",
00117 "  if(TexDims == 3) index = SrcWrap::wrap(sh_cc_backend_nearest(src[2]), TexDepth);\n",
00118 "  if(TexDims >= 2) index = SrcWrap::wrap(sh_cc_backend_nearest(src[1]), TexHeight) \n",
00119 "      + TexHeight * index;\n",
00120 "  index = SrcWrap::wrap(sh_cc_backend_nearest(src[0]), TexWidth)\n",
00121 "          + TexWidth * index;\n",
00122 "\n",
00123 "  int start = index * TexSize; \n",
00124 "  for(int i = 0; i < TexSize; ++i) {\n",
00125 "    dest[i] = static_cast<MemoryType>(DestClamp::clamp(data[start + i])); \n",
00126 "  }\n",
00127 "}\n",
00128 "\n",
00129 "template<int TexDims, int TexSize, int TexWidth, int TexHeight, int TexDepth, typename TexType,\n",
00130 "  typename SrcWrap, typename DestClamp,\n",
00131 "  typename IndexType, typename MemoryType> \n",
00132 "void sh_cc_backend_lookup(const void *texture, IndexType *src, MemoryType *dest)\n",
00133 "{\n",
00134 "  IndexType scaled_src[TexDims];\n",
00135 "  scaled_src[0] = TexWidth * src[0];\n",
00136 "  if(TexDims > 1) scaled_src[1] = TexHeight * src[1];\n",
00137 "  if(TexDims > 2) scaled_src[2] = TexDepth * src[2];\n",
00138 "\n",
00139 "  sh_cc_backend_lookupi<TexDims, TexSize, TexWidth, TexHeight, TexDepth, TexType, \n",
00140 "    SrcWrap, DestClamp>(texture, scaled_src, dest);\n",
00141 "}\n",
00142 "\n",
00143 ""};

Generated on Thu Apr 21 17:32:45 2005 for Sh by  doxygen 1.4.2