Пример #1
0
static radeon_mipmap_tree *radeon_miptree_create_for_teximage(radeonContextPtr rmesa,
        struct gl_texture_object *texObj,
        struct gl_texture_image *texImage)
{
    radeonTexObj *t = radeon_tex_obj(texObj);
    GLuint firstLevel;
    GLuint lastLevel;
    int width, height, depth;
    int i;

    width = texImage->Width;
    height = texImage->Height;
    depth = texImage->Depth;

    if (texImage->Level > texObj->BaseLevel &&
            (width == 1 ||
             (texObj->Target != GL_TEXTURE_1D && height == 1) ||
             (texObj->Target == GL_TEXTURE_3D && depth == 1))) {
        /* For this combination, we're at some lower mipmap level and
         * some important dimension is 1.  We can't extrapolate up to a
         * likely base level width/height/depth for a full mipmap stack
         * from this info, so just allocate this one level.
         */
        firstLevel = texImage->Level;
        lastLevel = texImage->Level;
    } else {
        if (texImage->Level < texObj->BaseLevel)
            firstLevel = 0;
        else
            firstLevel = texObj->BaseLevel;

        for (i = texImage->Level; i > firstLevel; i--) {
            width <<= 1;
            if (height != 1)
                height <<= 1;
            if (depth != 1)
                depth <<= 1;
        }
        if ((texObj->Sampler.MinFilter == GL_NEAREST ||
                texObj->Sampler.MinFilter == GL_LINEAR) &&
                texImage->Level == firstLevel) {
            lastLevel = firstLevel;
        } else {
            lastLevel = firstLevel + _mesa_logbase2(MAX2(MAX2(width, height), depth));
        }
    }

    return  radeon_miptree_create(rmesa, texObj->Target,
                                  texImage->TexFormat, firstLevel, lastLevel - firstLevel + 1,
                                  width, height, depth,
                                  t->tile_bits);
}
Пример #2
0
/**
 * Try to allocate a mipmap tree for the given texture object.
 * @param[in] rmesa radeon context
 * @param[in] t radeon texture object
 */
void radeon_try_alloc_miptree(radeonContextPtr rmesa, radeonTexObj *t)
{
	struct gl_texture_object *texObj = &t->base;
	struct gl_texture_image *texImg = texObj->Image[0][texObj->BaseLevel];
	GLuint numLevels;
	assert(!t->mt);

	if (!texImg) {
		radeon_warning("%s(%p) No image in given texture object(%p).\n",
				__func__, rmesa, t);
		return;
	}


	numLevels = MIN2(texObj->MaxLevel - texObj->BaseLevel + 1, texImg->MaxNumLevels);

	t->mt = radeon_miptree_create(rmesa, t->base.Target,
		texImg->TexFormat, texObj->BaseLevel,
		numLevels, texImg->Width, texImg->Height,
		texImg->Depth, t->tile_bits);
}