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 library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 const char* cc_texture_string[] = {
00021 "// Sh: A GPU metaprogramming language.\n",
00022 "//\n",
00023 "// Copyright 2003-2005 Serious Hack Inc.\n",
00024 "// \n",
00025 "// This library is free software; you can redistribute it and/or\n",
00026 "// modify it under the terms of the GNU Lesser General Public\n",
00027 "// License as published by the Free Software Foundation; either\n",
00028 "// version 2.1 of the License, or (at your option) any later version.\n",
00029 "//\n"
00030 "// This library is distributed in the hope that it will be useful,\n",
00031 "// but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
00032 "// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n",
00033 "// Lesser General Public License for more details.\n",
00034 "//\n",
00035 "// You should have received a copy of the GNU Lesser General Public\n",
00036 "// License along with this library; if not, write to the Free Software\n",
00037 "// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,\n",
00038 "// MA  02110-1301, USA\n",
00039 "
00040 "\n",
00041 "\n",
00055 "\n",
00056 "// @todo type\n",
00057 "// add casting code for when MemoryType is not equivalent to the type used in computation\n",
00058 "\n",
00059 "// floor and clamp to [0, max) for aninteger lookup\n",
00060 "template<typename T>\n",
00061 "inline int sh_cc_backend_nearest(T value)\n",
00062 "{\n",
00063 "  return (int)(floor(static_cast<double>(value))); \n",
00064 "}\n",
00065 "\n",
00066 "struct sh_gcc_backend_wrap_clamp\n",
00067 "{\n",
00068 "  static inline int wrap(int src, int Max) \n",
00069 "  {\n",
00070 "    return src >= Max ? Max - 1 : (src < 0 ? 0 : src);\n",
00071 "  }\n",
00072 "};\n",
00073 "\n",
00074 "struct sh_gcc_backend_wrap_repeat\n",
00075 "{\n",
00076 "  static int wrap(int src, int Max) \n",
00077 "  {\n",
00078 "    src %= Max;\n",
00079 "    if(src < 0) src += Max;\n",
00080 "    return src; \n",
00081 "  }\n",
00082 "};\n",
00083 "\n",
00084 "template<int TexDims, int TexSize, int TexWidth, int TexHeight, int TexDepth, typename TexType,\n",
00085 "  typename SrcWrap, typename IndexType, typename MemoryType> \n",
00086 "void sh_cc_backend_lookupi(const void *texture, IndexType *src, MemoryType *dest)\n",
00087 "{\n",
00088 "  const TexType* data = reinterpret_cast<const TexType*>(texture);\n",
00089 "  int index = 0;\n",
00090 "  if(TexDims == 3) index = SrcWrap::wrap(sh_cc_backend_nearest(src[2]), TexDepth);\n",
00091 "  if(TexDims >= 2) index = SrcWrap::wrap(sh_cc_backend_nearest(src[1]), TexHeight) \n",
00092 "      + TexHeight * index;\n",
00093 "  index = SrcWrap::wrap(sh_cc_backend_nearest(src[0]), TexWidth)\n",
00094 "          + TexWidth * index;\n",
00095 "\n",
00096 "  int start = index * TexSize; \n",
00097 "  for(int i = 0; i < TexSize; ++i) {\n",
00098 "    dest[i] = static_cast<MemoryType>(data[start + i]); \n",
00099 "  }\n",
00100 "}\n",
00101 "\n",
00102 "template<int TexDims, int TexSize, int TexWidth, int TexHeight, int TexDepth, typename TexType,\n",
00103 "  typename SrcWrap, typename IndexType, typename MemoryType> \n",
00104 "void sh_cc_backend_lookup(const void *texture, IndexType *src, MemoryType *dest)\n",
00105 "{\n",
00106 "  IndexType scaled_src[TexDims];\n",
00107 "  scaled_src[0] = TexWidth * src[0];\n",
00108 "  if(TexDims > 1) scaled_src[1] = TexHeight * src[1];\n",
00109 "  if(TexDims > 2) scaled_src[2] = TexDepth * src[2];\n",
00110 "\n",
00111 "  sh_cc_backend_lookupi<TexDims, TexSize, TexWidth, TexHeight, TexDepth, TexType, \n",
00112 "    SrcWrap>(texture, scaled_src, dest);\n",
00113 "}\n",
00114 "\n",
00115 ""};

Generated on Thu Jul 28 17:33:00 2005 for Sh by  doxygen 1.4.3-20050530