deltabeard / Peanut-GB

A Game Boy (DMG) emulator single header library written in C99. Performance is prioritised over accuracy.
https://projects.deltabeard.com/peanutgb/
276 stars 35 forks source link

core: frontend should provide pointer for pixel data #87

Open deltabeard opened 1 year ago

deltabeard commented 1 year ago

A function should be added to allow the frontend to provide a pointer to Peanut-GB for it to fill with pixel data. This function could be called at any time.

This could be used by the frontend to enable double buffering. This could also be used to make Peanut-GB draw each line of pixel data in a surface representing the LCD screen size.

void lcd_draw_line(struct gb_s *gb, const uint8_t *pixels, const uint_fast8_t line)
{
        struct priv *p = gb->priv;
        SDL_Surface *s = p->surf;
        /* "pixels" is already set to a pointer in the SDL surface from a previous
         * call to gb_set_pixels_ptr, so peanut-gb has already copied pixel data
         * for the line directly to the surface. */
        /* Set pointer to pixels for the next line. */
        gb_set_pixels_ptr(s->pixels + (LCD_WIDTH * line));
}