示例#1
0
static int dxt_prepare_yuv422_shader(struct dxt_encoder *encoder) {
        encoder->yuv422_to_444_fp = 0;    
        if(encoder->legacy) {
            encoder->yuv422_to_444_fp = dxt_shader_create_from_source(fp_yuv422_to_yuv_444_legacy, GL_FRAGMENT_SHADER);
        } else {
            encoder->yuv422_to_444_fp = dxt_shader_create_from_source(fp_yuv422_to_yuv_444, GL_FRAGMENT_SHADER);
        }

        if ( encoder->yuv422_to_444_fp == 0) {
                fprintf(stderr, "Failed to compile YUV422->YUV444 fragment program!\n");
                return 0;
        }

        if(encoder->legacy) {
            encoder->yuv422_to_444_vp = dxt_shader_create_from_source(vp_compress_legacy, GL_VERTEX_SHADER);
        } else {
            encoder->yuv422_to_444_vp = dxt_shader_create_from_source(vp_compress, GL_VERTEX_SHADER);
        }
        
        encoder->yuv422_to_444_program = glCreateProgram();
        glAttachShader(encoder->yuv422_to_444_program, encoder->yuv422_to_444_fp);
        glAttachShader(encoder->yuv422_to_444_program, encoder->yuv422_to_444_vp);
        glLinkProgram(encoder->yuv422_to_444_program);

        if(!encoder->legacy) {
#if ! defined HAVE_MACOSX || OS_VERSION_MAJOR >= 11
            GLint g_vertexLocation;
            GLuint g_vertices;

            // ToDo:
            glGenVertexArrays(1, &encoder->g_vao_422);

            // ToDo:
            glBindVertexArray(encoder->g_vao_422);

            // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml
            g_vertexLocation = glGetAttribLocation(encoder->yuv422_to_444_program, "position");

            // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml
            glGenBuffers(1, &g_vertices);

            // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml
            glBindBuffer(GL_ARRAY_BUFFER, g_vertices);

            // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml
            //glBufferData(GL_ARRAY_BUFFER, 3 * 4 * sizeof(GLfloat), (GLfloat*) points, GL_STATIC_DRAW);
            glBufferData(GL_ARRAY_BUFFER, 8 * 4 * sizeof(GLfloat), (GLfloat*) points, GL_STATIC_DRAW);

            // http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml
            glUseProgram(encoder->yuv422_to_444_program);

            // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml
            glVertexAttribPointer(g_vertexLocation, 4, GL_FLOAT, GL_FALSE, 0, 0);

            // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml
            glEnableVertexAttribArray(g_vertexLocation);

            glBindFragDataLocation(encoder->yuv422_to_444_program, 0, "colorOut");

            glUseProgram(0);
#endif
        }
        
        char log[32768];
        glGetProgramInfoLog(encoder->yuv422_to_444_program, 32768, NULL, (GLchar*)log);
        if ( strlen(log) > 0 )
                printf("Link Log: %s\n", log);
        
        glGenTextures(1, &encoder->texture_yuv422);
        glBindTexture(GL_TEXTURE_2D, encoder->texture_yuv422);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, encoder->width / 2, encoder->height,
                        0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
        
        glUseProgram(encoder->yuv422_to_444_program);
        glUniform1i(glGetUniformLocation(encoder->yuv422_to_444_program, "image"), 0);
        glUniform1f(glGetUniformLocation(encoder->yuv422_to_444_program, "imageWidth"),
                        (GLfloat) encoder->width);

        // Create fbo    
        glGenFramebuffers(1, &encoder->fbo444_id);
        return 1;
}
示例#2
0
/** Documented at declaration */
struct dxt_encoder*
dxt_encoder_create(enum dxt_type type, int width, int height, enum dxt_format format, int legacy)
{
    struct dxt_encoder* encoder = (struct dxt_encoder*)malloc(sizeof(struct dxt_encoder));

#ifndef HAVE_MACOSX
    glewExperimental = GL_TRUE;
    GLenum err = glewInit();
    assert(err == GLEW_OK);
#endif

    if ( encoder == NULL )
        return NULL;
    encoder->type = type;
    encoder->width = width;
    encoder->height = height;
    encoder->format = format;
    encoder->legacy = legacy;

    if(legacy) {
            glEnable(GL_TEXTURE_2D);
    }

    //glEnable(GL_TEXTURE_2D);
#ifdef HAVE_GPUPERFAPI
    GPA_EnableAllCounters();
#endif

    glGenFramebuffers(1, &encoder->fbo_id);
    glBindFramebuffer(GL_FRAMEBUFFER, encoder->fbo_id);

#ifdef USE_PBO_DXT_ENCODER
    int bpp;
    if(format == DXT_FORMAT_RGB) {
        bpp = 3;
    } else {
        bpp = 4;
    }

    glGenBuffersARB(1, &encoder->pbo_in); //Allocate PBO
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, encoder->pbo_in);
    glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB,width*height*bpp,0,GL_STREAM_DRAW_ARB);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
        
    glGenBuffersARB(1, &encoder->pbo_out); //Allocate PBO
    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, encoder->pbo_out);
    glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, ((width + 3) / 4 * 4) * ((height + 3) / 4 * 4)  / (encoder->type == DXT_TYPE_DXT5_YCOCG ? 1 : 2), 0, GL_STREAM_READ_ARB);
    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
    
