2 * Copyright (C) 2009 Francisco Jerez.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "nouveau_driver.h"
28 #include "nouveau_context.h"
29 #include "nouveau_texture.h"
30 #include "nouveau_util.h"
31 #include "nouveau_gldefs.h"
32 #include "nouveau_class.h"
33 #include "nv04_driver.h"
36 get_tex_format(struct gl_texture_image
*ti
)
38 switch (ti
->TexFormat
) {
41 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_Y8
;
42 case MESA_FORMAT_ARGB1555
:
43 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A1R5G5B5
;
44 case MESA_FORMAT_ARGB4444
:
45 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A4R4G4B4
;
46 case MESA_FORMAT_RGB565
:
47 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_R5G6B5
;
48 case MESA_FORMAT_ARGB8888
:
49 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A8R8G8B8
;
55 static inline unsigned
56 get_wrap_mode(unsigned wrap
)
61 case GL_MIRRORED_REPEAT
:
64 case GL_CLAMP_TO_EDGE
:
66 case GL_CLAMP_TO_BORDER
:
74 nv04_emit_tex_obj(GLcontext
*ctx
, int emit
)
76 const int i
= emit
- NOUVEAU_STATE_TEX_OBJ0
;
77 struct nouveau_channel
*chan
= context_chan(ctx
);
78 struct nouveau_grobj
*fahrenheit
= nv04_context_engine(ctx
);
79 struct nouveau_bo_context
*bctx
= context_bctx_i(ctx
, TEXTURE
, i
);
80 const int bo_flags
= NOUVEAU_BO_RD
| NOUVEAU_BO_GART
| NOUVEAU_BO_VRAM
;
81 struct nouveau_surface
*s
;
82 uint32_t format
= 0xa0, filter
= 0x1010;
84 if (i
&& !nv04_mtex_engine(fahrenheit
))
87 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
) {
88 struct gl_texture_object
*t
= ctx
->Texture
.Unit
[i
]._Current
;
89 struct gl_texture_image
*ti
= t
->Image
[0][t
->BaseLevel
];
90 int lod_max
= 1, lod_bias
= 0;
92 nouveau_texture_validate(ctx
, t
);
93 s
= &to_nouveau_texture(t
)->surfaces
[t
->BaseLevel
];
95 if (t
->MinFilter
!= GL_NEAREST
&&
96 t
->MinFilter
!= GL_LINEAR
) {
97 lod_max
= CLAMP(MIN2(t
->MaxLod
, t
->_MaxLambda
),
100 lod_bias
= CLAMP(ctx
->Texture
.Unit
[i
].LodBias
+
104 format
|= get_wrap_mode(t
->WrapT
) << 28 |
105 get_wrap_mode(t
->WrapS
) << 24 |
106 ti
->HeightLog2
<< 20 |
107 ti
->WidthLog2
<< 16 |
111 filter
|= log2i(t
->MaxAnisotropy
) << 31 |
112 nvgl_filter_mode(t
->MagFilter
) << 28 |
113 log2i(t
->MaxAnisotropy
) << 27 |
114 nvgl_filter_mode(t
->MinFilter
) << 24 |
118 s
= &to_nv04_context(ctx
)->dummy_texture
;
120 format
|= NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_REPEAT
|
121 NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSV_REPEAT
|
123 NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A8R8G8B8
;
125 filter
|= NV04_TEXTURED_TRIANGLE_FILTER_MINIFY_NEAREST
|
126 NV04_TEXTURED_TRIANGLE_FILTER_MAGNIFY_NEAREST
;
129 if (nv04_mtex_engine(fahrenheit
)) {
130 nouveau_bo_markl(bctx
, fahrenheit
,
131 NV04_MULTITEX_TRIANGLE_OFFSET(i
),
134 nouveau_bo_mark(bctx
, fahrenheit
,
135 NV04_MULTITEX_TRIANGLE_FORMAT(i
),
137 NV04_MULTITEX_TRIANGLE_FORMAT_DMA_A
,
138 NV04_MULTITEX_TRIANGLE_FORMAT_DMA_B
,
139 bo_flags
| NOUVEAU_BO_OR
);
141 BEGIN_RING(chan
, fahrenheit
, NV04_MULTITEX_TRIANGLE_FILTER(i
), 1);
142 OUT_RING(chan
, filter
);
145 nouveau_bo_markl(bctx
, fahrenheit
,
146 NV04_TEXTURED_TRIANGLE_OFFSET
,
149 nouveau_bo_mark(bctx
, fahrenheit
,
150 NV04_TEXTURED_TRIANGLE_FORMAT
,
152 NV04_TEXTURED_TRIANGLE_FORMAT_DMA_A
,
153 NV04_TEXTURED_TRIANGLE_FORMAT_DMA_B
,
154 bo_flags
| NOUVEAU_BO_OR
);
156 BEGIN_RING(chan
, fahrenheit
, NV04_TEXTURED_TRIANGLE_COLORKEY
, 1);
159 BEGIN_RING(chan
, fahrenheit
, NV04_TEXTURED_TRIANGLE_FILTER
, 1);
160 OUT_RING(chan
, filter
);