00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020
00036
00037
00038
00039
00040 template<typename T>
00041 inline int sh_cc_backend_nearest(T value)
00042 {
00043 return (int)(floor(static_cast<double>(value)));
00044 }
00045
00046 struct sh_gcc_backend_wrap_clamp
00047 {
00048 static inline int wrap(int src, int Max)
00049 {
00050 return src >= Max ? Max - 1 : (src < 0 ? 0 : src);
00051 }
00052 };
00053
00054 struct sh_gcc_backend_wrap_repeat
00055 {
00056 static int wrap(int src, int Max)
00057 {
00058 src %= Max;
00059 if(src < 0) src += Max;
00060 return src;
00061 }
00062 };
00063
00064 template<int TexDims, int TexSize, int TexWidth, int TexHeight, int TexDepth, typename TexType,
00065 typename SrcWrap, typename IndexType, typename MemoryType>
00066 void sh_cc_backend_lookupi(const void *texture, IndexType *src, MemoryType *dest)
00067 {
00068 const TexType* data = reinterpret_cast<const TexType*>(texture);
00069 int index = 0;
00070 if(TexDims == 3) index = SrcWrap::wrap(sh_cc_backend_nearest(src[2]), TexDepth);
00071 if(TexDims >= 2) index = SrcWrap::wrap(sh_cc_backend_nearest(src[1]), TexHeight)
00072 + TexHeight * index;
00073 index = SrcWrap::wrap(sh_cc_backend_nearest(src[0]), TexWidth)
00074 + TexWidth * index;
00075
00076 int start = index * TexSize;
00077 for(int i = 0; i < TexSize; ++i) {
00078 dest[i] = static_cast<MemoryType>(data[start + i]);
00079 }
00080 }
00081
00082 template<int TexDims, int TexSize, int TexWidth, int TexHeight, int TexDepth, typename TexType,
00083 typename SrcWrap, typename IndexType, typename MemoryType>
00084 void sh_cc_backend_lookup(const void *texture, IndexType *src, MemoryType *dest)
00085 {
00086 IndexType scaled_src[TexDims];
00087 scaled_src[0] = TexWidth * src[0];
00088 if(TexDims > 1) scaled_src[1] = TexHeight * src[1];
00089 if(TexDims > 2) scaled_src[2] = TexDepth * src[2];
00090
00091 sh_cc_backend_lookupi<TexDims, TexSize, TexWidth, TexHeight, TexDepth, TexType,
00092 SrcWrap>(texture, scaled_src, dest);
00093 }
00094