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
) {
42 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_Y8
;
43 case MESA_FORMAT_ARGB1555
:
44 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A1R5G5B5
;
45 case MESA_FORMAT_ARGB4444
:
46 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A4R4G4B4
;
47 case MESA_FORMAT_RGB565
:
48 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_R5G6B5
;
49 case MESA_FORMAT_ARGB8888
:
50 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A8R8G8B8
;
51 case MESA_FORMAT_XRGB8888
:
52 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_X8R8G8B8
;
58 static inline unsigned
59 get_wrap_mode(unsigned wrap
)
64 case GL_MIRRORED_REPEAT
:
67 case GL_CLAMP_TO_EDGE
:
69 case GL_CLAMP_TO_BORDER
:
77 nv04_emit_tex_obj(GLcontext
*ctx
, int emit
)
79 const int i
= emit
- NOUVEAU_STATE_TEX_OBJ0
;
80 struct nouveau_channel
*chan
= context_chan(ctx
);
81 struct nouveau_grobj
*fahrenheit
= nv04_context_engine(ctx
);
82 struct nouveau_bo_context
*bctx
= context_bctx_i(ctx
, TEXTURE
, i
);
83 const int bo_flags
= NOUVEAU_BO_RD
| NOUVEAU_BO_GART
| NOUVEAU_BO_VRAM
;
84 struct nouveau_surface
*s
;
85 uint32_t format
= 0xa0, filter
= 0x1010;
87 if (i
&& !nv04_mtex_engine(fahrenheit
))
90 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
) {
91 struct gl_texture_object
*t
= ctx
->Texture
.Unit
[i
]._Current
;
92 struct gl_texture_image
*ti
= t
->Image
[0][t
->BaseLevel
];
93 int lod_max
= 1, lod_bias
= 0;
95 if (!nouveau_texture_validate(ctx
, t
))
98 s
= &to_nouveau_texture(t
)->surfaces
[t
->BaseLevel
];
100 if (t
->MinFilter
!= GL_NEAREST
&&
101 t
->MinFilter
!= GL_LINEAR
) {
102 lod_max
= CLAMP(MIN2(t
->MaxLod
, t
->_MaxLambda
),
105 lod_bias
= CLAMP(ctx
->Texture
.Unit
[i
].LodBias
+
109 format
|= get_wrap_mode(t
->WrapT
) << 28 |
110 get_wrap_mode(t
->WrapS
) << 24 |
111 ti
->HeightLog2
<< 20 |
112 ti
->WidthLog2
<< 16 |
116 filter
|= log2i(t
->MaxAnisotropy
) << 31 |
117 nvgl_filter_mode(t
->MagFilter
) << 28 |
118 log2i(t
->MaxAnisotropy
) << 27 |
119 nvgl_filter_mode(t
->MinFilter
) << 24 |
123 s
= &to_nv04_context(ctx
)->dummy_texture
;
125 format
|= NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_REPEAT
|
126 NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSV_REPEAT
|
128 NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A8R8G8B8
;
130 filter
|= NV04_TEXTURED_TRIANGLE_FILTER_MINIFY_NEAREST
|
131 NV04_TEXTURED_TRIANGLE_FILTER_MAGNIFY_NEAREST
;
134 if (nv04_mtex_engine(fahrenheit
)) {
135 nouveau_bo_markl(bctx
, fahrenheit
,
136 NV04_MULTITEX_TRIANGLE_OFFSET(i
),
139 nouveau_bo_mark(bctx
, fahrenheit
,
140 NV04_MULTITEX_TRIANGLE_FORMAT(i
),
142 NV04_MULTITEX_TRIANGLE_FORMAT_DMA_A
,
143 NV04_MULTITEX_TRIANGLE_FORMAT_DMA_B
,
144 bo_flags
| NOUVEAU_BO_OR
);
146 BEGIN_RING(chan
, fahrenheit
, NV04_MULTITEX_TRIANGLE_FILTER(i
), 1);
147 OUT_RING(chan
, filter
);
150 nouveau_bo_markl(bctx
, fahrenheit
,
151 NV04_TEXTURED_TRIANGLE_OFFSET
,
154 nouveau_bo_mark(bctx
, fahrenheit
,
155 NV04_TEXTURED_TRIANGLE_FORMAT
,
157 NV04_TEXTURED_TRIANGLE_FORMAT_DMA_A
,
158 NV04_TEXTURED_TRIANGLE_FORMAT_DMA_B
,
159 bo_flags
| NOUVEAU_BO_OR
);
161 BEGIN_RING(chan
, fahrenheit
, NV04_TEXTURED_TRIANGLE_COLORKEY
, 1);
164 BEGIN_RING(chan
, fahrenheit
, NV04_TEXTURED_TRIANGLE_FILTER
, 1);
165 OUT_RING(chan
, filter
);