X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fdevices%2Fopengl.c;h=fd1b745681eac6872bf10836f1b110649a15d7c1;hb=e4687b3aa2aed49fb16ba9e9561344d808750297;hp=e5d2e915ae32f2e0e589d608c3064bddecca4630;hpb=193a487d93e0e4ce6c0f4b17bf63a1e1d10d3a56;p=swftools.git diff --git a/lib/devices/opengl.c b/lib/devices/opengl.c index e5d2e91..fd1b745 100644 --- a/lib/devices/opengl.c +++ b/lib/devices/opengl.c @@ -47,7 +47,7 @@ static void dbg(char*format, ...) if(!verbose) return; va_start(arglist, format); - vsprintf(buf, format, arglist); + vsnprintf(buf, sizeof(buf)-1, format, arglist); va_end(arglist); l = strlen(buf); while(l && buf[l-1]=='\n') { @@ -294,12 +294,13 @@ typedef struct _imgopengl gfxhash_t hash; GLuint texID; int width, height; + unsigned char*data; struct _imgopengl*next; } imgopengl_t; -imgopengl_t*img2texid = 0; +static imgopengl_t*img2texid = 0; -gfxhash_t gfximage_hash(gfximage_t*img) +static gfxhash_t gfximage_hash(gfximage_t*img) { int t; int size = img->width*img->height*4; @@ -309,7 +310,22 @@ gfxhash_t gfximage_hash(gfximage_t*img) return hash; } -imgopengl_t*addTexture(gfximage_t*img) +static void delTextures() +{ + imgopengl_t*i = img2texid; + while(i) { + imgopengl_t*next = i->next; + if(i->data) { + glDeleteTextures(1, &i->texID); + free(i->data); + } + memset(i, 0, sizeof(imgopengl_t)); + free(i); + i = next; + } +} + +static imgopengl_t*addTexture(gfximage_t*img) { gfxhash_t hash = gfximage_hash(img); imgopengl_t*i = img2texid; @@ -343,6 +359,7 @@ imgopengl_t*addTexture(gfximage_t*img) i->height = newheight; unsigned char*data = malloc(newwidth*newheight*4); + i->data = data; int x,y; for(y=0;yheight;y++) { for(x=0;xwidth;x++) { @@ -543,6 +560,7 @@ void opengl_result_destroy(struct _gfxresult*gfx) { dbg("result:destroy"); free(gfx); + delTextures(); } gfxresult_t*opengl_finish(struct _gfxdevice*dev)