Results 1 to 3 of 3

Thread: How to use tex2D

  1. #1
    Junior Member
    Join Date
    Oct 2010

    How to use tex2D

    Hi to everyone.
    I want to do an algorithm of image rotation. The code is like this

    Code :
    __global__ void Rotate(__read_only image2d_t imageIn, uchar4 * output, int width, int height, float angle)
     const int xOut=get_global_id(0); //block dimension x=16
     const int yOut=get_global_id(0); //block dimension y=4
     int x=(yout*width)+xOut;
     int y=(xOut*height)+yOut;
      if(x < width && y < height)
        // variables to hold the center coordinate of the image.
          // Texture operations use floating point coordinates
        float xf = (float)x - (float)width  / 2.0f;
        float yf = (float)y - (float)height / 2.0f;
        // transform to polar coordinates
        float r = sqrt((float)(xf*xf + yf*yf));
        float theta = atan2f(xf,yf) + 3.14159f / 2.0f;
        // compute the new theta by adding the rotation angle
        theta += radians(angle);
        // convert back to cartesian coordinates oriented at 0,0
        yf = r * sinf(theta);   
        yf += (float)h / 2.0f;
        xf = -r * cosf(theta);       
        xf += (float)w / 2.0f;  
        float4 out_val_f = tex2D(sampler,(float2)(xf,yf));
        // convert back to unsigned char and scale.
        uchar4 out_val;
        out_val.x = (unsigned char)(255.0f * out_val_f.x);
        out_val.y = (unsigned char)(255.0f * out_val_f.y);
        out_val.z = (unsigned char)(255.0f * out_val_f.z);
        out_val.w = 255;
        out_image[x] = out_val;

    I have the problem when i try to use tex2d and sampler_t. This is the error
    :117: error:unexpected type name 'float2' : expected expression float4 out_val_f=tex2D(sampler,(float2)(xf,yf));

    Help me

  2. #2
    Junior Member
    Join Date
    Oct 2010

    Re: How to use tex2D

    Sorry...This is the real error
    :117: error: incompatible type initializing 'int', expected 'float4' out_val_f=tex2D(sampler,(float2)(xf,yf));

  3. #3
    Senior Member
    Join Date
    May 2010
    Toronto, Canada

    Re: How to use tex2D

    There is no "tex2D" function in OpenCL. What you are looking for is called read_imagef(), which is explained in section 6.11.13 of the OpenCL 1.1. spec.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts