Added a Shader to Azur to render a pixel with pixel(x, y, color)

This commit is contained in:
Sylvain PILLOT 2023-01-08 23:21:23 +01:00
parent aa1daa9b7e
commit df570a43c7
5 changed files with 74 additions and 8 deletions

View File

@ -15,17 +15,13 @@ set(SOURCES
src/main.cpp
src/utilities.cpp
src/particles.cpp
src/pixelshader.cpp
# ...
)
set(ASSETS_cg
assets-cg/font.png
assets-cg/Sprites/emp_circ.png
assets-cg/Sprites/fill_circ_0.png
#assets-cg/Sprites/fill_circ_1.png
#assets-cg/Sprites/fill_circ_2.png
#assets-cg/Sprites/fill_circ_3.png
#assets-cg/Sprites/fill_circ_4.png
#assets-cg/Sprites/fill_circ_5.png
assets-cg/Sprites/fill_circ.png
# ...
)

View File

@ -26,6 +26,8 @@
#include <vector>
#include <algorithm>
#include "pixelshader.h"
bool screenshot = false;
bool record = false;
@ -153,6 +155,12 @@ int main(void)
// all the stuff to be rendered should be put here
azrp_clear( C_BLACK );
azrp_pixel( 158, 11, 0xFFFF );
azrp_pixel( 157, 12, 0xFFFF );
azrp_pixel( 158, 12, 0xFFFF );
azrp_pixel( 159, 12, 0xFFFF );
azrp_pixel( 158, 13, 0xFFFF );
#if(BIAS)
if (texttodraw>=1) Azur_draw_text(1,01, " FPS = %.0f", (float) (1000000.0f / elapsedTime) );
if (texttodraw>=1) Azur_draw_text(1,11, "Parts = %d", MyParticles.size() );

View File

@ -9,7 +9,7 @@
#include <num/num.h>
extern bopti_image_t img_fill_circ_0;
extern bopti_image_t img_fill_circ;
Particle::Particle( uint16_t lx, uint16_t ly )
@ -65,7 +65,7 @@ void Particle::Render( )
else color = 0xFFFF; // White
azrp_subimage_p8_dye( px-7, py-7,
&img_fill_circ_0,
&img_fill_circ,
dximg+7-sz, 7-sz, sz*2, sz*2,
IMAGE_DYE, color );
}

59
src/pixelshader.cpp Normal file
View File

@ -0,0 +1,59 @@
#include <azur/gint/render.h>
#include "pixelshader.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 {
uint16_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);
/* Find a rectangle containing the triangle */
if(x1 >= azrp_width || x1 < 0 || y1 >= azrp_height || y1 < 0) {
prof_leave(azrp_perf_cmdgen);
return;
}
/* TODO: Have a proper way to do optimized-division by azrp_frag_height
TODO: Also account for first-fragment offset */
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;
}

3
src/pixelshader.h Normal file
View File

@ -0,0 +1,3 @@
void azrp_pixel(int x1, int y1, int color);