# HG changeset patch # User John Tsiombikas # Date 1458600907 -7200 # Node ID 11f024648101a9f2e996ae791f7cf88ebbbd523a initial diff -r 000000000000 -r 11f024648101 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Tue Mar 22 00:55:07 2016 +0200 @@ -0,0 +1,20 @@ +src = $(wildcard src/*.c) +obj = $(src:.c=.o) +bin = test + +CFLAGS = -pedantic -Wall -g +LDFLAGS = -lSDL -lm -lpthread + +.PHONY: all +all: .clang_complete $(bin) + +$(bin): $(obj) + $(CC) -o $@ $(obj) $(LDFLAGS) + +.clang_complete: + echo '-x c' >$@ + echo $(CFLAGS) >>$@ + +.PHONY: clean +clean: + rm -f $(obj) $(bin) diff -r 000000000000 -r 11f024648101 src/app.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/app.c Tue Mar 22 00:55:07 2016 +0200 @@ -0,0 +1,36 @@ +#include +#include "app.h" + +int app_init(void) +{ + if(p3d_init() == -1) { + fprintf(stderr, "failed to initialize par3d\n"); + return -1; + } + return 0; +} + +void app_cleanup(void) +{ +} + +void app_draw(void) +{ + int i, j; + uint32_t *pptr = fb_pixels; + for(i=0; i +#include +#include +#include "app.h" + +static int handle_event(SDL_Event *ev); + +static SDL_Surface *fbsurf; +static int quit; + +int main(int argc, char **argv) +{ + unsigned long msec, prev_fps_upd; + unsigned int num_frames, framerate; + + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) { + fprintf(stderr, "failed to initialize SDL\n"); + return 1; + } + if(!(fbsurf = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE | SDL_RESIZABLE))) { + fprintf(stderr, "failed to create surface\n"); + SDL_Quit(); + return 1; + } + SDL_WM_SetCaption("parallel rasterization test", 0); + + if(app_init() == -1) { + return 1; + } + + prev_fps_upd = SDL_GetTicks(); + num_frames = 0; + + while(!quit) { + unsigned long dt; + SDL_Event ev; + while(SDL_PollEvent(&ev)) { + if(handle_event(&ev) == -1 || quit) { + goto break_main_loop; + } + } + + if(SDL_MUSTLOCK(fbsurf)) { + SDL_LockSurface(fbsurf); + } + fb_pixels = fbsurf->pixels; + fb_width = fbsurf->w; + fb_height = fbsurf->h; + + app_draw(); + + if(SDL_MUSTLOCK(fbsurf)) { + SDL_UnlockSurface(fbsurf); + } + SDL_Flip(fbsurf); + + ++num_frames; + msec = SDL_GetTicks(); + dt = msec - prev_fps_upd; + if(dt > 1500) { + char tmp[32]; + framerate = 10000 * num_frames / dt; + num_frames = 0; + prev_fps_upd = msec; + + sprintf(tmp, "fps: %u.%u\n", framerate / 10, framerate % 10); + SDL_WM_SetCaption(tmp, 0); + } + } +break_main_loop: + app_cleanup(); + SDL_Quit(); + return 0; +} + +void app_quit(void) +{ + quit = 1; +} + +static int handle_event(SDL_Event *ev) +{ + switch(ev->type) { + case SDL_KEYDOWN: + app_keyboard(ev->key.keysym.sym, ev->key.state == SDL_PRESSED); + break; + + default: + break; + } + return 0; +} diff -r 000000000000 -r 11f024648101 src/par3d.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/par3d.h Tue Mar 22 00:55:07 2016 +0200 @@ -0,0 +1,11 @@ +#ifndef PAR3D_H_ +#define PAR3D_H_ + +int p3d_init(void); +void p3d_setfb(int width, int height, uint32_t *pixels); + +int p3d_vertex_buffer(int vcount, int nfloats); +void *p3d_map_buffer(int vb); +void p3d_unmap_buffer(int vb); + +#endif /* PAR3D_H_ */