Minor r200 vertex program cleanups. Remove disabled leftovers from r300 vertex progra...
[mesa.git] / src / mesa / drivers / dri / i965 / brw_tex_layout.c
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32
33 /* Code to layout images in a mipmap tree for i965.
34 */
35
36 #include "intel_mipmap_tree.h"
37 #include "macros.h"
38
39 static GLuint minify( GLuint d )
40 {
41 return MAX2(1, d>>1);
42 }
43
44
45 GLboolean brw_miptree_layout( struct intel_mipmap_tree *mt )
46 {
47 /* XXX: these vary depending on image format:
48 */
49 /* GLint align_w = 4; */
50 GLint align_h = 2;
51
52
53 switch (mt->target) {
54 case GL_TEXTURE_CUBE_MAP:
55 case GL_TEXTURE_3D: {
56 GLuint width = mt->width0;
57 GLuint height = mt->height0;
58 GLuint depth = mt->depth0;
59 GLuint pack_x_pitch, pack_x_nr;
60 GLuint pack_y_pitch;
61 GLuint level;
62
63 mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp;
64 mt->total_height = 0;
65
66 pack_y_pitch = MAX2(mt->height0, 2);
67 pack_x_pitch = mt->pitch;
68 pack_x_nr = 1;
69
70 for ( level = mt->first_level ; level <= mt->last_level ; level++ ) {
71 GLuint nr_images = mt->target == GL_TEXTURE_3D ? depth : 6;
72 GLint x = 0;
73 GLint y = 0;
74 GLint q, j;
75
76 intel_miptree_set_level_info(mt, level, nr_images,
77 0, mt->total_height,
78 width, height, depth);
79
80 for (q = 0; q < nr_images;) {
81 for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) {
82 intel_miptree_set_image_offset(mt, level, q, x, y);
83 x += pack_x_pitch;
84 }
85
86 x = 0;
87 y += pack_y_pitch;
88 }
89
90
91 mt->total_height += y;
92
93 if (pack_x_pitch > 4) {
94 pack_x_pitch >>= 1;
95 pack_x_nr <<= 1;
96 assert(pack_x_pitch * pack_x_nr <= mt->pitch);
97 }
98
99 if (pack_y_pitch > 2) {
100 pack_y_pitch >>= 1;
101 }
102
103 width = minify(width);
104 height = minify(height);
105 depth = minify(depth);
106 }
107 break;
108 }
109
110 default: {
111 GLuint level;
112 GLuint x = 0;
113 GLuint y = 0;
114 GLuint width = mt->width0;
115 GLuint height = mt->height0;
116
117 mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp;
118 mt->total_height = 0;
119
120 for ( level = mt->first_level ; level <= mt->last_level ; level++ ) {
121 GLuint img_height;
122
123 intel_miptree_set_level_info(mt, level, 1,
124 x, y,
125 width,
126 mt->compressed ? height/4 : height, 1);
127
128 if (mt->compressed)
129 img_height = MAX2(1, height/4);
130 else
131 img_height = MAX2(align_h, height);
132
133
134 /* Because the images are packed better, the final offset
135 * might not be the maximal one:
136 */
137 mt->total_height = MAX2(mt->total_height, y + img_height);
138
139 /* Layout_below: step right after second mipmap.
140 */
141 if (level == mt->first_level + 1)
142 x += mt->pitch / 2;
143 else {
144 y += img_height;
145 }
146
147
148 width = minify(width);
149 height = minify(height);
150 }
151 break;
152 }
153 }
154 DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__,
155 mt->pitch,
156 mt->total_height,
157 mt->cpp,
158 mt->pitch * mt->total_height * mt->cpp );
159
160 return GL_TRUE;
161 }
162