2 * Mesa 3-D graphics library
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * \file slang_library_texsample.c
27 * built-in library functions for texture and shadow sampling
34 #include "swrast/s_context.h"
35 #include "slang_library_texsample.h"
37 GLvoid
_slang_library_tex1d (GLfloat bias
, GLfloat s
, GLfloat sampler
, GLfloat
*color
)
39 GET_CURRENT_CONTEXT(ctx
);
40 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
41 GLuint unit
= (GLuint
) sampler
;
43 GLfloat lambda
= bias
;
51 swrast
->TextureSample
[unit
] (ctx
, ctx
->Texture
.Unit
[unit
]._Current
, 1,
52 (const GLfloat (*)[4]) texcoord
, &lambda
, &rgba
);
53 color
[0] = CHAN_TO_FLOAT(rgba
[0]);
54 color
[1] = CHAN_TO_FLOAT(rgba
[1]);
55 color
[2] = CHAN_TO_FLOAT(rgba
[2]);
56 color
[3] = CHAN_TO_FLOAT(rgba
[3]);
59 GLvoid
_slang_library_tex2d (GLfloat bias
, GLfloat s
, GLfloat t
, GLfloat sampler
, GLfloat
*color
)
61 GET_CURRENT_CONTEXT(ctx
);
62 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
63 GLuint unit
= (GLuint
) sampler
;
65 GLfloat lambda
= bias
;
73 swrast
->TextureSample
[unit
] (ctx
, ctx
->Texture
.Unit
[unit
]._Current
, 1,
74 (const GLfloat (*)[4]) texcoord
, &lambda
, &rgba
);
75 color
[0] = CHAN_TO_FLOAT(rgba
[0]);
76 color
[1] = CHAN_TO_FLOAT(rgba
[1]);
77 color
[2] = CHAN_TO_FLOAT(rgba
[2]);
78 color
[3] = CHAN_TO_FLOAT(rgba
[3]);
81 GLvoid
_slang_library_tex3d (GLfloat bias
, GLfloat s
, GLfloat t
, GLfloat r
, GLfloat sampler
,
84 GET_CURRENT_CONTEXT(ctx
);
85 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
86 GLuint unit
= (GLuint
) sampler
;
88 GLfloat lambda
= bias
;
96 swrast
->TextureSample
[unit
] (ctx
, ctx
->Texture
.Unit
[unit
]._Current
, 1,
97 (const GLfloat (*)[4]) texcoord
, &lambda
, &rgba
);
98 color
[0] = CHAN_TO_FLOAT(rgba
[0]);
99 color
[1] = CHAN_TO_FLOAT(rgba
[1]);
100 color
[2] = CHAN_TO_FLOAT(rgba
[2]);
101 color
[3] = CHAN_TO_FLOAT(rgba
[3]);
104 GLvoid
_slang_library_texcube (GLfloat bias
, GLfloat s
, GLfloat t
, GLfloat r
, GLfloat sampler
,
107 GET_CURRENT_CONTEXT(ctx
);
108 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
109 GLuint unit
= (GLuint
) sampler
;
111 GLfloat lambda
= bias
;
119 swrast
->TextureSample
[unit
] (ctx
, ctx
->Texture
.Unit
[unit
]._Current
, 1,
120 (const GLfloat (*)[4]) texcoord
, &lambda
, &rgba
);
121 color
[0] = CHAN_TO_FLOAT(rgba
[0]);
122 color
[1] = CHAN_TO_FLOAT(rgba
[1]);
123 color
[2] = CHAN_TO_FLOAT(rgba
[2]);
124 color
[3] = CHAN_TO_FLOAT(rgba
[3]);
127 GLvoid
_slang_library_shad1d (GLfloat bias
, GLfloat s
, GLfloat t
, GLfloat r
, GLfloat sampler
,
130 GET_CURRENT_CONTEXT(ctx
);
131 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
132 GLuint unit
= (GLuint
) sampler
;
134 GLfloat lambda
= bias
;
142 swrast
->TextureSample
[unit
] (ctx
, ctx
->Texture
.Unit
[unit
]._Current
, 1,
143 (const GLfloat (*)[4]) texcoord
, &lambda
, &rgba
);
144 color
[0] = CHAN_TO_FLOAT(rgba
[0]);
145 color
[1] = CHAN_TO_FLOAT(rgba
[1]);
146 color
[2] = CHAN_TO_FLOAT(rgba
[2]);
147 color
[3] = CHAN_TO_FLOAT(rgba
[3]);
150 GLvoid
_slang_library_shad2d (GLfloat bias
, GLfloat s
, GLfloat t
, GLfloat r
, GLfloat sampler
,
153 GET_CURRENT_CONTEXT(ctx
);
154 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
155 GLuint unit
= (GLuint
) sampler
;
157 GLfloat lambda
= bias
;
165 swrast
->TextureSample
[unit
] (ctx
, ctx
->Texture
.Unit
[unit
]._Current
, 1,
166 (const GLfloat (*)[4]) texcoord
, &lambda
, &rgba
);
167 color
[0] = CHAN_TO_FLOAT(rgba
[0]);
168 color
[1] = CHAN_TO_FLOAT(rgba
[1]);
169 color
[2] = CHAN_TO_FLOAT(rgba
[2]);
170 color
[3] = CHAN_TO_FLOAT(rgba
[3]);