OgreD3D11RenderSystem.h
Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004 (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 #ifndef __D3D11RENDERSYSTEM_H__
00029 #define __D3D11RENDERSYSTEM_H__
00030 
00031 #include "OgreD3D11Prerequisites.h"
00032 #include "OgreRenderSystem.h"
00033 #include "OgreD3D11Device.h"
00034 #include "OgreD3D11Mappings.h"
00035 
00036 namespace Ogre 
00037 {
00038 #define MAX_LIGHTS 8
00039 
00040     class D3D11DriverList;
00041     class D3D11Driver;
00042 
00046     class D3D11RenderSystem : public RenderSystem
00047     {
00048     private:
00049 
00050         // an enum to define the driver type of d3d11
00051         enum OGRE_D3D11_DRIVER_TYPE
00052         {
00053             DT_HARDWARE, // GPU based
00054             DT_SOFTWARE, // microsoft original (slow) software driver
00055             DT_WARP // microsoft new (faster) software driver - (Windows Advanced Rasterization Platform) - http://msdn.microsoft.com/en-us/library/dd285359.aspx
00056 
00057         };
00058 
00059         OGRE_D3D11_DRIVER_TYPE mDriverType; // d3d11 driver type
00060 
00062         //int           mpD3D;
00064         D3D11Device     mDevice;
00065         
00066         // Stored options
00067         ConfigOptionMap mOptions;
00068 
00070         HINSTANCE mhInstance;
00071 
00073         D3D11DriverList* mDriverList;
00075         D3D11Driver* mActiveD3DDriver;
00077         bool mUseNVPerfHUD;
00079         bool mPerStageConstantSupport;
00080 
00082 
00083 
00084         D3D11DriverList* getDirect3DDrivers(void);
00085         void refreshD3DSettings(void);
00086         void refreshFSAAOptions(void);
00087         void freeDevice(void);
00088 
00089 //      inline bool compareDecls( D3DVERTEXELEMENT9* pDecl1, D3DVERTEXELEMENT9* pDecl2, size_t size );
00090 
00091 
00092         void initInputDevices(void);
00093         void processInputDevices(void);
00094         
00096         DWORD _getCurrentAnisotropy(size_t unit);
00098         bool _checkMultiSampleQuality(UINT SampleCount, UINT *outQuality, DXGI_FORMAT format);
00099         
00100         D3D11HardwareBufferManager* mHardwareBufferManager;
00101         D3D11GpuProgramManager* mGpuProgramManager;
00102         D3D11HLSLProgramFactory* mHLSLProgramFactory;
00103 
00104         size_t mLastVertexSourceCount;
00105 
00107         RenderSystemCapabilities* createRenderSystemCapabilities() const;
00109         void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
00110 
00111         void convertVertexShaderCaps(RenderSystemCapabilities* rsc) const;
00112         void convertPixelShaderCaps(RenderSystemCapabilities* rsc) const;
00113         void convertGeometryShaderCaps(RenderSystemCapabilities* rsc) const;
00114         bool checkVertexTextureFormats(void);
00115 
00116 
00117         CompareFunction mSceneAlphaRejectFunc; // should be merged with - mBlendDesc
00118         unsigned char mSceneAlphaRejectValue; // should be merged with - mBlendDesc
00119         bool mSceneAlphaToCoverage;
00120 
00121         D3D11_BLEND_DESC mBlendDesc;
00122 
00123         D3D11_RASTERIZER_DESC mRasterizerDesc;
00124 
00125         UINT mStencilRef;
00126         D3D11_DEPTH_STENCIL_DESC mDepthStencilDesc; 
00127 
00128         PolygonMode mPolygonMode;
00129 
00130         FilterOptions FilterMinification;
00131         FilterOptions FilterMagnification;
00132         FilterOptions FilterMips;
00133 
00134         D3D11_RECT mScissorRect;
00135 
00136 
00137         D3D11HLSLProgram* mBoundVertexProgram;
00138         D3D11HLSLProgram* mBoundFragmentProgram;
00139         D3D11HLSLProgram* mBoundGeometryProgram;
00140 
00141         ID3D11BlendState * mBoundBlendState;
00142         ID3D11RasterizerState * mBoundRasterizer;
00143         ID3D11DepthStencilState * mBoundDepthStencilState;
00144         ID3D11SamplerState * mBoundSamplerStates[OGRE_MAX_TEXTURE_LAYERS];
00145         size_t mBoundSamplerStatesCount;
00146 
00147         ID3D11ShaderResourceView * mBoundTextures[OGRE_MAX_TEXTURE_LAYERS];
00148         size_t mBoundTexturesCount;
00149 
00150 
00152         struct sD3DTextureStageDesc
00153         {
00155             //D3D11Mappings::eD3DTexType texType;
00156             TextureType type;
00158             size_t coordIndex;
00160             TexCoordCalcMethod autoTexCoordType;
00162             const Frustum *frustum; 
00163 
00164             LayerBlendModeEx layerBlendMode;
00165 
00167             ID3D11ShaderResourceView  *pTex;
00168             D3D11_SAMPLER_DESC  samplerDesc;
00169             D3D11_SAMPLER_DESC currentSamplerDesc;
00170             //ID3D11SamplerState * pSampler;
00171             bool used;
00172         } mTexStageDesc[OGRE_MAX_TEXTURE_LAYERS];
00173 
00174 
00175         // What follows is a set of duplicated lists just to make it
00176         // easier to deal with lost devices
00177         
00179         D3D11RenderWindow* mPrimaryWindow;
00180 
00181         typedef vector<D3D11RenderWindow*>::type SecondaryWindowList;
00182         // List of additional windows after the first (swap chains)
00183         SecondaryWindowList mSecondaryWindows;
00184 
00185         bool mBasicStatesInitialised;
00186         
00187         bool mRenderSystemWasInited;
00188 
00189         IDXGIFactory1*  mpDXGIFactory;
00190     protected:
00191         void setClipPlanesImpl(const PlaneList& clipPlanes);
00192     public:
00193         // constructor
00194         D3D11RenderSystem( HINSTANCE hInstance );
00195 
00196         // destructor
00197         ~D3D11RenderSystem();
00198 
00199 
00200         void initRenderSystem();
00201 
00202         virtual void initConfigOptions(void);
00203 
00204         // Overridden RenderSystem functions
00205         ConfigOptionMap& getConfigOptions(void);
00206         String validateConfigOptions(void);
00207         RenderWindow* _initialise( bool autoCreateWindow, const String& windowTitle = "OGRE Render Window"  );
00209         RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height, 
00210             bool fullScreen, const NameValuePairList *miscParams = 0);
00211 
00213         RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height,
00214             TextureType texType = TEX_TYPE_2D, PixelFormat internalFormat = PF_X8R8G8B8, 
00215             const NameValuePairList *miscParams = 0 ); 
00216 
00218         virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
00219 
00220         virtual DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget );
00221 
00227         DepthBuffer* _addManualDepthBuffer( ID3D11DepthStencilView *depthSurface,
00228                                             uint32 width, uint32 height, uint32 fsaa, uint32 fsaaQuality );
00229 
00230 
00231         const String& getName(void) const;
00232         // Low-level overridden members
00233         void setConfigOption( const String &name, const String &value );
00234         void reinitialise();
00235         void shutdown();
00236         void setAmbientLight( float r, float g, float b );
00237         void setShadingType( ShadeOptions so );
00238         void setLightingEnabled( bool enabled );
00239         void destroyRenderTarget(const String& name);
00240         VertexElementType getColourVertexElementType(void) const;
00241         void setStencilCheckEnabled(bool enabled);
00242         void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
00243             uint32 refValue = 0, uint32 mask = 0xFFFFFFFF, 
00244             StencilOperation stencilFailOp = SOP_KEEP, 
00245             StencilOperation depthFailOp = SOP_KEEP,
00246             StencilOperation passOp = SOP_KEEP, 
00247             bool twoSidedOperation = false);
00248         void setNormaliseNormals(bool normalise);
00249 
00250         virtual String getErrorDescription(long errorNumber) const;
00251 
00252         // Low-level overridden members, mainly for internal use
00253         D3D11HLSLProgram* _getBoundVertexProgram() const;
00254         D3D11HLSLProgram* _getBoundFragmentProgram() const;
00255         D3D11HLSLProgram* _getBoundGeometryProgram() const;
00256         void _useLights(const LightList& lights, unsigned short limit);
00257         void _setWorldMatrix( const Matrix4 &m );
00258         void _setViewMatrix( const Matrix4 &m );
00259         void _setProjectionMatrix( const Matrix4 &m );
00260         void _setSurfaceParams( const ColourValue &ambient, const ColourValue &diffuse, const ColourValue &specular, const ColourValue &emissive, Real shininess, TrackVertexColourType tracking );
00261         void _setPointSpritesEnabled(bool enabled);
00262         void _setPointParameters(Real size, bool attenuationEnabled, 
00263             Real constant, Real linear, Real quadratic, Real minSize, Real maxSize);
00264         void _setTexture(size_t unit, bool enabled, const TexturePtr &texPtr);
00265         void _setVertexTexture(size_t unit, const TexturePtr& tex);
00266         void _disableTextureUnit(size_t texUnit);
00267         void _setTextureCoordSet( size_t unit, size_t index );
00268         void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m, 
00269             const Frustum* frustum = 0);
00270         void _setTextureBlendMode( size_t unit, const LayerBlendModeEx& bm );
00271         void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
00272         void _setTextureBorderColour(size_t stage, const ColourValue& colour);
00273         void _setTextureMipmapBias(size_t unit, float bias);
00274         void _setTextureMatrix( size_t unit, const Matrix4 &xform );
00275         void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op = SBO_ADD);
00276         void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 
00277             SceneBlendFactor destFactorAlpha, SceneBlendOperation op = SBO_ADD, SceneBlendOperation alphaOp = SBO_ADD);
00278         void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
00279         void _setViewport( Viewport *vp );
00280         void _beginFrame(void);
00281         void _endFrame(void);
00282         void _setCullingMode( CullingMode mode );
00283         void _setDepthBufferParams( bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL );
00284         void _setDepthBufferCheckEnabled( bool enabled = true );
00285         bool _getDepthBufferCheckEnabled( void );
00286         void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
00287         void _setDepthBufferWriteEnabled(bool enabled = true);
00288         void _setDepthBufferFunction( CompareFunction func = CMPF_LESS_EQUAL );
00289         void _setDepthBias(float constantBias, float slopeScaleBias);
00290         void _setFog( FogMode mode = FOG_NONE, const ColourValue& colour = ColourValue::White, Real expDensity = 1.0, Real linearStart = 0.0, Real linearEnd = 1.0 );
00291         void _convertProjectionMatrix(const Matrix4& matrix,
00292             Matrix4& dest, bool forGpuProgram = false);
00293         void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 
00294             Matrix4& dest, bool forGpuProgram = false);
00295         void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, Real nearPlane, 
00296             Real farPlane, Matrix4& dest, bool forGpuProgram = false);
00297         void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 
00298             Matrix4& dest, bool forGpuProgram = false);
00299         void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 
00300             bool forGpuProgram);
00301         void _setPolygonMode(PolygonMode level);
00302         void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
00303         void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
00304         void setVertexDeclaration(VertexDeclaration* decl);
00305         void setVertexDeclaration(VertexDeclaration* decl, VertexBufferBinding* binding);
00306         void setVertexBufferBinding(VertexBufferBinding* binding);
00307         void _render(const RenderOperation& op);
00311         void bindGpuProgram(GpuProgram* prg);
00315         void unbindGpuProgram(GpuProgramType gptype);
00319         void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask);
00323         void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
00324 
00325         void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
00326         void clearFrameBuffer(unsigned int buffers, 
00327             const ColourValue& colour = ColourValue::Black, 
00328             Real depth = 1.0f, unsigned short stencil = 0);
00329         void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
00330         void enableClipPlane (ushort index, bool enable);
00331         HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
00332         Real getHorizontalTexelOffset(void);
00333         Real getVerticalTexelOffset(void);
00334         Real getMinimumDepthInputValue(void);
00335         Real getMaximumDepthInputValue(void);
00336         void registerThread();
00337         void unregisterThread();
00338         void preExtraThreadsStarted();
00339         void postExtraThreadsStarted();
00340 
00344         void _setRenderTarget(RenderTarget *target);
00345 
00349         bool _checkTextureFilteringSupported(TextureType ttype, PixelFormat format, int usage);
00350 
00351         void determineFSAASettings(uint fsaa, const String& fsaaHint, DXGI_FORMAT format, DXGI_SAMPLE_DESC* outFSAASettings);
00352 
00354         unsigned int getDisplayMonitorCount() const {return 1;} //todo
00355 
00356     };
00357 }
00358 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 2012 21:48:49