/* Clear to green, so that errors in the following code cause a problem */
glClearColor (0.0, 1.0, 0.0, 1.0);
glClear (GL_COLOR_BUFFER_BIT);
/* load the checkerboard image */
bytes = g_bytes_new_static (image_data, G_N_ELEMENTS (image_data));
texture = gdk_texture_new_from_bytes (bytes, NULL);
g_bytes_unref (bytes);
width = gdk_texture_get_width (texture);
height = gdk_texture_get_height (texture);
downloader = gdk_texture_downloader_new (texture); /* Make sure we use a format that GLES does *NOT* support. *Andthatmustincludeextensions. *ButGL_EXT_texture_norm16doessupportRGB16asasource,which
* is why we also use mipmaps below. */
gdk_texture_downloader_set_format (downloader, GDK_MEMORY_R16G16B16);
bytes = gdk_texture_downloader_download_bytes (downloader, &stride);
g_object_unref (texture);
gdk_texture_downloader_free (downloader);
glGenTextures (1, &tex_id);
glActiveTexture (GL_TEXTURE0);
glBindTexture (GL_TEXTURE_2D, tex_id); /* Now load the image in this ideally unsupported format. Maybe
* things fail already here. Usually they don't. */
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB16,
width, height, 0, GL_RGB, GL_UNSIGNED_SHORT, g_bytes_get_data (bytes, NULL));
g_bytes_unref (bytes); /* Generate mipmaps. GLES should give up now. *GLshouldturnthecheckerboardintoorangemipmaplevelsthough.
*/
glGenerateMipmap (GL_TEXTURE_2D);
glGenFramebuffers (1, &fb_id);
glBindFramebuffer (GL_READ_FRAMEBUFFER, fb_id); /* Bind mipmap level 2 for reading, so we rely on properly converted
* mipmaps. */
glFramebufferTexture2D (GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_id, 2);
/* On GLES, this should now fail due to incomplete framebuffer and *leaveuswiththegreencontentswe'vedrawnabove.
* Or we are on GL, everything works perfectly, and we now get orange. */
glBlitFramebuffer (0, 0,
width / 4, height / 4, 0, 0,
gtk_widget_get_width (glarea) * gtk_widget_get_scale_factor (glarea),
gtk_widget_get_height (glarea) * gtk_widget_get_scale_factor (glarea),
GL_COLOR_BUFFER_BIT,
GL_LINEAR);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.