SimpleTexture_kernel.cu 954 B

123456789101112131415161718192021222324252627
  1. // declare texture reference for 2D float texture
  2. texture<float, 2, cudaReadModeElementType> tex;
  3. ////////////////////////////////////////////////////////////////////////////////
  4. //! Transform an image using texture lookups
  5. //! @param g_odata output data in global memory
  6. ////////////////////////////////////////////////////////////////////////////////
  7. extern "C"
  8. __global__ void
  9. transformKernel( float* g_odata, int width, int height, float theta)
  10. {
  11. // calculate normalized texture coordinates
  12. unsigned int x = blockIdx.x*blockDim.x + threadIdx.x;
  13. unsigned int y = blockIdx.y*blockDim.y + threadIdx.y;
  14. float u = x / (float) width;
  15. float v = y / (float) height;
  16. // transform coordinates
  17. u -= 0.5f;
  18. v -= 0.5f;
  19. float tu = u*cosf(theta) - v*sinf(theta) + 0.5f;
  20. float tv = v*cosf(theta) + u*sinf(theta) + 0.5f;
  21. // read from texture and write to global memory
  22. g_odata[y*width + x] = tex2D(tex, tu, tv);
  23. }