source: OGRE/trunk/ogrenew/RenderSystems/Direct3D9/include/OgreD3D9RenderSystem.h @ 657

Revision 657, 10.8 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://ogre.sourceforge.net/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#ifndef __D3D9RENDERSYSTEM_H__
26#define __D3D9RENDERSYSTEM_H__
27
28#include "OgreD3D9Prerequisites.h"
29#include "OgreString.h"
30#include "OgreStringConverter.h"
31#include "OgreRenderSystem.h"
32#include "OgreD3D9Mappings.h"
33
34#include "OgreNoMemoryMacros.h"
35#include <d3d9.h>
36#include <d3dx9.h>
37#include <dxerr9.h>
38#include "OgreMemoryMacros.h"
39
40namespace Ogre
41{
42#define MAX_LIGHTS 8
43
44        class D3D9DriverList;
45        class D3D9Driver;
46
47        /**
48        Implementation of DirectX9 as a rendering system.
49        */
50        class D3D9RenderSystem : public RenderSystem
51        {
52        private:
53                /// Direct3D
54                LPDIRECT3D9                     mpD3D;
55                /// Direct3D rendering device
56                LPDIRECT3DDEVICE9       mpD3DDevice;
57               
58                // Stored options
59                ConfigOptionMap mOptions;
60                /// full-screen multisampling antialiasing type
61                D3DMULTISAMPLE_TYPE mFSAAType;
62                /// full-screen multisampling antialiasing level
63                DWORD mFSAAQuality;
64
65                /// instance
66                HINSTANCE mhInstance;
67
68                /// List of D3D drivers installed (video cards)
69                D3D9DriverList* mDriverList;
70                /// Currently active driver
71                D3D9Driver* mActiveD3DDriver;
72                /// Device caps.
73                D3DCAPS9 mCaps;
74
75                /// structure holding texture unit settings for every stage
76                struct sD3DTextureStageDesc
77                {
78                        /// the type of the texture
79                        D3D9Mappings::eD3DTexType texType;
80                        /// wich texCoordIndex to use
81                        size_t coordIndex;
82                        /// type of auto tex. calc. used
83                        TexCoordCalcMethod autoTexCoordType;
84            /// Frustum, used if the above is projection
85            const Frustum *frustum;
86                        /// texture
87                        IDirect3DBaseTexture9 *pTex;
88                } mTexStageDesc[OGRE_MAX_TEXTURE_LAYERS];
89
90                // Array of up to 8 lights, indexed as per API
91                // Note that a null value indeicates a free slot
92                Light* mLights[MAX_LIGHTS];
93
94                D3D9DriverList* getDirect3DDrivers(void);
95                void refreshD3DSettings(void);
96                void freeDevice(void);
97
98                inline bool compareDecls( D3DVERTEXELEMENT9* pDecl1, D3DVERTEXELEMENT9* pDecl2, size_t size );
99
100
101                void initInputDevices(void);
102                void processInputDevices(void);
103                void setD3D9Light( size_t index, Light* light );
104               
105                // state management methods, very primitive !!!
106                HRESULT __SetRenderState(D3DRENDERSTATETYPE state, DWORD value);
107                HRESULT __SetSamplerState(DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD value);
108                HRESULT __SetTextureStageState(DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value);
109
110                HRESULT __SetFloatRenderState(D3DRENDERSTATETYPE state, Real value)
111                {
112#if OGRE_DOUBLE_PRECISION == 1
113                        float temp = static_cast<float>(value);
114                        return __SetRenderState(state, *((LPDWORD)(&temp)));
115#else
116                        return __SetRenderState(state, *((LPDWORD)(&value)));
117#endif
118                }
119
120                /// return anisotropy level
121                DWORD _getCurrentAnisotropy(size_t unit);
122                /// check if a FSAA is supported
123                bool _checkMultiSampleQuality(D3DMULTISAMPLE_TYPE type, DWORD *outQuality, D3DFORMAT format, UINT adapterNum, D3DDEVTYPE deviceType, BOOL fullScreen);
124                /// set FSAA
125                void _setFSAA(D3DMULTISAMPLE_TYPE type, DWORD qualityLevel);
126               
127                D3D9HardwareBufferManager* mHardwareBufferManager;
128                D3D9GpuProgramManager* mGpuProgramManager;
129        //D3D9HLSLProgramFactory* mHLSLProgramFactory;
130
131                size_t mLastVertexSourceCount;
132
133
134        /// Internal method for populating the capabilities structure
135        void initCapabilities(void);
136
137        void convertVertexShaderCaps(void);
138        void convertPixelShaderCaps(void);
139
140        unsigned short mCurrentLights;
141        /// Saved last view matrix
142        Matrix4 mViewMatrix;
143
144                // What follows is a set of duplicated lists just to make it
145                // easier to deal with lost devices
146               
147                /// Primary window, the one used to create the device
148                D3D9RenderWindow* mPrimaryWindow;
149
150                typedef std::vector<D3D9RenderWindow*> SecondaryWindowList;
151                // List of additional windows after the first (swap chains)
152                SecondaryWindowList mSecondaryWindows;
153
154                bool mDeviceLost;
155                bool mBasicStatesInitialised;
156
157        public:
158                // constructor
159                D3D9RenderSystem( HINSTANCE hInstance );
160                // destructor
161                ~D3D9RenderSystem();
162
163                virtual void initConfigOptions(void);
164
165                // Overridden RenderSystem functions
166                ConfigOptionMap& getConfigOptions(void);
167                String validateConfigOptions(void);
168                RenderWindow* initialise( bool autoCreateWindow, const String& windowTitle = "OGRE Render Window"  );
169                /// @copydoc RenderSystem::createRenderWindow
170                RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height,
171                        bool fullScreen, const NameValuePairList *miscParams = 0);
172
173                /// @copydoc RenderSystem::createRenderTexture
174                RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height,
175                        TextureType texType = TEX_TYPE_2D, PixelFormat internalFormat = PF_X8R8G8B8,
176                        const NameValuePairList *miscParams = 0 );
177
178                String getErrorDescription( long errorNumber ) const;
179                const String& getName(void) const;
180                // Low-level overridden members
181                void setConfigOption( const String &name, const String &value );
182                void reinitialise();
183                void shutdown();
184                void setAmbientLight( float r, float g, float b );
185                void setShadingType( ShadeOptions so );
186                void setLightingEnabled( bool enabled );
187                void destroyRenderTarget(const String& name);
188                void convertColourValue( const ColourValue& colour, uint32* pDest );
189                void setStencilCheckEnabled(bool enabled);
190        void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
191            uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
192            StencilOperation stencilFailOp = SOP_KEEP,
193            StencilOperation depthFailOp = SOP_KEEP,
194            StencilOperation passOp = SOP_KEEP,
195            bool twoSidedOperation = false);
196        void setNormaliseNormals(bool normalise);
197
198                // Low-level overridden members, mainly for internal use
199        void _useLights(const LightList& lights, unsigned short limit);
200                void _setWorldMatrix( const Matrix4 &m );
201                void _setViewMatrix( const Matrix4 &m );
202                void _setProjectionMatrix( const Matrix4 &m );
203                void _setSurfaceParams( const ColourValue &ambient, const ColourValue &diffuse, const ColourValue &specular, const ColourValue &emissive, Real shininess, TrackVertexColourType tracking );
204                void _setTexture( size_t unit, bool enabled, const String &texname );
205        void _setTextureCoordSet( size_t unit, size_t index );
206        void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m,
207            const Frustum* frustum = 0);
208                void _setTextureBlendMode( size_t unit, const LayerBlendModeEx& bm );
209                void _setTextureAddressingMode( size_t unit, TextureUnitState::TextureAddressingMode tam );
210                void _setTextureMatrix( size_t unit, const Matrix4 &xform );
211                void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor );
212                void _setAlphaRejectSettings( CompareFunction func, unsigned char value );
213                void _setViewport( Viewport *vp );
214                void _beginFrame(void);
215                void _endFrame(void);
216                void _setCullingMode( CullingMode mode );
217                void _setDepthBufferParams( bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL );
218                void _setDepthBufferCheckEnabled( bool enabled = true );
219                void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
220                void _setDepthBufferWriteEnabled(bool enabled = true);
221                void _setDepthBufferFunction( CompareFunction func = CMPF_LESS_EQUAL );
222                void _setDepthBias(ushort bias);
223                void _setFog( FogMode mode = FOG_NONE, const ColourValue& colour = ColourValue::White, Real expDensity = 1.0, Real linearStart = 0.0, Real linearEnd = 1.0 );
224                void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
225            Matrix4& dest, bool forGpuProgram = false);
226                void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, Real nearPlane,
227            Real farPlane, Matrix4& dest, bool forGpuProgram = false);
228                void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
229            Matrix4& dest, bool forGpuProgram = false);
230        void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
231            bool forGpuProgram);
232                void _setRasterisationMode(SceneDetailLevel level);
233        void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
234                void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
235                void setVertexDeclaration(VertexDeclaration* decl);
236                void setVertexBufferBinding(VertexBufferBinding* binding);
237        void _render(const RenderOperation& op);
238        void bindGpuProgram(GpuProgram* prg);
239        void unbindGpuProgram(GpuProgramType gptype);
240        void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params);
241        /** See
242          RenderSystem
243         */
244        void setClipPlanes(const PlaneList& clipPlanes);
245
246        void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
247        void clearFrameBuffer(unsigned int buffers,
248            const ColourValue& colour = ColourValue::Black,
249            Real depth = 1.0f, unsigned short stencil = 0);
250                void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
251                void enableClipPlane (ushort index, bool enable);
252        HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
253        Real getHorizontalTexelOffset(void);
254        Real getVerticalTexelOffset(void);
255        Real getMinimumDepthInputValue(void);
256        Real getMaximumDepthInputValue(void);
257
258                /** D3D specific method to restore a lost device. */
259                void restoreLostDevice(void);
260                /** D3D specific method to return whether the device has been lost. */
261                bool isDeviceLost(void);
262                /** Notify that a device has been lost */
263                void _notifyDeviceLost(void);
264
265
266
267        };
268}
269#endif
Note: See TracBrowser for help on using the repository browser.