azrp: allow any point order in triangle shader

This commit is contained in:
Lephenixnoir 2023-05-29 09:50:06 +02:00
parent 6eeef0fce9
commit f3bd29fb32
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
3 changed files with 25 additions and 12 deletions

View File

@ -184,25 +184,24 @@ void azrp_hook_set_prefrag(azrp_hook_prefrag_t *);
//---
// Standard shaders
//
// None of the functions below acturally draw to the display; they all queue
// commands that get executed when azrp_render_fragment() or azrp_update() is
// called. They all return rather quickly and the time they take executing is
// counted towards command generation, not rendering.
//---
/* Clears the entire output with a single color */
extern uint8_t AZRP_SHADER_CLEAR;
/* Renders gint images with various dynamic effects */
extern uint8_t AZRP_SHADER_IMAGE_RGB16;
extern uint8_t AZRP_SHADER_IMAGE_P8;
extern uint8_t AZRP_SHADER_IMAGE_P4;
/* azrp_clear(): Clear output [ARZP_SHADER_CLEAR] */
/* azrp_clear(): Clear output with a flat color */
void azrp_clear(uint16_t color);
/* azrp_image(): Queue image command [AZRP_SHADER_IMAGE_*] */
/* azrp_image(): Render a full image, like dimage(). */
void azrp_image(int x, int y, bopti_image_t const *image);
/* azrp_subimage(): Queue image subsection command [AZRP_SHADER_IMAGE_*] */
/* azrp_subimage(): Render a section of an image, like dsubimage(). */
void azrp_subimage(int x, int y, bopti_image_t const *image,
int left, int top, int width, int height, int flags);
/* azrp_triangle(): Render a flat triangle. Points can be in any order. */
void azrp_triangle(int x1, int y1, int x2, int y2, int x3, int y3, int color);
/* See below for more detailed image functions. Dynamic effects are provided

View File

@ -1,6 +1,10 @@
#include <azur/gint/render.h>
#include <gint/defs/util.h>
extern uint8_t AZRP_SHADER_IMAGE_RGB16;
extern uint8_t AZRP_SHADER_IMAGE_P8;
extern uint8_t AZRP_SHADER_IMAGE_P4;
void azrp_queue_image(struct gint_image_box *box, image_t const *img,
struct gint_image_cmd *cmd)
{

View File

@ -29,7 +29,7 @@ struct command {
uint8_t shader_id;
/* Local y coordinate of the first line in the fragment */
uint8_t y;
/* Numebr of lines to render total, including this fragment */
/* Number of lines to render total, including this fragment */
uint8_t height_total;
/* Number of lines to render on the current fragment */
uint8_t height_frag;
@ -43,7 +43,7 @@ struct command {
int u0, v0, w0;
/* Variation of each coordinate for a movement in x */
int du_x, dv_x, dw_x;
/* Variation of each coordinate for a movement in y while canceling rows's
/* Variation of each coordinate for a movement in y while canceling rows'
movements in x */
int du_row, dv_row, dw_row;
};
@ -83,6 +83,16 @@ void azrp_triangle(int x1, int y1, int x2, int y2, int x3, int y3, int color)
cmd.x_max = max_x;
cmd.color = color;
/* Swap points 1 and 2 if the order of points is not left-handed */
if(edge_start(x1, y1, x2, y2, x3, y3) < 0) {
int xt = x1;
x1 = x2;
x2 = xt;
int yt = y1;
y1 = y2;
y2 = yt;
}
/* Vector products for barycentric coordinates */
cmd.u0 = edge_start(x2, y2, x3, y3, min_x, min_y);
cmd.du_x = y3 - y2;