#endif
    
    GLuint fbo_tex;
    glGenTextures(1, &fbo_tex); 
    glBindTexture(GL_TEXTURE_2D, fbo_tex); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    if ( encoder->type == DXT_TYPE_DXT5_YCOCG )
        glTexImage2D(GL_TEXTURE_2D, 0 , GL_RGBA32UI_EXT, (encoder->width + 3) / 4 * 4, (encoder->height + 3) / 4, 0, GL_RGBA_INTEGER_EXT, GL_INT, 0); 
    else
        glTexImage2D(GL_TEXTURE_2D, 0 , GL_RGBA16UI_EXT, (encoder->width + 3) / 4 * 4, (encoder->height + 3) / 4, 0, GL_RGBA_INTEGER_EXT, GL_INT, 0); 
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fbo_tex, 0);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    // Create program [display] and its shader
    encoder->program_compress = glCreateProgram();
    // Create fragment shader from file
    encoder->shader_fragment_compress = 0;
    if ( encoder->type == DXT_TYPE_DXT5_YCOCG ) {
        if(encoder->legacy) {
            if(format == DXT_FORMAT_YUV422 || format == DXT_FORMAT_YUV) {
                encoder->shader_fragment_compress = dxt_shader_create_from_source(fp_compress_dxt5ycocg_yuv_legacy, GL_FRAGMENT_SHADER);
            } else {
                encoder->shader_fragment_compress = dxt_shader_create_from_source(fp_compress_dxt5ycocg_legacy, GL_FRAGMENT_SHADER);
            }
        } else {
            if(format == DXT_FORMAT_YUV422 || format == DXT_FORMAT_YUV) {
                encoder->shader_fragment_compress = dxt_shader_create_from_source(fp_compress_dxt5ycocg_yuv, GL_FRAGMENT_SHADER);
            } else {
                encoder->shader_fragment_compress = dxt_shader_create_from_source(fp_compress_dxt5ycocg, GL_FRAGMENT_SHADER);
            }
        }
    } else {
        if(encoder->legacy) {
            if(format == DXT_FORMAT_YUV422 || format == DXT_FORMAT_YUV) {
                encoder->shader_fragment_compress = dxt_shader_create_from_source(fp_compress_dxt1_yuv_legacy, GL_FRAGMENT_SHADER);
            } else {
                encoder->shader_fragment_compress = dxt_shader_create_from_source(fp_compress_dxt1_legacy, GL_FRAGMENT_SHADER);
            }
        } else {
            if(format == DXT_FORMAT_YUV422 || format == DXT_FORMAT_YUV) {
                encoder->shader_fragment_compress = dxt_shader_create_from_source(fp_compress_dxt1_yuv, GL_FRAGMENT_SHADER);
            } else {
                encoder->shader_fragment_compress = dxt_shader_create_from_source(fp_compress_dxt1, GL_FRAGMENT_SHADER);
            }
        }
    }
    if ( encoder->shader_fragment_compress == 0 ) {
        fprintf(stderr, "Failed to compile fragment compress program!\n");
        free(encoder);
        return NULL;
    }
    // Create vertex shader from file
    encoder->shader_vertex_compress = 0;
    if(encoder->legacy) {
        encoder->shader_vertex_compress = dxt_shader_create_from_source(vp_compress_legacy, GL_VERTEX_SHADER);
    } else {
        encoder->shader_vertex_compress = dxt_shader_create_from_source(vp_compress, GL_VERTEX_SHADER);
    }
    if ( encoder->shader_vertex_compress == 0 ) {
        fprintf(stderr, "Failed to compile vertex compress program!\n");
        free(encoder);
        return NULL;
    }
    // Attach shader to program and link the program
    glAttachShader(encoder->program_compress, encoder->shader_fragment_compress);
    glAttachShader(encoder->program_compress, encoder->shader_vertex_compress);
    glLinkProgram(encoder->program_compress);
    
    char log[32768];
    glGetProgramInfoLog(encoder->program_compress, 32768, NULL, (GLchar*)log);
    if ( strlen(log) > 0 )
        printf("Link Log: %s\n", log);
    

    glGenTextures(1, &encoder->texture_id);
    glBindTexture(GL_TEXTURE_2D, encoder->texture_id);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    if(format == DXT_FORMAT_RGB) {
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, encoder->width, encoder->height, 0, GL_RGB, GL_BYTE, NULL);
    } else {
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, encoder->width, encoder->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    }
    
    //glActiveTexture(GL_TEXTURE0);
    
    if(format == DXT_FORMAT_YUV422) {
            if(!dxt_prepare_yuv422_shader(encoder)) {
                /// @todo What about generated textures etc. ?
                free(encoder);
                return NULL;
            }
    }

    glBindTexture(GL_TEXTURE_2D, encoder->texture_id);
    //glClear(GL_COLOR_BUFFER_BIT);
 
    glViewport(0, 0, (encoder->width + 3) / 4, encoder->height / 4);
    glDisable(GL_DEPTH_TEST);
    
    // User compress program and set image size parameters
    glUseProgram(encoder->program_compress);
