Project

General

Profile

SO3Engine
SCOLRenderToTexture.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25
34#include "SCOLPack/SO3SCOL.h"
35
36// Material includes
39
40// Scene Graph includes
43
55{
56#ifdef SO3_DEBUG
57 MMechostr(MSKDEBUG, "SO3RenderToTextureCreate\n");
58#endif
59
60 int c = MMpull(m);
61 int n = MMpull(m);
62 int s = MMget(m, 0);
63
64 // Checking parameters.
65 if ((s == NIL) || (n == NIL) || (c == NIL))
66 {
67 MMset(m, 0, NIL);
68 return 0;
69 }
70
71 // Get the SScene pointer
72 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
73 if (scene == NULL)
74 {
75 MMset(m, 0, NIL);
76 return 0;
77 }
78
79 // Get the name
80 std::string tmpRenderToTextureName = MMstartstr(m, MTOP(n));
81
82 // Get the SCamera pointer
83 SNode* node = MMgetPointer<SNode*>(m, MTOP(c));
84 if (node == NULL)
85 {
86 MMset(m, 0, NIL);
87 return 0;
88 }
89
90 // Check that the node is a camera node.
91 if (node->GetNodeType() != SNode::CAMERA_TYPE_ID)
92 {
93 MMset(m, 0, NIL);
94 return 0;
95 }
96
97 // Create the object
98 SRenderToTexture* renderToTexture = 0;
99 try
100 {
101 renderToTexture = scene->CreateRenderToTexture(tmpRenderToTextureName, static_cast<SCamera*>(node));
102 }
103 catch (Ogre::Exception &e)
104 {
105 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
106 MMset(m, 0, NIL);
107 return 0;
108 }
109
110 //get scene scol object
111 int p = OBJfindTH(m, SO3SCENETYPE, SCOL_PTR scene);
112 // push channel
113 MMset(m, 0, MMfetch(m, p, OFFOBJCHN));
114
115 // Create the scol object, set the pov camera as parent (not the scene like any other so3_object).
116 if ((MMpushPointer(m, renderToTexture) != 0))
117 {
118 scene->DeleteRenderToTexture(renderToTexture);
119 MMset(m, 0, NIL);
120 return MERRMEM;
121 }
122
123 OBJcreate(m, SO3OBJTYPE, SCOL_PTR renderToTexture, SO3OBJTYPE, SCOL_PTR node);
124 return 0;
125}
126
140{
141#ifdef SO3_DEBUG
142 MMechostr(MSKDEBUG, "SO3RenderToTextureSetTargetMaterial\n");
143#endif
144
145 int textureUnit = MMpull(m);
146 int pass = MMpull(m);
147 int technique = MMpull(m);
148 int mat = MMpull(m);
149 int dcm = MMget(m, 0);
150
151 // Checking parameters.
152 if ((dcm == NIL) || (mat == NIL) || (technique == NIL) || (pass == NIL) || (textureUnit == NIL))
153 {
154 MMset(m, 0, NIL);
155 return 0;
156 }
157
158 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
159 if (node == 0)
160 {
161 MMset(m, 0, NIL);
162 return 0;
163 }
164
165 if (node->GetNodeType() != SNode::RENDER_TO_TEXTURE_ID)
166 {
167 MMset(m, 0, NIL);
168 return 0;
169 }
170
171 // Get the targeted SMaterial pointer
172 SRenderToTexture* renderToTexture = static_cast<SRenderToTexture*>(node);
173 SMaterial* material = MMgetPointer<SMaterial*>(m, MTOP(mat));
174 if (material == 0)
175 {
176 MMset(m, 0, NIL);
177 return 0;
178 }
179
180 // Get other parameters
181 technique = MTOI(technique);
182 pass = MTOI(pass);
183 textureUnit = MTOI(textureUnit);
184
185 try
186 {
187 renderToTexture->SetMaterial(material, technique, pass, textureUnit);
188 MMset(m, 0, ITOM(1));
189 }
190 catch (Ogre::Exception& e)
191 {
192 MMechostr(MSKRUNTIME, "An exception has occurred: %s\n", e.what());
193 MMset(m, 0, NIL);
194 }
195 return 0;
196}
197
207{
208#ifdef SO3_DEBUG
209 MMechostr(MSKDEBUG, "SO3RenderToTextureGetEnable\n");
210#endif
211
212 int dcm = MMget(m, 0);
213 if (dcm == NIL)
214 {
215 MMset(m, 0, NIL);
216 return 0;
217 }
218
219 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
220 if (node == 0)
221 {
222 MMset(m, 0, NIL);
223 return 0;
224 }
225
226 if (node->GetNodeType() != SNode::RENDER_TO_TEXTURE_ID)
227 {
228 MMset(m, 0, NIL);
229 return 0;
230 }
231
232 SRenderToTexture* renderToTexture = static_cast<SRenderToTexture*>(node);
233 int val = 0;
234 if (renderToTexture->GetEnable())
235 val = 1;
236
237 MMset(m, 0, ITOM(val));
238 return 0;
239}
240
251{
252#ifdef SO3_DEBUG
253 MMechostr(MSKDEBUG, "SO3RenderToTextureSetEnable\n");
254#endif
255
256 int b = MMpull(m);
257 int dcm = MMget(m, 0);
258 if ((dcm == NIL) || (b == NIL))
259 {
260 MMset(m, 0, NIL);
261 return 0;
262 }
263
264 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
265 if (node == 0)
266 {
267 MMset(m, 0, NIL);
268 return 0;
269 }
270
271 if (node->GetNodeType() != SNode::RENDER_TO_TEXTURE_ID)
272 {
273 MMset(m, 0, NIL);
274 return 0;
275 }
276
277 SRenderToTexture* renderToTexture = static_cast<SRenderToTexture*>(node);
278 if (MTOI(b) >= 1)
279 renderToTexture->SetEnable(true);
280 else
281 renderToTexture->SetEnable(false);
282
283 MMset(m, 0, ITOM(1));
284 return 0;
285}
286
296{
297#ifdef SO3_DEBUG
298 MMechostr(MSKDEBUG, "SO3RenderToTextureGetAutoUpdate\n");
299#endif
300
301 int dcm = MMget(m, 0);
302 if (dcm == NIL)
303 {
304 MMset(m, 0, NIL);
305 return 0;
306 }
307
308 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
309 if (node == 0)
310 {
311 MMset(m, 0, NIL);
312 return 0;
313 }
314
315 if (node->GetNodeType() != SNode::RENDER_TO_TEXTURE_ID)
316 {
317 MMset(m, 0, NIL);
318 return 0;
319 }
320
321 SRenderToTexture* renderToTexture = static_cast<SRenderToTexture*>(node);
322 int val = 0;
323 if (renderToTexture->GetAutoUpdate())
324 val = 1;
325
326 MMset(m, 0, ITOM(val));
327 return 0;
328}
329
340{
341#ifdef SO3_DEBUG
342 MMechostr(MSKDEBUG, "SO3RenderToTextureSetAutoUpdate\n");
343#endif
344
345 int b = MMpull(m);
346 int dcm = MMget(m, 0);
347 if ((dcm == NIL) || (b == NIL))
348 {
349 MMset(m, 0, NIL);
350 return 0;
351 }
352
353 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
354 if (node == 0)
355 {
356 MMset(m, 0, NIL);
357 return 0;
358 }
359
360 if (node->GetNodeType() != SNode::RENDER_TO_TEXTURE_ID)
361 {
362 MMset(m, 0, NIL);
363 return 0;
364 }
365
366 SRenderToTexture* renderToTexture = static_cast<SRenderToTexture*>(node);
367 if (MTOI(b) >= 1)
368 renderToTexture->SetAutoUpdate(true);
369 else
370 renderToTexture->SetAutoUpdate(false);
371
372 MMset(m, 0, ITOM(1));
373 return 0;
374}
375
376
386{
387#ifdef SO3_DEBUG
388 MMechostr(MSKDEBUG, "SO3RenderToTextureGetTextureSize\n");
389#endif
390
391 int dcm = MMget(m, 0);
392 if (dcm == NIL)
393 {
394 MMset(m, 0, NIL);
395 return 0;
396 }
397
398 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
399 if (node == 0)
400 {
401 MMset(m, 0, NIL);
402 return 0;
403 }
404
405 if (node->GetNodeType() != SNode::RENDER_TO_TEXTURE_ID)
406 {
407 MMset(m, 0, NIL);
408 return 0;
409 }
410
411 SRenderToTexture* renderToTexture = static_cast<SRenderToTexture*>(node);
412 MMset(m, 0, ITOM(renderToTexture->GetSize()));
413 return 0;
414}
415
426{
427#ifdef SO3_DEBUG
428 MMechostr(MSKDEBUG, "SO3RenderToTextureSetTextureSize\n");
429#endif
430
431 int size = MMpull(m);
432 int dcm = MMget(m, 0);
433 if ((dcm == NIL) || (size == NIL))
434 {
435 MMset(m, 0, NIL);
436 return 0;
437 }
438
439 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
440 if (node == 0)
441 {
442 MMset(m, 0, NIL);
443 return 0;
444 }
445
446 if (node->GetNodeType() != SNode::RENDER_TO_TEXTURE_ID)
447 {
448 MMset(m, 0, NIL);
449 return 0;
450 }
451
452 SRenderToTexture* renderToTexture = static_cast<SRenderToTexture*>(node);
453 try
454 {
455 renderToTexture->SetSize(MTOI(size));
456 MMset(m, 0, ITOM(1));
457 }
458 catch (Ogre::Exception& e)
459 {
460 MMechostr(MSKRUNTIME, "An exception has occurred: %s\n", e.what());
461 MMset(m, 0, NIL);
462 }
463 return 0;
464}
465
475{
476#ifdef SO3_DEBUG
477 MMechostr(MSKDEBUG, "SO3RenderToTextureUpdate\n");
478#endif
479
480 int dcm = MMget(m, 0);
481 if (dcm == NIL)
482 {
483 MMset(m, 0, NIL);
484 return 0;
485 }
486
487 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
488 if (node == 0)
489 {
490 MMset(m, 0, NIL);
491 return 0;
492 }
493
494 if (node->GetNodeType() != SNode::RENDER_TO_TEXTURE_ID)
495 {
496 MMset(m, 0, NIL);
497 return 0;
498 }
499
500 SRenderToTexture* renderToTexture = static_cast<SRenderToTexture*>(node);
501 renderToTexture->Update();
502 MMset(m, 0, ITOM(1));
503 return 0;
504}
505
506
517{
518#ifdef SO3_DEBUG
519 MMechostr(MSKDEBUG, "SO3RenderToTextureSetMaterialScheme\n");
520#endif
521
522 int mscheme = MMpull(m);
523 int dcm = MMget(m, 0);
524 if (dcm == NIL)
525 {
526 MMset(m, 0, NIL);
527 return 0;
528 }
529
530 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
531 if (node == 0)
532 {
533 MMset(m, 0, NIL);
534 return 0;
535 }
536
537 if (node->GetNodeType() != SNode::RENDER_TO_TEXTURE_ID)
538 {
539 MMset(m, 0, NIL);
540 return 0;
541 }
542
543 std::string matScheme;
544 if (mscheme != NIL)
545 matScheme = MMstartstr(m, MTOP(mscheme));
546
547 SRenderToTexture* renderToTexture = static_cast<SRenderToTexture*>(node);
548 renderToTexture->SetMaterialScheme(matScheme);
549 MMset(m, 0, ITOM(1));
550 return 0;
551}
552
553
565{
566#ifdef SO3_DEBUG
567 MMechostr(MSKDEBUG, "SO3RenderToTextureAddCompositor\n");
568#endif
569
570 int sc = MMpull(m);
571 int cn = MMpull(m);
572 int dcm = MMget(m, 0);
573 if ((dcm == NIL) || (cn == NIL))
574 {
575 MMset(m, 0, NIL);
576 return 0;
577 }
578
579 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
580 if (node == 0)
581 {
582 MMset(m, 0, NIL);
583 return 0;
584 }
585
586 if (node->GetNodeType() != SNode::RENDER_TO_TEXTURE_ID)
587 {
588 MMset(m, 0, NIL);
589 return 0;
590 }
591
592 SRenderToTexture* renderToTexture = static_cast<SRenderToTexture*>(node);
593
594 std::string compositorName(MMstartstr(m, MTOP(cn)));
595 std::string schemeName((sc == NIL) ? "" : MMstartstr(m, MTOP(sc)));
596
597 SCompositor* newCompositor = renderToTexture->CreateCompositor(compositorName, schemeName);
598
599 MMset(m, 0, ITOM(1));
600 return 0;
601}
602
603
614{
615#ifdef SO3_DEBUG
616 MMechostr(MSKDEBUG, "SO3RenderToTextureRemoveCompositor\n");
617#endif
618
619 int cn = MMpull(m);
620 int dcm = MMget(m, 0);
621 if ((dcm == NIL) || (cn == NIL))
622 {
623 MMset(m, 0, NIL);
624 return 0;
625 }
626
627 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
628 if (node == 0)
629 {
630 MMset(m, 0, NIL);
631 return 0;
632 }
633
634 if (node->GetNodeType() != SNode::RENDER_TO_TEXTURE_ID)
635 {
636 MMset(m, 0, NIL);
637 return 0;
638 }
639
640 SRenderToTexture* renderToTexture = static_cast<SRenderToTexture*>(node);
641
642 std::string compositorName(MMstartstr(m, MTOP(cn)));
643 SCompositor* compositorInstance = renderToTexture->GetCompositor(compositorName);
644 if (compositorInstance)
645 try
646 {
647 renderToTexture->DeleteCompositor(compositorInstance);
648 }
649 catch (Ogre::Exception &e)
650 {
651 MMechostr(MSKDEBUG, "SO3RenderToTextureRemoveCompositor : exception > %s", e.what());
652 }
653
654 MMset(m, 0, ITOM(1));
655 return 0;
656}
657
658
670{
671#ifdef SO3_DEBUG
672 MMechostr(MSKDEBUG, "SO3RenderToTextureCompositorSetEnable\n");
673#endif
674
675 int b = MMpull(m);
676 int cn = MMpull(m);
677 int dcm = MMget(m, 0);
678 if ((dcm == NIL) || (cn == NIL))
679 {
680 MMset(m, 0, NIL);
681 return 0;
682 }
683
684 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
685 if (node == 0)
686 {
687 MMset(m, 0, NIL);
688 return 0;
689 }
690
691 if (node->GetNodeType() != SNode::RENDER_TO_TEXTURE_ID)
692 {
693 MMset(m, 0, NIL);
694 return 0;
695 }
696
697 SRenderToTexture* renderToTexture = static_cast<SRenderToTexture*>(node);
698
699 std::string compositorName(MMstartstr(m, MTOP(cn)));
700 SCompositor* tmpCompositor = renderToTexture->GetCompositor(compositorName);
701 if (MTOI(b) == 0)
702 tmpCompositor->SetEnable(false);
703 else
704 tmpCompositor->SetEnable(true);
705
706 MMset(m, 0, ITOM(1));
707 return 0;
708}
709
710
721{
722#ifdef SO3_DEBUG
723 MMechostr(MSKDEBUG, "SO3CompositorGetEnable\n");
724#endif
725
726 int cn = MMpull(m);
727 int dcm = MMget(m, 0);
728 if ((dcm == NIL) || (cn == NIL))
729 {
730 MMset(m, 0, NIL);
731 return 0;
732 }
733
734 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
735 if (node == 0)
736 {
737 MMset(m, 0, NIL);
738 return 0;
739 }
740
741 if (node->GetNodeType() != SNode::RENDER_TO_TEXTURE_ID)
742 {
743 MMset(m, 0, NIL);
744 return 0;
745 }
746
747 SRenderToTexture* renderToTexture = static_cast<SRenderToTexture*>(node);
748
749 std::string compositorName(MMstartstr(m, MTOP(cn)));
750 SCompositor* tmpCompositor = renderToTexture->GetCompositor(compositorName);
751
752 int state = 0;
753 if (tmpCompositor != 0)
754 if (tmpCompositor->GetEnable())
755 state = 1;
756
757 MMset(m, 0, ITOM(state));
758 return 0;
759}
760
761
762NativeDefinition natSO3Rtt[] = {
763 { "SO3RenderToTextureCreate", 3, "fun [SO3_SCENE S SO3_OBJECT] SO3_OBJECT", SO3RenderToTextureCreate },
764 { "SO3RenderToTextureSetTargetMaterial", 5, "fun [SO3_OBJECT SO3_MATERIAL I I I] SO3_OBJECT", SO3RenderToTextureSetTargetMaterial },
765 { "SO3RenderToTextureGetEnable", 1, "fun [SO3_OBJECT] I", SO3RenderToTextureGetEnable },
766 { "SO3RenderToTextureSetEnable", 2, "fun [SO3_OBJECT I] I", SO3RenderToTextureSetEnable },
767 { "SO3RenderToTextureGetTextureSize", 1, "fun [SO3_OBJECT] I", SO3RenderToTextureGetTextureSize },
768 { "SO3RenderToTextureSetTextureSize", 2, "fun [SO3_OBJECT I] I", SO3RenderToTextureSetTextureSize },
769 { "SO3RenderToTextureGetAutoUpdate", 1, "fun [SO3_OBJECT] I", SO3RenderToTextureGetAutoUpdate },
770 { "SO3RenderToTextureSetAutoUpdate", 2, "fun [SO3_OBJECT I] I", SO3RenderToTextureSetAutoUpdate },
771 { "SO3RenderToTextureUpdate", 1, "fun [SO3_OBJECT] I", SO3RenderToTextureUpdate },
772 { "SO3RenderToTextureSetMaterialScheme", 2, "fun [SO3_OBJECT S] I", SO3RenderToTextureSetMaterialScheme },
773 { "SO3RenderToTextureAddCompositor", 3, "fun [SO3_OBJECT S S] I", SO3RenderToTextureAddCompositor },
774 { "SO3RenderToTextureRemoveCompositor", 2, "fun [SO3_OBJECT S] I", SO3RenderToTextureRemoveCompositor },
775 { "SO3RenderToTextureCompositorSetEnable", 3, "fun [SO3_OBJECT S I] I", SO3RenderToTextureCompositorSetEnable },
776 { "SO3RenderToTextureCompositorGetEnable", 2, "fun [SO3_OBJECT S] I", SO3RenderToTextureCompositorGetEnable }
777};
778
779
785int SCOLloadRenderToTexture(mmachine m, cbmachine w)
786{
787 return PKhardpak2(m, "SO3Rtt.pkg", sizeof(natSO3Rtt) / sizeof(natSO3Rtt[0]), natSO3Rtt);
788}
789
795{
796 return 0;
797}
NativeDefinition natSO3Rtt[]
int SCOLfreeRenderToTexture()
free the SO3Engine RenderToTexture function
int SCOLloadRenderToTexture(mmachine m, cbmachine w)
Load the SO3Engine RenderToTexture function.
MMechostr(MSKDEBUG, " > Start loading Plugin SO3Engine dll\n")
SCOL_EXPORT int cbmachine w
Definition SO3SCOL.cpp:5150
int SO3SCENETYPE
Definition SO3SCOL.cpp:88
int SO3OBJTYPE
Definition SO3SCOL.cpp:90
int SO3RenderToTextureRemoveCompositor(mmachine m)
SO3RenderToTextureRemoveCompositor : Remove a compositor from a given RenderToTexture.
int SO3RenderToTextureSetMaterialScheme(mmachine m)
SO3RenderToTextureSetMaterialScheme : set the render to texture material scheme.
int SO3RenderToTextureGetTextureSize(mmachine m)
SO3RenderToTextureGetTextureSize : Get the size of the target texture.
int SO3RenderToTextureSetTextureSize(mmachine m)
SO3RenderToTextureSetTextureSize : Set the size of the target texture.
int SO3RenderToTextureSetTargetMaterial(mmachine m)
SO3RenderToTextureSetTargetMaterial : Set the material on wich the rendered texture will be setted....
int SO3RenderToTextureSetEnable(mmachine m)
SO3RenderToTextureSetEnable : Set the Enable state for render to texture object.
int SO3RenderToTextureCreate(mmachine m)
main include
int SO3RenderToTextureUpdate(mmachine m)
SO3RenderToTextureUpdate : manually update a dynamic render to texture object (in case autoUpdate is ...
int SO3RenderToTextureCompositorGetEnable(mmachine m)
SO3RenderToTextureCompositorGetEnable : Get Compositor state on a given RenderToTexture.
int SO3RenderToTextureGetAutoUpdate(mmachine m)
SO3RenderToTextureGetAutoUpdate : Get the auto update state (is the render to texture object should b...
int SO3RenderToTextureCompositorSetEnable(mmachine m)
SO3RenderToTextureCompositorSetEnable : Set Compositor state on a given RenderToTexture.
int SO3RenderToTextureSetAutoUpdate(mmachine m)
SO3RenderToTextureSetAutoUpdate : Set the AutoUpdate state (refresh every frame) for render to textur...
int SO3RenderToTextureGetEnable(mmachine m)
SO3RenderToTextureGetEnable : Get the enable state for the render to texture object.
int SO3RenderToTextureAddCompositor(mmachine m)
SO3RenderToTextureAddCompositor : Add a compositor on a given RenderToTexture.