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         void detachRenderTargetImpl(const String& name);
    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
    00231         virtual RenderTarget * detachRenderTarget(const String &name);
    00232
    00233         const String& getName(void) const;
    00234         // Low-level overridden members
    00235         void setConfigOption( const String &name, const String &value );
    00236         void reinitialise();
    00237         void shutdown();
    00238         void setAmbientLight( float r, float g, float b );
    00239         void setShadingType( ShadeOptions so );
    00240         void setLightingEnabled( bool enabled );
    00241         void destroyRenderTarget(const String& name);
    00242         VertexElementType getColourVertexElementType(void) const;
    00243         void setStencilCheckEnabled(bool enabled);
    00244         void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
    00245             uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
    00246             StencilOperation stencilFailOp = SOP_KEEP,
    00247             StencilOperation depthFailOp = SOP_KEEP,
    00248             StencilOperation passOp = SOP_KEEP,
    00249             bool twoSidedOperation = false);
    00250         void setNormaliseNormals(bool normalise);
    00251
    00252         virtual String getErrorDescription(long errorNumber) const;
    00253
    00254         // Low-level overridden members, mainly for internal use
    00255         D3D11HLSLProgram* _getBoundVertexProgram() const;
    00256         D3D11HLSLProgram* _getBoundFragmentProgram() const;
    00257         D3D11HLSLProgram* _getBoundGeometryProgram() const;
    00258         void _useLights(const LightList& lights, unsigned short limit);
    00259         void _setWorldMatrix( const Matrix4 &m );
    00260         void _setViewMatrix( const Matrix4 &m );
    00261         void _setProjectionMatrix( const Matrix4 &m );
    00262         void _setSurfaceParams( const ColourValue &ambient, const ColourValue &diffuse, const ColourValue &specular, const ColourValue &emissive, Real shininess, TrackVertexColourType tracking );
    00263         void _setPointSpritesEnabled(bool enabled);
    00264         void _setPointParameters(Real size, bool attenuationEnabled,
    00265             Real constant, Real linear, Real quadratic, Real minSize, Real maxSize);
    00266         void _setTexture(size_t unit, bool enabled, const TexturePtr &texPtr);
    00267         void _setVertexTexture(size_t unit, const TexturePtr& tex);
    00268         void _disableTextureUnit(size_t texUnit);
    00269         void _setTextureCoordSet( size_t unit, size_t index );
    00270         void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m,
    00271             const Frustum* frustum = 0);
    00272         void _setTextureBlendMode( size_t unit, const LayerBlendModeEx& bm );
    00273         void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
    00274         void _setTextureBorderColour(size_t stage, const ColourValue& colour);
    00275         void _setTextureMipmapBias(size_t unit, float bias);
    00276         void _setTextureMatrix( size_t unit, const Matrix4 &xform );
    00277         void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op = SBO_ADD);
    00278         void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha,
    00279             SceneBlendFactor destFactorAlpha, SceneBlendOperation op = SBO_ADD, SceneBlendOperation alphaOp = SBO_ADD);
    00280         void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
    00281         void _setViewport( Viewport *vp );
    00282         void _beginFrame(void);
    00283         void _endFrame(void);
    00284         void _setCullingMode( CullingMode mode );
    00285         void _setDepthBufferParams( bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL );
    00286         void _setDepthBufferCheckEnabled( bool enabled = true );
    00287         bool _getDepthBufferCheckEnabled( void );
    00288         void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
    00289         void _setDepthBufferWriteEnabled(bool enabled = true);
    00290         void _setDepthBufferFunction( CompareFunction func = CMPF_LESS_EQUAL );
    00291         void _setDepthBias(float constantBias, float slopeScaleBias);
    00292         void _setFog( FogMode mode = FOG_NONE, const ColourValue& colour = ColourValue::White, Real expDensity = 1.0, Real linearStart = 0.0, Real linearEnd = 1.0 );
    00293         void _convertProjectionMatrix(const Matrix4& matrix,
    00294             Matrix4& dest, bool forGpuProgram = false);
    00295         void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
    00296             Matrix4& dest, bool forGpuProgram = false);
    00297         void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, Real nearPlane,
    00298             Real farPlane, Matrix4& dest, bool forGpuProgram = false);
    00299         void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
    00300             Matrix4& dest, bool forGpuProgram = false);
    00301         void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
    00302             bool forGpuProgram);
    00303         void _setPolygonMode(PolygonMode level);
    00304         void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
    00305         void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
    00306         void setVertexDeclaration(VertexDeclaration* decl);
    00307         void setVertexDeclaration(VertexDeclaration* decl, VertexBufferBinding* binding);
    00308         void setVertexBufferBinding(VertexBufferBinding* binding);
    00309         void _render(const RenderOperation& op);
    00313         void bindGpuProgram(GpuProgram* prg);
    00317         void unbindGpuProgram(GpuProgramType gptype);
    00321         void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask);
    00325         void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
    00326
    00327         void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
    00328         void clearFrameBuffer(unsigned int buffers,
    00329             const ColourValue& colour = ColourValue::Black,
    00330             Real depth = 1.0f, unsigned short stencil = 0);
    00331         void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
    00332         void enableClipPlane (ushort index, bool enable);
    00333         HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
    00334         Real getHorizontalTexelOffset(void);
    00335         Real getVerticalTexelOffset(void);
    00336         Real getMinimumDepthInputValue(void);
    00337         Real getMaximumDepthInputValue(void);
    00338         void registerThread();
    00339         void unregisterThread();
    00340         void preExtraThreadsStarted();
    00341         void postExtraThreadsStarted();
    00342
    00346         void _setRenderTarget(RenderTarget *target);
    00347
    00351         bool _checkTextureFilteringSupported(TextureType ttype, PixelFormat format, int usage);
    00352
    00353         void determineFSAASettings(uint fsaa, const String& fsaaHint, DXGI_FORMAT format, DXGI_SAMPLE_DESC* outFSAASettings);
    00354
    00356         unsigned int getDisplayMonitorCount() const {return 1;} //todo
    00357
    00359         virtual void beginProfileEvent( const String &eventName );
    00360
    00362         virtual void endProfileEvent( void );
    00363
    00365         virtual void markProfileEvent( const String &eventName );
    00366
    00367     };
    00368 }
    00369 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:21