silence a bunch of warnings
[mesa.git] / src / mesa / shader / shaderobjects_3dlabs.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 2005-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 shaderobjects_3dlabs.c
27 * shader objects definitions for 3dlabs compiler
28 * \author Michal Krol
29 */
30
31 /* Set this to 1 when we are ready to use 3dlabs' front-end */
32 #define USE_3DLABS_FRONTEND 0
33
34 #include "imports.h"
35 #include "hash.h"
36 #include "shaderobjects.h"
37 #include "shaderobjects_3dlabs.h"
38
39 #if USE_3DLABS_FRONTEND
40 #include "slang_mesa.h"
41 #include "Public/ShaderLang.h"
42 #else
43 #include "slang_link.h"
44 #endif
45
46 struct gl2_unknown_obj
47 {
48 GLuint reference_count;
49 void (* _destructor) (struct gl2_unknown_intf **);
50 };
51
52 struct gl2_unknown_impl
53 {
54 struct gl2_unknown_intf *_vftbl;
55 struct gl2_unknown_obj _obj;
56 };
57
58 static void
59 _unknown_destructor (struct gl2_unknown_intf **intf)
60 {
61 }
62
63 static void
64 _unknown_AddRef (struct gl2_unknown_intf **intf)
65 {
66 struct gl2_unknown_impl *impl = (struct gl2_unknown_impl *) intf;
67
68 impl->_obj.reference_count++;
69 }
70
71 static void
72 _unknown_Release (struct gl2_unknown_intf **intf)
73 {
74 struct gl2_unknown_impl *impl = (struct gl2_unknown_impl *) intf;
75
76 impl->_obj.reference_count--;
77 if (impl->_obj.reference_count == 0)
78 {
79 impl->_obj._destructor (intf);
80 _mesa_free ((void *) intf);
81 }
82 }
83
84 static struct gl2_unknown_intf **
85 _unknown_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
86 {
87 if (uiid == UIID_UNKNOWN)
88 {
89 (**intf).AddRef (intf);
90 return intf;
91 }
92 return NULL;
93 }
94
95 static struct gl2_unknown_intf _unknown_vftbl = {
96 _unknown_AddRef,
97 _unknown_Release,
98 _unknown_QueryInterface
99 };
100
101 static void
102 _unknown_constructor (struct gl2_unknown_impl *impl)
103 {
104 impl->_vftbl = &_unknown_vftbl;
105 impl->_obj.reference_count = 1;
106 impl->_obj._destructor = _unknown_destructor;
107 }
108
109 struct gl2_unkinner_obj
110 {
111 struct gl2_unknown_intf **unkouter;
112 };
113
114 struct gl2_unkinner_impl
115 {
116 struct gl2_unknown_intf *_vftbl;
117 struct gl2_unkinner_obj _obj;
118 };
119
120 static void
121 _unkinner_destructor (struct gl2_unknown_intf **intf)
122 {
123 }
124
125 static void
126 _unkinner_AddRef (struct gl2_unknown_intf **intf)
127 {
128 struct gl2_unkinner_impl *impl = (struct gl2_unkinner_impl *) intf;
129
130 (**impl->_obj.unkouter).AddRef (impl->_obj.unkouter);
131 }
132
133 static void
134 _unkinner_Release (struct gl2_unknown_intf **intf)
135 {
136 struct gl2_unkinner_impl *impl = (struct gl2_unkinner_impl *) intf;
137
138 (**impl->_obj.unkouter).Release (impl->_obj.unkouter);
139 }
140
141 static struct gl2_unknown_intf **
142 _unkinner_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
143 {
144 struct gl2_unkinner_impl *impl = (struct gl2_unkinner_impl *) intf;
145
146 return (**impl->_obj.unkouter).QueryInterface (impl->_obj.unkouter, uiid);
147 }
148
149 static struct gl2_unknown_intf _unkinner_vftbl = {
150 _unkinner_AddRef,
151 _unkinner_Release,
152 _unkinner_QueryInterface
153 };
154
155 static void
156 _unkinner_constructor (struct gl2_unkinner_impl *impl, struct gl2_unknown_intf **outer)
157 {
158 impl->_vftbl = &_unkinner_vftbl;
159 impl->_obj.unkouter = outer;
160 }
161
162 struct gl2_generic_obj
163 {
164 struct gl2_unknown_obj _unknown;
165 GLhandleARB name;
166 GLboolean delete_status;
167 GLcharARB *info_log;
168 };
169
170 struct gl2_generic_impl
171 {
172 struct gl2_generic_intf *_vftbl;
173 struct gl2_generic_obj _obj;
174 };
175
176 static void
177 _generic_destructor (struct gl2_unknown_intf **intf)
178 {
179 GET_CURRENT_CONTEXT(ctx);
180 struct gl2_generic_impl *impl = (struct gl2_generic_impl *) intf;
181
182 _mesa_free ((void *) impl->_obj.info_log);
183
184 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
185 _mesa_HashRemove (ctx->Shared->GL2Objects, impl->_obj.name);
186 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
187
188 _unknown_destructor (intf);
189 }
190
191 static struct gl2_unknown_intf **
192 _generic_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
193 {
194 if (uiid == UIID_GENERIC)
195 {
196 (**intf).AddRef (intf);
197 return intf;
198 }
199 return _unknown_QueryInterface (intf, uiid);
200 }
201
202 static void
203 _generic_Delete (struct gl2_generic_intf **intf)
204 {
205 struct gl2_generic_impl *impl = (struct gl2_generic_impl *) intf;
206
207 if (impl->_obj.delete_status == GL_FALSE)
208 {
209 impl->_obj.delete_status = GL_TRUE;
210 (**intf)._unknown.Release ((struct gl2_unknown_intf **) intf);
211 }
212 }
213
214 static GLhandleARB
215 _generic_GetName (struct gl2_generic_intf **intf)
216 {
217 struct gl2_generic_impl *impl = (struct gl2_generic_impl *) intf;
218
219 return impl->_obj.name;
220 }
221
222 static GLboolean
223 _generic_GetDeleteStatus (struct gl2_generic_intf **intf)
224 {
225 struct gl2_generic_impl *impl = (struct gl2_generic_impl *) intf;
226
227 return impl->_obj.delete_status;
228 }
229
230 static const GLcharARB *
231 _generic_GetInfoLog (struct gl2_generic_intf **intf)
232 {
233 struct gl2_generic_impl *impl = (struct gl2_generic_impl *) intf;
234
235 return impl->_obj.info_log;
236 }
237
238 static struct gl2_generic_intf _generic_vftbl = {
239 {
240 _unknown_AddRef,
241 _unknown_Release,
242 _generic_QueryInterface
243 },
244 _generic_Delete,
245 NULL, /* abstract GetType */
246 _generic_GetName,
247 _generic_GetDeleteStatus,
248 _generic_GetInfoLog
249 };
250
251 static void
252 _generic_constructor (struct gl2_generic_impl *impl)
253 {
254 GET_CURRENT_CONTEXT(ctx);
255
256 _unknown_constructor ((struct gl2_unknown_impl *) impl);
257 impl->_vftbl = &_generic_vftbl;
258 impl->_obj._unknown._destructor = _generic_destructor;
259 impl->_obj.delete_status = GL_FALSE;
260 impl->_obj.info_log = NULL;
261
262 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
263 impl->_obj.name = _mesa_HashFindFreeKeyBlock (ctx->Shared->GL2Objects, 1);
264 _mesa_HashInsert (ctx->Shared->GL2Objects, impl->_obj.name, (void *) impl);
265 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
266 }
267
268 struct gl2_container_obj
269 {
270 struct gl2_generic_obj _generic;
271 struct gl2_generic_intf ***attached;
272 GLuint attached_count;
273 };
274
275 struct gl2_container_impl
276 {
277 struct gl2_container_intf *_vftbl;
278 struct gl2_container_obj _obj;
279 };
280
281 static void
282 _container_destructor (struct gl2_unknown_intf **intf)
283 {
284 struct gl2_container_impl *impl = (struct gl2_container_impl *) intf;
285 GLuint i;
286
287 for (i = 0; i < impl->_obj.attached_count; i++)
288 {
289 struct gl2_generic_intf **x = impl->_obj.attached[i];
290 (**x)._unknown.Release ((struct gl2_unknown_intf **) x);
291 }
292
293 _generic_destructor (intf);
294 }
295
296 static struct gl2_unknown_intf **
297 _container_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
298 {
299 if (uiid == UIID_CONTAINER)
300 {
301 (**intf).AddRef (intf);
302 return intf;
303 }
304 return _generic_QueryInterface (intf, uiid);
305 }
306
307 static GLboolean
308 _container_Attach (struct gl2_container_intf **intf, struct gl2_generic_intf **att)
309 {
310 GET_CURRENT_CONTEXT(ctx);
311 struct gl2_container_impl *impl = (struct gl2_container_impl *) intf;
312 GLuint i;
313
314 for (i = 0; i < impl->_obj.attached_count; i++)
315 if (impl->_obj.attached[i] == att)
316 {
317 _mesa_error (ctx, GL_INVALID_OPERATION, "_container_Attach");
318 return GL_FALSE;
319 }
320
321 impl->_obj.attached = (struct gl2_generic_intf ***) _mesa_realloc (impl->_obj.attached,
322 impl->_obj.attached_count * sizeof (*impl->_obj.attached), (impl->_obj.attached_count + 1) *
323 sizeof (*impl->_obj.attached));
324 if (impl->_obj.attached == NULL)
325 return GL_FALSE;
326
327 impl->_obj.attached[impl->_obj.attached_count] = att;
328 impl->_obj.attached_count++;
329 (**att)._unknown.AddRef ((struct gl2_unknown_intf **) att);
330 return GL_TRUE;
331 }
332
333 static GLboolean
334 _container_Detach (struct gl2_container_intf **intf, struct gl2_generic_intf **att)
335 {
336 GET_CURRENT_CONTEXT(ctx);
337 struct gl2_container_impl *impl = (struct gl2_container_impl *) intf;
338 GLuint i, j;
339
340 for (i = 0; i < impl->_obj.attached_count; i++)
341 if (impl->_obj.attached[i] == att)
342 {
343 for (j = i; j < impl->_obj.attached_count - 1; j++)
344 impl->_obj.attached[j] = impl->_obj.attached[j + 1];
345 impl->_obj.attached = (struct gl2_generic_intf ***) _mesa_realloc (impl->_obj.attached,
346 impl->_obj.attached_count * sizeof (*impl->_obj.attached),
347 (impl->_obj.attached_count - 1) * sizeof (*impl->_obj.attached));
348 impl->_obj.attached_count--;
349 (**att)._unknown.Release ((struct gl2_unknown_intf **) att);
350 return GL_TRUE;
351 }
352
353 _mesa_error (ctx, GL_INVALID_OPERATION, "_container_Detach");
354 return GL_FALSE;
355 }
356
357 static GLsizei
358 _container_GetAttachedCount (struct gl2_container_intf **intf)
359 {
360 struct gl2_container_impl *impl = (struct gl2_container_impl *) intf;
361
362 return impl->_obj.attached_count;
363 }
364
365 static struct gl2_generic_intf **
366 _container_GetAttached (struct gl2_container_intf **intf, GLuint index)
367 {
368 struct gl2_container_impl *impl = (struct gl2_container_impl *) intf;
369
370 (**impl->_obj.attached[index])._unknown.AddRef (
371 (struct gl2_unknown_intf **)impl->_obj.attached[index]);
372 return impl->_obj.attached[index];
373 }
374
375 static struct gl2_container_intf _container_vftbl = {
376 {
377 {
378 _unknown_AddRef,
379 _unknown_Release,
380 _container_QueryInterface
381 },
382 _generic_Delete,
383 NULL, /* abstract GetType */
384 _generic_GetName,
385 _generic_GetDeleteStatus,
386 _generic_GetInfoLog
387 },
388 _container_Attach,
389 _container_Detach,
390 _container_GetAttachedCount,
391 _container_GetAttached
392 };
393
394 static void
395 _container_constructor (struct gl2_container_impl *impl)
396 {
397 _generic_constructor ((struct gl2_generic_impl *) impl);
398 impl->_vftbl = &_container_vftbl;
399 impl->_obj._generic._unknown._destructor = _container_destructor;
400 impl->_obj.attached = NULL;
401 impl->_obj.attached_count = 0;
402 }
403
404 struct gl2_3dlabs_shhandle_obj
405 {
406 struct gl2_unkinner_obj _unknown;
407 #if USE_3DLABS_FRONTEND
408 ShHandle handle;
409 #endif
410 };
411
412 struct gl2_3dlabs_shhandle_impl
413 {
414 struct gl2_3dlabs_shhandle_intf *_vftbl;
415 struct gl2_3dlabs_shhandle_obj _obj;
416 };
417
418 static void
419 _3dlabs_shhandle_destructor (struct gl2_unknown_intf **intf)
420 {
421 #if USE_3DLABS_FRONTEND
422 struct gl2_3dlabs_shhandle_impl *impl = (struct gl2_3dlabs_shhandle_impl *) intf;
423 ShDestruct (impl->_obj.handle);
424 #endif
425 _unkinner_destructor (intf);
426 }
427
428 static GLvoid *
429 _3dlabs_shhandle_GetShHandle (struct gl2_3dlabs_shhandle_intf **intf)
430 {
431 #if USE_3DLABS_FRONTEND
432 struct gl2_3dlabs_shhandle_impl *impl = (struct gl2_3dlabs_shhandle_impl *) intf;
433 return impl->_obj.handle;
434 #else
435 return NULL;
436 #endif
437 }
438
439 static struct gl2_3dlabs_shhandle_intf _3dlabs_shhandle_vftbl = {
440 {
441 _unkinner_AddRef,
442 _unkinner_Release,
443 _unkinner_QueryInterface
444 },
445 _3dlabs_shhandle_GetShHandle
446 };
447
448 static void
449 _3dlabs_shhandle_constructor (struct gl2_3dlabs_shhandle_impl *impl, struct gl2_unknown_intf **outer)
450 {
451 _unkinner_constructor ((struct gl2_unkinner_impl *) impl, outer);
452 impl->_vftbl = &_3dlabs_shhandle_vftbl;
453 #if USE_3DLABS_FRONTEND
454 impl->_obj.handle = NULL;
455 #endif
456 }
457
458 struct gl2_shader_obj
459 {
460 struct gl2_generic_obj _generic;
461 struct gl2_3dlabs_shhandle_impl _3dlabs_shhandle;
462 GLboolean compile_status;
463 GLcharARB *source;
464 GLint *offsets;
465 GLsizei offset_count;
466 slang_translation_unit unit;
467 };
468
469 struct gl2_shader_impl
470 {
471 struct gl2_shader_intf *_vftbl;
472 struct gl2_shader_obj _obj;
473 };
474
475 static void
476 _shader_destructor (struct gl2_unknown_intf **intf)
477 {
478 struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;
479
480 _mesa_free ((void *) impl->_obj.source);
481 _mesa_free ((void *) impl->_obj.offsets);
482 _3dlabs_shhandle_destructor ((struct gl2_unknown_intf **) &impl->_obj._3dlabs_shhandle._vftbl);
483 _generic_destructor (intf);
484 }
485
486 static struct gl2_unknown_intf **
487 _shader_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
488 {
489 #if USE_3DLABS_FRONTEND
490 struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;
491 #endif
492
493 if (uiid == UIID_SHADER)
494 {
495 (**intf).AddRef (intf);
496 return intf;
497 }
498 #if USE_3DLABS_FRONTEND
499 if (uiid == UIID_3DLABS_SHHANDLE)
500 {
501 (**intf).AddRef (intf);
502 return (struct gl2_unknown_intf **) &impl->_obj._3dlabs_shhandle._vftbl;
503 }
504 #endif
505 return _generic_QueryInterface (intf, uiid);
506 }
507
508 static GLenum
509 _shader_GetType (struct gl2_generic_intf **intf)
510 {
511 return GL_SHADER_OBJECT_ARB;
512 }
513
514 static GLboolean
515 _shader_GetCompileStatus (struct gl2_shader_intf **intf)
516 {
517 struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;
518
519 return impl->_obj.compile_status;
520 }
521
522 static GLvoid
523 _shader_SetSource (struct gl2_shader_intf **intf, GLcharARB *src, GLint *off, GLsizei cnt)
524 {
525 struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;
526
527 _mesa_free ((void *) impl->_obj.source);
528 impl->_obj.source = src;
529 _mesa_free ((void *) impl->_obj.offsets);
530 impl->_obj.offsets = off;
531 impl->_obj.offset_count = cnt;
532 }
533
534 static const GLcharARB *
535 _shader_GetSource (struct gl2_shader_intf **intf)
536 {
537 struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;
538
539 return impl->_obj.source;
540 }
541
542 static GLvoid
543 _shader_Compile (struct gl2_shader_intf **intf)
544 {
545 struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;
546 #if USE_3DLABS_FRONTEND
547 char **strings;
548 TBuiltInResource res;
549 #else
550 slang_unit_type type;
551 slang_info_log info_log;
552 #endif
553
554 impl->_obj.compile_status = GL_FALSE;
555 _mesa_free ((void *) impl->_obj._generic.info_log);
556 impl->_obj._generic.info_log = NULL;
557
558 #if USE_3DLABS_FRONTEND
559 /* 3dlabs compiler expects us to feed it with null-terminated string array,
560 we've got only one big string with offsets, so we must split it; but when
561 there's only one string to deal with, we pass its address directly */
562
563 if (impl->_obj.offset_count <= 1)
564 strings = &impl->_obj.source;
565 else
566 {
567 GLsizei i, offset = 0;
568
569 strings = (char **) _mesa_malloc (impl->_obj.offset_count * sizeof (char *));
570 if (strings == NULL)
571 return;
572
573 for (i = 0; i < impl->_obj.offset_count; i++)
574 {
575 GLsizei size = impl->_obj.offsets[i] - offset;
576
577 strings[i] = (char *) _mesa_malloc ((size + 1) * sizeof (char));
578 if (strings[i] == NULL)
579 {
580 GLsizei j;
581
582 for (j = 0; j < i; j++)
583 _mesa_free (strings[j]);
584 _mesa_free (strings);
585 return;
586 }
587
588 _mesa_memcpy (strings[i], impl->_obj.source + offset, size * sizeof (char));
589 strings[i][size] = '\0';
590 offset = impl->_obj.offsets[i];
591 }
592 }
593
594 /* TODO set these fields to some REAL numbers */
595 res.maxLights = 8;
596 res.maxClipPlanes = 6;
597 res.maxTextureUnits = 2;
598 res.maxTextureCoords = 2;
599 res.maxVertexAttribs = 8;
600 res.maxVertexUniformComponents = 64;
601 res.maxVaryingFloats = 8;
602 res.maxVertexTextureImageUnits = 2;
603 res.maxCombinedTextureImageUnits = 2;
604 res.maxTextureImageUnits = 2;
605 res.maxFragmentUniformComponents = 64;
606 res.maxDrawBuffers = 1;
607
608 if (ShCompile (impl->_obj._3dlabs_shhandle._obj.handle, strings, impl->_obj.offset_count,
609 EShOptFull, &res, 0))
610 impl->_obj.compile_status = GL_TRUE;
611 if (impl->_obj.offset_count > 1)
612 {
613 GLsizei i;
614
615 for (i = 0; i < impl->_obj.offset_count; i++)
616 _mesa_free (strings[i]);
617 _mesa_free (strings);
618 }
619
620 impl->_obj._generic.info_log = _mesa_strdup (ShGetInfoLog (
621 impl->_obj._3dlabs_shhandle._obj.handle));
622 #else
623 if (impl->_vftbl->GetSubType (intf) == GL_FRAGMENT_SHADER)
624 type = slang_unit_fragment_shader;
625 else
626 type = slang_unit_vertex_shader;
627 slang_info_log_construct (&info_log);
628 if (_slang_compile (impl->_obj.source, &impl->_obj.unit, type, &info_log))
629 {
630 impl->_obj.compile_status = GL_TRUE;
631 }
632 if (info_log.text != NULL)
633 impl->_obj._generic.info_log = _mesa_strdup (info_log.text);
634 else
635 impl->_obj._generic.info_log = _mesa_strdup ("");
636 slang_info_log_destruct (&info_log);
637 #endif
638 }
639
640 static struct gl2_shader_intf _shader_vftbl = {
641 {
642 {
643 _unknown_AddRef,
644 _unknown_Release,
645 _shader_QueryInterface
646 },
647 _generic_Delete,
648 _shader_GetType,
649 _generic_GetName,
650 _generic_GetDeleteStatus,
651 _generic_GetInfoLog
652 },
653 NULL, /* abstract GetSubType */
654 _shader_GetCompileStatus,
655 _shader_SetSource,
656 _shader_GetSource,
657 _shader_Compile
658 };
659
660 static void
661 _shader_constructor (struct gl2_shader_impl *impl)
662 {
663 _generic_constructor ((struct gl2_generic_impl *) impl);
664 _3dlabs_shhandle_constructor (&impl->_obj._3dlabs_shhandle, (struct gl2_unknown_intf **)
665 &impl->_vftbl);
666 impl->_vftbl = &_shader_vftbl;
667 impl->_obj._generic._unknown._destructor = _shader_destructor;
668 impl->_obj.compile_status = GL_FALSE;
669 impl->_obj.source = NULL;
670 impl->_obj.offsets = NULL;
671 impl->_obj.offset_count = 0;
672 }
673
674 struct gl2_program_obj
675 {
676 struct gl2_container_obj _container;
677 GLboolean link_status;
678 GLboolean validate_status;
679 #if USE_3DLABS_FRONTEND
680 ShHandle linker;
681 ShHandle uniforms;
682 #endif
683 slang_program prog;
684 };
685
686 struct gl2_program_impl
687 {
688 struct gl2_program_intf *_vftbl;
689 struct gl2_program_obj _obj;
690 };
691
692 static void
693 _program_destructor (struct gl2_unknown_intf **intf)
694 {
695 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
696 #if USE_3DLABS_FRONTEND
697 ShDestruct (impl->_obj.linker);
698 ShDestruct (impl->_obj.uniforms);
699 #endif
700 _container_destructor (intf);
701 slang_program_dtr (&impl->_obj.prog);
702 }
703
704 static struct gl2_unknown_intf **
705 _program_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
706 {
707 if (uiid == UIID_PROGRAM)
708 {
709 (**intf).AddRef (intf);
710 return intf;
711 }
712 return _container_QueryInterface (intf, uiid);
713 }
714
715 static GLenum
716 _program_GetType (struct gl2_generic_intf **intf)
717 {
718 return GL_PROGRAM_OBJECT_ARB;
719 }
720
721 static GLboolean
722 _program_Attach (struct gl2_container_intf **intf, struct gl2_generic_intf **att)
723 {
724 GET_CURRENT_CONTEXT(ctx);
725 struct gl2_unknown_intf **sha;
726
727 sha = (**att)._unknown.QueryInterface ((struct gl2_unknown_intf **) att, UIID_SHADER);
728 if (sha == NULL)
729 {
730 _mesa_error (ctx, GL_INVALID_OPERATION, "_program_Attach");
731 return GL_FALSE;
732 }
733
734 (**sha).Release (sha);
735 return _container_Attach (intf, att);
736 }
737
738 static GLboolean
739 _program_GetLinkStatus (struct gl2_program_intf **intf)
740 {
741 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
742
743 return impl->_obj.link_status;
744 }
745
746 static GLboolean
747 _program_GetValidateStatus (struct gl2_program_intf **intf)
748 {
749 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
750
751 return impl->_obj.validate_status;
752 }
753
754 static GLvoid
755 _program_Link (struct gl2_program_intf **intf)
756 {
757 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
758 #if USE_3DLABS_FRONTEND
759 ShHandle *handles;
760 #endif
761 GLuint i, count;
762 slang_translation_unit *units[2];
763
764 impl->_obj.link_status = GL_FALSE;
765 _mesa_free ((void *) impl->_obj._container._generic.info_log);
766 impl->_obj._container._generic.info_log = NULL;
767 slang_program_dtr (&impl->_obj.prog);
768 slang_program_ctr (&impl->_obj.prog);
769
770 #if USE_3DLABS_FRONTEND
771 handles = (ShHandle *) _mesa_malloc (impl->_obj._container.attached_count * sizeof (ShHandle));
772 if (handles == NULL)
773 return;
774
775 for (i = 0; i < impl->_obj._container.attached_count; i++)
776 {
777 struct gl2_generic_intf **gen = impl->_obj._container.attached[i];
778 struct gl2_3dlabs_shhandle_intf **sh;
779
780 sh = (struct gl2_3dlabs_shhandle_intf **) (**gen)._unknown.QueryInterface (
781 (struct gl2_unknown_intf **) gen, UIID_3DLABS_SHHANDLE);
782 if (sh != NULL)
783 {
784 handles[i] = (**sh).GetShHandle (sh);
785 (**sh)._unknown.Release ((struct gl2_unknown_intf **) sh);
786 }
787 else
788 {
789 _mesa_free (handles);
790 return;
791 }
792 }
793
794 if (ShLink (impl->_obj.linker, handles, impl->_obj._container.attached_count,
795 impl->_obj.uniforms, NULL, NULL))
796 impl->_obj.link_status = GL_TRUE;
797
798 impl->_obj._container._generic.info_log = _mesa_strdup (ShGetInfoLog (impl->_obj.linker));
799 #else
800 count = impl->_obj._container.attached_count;
801 if (count == 0 || count > 2)
802 return;
803 for (i = 0; i < count; i++)
804 {
805 struct gl2_generic_intf **obj;
806 struct gl2_unknown_intf **unk;
807 struct gl2_shader_impl *sha;
808
809 obj = impl->_obj._container.attached[i];
810 unk = (**obj)._unknown.QueryInterface ((struct gl2_unknown_intf **) obj, UIID_SHADER);
811 (**obj)._unknown.Release ((struct gl2_unknown_intf **) obj);
812 if (unk == NULL)
813 return;
814 sha = (struct gl2_shader_impl *) unk;
815 units[i] = &sha->_obj.unit;
816 (**unk).Release (unk);
817 }
818
819 impl->_obj.link_status = _slang_link (&impl->_obj.prog, units, count);
820 if (impl->_obj.link_status)
821 impl->_obj._container._generic.info_log = _mesa_strdup ("Link OK.\n");
822 else
823 impl->_obj._container._generic.info_log = _mesa_strdup ("Link failed.\n");
824 #endif
825 }
826
827 static GLvoid
828 _program_Validate (struct gl2_program_intf **intf)
829 {
830 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
831
832 impl->_obj.validate_status = GL_FALSE;
833 _mesa_free ((void *) impl->_obj._container._generic.info_log);
834 impl->_obj._container._generic.info_log = NULL;
835
836 /* TODO validate */
837 }
838
839 static GLvoid
840 write_common_fixed (slang_program *pro, GLuint index, const GLvoid *src, GLuint off, GLuint size)
841 {
842 GLuint i;
843
844 for (i = 0; i < SLANG_UNIFORM_BINDING_MAX; i++)
845 {
846 GLuint addr;
847
848 addr = pro->common_fixed_entries[i][index];
849 if (addr != ~0)
850 {
851 GLubyte *dst;
852
853 dst = (GLubyte *) pro->machines[i]->mem + addr + off * size;
854 _mesa_memcpy (dst, src, size);
855 }
856 }
857 }
858
859 static GLvoid
860 write_common_fixed_mat4 (slang_program *pro, GLmatrix *matrix, GLuint off, GLuint i, GLuint ii,
861 GLuint it, GLuint iit)
862 {
863 GLfloat mat[16];
864
865 /* we want inverse matrix */
866 if (!matrix->inv)
867 {
868 /* allocate inverse matrix and make it dirty */
869 _math_matrix_alloc_inv (matrix);
870 _math_matrix_loadf (matrix, matrix->m);
871 }
872 _math_matrix_analyse (matrix);
873
874 write_common_fixed (pro, i, matrix->m, off, 16 * sizeof (GLfloat));
875
876 /* inverse */
877 write_common_fixed (pro, ii, matrix->inv, off, 16 * sizeof (GLfloat));
878
879 /* transpose */
880 _math_transposef (mat, matrix->m);
881 write_common_fixed (pro, it, mat, off, 16 * sizeof (GLfloat));
882
883 /* inverse transpose */
884 _math_transposef (mat, matrix->inv);
885 write_common_fixed (pro, iit, mat, off, 16 * sizeof (GLfloat));
886 }
887
888 static GLvoid
889 _program_UpdateFixedUniforms (struct gl2_program_intf **intf)
890 {
891 GET_CURRENT_CONTEXT(ctx);
892 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
893 slang_program *pro = &impl->_obj.prog;
894 GLuint i;
895 GLfloat v[9];
896 GLfloat *p;
897
898 /* MODELVIEW matrix */
899 write_common_fixed_mat4 (pro, ctx->ModelviewMatrixStack.Top, 0,
900 SLANG_COMMON_FIXED_MODELVIEWMATRIX,
901 SLANG_COMMON_FIXED_MODELVIEWMATRIXINVERSE,
902 SLANG_COMMON_FIXED_MODELVIEWMATRIXTRANSPOSE,
903 SLANG_COMMON_FIXED_MODELVIEWMATRIXINVERSETRANSPOSE);
904
905 /* PROJECTION matrix */
906 write_common_fixed_mat4 (pro, ctx->ProjectionMatrixStack.Top, 0,
907 SLANG_COMMON_FIXED_PROJECTIONMATRIX,
908 SLANG_COMMON_FIXED_PROJECTIONMATRIXINVERSE,
909 SLANG_COMMON_FIXED_PROJECTIONMATRIXTRANSPOSE,
910 SLANG_COMMON_FIXED_PROJECTIONMATRIXINVERSETRANSPOSE);
911
912 /* MVP matrix */
913 write_common_fixed_mat4 (pro, &ctx->_ModelProjectMatrix, 0,
914 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIX,
915 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXINVERSE,
916 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXTRANSPOSE,
917 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXINVERSETRANSPOSE);
918
919 /* TEXTURE matrix */
920 for (i = 0; i < 8; i++)
921 {
922 write_common_fixed_mat4 (pro, ctx->TextureMatrixStack[i].Top, i,
923 SLANG_COMMON_FIXED_TEXTUREMATRIX,
924 SLANG_COMMON_FIXED_TEXTUREMATRIXINVERSE,
925 SLANG_COMMON_FIXED_TEXTUREMATRIXTRANSPOSE,
926 SLANG_COMMON_FIXED_TEXTUREMATRIXINVERSETRANSPOSE);
927 }
928
929 /* NORMAL matrix - upper 3x3 inverse transpose of MODELVIEW matrix */
930 p = ctx->ModelviewMatrixStack.Top->inv;
931 v[0] = p[0];
932 v[1] = p[4];
933 v[2] = p[8];
934 v[3] = p[1];
935 v[4] = p[5];
936 v[5] = p[9];
937 v[6] = p[2];
938 v[7] = p[6];
939 v[8] = p[10];
940 write_common_fixed (pro, SLANG_COMMON_FIXED_NORMALMATRIX, v, 0, 9 * sizeof (GLfloat));
941
942 /* XXX: fetch uniform float gl_NormalScale */
943 /* XXX: fetch uniform mat4 gl_ClipPlane */
944 /* XXX: fetch uniform mat4 gl_TextureEnvColor */
945 /* XXX: fetch uniform mat4 gl_EyePlaneS */
946 /* XXX: fetch uniform mat4 gl_EyePlaneT */
947 /* XXX: fetch uniform mat4 gl_EyePlaneR */
948 /* XXX: fetch uniform mat4 gl_EyePlaneQ */
949 /* XXX: fetch uniform mat4 gl_ObjectPlaneS */
950 /* XXX: fetch uniform mat4 gl_ObjectPlaneT */
951 /* XXX: fetch uniform mat4 gl_ObjectPlaneR */
952 /* XXX: fetch uniform mat4 gl_ObjectPlaneQ */
953 }
954
955 static GLvoid
956 _program_UpdateFixedAttribute (struct gl2_program_intf **intf, GLuint index, GLvoid *data,
957 GLuint offset, GLuint size, GLboolean write)
958 {
959 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
960 slang_program *pro = &impl->_obj.prog;
961 GLuint addr;
962
963 addr = pro->vertex_fixed_entries[index];
964 if (addr != ~0)
965 {
966 GLubyte *mem;
967
968 mem = (GLubyte *) pro->machines[SLANG_UNIFORM_BINDING_VERTEX]->mem + addr + offset * size;
969 if (write)
970 _mesa_memcpy (mem, data, size);
971 else
972 _mesa_memcpy (data, mem, size);
973 }
974 }
975
976 static GLvoid
977 _program_UpdateFixedVarying (struct gl2_program_intf **intf, GLuint index, GLvoid *data,
978 GLuint offset, GLuint size, GLboolean write)
979 {
980 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
981 slang_program *pro = &impl->_obj.prog;
982 GLuint addr;
983
984 addr = pro->fragment_fixed_entries[index];
985 if (addr != ~0)
986 {
987 GLubyte *mem;
988
989 mem = (GLubyte *) pro->machines[SLANG_UNIFORM_BINDING_FRAGMENT]->mem + addr + offset * size;
990 if (write)
991 _mesa_memcpy (mem, data, size);
992 else
993 _mesa_memcpy (data, mem, size);
994 }
995 }
996
997 static struct gl2_program_intf _program_vftbl = {
998 {
999 {
1000 {
1001 _unknown_AddRef,
1002 _unknown_Release,
1003 _program_QueryInterface
1004 },
1005 _generic_Delete,
1006 _program_GetType,
1007 _generic_GetName,
1008 _generic_GetDeleteStatus,
1009 _generic_GetInfoLog
1010 },
1011 _program_Attach,
1012 _container_Detach,
1013 _container_GetAttachedCount,
1014 _container_GetAttached
1015 },
1016 _program_GetLinkStatus,
1017 _program_GetValidateStatus,
1018 _program_Link,
1019 _program_Validate,
1020 _program_UpdateFixedUniforms,
1021 _program_UpdateFixedAttribute,
1022 _program_UpdateFixedVarying
1023 };
1024
1025 static void
1026 _program_constructor (struct gl2_program_impl *impl)
1027 {
1028 _container_constructor ((struct gl2_container_impl *) impl);
1029 impl->_vftbl = &_program_vftbl;
1030 impl->_obj._container._generic._unknown._destructor = _program_destructor;
1031 impl->_obj.link_status = GL_FALSE;
1032 impl->_obj.validate_status = GL_FALSE;
1033 #if USE_3DLABS_FRONTEND
1034 impl->_obj.linker = ShConstructLinker (EShExVertexFragment, 0);
1035 impl->_obj.uniforms = ShConstructUniformMap ();
1036 #endif
1037 slang_program_ctr (&impl->_obj.prog);
1038 }
1039
1040 struct gl2_fragment_shader_obj
1041 {
1042 struct gl2_shader_obj _shader;
1043 };
1044
1045 struct gl2_fragment_shader_impl
1046 {
1047 struct gl2_fragment_shader_intf *_vftbl;
1048 struct gl2_fragment_shader_obj _obj;
1049 };
1050
1051 static void
1052 _fragment_shader_destructor (struct gl2_unknown_intf **intf)
1053 {
1054 struct gl2_fragment_shader_impl *impl = (struct gl2_fragment_shader_impl *) intf;
1055
1056 (void) impl;
1057 /* TODO free fragment shader data */
1058
1059 _shader_destructor (intf);
1060 }
1061
1062 static struct gl2_unknown_intf **
1063 _fragment_shader_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
1064 {
1065 if (uiid == UIID_FRAGMENT_SHADER)
1066 {
1067 (**intf).AddRef (intf);
1068 return intf;
1069 }
1070 return _shader_QueryInterface (intf, uiid);
1071 }
1072
1073 static GLenum
1074 _fragment_shader_GetSubType (struct gl2_shader_intf **intf)
1075 {
1076 return GL_FRAGMENT_SHADER_ARB;
1077 }
1078
1079 static struct gl2_fragment_shader_intf _fragment_shader_vftbl = {
1080 {
1081 {
1082 {
1083 _unknown_AddRef,
1084 _unknown_Release,
1085 _fragment_shader_QueryInterface
1086 },
1087 _generic_Delete,
1088 _shader_GetType,
1089 _generic_GetName,
1090 _generic_GetDeleteStatus,
1091 _generic_GetInfoLog
1092 },
1093 _fragment_shader_GetSubType,
1094 _shader_GetCompileStatus,
1095 _shader_SetSource,
1096 _shader_GetSource,
1097 _shader_Compile
1098 }
1099 };
1100
1101 static void
1102 _fragment_shader_constructor (struct gl2_fragment_shader_impl *impl)
1103 {
1104 _shader_constructor ((struct gl2_shader_impl *) impl);
1105 impl->_vftbl = &_fragment_shader_vftbl;
1106 impl->_obj._shader._generic._unknown._destructor = _fragment_shader_destructor;
1107 #if USE_3DLABS_FRONTEND
1108 impl->_obj._shader._3dlabs_shhandle._obj.handle = ShConstructCompiler (EShLangFragment, 0);
1109 #endif
1110 }
1111
1112 struct gl2_vertex_shader_obj
1113 {
1114 struct gl2_shader_obj _shader;
1115 };
1116
1117 struct gl2_vertex_shader_impl
1118 {
1119 struct gl2_vertex_shader_intf *_vftbl;
1120 struct gl2_vertex_shader_obj _obj;
1121 };
1122
1123 static void
1124 _vertex_shader_destructor (struct gl2_unknown_intf **intf)
1125 {
1126 struct gl2_vertex_shader_impl *impl = (struct gl2_vertex_shader_impl *) intf;
1127
1128 (void) impl;
1129 /* TODO free vertex shader data */
1130
1131 _shader_destructor (intf);
1132 }
1133
1134 static struct gl2_unknown_intf **
1135 _vertex_shader_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
1136 {
1137 if (uiid == UIID_VERTEX_SHADER)
1138 {
1139 (**intf).AddRef (intf);
1140 return intf;
1141 }
1142 return _shader_QueryInterface (intf, uiid);
1143 }
1144
1145 static GLenum
1146 _vertex_shader_GetSubType (struct gl2_shader_intf **intf)
1147 {
1148 return GL_VERTEX_SHADER_ARB;
1149 }
1150
1151 static struct gl2_vertex_shader_intf _vertex_shader_vftbl = {
1152 {
1153 {
1154 {
1155 _unknown_AddRef,
1156 _unknown_Release,
1157 _vertex_shader_QueryInterface
1158 },
1159 _generic_Delete,
1160 _shader_GetType,
1161 _generic_GetName,
1162 _generic_GetDeleteStatus,
1163 _generic_GetInfoLog
1164 },
1165 _vertex_shader_GetSubType,
1166 _shader_GetCompileStatus,
1167 _shader_SetSource,
1168 _shader_GetSource,
1169 _shader_Compile
1170 }
1171 };
1172
1173 static void
1174 _vertex_shader_constructor (struct gl2_vertex_shader_impl *impl)
1175 {
1176 _shader_constructor ((struct gl2_shader_impl *) impl);
1177 impl->_vftbl = &_vertex_shader_vftbl;
1178 impl->_obj._shader._generic._unknown._destructor = _vertex_shader_destructor;
1179 #if USE_3DLABS_FRONTEND
1180 impl->_obj._shader._3dlabs_shhandle._obj.handle = ShConstructCompiler (EShLangVertex, 0);
1181 #endif
1182 }
1183
1184 GLhandleARB
1185 _mesa_3dlabs_create_shader_object (GLenum shaderType)
1186 {
1187 switch (shaderType)
1188 {
1189 case GL_FRAGMENT_SHADER_ARB:
1190 {
1191 struct gl2_fragment_shader_impl *x = (struct gl2_fragment_shader_impl *)
1192 _mesa_malloc (sizeof (struct gl2_fragment_shader_impl));
1193
1194 if (x != NULL)
1195 {
1196 _fragment_shader_constructor (x);
1197 return x->_obj._shader._generic.name;
1198 }
1199 }
1200 break;
1201 case GL_VERTEX_SHADER_ARB:
1202 {
1203 struct gl2_vertex_shader_impl *x = (struct gl2_vertex_shader_impl *)
1204 _mesa_malloc (sizeof (struct gl2_vertex_shader_impl));
1205
1206 if (x != NULL)
1207 {
1208 _vertex_shader_constructor (x);
1209 return x->_obj._shader._generic.name;
1210 }
1211 }
1212 break;
1213 }
1214
1215 return 0;
1216 }
1217
1218 GLhandleARB
1219 _mesa_3dlabs_create_program_object (void)
1220 {
1221 struct gl2_program_impl *x = (struct gl2_program_impl *)
1222 _mesa_malloc (sizeof (struct gl2_program_impl));
1223
1224 if (x != NULL)
1225 {
1226 _program_constructor (x);
1227 return x->_obj._container._generic.name;
1228 }
1229
1230 return 0;
1231 }
1232
1233 #include "slang_assemble.h"
1234 #include "slang_execute.h"
1235
1236 int _slang_fetch_discard (struct gl2_program_intf **pro, GLboolean *val)
1237 {
1238 struct gl2_program_impl *impl;
1239
1240 impl = (struct gl2_program_impl *) pro;
1241 *val = impl->_obj.prog.machines[SLANG_UNIFORM_BINDING_FRAGMENT]->kill ? GL_TRUE : GL_FALSE;
1242 return 1;
1243 }
1244
1245 static GLvoid exec_shader (struct gl2_program_intf **pro, GLuint i)
1246 {
1247 struct gl2_program_impl *impl;
1248 slang_program *p;
1249
1250 impl = (struct gl2_program_impl *) pro;
1251 p = &impl->_obj.prog;
1252
1253 slang_machine_init (p->machines[i]);
1254 p->machines[i]->ip = p->code[i];
1255
1256 _slang_execute2 (p->assemblies[i], p->machines[i]);
1257 }
1258
1259 GLvoid _slang_exec_fragment_shader (struct gl2_program_intf **pro)
1260 {
1261 exec_shader (pro, SLANG_UNIFORM_BINDING_FRAGMENT);
1262 }
1263
1264 GLvoid _slang_exec_vertex_shader (struct gl2_program_intf **pro)
1265 {
1266 exec_shader (pro, SLANG_UNIFORM_BINDING_VERTEX);
1267 }
1268
1269 GLint _slang_get_uniform_location (struct gl2_program_intf **pro, const char *name)
1270 {
1271 struct gl2_program_impl *impl;
1272 slang_uniform_bindings *bind;
1273 GLuint i;
1274
1275 impl = (struct gl2_program_impl *) pro;
1276 bind = &impl->_obj.prog.uniforms;
1277 for (i = 0; i < bind->count; i++)
1278 if (_mesa_strcmp (bind->table[i].name, name) == 0)
1279 return i;
1280 return -1;
1281 }
1282
1283 GLboolean _slang_write_uniform (struct gl2_program_intf **pro, GLint loc, GLsizei count,
1284 const GLvoid *data, GLenum type)
1285 {
1286 struct gl2_program_impl *impl;
1287 slang_uniform_bindings *bind;
1288 slang_uniform_binding *b;
1289 GLuint i;
1290
1291 if (loc == -1)
1292 return GL_TRUE;
1293
1294 impl = (struct gl2_program_impl *) pro;
1295 bind = &impl->_obj.prog.uniforms;
1296 if (loc >= bind->count)
1297 return GL_FALSE;
1298
1299 b = &bind->table[loc];
1300 /* TODO: check sizes */
1301 /* TODO: check if not structure */
1302 if (b->quant->u.basic_type != type)
1303 return GL_FALSE;
1304
1305 for (i = 0; i < SLANG_UNIFORM_BINDING_MAX; i++)
1306 if (b->address[i] != ~0)
1307 {
1308 _mesa_memcpy (&impl->_obj.prog.machines[i]->mem[b->address[i] / 4], data,
1309 count * b->quant->size);
1310 }
1311 return GL_TRUE;
1312 }
1313
1314 GLuint _slang_get_active_uniform_count (struct gl2_program_intf **pro)
1315 {
1316 struct gl2_program_impl *impl;
1317
1318 impl = (struct gl2_program_impl *) pro;
1319 return impl->_obj.prog.active_uniforms.count;
1320 }
1321
1322 GLuint _slang_get_active_uniform_max_length (struct gl2_program_intf **pro)
1323 {
1324 struct gl2_program_impl *impl;
1325 GLuint i, len = 0;
1326
1327 impl = (struct gl2_program_impl *) pro;
1328 for (i = 0; i < impl->_obj.prog.active_uniforms.count; i++)
1329 {
1330 GLuint n = _mesa_strlen (impl->_obj.prog.active_uniforms.table[i].name);
1331 if (n > len)
1332 len = n;
1333 }
1334 return len;
1335 }
1336
1337 GLvoid _slang_get_active_uniform (struct gl2_program_intf **pro, GLuint index, GLsizei maxLength,
1338 GLsizei *length, GLint *size, GLenum *type, char *name)
1339 {
1340 struct gl2_program_impl *impl;
1341 slang_active_uniform *u;
1342 GLsizei len;
1343
1344 impl = (struct gl2_program_impl *) pro;
1345 u = &impl->_obj.prog.active_uniforms.table[index];
1346
1347 len = _mesa_strlen (u->name);
1348 if (len >= maxLength)
1349 len = maxLength - 1;
1350 _mesa_memcpy (name, u->name, len);
1351 name[len] = '\0';
1352 if (length != NULL)
1353 *length = len;
1354 *type = u->quant->u.basic_type;
1355 if (u->quant->array_len == 0)
1356 *size = 1;
1357 else
1358 *size = u->quant->array_len;
1359 }
1360
1361 void
1362 _mesa_init_shaderobjects_3dlabs (GLcontext *ctx)
1363 {
1364 #if USE_3DLABS_FRONTEND
1365 _glslang_3dlabs_InitProcess ();
1366 _glslang_3dlabs_ShInitialize ();
1367 #endif
1368 }
1369