Skip to content

Commit 2498a89

Browse files
committed
rg_display: improved rendering compatibility with the differents formats available
1 parent 33e814f commit 2498a89

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

components/retro-go/rg_display.c

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -297,46 +297,47 @@ static inline void write_update(const rg_surface_t *update)
297297
// FIXME: only redraw when background has changed
298298
for (size_t y = 0; y < height;)
299299
{
300-
uint16_t *lcd_buffer = lcd_get_buffer(LCD_BUFFER_LENGTH);
300+
uint16_t *line_buffer = lcd_get_buffer(LCD_BUFFER_LENGTH);
301301
size_t num_lines = RG_MIN(LCD_BUFFER_LENGTH / width, height - y);
302302

303303
// Copy line by line because stride may not match width
304304
for (size_t line = 0; line < num_lines; ++line)
305305
{
306-
uint16_t *viewport = (void *)data + map_viewport_to_source_y[y + line] * stride;
307306
uint16_t *osd_buffer = (void *)buffer + (y + line) * osd.surface->width * 2;
308-
uint16_t *dst = lcd_buffer + (line * width);
309-
for (size_t i = 0; i < width; ++i)
310-
{
311-
if(osd.has_transparency && osd_buffer[i] == C_TRANSPARENT)
312-
{
313-
if((y+line)>=y0 && (i-draw_left)>=x0 && (y+line)<=min_height && (i-draw_left)<=min_width)
314-
{ // the pixel is within the display surface and within the OSD
315-
switch(format)
316-
{
317-
case RG_PIXEL_PALETTE:
318-
dst[i] = palette[viewport[map_viewport_to_source_x[i]]];
319-
break;
320-
case RG_PIXEL_565_LE:
321-
dst[i] = (viewport[map_viewport_to_source_x[i]] >> 8) | (viewport[map_viewport_to_source_x[i]] << 8);
322-
break;
323-
default:
324-
dst[i] = viewport[map_viewport_to_source_x[i]];
325-
}
326-
}
327-
else
328-
{
329-
dst[i] = 0x0000; // the ideal would be to put a "background" color
330-
}
331-
}
332-
else
333-
{
334-
dst[i] = (osd_buffer[i] >> 8) | (osd_buffer[i] << 8);
307+
uint16_t *dst = line_buffer + (line * width);
308+
309+
#define OSD_TO_SCREEN(PTR_TYPE, BACKGROUND_PIXEL) { \
310+
PTR_TYPE *viewport = (PTR_TYPE *)data; \
311+
if(y + line >= draw_top){ \
312+
viewport += ((map_viewport_to_source_y[y + line - draw_top] * stride) >> 1); \
313+
} \
314+
else{ \
315+
viewport += ((map_viewport_to_source_y[y + line] * stride) >> 1); \
316+
} \
317+
for (size_t x = 0; x < width; ++x){ \
318+
if(osd.has_transparency && osd_buffer[x] == C_TRANSPARENT){ \
319+
if((y+line)>=y0 && (x-draw_left)>=x0 && (y+line)<=min_height && (x-draw_left)<=min_width){\
320+
dst[x] = BACKGROUND_PIXEL; \
321+
} \
322+
else{ \
323+
dst[x] = 0x0000; \
324+
} \
325+
} \
326+
else{ \
327+
dst[x] = (osd_buffer[x] >> 8) | (osd_buffer[x] << 8); \
328+
} \
329+
} \
335330
}
336-
}
331+
332+
if (format & RG_PIXEL_PALETTE)
333+
OSD_TO_SCREEN(uint8_t, palette[viewport[map_viewport_to_source_x[x - draw_left]]])
334+
else if (format == RG_PIXEL_565_LE)
335+
OSD_TO_SCREEN(uint16_t, (viewport[map_viewport_to_source_x[x - draw_left]] >> 8) | (viewport[map_viewport_to_source_x[x - draw_left]] << 8))
336+
else
337+
OSD_TO_SCREEN(uint16_t, viewport[map_viewport_to_source_x[x - draw_left]])
337338
}
338339

339-
lcd_send_buffer(lcd_buffer, width * num_lines);
340+
lcd_send_buffer(line_buffer, width * num_lines);
340341
y += num_lines;
341342
}
342343
lcd_sync();

0 commit comments

Comments
 (0)