Results 1 to 3 of 3

Thread: Very Basic Question

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    2

    Very Basic Question

    Hi all,
    I'm very new to OpenCL and I'm trying to figure out how I'd write a (very) simple function. Essentially I need to be able to alter the values of the arguments to a function without returning them. Is there an equivalent to the inout parameter in GLSL?

    In C it would be
    Code :
    void ContourTree::switchPoints(Point& a, Point& b)
    {
    	Point switch_point = a;
    	a = b;
    	b = switch_point;
    }

    In GLSL it looks like
    Code :
    void switchPoints(inout vec3 a, inout vec3 b)
    {
    	vec3 switch_pt = a;
    	a = b;
    	b = switch_pt;
    }

    I thought that this would work, but it doesn't seem to for some reason:
    Code :
    void
    test( float* a,
    	float* b)
    {
    	float* temp = a;
    	a = b;
    	b = temp;
    }

    wherein I call it like so
    Code :
    test(&a, &b);
    I'm sure I'm missing something very basic here.

  2. #2

    Re: Very Basic Question

    Quote Originally Posted by bmac
    Hi all,
    I'm very new to OpenCL and I'm trying to figure out how I'd write a (very) simple function. Essentially I need to be able to alter the values of the arguments to a function without returning them. Is there an equivalent to the inout parameter in GLSL?

    I thought that this would work, but it doesn't seem to for some reason:
    Code :
    void
    test( float* a,
    	float* b)
    {
    	float* temp = a;
    	a = b;
    	b = temp;
    }
    It seems to me that you are swapping pointers instead of the values pointed to. Try

    Code :
    void
    test( float* a,
    	float* b)
    {
    	float temp = *a;
    	*a = *b;
    	*b = temp;
    }

  3. #3
    Junior Member
    Join Date
    Dec 2009
    Posts
    2

    Re: Very Basic Question

    That's it. Thank you very much.

Similar Threads

  1. Basic question
    By sajis997 in forum OpenCL
    Replies: 1
    Last Post: 11-12-2012, 11:34 AM
  2. A Basic question
    By johnvarghese in forum OpenML Coding & Technical Issues
    Replies: 3
    Last Post: 03-31-2005, 04:39 PM

Posting Permissions

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