GMS 2 Get_Pixel alternative

Discussion in 'Programming' started by IGameArt, Apr 17, 2019 at 12:52 PM.

  1. IGameArt

    IGameArt Member

    Joined:
    Jun 21, 2016
    Posts:
    122
    Hey guys, it's been a while since I've really dug into the new buffers system but I remember seeing something about how much faster accessing a buffer directly is compared to using surface_get_pixel.

    So my question is, what's the most efficient (read absolute fastest) way to get the rgba values of a specific pixel in a surface/sprite?
     
  2. muki

    muki Member

    Joined:
    Mar 5, 2017
    Posts:
    216
    Are you looking to read more than a handful of pixels per frame? A whole surface maybe? If so, best to use a shader for that kind of work. That would be the fastest, but also more advanced.
     
  3. IGameArt

    IGameArt Member

    Joined:
    Jun 21, 2016
    Posts:
    122
    I'm trying to create an array carrying the values of each pixel in an image. This is not meant to be a realtime effect, it will be performed one time. And I cannot do it with a shader because shaders will not give me a value but merely display what data I put into it on the screen. I need to just find a faster way of getting the data of a certain pixel.
     
  4. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    488
    You are probably looking for buffer_get_surface . Once the buffer containing the RGBA values of the surface is set, reading its values should definitely be a lot faster than using getpixel functions.
     
  5. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,211
  6. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,436
    If you aren't using too many colors, you could consider making a ds_list of all the colors, create a second buffer that's 1/4 the size of the surface buffer, then retrieve the index in the list of each color and write the index to the second buffer. Now the second buffer has a 1-byte value for each pixel instead of a 4-byte value.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice