00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024 const char* cc_texture_string[] = {
00025 "// Sh: A GPU metaprogramming language.\n",
00026 "//\n",
00027 "// Copyright 2003-2005 Serious Hack Inc.\n",
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 "
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 "template<int TexDims, int TexSize, int TexWidth, int TexHeight, int TexDepth, typename TexType,\n",
00093 " typename SrcWrap, typename IndexType, typename MemoryType> \n",
00094 "void sh_cc_backend_lookupi(const void *texture, IndexType *src, MemoryType *dest)\n",
00095 "{\n",
00096 " const TexType* data = reinterpret_cast<const TexType*>(texture);\n",
00097 " int index = 0;\n",
00098 " if(TexDims == 3) index = SrcWrap::wrap(sh_cc_backend_nearest(src[2]), TexDepth);\n",
00099 " if(TexDims >= 2) index = SrcWrap::wrap(sh_cc_backend_nearest(src[1]), TexHeight) \n",
00100 " + TexHeight * index;\n",
00101 " index = SrcWrap::wrap(sh_cc_backend_nearest(src[0]), TexWidth)\n",
00102 " + TexWidth * index;\n",
00103 "\n",
00104 " int start = index * TexSize; \n",
00105 " for(int i = 0; i < TexSize; ++i) {\n",
00106 " dest[i] = static_cast<MemoryType>(data[start + i]); \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 IndexType, typename MemoryType> \n",
00112 "void sh_cc_backend_lookup(const void *texture, IndexType *src, MemoryType *dest)\n",
00113 "{\n",
00114 " IndexType scaled_src[TexDims];\n",
00115 " scaled_src[0] = TexWidth * src[0];\n",
00116 " if(TexDims > 1) scaled_src[1] = TexHeight * src[1];\n",
00117 " if(TexDims > 2) scaled_src[2] = TexDepth * src[2];\n",
00118 "\n",
00119 " sh_cc_backend_lookupi<TexDims, TexSize, TexWidth, TexHeight, TexDepth, TexType, \n",
00120 " SrcWrap>(texture, scaled_src, dest);\n",
00121 "}\n",
00122 "\n",
00123 ""};