1 | #include "OgreSBBRenderTechnique.h"
|
---|
2 | #include "OgreTechniqueGroup.h"
|
---|
3 | #include "OgreIlluminationManager.h"
|
---|
4 | #include "OgreSceneCameraDepthRenderingRun.h"
|
---|
5 |
|
---|
6 |
|
---|
7 | OgreSBBRenderTechnique::OgreSBBRenderTechnique( unsigned char depthTexID,
|
---|
8 | bool bindTexture,
|
---|
9 | Pass* pass,
|
---|
10 | OgreRenderable* parentRenderable,
|
---|
11 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
12 | :RenderTechnique( parentRenderable, parentTechniqueGroup),
|
---|
13 | OgreRenderTechnique(pass, parentRenderable, parentTechniqueGroup),
|
---|
14 | SBBRenderTechnique(parentRenderable, parentTechniqueGroup)
|
---|
15 | {
|
---|
16 | this->depthTexID = depthTexID;
|
---|
17 | this->bindTexture = bindTexture;
|
---|
18 |
|
---|
19 | OgreIlluminationManager::getSingleton().createGlobalRun(ILLUMRUN_SCENE_CAMERA_DEPTH);
|
---|
20 |
|
---|
21 | OgreSceneCameraDepthRenderingRun* run = (OgreSceneCameraDepthRenderingRun*)
|
---|
22 | OgreIlluminationManager::getSingleton().getGlobalRun(ILLUMRUN_SCENE_CAMERA_DEPTH)->asOgreRenderingRun();
|
---|
23 |
|
---|
24 | Root::getSingleton().addFrameListener(this);
|
---|
25 | OgreIlluminationManager::getSingleton().getMainViewport()
|
---|
26 | ->getTarget()->addListener(this);
|
---|
27 | OgreIlluminationManager::getSingleton().addUpdateListener(this);
|
---|
28 |
|
---|
29 | if(bindTexture)
|
---|
30 | pass->getTextureUnitState(depthTexID)->setTextureName(run->getDepthTextureName());
|
---|
31 |
|
---|
32 | }
|
---|
33 |
|
---|
34 | void OgreSBBRenderTechnique::preAllUpdates()
|
---|
35 | {
|
---|
36 | lastVisibility = parentOgreRenderable->isVisible();
|
---|
37 | parentOgreRenderable->setVisible(false);
|
---|
38 | }
|
---|
39 | void OgreSBBRenderTechnique::preRenderTargetUpdate (const RenderTargetEvent &evt)
|
---|
40 | {
|
---|
41 | //parentOgreRenderable->setVisible(lastVisibility);
|
---|
42 | }
|
---|
43 | void OgreSBBRenderTechnique::postRenderTargetUpdate (const RenderTargetEvent &evt)
|
---|
44 | {
|
---|
45 | //parentOgreRenderable->setVisible(false);
|
---|
46 | }
|
---|
47 | bool OgreSBBRenderTechnique::frameEnded (const FrameEvent &evt)
|
---|
48 | {
|
---|
49 |
|
---|
50 | return true;
|
---|
51 | }
|
---|
52 | void OgreSBBRenderTechnique::postAllUpdates()
|
---|
53 | {
|
---|
54 | parentOgreRenderable->setVisible(lastVisibility);
|
---|
55 | }
|
---|
56 |
|
---|
57 | OgreSBBRenderTechnique::~OgreSBBRenderTechnique()
|
---|
58 | {
|
---|
59 |
|
---|
60 | }
|
---|
61 |
|
---|
62 | void OgreSBBRenderTechnique::update(unsigned long frameNum)
|
---|
63 | {
|
---|
64 | OgreIlluminationManager::getSingleton().updateGlobalRun(ILLUMRUN_SCENE_CAMERA_DEPTH, frameNum);
|
---|
65 | }
|
---|
66 |
|
---|
67 | namespace SBBParsers
|
---|
68 | {
|
---|
69 | ///Technique parsers
|
---|
70 | void parseDepthTexID(String& params, RenderTechniqueFactory* factory)
|
---|
71 | {
|
---|
72 | OgreSBBRenderTechniqueFactory* f = (OgreSBBRenderTechniqueFactory*) factory;
|
---|
73 | f->depthTexID = StringConverter::parseUnsignedInt(params);
|
---|
74 | }
|
---|
75 | void parseBindTexture(String& params, RenderTechniqueFactory* factory)
|
---|
76 | {
|
---|
77 | OgreSBBRenderTechniqueFactory* f = (OgreSBBRenderTechniqueFactory*) factory;
|
---|
78 | f->bindTexture = StringConverter::parseBool(params);
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | OgreSBBRenderTechniqueFactory::OgreSBBRenderTechniqueFactory()
|
---|
83 | {
|
---|
84 | typeName = "SphericalBillboard";
|
---|
85 |
|
---|
86 | using namespace SBBParsers;
|
---|
87 |
|
---|
88 | //register parsers
|
---|
89 | this->attributeParsers.insert(AttribParserList::value_type("texture_unit_id", (ILLUM_ATTRIBUTE_PARSER) parseDepthTexID));
|
---|
90 | this->attributeParsers.insert(AttribParserList::value_type("bind_texture", (ILLUM_ATTRIBUTE_PARSER) parseBindTexture));
|
---|
91 | }
|
---|
92 |
|
---|
93 | OgreRenderTechnique* OgreSBBRenderTechniqueFactory::createInstance(
|
---|
94 | IllumTechniqueParams* params,
|
---|
95 | Pass* pass,
|
---|
96 | OgreRenderable* parentRenderable,
|
---|
97 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
98 | {
|
---|
99 | //reset parameters
|
---|
100 | depthTexID = 1;
|
---|
101 | bindTexture = true;
|
---|
102 |
|
---|
103 | parseParams(params);
|
---|
104 |
|
---|
105 | OgreSBBRenderTechnique* result = new OgreSBBRenderTechnique(
|
---|
106 | depthTexID,
|
---|
107 | bindTexture,
|
---|
108 | pass,
|
---|
109 | parentRenderable,
|
---|
110 | parentTechniqueGroup);
|
---|
111 | return result;
|
---|
112 | }
|
---|
113 |
|
---|
114 |
|
---|
115 |
|
---|