1 typedef unsigned int GLenum
;
2 typedef unsigned char GLboolean
;
4 typedef unsigned short GLushort
;
5 typedef unsigned int GLuint
;
7 typedef GLushort GLchan
;
8 struct gl_texture_image
;
9 typedef struct __GLcontextRec GLcontext
;
10 typedef void (*FetchTexelFuncC
) (const struct gl_texture_image
* texImage
,
11 GLint col
, GLint row
, GLint img
,
13 struct gl_texture_format
16 struct gl_texture_image
19 GLboolean _IsPowerOfTwo
;
20 FetchTexelFuncC FetchTexelc
;
22 struct gl_texture_object
30 struct gl_texture_image
*Image
[6][12];
34 MESA_FORMAT_RGBA_DXT3
, MESA_FORMAT_RGBA_DXT5
, MESA_FORMAT_RGBA
,
35 MESA_FORMAT_RGB
, MESA_FORMAT_ALPHA
, MESA_FORMAT_LUMINANCE
,
37 typedef void (*texture_sample_func
) (GLcontext
* ctx
,
38 const struct gl_texture_object
* tObj
,
39 GLuint n
, const GLfloat texcoords
[][4],
40 const GLfloat lambda
[],
42 lerp_2d (GLfloat a
, GLfloat b
, GLfloat v00
, GLfloat v10
, GLfloat v01
,
45 const GLfloat temp0
= ((v00
) + (a
) * ((v10
) - (v00
)));
46 const GLfloat temp1
= ((v01
) + (a
) * ((v11
) - (v01
)));
47 return ((temp0
) + (b
) * ((temp1
) - (temp0
)));
49 static __inline__
void
50 lerp_rgba (GLchan result
[4], GLfloat t
, const GLchan a
[4], const GLchan b
[4])
52 result
[0] = (GLchan
) (((a
[0]) + (t
) * ((b
[0]) - (a
[0]))) + 0.5);
53 result
[1] = (GLchan
) (((a
[1]) + (t
) * ((b
[1]) - (a
[1]))) + 0.5);
54 result
[2] = (GLchan
) (((a
[2]) + (t
) * ((b
[2]) - (a
[2]))) + 0.5);
56 static __inline__
void
57 lerp_rgba_2d (GLchan result
[4], GLfloat a
, GLfloat b
, const GLchan t00
[4],
58 const GLchan t10
[4], const GLchan t01
[4], const GLchan t11
[4])
60 result
[0] = (GLchan
) (lerp_2d (a
, b
, t00
[0], t10
[0], t01
[0], t11
[0]) + 0.5);
61 result
[1] = (GLchan
) (lerp_2d (a
, b
, t00
[1], t10
[1], t01
[1], t11
[1]) + 0.5);
62 result
[2] = (GLchan
) (lerp_2d (a
, b
, t00
[2], t10
[2], t01
[2], t11
[2]) + 0.5);
64 static __inline__
void
65 sample_2d_linear_repeat (GLcontext
* ctx
,
66 const struct gl_texture_object
*tObj
,
67 const struct gl_texture_image
*img
,
68 const GLfloat texcoord
[4], GLchan rgba
[])
72 GLchan t00
[4], t10
[4], t01
[4], t11
[4];
75 img
->FetchTexelc (img
, i1
, j1
, 0, t11
);
76 lerp_rgba_2d (rgba
, a
, b
, t00
, t10
, t01
, t11
);
78 sample_2d_nearest_mipmap_linear (GLcontext
* ctx
,
79 const struct gl_texture_object
*tObj
,
80 GLuint n
, const GLfloat texcoord
[][4],
81 const GLfloat lambda
[], GLchan rgba
[][4])
84 GLint level
= linear_mipmap_level (tObj
, lambda
[i
]);
85 sample_2d_nearest (ctx
, tObj
, tObj
->Image
[0][tObj
->_MaxLevel
], texcoord
[i
], rgba
[i
]);
87 sample_2d_nearest (ctx
, tObj
, tObj
->Image
[0][level
], texcoord
[i
], t0
);
88 sample_2d_nearest (ctx
, tObj
, tObj
->Image
[0][level
+ 1], texcoord
[i
], t1
);
91 sample_2d_linear_mipmap_linear_repeat (GLcontext
* ctx
,
92 const struct gl_texture_object
*tObj
,
93 GLuint n
, const GLfloat texcoord
[][4],
94 const GLfloat lambda
[],
98 for (i
= 0; i
< n
; i
++)
100 GLint level
= linear_mipmap_level (tObj
, lambda
[i
]);
101 if (level
>= tObj
->_MaxLevel
)
104 const GLfloat f
= ((lambda
[i
]) - ifloor (lambda
[i
]));
105 sample_2d_linear_repeat (ctx
, tObj
, tObj
->Image
[0][level
],
107 sample_2d_linear_repeat (ctx
, tObj
, tObj
->Image
[0][level
+ 1],
109 lerp_rgba (rgba
[i
], f
, t0
, t1
);
114 sample_lambda_2d (GLcontext
* ctx
, const struct gl_texture_object
*tObj
,
115 GLuint n
, const GLfloat texcoords
[][4],
116 const GLfloat lambda
[], GLchan rgba
[][4])
118 const struct gl_texture_image
*tImg
= tObj
->Image
[0][tObj
->BaseLevel
];
119 GLuint minStart
, minEnd
;
120 GLuint magStart
, magEnd
;
121 const GLboolean repeatNoBorderPOT
= (tObj
->WrapS
== 0x2901)
122 && (tImg
->_BaseFormat
!= 0x1900) && tImg
->_IsPowerOfTwo
;
123 compute_min_mag_ranges (tObj
, n
, lambda
, &minStart
, &minEnd
, &magStart
,
125 if (minStart
< minEnd
)
127 const GLuint m
= minEnd
- minStart
;
128 switch (tObj
->MinFilter
)
131 if (repeatNoBorderPOT
)
133 case MESA_FORMAT_RGB
:
134 opt_sample_rgb_2d (ctx
, tObj
, m
, texcoords
+ minStart
,
135 ((void *) 0), rgba
+ minStart
);
136 case MESA_FORMAT_RGBA
:
137 opt_sample_rgba_2d (ctx
, tObj
, m
, texcoords
+ minStart
,
138 ((void *) 0), rgba
+ minStart
);
141 sample_nearest_2d (ctx
, tObj
, m
, texcoords
+ minStart
,
142 ((void *) 0), rgba
+ minStart
);
145 sample_2d_nearest_mipmap_linear (ctx
, tObj
, m
, texcoords
+ minStart
,
149 if (repeatNoBorderPOT
)
150 sample_2d_linear_mipmap_linear_repeat (ctx
, tObj
, m
,
151 texcoords
+ minStart
,
155 switch (tObj
->MagFilter
)
157 case MESA_FORMAT_RGB
:
158 opt_sample_rgb_2d (ctx
, tObj
, m
, texcoords
+ magStart
,
159 ((void *) 0), rgba
+ magStart
);
160 opt_sample_rgba_2d (ctx
, tObj
, m
, texcoords
+ magStart
,
161 ((void *) 0), rgba
+ magStart
);
162 sample_nearest_2d (ctx
, tObj
, m
, texcoords
+ magStart
,
163 ((void *) 0), rgba
+ magStart
);
168 _swrast_choose_texture_sample_func (const struct gl_texture_object
*t
)
173 return &sample_lambda_2d
;