struct simple_soft_ctx *simple_soft_init(int w, int h, simple_soft_map_func map_func, int audio_rate, int audio_channels, julia_vis_pixel_format format) { struct simple_soft_ctx *ctx = malloc(sizeof(*ctx)); if(!ctx) return NULL; ctx->map_surf[0] = ctx->map_surf[1] = NULL; ctx->maxsrc = NULL; ctx->pal_ctx = NULL; ctx->pd = NULL; ctx->beat = NULL; ctx->cur_buf = ctx->prev_buf = ctx->fft_tmp = NULL; // force divisible by 16 ctx->im_w = w - w%16; ctx->im_h = h - h%16; simple_soft_change_map_func(ctx, map_func); ctx->m = 0; ctx->map_surf[0] = aligned_alloc(64, ctx->im_w * ctx->im_h * sizeof(uint16_t)); ctx->map_surf[1] = aligned_alloc(64, ctx->im_w * ctx->im_h * sizeof(uint16_t)); if(!ctx->map_surf[0] || !ctx->map_surf[1]) goto fail; memset(ctx->map_surf[0], 0, ctx->im_w * ctx->im_h * sizeof(uint16_t)); memset(ctx->map_surf[1], 0, ctx->im_w * ctx->im_h * sizeof(uint16_t)); ctx->pal_ctx = pal_ctx_pix_format_new(format); ctx->maxsrc_rate = 24; //TODO: add a property that can change this ctx->maxsrc = maxsrc_new(ctx->im_w, ctx->im_h); ctx->pd = new_point_data(ctx->rational_julia?4:2); if(!ctx->maxsrc || !ctx->pal_ctx || !ctx->pd) goto fail; ctx->last_beat_time = 0; ctx->lastpalstep = 0; ctx->maxfrms = 1; ctx->beats = 0; ctx->beat = beat_new(); if(!ctx->beat) goto fail; ctx->audio_bufp = 0; ctx->sample_count = 0; ctx->sample_rate = audio_rate; ctx->channels = audio_channels; int nr_samp = ctx->nr_samp = (audio_rate<50000)?1024:2048; ctx->fft_tmp = aligned_alloc(64, nr_samp*sizeof(float)); ctx->cur_buf = aligned_alloc(64, sizeof(float)*nr_samp/2); ctx->prev_buf = aligned_alloc(64, sizeof(float)*nr_samp/2); if(!ctx->fft_tmp || !ctx->cur_buf || !ctx->prev_buf) goto fail; memset(ctx->fft_tmp, 0, nr_samp*sizeof(float)); memset(ctx->cur_buf, 0, sizeof(float)*nr_samp/2); memset(ctx->prev_buf, 0, sizeof(float)*nr_samp/2); return ctx; fail: simple_soft_destroy(ctx); return NULL; }
static int run_map_thread(tribuf *tb) { set_threadname("render"); struct point_data *pd = new_point_data(opts.rational_julia?4:2); unsigned int beats = beat_get_count(); unsigned int tick0, fps_oldtime, frmcnt=0, last_beat_time = 0; tick0 = fps_oldtime = SDL_GetTicks(); unsigned int fpstimes[40]; for(int i=0; i<40; i++) fpstimes[i] = 0; uint16_t *map_src = tribuf_get_read_nolock(tb); while(running) { frmcnt++; if((tick0-SDL_GetTicks())*opts.maxsrc_rate + (maxfrms*1000) > 1000) { audio_data ad; audio_get_samples(&ad); maxsrc_update(maxsrc, ad.data, ad.len); audio_finish_samples(); maxfrms++; } uint16_t *map_dest = tribuf_get_write(tb); map_func(map_dest, map_src, im_w, im_h, pd); maxblend(map_dest, maxsrc_get(maxsrc), im_w, im_h); tribuf_finish_write(tb); map_src=map_dest; unsigned int now = SDL_GetTicks() - tick0; float fpsd = (now - fpstimes[frmcnt%40])/1000.0f; fpstimes[frmcnt%40] = now; map_fps = 40.0f / fpsd; unsigned int newbeat = beat_get_count(); if(newbeat != beats && now - last_beat_time > 1000) { last_beat_time = now; update_points(pd, now, 1); } else update_points(pd, now, 0); beats = newbeat; if(map_fps > 750) SDL_Delay(1); // hard limit ourselves because 1500FPS is just pointless use of CPU (except of course to say that we can do it) // also if we run at more that 1000FPS the point motion code might blow up without the microsecond accurate timers... // high threshhold because we want it high enough that we don't notice if we jitter back // and fourth across it } return 0; }
void init_gl(const opt_data *opt_data, int width, int height) { if(!ogl_LoadFunctions()) { fprintf(stderr, "ERROR: Failed to load GL extensions\n"); exit(EXIT_FAILURE); } CHECK_GL_ERR; if(!(ogl_GetMajorVersion() > 1 || ogl_GetMinorVersion() >= 4)) { fprintf(stderr, "ERROR: Your OpenGL Implementation is too old\n"); exit(EXIT_FAILURE); } opts = opt_data; GLboolean force_fixed = opts->gl_opts != NULL && strstr(opts->gl_opts, "fixed") != NULL; GLboolean res_boost = opts->gl_opts != NULL && strstr(opts->gl_opts, "rboost") != NULL; packed_intesity_pixels = opts->gl_opts != NULL && strstr(opts->gl_opts, "pintens") != NULL; scr_w = width; scr_h = height; if(opts->fullscreen) im_w = scr_w, im_h=scr_h; else im_w = IMAX(make_pow2(IMAX(scr_w, scr_h)), 128)<<res_boost; im_h = im_w; while(!check_res(im_w, im_h)) { // shrink textures until they work printf(" %ix%i Too big! Shrink texture\n", im_h, im_w); im_w = im_w/2; im_h = im_h/2; } printf("Using internel resolution of %ix%i\n\n", im_h, im_w); CHECK_GL_ERR; setup_viewport(scr_w, scr_h); CHECK_GL_ERR; //glEnable(GL_LINE_SMOOTH); CHECK_GL_ERR; glClear(GL_COLOR_BUFFER_BIT); CHECK_GL_ERR; glRasterPos2f(-1,1 - 20.0f/(scr_h*0.5f)); //draw_string("Loading... "); swap_buffers(); CHECK_GL_ERR; printf("GL_VENDOR: %s\n", glGetString(GL_VENDOR)); printf("GL_RENDERER: %s\n", glGetString(GL_RENDERER)); printf("GL_VERSION: %s\n", glGetString(GL_VERSION)); if(ogl_ext_ARB_shading_language_100) printf("GL_SL_VERSION: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION_ARB)); printf("GL_EXTENSIONS: %s\n", glGetString(GL_EXTENSIONS)); printf("\n\n"); /* void DebugMessageControlARB(enum source, enum type, enum severity, sizei count, const uint* ids, boolean enabled); */ if(ogl_ext_ARB_debug_output) { glDebugMessageCallbackARB((GLDEBUGPROCARB)gl_debug_callback, NULL); #if DEBUG glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); #else glDebugMessageControlARB(GL_DONT_CARE, GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB, GL_DONT_CARE, 0, NULL, GL_TRUE); glDebugMessageControlARB(GL_DONT_CARE, GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB, GL_DONT_CARE, 0, NULL, GL_TRUE); #endif printf("Have ARB_debug_output: registered callback\n"); } CHECK_GL_ERR; // for ES we need: // EXT_blend_minmax // EXT_texture_format_BGRA8888 // optionally we should use // EXT_texture_rg + OES_texture_float/OES_texture_half_float // OES_mapbuffer /* if(!ogl_ext_EXT_blend_minmax) { // can stop checking for this, it's in OpenGL 1.4*/ /* printf("missing required gl extension EXT_blend_minmax!\n");*/ /* exit(1);*/ /* }*/ if(!ogl_ext_EXT_framebuffer_object && !ogl_ext_ARB_framebuffer_object) { printf("missing required gl extension EXT_framebuffer_object!\n"); exit(1); } // TODO: this should also pass if we have GL 2.0+ if(!ogl_ext_ARB_shading_language_100 && !(ogl_ext_ARB_fragment_shader && ogl_ext_ARB_vertex_shader && ogl_ext_ARB_shader_objects)) { if(!ogl_ext_ARB_pixel_buffer_object) printf("Missing GLSL and no pixel buffer objects, WILL be slow!\n"); else printf("No GLSL using all fixed function! (might be slow)\n"); } if(force_fixed) { printf("Fixed function code forced\n"); packed_intesity_pixels = GL_FALSE; } CHECK_GL_ERR; if(packed_intesity_pixels) printf("Packed intensity enabled\n"); glEnable(GL_TEXTURE_2D); CHECK_GL_ERR; init_mandel(); CHECK_GL_ERR; if(!force_fixed) glfract = fractal_glsl_init(opts, im_w, im_h, packed_intesity_pixels); if(!glfract) glfract = fractal_fixed_init(opts, im_w, im_h); CHECK_GL_ERR; if(!force_fixed) glmaxsrc = maxsrc_new_glsl(IMAX(im_w>>res_boost, 256), IMAX(im_h>>res_boost, 256), packed_intesity_pixels); if(!glmaxsrc) glmaxsrc = maxsrc_new_fixed(IMAX(im_w>>res_boost, 256), IMAX(im_h>>res_boost, 256)); CHECK_GL_ERR; if(!force_fixed) glpal = pal_init_glsl(packed_intesity_pixels); if(!glpal) glpal = pal_init_fixed(im_w, im_h); CHECK_GL_ERR; pd = new_point_data(opts->rational_julia?4:2); memset(frametimes, 0, sizeof(frametimes)); totframetime = frametimes[0] = MAX(10000000/opts->draw_rate, 1); memset(worktimes, 0, sizeof(worktimes)); totworktime = worktimes[0] = MIN(10000000/opts->draw_rate, 1); tick0 = uget_ticks(); }