vxKernel/src/modules/display/draw/dpixel.c

58 lines
1.2 KiB
C

#include <vhex/display.h>
#include <vhex/defs/attributes.h>
#include <vhex/defs/types.h>
//---
// Kernel-level API
//---
/* dpixel_render() : drawing algorithm */
void dpixel_render(struct dshader_surface *surface, int x, int y, int color)
{
if (color == C_NONE)
return;
/* check point culling */
if (y < surface->y
|| x < surface->x
|| y >= (int)(surface->y + surface->height)
|| x >= (int)(surface->x + surface->width)) {
return;
}
/* calculate the draw index */
int real_y = (y - surface->y) * surface->width;
int real_x = (x - surface->x);
int draw_idx = real_y + real_x;
/* handle special color */
//uint16_t *draw = surface->draw;
uint16_t *frag = surface->frag;
if (color == C_INVERT)
color = frag[draw_idx] ^ 0xffff;
/* set the pixel */
frag[draw_idx] = color;
}
/* dpixel_render_dstack() : dstack-API compatible render */
void dpixel_render_dstack(struct dshader_surface *surface, uint32_t *arg)
{
dpixel_render(surface, arg[0], arg[1], arg[2]);
}
//---
// User-level API
//---
/* dpixel() : draw a pixel in screen */
did_t dpixel(int x, int y, int color)
{
return dstack_add_action(
&DSTACK_CALL(&dpixel_render_dstack, x, y, color),
NULL,
NULL
);
}