void finiTexture (CompScreen *screen, CompTexture *texture) { if (texture->name) { releasePixmapFromTexture (screen, texture); glDeleteTextures (1, &texture->name); } }
void finiTexture(CompScreen *screen, CompTexture *texture) { if (texture->name) { makeScreenCurrent(screen); compiz_texture_activate(texture, 1, NULL); releasePixmapFromTexture(screen, texture); compiz_glapi->glDeleteTextures(1, &texture->name); } }
static void scalefilterFreeFilterText (CompScreen *s) { FILTER_SCREEN (s); if (!fs->filterInfo) return; if (!fs->filterInfo->textPixmap) return; releasePixmapFromTexture(s, &fs->filterInfo->textTexture); XFreePixmap (s->display->display, fs->filterInfo->textPixmap); initTexture (s, &fs->filterInfo->textTexture); fs->filterInfo->textPixmap = None; }
static Bool imageToTexture(CompScreen *screen, CompTexture *texture, const char *image, unsigned int width, unsigned int height, GLenum format, GLenum type) { char *data; int i; GLint internalFormat; data = malloc(4 * width * height); if (!data) return FALSE; for (i = 0; i < height; i++) memcpy(&data[i * width * 4], &image[(height - i - 1) * width * 4], width * 4); makeScreenCurrent(screen); releasePixmapFromTexture(screen, texture); if (screen->textureNonPowerOfTwo || (POWER_OF_TWO(width) && POWER_OF_TWO(height))) { texture->target = GL_TEXTURE_2D; texture->matrix.xx = 1.0f / width; texture->matrix.yy = -1.0f / height; texture->matrix.y0 = 1.0f; texture->mipmap = TRUE; } else { texture->target = GL_TEXTURE_RECTANGLE_NV; texture->matrix.xx = 1.0f; texture->matrix.yy = -1.0f; texture->matrix.y0 = height; texture->mipmap = FALSE; } if (!texture->name) compiz_glapi->glGenTextures(1, &texture->name); compiz_glapi->glBindTexture(texture->target, texture->name); internalFormat = (screen->opt[COMP_SCREEN_OPTION_TEXTURE_COMPRESSION].value.b && screen->textureCompression ? GL_COMPRESSED_RGBA_ARB : GL_RGBA); compiz_glapi->glTexImage2D(texture->target, 0, internalFormat, width, height, 0, format, type, data); texture->filter = GL_NEAREST; compiz_glapi->glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); compiz_glapi->glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); compiz_glapi->glTexParameteri(texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); compiz_glapi->glTexParameteri(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); texture->wrap = GL_CLAMP_TO_EDGE; compiz_glapi->glBindTexture(texture->target, 0); free(data); return TRUE; }
Bool readImageToTexture (CompScreen *screen, CompTexture *texture, char *imageFileName, unsigned int *returnWidth, unsigned int *returnHeight) { char *data, *image; unsigned int width, height; int i; if (!readPng (imageFileName, &image, &width, &height)) { fprintf (stderr, "%s: Failed to load image: %s\n", programName, imageFileName); return FALSE; } data = malloc (4 * width * height); if (!data) { free (image); return FALSE; } for (i = 0; i < height; i++) memcpy (&data[i * width * 4], &image[(height - i - 1) * width * 4], width * 4); free (image); releasePixmapFromTexture (screen, texture); if (screen->textureNonPowerOfTwo || (POWER_OF_TWO (width) && POWER_OF_TWO (height))) { texture->target = GL_TEXTURE_2D; texture->matrix.xx = 1.0f / width; texture->matrix.yy = -1.0f / height; texture->matrix.y0 = 1.0f; } else { texture->target = GL_TEXTURE_RECTANGLE_NV; texture->matrix.xx = 1.0f; texture->matrix.yy = -1.0f; texture->matrix.y0 = height; } if (!texture->name) glGenTextures (1, &texture->name); glBindTexture (texture->target, texture->name); glTexImage2D (texture->target, 0, GL_RGB, width, height, 0, GL_BGRA, #if IMAGE_BYTE_ORDER == MSBFirst GL_UNSIGNED_INT_8_8_8_8_REV, #else GL_UNSIGNED_BYTE, #endif data); texture->filter = COMP_TEXTURE_FILTER_FAST; glTexParameteri (texture->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri (texture->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri (texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri (texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP); glBindTexture (texture->target, 0); free (data); *returnWidth = width; *returnHeight = height; return TRUE; }