summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/nine/nine_ff.h
blob: 9c33c76370df15da75db8d6c6af15b7472b0598a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

#ifndef _NINE_FF_H_
#define _NINE_FF_H_

#include "device9.h"
#include "vertexdeclaration9.h"

boolean nine_ff_init(struct NineDevice9 *);
void    nine_ff_fini(struct NineDevice9 *);

void nine_ff_update(struct NineDevice9 *);

void
nine_d3d_matrix_matrix_mul(D3DMATRIX *, const D3DMATRIX *, const D3DMATRIX *);

void
nine_d3d_vector4_matrix_mul(D3DVECTOR *, const D3DVECTOR *, const D3DMATRIX *);
void
nine_d3d_vector3_matrix_mul(D3DVECTOR *, const D3DVECTOR *, const D3DMATRIX *);

float
nine_d3d_matrix_det(const D3DMATRIX *);

void
nine_d3d_matrix_inverse(D3DMATRIX *, const D3DMATRIX *);

void
nine_d3d_matrix_inverse_3x3(D3DMATRIX *, const D3DMATRIX *);

void
nine_d3d_matrix_transpose(D3DMATRIX *, const D3DMATRIX *);

#define NINED3DTSS_TCI_DISABLE                       0
#define NINED3DTSS_TCI_PASSTHRU                      1
#define NINED3DTSS_TCI_CAMERASPACENORMAL             2
#define NINED3DTSS_TCI_CAMERASPACEPOSITION           3
#define NINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR   4
#define NINED3DTSS_TCI_SPHEREMAP                     5

static inline unsigned
nine_decltype_get_dim(BYTE type)
{
    switch (type) {
    case D3DDECLTYPE_FLOAT1: return 1;
    case D3DDECLTYPE_FLOAT2: return 2;
    case D3DDECLTYPE_FLOAT3: return 3;
    case D3DDECLTYPE_FLOAT4: return 4;
    case D3DDECLTYPE_D3DCOLOR: return 1;
    case D3DDECLTYPE_UBYTE4: return 4;
    case D3DDECLTYPE_SHORT2: return 2;
    case D3DDECLTYPE_SHORT4: return 4;
    case D3DDECLTYPE_UBYTE4N: return 4;
    case D3DDECLTYPE_SHORT2N: return 2;
    case D3DDECLTYPE_SHORT4N: return 4;
    case D3DDECLTYPE_USHORT2N: return 2;
    case D3DDECLTYPE_USHORT4N: return 4;
    case D3DDECLTYPE_UDEC3: return 3;
    case D3DDECLTYPE_DEC3N: return 3;
    case D3DDECLTYPE_FLOAT16_2: return 2;
    case D3DDECLTYPE_FLOAT16_4: return 4;
    default:
        assert(!"Implementation error !");
    }
    return 0;
}

static inline uint16_t
nine_ff_get_projected_key(struct nine_state *state)
{
    unsigned s, i;
    uint16_t projected = 0;
    char input_texture_coord[8];
    memset(&input_texture_coord, 0, sizeof(input_texture_coord));

    if (state->vdecl) {
        for (i = 0; i < state->vdecl->nelems; i++) {
            uint16_t usage = state->vdecl->usage_map[i];
            if (usage % NINE_DECLUSAGE_COUNT == NINE_DECLUSAGE_TEXCOORD) {
                s = usage / NINE_DECLUSAGE_COUNT;
                if (s < 8)
                    input_texture_coord[s] = nine_decltype_get_dim(state->vdecl->decls[i].Type);
            }
        }
    }

    for (s = 0; s < 8; ++s) {
        unsigned gen = (state->ff.tex_stage[s][D3DTSS_TEXCOORDINDEX] >> 16) + 1;
        unsigned dim = state->ff.tex_stage[s][D3DTSS_TEXTURETRANSFORMFLAGS] & 0x7;
        unsigned proj = !!(state->ff.tex_stage[s][D3DTSS_TEXTURETRANSFORMFLAGS] & D3DTTFF_PROJECTED);

        if (!state->vs) {
            if (dim > 4)
                dim = input_texture_coord[s];

            if (!dim && gen == NINED3DTSS_TCI_PASSTHRU)
                dim = input_texture_coord[s];
            else if (!dim)
                dim = 4;

            if (dim == 1) /* NV behaviour */
                proj = 0;
            if (dim > input_texture_coord[s] && gen == NINED3DTSS_TCI_PASSTHRU)
                proj = 0;
        } else {
            dim = 4;
        }
        if (proj)
            projected |= (dim-1) << (2 * s);
    }
    return projected;
}

#endif /* _NINE_FF_H_ */