Ejemplo n.º 1
0
void BL_Texture::InitGLCompressedTex(ImBuf *ibuf, bool mipmap)
{
#ifndef WITH_DDS
    // Fall back to uncompressed if DDS isn't enabled
    InitGLTex(ibuf->rect, ibuf->x, ibuf->y, mipmap);
    return;
#else
    glBindTexture(GL_TEXTURE_2D, mTexture);

    if (GPU_upload_dxt_texture(ibuf) == 0) {
        InitGLTex(ibuf->rect, ibuf->x, ibuf->y, mipmap);
        return;
    }
#endif
}
Ejemplo n.º 2
0
bool BL_Texture::InitFromImage(int unit,  Image *img, bool mipmap)
{

    ImBuf *ibuf;
    if (!img || img->ok==0)
    {
        mOk = false;
        return mOk;
    }

    ibuf= BKE_image_get_ibuf(img, NULL);
    if (ibuf==NULL)
    {
        img->ok = 0;
        mOk = false;
        return mOk;
    }


    mTexture = img->bindcode;
    mType = GL_TEXTURE_2D;
    mUnit = unit;

    ActivateUnit(mUnit);

    if (mTexture != 0) {
        glBindTexture(GL_TEXTURE_2D, mTexture );
        Validate();
        return mOk;
    }

    // look for an existing gl image
    BL_TextureMap::iterator mapLook = g_textureManager.find(img->id.name);
    if (mapLook != g_textureManager.end())
    {
        if (mapLook->second.gl_texture != 0)
        {
            mTexture = mapLook->second.gl_texture;
            glBindTexture(GL_TEXTURE_2D, mTexture);
            mOk = IsValid();
            return mOk;
        }
    }

    mNeedsDeleted = 1;
    glGenTextures(1, (GLuint*)&mTexture);
    InitGLTex(ibuf->rect, ibuf->x, ibuf->y, mipmap);

    // track created units
    BL_TextureObject obj;
    obj.gl_texture = mTexture;
    obj.ref_buffer = img;
    g_textureManager.insert(std::pair<char*, BL_TextureObject>((char*)img->id.name, obj));


    glDisable(GL_TEXTURE_2D);
    ActivateUnit(0);
    Validate();
    return mOk;
}