# HG changeset patch # User John Tsiombikas # Date 1392213732 -7200 # Node ID c6073bf9fd38131d39cbf5184753a4325137baa8 # Parent ee117b67b3e5054d5e83196a29988cc56aa0bbff finally! async loading works. Now on to inotify... diff -r ee117b67b3e5 -r c6073bf9fd38 examples/imgthumbs/imgthumbs.vcproj --- a/examples/imgthumbs/imgthumbs.vcproj Wed Feb 12 06:54:52 2014 +0200 +++ b/examples/imgthumbs/imgthumbs.vcproj Wed Feb 12 16:02:12 2014 +0200 @@ -19,7 +19,7 @@ aspect = 1.0; -#ifndef DBG_SYNC - resman_lookup(texman, node->fname, node); -#else - img_init(&img); - if(img_load(&img, node->fname) == -1) { + if(dbg_load_async) { + resman_lookup(texman, node->fname, node); + } else { + img_init(&img); + if(img_load(&img, node->fname) == -1) { + img_destroy(&img); + free(node->fname); + free(node); + continue; + } + + printf("loaded image: %s\n", node->fname); + + node->aspect = (float)img.width / (float)img.height; + + glGenTextures(1, &node->tex); + glBindTexture(GL_TEXTURE_2D, node->tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, img_glintfmt(&img), img.width, img.height, 0, img_glfmt(&img), img_gltype(&img), img.pixels); img_destroy(&img); - free(node->fname); - free(node); - continue; + + node->prev = list; + node->next = list->next; + if(list->next) list->next->prev = node; + list->next = node; } - - printf("loaded image: %s\n", node->fname); - - node->aspect = (float)img.width / (float)img.height; - - glGenTextures(1, &node->tex); - glBindTexture(GL_TEXTURE_2D, node->tex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, img_glintfmt(&img), img.width, img.height, 0, img_glfmt(&img), img_gltype(&img), img.pixels); - img_destroy(&img); -#endif - - node->next = list->next; - node->prev = list; - list->next = node; + node->list = list; } closedir(dir); @@ -138,7 +130,6 @@ thumbs = thumbs->next; /* skip dummy node */ while(thumbs) { - printf("drawing thumb: %s\n", thumbs->fname); glPushMatrix(); glTranslatef(x, y, 0); @@ -225,7 +216,7 @@ static int done_res_texture(int id, void *cls) { - struct thumbnail *rdata = resman_get_res_data(texman, id); + struct thumbnail *thumb = resman_get_res_data(texman, id); int load_result = resman_get_res_result(texman, id); if(load_result == -1) { @@ -236,21 +227,27 @@ return -1; } - if(resman_get_res_result(texman, id) != 0 || !rdata) { + if(resman_get_res_result(texman, id) != 0 || !thumb) { fprintf(stderr, "failed to load resource %d (%s)\n", id, resman_get_res_name(texman, id)); } else { printf("done loading resource %d (%s)\n", id, resman_get_res_name(texman, id)); } - if(!rdata->tex) { - glGenTextures(1, &rdata->tex); + if(!thumb->tex) { + glGenTextures(1, &thumb->tex); } - glBindTexture(GL_TEXTURE_2D, rdata->tex); + glBindTexture(GL_TEXTURE_2D, thumb->tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, img_glintfmt(rdata->img), - rdata->img->width, rdata->img->height, 0, img_glfmt(rdata->img), - img_gltype(rdata->img), rdata->img->pixels); + glTexImage2D(GL_TEXTURE_2D, 0, img_glintfmt(thumb->img), + thumb->img->width, thumb->img->height, 0, img_glfmt(thumb->img), + img_gltype(thumb->img), thumb->img->pixels); + + /* and add it to the list of thumbnails */ + thumb->prev = thumb->list; + thumb->next = thumb->list->next; + if(thumb->list->next) thumb->list->next->prev = thumb; + thumb->list->next = thumb; return 0; } diff -r ee117b67b3e5 -r c6073bf9fd38 examples/imgthumbs/src/thumbs.h --- a/examples/imgthumbs/src/thumbs.h Wed Feb 12 06:54:52 2014 +0200 +++ b/examples/imgthumbs/src/thumbs.h Wed Feb 12 16:02:12 2014 +0200 @@ -14,6 +14,7 @@ struct img_pixmap *img; struct thumbnail *next, *prev; + struct thumbnail *list; /* pointer to the list this thumbnail belongs to */ }; struct thumbnail *create_thumbs(const char *dirpath); diff -r ee117b67b3e5 -r c6073bf9fd38 libresman-static.vcproj --- a/libresman-static.vcproj Wed Feb 12 06:54:52 2014 +0200 +++ b/libresman-static.vcproj Wed Feb 12 16:02:12 2014 +0200 @@ -18,8 +18,8 @@ diff -r ee117b67b3e5 -r c6073bf9fd38 src/resman.c --- a/src/resman.c Wed Feb 12 06:54:52 2014 +0200 +++ b/src/resman.c Wed Feb 12 16:02:12 2014 +0200 @@ -166,10 +166,8 @@ continue; } - printf("locking mutex %d\n", res->id); pthread_mutex_lock(&res->done_lock); if(!res->done_pending) { - printf(" unlocking mutex %d\n", res->id); pthread_mutex_unlock(&res->done_lock); continue; } @@ -178,12 +176,10 @@ res->done_pending = 0; if(rman->done_func(i, rman->done_func_cls) == -1) { /* done-func returned -1, so let's remove the resource */ - printf(" unlocking mutex %d\n", res->id); pthread_mutex_unlock(&res->done_lock); remove_resource(rman, i); continue; } - printf(" unlocking mutex %d\n", res->id); pthread_mutex_unlock(&res->done_lock); } return 0; @@ -309,9 +305,7 @@ return; } - printf("locking mutex %d\n", res->id); pthread_mutex_lock(&res->done_lock); res->done_pending = 1; - printf(" unlocking mutex %d\n", res->id); pthread_mutex_unlock(&res->done_lock); }