//glBindFragDataLocation(encoder->program_compress, 0, "colorInt");
    glUniform1i(glGetUniformLocation(encoder->program_compress, "image"), 0);
    
    if(format == DXT_FORMAT_YUV422 || format == DXT_FORMAT_YUV) {
            glUniform1i(glGetUniformLocation(encoder->program_compress, "imageFormat"), FORMAT_YUV);
    } else {
            glUniform1i(glGetUniformLocation(encoder->program_compress, "imageFormat"), FORMAT_RGB); 
    }
    glUniform2f(glGetUniformLocation(encoder->program_compress, "imageSize"), encoder->width, (encoder->height + 3) / 4 * 4); 
    glUniform1f(glGetUniformLocation(encoder->program_compress, "textureWidth"), (encoder->width + 3) / 4 * 4); 

    if(!encoder->legacy) {
#if ! defined HAVE_MACOSX || OS_VERSION_MAJOR >= 11
        GLint g_vertexLocation;

        // ToDo:
        glGenVertexArrays(1, &encoder->g_vao);

        // ToDo:
        glBindVertexArray(encoder->g_vao);

        // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml
        g_vertexLocation = glGetAttribLocation(encoder->program_compress, "position");

        // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml
        glGenBuffers(1, &encoder->g_vertices);

        // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml
        glBindBuffer(GL_ARRAY_BUFFER, encoder->g_vertices);

        // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml
        //glBufferData(GL_ARRAY_BUFFER, 3 * 4 * sizeof(GLfloat), (GLfloat*) points, GL_STATIC_DRAW);
        glBufferData(GL_ARRAY_BUFFER, 8 * 4 * sizeof(GLfloat), (GLfloat*) points, GL_STATIC_DRAW);

        // http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml
        //glUseProgram(g_program.program);

        // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml
        glVertexAttribPointer(g_vertexLocation, 4, GL_FLOAT, GL_FALSE, 0, 0);

        // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml
        glEnableVertexAttribArray(g_vertexLocation);

        glBindFragDataLocation(encoder->program_compress, 0, "colorOut");
#endif
    }

    // Render to framebuffer
    glBindFramebuffer(GL_FRAMEBUFFER, encoder->fbo_id);

#ifdef HAVE_GPUPERFAPI
    GPA_BeginSession( &encoder->sessionID );
    GPA_GetPassCount( &encoder->numRequiredPasses );
    encoder->currentWaitSessionID = 0;
#endif
#ifdef RTDXT_DEBUG
    glGenQueries(4, encoder->queries);
