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-2013 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         D3D_FEATURE_LEVEL mFeatureLevel;
00061         D3D_FEATURE_LEVEL mMinRequestedFeatureLevel;
00062         D3D_FEATURE_LEVEL mMaxRequestedFeatureLevel;
00064         //int           mpD3D;
00066         D3D11Device     mDevice;
00067         
00068         // Stored options
00069         ConfigOptionMap mOptions;
00070 
00072         HINSTANCE mhInstance;
00073 
00075         D3D11DriverList* mDriverList;
00077         D3D11Driver* mActiveD3DDriver;
00079         bool mUseNVPerfHUD;
00081         bool mPerStageConstantSupport;
00082 
00084 
00085 
00086         D3D11DriverList* getDirect3DDrivers(void);
00087         void refreshD3DSettings(void);
00088         void refreshFSAAOptions(void);
00089         void freeDevice(void);
00090 
00091 //      inline bool compareDecls( D3DVERTEXELEMENT9* pDecl1, D3DVERTEXELEMENT9* pDecl2, size_t size );
00092 
00093 
00094         void initInputDevices(void);
00095         void processInputDevices(void);
00096         
00098         DWORD _getCurrentAnisotropy(size_t unit);
00100         bool _checkMultiSampleQuality(UINT SampleCount, UINT *outQuality, DXGI_FORMAT format);
00101         
00102         D3D11HardwareBufferManager* mHardwareBufferManager;
00103         D3D11GpuProgramManager* mGpuProgramManager;
00104         D3D11HLSLProgramFactory* mHLSLProgramFactory;
00105 
00106         size_t mLastVertexSourceCount;
00107 
00109         RenderSystemCapabilities* createRenderSystemCapabilities() const;
00111         void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
00112 
00113         void convertVertexShaderCaps(RenderSystemCapabilities* rsc) const;
00114         void convertPixelShaderCaps(RenderSystemCapabilities* rsc) const;
00115         void convertGeometryShaderCaps(RenderSystemCapabilities* rsc) const;
00116         void convertHullShaderCaps(RenderSystemCapabilities* rsc) const;
00117         void convertDomainShaderCaps(RenderSystemCapabilities* rsc) const;
00118         void convertComputeShaderCaps(RenderSystemCapabilities* rsc) const;
00119 
00120         bool checkVertexTextureFormats(void);
00121         void detachRenderTargetImpl(const String& name);
00122 
00123         CompareFunction mSceneAlphaRejectFunc; // should be merged with - mBlendDesc
00124         unsigned char mSceneAlphaRejectValue; // should be merged with - mBlendDesc
00125         bool mSceneAlphaToCoverage;
00126 
00127         D3D11_BLEND_DESC mBlendDesc;
00128 
00129         D3D11_RASTERIZER_DESC mRasterizerDesc;
00130 
00131         UINT mStencilRef;
00132         D3D11_DEPTH_STENCIL_DESC mDepthStencilDesc; 
00133 
00134         PolygonMode mPolygonMode;
00135 
00136         FilterOptions FilterMinification[OGRE_MAX_TEXTURE_LAYERS];
00137         FilterOptions FilterMagnification[OGRE_MAX_TEXTURE_LAYERS];
00138         FilterOptions FilterMips[OGRE_MAX_TEXTURE_LAYERS];
00139         bool          CompareEnabled;
00140 
00141         D3D11_RECT mScissorRect;
00142 
00143 
00144         D3D11HLSLProgram* mBoundVertexProgram;
00145         D3D11HLSLProgram* mBoundFragmentProgram;
00146         D3D11HLSLProgram* mBoundGeometryProgram;
00147         D3D11HLSLProgram* mBoundTesselationHullProgram;
00148         D3D11HLSLProgram* mBoundTesselationDomainProgram;
00149         D3D11HLSLProgram* mBoundComputeProgram;
00150 
00151         ID3D11BlendState * mBoundBlendState;
00152         ID3D11RasterizerState * mBoundRasterizer;
00153         ID3D11DepthStencilState * mBoundDepthStencilState;
00154         ID3D11SamplerState * mBoundSamplerStates[OGRE_MAX_TEXTURE_LAYERS];
00155         size_t mBoundSamplerStatesCount;
00156 
00157         ID3D11ShaderResourceView * mBoundTextures[OGRE_MAX_TEXTURE_LAYERS];
00158         size_t mBoundTexturesCount;
00159 
00160         // List of class instances per shader stage
00161         ID3D11ClassInstance* mClassInstances[6][8];
00162 
00163         // Number of class instances per shader stage
00164         UINT mNumClassInstances[6];
00165         
00166         // Store created shader subroutines, to prevent creation and destruction every frame
00167         typedef std::map<String, ID3D11ClassInstance*> ClassInstanceMap;
00168         typedef std::map<String, ID3D11ClassInstance*>::iterator ClassInstanceIterator;
00169         ClassInstanceMap mInstanceMap;
00170 
00172         struct sD3DTextureStageDesc
00173         {
00175             //D3D11Mappings::eD3DTexType texType;
00176             TextureType type;
00178             size_t coordIndex;
00180             TexCoordCalcMethod autoTexCoordType;
00182             const Frustum *frustum; 
00183 
00184             LayerBlendModeEx layerBlendMode;
00185 
00187             ID3D11ShaderResourceView  *pTex;
00188             D3D11_SAMPLER_DESC  samplerDesc;
00189             D3D11_SAMPLER_DESC currentSamplerDesc;
00190             //ID3D11SamplerState * pSampler;
00191             bool used;
00192         } mTexStageDesc[OGRE_MAX_TEXTURE_LAYERS];
00193 
00194 
00195         // What follows is a set of duplicated lists just to make it
00196         // easier to deal with lost devices
00197         
00199         D3D11RenderWindowBase* mPrimaryWindow;
00200 
00201         typedef vector<D3D11RenderWindowBase*>::type SecondaryWindowList;
00202         // List of additional windows after the first (swap chains)
00203         SecondaryWindowList mSecondaryWindows;
00204 
00205         bool mBasicStatesInitialised;
00206         
00207         bool mRenderSystemWasInited;
00208 
00209         IDXGIFactoryN*  mpDXGIFactory;
00210     protected:
00211         void setClipPlanesImpl(const PlaneList& clipPlanes);
00212 
00217         void _setRenderTargetViews();
00218 
00219     public:
00220         // constructor
00221         D3D11RenderSystem( );
00222 
00223         // destructor
00224         ~D3D11RenderSystem();
00225 
00226 
00227         void initRenderSystem();
00228 
00229         virtual void initConfigOptions(void);
00230 
00231         // Overridden RenderSystem functions
00232         ConfigOptionMap& getConfigOptions(void);
00233         String validateConfigOptions(void);
00234         RenderWindow* _initialise( bool autoCreateWindow, const String& windowTitle = "OGRE Render Window"  );
00236         RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height, 
00237             bool fullScreen, const NameValuePairList *miscParams = 0);
00238 
00240         RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height,
00241             TextureType texType = TEX_TYPE_2D, PixelFormat internalFormat = PF_X8R8G8B8, 
00242             const NameValuePairList *miscParams = 0 ); 
00243 
00245         virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
00246 
00247         virtual DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget );
00248 
00254         DepthBuffer* _addManualDepthBuffer( ID3D11DepthStencilView *depthSurface,
00255                                             uint32 width, uint32 height, uint32 fsaa, uint32 fsaaQuality );
00256 
00258         void _removeManualDepthBuffer(DepthBuffer *depthBuffer);
00260         virtual RenderTarget * detachRenderTarget(const String &name);
00261 
00262         const String& getName(void) const;
00263         void getCustomAttribute(const String& name, void* pData);
00264         // Low-level overridden members
00265         void setConfigOption( const String &name, const String &value );
00266         void reinitialise();
00267         void shutdown();
00268         void setAmbientLight( float r, float g, float b );
00269         void setShadingType( ShadeOptions so );
00270         void setLightingEnabled( bool enabled );
00271         void destroyRenderTarget(const String& name);
00272         VertexElementType getColourVertexElementType(void) const;
00273         void setStencilCheckEnabled(bool enabled);
00274         void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
00275             uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF,
00276             StencilOperation stencilFailOp = SOP_KEEP, 
00277             StencilOperation depthFailOp = SOP_KEEP,
00278             StencilOperation passOp = SOP_KEEP, 
00279             bool twoSidedOperation = false);
00280         void setNormaliseNormals(bool normalise);
00281 
00282         virtual String getErrorDescription(long errorNumber) const;
00283 
00284         // Low-level overridden members, mainly for internal use
00285         D3D11HLSLProgram* _getBoundVertexProgram() const;
00286         D3D11HLSLProgram* _getBoundFragmentProgram() const;
00287         D3D11HLSLProgram* _getBoundGeometryProgram() const;
00288         D3D11HLSLProgram* _getBoundTesselationHullProgram() const;
00289         D3D11HLSLProgram* _getBoundTesselationDomainProgram() const;
00290         D3D11HLSLProgram* _getBoundComputeProgram() const;
00291         void _useLights(const LightList& lights, unsigned short limit);
00292         void _setWorldMatrix( const Matrix4 &m );
00293         void _setViewMatrix( const Matrix4 &m );
00294         void _setProjectionMatrix( const Matrix4 &m );
00295         void _setSurfaceParams( const ColourValue &ambient, const ColourValue &diffuse, const ColourValue &specular, const ColourValue &emissive, Real shininess, TrackVertexColourType tracking );
00296         void _setPointSpritesEnabled(bool enabled);
00297         void _setPointParameters(Real size, bool attenuationEnabled, 
00298             Real constant, Real linear, Real quadratic, Real minSize, Real maxSize);
00299         void _setTexture(size_t unit, bool enabled, const TexturePtr &texPtr);
00300         void _setVertexTexture(size_t unit, const TexturePtr& tex);
00301         void _disableTextureUnit(size_t texUnit);
00302         void _setTextureCoordSet( size_t unit, size_t index );
00303         void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m, 
00304             const Frustum* frustum = 0);
00305         void _setTextureBlendMode( size_t unit, const LayerBlendModeEx& bm );
00306         void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
00307         void _setTextureBorderColour(size_t stage, const ColourValue& colour);
00308         void _setTextureMipmapBias(size_t unit, float bias);
00309         void _setTextureMatrix( size_t unit, const Matrix4 &xform );
00310         void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op = SBO_ADD);
00311         void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 
00312             SceneBlendFactor destFactorAlpha, SceneBlendOperation op = SBO_ADD, SceneBlendOperation alphaOp = SBO_ADD);
00313         void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
00314         void _setViewport( Viewport *vp );
00315         void _beginFrame(void);
00316         void _endFrame(void);
00317         void _setCullingMode( CullingMode mode );
00318         void _setDepthBufferParams( bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL );
00319         void _setDepthBufferCheckEnabled( bool enabled = true );
00320         bool _getDepthBufferCheckEnabled( void );
00321         void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
00322         void _setDepthBufferWriteEnabled(bool enabled = true);
00323         void _setDepthBufferFunction( CompareFunction func = CMPF_LESS_EQUAL );
00324         void _setDepthBias(float constantBias, float slopeScaleBias);
00325         void _setFog( FogMode mode = FOG_NONE, const ColourValue& colour = ColourValue::White, Real expDensity = 1.0, Real linearStart = 0.0, Real linearEnd = 1.0 );
00326         void _convertProjectionMatrix(const Matrix4& matrix,
00327             Matrix4& dest, bool forGpuProgram = false);
00328         void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 
00329             Matrix4& dest, bool forGpuProgram = false);
00330         void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, Real nearPlane, 
00331             Real farPlane, Matrix4& dest, bool forGpuProgram = false);
00332         void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 
00333             Matrix4& dest, bool forGpuProgram = false);
00334         void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 
00335             bool forGpuProgram);
00336         void _setPolygonMode(PolygonMode level);
00337         void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
00338         void _setTextureUnitCompareFunction(size_t unit, CompareFunction function);
00339         void _setTextureUnitCompareEnabled(size_t unit, bool compare);
00340         void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
00341         void setVertexDeclaration(VertexDeclaration* decl);
00342         void setVertexDeclaration(VertexDeclaration* decl, VertexBufferBinding* binding);
00343         void setVertexBufferBinding(VertexBufferBinding* binding);
00344         void _render(const RenderOperation& op);
00348         void bindGpuProgram(GpuProgram* prg);
00352         void unbindGpuProgram(GpuProgramType gptype);
00356         void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask);
00360         void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
00361 
00362         void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
00363         void clearFrameBuffer(unsigned int buffers, 
00364             const ColourValue& colour = ColourValue::Black, 
00365             Real depth = 1.0f, unsigned short stencil = 0);
00366         void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
00367         void enableClipPlane (ushort index, bool enable);
00368         HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
00369         Real getHorizontalTexelOffset(void);
00370         Real getVerticalTexelOffset(void);
00371         Real getMinimumDepthInputValue(void);
00372         Real getMaximumDepthInputValue(void);
00373         void registerThread();
00374         void unregisterThread();
00375         void preExtraThreadsStarted();
00376         void postExtraThreadsStarted();
00377 
00381         void _setRenderTarget(RenderTarget *target);
00382 
00386         bool _checkTextureFilteringSupported(TextureType ttype, PixelFormat format, int usage);
00387 
00388         void determineFSAASettings(uint fsaa, const String& fsaaHint, DXGI_FORMAT format, DXGI_SAMPLE_DESC* outFSAASettings);
00389 
00391         unsigned int getDisplayMonitorCount() const {return 1;} //todo
00392 
00394         virtual bool hasAnisotropicMipMapFilter() const { return true; }  
00395 
00396         D3D11Device &_getDevice() { return mDevice; }
00397         
00398         
00399         D3D_FEATURE_LEVEL _getFeatureLevel() const { return mFeatureLevel; }
00400 
00402         void setSubroutine(GpuProgramType gptype, unsigned int slotIndex, const String& subroutineName);
00403         
00405         void setSubroutine(GpuProgramType gptype, const String& slotName, const String& subroutineName);
00406 
00408         virtual void beginProfileEvent( const String &eventName );
00409 
00411         virtual void endProfileEvent( void );
00412 
00414         virtual void markProfileEvent( const String &eventName );
00415     };
00416 }
00417 #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 Mon Jul 27 2020 13:40:41