source: GTP/trunk/App/Games/Jungle_Rumble/src/RenderPass.cpp @ 1378

Revision 1378, 4.0 KB checked in by giegl, 18 years ago (diff)

GTPD - Jungle Rumble - integrate into GTP SVN structure

Line 
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
9RenderPass::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
29RenderPass::~RenderPass(void)
30{
31}
32
33void RenderPass::setRenderer(Renderer* _renderer)
34{
35        this->renderer = _renderer;
36        this->scene = this->renderer->myScene;
37        this->device = this->scene->device;
38}
39
40void RenderPass::setSafeAndRestoreRenderTarget(bool _safeRenderTarget)
41{
42        this->safeRenderTarget = _safeRenderTarget;
43}
44
45void RenderPass::setRenderTarget(LPDIRECT3DSURFACE9 _renderTarget)
46{
47        this->renderTarget = _renderTarget;
48}
49
50void RenderPass::setDepthStencilSurface(LPDIRECT3DSURFACE9 _depthStencilSurface)
51{
52        this->dephStencilSurface = _depthStencilSurface;
53}
54
55void RenderPass::setViewMatrix(D3DXMATRIX &_viewMat)
56{
57        this->viewMat = _viewMat;
58}
59
60void RenderPass::setProjectionMatrix(D3DXMATRIX &_projMat)
61{
62        this->projMat = _projMat;
63}
64
65void RenderPass::execute(int command, bool _execute)
66{
67        this->executeCommand[command] = _execute;
68}
69
70void 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
126D3DXMATRIX* RenderPass::getViewMatrix()
127{
128        return &this->viewMat;
129}
130
131D3DXMATRIX* RenderPass::getProjectionMatrix()
132{
133        return &this->projMat;
134}
135
136D3DXMATRIX* RenderPass::getViewProjectionMatrix()
137{
138        return &this->viewProjMat;
139}
140
141D3DXMATRIX  RenderPass::getWorldViewMatrix(D3DXMATRIX *worldMat)
142{
143        D3DXMATRIX temp;
144        D3DXMatrixMultiply(&temp, worldMat, &this->viewMat);
145        return temp;
146}
147
148D3DXMATRIX  RenderPass::getWorldViewProjectionMatrix(D3DXMATRIX *worldMat)
149{
150        D3DXMATRIX temp;
151        D3DXMatrixMultiply(&temp, worldMat, &this->viewProjMat);
152        return temp;
153}
154
155void RenderPass::setRenderPassId(int _passId)
156{
157        this->renderPassId = _passId;
158}
159
160int RenderPass::getRenderPassId()
161{
162        if(this->renderPassId==-1) {
163                this->scene->manager->printToConsole("RenderPass ID not set!!!!!");
164        }
165        return this->renderPassId;
166}
167
168void RenderPass::setScene(Scene &_scene)
169{
170        this->scene = &_scene;
171        this->device = this->scene->device;
172}
173
174void RenderPass::calculateMatrices()
175{
176        D3DXMatrixMultiply(&this->viewProjMat, &this->viewMat, &this->projMat);
177}
178
179void RenderPass::useThisRendererList(std::vector<Renderer *>* _otherList)
180{
181        this->usedRendererList = _otherList;
182}
Note: See TracBrowser for help on using the repository browser.