From: Derek Foreman Date: Mon, 9 Jun 2003 00:37:01 +0000 (+0000) Subject: pad textures to power of 2 sizes X-Git-Tag: gl-oldtheme~26 X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=497f6249ab5a95a683b4b6d3c5faf213b13da9c8;p=dana%2Fopenbox.git pad textures to power of 2 sizes --- diff --git a/render2/texture.c b/render2/texture.c index 84ee5562..2e65754a 100644 --- a/render2/texture.c +++ b/render2/texture.c @@ -30,6 +30,8 @@ void RrTextureSetRGBA(struct RrSurface *sur, int w, int h) { + int i; + unsigned char *padbuf; unsigned int num; struct RrTexture *tex = RrSurfaceTexture(sur, texnum); if (!tex) return; @@ -39,6 +41,25 @@ void RrTextureSetRGBA(struct RrSurface *sur, tex->data.rgba.y = y; tex->data.rgba.w = w; tex->data.rgba.h = h; + tex->data.rgba.padw = 1; + tex->data.rgba.padh = 1; + + while (tex->data.rgba.padw < w) + tex->data.rgba.padw <<= 1; + + while (tex->data.rgba.padh < h) + tex->data.rgba.padh <<= 1; + + padbuf = malloc(sizeof(RrData32) + * tex->data.rgba.padh * tex->data.rgba.padw); + memset(padbuf, 0, sizeof(RrData32) * tex->data.rgba.padh * + tex->data.rgba.padw); + + for (i = 0; i < h; i++) + memcpy(padbuf + i*tex->data.rgba.padw, + data + i*w, + w); + glGenTextures(1, &num); tex->data.rgba.texid = num; glBindTexture(GL_TEXTURE_2D, num); @@ -48,8 +69,10 @@ void RrTextureSetRGBA(struct RrSurface *sur, glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, - 0, GL_RGBA, GL_UNSIGNED_BYTE, data); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, + tex->data.rgba.padw, tex->data.rgba.padh, + 0, GL_RGBA, GL_UNSIGNED_BYTE, padbuf); + free(padbuf); } void RrTextureSetText(struct RrSurface *sur, diff --git a/render2/texture.h b/render2/texture.h index a98efef1..4c31884e 100644 --- a/render2/texture.h +++ b/render2/texture.h @@ -23,6 +23,8 @@ struct RrTextureRGBA { int y; int w; int h; + int padw; + int padh; }; struct RrTexture;