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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# Create an 8x8 texture with four miplevels, colored red, green, blue, and
# white, respectively. Set the Lod-bias to 1. Draw the following:
#
# .0 .2 .4 .6 .8
#
# miplevel 3 + + +
#
# miplevel 3 +-+ +-+ +-+
# +-+ +-+ +-+ + +
#
# miplevel 2 +---+ +---+ +---+
# |2.0| |2.2| |2.4| +-+ +-+
# +---+ +---+ +---+ +-+ +-+
#
# +------+ +------+ +------+
# miplevel 1 | 1.0 | | 1.2 | | 1.4 | +---+ +---+
# | | | | | | |1.6| |1.8|
# +------+ +------+ +------+ +---+ +---+
#
# Instead of seeing red, green, blue, and white squares, we should see only
# green, blue, white, and again white squares.
#
# The ARB_texture_query_lod spec says:
#
# "The x component of the result vector contains information on the mipmap
# array(s) that would be accessed by a normal texture lookup using the
# same coordinates. If a single level of detail would be accessed, the
# level-of-detail number relative to the base level is returned."
#
# So check that the x component is equal to the calculated LOD + the bias
# clamped to the maximum mipmap level.
#
# The ARB_texture_query_lod spec says:
#
# "The computed level of detail lambda_prime (equation 3.19), relative to
# the base level, is returned in the y component of the result vector.
#
# The level of detail is obtained after any LOD bias, but prior to
# clamping to [TEXTURE_MIN_LOD, TEXTURE_MAX_LOD]."
#
# Thus the y component ranges from 1 to 4 (since it is obtained after LOD bias
# but before clamping) while the x component ranges from 1 to 3. So check that
# the x component is equal to the clamped y component.
[require]
GLSL >= 1.30
GL_ARB_texture_query_lod
[fragment shader]
#extension GL_ARB_texture_query_lod : enable
#define MAX_MIPMAP_LEVEL 3
uniform sampler2D tex;
uniform float lod;
void main()
{
/* The ARB_texture_query_lod spec says that if TEXTURE_MIN_FILTER is set
* to *_MIPMAP_NEAREST that the computed LOD is
*
* ceil(computedLod + 0.5) - 1.0
*
* which is "round to nearest integer, and round down for 0.5."
*/
float nearest_lod = ceil(lod + 0.5f) - 1.0f;
vec4 frag1 = texture(tex, gl_TexCoord[0].st);
vec4 frag2 = textureLod(tex, gl_TexCoord[0].st, nearest_lod);
if (frag1 != frag2) {
discard;
}
vec2 queried_lod = textureQueryLOD(tex, gl_TexCoord[0].st);
if (queried_lod.x != min(queried_lod.y, MAX_MIPMAP_LEVEL)) {
discard;
}
if (queried_lod.x != min(nearest_lod + 1, MAX_MIPMAP_LEVEL)) {
discard;
}
gl_FragColor = frag1;
}
[vertex shader]
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
[test]
ortho
clear color 0 0 0 0
clear
uniform int tex 0
texture miptree 0
# Draw the miptree: basic integer LODs.
texparameter 2D min nearest_mipmap_nearest
texparameter 2D mag nearest
texparameter 2D lod_bias 1.0
uniform float lod 0
draw rect tex 10 10 8 8 0 0 1 1
uniform float lod 1
draw rect tex 10 28 4 4 0 0 1 1
uniform float lod 2
draw rect tex 10 42 2 2 0 0 1 1
uniform float lod 3
draw rect tex 10 54 1 1 0 0 1 1
# Fractional LODs: nearest filtering between miplevels
uniform float lod 0.2
draw rect tex 28 10 8 8 0 0 1 1
uniform float lod 0.4
draw rect tex 46 10 8 8 0 0 1 1
uniform float lod 0.6
draw rect tex 64 10 4 4 0 0 1 1
uniform float lod 0.8
draw rect tex 82 10 4 4 0 0 1 1
uniform float lod 1.2
draw rect tex 28 28 4 4 0 0 1 1
uniform float lod 1.4
draw rect tex 46 28 4 4 0 0 1 1
uniform float lod 1.6
draw rect tex 64 28 2 2 0 0 1 1
uniform float lod 1.8
draw rect tex 82 28 2 2 0 0 1 1
uniform float lod 2.2
draw rect tex 28 42 2 2 0 0 1 1
uniform float lod 2.4
draw rect tex 46 42 2 2 0 0 1 1
uniform float lod 2.6
draw rect tex 64 42 1 1 0 0 1 1
uniform float lod 2.8
draw rect tex 82 42 1 1 0 0 1 1
uniform float lod 3.2
draw rect tex 28 54 1 1 0 0 1 1
uniform float lod 3.4
draw rect tex 46 54 1 1 0 0 1 1
# Probes: integer LODs
probe rgb 10 10 0.0 1.0 0.0
probe rgb 10 28 0.0 0.0 1.0
probe rgb 10 42 1.0 1.0 1.0
probe rgb 10 54 1.0 1.0 1.0
# Probes: nearest filtering
probe rgb 28 10 0.0 1.0 0.0
probe rgb 46 10 0.0 1.0 0.0
probe rgb 64 10 0.0 0.0 1.0
probe rgb 82 10 0.0 0.0 1.0
probe rgb 28 28 0.0 0.0 1.0
probe rgb 46 28 0.0 0.0 1.0
probe rgb 64 28 1.0 1.0 1.0
probe rgb 82 28 1.0 1.0 1.0
probe rgb 28 42 1.0 1.0 1.0
probe rgb 46 42 1.0 1.0 1.0
probe rgb 64 42 1.0 1.0 1.0
probe rgb 82 42 1.0 1.0 1.0
probe rgb 28 54 1.0 1.0 1.0
probe rgb 46 54 1.0 1.0 1.0
|