… | |
… | |
3 | |
3 | |
4 | namespace shader { |
4 | namespace shader { |
5 | |
5 | |
6 | refcounted::~refcounted () |
6 | refcounted::~refcounted () |
7 | { |
7 | { |
8 | #if 0 |
8 | #if 1 |
9 | if (refcnt) |
9 | if (refcnt) |
10 | abort (); |
10 | abort (); |
11 | #endif |
11 | #endif |
|
|
12 | } |
|
|
13 | |
|
|
14 | void refcounted::refcnt_dec () const |
|
|
15 | { |
|
|
16 | if (!--refcnt) |
|
|
17 | delete this; // quite a bit of code... |
12 | } |
18 | } |
13 | |
19 | |
14 | const char str_float [] = "float"; |
20 | const char str_float [] = "float"; |
15 | const char str_vec2 [] = "vec2"; |
21 | const char str_vec2 [] = "vec2"; |
16 | const char str_vec3 [] = "vec3"; |
22 | const char str_vec3 [] = "vec3"; |
… | |
… | |
209 | { |
215 | { |
210 | string src = source (); |
216 | string src = source (); |
211 | const char *sptr = src.data (); |
217 | const char *sptr = src.data (); |
212 | const int slen = src.size (); |
218 | const int slen = src.size (); |
213 | |
219 | |
214 | printf ("SOURCE<%s>\n", src.c_str ()); |
220 | printf ("SOURCE<%s>\n", src.c_str ()); |
215 | abort (); |
|
|
216 | glShaderSourceARB (id, 1, &sptr, &slen); |
221 | glShaderSourceARB (id, 1, &sptr, &slen); |
217 | glCompileShaderARB (id); |
222 | glCompileShaderARB (id); |
218 | |
223 | |
219 | GLint compiled; |
224 | GLint compiled; |
220 | glGetObjectParameterivARB (id, GL_OBJECT_COMPILE_STATUS_ARB, &compiled); |
225 | glGetObjectParameterivARB (id, GL_OBJECT_COMPILE_STATUS_ARB, &compiled); |
… | |
… | |
227 | printf ("INFOLOG<%s>\n", infolog); |
232 | printf ("INFOLOG<%s>\n", infolog); |
228 | abort (); |
233 | abort (); |
229 | } |
234 | } |
230 | } |
235 | } |
231 | |
236 | |
|
|
237 | void sl_func0::begin () const |
|
|
238 | { |
|
|
239 | cur->append_string (name_par); |
|
|
240 | } |
|
|
241 | |
|
|
242 | void sl_func0::comma () const |
|
|
243 | { |
|
|
244 | cur->append (str_comma); |
|
|
245 | } |
|
|
246 | |
|
|
247 | void sl_func0::end () const |
|
|
248 | { |
|
|
249 | str_rpar (); |
|
|
250 | } |
|
|
251 | |
|
|
252 | void sl_float::operator ()() const |
|
|
253 | { |
|
|
254 | char s[20]; |
|
|
255 | sprintf (s, "%g", c); |
|
|
256 | cur->append_string (s); |
|
|
257 | } |
|
|
258 | |
|
|
259 | const sl_convert< ::vec2 >::T sl_convert< ::vec2 >::convert (const ::vec2 &v) |
|
|
260 | { |
|
|
261 | sl_string<60> s; |
|
|
262 | sprintf (s.str, "vec2 (%g, %g)", v.x, v.y); |
|
|
263 | return s; |
|
|
264 | } |
|
|
265 | |
|
|
266 | const sl_convert< ::vec3 >::T sl_convert< ::vec3 >::convert (const ::vec3 &v) |
|
|
267 | { |
|
|
268 | sl_string<80> s; |
|
|
269 | sprintf (s.str, "vec3 (%g, %g, %g)", v.x, v.y, v.z); |
|
|
270 | return s; |
|
|
271 | } |
|
|
272 | |
|
|
273 | const sl_convert< ::vec4 >::T sl_convert< ::vec4 >::convert (const ::vec4 &v) |
|
|
274 | { |
|
|
275 | sl_string<100> s; |
|
|
276 | sprintf (s.str, "vec4 (%g, %g, %g, %g)", v.x, v.y, v.z, v.w); |
|
|
277 | return s; |
|
|
278 | } |
|
|
279 | |
|
|
280 | const fragment_const_string str_2sp (" "); |
|
|
281 | const fragment_const_string str_equal (" = "); |
|
|
282 | const fragment_const_string str_comma (", "); |
|
|
283 | const fragment_const_string str_endl (";\n"); |
|
|
284 | |
232 | const sl_append_const_string str_plus (" + "); |
285 | const sl_append_const_string str_plus (" + "); |
233 | const sl_append_const_string str_minus (" - "); |
286 | const sl_append_const_string str_minus (" - "); |
234 | const sl_append_const_string str_mul (" * "); |
287 | const sl_append_const_string str_mul (" * "); |
235 | const sl_append_const_string str_div (" / "); |
288 | const sl_append_const_string str_div (" / "); |
|
|
289 | const sl_append_const_string str_mod (" % "); |
236 | |
290 | |
|
|
291 | const sl_append_const_string str_lpar ("("); |
237 | const sl_append_const_string str_rpar (")"); |
292 | const sl_append_const_string str_rpar (")"); |
238 | |
293 | |
|
|
294 | void swizzle_mask (sl_string<7> &s, int mask) |
|
|
295 | { |
|
|
296 | static const char channel[4] = { 'x', 'y', 'z', 'w' }; |
|
|
297 | |
|
|
298 | char *str = s.str; |
|
|
299 | |
|
|
300 | *str++ = ')'; |
|
|
301 | *str++ = '.'; |
|
|
302 | |
|
|
303 | while (mask) |
|
|
304 | { |
|
|
305 | int c = mask % 5; |
|
|
306 | mask /= 5; |
|
|
307 | |
|
|
308 | if (c) |
|
|
309 | *str++ = channel[c - 1]; |
|
|
310 | } |
|
|
311 | |
|
|
312 | *str++ = 0; |
|
|
313 | } |
|
|
314 | |
|
|
315 | |
239 | void debdebdebdebug ()//D |
316 | void debdebdebdebug ()//D |
240 | { |
317 | { |
241 | vertex_shader vsh; |
318 | vertex_shader vsh; |
242 | fragment_shader fsh; |
|
|
243 | temp_4f t1, t2; |
|
|
244 | sampler_2d s2d (1); |
|
|
245 | |
319 | |
246 | vsh->start (); |
320 | vsh->start (); |
247 | |
321 | |
248 | temp_4f lightpos; |
322 | temp_4f lightpos; |
249 | temp_3f wpos; |
323 | temp_3f wpos; |
250 | |
324 | |
251 | lightpos = vec4 (10, -10, 0, 1); |
325 | lightpos = vec4 (10, -10, 0, 1); |
|
|
326 | wpos = xyz (gl.model_view_matrix * vin.vertex); |
252 | wpos = gl.model_view_matrix_inverse_transpose * vin.normal; |
327 | vout.position = gl.model_view_matrix_inverse_transpose * vin.vertex; |
253 | vout.position = wpos; |
328 | vout.tex_coord[0] = vin.tex_coord[0]; |
|
|
329 | vout.tex_coord[1] = normalize (lightpos - wpos); |
|
|
330 | vout.tex_coord[2] = normalize (wpos); |
|
|
331 | vout.tex_coord[3] = normalize (xyz (gl.model_view_matrix_inverse_transpose) * vin.normal); |
|
|
332 | vout.tex_coord[4] = normalize (xyz (gl.projection_matrix_inverse_transpose) - wpos); |
254 | |
333 | |
255 | vsh->end (); |
334 | vsh->end (); |
256 | vsh->compile (); |
335 | //vsh->compile (); |
|
|
336 | |
|
|
337 | fragment_shader fsh; |
|
|
338 | |
|
|
339 | fsh->start (); |
|
|
340 | |
|
|
341 | xyz (fout.frag_color) = noise3 (x (fin.frag_coord) * y (fin.frag_coord)); |
|
|
342 | |
|
|
343 | temp_1f spec_expon; |
|
|
344 | spec_expon = 200; |
|
|
345 | |
|
|
346 | fsh->end (); |
|
|
347 | fsh->compile (); |
|
|
348 | |
|
|
349 | //abort (); |
257 | } |
350 | } |
258 | |
351 | |
259 | } |
352 | } |
260 | |
353 | |