Ejemplo n.º 1
0
// Bind texture, preserve previous texture state
bool GnashTexture::bind()
{
    TextureState * const ts = &_texture_state;
    ts->old_texture = 0;
    ts->was_bound   = 0;
    ts->was_enabled = glIsEnabled(GL_TEXTURE_2D);

    if (!ts->was_enabled)
        glEnable(GL_TEXTURE_2D);
    else if (gl_get_param(GL_TEXTURE_BINDING_2D, &ts->old_texture))
        ts->was_bound = _texture == ts->old_texture;
    else
        return false;

    if (!ts->was_bound) {
        gl_purge_errors();
        glBindTexture(GL_TEXTURE_2D, _texture);
        if (gl_check_error())
            return false;
    }

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    return true;
}
Ejemplo n.º 2
0
// glGetIntegerv() wrapper
static bool gl_get_param(GLenum param, unsigned int *pval)
{
    GLint val;

    gl_purge_errors();
    glGetIntegerv(param, &val);
    if (gl_check_error())
        return false;
    if (pval)
        *pval = val;
    return true;
}
/**
 * gl_get_texture_param:
 * @target: the target to which the texture is bound
 * @param: the parameter name
 * @pval: return location for the value
 *
 * This function is a wrapper around glGetTexLevelParameteriv() that
 * does extra error checking.
 *
 * Return value: %TRUE on success
 */
gboolean
gl_get_texture_param(GLenum target, GLenum param, guint *pval)
{
    GLint val;

    gl_purge_errors();
    glGetTexLevelParameteriv(target, 0, param, &val);
    if (gl_check_error())
        return FALSE;

    if (pval)
        *pval = val;
    return TRUE;
}
/**
 * gl_get_param:
 * @param: the parameter name
 * @pval: return location for the value
 *
 * This function is a wrapper around glGetIntegerv() that does extra
 * error checking.
 *
 * Return value: %TRUE on success
 */
gboolean
gl_get_param(GLenum param, guint *pval)
{
    GLint val;

    gl_purge_errors();
    glGetIntegerv(param, &val);
    if (gl_check_error())
        return FALSE;

    if (pval)
        *pval = val;
    return TRUE;
}
Ejemplo n.º 5
0
/// Bind texture, preserve previous texture state
static bool bind_texture(TextureState *ts, GLenum target, GLuint texture)
{
    ts->target      = target;
    ts->old_texture = 0;
    ts->was_bound   = 0;
    ts->was_enabled = glIsEnabled(target);

    GLenum texture_binding;
    switch (target) {
    case GL_TEXTURE_1D:
        texture_binding = GL_TEXTURE_BINDING_1D;
        break;
    case GL_TEXTURE_2D:
        texture_binding = GL_TEXTURE_BINDING_2D;
        break;
    case GL_TEXTURE_3D:
        texture_binding = GL_TEXTURE_BINDING_3D;
        break;
    case GL_TEXTURE_RECTANGLE_ARB:
        texture_binding = GL_TEXTURE_BINDING_RECTANGLE_ARB;
        break;
    default:
        assert(!target);
        return false;
    }

    if (!ts->was_enabled) {
        glEnable(target);
    } else if (gl_get_param(texture_binding, &ts->old_texture)) {
        ts->was_bound = texture == ts->old_texture;
    } else {
        return false;
    }

    if (!ts->was_bound) {
        gl_purge_errors();
        glBindTexture(target, texture);
        if (gl_check_error()) {
            return false;
        }
    }
    return true;
}