#endif

    return encoder;
}
示例#3
0
/** Documented at declaration */
struct dxt_decoder*
dxt_decoder_create(enum dxt_type type, int width, int height, enum dxt_format out_format, int legacy)
{
    struct dxt_decoder* decoder = (struct dxt_decoder*)malloc(sizeof(struct dxt_decoder));
    
    assert(out_format == DXT_FORMAT_RGBA || out_format == DXT_FORMAT_YUV422);
    assert(out_format == DXT_FORMAT_RGBA ||
        (out_format == DXT_FORMAT_YUV422 && width % 2 == 0)); /* width % 2 for YUV422 */

    if ( decoder == NULL )
        return NULL;
    decoder->type = type;
    decoder->width = width;
    decoder->height = height;
    decoder->out_format = out_format;
    decoder->legacy = legacy;
    //glutReshapeWindow(1, 1);
    
    // Create empty texture
    glGenTextures(1, &decoder->compressed_tex);
    glBindTexture(GL_TEXTURE_2D, decoder->compressed_tex);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    
    if ( decoder->type == DXT_TYPE_DXT5_YCOCG )
        glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, decoder->width, decoder->height, 0,
                        ((decoder->width + 3) / 4 * 4) * ((decoder->height + 3) / 4 * 4), 0);
    else
        glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, decoder->width, decoder->height, 0,
                        ((decoder->width + 3) / 4 * 4) * ((decoder->height + 3) / 4 * 4) / 2, 0);
    
    // Create fbo    
    glGenFramebuffers(1, &decoder->fbo_rgba);
    glBindFramebuffer(GL_FRAMEBUFFER, decoder->fbo_rgba);
    
    glGenTextures(1, &decoder->uncompressed_rgba_tex); 
    glBindTexture(GL_TEXTURE_2D, decoder->uncompressed_rgba_tex); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
    glTexImage2D(GL_TEXTURE_2D, 0 , DXT_IMAGE_GL_FORMAT, decoder->width, decoder->height, 0, GL_RGBA, DXT_IMAGE_GL_TYPE, 0); 
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, decoder->uncompressed_rgba_tex, 0);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    
    // Create program [display] and its shader
    decoder->program_display = glCreateProgram();  
    // Create shader from file
    decoder->shader_fragment_display = 0;
    switch(decoder->type) 
    {
        case DXT_TYPE_DXT5_YCOCG:
                if(legacy)
                    decoder->shader_fragment_display = dxt_shader_create_from_source(fp_display_dxt5ycocg_legacy, GL_FRAGMENT_SHADER);
                else
                    decoder->shader_fragment_display = dxt_shader_create_from_source(fp_display_dxt5ycocg, GL_FRAGMENT_SHADER);
                break;
        case DXT_TYPE_DXT1:
                if(legacy)
                    decoder->shader_fragment_display = dxt_shader_create_from_source(fp_display_legacy, GL_FRAGMENT_SHADER);
                else
                    decoder->shader_fragment_display = dxt_shader_create_from_source(fp_display, GL_FRAGMENT_SHADER);
                break;
        case DXT_TYPE_DXT1_YUV:
                if(legacy)
                    decoder->shader_fragment_display = dxt_shader_create_from_source(fp_display_dxt1_yuv_legacy, GL_FRAGMENT_SHADER);
                else
                    decoder->shader_fragment_display = dxt_shader_create_from_source(fp_display_dxt1_yuv, GL_FRAGMENT_SHADER);
                break;
    }
    if(legacy) {
        decoder->shader_vertex_display = dxt_shader_create_from_source(vp_compress_legacy, GL_VERTEX_SHADER);
    } else {
        decoder->shader_vertex_display = dxt_shader_create_from_source(vp_compress, GL_VERTEX_SHADER);
    }
    if ( decoder->shader_fragment_display == 0 || decoder->shader_vertex_display == 0 )
        return NULL;
    // Attach shader to program and link the program
    glAttachShader(decoder->program_display, decoder->shader_fragment_display);
    glAttachShader(decoder->program_display, decoder->shader_vertex_display);
    glLinkProgram(decoder->program_display);
    
    if(out_format == DXT_FORMAT_YUV422) {
            glGenTextures(1, &decoder->uncompressed_yuv422_tex);
            glBindTexture(GL_TEXTURE_2D, decoder->uncompressed_yuv422_tex); 
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
            glTexImage2D(GL_TEXTURE_2D, 0 , GL_RGBA, decoder->width / 2, decoder->height, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0); 
            
            glGenFramebuffers(1, &decoder->fbo_yuv422);
            
            if(legacy) {
                decoder->shader_fragment_rgba_to_yuv422 = dxt_shader_create_from_source(fp_display_rgba_to_yuv422_legacy, GL_FRAGMENT_SHADER);
                decoder->shader_vertex_rgba_to_yuv422 = dxt_shader_create_from_source(vp_compress_legacy, GL_VERTEX_SHADER);
            } else {
                decoder->shader_fragment_rgba_to_yuv422 = dxt_shader_create_from_source(fp_display_rgba_to_yuv422, GL_FRAGMENT_SHADER);
                decoder->shader_vertex_rgba_to_yuv422 = dxt_shader_create_from_source(vp_compress, GL_VERTEX_SHADER);
            }
            
            decoder->program_rgba_to_yuv422 = glCreateProgram();
            glAttachShader(decoder->program_rgba_to_yuv422, decoder->shader_fragment_rgba_to_yuv422);
            glAttachShader(decoder->program_rgba_to_yuv422, decoder->shader_vertex_rgba_to_yuv422);
            glLinkProgram(decoder->program_rgba_to_yuv422);
            
            glUseProgram(decoder->program_rgba_to_yuv422);
            glUniform1i(glGetUniformLocation(decoder->program_rgba_to_yuv422, "image"), 0);
            glUniform1f(glGetUniformLocation(decoder->program_rgba_to_yuv422, "imageWidth"),
                        (GLfloat) decoder->width);

            if(!decoder->legacy) {
#if ! defined HAVE_MACOSX || OS_VERSION_MAJOR >= 11
                GLint g_vertexLocation;
                GLuint g_vertices;

                // ToDo:
                glGenVertexArrays(1, &decoder->g_vao_422);

                // ToDo:
                glBindVertexArray(decoder->g_vao_422);

                // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml
                g_vertexLocation = glGetAttribLocation(decoder->program_rgba_to_yuv422, "position");

                // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml
                glGenBuffers(1, &g_vertices);

                // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml
                glBindBuffer(GL_ARRAY_BUFFER, g_vertices);

                // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml
                //glBufferData(GL_ARRAY_BUFFER, 3 * 4 * sizeof(GLfloat), (GLfloat*) points, GL_STATIC_DRAW);
                glBufferData(GL_ARRAY_BUFFER, 8 * 4 * sizeof(GLfloat), (GLfloat*) points, GL_STATIC_DRAW);

                // http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml
                glUseProgram(decoder->program_rgba_to_yuv422);

                // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml
                glVertexAttribPointer(g_vertexLocation, 4, GL_FLOAT, GL_FALSE, 0, 0);

                // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml
                glEnableVertexAttribArray(g_vertexLocation);

                glBindFragDataLocation(decoder->program_rgba_to_yuv422, 0, "colorOut");
#endif
            }
                        
            glUseProgram(0);
    }
    if(!decoder->legacy) {
#if ! defined HAVE_MACOSX || OS_VERSION_MAJOR >= 11
        GLint g_vertexLocation;
        GLuint g_vertices;

        // ToDo:
        glGenVertexArrays(1, &decoder->g_vao);

        // ToDo:
        glBindVertexArray(decoder->g_vao);

        // http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml
        g_vertexLocation = glGetAttribLocation(decoder->program_display, "position");

        // http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml
        glGenBuffers(1, &g_vertices);

        // http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml
        glBindBuffer(GL_ARRAY_BUFFER, g_vertices);

        // http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml
        //glBufferData(GL_ARRAY_BUFFER, 3 * 4 * sizeof(GLfloat), (GLfloat*) points, GL_STATIC_DRAW);
        glBufferData(GL_ARRAY_BUFFER, 8 * 4 * sizeof(GLfloat), (GLfloat*) points, GL_STATIC_DRAW);

        // http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml
        glUseProgram(decoder->program_display);

        // http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml
        glVertexAttribPointer(g_vertexLocation, 4, GL_FLOAT, GL_FALSE, 0, 0);

        // http://www.opengl.org/sdk/docs/man/xhtml/glEnableVertexAttribArray.xml
        glEnableVertexAttribArray(g_vertexLocation);

        glBindFragDataLocation(decoder->program_display, 0, "colorOut");

        glUseProgram(0);
#endif
    }
    
    return decoder;
}