/** * Initializes the one glyph cache (texture and data structure). * If lcdCache is JNI_TRUE, the texture will contain RGB data, * otherwise we will simply store the grayscale/monochrome glyph images * as intensity values (which work well with the GL_MODULATE function). */ static jboolean OGLTR_InitGlyphCache(jboolean lcdCache) { GlyphCacheInfo *gcinfo; GLclampf priority = 1.0f; GLenum internalFormat = lcdCache ? GL_RGB8 : GL_INTENSITY8; GLenum pixelFormat = lcdCache ? GL_RGB : GL_LUMINANCE; J2dTraceLn(J2D_TRACE_INFO, "OGLTR_InitGlyphCache"); // init vertex cache (if it hasn't been already) if (!OGLVertexCache_InitVertexCache()) { return JNI_FALSE; } // init glyph cache data structure gcinfo = AccelGlyphCache_Init(OGLTR_CACHE_WIDTH, OGLTR_CACHE_HEIGHT, OGLTR_CACHE_CELL_WIDTH, OGLTR_CACHE_CELL_HEIGHT, OGLVertexCache_FlushVertexCache); if (gcinfo == NULL) { J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLTR_InitGlyphCache: could not init OGL glyph cache"); return JNI_FALSE; } // init cache texture object j2d_glGenTextures(1, &gcinfo->cacheID); j2d_glBindTexture(GL_TEXTURE_2D, gcinfo->cacheID); j2d_glPrioritizeTextures(1, &gcinfo->cacheID, &priority); j2d_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); j2d_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); j2d_glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, OGLTR_CACHE_WIDTH, OGLTR_CACHE_HEIGHT, 0, pixelFormat, GL_UNSIGNED_BYTE, NULL); cacheStatus = (lcdCache ? CACHE_LCD : CACHE_GRAY); glyphCache = gcinfo; return JNI_TRUE; }
/** * Creates a 2D texture of the given format and dimensions and returns the * texture object identifier. This method is typically used to create a * temporary texture for intermediate work, such as in the * OGLContext_InitBlitTileTexture() method below. */ GLuint OGLContext_CreateBlitTexture(GLenum internalFormat, GLenum pixelFormat, GLuint width, GLuint height) { GLuint texID; GLint sp, sr, rl, align; GLclampf priority = 1.0f; J2dTraceLn(J2D_TRACE_INFO, "OGLContext_CreateBlitTexture"); j2d_glGenTextures(1, &texID); j2d_glBindTexture(GL_TEXTURE_2D, texID); j2d_glPrioritizeTextures(1, &texID, &priority); j2d_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); j2d_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); OGLSD_RESET_TEXTURE_WRAP(GL_TEXTURE_2D); // save pixel store parameters (since this method could be invoked after // the caller has already set up its pixel store parameters) j2d_glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &sp); j2d_glGetIntegerv(GL_UNPACK_SKIP_ROWS, &sr); j2d_glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rl); j2d_glGetIntegerv(GL_UNPACK_ALIGNMENT, &align); // set pixel store parameters to default values j2d_glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); j2d_glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); j2d_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); j2d_glPixelStorei(GL_UNPACK_ALIGNMENT, 1); j2d_glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, pixelFormat, GL_UNSIGNED_BYTE, NULL); // restore pixel store parameters j2d_glPixelStorei(GL_UNPACK_SKIP_PIXELS, sp); j2d_glPixelStorei(GL_UNPACK_SKIP_ROWS, sr); j2d_glPixelStorei(GL_UNPACK_ROW_LENGTH, rl); j2d_glPixelStorei(GL_UNPACK_ALIGNMENT, align); return texID; }