add an overdraw buffer to allow for layered rendering
This commit is contained in:
@@ -2,16 +2,36 @@
|
||||
#include <dangerzone/render/misc.h>
|
||||
#include <dangerzone/render/rect.h>
|
||||
|
||||
#include "internal/engine_internal.h"
|
||||
#include "internal/util/error.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// helper function to return the correct pointer to a framebuffer for drawing selection
|
||||
uint32_t*
|
||||
get_framebuffer(
|
||||
framebuffer_e framebuffer
|
||||
) {
|
||||
switch (framebuffer) {
|
||||
case BASE:
|
||||
return game_state->framebuffer_base;
|
||||
case OVERDRAW:
|
||||
return game_state->framebuffer_overdraw;
|
||||
default:
|
||||
return game_state->framebuffer_base;
|
||||
}
|
||||
}
|
||||
|
||||
// alter a pixel at an imaginary x & y coordinates
|
||||
void
|
||||
put_pixel(
|
||||
framebuffer_e framebuffer,
|
||||
unsigned int x,
|
||||
unsigned int y,
|
||||
uint32_t color
|
||||
) {
|
||||
uint32_t *current_framebuffer = get_framebuffer(framebuffer);
|
||||
|
||||
uint16_t w = game_state->width;
|
||||
uint16_t h = game_state->height;
|
||||
|
||||
@@ -21,7 +41,7 @@ put_pixel(
|
||||
"at x = %d, y = %d", x, y
|
||||
);
|
||||
} else {
|
||||
game_state->framebuffer[game_state->width * y + x]
|
||||
current_framebuffer[game_state->width * y + x]
|
||||
= color;
|
||||
|
||||
mark_dirty_rect(x, y, 1, 1);
|
||||
@@ -31,12 +51,15 @@ put_pixel(
|
||||
// fill the entire framebuffer with a given color
|
||||
void
|
||||
clear_framebuffer(
|
||||
framebuffer_e framebuffer,
|
||||
uint32_t color
|
||||
) {
|
||||
uint32_t *current_framebuffer = get_framebuffer(framebuffer);
|
||||
|
||||
for (size_t i = 0;
|
||||
i < (size_t)game_state->width * game_state->height;
|
||||
++i) {
|
||||
game_state->framebuffer[i] = color;
|
||||
current_framebuffer[i] = color;
|
||||
}
|
||||
|
||||
mark_dirty_rect(
|
||||
@@ -45,4 +68,4 @@ clear_framebuffer(
|
||||
game_state->width,
|
||||
game_state->height
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user