source: GTP/trunk/App/Demos/Illum/Standalone/HierRayEngine [DirectX]/HREEffect.h @ 1481

Revision 1481, 5.4 KB checked in by szirmay, 18 years ago (diff)
Line 
1#pragma once
2#include <vector>
3#include "Parameters.h"
4#include "Vector.hpp"
5#include "half.h"
6
7#define RAY_TABLE_WIDTH         512
8#define RAY_TABLE_HEIGHT                512
9
10#define RAY_ORIGIN_COLOR_FORMAT         D3DFMT_A16B16G16R16F
11#define RAY_DIR_COLOR_FORMAT                    D3DFMT_A16B16G16R16F
12#define DEPTH_FORMAT                                                    D3DFMT_D24S8
13
14
15class HREEffect
16{
17        //! pointer to global user-adjustable application parameters object
18        static Parameters*              parameters;
19
20        //! pointer to main DX device
21        LPDIRECT3DDEVICE9               device;
22        //! pointer to main DX effect
23        LPD3DXEFFECT                    effect;
24
25        //! frame color buffer surface
26        //! saved before render-to-texture, and restored as the render target for the final rendering to the screen
27        LPDIRECT3DSURFACE9              frameColorBuffer;
28        //! frame depth buffer surface
29        //! saved before render-to-texture, and restored as the render target for the final rendering to the screen
30        LPDIRECT3DSURFACE9              frameDepthStencilBuffer;
31
32    LPDIRECT3DTEXTURE9  rayOriginTableTexture;
33    LPDIRECT3DSURFACE9  rayOriginTableSurface;
34
35    LPDIRECT3DTEXTURE9  rayDirTableTexture;
36    LPDIRECT3DSURFACE9  rayDirTableSurface;
37
38    LPDIRECT3DTEXTURE9  rayOriginTableTexture2;
39    LPDIRECT3DSURFACE9  rayOriginTableSurface2;
40
41    LPDIRECT3DTEXTURE9  rayDirTableTexture2;
42    LPDIRECT3DSURFACE9  rayDirTableSurface2;
43
44    LPDIRECT3DTEXTURE9  conePeakTexture;
45    LPDIRECT3DSURFACE9  conePeakSurface;
46    LPDIRECT3DTEXTURE9  coneDirTexture;
47    LPDIRECT3DSURFACE9  coneDirSurface;
48
49    LPDIRECT3DTEXTURE9  conePeakTextureMem;
50    LPDIRECT3DSURFACE9  conePeakSurfaceMem;
51    LPDIRECT3DTEXTURE9  coneDirTextureMem;
52    LPDIRECT3DSURFACE9  coneDirSurfaceMem;
53
54        LPDIRECT3DCUBETEXTURE9 environmentCubeTexture;
55
56    LPDIRECT3DSURFACE9  depthSurface;
57        LPDIRECT3DSURFACE9      coneStencil;
58
59        LPDIRECT3DVERTEXDECLARATION9 trianglePrimitiveDeclaration;
60
61        //! camera
62        CFirstPersonCamera*                     camera;
63        //! primary light source (can be moved just like the real camera, and can be used as the camera)
64        CFirstPersonCamera*                     lightCamera;
65
66        //! struct containing all mesh related data. Will be filled from X files in HREEffect constructor
67        class Mesh
68        {
69        public:
70                HREEffect* owner;
71                unsigned int            nSubsets;       //!< number of submeshes (with possible different material)
72                LPD3DXMESH                      mesh;           //!< D3D mesh
73                LPD3DXBUFFER            materialBuffer; //!< D3D material buffer
74                D3DXMATERIAL*           materials;              //!< D3D material array
75                LPDIRECT3DTEXTURE9*     textures;               //!< D3D textures for the materials
76                LPDIRECT3DVERTEXBUFFER9 primitiveVertexBuffer; //!< ray engine representation of the mesh (list of points with a triangle encoded in each)
77
78                HRESULT setVertexFormat(DWORD fvf, LPDIRECT3DDEVICE9 device);   //!< rebuild D3D to have differnet vertex format
79
80        };
81        //! private method that loads a mesh and its textures
82        void loadMesh(LPCWSTR fileName);
83
84        //! private method to load a texture
85        LPDIRECT3DTEXTURE9 loadTexture(LPCWSTR fileName);
86
87        //! release material texture resources
88        void releaseTextures();
89        //! release mesh resources
90        void releaseMeshes();
91        //! release entities
92        void releaseEntities();
93
94        //! struct that represents a virtual world object: a mesh and a model-world transformation matrix
95        friend struct Entity;
96        struct Entity
97        {
98                HREEffect* owner;       //!< enclosing class instance
99
100                Mesh*   mesh;           //!< mesh
101                D3DXMATRIX      modelWorldTransform;    //!< modeling transform
102                D3DXMATRIX      inverseTransposedModelWorldTransform;   //!< IT modeling transform for surface normal transformation
103        };
104
105        //! vector of loaded meshes
106        std::vector<Mesh*>      meshes;
107        //! vector of loaded textures (textures specified in mesh's material will be loaded here)
108        std::vector<LPDIRECT3DTEXTURE9> materialTextures;
109        //! vector of virtual world objects
110        std::vector<Entity> entities;
111
112        //! for materials with no texture we will render with this texture
113        LPDIRECT3DTEXTURE9              emptyTexture;
114
115        //! render a full-screen quad
116        static void drawFullScreenQuad(LPDIRECT3DDEVICE9 device, float depth = 0.0f, float fLeftU=0.0f, float fTopV=0.0f, float fRightU=1.0f, float fBottomV=1.0f);
117
118                //! clever enum for supported final rendering methods
119        class Method{
120                unsigned int mid;
121                Method(unsigned int mid) {this->mid = mid;}
122                static const wchar_t * methodNames[10];
123        public:
124                Method(const Method& o) {mid = o.mid;}
125                const Method& operator=(const Method& o) {mid = o.mid; return *this;}
126                bool operator==(const Method& o) const {return mid == o.mid;}
127                bool operator!=(const Method& o) const {return mid != o.mid;}
128                const static Method RAYENGINE;
129                const static Method LAST;
130                const Method& next() {mid = (mid + 1)%LAST.mid; return *this;}
131                const Method& prev() {mid = (mid + LAST.mid - 1)%LAST.mid; return *this;}
132                const wchar_t* getName() {return methodNames[mid];}
133        }method;
134public:
135        void nextMethod() {method.next();}
136        void prevMethod() {method.prev();}
137        const wchar_t* getCurrentMethodName() {return method.getName();}
138
139        //! constructor: allocates all resources
140        HREEffect(LPDIRECT3DDEVICE9 device);
141        //! destructor: releases all resources
142        ~HREEffect(void);
143
144        //! renders the scene using the currently selected method
145        void render();
146
147        //! moves the virtual world objects (camera, light)
148        void move(float fElapsedTime);
149
150        LRESULT handleMessage( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
151
152        //! adds controls for the user-adjustable application parameters
153        static void addUiParameters(Parameters* parameters);
154
155        LPDIRECT3DDEVICE9 getDevice() {return device;}
156};
Note: See TracBrowser for help on using the repository browser.