示例#1
0
static void configure_with(struct state_decompress *decompressor, struct video_desc desc)
{
        enum dxt_type type;

#ifndef HAVE_MACOSX
        printf("[RTDXT] Trying OpenGL 3.1 context first.\n");
        decompressor->gl_context = glx_init(MK_OPENGL_VERSION(3,1));
        decompressor->legacy = FALSE;
        if(!decompressor->gl_context) {
                fprintf(stderr, "[RTDXT] OpenGL 3.1 profile failed to initialize, falling back to legacy profile.\n");
                decompressor->gl_context = glx_init(OPENGL_VERSION_UNSPECIFIED);
                decompressor->legacy = TRUE;
        }
        glx_validate(decompressor->gl_context);
#else
        decompressor->gl_context = NULL;
        if(get_mac_kernel_version_major() >= 11) {
                printf("[RTDXT] Mac 10.7 or latter detected. Trying OpenGL 3.2 Core profile first.\n");
                decompressor->gl_context = mac_gl_init(MAC_GL_PROFILE_3_2);
                if(!decompressor->gl_context) {
                        fprintf(stderr, "[RTDXT] OpenGL 3.2 Core profile failed to initialize, falling back to legacy profile.\n");
                } else {
                        decompressor->legacy = FALSE;
                }
        }

        if(!decompressor->gl_context) {
                decompressor->gl_context = mac_gl_init(MAC_GL_PROFILE_LEGACY);
                decompressor->legacy = TRUE;
        }
#endif
        if(!decompressor->gl_context) {
                fprintf(stderr, "[RTDXT decompress] Failed to create GL context.");
                exit_uv(128);
                decompressor->compressed_len = 0;
                return;
        }

        if(desc.color_spec == DXT5) {
                type = DXT_TYPE_DXT5_YCOCG;
        } else if(desc.color_spec == DXT1) {
                type = DXT_TYPE_DXT1;
        } else if(desc.color_spec == DXT1_YUV) {
                type = DXT_TYPE_DXT1_YUV;
        } else {
                fprintf(stderr, "Wrong compressiong to decompress.\n");
                return;
        }
        
        decompressor->desc = desc;

        decompressor->decoder = dxt_decoder_create(type, desc.width,
                        desc.height, decompressor->out_codec == RGBA ? DXT_FORMAT_RGBA : DXT_FORMAT_YUV422, decompressor->legacy);

        assert(decompressor->decoder != NULL);
        
        decompressor->compressed_len = dxt_get_size(desc.width, desc.height, type);
        decompressor->configured = TRUE;
}
示例#2
0
bool init_gl_context(struct gl_context *context, int which) {
        context->context = NULL;
#ifdef HAVE_LINUX
        x11_enter_thread();
        if(which == GL_CONTEXT_ANY) {
                printf("Trying OpenGL 3.1 first.\n");
                context->context = glx_init(MK_OPENGL_VERSION(3,1));
                context->legacy = FALSE;
        }
        if(!context->context) {
                if(which != GL_CONTEXT_LEGACY) {
                        fprintf(stderr, "[RTDXT] OpenGL 3.1 profile failed to initialize, falling back to legacy profile.\n");
                }
                context->context = glx_init(OPENGL_VERSION_UNSPECIFIED);
                context->legacy = TRUE;
        }
        if(context->context) {
                glx_validate(context->context);
        }
#elif defined HAVE_MACOSX
        if(which == GL_CONTEXT_ANY) {
                if(get_mac_kernel_version_major() >= 11) {
                        printf("[RTDXT] Mac 10.7 or latter detected. Trying OpenGL 3.2 Core profile first.\n");
                        context->context = mac_gl_init(MAC_GL_PROFILE_3_2);
                        if(!context->context) {
                                fprintf(stderr, "[RTDXT] OpenGL 3.2 Core profile failed to initialize, falling back to legacy profile.\n");
                        } else {
                                context->legacy = FALSE;
                        }
                }
        }

        if(!context->context) {
                context->context = mac_gl_init(MAC_GL_PROFILE_LEGACY);
                context->legacy = TRUE;
        }
#else // WIN32
        if(which == GL_CONTEXT_ANY) {
                context->context = win32_context_init(OPENGL_VERSION_UNSPECIFIED);
        } else if(which == GL_CONTEXT_LEGACY) {
                context->context = win32_context_init(OPENGL_VERSION_LEGACY);
        }

        context->legacy = TRUE;
#endif

        if(context->context) {
                return true;
        } else {
                return false;
        }
}
示例#3
0
/**
 * @brief initializes specified OpenGL context
 *
 * @note
 * After this call, context is current for calling thread.
 *
 * @param[out] context newly created context
 * @param      which   OpenGL version specifier
 * @return     info if context creation succeeded or failed
 */
bool init_gl_context(struct gl_context *context, int which) {
        context->context = NULL;
#ifdef HAVE_LINUX
        x11_enter_thread();
        if(which == GL_CONTEXT_ANY) {
                debug_msg("Trying OpenGL 3.1 first.\n");
                context->context = glx_init(MK_OPENGL_VERSION(3,1));
                context->legacy = FALSE;
        }
        if(!context->context) {
                if(which != GL_CONTEXT_LEGACY) {
                        debug_msg("OpenGL 3.1 profile failed to initialize, falling back to legacy profile.\n");
                }
                context->context = glx_init(OPENGL_VERSION_UNSPECIFIED);
                context->legacy = TRUE;
        }
        if(context->context) {
                glx_validate(context->context);
        }
#elif defined HAVE_MACOSX
        if(which == GL_CONTEXT_ANY) {
                if(get_mac_kernel_version_major() >= 11) {
                        debug_msg("Mac 10.7 or latter detected. Trying OpenGL 3.2 Core profile first.\n");
                        context->context = mac_gl_init(MAC_GL_PROFILE_3_2);
                        if(!context->context) {
                                debug_msg("OpenGL 3.2 Core profile failed to initialize, falling back to legacy profile.\n");
                        } else {
                                context->legacy = FALSE;
                        }
                }
        }

        if(!context->context) {
                context->context = mac_gl_init(MAC_GL_PROFILE_LEGACY);
                context->legacy = TRUE;
        }
#else // WIN32
        if(which == GL_CONTEXT_ANY) {
                context->context = win32_context_init(OPENGL_VERSION_UNSPECIFIED);
        } else if(which == GL_CONTEXT_LEGACY) {
                context->context = win32_context_init(OPENGL_VERSION_LEGACY);
        }

        context->legacy = TRUE;
#endif

        {
                char *save_ptr;
                const char *gl_ver = (const char *) glGetString(GL_VERSION);
                if (!gl_ver) {
                        fprintf(stderr, "Unable to determine OpenGL version!\n");
                        return false;
                }

                char *tmp = strdup(gl_ver);
                char *item = strtok_r(tmp, ".", &save_ptr);
                if (!item) {
                        fprintf(stderr, "Unable to determine OpenGL version!\n");
                        free(tmp);
                        return false;
                }
                context->gl_major = atoi(item);
                item = strtok_r(NULL, ".", &save_ptr);
                if (!item) {
                        fprintf(stderr, "Unable to determine OpenGL version!\n");
                        free(tmp);
                        return false;
                }
                context->gl_minor = atoi(item);
                free(tmp);
        }

        if(context->context) {
                return true;
        } else {
                return false;
        }
}