129 lines
2.4 KiB
C++
129 lines
2.4 KiB
C++
#include <azur/gint/render.h>
|
|
#include "fractalshaders.h"
|
|
#include <cstdlib>
|
|
#include <cstdio>
|
|
|
|
#include <gint/rtc.h>
|
|
#include <gint/usb.h>
|
|
#include <gint/usb-ff-bulk.h>
|
|
|
|
#include <num/num.h>
|
|
|
|
|
|
|
|
uint8_t AZRP_SHADER_MANDELBROT = -1;
|
|
|
|
|
|
__attribute__((constructor))
|
|
static void register_shader(void)
|
|
{
|
|
extern azrp_shader_t azrp_shader_mandelbrot;
|
|
AZRP_SHADER_MANDELBROT = azrp_register_shader(azrp_shader_mandelbrot);
|
|
}
|
|
|
|
|
|
void azrp_shader_mandelbrot_configure(void)
|
|
{
|
|
azrp_set_uniforms(AZRP_SHADER_MANDELBROT, (void *)azrp_width);
|
|
}
|
|
|
|
|
|
void azrp_mandelbrot_USBDEBUG( void )
|
|
{
|
|
char texttosend[1024];
|
|
|
|
sprintf( texttosend, "data" );
|
|
usb_fxlink_text(texttosend, 0);
|
|
|
|
}
|
|
|
|
|
|
void azrp_mandelbrot_init( )
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void azrp_mandelbrot_close( void )
|
|
{
|
|
|
|
}
|
|
|
|
|
|
struct command {
|
|
uint8_t shader_id;
|
|
uint8_t current_frag;
|
|
libnum::num xmin;
|
|
libnum::num xmax;
|
|
libnum::num ymin;
|
|
libnum::num ymax;
|
|
libnum::num xinc;
|
|
libnum::num yinc;
|
|
};
|
|
|
|
|
|
void azrp_mandelbrot( void )
|
|
{
|
|
prof_enter(azrp_perf_cmdgen);
|
|
|
|
struct command cmd;
|
|
|
|
cmd.shader_id = AZRP_SHADER_MANDELBROT;
|
|
cmd.current_frag = 0;
|
|
cmd.xmin = libnum::num(-2.48f);
|
|
cmd.xmax = libnum::num(1.48f);
|
|
cmd.ymin = libnum::num(-1.12f);
|
|
cmd.ymax = libnum::num(1.12f);
|
|
cmd.xinc = libnum::num((2*1.98f)/azrp_width);
|
|
cmd.yinc = libnum::num((2*1.12f)/azrp_height);
|
|
int fragmin = 0;
|
|
int fragcount = (azrp_height >> 4) + 1;
|
|
|
|
azrp_queue_command(&cmd, sizeof cmd, fragmin, fragcount);
|
|
prof_leave(azrp_perf_cmdgen);
|
|
}
|
|
|
|
extern "C" {
|
|
extern int mandelbrot(int32_t cr, int32_t ci, uint32_t t_squared, int steps);
|
|
}
|
|
|
|
void azrp_shader_mandelbrot( void *uniforms, void *comnd, void *fragment )
|
|
{
|
|
struct command *cmd = (struct command *) comnd;
|
|
uint16_t *frag = (uint16_t *) fragment;
|
|
|
|
int maxiter = 60;
|
|
|
|
libnum::num zr, zi;
|
|
|
|
libnum::num zrsave = cmd->xmin;
|
|
libnum::num zisave = cmd->ymax - libnum::num(cmd->current_frag*16)*cmd->yinc;
|
|
|
|
int u;
|
|
|
|
int offset = 0;
|
|
|
|
for( int j=0; j<16; j++)
|
|
{
|
|
for( int i=0; i<azrp_width; i++ )
|
|
{
|
|
zr = zrsave;
|
|
zi = zisave;
|
|
|
|
u = mandelbrot( zr.v, zi.v, (2*2)<<16, maxiter );
|
|
|
|
if (u==0) frag[offset + i] = C_RGB(255,255,255);
|
|
else frag[offset + i] = C_RGB(u*4,u*4,u*4);
|
|
|
|
zrsave += cmd->xinc;
|
|
}
|
|
|
|
zrsave = cmd->xmin;
|
|
zisave -= cmd->yinc;
|
|
|
|
offset += azrp_width;
|
|
}
|
|
|
|
cmd->current_frag++;
|
|
}
|