1 | #include "dxstdafx.h"
|
---|
2 | #include ".\renderpass.h"
|
---|
3 |
|
---|
4 | #include "Scene.h"
|
---|
5 | #include "GameScene.h"
|
---|
6 | #include "SkyBox.h"
|
---|
7 | #include "Renderer.h"
|
---|
8 |
|
---|
9 | RenderPass::RenderPass(void)
|
---|
10 | {
|
---|
11 | this->renderTargetSurfaceOld = NULL;
|
---|
12 | this->depthStencilSurfaceOld = NULL;
|
---|
13 |
|
---|
14 | this->renderTarget = NULL;
|
---|
15 | this->dephStencilSurface = NULL;
|
---|
16 |
|
---|
17 | for(int i=0;i<SIZEOFCMD;i++)
|
---|
18 | {
|
---|
19 | this->executeCommand[i] = false;
|
---|
20 | }
|
---|
21 |
|
---|
22 | D3DXMatrixIdentity(&this->viewMat);
|
---|
23 | D3DXMatrixIdentity(&this->projMat);
|
---|
24 | this->renderPassId = -1;
|
---|
25 |
|
---|
26 | this->usedRendererList = &this->myRendererList;
|
---|
27 | }
|
---|
28 |
|
---|
29 | RenderPass::~RenderPass(void)
|
---|
30 | {
|
---|
31 | }
|
---|
32 |
|
---|
33 | void RenderPass::setRenderer(Renderer* _renderer)
|
---|
34 | {
|
---|
35 | this->renderer = _renderer;
|
---|
36 | this->scene = this->renderer->myScene;
|
---|
37 | this->device = this->scene->device;
|
---|
38 | }
|
---|
39 |
|
---|
40 | void RenderPass::setSafeAndRestoreRenderTarget(bool _safeRenderTarget)
|
---|
41 | {
|
---|
42 | this->safeRenderTarget = _safeRenderTarget;
|
---|
43 | }
|
---|
44 |
|
---|
45 | void RenderPass::setRenderTarget(LPDIRECT3DSURFACE9 _renderTarget)
|
---|
46 | {
|
---|
47 | this->renderTarget = _renderTarget;
|
---|
48 | }
|
---|
49 |
|
---|
50 | void RenderPass::setDepthStencilSurface(LPDIRECT3DSURFACE9 _depthStencilSurface)
|
---|
51 | {
|
---|
52 | this->dephStencilSurface = _depthStencilSurface;
|
---|
53 | }
|
---|
54 |
|
---|
55 | void RenderPass::setViewMatrix(D3DXMATRIX &_viewMat)
|
---|
56 | {
|
---|
57 | this->viewMat = _viewMat;
|
---|
58 | }
|
---|
59 |
|
---|
60 | void RenderPass::setProjectionMatrix(D3DXMATRIX &_projMat)
|
---|
61 | {
|
---|
62 | this->projMat = _projMat;
|
---|
63 | }
|
---|
64 |
|
---|
65 | void RenderPass::execute(int command, bool _execute)
|
---|
66 | {
|
---|
67 | this->executeCommand[command] = _execute;
|
---|
68 | }
|
---|
69 |
|
---|
70 | void RenderPass::executePass()
|
---|
71 | {
|
---|
72 | this->device = this->scene->device;
|
---|
73 | if(this->scene->activeRenderPass!=this) {
|
---|
74 | this->scene->manager->printToConsole("activeRenderPass != executed RenderPass!!! -> call setActiveRenderPass in Scene!");
|
---|
75 | return;
|
---|
76 | }
|
---|
77 | //asdf++;
|
---|
78 |
|
---|
79 | HRESULT hr;
|
---|
80 |
|
---|
81 | if(!this->device)
|
---|
82 | {
|
---|
83 | this->device = this->scene->device;
|
---|
84 | }
|
---|
85 |
|
---|
86 | if(this->safeRenderTarget) {
|
---|
87 | V( this->device->GetRenderTarget(0, &this->renderTargetSurfaceOld));
|
---|
88 | V( this->device->GetDepthStencilSurface(&this->depthStencilSurfaceOld))
|
---|
89 | }
|
---|
90 | V( this->device->SetRenderTarget( 0, this->renderTarget) );
|
---|
91 |
|
---|
92 | if(this->dephStencilSurface!=NULL) {
|
---|
93 | V( this->device->SetDepthStencilSurface( this->dephStencilSurface ) );
|
---|
94 | }
|
---|
95 | for(int i=0;i<SIZEOFCMD;i++)
|
---|
96 | {
|
---|
97 | if(this->executeCommand[i])
|
---|
98 | {
|
---|
99 | switch(i)
|
---|
100 | {
|
---|
101 | case this->CMD_CLEARRENDERTARGETANDZBUFFER:
|
---|
102 | this->scene->clearRenderTargetAndZBuffer();
|
---|
103 | break;
|
---|
104 | case this->CMD_DOFRUSTUMCULLING:
|
---|
105 | this->scene->doFrustumCulling();
|
---|
106 | break;
|
---|
107 | case this->CMD_RENDERNODES:
|
---|
108 | this->scene->renderNodes();
|
---|
109 | break;
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 | //Restore old RenderTarget
|
---|
115 | if(this->safeRenderTarget) {
|
---|
116 | if(this->depthStencilSurfaceOld)
|
---|
117 | {
|
---|
118 | V(this->device->SetDepthStencilSurface(this->depthStencilSurfaceOld));
|
---|
119 | SAFE_RELEASE(this->depthStencilSurfaceOld);
|
---|
120 | }
|
---|
121 | V(this->device->SetRenderTarget( 0, this->renderTargetSurfaceOld));
|
---|
122 | SAFE_RELEASE(this->renderTargetSurfaceOld);
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | D3DXMATRIX* RenderPass::getViewMatrix()
|
---|
127 | {
|
---|
128 | return &this->viewMat;
|
---|
129 | }
|
---|
130 |
|
---|
131 | D3DXMATRIX* RenderPass::getProjectionMatrix()
|
---|
132 | {
|
---|
133 | return &this->projMat;
|
---|
134 | }
|
---|
135 |
|
---|
136 | D3DXMATRIX* RenderPass::getViewProjectionMatrix()
|
---|
137 | {
|
---|
138 | return &this->viewProjMat;
|
---|
139 | }
|
---|
140 |
|
---|
141 | D3DXMATRIX RenderPass::getWorldViewMatrix(D3DXMATRIX *worldMat)
|
---|
142 | {
|
---|
143 | D3DXMATRIX temp;
|
---|
144 | D3DXMatrixMultiply(&temp, worldMat, &this->viewMat);
|
---|
145 | return temp;
|
---|
146 | }
|
---|
147 |
|
---|
148 | D3DXMATRIX RenderPass::getWorldViewProjectionMatrix(D3DXMATRIX *worldMat)
|
---|
149 | {
|
---|
150 | D3DXMATRIX temp;
|
---|
151 | D3DXMatrixMultiply(&temp, worldMat, &this->viewProjMat);
|
---|
152 | return temp;
|
---|
153 | }
|
---|
154 |
|
---|
155 | void RenderPass::setRenderPassId(int _passId)
|
---|
156 | {
|
---|
157 | this->renderPassId = _passId;
|
---|
158 | }
|
---|
159 |
|
---|
160 | int RenderPass::getRenderPassId()
|
---|
161 | {
|
---|
162 | if(this->renderPassId==-1) {
|
---|
163 | this->scene->manager->printToConsole("RenderPass ID not set!!!!!");
|
---|
164 | }
|
---|
165 | return this->renderPassId;
|
---|
166 | }
|
---|
167 |
|
---|
168 | void RenderPass::setScene(Scene &_scene)
|
---|
169 | {
|
---|
170 | this->scene = &_scene;
|
---|
171 | this->device = this->scene->device;
|
---|
172 | }
|
---|
173 |
|
---|
174 | void RenderPass::calculateMatrices()
|
---|
175 | {
|
---|
176 | D3DXMatrixMultiply(&this->viewProjMat, &this->viewMat, &this->projMat);
|
---|
177 | }
|
---|
178 |
|
---|
179 | void RenderPass::useThisRendererList(std::vector<Renderer *>* _otherList)
|
---|
180 | {
|
---|
181 | this->usedRendererList = _otherList;
|
---|
182 | } |
---|