#define LONGSTRING __extension__ in imports.h and use it to silence gcc
[mesa.git] / src / mesa / shader / slang / slang_library_texsample.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25 /**
26 * \file slang_library_texsample.c
27 * built-in library functions for texture and shadow sampling
28 * \author Michal Krol
29 */
30
31 #include "imports.h"
32 #include "context.h"
33 #include "colormac.h"
34 #include "swrast/s_context.h"
35 #include "slang_library_texsample.h"
36
37 GLvoid _slang_library_tex1d (GLfloat bias, GLfloat s, GLfloat sampler, GLfloat *color)
38 {
39 GET_CURRENT_CONTEXT(ctx);
40 SWcontext *swrast = SWRAST_CONTEXT(ctx);
41 GLuint unit = (GLuint) sampler;
42 GLfloat texcoord[4];
43 GLfloat lambda = bias;
44 GLchan rgba[4];
45
46 texcoord[0] = s;
47 texcoord[1] = 0.0f;
48 texcoord[2] = 0.0f;
49 texcoord[3] = 1.0f;
50
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]);
57 }
58
59 GLvoid _slang_library_tex2d (GLfloat bias, GLfloat s, GLfloat t, GLfloat sampler, GLfloat *color)
60 {
61 GET_CURRENT_CONTEXT(ctx);
62 SWcontext *swrast = SWRAST_CONTEXT(ctx);
63 GLuint unit = (GLuint) sampler;
64 GLfloat texcoord[4];
65 GLfloat lambda = bias;
66 GLchan rgba[4];
67
68 texcoord[0] = s;
69 texcoord[1] = t;
70 texcoord[2] = 0.0f;
71 texcoord[3] = 1.0f;
72
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]);
79 }
80
81 GLvoid _slang_library_tex3d (GLfloat bias, GLfloat s, GLfloat t, GLfloat r, GLfloat sampler,
82 GLfloat *color)
83 {
84 GET_CURRENT_CONTEXT(ctx);
85 SWcontext *swrast = SWRAST_CONTEXT(ctx);
86 GLuint unit = (GLuint) sampler;
87 GLfloat texcoord[4];
88 GLfloat lambda = bias;
89 GLchan rgba[4];
90
91 texcoord[0] = s;
92 texcoord[1] = t;
93 texcoord[2] = r;
94 texcoord[3] = 1.0f;
95
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]);
102 }
103
104 GLvoid _slang_library_texcube (GLfloat bias, GLfloat s, GLfloat t, GLfloat r, GLfloat sampler,
105 GLfloat *color)
106 {
107 GET_CURRENT_CONTEXT(ctx);
108 SWcontext *swrast = SWRAST_CONTEXT(ctx);
109 GLuint unit = (GLuint) sampler;
110 GLfloat texcoord[4];
111 GLfloat lambda = bias;
112 GLchan rgba[4];
113
114 texcoord[0] = s;
115 texcoord[1] = t;
116 texcoord[2] = r;
117 texcoord[3] = 1.0f;
118
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]);
125 }
126
127 GLvoid _slang_library_shad1d (GLfloat bias, GLfloat s, GLfloat t, GLfloat r, GLfloat sampler,
128 GLfloat *color)
129 {
130 GET_CURRENT_CONTEXT(ctx);
131 SWcontext *swrast = SWRAST_CONTEXT(ctx);
132 GLuint unit = (GLuint) sampler;
133 GLfloat texcoord[4];
134 GLfloat lambda = bias;
135 GLchan rgba[4];
136
137 texcoord[0] = s;
138 texcoord[1] = t;
139 texcoord[2] = r;
140 texcoord[3] = 1.0f;
141
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]);
148 }
149
150 GLvoid _slang_library_shad2d (GLfloat bias, GLfloat s, GLfloat t, GLfloat r, GLfloat sampler,
151 GLfloat *color)
152 {
153 GET_CURRENT_CONTEXT(ctx);
154 SWcontext *swrast = SWRAST_CONTEXT(ctx);
155 GLuint unit = (GLuint) sampler;
156 GLfloat texcoord[4];
157 GLfloat lambda = bias;
158 GLchan rgba[4];
159
160 texcoord[0] = s;
161 texcoord[1] = t;
162 texcoord[2] = r;
163 texcoord[3] = 1.0f;
164
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]);
171 }
172