Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


C++ TBB simple/silly 2D->1D array question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 mynameisnafe   Members   -  Reputation: 252

Like
0Likes
Like

Posted 12 April 2013 - 06:59 AM

So I've got mandelbrot running in OpenCL: I am to compare it to Intels TBB.

 

This is something I really should know by now and I feel silly asking.

 

I have a struct that represents an RGBA pixel, and I create a buffer of them - a bitmap

BGRA8* buffer = (BGRA8*)malloc( width * height * sizeof(BGRA8) );

Then I iterate through x and y doing whatever using parallel_for

 

Where do I put my x, y in terms of

buffer[ index ]

?

 

Thanks in advance, I know this is a silly question!



Sponsor:

#2 Deortuka   Members   -  Reputation: 493

Like
3Likes
Like

Posted 12 April 2013 - 07:02 AM

BGRA8& pixel = buffer[(y * width) + x];

Edited by Deortuka, 12 April 2013 - 10:42 AM.


#3 mynameisnafe   Members   -  Reputation: 252

Like
0Likes
Like

Posted 12 April 2013 - 07:23 AM

Thank you!



#4 Brother Bob   Moderators   -  Reputation: 8570

Like
3Likes
Like

Posted 12 April 2013 - 08:00 AM

Drop the size from the index equation. Pointer arithmetics already takes the size of its type into account.



#5 AgPF6   Members   -  Reputation: 165

Like
0Likes
Like

Posted 12 April 2013 - 09:18 AM

You would access it by the same way you access anything:  by the way you defined it in your struct, except that you don't use this "->" you use this ".". 

 

buffer [index].x



#6 Deortuka   Members   -  Reputation: 493

Like
0Likes
Like

Posted 12 April 2013 - 10:41 AM

For some reason I assumed that buffer was a pointer to bytes and not a pointer to BGRA8. That was a mistake on my part. I have edited my previous answer to take that into account.

 

Sorry for the mistake.


Edited by Deortuka, 12 April 2013 - 11:58 AM.


#7 Servant of the Lord   Crossbones+   -  Reputation: 20921

Like
1Likes
Like

Posted 12 April 2013 - 12:13 PM

I posted in a thread a bit ago trying to explain it. I might not have done that great a job word-wise, but at least there are pretty pictures to illustrate! biggrin.png


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS