Exemplo n.º 1
0
void
nv04_emit_tex_env(struct gl_context *ctx, int emit)
{
    const int i = emit - NOUVEAU_STATE_TEX_ENV0;
    struct nouveau_channel *chan = context_chan(ctx);
    struct nouveau_grobj *fahrenheit = nv04_context_engine(ctx);
    struct combiner_state rc_a = {}, rc_c = {};

    if (!nv04_mtex_engine(fahrenheit)) {
        context_dirty(ctx, BLEND);
        return;
    }

    /* Compute the new combiner state. */
    if (ctx->Texture.Unit[i]._ReallyEnabled) {
        INIT_COMBINER(A, ctx, &rc_a, i);
        setup_combiner(&rc_a);

        INIT_COMBINER(RGB, ctx, &rc_c, i);
        setup_combiner(&rc_c);

    } else {
        if (i == 0) {
            INPUT_SRC(&rc_a, 0, PRIMARY_COLOR, 0);
            INPUT_SRC(&rc_c, 0, PRIMARY_COLOR, 0);
        } else {
            INPUT_SRC(&rc_a, 0, PREVIOUS, 0);
            INPUT_SRC(&rc_c, 0, PREVIOUS, 0);
        }

        INPUT_SRC(&rc_a, 1, ZERO, INVERT);
        INPUT_SRC(&rc_c, 1, ZERO, INVERT);
        INPUT_SRC(&rc_a, 2, ZERO, 0);
        INPUT_SRC(&rc_c, 2, ZERO, 0);
        INPUT_SRC(&rc_a, 3, ZERO, 0);
        INPUT_SRC(&rc_c, 3, ZERO, 0);

        UNSIGNED_OP(&rc_a);
        UNSIGNED_OP(&rc_c);
    }

    /* Write the register combiner state out to the hardware. */
    BEGIN_RING(chan, fahrenheit,
               NV04_MULTITEX_TRIANGLE_COMBINE_ALPHA(i), 2);
    OUT_RING(chan, rc_a.hw);
    OUT_RING(chan, rc_c.hw);

    BEGIN_RING(chan, fahrenheit,
               NV04_MULTITEX_TRIANGLE_COMBINE_FACTOR, 1);
    OUT_RING(chan, pack_rgba_f(MESA_FORMAT_ARGB8888,
                               ctx->Texture.Unit[0].EnvColor));
}
Exemplo n.º 2
0
void
nv04_emit_tex_obj(struct gl_context *ctx, int emit)
{
	const int i = emit - NOUVEAU_STATE_TEX_OBJ0;
	struct nouveau_channel *chan = context_chan(ctx);
	struct nouveau_grobj *fahrenheit = nv04_context_engine(ctx);
	struct nouveau_bo_context *bctx = context_bctx_i(ctx, TEXTURE, i);
	const int bo_flags = NOUVEAU_BO_RD | NOUVEAU_BO_GART | NOUVEAU_BO_VRAM;
	struct nouveau_surface *s;
	uint32_t format = 0xa0, filter = 0x1010;

	if (i && !nv04_mtex_engine(fahrenheit))
		return;

	if (ctx->Texture.Unit[i]._ReallyEnabled) {
		struct gl_texture_object *t = ctx->Texture.Unit[i]._Current;
		struct gl_texture_image *ti = t->Image[0][t->BaseLevel];
		int lod_max = 1, lod_bias = 0;

		if (!nouveau_texture_validate(ctx, t))
			return;

		s = &to_nouveau_texture(t)->surfaces[t->BaseLevel];

		if (t->MinFilter != GL_NEAREST &&
		    t->MinFilter != GL_LINEAR) {
			lod_max = CLAMP(MIN2(t->MaxLod, t->_MaxLambda),
					0, 15) + 1;

			lod_bias = CLAMP(ctx->Texture.Unit[i].LodBias +
					 t->LodBias, -16, 15) * 8;
		}

		format |= nvgl_wrap_mode(t->WrapT) << 28 |
			nvgl_wrap_mode(t->WrapS) << 24 |
			ti->HeightLog2 << 20 |
			ti->WidthLog2 << 16 |
			lod_max << 12 |
			get_tex_format(ti);

		filter |= log2i(t->MaxAnisotropy) << 31 |
			nvgl_filter_mode(t->MagFilter) << 28 |
			log2i(t->MaxAnisotropy) << 27 |
			nvgl_filter_mode(t->MinFilter) << 24 |
			(lod_bias & 0xff) << 16;

	} else {
		s = &to_nv04_context(ctx)->dummy_texture;

		format |= NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_REPEAT |
			NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSV_REPEAT |
			1 << 12 |
			NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A8R8G8B8;

		filter |= NV04_TEXTURED_TRIANGLE_FILTER_MINIFY_NEAREST |
			NV04_TEXTURED_TRIANGLE_FILTER_MAGNIFY_NEAREST;
	}

	if (nv04_mtex_engine(fahrenheit)) {
		nouveau_bo_markl(bctx, fahrenheit,
				 NV04_MULTITEX_TRIANGLE_OFFSET(i),
				 s->bo, s->offset, bo_flags);

		nouveau_bo_mark(bctx, fahrenheit,
				NV04_MULTITEX_TRIANGLE_FORMAT(i),
				s->bo, format, 0,
				NV04_MULTITEX_TRIANGLE_FORMAT_DMA_A,
				NV04_MULTITEX_TRIANGLE_FORMAT_DMA_B,
				bo_flags | NOUVEAU_BO_OR);

		BEGIN_RING(chan, fahrenheit, NV04_MULTITEX_TRIANGLE_FILTER(i), 1);
		OUT_RING(chan, filter);

	} else {
		nouveau_bo_markl(bctx, fahrenheit,
				 NV04_TEXTURED_TRIANGLE_OFFSET,
				 s->bo, s->offset, bo_flags);

		nouveau_bo_mark(bctx, fahrenheit,
				NV04_TEXTURED_TRIANGLE_FORMAT,
				s->bo, format, 0,
				NV04_TEXTURED_TRIANGLE_FORMAT_DMA_A,
				NV04_TEXTURED_TRIANGLE_FORMAT_DMA_B,
				bo_flags | NOUVEAU_BO_OR);

		BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_COLORKEY, 1);
		OUT_RING(chan, 0);

		BEGIN_RING(chan, fahrenheit, NV04_TEXTURED_TRIANGLE_FILTER, 1);
		OUT_RING(chan, filter);
	}
}