Shmup/src/pixelshader.cpp

60 lines
1.2 KiB
C++

#include <azur/gint/render.h>
#include "MyAzurShaders.h"
uint8_t AZRP_SHADER_PIXEL = -1;
__attribute__((constructor))
static void register_shader(void)
{
extern azrp_shader_t azrp_shader_pixel;
AZRP_SHADER_PIXEL = azrp_register_shader(azrp_shader_pixel);
}
void azrp_shader_pixel_configure(void)
{
azrp_set_uniforms(AZRP_SHADER_PIXEL, (void *)azrp_width);
}
struct command {
uint8_t shader_id;
uint16_t x;
uint16_t y;
uint16_t color;
};
void azrp_pixel(int x1, int y1, int color)
{
prof_enter(azrp_perf_cmdgen);
if(x1 >= azrp_width || x1 < 0 || y1 >= azrp_height || y1 < 0) {
prof_leave(azrp_perf_cmdgen);
return;
}
int frag_first = y1 >> 4;
int frag_count = 1;
int first_offset = y1 & 15;
struct command cmd;
cmd.shader_id = AZRP_SHADER_PIXEL;
cmd.y = first_offset;
cmd.x = x1;
cmd.color = color;
azrp_queue_command(&cmd, sizeof cmd, frag_first, 1);
prof_leave(azrp_perf_cmdgen);
}
void azrp_shader_pixel( void *uniforms, void *command, void *fragment )
{
struct command *cmd = (struct command *) command;
uint16_t *frag = (uint16_t *) fragment;
frag[azrp_width * cmd->y + cmd->x] = cmd->color;
}