1 /* { dg-skip-if "too many arguments in function call" { bpf-*-* } } */
2 
3 typedef unsigned int GLenum;
4 typedef unsigned char GLboolean;
5 typedef int GLint;
6 typedef unsigned short GLushort;
7 typedef unsigned int GLuint;
8 typedef float GLfloat;
9 typedef GLushort GLchan;
10 struct gl_texture_image;
11 typedef struct __GLcontextRec GLcontext;
12 typedef void (*FetchTexelFuncC) (const struct gl_texture_image * texImage,
13 				 GLint col, GLint row, GLint img,
14 				 GLchan * texelOut);
15 struct gl_texture_format
16 {
17 };
18 struct gl_texture_image
19 {
20   GLenum _BaseFormat;
21   GLboolean _IsPowerOfTwo;
22   FetchTexelFuncC FetchTexelc;
23 };
24 struct gl_texture_object
25 {
26   GLenum Target;
27   GLenum WrapS;
28   GLenum MinFilter;
29   GLenum MagFilter;
30   GLint BaseLevel;
31   GLint _MaxLevel;
32   struct gl_texture_image *Image[6][12];
33 };
34 enum _format
35 {
36     MESA_FORMAT_RGBA_DXT3, MESA_FORMAT_RGBA_DXT5, MESA_FORMAT_RGBA,
37     MESA_FORMAT_RGB, MESA_FORMAT_ALPHA, MESA_FORMAT_LUMINANCE,
38 };
39 typedef void (*texture_sample_func) (GLcontext * ctx,
40 				     const struct gl_texture_object * tObj,
41 				     GLuint n, const GLfloat texcoords[][4],
42 				     const GLfloat lambda[],
43 				     GLchan rgba[][4]);
lerp_2d(GLfloat a,GLfloat b,GLfloat v00,GLfloat v10,GLfloat v01,GLfloat v11)44 lerp_2d (GLfloat a, GLfloat b, GLfloat v00, GLfloat v10, GLfloat v01,
45 	 GLfloat v11)
46 {
47   const GLfloat temp0 = ((v00) + (a) * ((v10) - (v00)));
48   const GLfloat temp1 = ((v01) + (a) * ((v11) - (v01)));
49   return ((temp0) + (b) * ((temp1) - (temp0)));
50 }
51 static __inline__ void
lerp_rgba(GLchan result[4],GLfloat t,const GLchan a[4],const GLchan b[4])52 lerp_rgba (GLchan result[4], GLfloat t, const GLchan a[4], const GLchan b[4])
53 {
54   result[0] = (GLchan) (((a[0]) + (t) * ((b[0]) - (a[0]))) + 0.5);
55   result[1] = (GLchan) (((a[1]) + (t) * ((b[1]) - (a[1]))) + 0.5);
56   result[2] = (GLchan) (((a[2]) + (t) * ((b[2]) - (a[2]))) + 0.5);
57 }
58 static __inline__ void
lerp_rgba_2d(GLchan result[4],GLfloat a,GLfloat b,const GLchan t00[4],const GLchan t10[4],const GLchan t01[4],const GLchan t11[4])59 lerp_rgba_2d (GLchan result[4], GLfloat a, GLfloat b, const GLchan t00[4],
60 	      const GLchan t10[4], const GLchan t01[4], const GLchan t11[4])
61 {
62   result[0] = (GLchan) (lerp_2d (a, b, t00[0], t10[0], t01[0], t11[0]) + 0.5);
63   result[1] = (GLchan) (lerp_2d (a, b, t00[1], t10[1], t01[1], t11[1]) + 0.5);
64   result[2] = (GLchan) (lerp_2d (a, b, t00[2], t10[2], t01[2], t11[2]) + 0.5);
65 }
66 static __inline__ void
sample_2d_linear_repeat(GLcontext * ctx,const struct gl_texture_object * tObj,const struct gl_texture_image * img,const GLfloat texcoord[4],GLchan rgba[])67 sample_2d_linear_repeat (GLcontext * ctx,
68 			 const struct gl_texture_object *tObj,
69 			 const struct gl_texture_image *img,
70 			 const GLfloat texcoord[4], GLchan rgba[])
71 {
72   GLint i0, j0, i1, j1;
73   GLfloat a, b;
74   GLchan t00[4], t10[4], t01[4], t11[4];
75   {
76   };
77   img->FetchTexelc (img, i1, j1, 0, t11);
78   lerp_rgba_2d (rgba, a, b, t00, t10, t01, t11);
79 }
sample_2d_nearest_mipmap_linear(GLcontext * ctx,const struct gl_texture_object * tObj,GLuint n,const GLfloat texcoord[][4],const GLfloat lambda[],GLchan rgba[][4])80 sample_2d_nearest_mipmap_linear (GLcontext * ctx,
81 				 const struct gl_texture_object *tObj,
82 				 GLuint n, const GLfloat texcoord[][4],
83 				 const GLfloat lambda[], GLchan rgba[][4])
84 {
85   GLuint i;
86   GLint level = linear_mipmap_level (tObj, lambda[i]);
87   sample_2d_nearest (ctx, tObj, tObj->Image[0][tObj->_MaxLevel], texcoord[i], rgba[i]);
88   GLchan t0[4], t1[4];
89   sample_2d_nearest (ctx, tObj, tObj->Image[0][level], texcoord[i], t0);
90   sample_2d_nearest (ctx, tObj, tObj->Image[0][level + 1], texcoord[i], t1);
91 }
92 static void
sample_2d_linear_mipmap_linear_repeat(GLcontext * ctx,const struct gl_texture_object * tObj,GLuint n,const GLfloat texcoord[][4],const GLfloat lambda[],GLchan rgba[][4])93 sample_2d_linear_mipmap_linear_repeat (GLcontext * ctx,
94 				       const struct gl_texture_object *tObj,
95 				       GLuint n, const GLfloat texcoord[][4],
96 				       const GLfloat lambda[],
97 				       GLchan rgba[][4])
98 {
99   GLuint i;
100   for (i = 0; i < n; i++)
101     {
102       GLint level = linear_mipmap_level (tObj, lambda[i]);
103       if (level >= tObj->_MaxLevel)
104 	{
105 	  GLchan t0[4], t1[4];
106 	  const GLfloat f = ((lambda[i]) - ifloor (lambda[i]));
107 	  sample_2d_linear_repeat (ctx, tObj, tObj->Image[0][level],
108 				   texcoord[i], t0);
109 	  sample_2d_linear_repeat (ctx, tObj, tObj->Image[0][level + 1],
110 				   texcoord[i], t1);
111 	  lerp_rgba (rgba[i], f, t0, t1);
112 	}
113     }
114 }
115 static void
sample_lambda_2d(GLcontext * ctx,const struct gl_texture_object * tObj,GLuint n,const GLfloat texcoords[][4],const GLfloat lambda[],GLchan rgba[][4])116 sample_lambda_2d (GLcontext * ctx, const struct gl_texture_object *tObj,
117 		  GLuint n, const GLfloat texcoords[][4],
118 		  const GLfloat lambda[], GLchan rgba[][4])
119 {
120   const struct gl_texture_image *tImg = tObj->Image[0][tObj->BaseLevel];
121   GLuint minStart, minEnd;
122   GLuint magStart, magEnd;
123   const GLboolean repeatNoBorderPOT = (tObj->WrapS == 0x2901)
124     && (tImg->_BaseFormat != 0x1900) && tImg->_IsPowerOfTwo;
125   compute_min_mag_ranges (tObj, n, lambda, &minStart, &minEnd, &magStart,
126 			  &magEnd);
127   if (minStart < minEnd)
128     {
129       const GLuint m = minEnd - minStart;
130       switch (tObj->MinFilter)
131 	{
132 	case 0x2600:
133 	  if (repeatNoBorderPOT)
134 	    {
135 		case MESA_FORMAT_RGB:
136 		  opt_sample_rgb_2d (ctx, tObj, m, texcoords + minStart,
137 				     ((void *) 0), rgba + minStart);
138 		case MESA_FORMAT_RGBA:
139 		  opt_sample_rgba_2d (ctx, tObj, m, texcoords + minStart,
140 				      ((void *) 0), rgba + minStart);
141 	    }
142 	    {
143 	      sample_nearest_2d (ctx, tObj, m, texcoords + minStart,
144 				 ((void *) 0), rgba + minStart);
145 	    }
146 	  break;
147 	  sample_2d_nearest_mipmap_linear (ctx, tObj, m, texcoords + minStart,
148 					   lambda + minStart,
149 					   rgba + minStart);
150 	case 0x2703:
151 	  if (repeatNoBorderPOT)
152 	    sample_2d_linear_mipmap_linear_repeat (ctx, tObj, m,
153 						   texcoords + minStart,
154 						   lambda + minStart,
155 						   rgba + minStart);
156 	}
157       switch (tObj->MagFilter)
158 	{
159 		case MESA_FORMAT_RGB:
160 		  opt_sample_rgb_2d (ctx, tObj, m, texcoords + magStart,
161 				     ((void *) 0), rgba + magStart);
162 		  opt_sample_rgba_2d (ctx, tObj, m, texcoords + magStart,
163 				      ((void *) 0), rgba + magStart);
164                   sample_nearest_2d (ctx, tObj, m, texcoords + magStart,
165                                      ((void *) 0), rgba + magStart);
166 	}
167     }
168 }
169 texture_sample_func
_swrast_choose_texture_sample_func(const struct gl_texture_object * t)170 _swrast_choose_texture_sample_func (const struct gl_texture_object *t)
171 {
172       switch (t->Target)
173 	{
174 	case 0x0DE0:
175 	      return &sample_lambda_2d;
176 	}
177 }
178