aboutsummaryrefslogtreecommitdiff
path: root/generic/Image.c
diff options
context:
space:
mode:
authorlecoanet2003-04-24 14:16:17 +0000
committerlecoanet2003-04-24 14:16:17 +0000
commit85139c8f33588f3dc86d9e8cae1b4aee6c2be7ba (patch)
tree1e09991b53fc753068930c6db1cfb50d70f2fa6d /generic/Image.c
parentbc07da535fbd483c077986ab96c4dffd7b35ab37 (diff)
downloadtkzinc-85139c8f33588f3dc86d9e8cae1b4aee6c2be7ba.zip
tkzinc-85139c8f33588f3dc86d9e8cae1b4aee6c2be7ba.tar.gz
tkzinc-85139c8f33588f3dc86d9e8cae1b4aee6c2be7ba.tar.bz2
tkzinc-85139c8f33588f3dc86d9e8cae1b4aee6c2be7ba.tar.xz
Test the allocation of textures both for images and
for fonts. Suppressed the glGetIntegerv on GL_MAX_TEXTURE_SIZE which can be erroneous before window mapping. Disabled the test on max_tex_size until the value can reliably be read as soon as the widget creation. The texture for font is increased on the width and the height in alternance. The limit on texture expansion will be found at texture creation time and reported through glGetError. The structure holding the font parameters used for openGL is not allocated is an error occur during font loading. The structure is also properly freed (this was partially leaking).
Diffstat (limited to 'generic/Image.c')
-rw-r--r--generic/Image.c65
1 files changed, 50 insertions, 15 deletions
diff --git a/generic/Image.c b/generic/Image.c
index 2a0f7c3..9b2bfff 100644
--- a/generic/Image.c
+++ b/generic/Image.c
@@ -655,6 +655,7 @@ ZnImageTex(ZnImage image,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glGetError();
if (ZnImageIsBitmap(image)) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY4,
this->bits->t_width, this->bits->t_height,
@@ -665,6 +666,11 @@ ZnImageTex(ZnImage image,
this->bits->t_width, this->bits->t_height,
0, GL_RGBA, GL_UNSIGNED_BYTE, this->bits->t_bits);
}
+ if (glGetError() != GL_NO_ERROR) {
+ ZnWarning("Can't allocate the texture for image ");
+ ZnWarning(ZnNameOfImage(image));
+ ZnWarning("\n");
+ }
glBindTexture(GL_TEXTURE_2D, 0);
}
@@ -994,7 +1000,7 @@ ZnGetTexFont(ZnWInfo *wi,
int width, height;
unsigned int texw, texh;
GLfloat xstep, ystep;
- GLuint max_tex_size[1];
+ ZnBool increase_h = False;
if (!inited) {
Tcl_InitHashTable(&font_textures, TCL_ONE_WORD_KEYS);
@@ -1017,13 +1023,8 @@ ZnGetTexFont(ZnWInfo *wi,
txf->lut = NULL;
txf->tkfont = font;
- entry = Tcl_CreateHashEntry(&font_textures, (char *) font, &new);
- Tcl_SetHashValue(entry, (ClientData) txf);
- txf->hash = entry;
-
/*printf("Chargement de la texture pour la fonte %s\n",
ZnNameOfTexFont(tfi));*/
- glGetIntegerv(GL_MAX_TEXTURE_SIZE, max_tex_size);
fontinfo = SuckGlyphsFromServer(wi, txf->tkfont);
if (fontinfo == NULL) {
goto error;
@@ -1034,16 +1035,22 @@ ZnGetTexFont(ZnWInfo *wi,
/*
* Initial size of texture.
- * Assume that max_tex_size is at least 128 texels.
*/
- texw = 128;
+ texw = texh = wi->max_tex_size;
texh = 64;
while (texh < (unsigned int) (txf->ascent+txf->descent)) {
texh *= 2;
}
- if (texh > max_tex_size[0]) {
+ /*
+ * This is temporarily disabled until we find out
+ * how to reliably get max_tex_size up front without
+ * waiting for the window mapping.
+ */
+#ifdef MAX_TEX_SIZE
+ if (texh > wi->max_tex_size) {
goto error;
}
+#endif
xstep = 0/*0.5 / texw*/;
ystep = 0/*0.5 / texh*/;
@@ -1109,8 +1116,8 @@ ZnGetTexFont(ZnWInfo *wi,
}
}
- /* If a fit was found, use that character; otherwise, advance a line
- in the texture. */
+ /* If a fit was found, use that character; otherwise
+ * advance a line in the texture. */
if (foundWidthFit) {
if (height > maxheight) {
maxheight = height;
@@ -1127,25 +1134,37 @@ ZnGetTexFont(ZnWInfo *wi,
px = gap;
maxheight = height;
if ((unsigned int) (py + height + gap) >= texh) {
- if (texh*2 < max_tex_size[0]) {
+#ifdef MAX_TEX_SIZE
+ if (texh*2 < wi->max_tex_size) {
+#else
+ if (increase_h) {
+ increase_h = False;
+#endif
texh *= 2;
ZnFree(txf->teximage);
txf->teximage = ZnMalloc(texw * texh * sizeof(unsigned char));
strcpy(glist, glist2);
goto restart;
}
- else if (texw*2 < max_tex_size[0]) {
+#ifdef MAX_TEX_SIZE
+ else if (texw*2 < wi->max_tex_size) {
+#else
+ else {
+ increase_h = True;
+#endif
texw *= 2;
ZnFree(txf->teximage);
txf->teximage = ZnMalloc(texw * texh * sizeof(unsigned char));
strcpy(glist, glist2);
goto restart;
}
+#ifdef MAX_TEX_SIZE
else {
/* Overflowed texture space */
ZnWarning("Font texture overflow\n");
goto error;
}
+#endif
}
c = i;
}
@@ -1237,8 +1256,13 @@ ZnGetTexFont(ZnWInfo *wi,
ZnFree(txf->teximage);
txf->teximage = NULL;
}
+ ZnFree(txf);
+ ZnWarning("Cannot load font texture for font ");
+ ZnWarning(Tk_NameOfFont(font));
+ ZnWarning("\n");
return 0;
}
+
memset(txf->lut, 0, txf->range * sizeof(ZnTexGVI *));
for (i = 0; i < txf->num_glyphs; i++) {
txf->lut[txf->tgi[i].c - txf->min_glyph] = &txf->tgvi[i];
@@ -1251,6 +1275,10 @@ ZnGetTexFont(ZnWInfo *wi,
ZnFree(fontinfo);
ZnFree(glist);
ZnFree(glist2);
+
+ entry = Tcl_CreateHashEntry(&font_textures, (char *) font, &new);
+ Tcl_SetHashValue(entry, (ClientData) txf);
+ txf->hash = entry;
}
/*
@@ -1317,8 +1345,15 @@ ZnTexFontTex(ZnTexFontInfo tfi)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY4, txf->tex_width, txf->tex_height,
- 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, txf->teximage);
+ glGetError();
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY4, txf->tex_width,
+ txf->tex_height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE,
+ txf->teximage);
+ if (glGetError() != GL_NO_ERROR) {
+ ZnWarning("Can't allocate the texture for font ");
+ ZnWarning(ZnNameOfTexFont(tfi));
+ ZnWarning("\n");
+ }
glBindTexture(GL_TEXTURE_2D, 0);
}