-#include "st_inlines.h"
-
-
-/**
- * one-time init for generate mipmap
- * XXX Note: there may be other times we need no-op/simple state like this.
- * In that case, some code refactoring would be good.
- */
-void
-st_init_generate_mipmap(struct st_context *st)
-{
- st->gen_mipmap = util_create_gen_mipmap(st->pipe, st->cso_context);
-}
-
-
-void
-st_destroy_generate_mipmap(struct st_context *st)
-{
- util_destroy_gen_mipmap(st->gen_mipmap);
- st->gen_mipmap = NULL;
-}
-
-
-/**
- * Generate mipmap levels using hardware rendering.
- * \return TRUE if successful, FALSE if not possible
- */
-static boolean
-st_render_mipmap(struct st_context *st,
- GLenum target,
- struct pipe_texture *pt,
- uint baseLevel, uint lastLevel)
-{
- struct pipe_context *pipe = st->pipe;
- struct pipe_screen *screen = pipe->screen;
- const uint face = _mesa_tex_target_to_face(target);
-
- assert(target != GL_TEXTURE_3D); /* not done yet */
-
- /* check if we can render in the texture's format */
- if (!screen->is_format_supported(screen, pt->format, pt->target,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
- return FALSE;
- }
-
- util_gen_mipmap(st->gen_mipmap, pt, face, baseLevel, lastLevel,
- PIPE_TEX_FILTER_LINEAR);
-
- return TRUE;
-}
-
-
-static void
-fallback_generate_mipmap(GLcontext *ctx, GLenum target,
- struct gl_texture_object *texObj)
-{
- struct pipe_context *pipe = ctx->st->pipe;
- struct pipe_screen *screen = pipe->screen;
- struct pipe_texture *pt = st_get_texobj_texture(texObj);
- const uint baseLevel = texObj->BaseLevel;
- const uint lastLevel = pt->last_level;
- const uint face = _mesa_tex_target_to_face(target), zslice = 0;
- uint dstLevel;
- GLenum datatype;
- GLuint comps;
-
- if (ST_DEBUG & DEBUG_FALLBACK)
- debug_printf("%s: fallback processing\n", __FUNCTION__);
-
- assert(target != GL_TEXTURE_3D); /* not done yet */
-
- _mesa_format_to_type_and_comps(texObj->Image[face][baseLevel]->TexFormat,
- &datatype, &comps);
-
- for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) {
- const uint srcLevel = dstLevel - 1;
- struct pipe_transfer *srcTrans, *dstTrans;
- const ubyte *srcData;
- ubyte *dstData;
- int srcStride, dstStride;
-
- srcTrans = st_cond_flush_get_tex_transfer(st_context(ctx), pt, face,
- srcLevel, zslice,
- PIPE_TRANSFER_READ, 0, 0,
- u_minify(pt->width0, srcLevel),
- u_minify(pt->height0, srcLevel));
-
- dstTrans = st_cond_flush_get_tex_transfer(st_context(ctx), pt, face,
- dstLevel, zslice,
- PIPE_TRANSFER_WRITE, 0, 0,
- u_minify(pt->width0, dstLevel),
- u_minify(pt->height0, dstLevel));
-
- srcData = (ubyte *) screen->transfer_map(screen, srcTrans);
- dstData = (ubyte *) screen->transfer_map(screen, dstTrans);
-
- srcStride = srcTrans->stride / util_format_get_blocksize(srcTrans->texture->format);
- dstStride = dstTrans->stride / util_format_get_blocksize(dstTrans->texture->format);
-
- _mesa_generate_mipmap_level(target, datatype, comps,
- 0 /*border*/,
- u_minify(pt->width0, srcLevel),
- u_minify(pt->height0, srcLevel),
- u_minify(pt->depth0, srcLevel),
- srcData,
- srcStride, /* stride in texels */
- u_minify(pt->width0, dstLevel),
- u_minify(pt->height0, dstLevel),
- u_minify(pt->depth0, dstLevel),
- dstData,
- dstStride); /* stride in texels */
-
- screen->transfer_unmap(screen, srcTrans);
- screen->transfer_unmap(screen, dstTrans);
-
- screen->tex_transfer_destroy(srcTrans);
- screen->tex_transfer_destroy(dstTrans);
- }
-}