Jump to content

View more

Image of the Day

The beast has a mighty searchlight of evil! #screenshotsaturday https://t.co/bzKepOojDL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

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

4: Adsense

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   

258
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!



#2 Deortuka   Members   

499
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   

258
Like
0Likes
Like

Posted 12 April 2013 - 07:23 AM

Thank you!



#4 Brother Bob   Moderators   

10281
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   

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   

499
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   Members   

33692
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' or 'SotL' 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]




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.