1 // 2 // Copyright (c) 2008-2017 the Urho3D project. 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a copy 5 // of this software and associated documentation files (the "Software"), to deal 6 // in the Software without restriction, including without limitation the rights 7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 // copies of the Software, and to permit persons to whom the Software is 9 // furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 // THE SOFTWARE. 21 // 22 23 #pragma once 24 25 #include "../../Graphics/ShaderProgram.h" 26 #include "../../Graphics/VertexDeclaration.h" 27 #include "../../Math/Color.h" 28 29 #include <d3d9.h> 30 31 namespace Urho3D 32 { 33 34 #define URHO3D_SAFE_RELEASE(p) if (p) { ((IUnknown*)p)->Release(); p = 0; } 35 36 #define URHO3D_LOGD3DERROR(msg, hr) URHO3D_LOGERRORF("%s (HRESULT %x)", msg, (unsigned)hr) 37 38 typedef HashMap<Pair<ShaderVariation*, ShaderVariation*>, SharedPtr<ShaderProgram> > ShaderProgramMap; 39 typedef HashMap<unsigned long long, SharedPtr<VertexDeclaration> > VertexDeclarationMap; 40 41 /// %Graphics implementation. Holds API-specific objects. 42 class URHO3D_API GraphicsImpl 43 { 44 friend class Graphics; 45 46 public: 47 /// Construct. 48 GraphicsImpl(); 49 50 /// Return Direct3D device. GetDevice()51 IDirect3DDevice9* GetDevice() const { return device_; } 52 53 /// Return device capabilities. GetDeviceCaps()54 const D3DCAPS9& GetDeviceCaps() const { return deviceCaps_; } 55 56 /// Return adapter identifier. GetAdapterIdentifier()57 const D3DADAPTER_IDENTIFIER9& GetAdapterIdentifier() const { return adapterIdentifier_; } 58 59 /// Return whether a texture format and usage is supported. 60 bool CheckFormatSupport(D3DFORMAT format, DWORD usage, D3DRESOURCETYPE type); 61 62 /// Return whether a multisample level is supported. 63 bool CheckMultiSampleSupport(D3DFORMAT format, int level); 64 65 private: 66 /// Direct3D interface. 67 IDirect3D9* interface_; 68 /// Direct3D device. 69 IDirect3DDevice9* device_; 70 /// Default color surface. 71 IDirect3DSurface9* defaultColorSurface_; 72 /// Default depth-stencil surface. 73 IDirect3DSurface9* defaultDepthStencilSurface_; 74 /// Frame query for flushing the GPU command queue. 75 IDirect3DQuery9* frameQuery_; 76 /// Adapter number. 77 DWORD adapter_; 78 /// Device type. 79 D3DDEVTYPE deviceType_; 80 /// Device capabilities. 81 D3DCAPS9 deviceCaps_; 82 /// Adapter identifier. 83 D3DADAPTER_IDENTIFIER9 adapterIdentifier_; 84 /// Direct3D presentation parameters. 85 D3DPRESENT_PARAMETERS presentParams_; 86 /// Texture min filter modes in use. 87 D3DTEXTUREFILTERTYPE minFilters_[MAX_TEXTURE_UNITS]; 88 /// Texture mag filter modes in use. 89 D3DTEXTUREFILTERTYPE magFilters_[MAX_TEXTURE_UNITS]; 90 /// Texture mip filter modes in use. 91 D3DTEXTUREFILTERTYPE mipFilters_[MAX_TEXTURE_UNITS]; 92 /// Texture U coordinate addressing modes in use. 93 D3DTEXTUREADDRESS uAddressModes_[MAX_TEXTURE_UNITS]; 94 /// Texture V coordinate addressing modes in use. 95 D3DTEXTUREADDRESS vAddressModes_[MAX_TEXTURE_UNITS]; 96 /// Texture W coordinate addressing modes in use. 97 D3DTEXTUREADDRESS wAddressModes_[MAX_TEXTURE_UNITS]; 98 /// Texture anisotropy setting in use. 99 unsigned maxAnisotropy_[MAX_TEXTURE_UNITS]; 100 /// Texture border colors in use. 101 Color borderColors_[MAX_TEXTURE_UNITS]; 102 /// Device lost flag. 103 bool deviceLost_; 104 /// Frame query issued flag. 105 bool queryIssued_; 106 /// sRGB mode in use. 107 bool sRGBModes_[MAX_TEXTURE_UNITS]; 108 /// sRGB write flag. 109 bool sRGBWrite_; 110 /// Color surfaces in use. 111 IDirect3DSurface9* colorSurfaces_[MAX_RENDERTARGETS]; 112 /// Depth-stencil surface in use. 113 IDirect3DSurface9* depthStencilSurface_; 114 /// Blending enabled flag. 115 DWORD blendEnable_; 116 /// Source blend mode. 117 D3DBLEND srcBlend_; 118 /// Destination blend mode. 119 D3DBLEND destBlend_; 120 /// Blend operation. 121 D3DBLENDOP blendOp_; 122 /// Vertex declarations. 123 VertexDeclarationMap vertexDeclarations_; 124 /// Stream frequencies by vertex buffer. 125 unsigned streamFrequencies_[MAX_VERTEX_STREAMS]; 126 /// Stream offsets by vertex buffer. 127 unsigned streamOffsets_[MAX_VERTEX_STREAMS]; 128 /// Vertex declaration in use. 129 VertexDeclaration* vertexDeclaration_; 130 /// Shader programs. 131 ShaderProgramMap shaderPrograms_; 132 /// Shader program in use. 133 ShaderProgram* shaderProgram_; 134 135 }; 136 137 } 138