DX11GraphicsApi.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. #include "GraphicsApi.h"
  2. #include "TexturModel.h"
  3. #include "TexturList.h"
  4. #include "Bild.h"
  5. #include "Fenster.h"
  6. #include "Shader.h"
  7. #include "DXBuffer.h"
  8. #include "Textur.h"
  9. #include "Globals.h"
  10. #include "DLLRegister.h"
  11. #include "UIVertexShader.h"
  12. #include "UIPixelShader.h"
  13. #include "Kam3D.h"
  14. #include "Welt3D.h"
  15. #include "Model3DList.h"
  16. #include <d3d11.h>
  17. #include <dxgi1_5.h>
  18. using namespace Framework;
  19. struct TexturEffect
  20. {
  21. bool enabled;
  22. float percentage;
  23. };
  24. DirectX11::DirectX11()
  25. : GraphicsApi( DIRECTX11 ),
  26. d3d11Device( 0 ),
  27. d3d11Context( 0 ),
  28. d3d11SpawChain( 0 ),
  29. uiTextur( 0 ),
  30. vertexShader( 0 ),
  31. pixelShader( 0 ),
  32. sampleState( 0 ),
  33. rtview( 0 ),
  34. dsView( 0 ),
  35. depthStencilBuffer( 0 ),
  36. depthStencilState( 0 ),
  37. depthDisabledStencilState( 0 ),
  38. blendStateAlphaBlend( 0 ),
  39. vp( 0 ),
  40. texturModel( 0 ),
  41. texturRegister( new TexturList() ),
  42. texturRS( 0 ),
  43. meshRS( 0 ),
  44. defaultTextur( 0 ),
  45. diffuseLights( 0 ),
  46. pointLights( 0 )
  47. {}
  48. DirectX11::~DirectX11()
  49. {
  50. if( diffuseLights )
  51. diffuseLights->release();
  52. if( pointLights )
  53. pointLights->release();
  54. if( defaultTextur )
  55. defaultTextur->release();
  56. if( texturRS )
  57. texturRS->Release();
  58. if( meshRS )
  59. meshRS->Release();
  60. if( texturModel )
  61. texturModel->release();
  62. texturRegister->release();
  63. if( blendStateAlphaBlend )
  64. {
  65. blendStateAlphaBlend->Release();
  66. blendStateAlphaBlend = NULL;
  67. }
  68. if( uiTextur )
  69. {
  70. uiTextur->release();
  71. uiTextur = NULL;
  72. }
  73. if( sampleState )
  74. {
  75. sampleState->Release();
  76. sampleState = NULL;
  77. }
  78. if( pixelShader )
  79. {
  80. pixelShader->release();
  81. pixelShader = NULL;
  82. }
  83. if( vertexShader )
  84. {
  85. vertexShader->release();
  86. vertexShader = NULL;
  87. }
  88. if( depthDisabledStencilState )
  89. {
  90. depthDisabledStencilState->Release();
  91. depthDisabledStencilState = NULL;
  92. }
  93. delete vp;
  94. vp = 0;
  95. if( dsView )
  96. {
  97. dsView->Release();
  98. dsView = NULL;
  99. }
  100. if( depthStencilState )
  101. {
  102. depthStencilState->Release();
  103. depthStencilState = NULL;
  104. }
  105. if( depthStencilBuffer )
  106. {
  107. depthStencilBuffer->Release();
  108. depthStencilBuffer = NULL;
  109. }
  110. if( rtview )
  111. {
  112. rtview->Release();
  113. rtview = NULL;
  114. }
  115. if( d3d11SpawChain )
  116. {
  117. d3d11SpawChain->Release();
  118. d3d11SpawChain = NULL;
  119. }
  120. if( d3d11Device )
  121. {
  122. d3d11Device->Release();
  123. d3d11Device = NULL;
  124. }
  125. if( d3d11Context )
  126. {
  127. d3d11Context->Release();
  128. d3d11Context = NULL;
  129. getDLLRegister()->releaseDLL( "d3d11.dll" );
  130. }
  131. }
  132. typedef HRESULT( __stdcall* D3D11CreateDeviceAndSwapChainFunction )(IDXGIAdapter*, D3D_DRIVER_TYPE,
  133. HMODULE, UINT, const D3D_FEATURE_LEVEL*,
  134. UINT, UINT, const DXGI_SWAP_CHAIN_DESC*,
  135. IDXGISwapChain**, ID3D11Device**,
  136. D3D_FEATURE_LEVEL*, ID3D11DeviceContext**);
  137. void DirectX11::initialize( WFenster* fenster, Vec2<int> backBufferSize, bool fullScreen )
  138. {
  139. if( d3d11Device )
  140. return GraphicsApi::initialize( fenster, backBufferSize, fullScreen );
  141. GraphicsApi::initialize( fenster, backBufferSize, fullScreen );
  142. //--------------------------------------------------------------------
  143. // Create Device
  144. HINSTANCE dll = getDLLRegister()->ladeDLL( "d3d11.dll", "d3d11.dll" );
  145. if( !dll )
  146. {
  147. WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht gefunden werden." ), MB_ICONERROR );
  148. return;
  149. }
  150. D3D11CreateDeviceAndSwapChainFunction createDeviceAndSwapChain = (D3D11CreateDeviceAndSwapChainFunction)GetProcAddress( dll, "D3D11CreateDeviceAndSwapChain" );
  151. if( !createDeviceAndSwapChain )
  152. {
  153. getDLLRegister()->releaseDLL( "d3d11.dll" );
  154. WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "Der Einstiegspunkt D3D11CreateDeviceAndSwapChain fon DirectX 11 konnte nicht gefunden werden." ), MB_ICONERROR );
  155. return;
  156. }
  157. // create a struct to hold information about the swap chain
  158. DXGI_SWAP_CHAIN_DESC scd;
  159. // clear out the struct for use
  160. ZeroMemory( &scd, sizeof( DXGI_SWAP_CHAIN_DESC ) );
  161. scd.Windowed = !fullScreen;
  162. scd.BufferCount = 2;
  163. scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  164. scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
  165. scd.SampleDesc.Count = 1; //multisampling setting
  166. scd.SampleDesc.Quality = 0; //vendor-specific flag
  167. scd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
  168. scd.OutputWindow = fenster ? fenster->getFensterHandle() : 0;
  169. scd.BufferDesc.Width = this->backBufferSize.x;
  170. scd.BufferDesc.Height = this->backBufferSize.y; // windowed/full-screen mode
  171. D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
  172. D3D_FEATURE_LEVEL support = D3D_FEATURE_LEVEL_11_0;
  173. // create a device, device context and swap chain using the information in the scd struct
  174. UINT flag = 0;
  175. #ifdef _DEBUG
  176. if( debugDX )
  177. flag |= D3D11_CREATE_DEVICE_DEBUG;
  178. #endif
  179. HRESULT result = createDeviceAndSwapChain( NULL,
  180. D3D_DRIVER_TYPE_HARDWARE,
  181. NULL,
  182. flag,
  183. &featureLevel,
  184. 1,
  185. D3D11_SDK_VERSION,
  186. &scd,
  187. &d3d11SpawChain,
  188. &d3d11Device,
  189. &support,
  190. &d3d11Context );
  191. if( result != S_OK )
  192. {
  193. getDLLRegister()->releaseDLL( "d3d11.dll" );
  194. std::cout << "ERROR: D3D11CreateDeviceAndSwapChain returned " << result << "\n";
  195. WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
  196. return;
  197. }
  198. ID3D11Texture2D* backBufferPtr;
  199. // Get the pointer to the back buffer.
  200. result = d3d11SpawChain->GetBuffer( 0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferPtr );
  201. if( result != S_OK )
  202. {
  203. std::cout << "ERROR: d3d11SpawChain->GetBuffer returned " << result << "\n";
  204. WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
  205. return;
  206. }
  207. vp = new D3D11_VIEWPORT();
  208. memset( vp, 0, sizeof( D3D11_VIEWPORT ) );
  209. vp->Width = (float)this->backBufferSize.x;
  210. vp->Height = (float)this->backBufferSize.y;
  211. vp->MinDepth = 0.0f;
  212. vp->MaxDepth = 1.0f;
  213. d3d11Context->RSSetViewports( 1, vp );
  214. // Create the render target view with the back buffer pointer.
  215. result = d3d11Device->CreateRenderTargetView( backBufferPtr, NULL, &rtview );
  216. if( result != S_OK )
  217. {
  218. std::cout << "ERROR: d3d11Device->CreateRenderTargetView returned " << result << "\n";
  219. WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
  220. return;
  221. }
  222. // Release pointer to the back buffer as we no longer need it.
  223. backBufferPtr->Release();
  224. // Initialize the description of the depth buffer.
  225. D3D11_TEXTURE2D_DESC depthBufferDesc;
  226. ZeroMemory( &depthBufferDesc, sizeof( depthBufferDesc ) );
  227. // Set up the description of the depth buffer.
  228. depthBufferDesc.Width = this->backBufferSize.x;
  229. depthBufferDesc.Height = this->backBufferSize.y;
  230. depthBufferDesc.MipLevels = 1;
  231. depthBufferDesc.ArraySize = 1;
  232. depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
  233. depthBufferDesc.SampleDesc.Count = 1;
  234. depthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
  235. depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
  236. // Create the texture for the depth buffer using the filled out description.
  237. result = d3d11Device->CreateTexture2D( &depthBufferDesc, NULL, &depthStencilBuffer );
  238. if( result != S_OK )
  239. {
  240. std::cout << "ERROR: d3d11Device->CreateTexture2D returned " << result << "\n";
  241. WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
  242. return;
  243. }
  244. // Initialize the description of the stencil state.
  245. D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
  246. ZeroMemory( &depthStencilDesc, sizeof( depthStencilDesc ) );
  247. // Set up the description of the stencil state.
  248. depthStencilDesc.DepthEnable = true;
  249. depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
  250. depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
  251. depthStencilDesc.StencilEnable = true;
  252. depthStencilDesc.StencilReadMask = 0xFF;
  253. depthStencilDesc.StencilWriteMask = 0xFF;
  254. // Stencil operations if pixel is front-facing.
  255. depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
  256. depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
  257. depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
  258. depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
  259. // Stencil operations if pixel is back-facing.
  260. depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
  261. depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
  262. depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
  263. depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
  264. // Create the depth stencil state.
  265. result = d3d11Device->CreateDepthStencilState( &depthStencilDesc, &depthStencilState );
  266. if( result != S_OK )
  267. {
  268. std::cout << "ERROR: d3d11Device->CreateDepthStencilState returned " << result << "\n";
  269. WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
  270. return;
  271. }
  272. d3d11Context->OMSetDepthStencilState( depthStencilState, 1 );
  273. // Initialize the depth stencil view.
  274. D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
  275. ZeroMemory( &depthStencilViewDesc, sizeof( depthStencilViewDesc ) );
  276. // Set up the depth stencil view description.
  277. depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
  278. depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
  279. // Create the depth stencil view.
  280. result = d3d11Device->CreateDepthStencilView( depthStencilBuffer, &depthStencilViewDesc, &dsView );
  281. if( result != S_OK )
  282. {
  283. std::cout << "ERROR: d3d11Device->CreateDepthStencilView returned " << result << "\n";
  284. WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
  285. return;
  286. }
  287. d3d11Context->OMSetRenderTargets( 1, &rtview, dsView );
  288. D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
  289. // Clear the second depth stencil state before setting the parameters.
  290. ZeroMemory( &depthDisabledStencilDesc, sizeof( depthDisabledStencilDesc ) );
  291. // Now create a second depth stencil state which turns off the Z buffer for 2D rendering. The only difference is
  292. // that DepthEnable is set to false, all other parameters are the same as the other depth stencil state.
  293. depthDisabledStencilDesc.DepthEnable = false;
  294. depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
  295. depthDisabledStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
  296. depthDisabledStencilDesc.StencilEnable = true;
  297. depthDisabledStencilDesc.StencilReadMask = 0xFF;
  298. depthDisabledStencilDesc.StencilWriteMask = 0xFF;
  299. depthDisabledStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
  300. depthDisabledStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
  301. depthDisabledStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
  302. depthDisabledStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
  303. depthDisabledStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
  304. depthDisabledStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
  305. depthDisabledStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
  306. depthDisabledStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
  307. // Create the state using the device.
  308. result = d3d11Device->CreateDepthStencilState( &depthDisabledStencilDesc, &depthDisabledStencilState );
  309. if( result != S_OK )
  310. {
  311. std::cout << "ERROR: d3d11Device->CreateDepthStencilState returned " << result << "\n";
  312. WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
  313. return;
  314. }
  315. //-------------------------------------------------
  316. // Shaders
  317. vertexShader = new DX11VertexShader( d3d11Device, d3d11Context );
  318. vertexShader->setCompiledByteArray( (unsigned char*)UIVertexShader, sizeof( UIVertexShader ) );
  319. pixelShader = new DX11PixelShader( d3d11Device, d3d11Context );
  320. pixelShader->setCompiledByteArray( (unsigned char*)UIPixelShader, sizeof( UIPixelShader ) );
  321. D3D11_INPUT_ELEMENT_DESC polygonLayout[ 4 ];
  322. // Create the vertex input layout description.
  323. // This setup needs to match the VertexType stucture in the ModelClass and in the shader.
  324. polygonLayout[ 0 ].SemanticName = "POSITION";
  325. polygonLayout[ 0 ].SemanticIndex = 0;
  326. polygonLayout[ 0 ].Format = DXGI_FORMAT_R32G32B32_FLOAT;
  327. polygonLayout[ 0 ].InputSlot = 0;
  328. polygonLayout[ 0 ].AlignedByteOffset = 0;
  329. polygonLayout[ 0 ].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
  330. polygonLayout[ 0 ].InstanceDataStepRate = 0;
  331. polygonLayout[ 1 ].SemanticName = "TEXCOORD";
  332. polygonLayout[ 1 ].SemanticIndex = 0;
  333. polygonLayout[ 1 ].Format = DXGI_FORMAT_R32G32_FLOAT;
  334. polygonLayout[ 1 ].InputSlot = 0;
  335. polygonLayout[ 1 ].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
  336. polygonLayout[ 1 ].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
  337. polygonLayout[ 1 ].InstanceDataStepRate = 0;
  338. polygonLayout[ 2 ].SemanticName = "NORMAL";
  339. polygonLayout[ 2 ].SemanticIndex = 0;
  340. polygonLayout[ 2 ].Format = DXGI_FORMAT_R32G32B32_FLOAT;
  341. polygonLayout[ 2 ].InputSlot = 0;
  342. polygonLayout[ 2 ].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
  343. polygonLayout[ 2 ].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
  344. polygonLayout[ 2 ].InstanceDataStepRate = 0;
  345. polygonLayout[ 3 ].SemanticName = "KNOCHEN_ID";
  346. polygonLayout[ 3 ].SemanticIndex = 0;
  347. polygonLayout[ 3 ].Format = DXGI_FORMAT_R32_UINT;
  348. polygonLayout[ 3 ].InputSlot = 0;
  349. polygonLayout[ 3 ].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
  350. polygonLayout[ 3 ].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
  351. polygonLayout[ 3 ].InstanceDataStepRate = 0;
  352. vertexShader->erstelleInputLayout( polygonLayout, 4 );
  353. vertexShader->erstelleConstBuffer( sizeof( Mat4< float > ) * MAX_KNOCHEN_ANZ, 0 ); // matrizen für skelett annimationen
  354. vertexShader->erstelleConstBuffer( sizeof( Mat4< float > ) * 2, 1 ); // View and Projection Matrix
  355. pixelShader->erstelleConstBuffer( sizeof( float ) * 3, 0 ); // Kamera Position
  356. pixelShader->erstelleConstBuffer( sizeof( float ) * 3, 1 ); // materialkonstanten nach phong model
  357. pixelShader->erstelleConstBuffer( sizeof( int ) * 2, 2 );
  358. pixelShader->erstelleConstBuffer( sizeof( TexturEffect ), 3 );
  359. // TODO: Remove Following Test Code
  360. int lc[] = { 0, 0 };
  361. pixelShader->füllConstBuffer( (char*)lc, 2, sizeof( int ) * 2 );
  362. TexturEffect e = { 0, 0.f };
  363. pixelShader->füllConstBuffer( (char*)&e, 3, sizeof( TexturEffect ) );
  364. // Create a texture sampler state description.
  365. D3D11_SAMPLER_DESC samplerDesc;
  366. samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
  367. samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
  368. samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
  369. samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
  370. samplerDesc.MipLODBias = 0.0f;
  371. samplerDesc.MaxAnisotropy = 1;
  372. samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
  373. samplerDesc.BorderColor[ 0 ] = 0;
  374. samplerDesc.BorderColor[ 1 ] = 0;
  375. samplerDesc.BorderColor[ 2 ] = 0;
  376. samplerDesc.BorderColor[ 3 ] = 0;
  377. samplerDesc.MinLOD = 0;
  378. samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
  379. // Create the texture sampler state.
  380. result = d3d11Device->CreateSamplerState( &samplerDesc, &sampleState );
  381. if( result != S_OK )
  382. {
  383. std::cout << "ERROR: d3d11Device->CreateSamplerState returned " << result << "\n";
  384. WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
  385. return;
  386. }
  387. //---------------------------------------------------------------
  388. // Framework Backbuffer Texture
  389. Bild* renderB = new Bild( 1 );
  390. renderB->setAlpha3D( 1 );
  391. renderB->neuBild( this->backBufferSize.x, this->backBufferSize.y, 0 );
  392. uiTextur = createOrGetTextur( "_f_Render_Bild", renderB );
  393. texturModel = new TexturModel( this );
  394. texturModel->setSize( this->backBufferSize );
  395. texturModel->setTextur( dynamic_cast<Textur*>(uiTextur->getThis()) );
  396. D3D11_BLEND_DESC blendState;
  397. ZeroMemory( &blendState, sizeof( D3D11_BLEND_DESC ) );
  398. blendState.AlphaToCoverageEnable = false;
  399. blendState.IndependentBlendEnable = false;
  400. blendState.RenderTarget[ 0 ].BlendEnable = true;
  401. blendState.RenderTarget[ 0 ].SrcBlend = D3D11_BLEND_SRC_ALPHA;
  402. blendState.RenderTarget[ 0 ].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
  403. blendState.RenderTarget[ 0 ].BlendOp = D3D11_BLEND_OP_ADD;
  404. blendState.RenderTarget[ 0 ].SrcBlendAlpha = D3D11_BLEND_ZERO;
  405. blendState.RenderTarget[ 0 ].DestBlendAlpha = D3D11_BLEND_ONE;
  406. blendState.RenderTarget[ 0 ].BlendOpAlpha = D3D11_BLEND_OP_ADD;
  407. blendState.RenderTarget[ 0 ].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
  408. d3d11Device->CreateBlendState( &blendState, &blendStateAlphaBlend );
  409. d3d11Context->OMSetBlendState( blendStateAlphaBlend, 0, 0xFFFFFFFF );
  410. // Setup Render Objekt
  411. vertexShader->benutzeShader();
  412. d3d11Context->PSSetSamplers( 0, 1, &sampleState );
  413. pixelShader->benutzeShader();
  414. D3D11_RASTERIZER_DESC rasterDesc;
  415. ZeroMemory( &rasterDesc, sizeof( rasterDesc ) );
  416. rasterDesc.AntialiasedLineEnable = false;
  417. rasterDesc.CullMode = D3D11_CULL_BACK;
  418. rasterDesc.DepthBiasClamp = 0.0f;
  419. rasterDesc.DepthClipEnable = true;
  420. rasterDesc.FillMode = D3D11_FILL_SOLID;
  421. rasterDesc.FrontCounterClockwise = false;
  422. rasterDesc.MultisampleEnable = false;
  423. rasterDesc.ScissorEnable = false;
  424. rasterDesc.SlopeScaledDepthBias = 0.0f;
  425. d3d11Device->CreateRasterizerState( &rasterDesc, &texturRS );
  426. ZeroMemory( &rasterDesc, sizeof( rasterDesc ) );
  427. rasterDesc.AntialiasedLineEnable = false;
  428. rasterDesc.CullMode = D3D11_CULL_BACK;
  429. rasterDesc.DepthBiasClamp = 0.0f;
  430. rasterDesc.DepthClipEnable = true;
  431. rasterDesc.FillMode = D3D11_FILL_WIREFRAME;
  432. rasterDesc.FrontCounterClockwise = false;
  433. rasterDesc.MultisampleEnable = false;
  434. rasterDesc.ScissorEnable = false;
  435. rasterDesc.SlopeScaledDepthBias = 0.0f;
  436. d3d11Device->CreateRasterizerState( &rasterDesc, &meshRS );
  437. d3d11Context->RSSetState( texturRS );
  438. Bild* b = new Bild();
  439. b->neuBild( 10, 10, 0xFFFFFFFF );
  440. defaultTextur = createOrGetTextur( "_default_textur", b );
  441. diffuseLights = new DX11StructuredBuffer( sizeof( DiffuseLight ), d3d11Device, d3d11Context );
  442. pointLights = new DX11StructuredBuffer( sizeof( PointLight ), d3d11Device, d3d11Context );
  443. }
  444. void DirectX11::update()
  445. {
  446. modelList->removeAll();
  447. if( texturModel )
  448. {
  449. texturModel->release();
  450. texturModel = 0;
  451. }
  452. if( pointLights )
  453. pointLights = (DX11StructuredBuffer*)pointLights->release();
  454. if( diffuseLights )
  455. diffuseLights = (DX11StructuredBuffer*)diffuseLights->release();
  456. if( texturRS )
  457. {
  458. texturRS->Release();
  459. texturRS = NULL;
  460. }
  461. if( meshRS )
  462. {
  463. meshRS->Release();
  464. meshRS = NULL;
  465. }
  466. texturRegister->leeren();
  467. if( defaultTextur )
  468. defaultTextur = (Textur*)defaultTextur->release();
  469. if( blendStateAlphaBlend )
  470. {
  471. blendStateAlphaBlend->Release();
  472. blendStateAlphaBlend = NULL;
  473. }
  474. if( uiTextur )
  475. {
  476. uiTextur->release();
  477. uiTextur = NULL;
  478. }
  479. if( sampleState )
  480. {
  481. sampleState->Release();
  482. sampleState = NULL;
  483. }
  484. if( pixelShader )
  485. {
  486. pixelShader->release();
  487. pixelShader = NULL;
  488. }
  489. if( vertexShader )
  490. {
  491. vertexShader->release();
  492. vertexShader = NULL;
  493. }
  494. if( depthDisabledStencilState )
  495. {
  496. depthDisabledStencilState->Release();
  497. depthDisabledStencilState = NULL;
  498. }
  499. delete vp;
  500. vp = 0;
  501. if( dsView )
  502. {
  503. dsView->Release();
  504. dsView = NULL;
  505. }
  506. if( depthStencilState )
  507. {
  508. depthStencilState->Release();
  509. depthStencilState = NULL;
  510. }
  511. if( depthStencilBuffer )
  512. {
  513. depthStencilBuffer->Release();
  514. depthStencilBuffer = NULL;
  515. }
  516. if( rtview )
  517. {
  518. rtview->Release();
  519. rtview = NULL;
  520. }
  521. if( d3d11SpawChain )
  522. {
  523. d3d11SpawChain->Release();
  524. d3d11SpawChain = NULL;
  525. }
  526. if( d3d11Device )
  527. {
  528. d3d11Device->Release();
  529. d3d11Device = NULL;
  530. }
  531. if( d3d11Context )
  532. {
  533. d3d11Context->Release();
  534. d3d11Context = NULL;
  535. }
  536. initialize( dynamic_cast<WFenster*>(fenster->getThis()), backBufferSize, fullScreen );
  537. }
  538. void DirectX11::beginFrame( bool fill2D, bool fill3D, int fillColor )
  539. {
  540. if( fill2D )
  541. uiTextur->zBild()->setFarbe( fillColor );
  542. if( fill3D || true )
  543. {
  544. float color[ 4 ];
  545. // Setup the color to clear the buffer.
  546. color[ 0 ] = ((fillColor >> 16) & 0xFF) / 255.f; // R
  547. color[ 1 ] = ((fillColor >> 8) & 0xFF) / 255.f; // G
  548. color[ 2 ] = (fillColor & 0xFF) / 255.f; // B
  549. color[ 3 ] = ((fillColor >> 24) & 0xFF) / 255.f; // A
  550. d3d11Context->ClearRenderTargetView( rtview, color );
  551. }
  552. // Clear the depth buffer.
  553. d3d11Context->ClearDepthStencilView( dsView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1, 0 );
  554. // Bind the render target view and depth stencil buffer to the output render pipeline.
  555. d3d11Context->OMSetRenderTargets( 1, &rtview, dsView );
  556. // Set the depth stencil state.
  557. d3d11Context->OMSetDepthStencilState( depthStencilState, 1 );
  558. }
  559. void DirectX11::renderObject( Model3D* zObj )
  560. {
  561. if( !zObj->zModelData() )
  562. return;
  563. int curId = zObj->zModelData()->getId();
  564. zObj->zModelData()->zDXVertexBuffer()->copieren();
  565. zObj->zModelData()->zDXIndexBuffer()->copieren();
  566. Mat4< float > trans = Mat4< float >::identity();
  567. int anz = zObj->errechneMatrizen( trans, matrixBuffer );
  568. if( vertexShader )
  569. vertexShader->füllConstBuffer( (char*)matrixBuffer, 0, sizeof( Mat4< float > ) * anz );
  570. float matirialBuffer[ 3 ]; // light factors (phong model)
  571. matirialBuffer[ 0 ] = zObj->getAmbientFactor();
  572. matirialBuffer[ 1 ] = zObj->getDiffusFactor();
  573. matirialBuffer[ 2 ] = zObj->getSpecularFactor();
  574. if( pixelShader )
  575. pixelShader->füllConstBuffer( (char*)matirialBuffer, 1, sizeof( float ) * 3 );
  576. unsigned int offset = 0;
  577. unsigned int es = (unsigned)zObj->zModelData()->zDXVertexBuffer()->getElementLength();
  578. ID3D11Buffer* vBuffer = ((DX11Buffer*)zObj->zModelData()->zDXVertexBuffer())->zBuffer();
  579. d3d11Context->IASetVertexBuffers( 0, 1, &vBuffer, &es, &offset );
  580. Model3DTextur* zTextur = zObj->zTextur();
  581. int ind = 0;
  582. int current = 0;
  583. if( zObj->zEffectTextur() )
  584. {
  585. ID3D11ShaderResourceView* v[ 1 ];
  586. DX11Textur* zEffectTextur = (DX11Textur*)zObj->zEffectTextur();
  587. if( zEffectTextur && zEffectTextur->brauchtUpdate() )
  588. zEffectTextur->updateTextur();
  589. v[ 0 ] = *zEffectTextur;
  590. d3d11Context->PSSetShaderResources( 3, 1, v );
  591. TexturEffect e = { 1, zObj->getEffectPercentage() };
  592. if( pixelShader )
  593. pixelShader->füllConstBuffer( (char*)&e, 3, sizeof( TexturEffect ) );
  594. }
  595. else
  596. {
  597. TexturEffect e = { 0, 0.f };
  598. if( pixelShader )
  599. pixelShader->füllConstBuffer( (char*)&e, 3, sizeof( TexturEffect ) );
  600. }
  601. for( auto i = zObj->zModelData()->getPolygons(); i; i++ )
  602. {
  603. if( zObj->needRenderPolygon( ind ) )
  604. {
  605. Textur* t = zTextur->zPolygonTextur( ind );
  606. if( t && t->brauchtUpdate() )
  607. t->updateTextur();
  608. DXGI_FORMAT f = DXGI_FORMAT_R32_UINT;
  609. if( zObj->zModelData()->zDXIndexBuffer()->getElementLength() == 2 )
  610. f = DXGI_FORMAT_R16_UINT;
  611. if( zObj->zModelData()->zDXIndexBuffer()->getElementLength() == 1 )
  612. f = DXGI_FORMAT_R8_UINT;
  613. d3d11Context->IASetIndexBuffer( ((DX11Buffer*)zObj->zModelData()->zDXIndexBuffer())->zBuffer(), f, 0 );
  614. d3d11Context->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
  615. if( t )
  616. {
  617. ID3D11ShaderResourceView* v[ 3 ];
  618. v[ 0 ] = *(DX11Textur*)t;
  619. v[ 1 ] = *diffuseLights;
  620. v[ 2 ] = *pointLights;
  621. d3d11Context->PSSetShaderResources( 0, 3, v );
  622. d3d11Context->DrawIndexed( i->indexAnz, current, 0 );
  623. }
  624. else
  625. {
  626. d3d11Context->RSSetState( meshRS );
  627. ID3D11ShaderResourceView* v[ 3 ];
  628. v[ 0 ] = *(DX11Textur*)defaultTextur;
  629. v[ 1 ] = *diffuseLights;
  630. v[ 2 ] = *pointLights;
  631. d3d11Context->PSSetShaderResources( 0, 3, v );
  632. d3d11Context->DrawIndexed( i->indexAnz, current, 0 );
  633. d3d11Context->RSSetState( texturRS );
  634. }
  635. }
  636. ind++;
  637. current += i->indexAnz;
  638. }
  639. }
  640. // Überprüft, ob eine Kugel in dem Sichtbaren Raum der Welt liegt und gezeichnet werden muss
  641. // pos: Der Mittelpunkt der Kugel
  642. // radius: Der Radius der Kugel
  643. // dist: Einen Zeiger auf einen float, in dem das quadrat des Abstands zur Kammeraposition gespeichert wird, falls diese Funktion true zurückgiebt und der Zeiger nicht 0 ist
  644. bool DirectX11::isInFrustrum( const Vec3< float >& pos, float radius, float* dist ) const
  645. {
  646. for( int i = 0; i < 6; i++ )
  647. {
  648. if( frustrum[ i ] * pos + radius < 0 )
  649. return 0;
  650. }
  651. if( dist )
  652. *dist = kamPos.abstand( pos );
  653. return 1;
  654. }
  655. void DirectX11::renderKamera( Kam3D* zKamera )
  656. {
  657. d3d11Context->RSSetViewports( 1, (D3D11_VIEWPORT*)zKamera->zViewPort() );
  658. Mat4< float > tmp = zKamera->getProjectionMatrix() * zKamera->getViewMatrix();
  659. frustrum[ 0 ].x = tmp.elements[ 3 ][ 0 ] + tmp.elements[ 0 ][ 0 ];
  660. frustrum[ 0 ].y = tmp.elements[ 3 ][ 1 ] + tmp.elements[ 0 ][ 1 ];
  661. frustrum[ 0 ].z = tmp.elements[ 3 ][ 2 ] + tmp.elements[ 0 ][ 2 ];
  662. frustrum[ 0 ].w = tmp.elements[ 3 ][ 3 ] + tmp.elements[ 0 ][ 3 ];
  663. frustrum[ 1 ].x = tmp.elements[ 3 ][ 0 ] - tmp.elements[ 0 ][ 0 ];
  664. frustrum[ 1 ].y = tmp.elements[ 3 ][ 1 ] - tmp.elements[ 0 ][ 1 ];
  665. frustrum[ 1 ].z = tmp.elements[ 3 ][ 2 ] - tmp.elements[ 0 ][ 2 ];
  666. frustrum[ 1 ].w = tmp.elements[ 3 ][ 3 ] - tmp.elements[ 0 ][ 3 ];
  667. frustrum[ 2 ].x = tmp.elements[ 3 ][ 0 ] - tmp.elements[ 1 ][ 0 ];
  668. frustrum[ 2 ].y = tmp.elements[ 3 ][ 1 ] - tmp.elements[ 1 ][ 1 ];
  669. frustrum[ 2 ].z = tmp.elements[ 3 ][ 2 ] - tmp.elements[ 1 ][ 2 ];
  670. frustrum[ 2 ].w = tmp.elements[ 3 ][ 3 ] - tmp.elements[ 1 ][ 3 ];
  671. frustrum[ 3 ].x = tmp.elements[ 3 ][ 0 ] + tmp.elements[ 1 ][ 0 ];
  672. frustrum[ 3 ].y = tmp.elements[ 3 ][ 1 ] + tmp.elements[ 1 ][ 1 ];
  673. frustrum[ 3 ].z = tmp.elements[ 3 ][ 2 ] + tmp.elements[ 1 ][ 2 ];
  674. frustrum[ 3 ].w = tmp.elements[ 3 ][ 3 ] + tmp.elements[ 1 ][ 3 ];
  675. frustrum[ 4 ].x = tmp.elements[ 2 ][ 0 ];
  676. frustrum[ 4 ].y = tmp.elements[ 2 ][ 1 ];
  677. frustrum[ 4 ].z = tmp.elements[ 2 ][ 2 ];
  678. frustrum[ 4 ].w = tmp.elements[ 2 ][ 3 ];
  679. frustrum[ 5 ].x = tmp.elements[ 3 ][ 0 ] - tmp.elements[ 2 ][ 0 ];
  680. frustrum[ 5 ].y = tmp.elements[ 3 ][ 1 ] - tmp.elements[ 2 ][ 1 ];
  681. frustrum[ 5 ].z = tmp.elements[ 3 ][ 2 ] - tmp.elements[ 2 ][ 2 ];
  682. frustrum[ 5 ].w = tmp.elements[ 3 ][ 3 ] - tmp.elements[ 2 ][ 3 ];
  683. for( int i = 0; i < 6; i++ )
  684. frustrum[ i ].normalize();
  685. viewAndProj[ 0 ] = zKamera->getViewMatrix();
  686. viewAndProj[ 1 ] = zKamera->getProjectionMatrix();
  687. kamPos = zKamera->getWorldPosition();
  688. if( vertexShader )
  689. vertexShader->füllConstBuffer( (char*)viewAndProj, 1, sizeof( Mat4< float > ) * 2 );
  690. if( pixelShader )
  691. pixelShader->füllConstBuffer( (char*)&kamPos, 0, sizeof( float ) * 3 );
  692. Welt3D* w = zKamera->zWelt();
  693. w->lock();
  694. int lc[] = { w->getDiffuseLightCount(), w->getPointLightCount() };
  695. pixelShader->füllConstBuffer( (char*)lc, 2, sizeof( int ) * 2 );
  696. w->copyLight( diffuseLights, pointLights );
  697. int maxDist = 0;
  698. int minDist = 0x7FFFFFFF;
  699. Model3DIterator* iterator = w->getIterator();
  700. Array<Model3D*> alphaModels;
  701. while( iterator->hasNext() )
  702. {
  703. Model3D* obj = iterator->getNext();
  704. float dist;
  705. if( isInFrustrum( obj->getPos(), obj->getRadius(), &dist ) )
  706. {
  707. if( (int)dist > maxDist )
  708. maxDist = (int)dist;
  709. if( (int)dist < minDist )
  710. minDist = (int)dist;
  711. if( obj->hatAlpha() )
  712. alphaModels.add( obj );
  713. else
  714. renderObject( obj );
  715. }
  716. }
  717. iterator->release();
  718. maxDist++;
  719. if( alphaModels.getEintragAnzahl() )
  720. {
  721. int size = maxDist - minDist;
  722. int* index = new int[ size ];
  723. memset( index, 0, size * 4 );
  724. Model3D** sorted = new Model3D * [ size * alphaModels.getEintragAnzahl() ];
  725. for( auto obj : alphaModels )
  726. {
  727. float dist;
  728. dist = kamPos.abstand( obj->getPos() );
  729. if( isInFrustrum( obj->getPos(), obj->getRadius(), &dist ) )
  730. {
  731. int pos = (int)dist - minDist;
  732. sorted[ pos * alphaModels.getEintragAnzahl() + index[ pos ]++ ] = obj;
  733. }
  734. }
  735. for( int i = 0; i < size; i++ )
  736. {
  737. for( int j = 0; j < index[ i ]; j++ )
  738. {
  739. renderObject( sorted[ i * alphaModels.getEintragAnzahl() + j ] );
  740. }
  741. }
  742. delete[] index;
  743. delete[] sorted;
  744. }
  745. w->unlock();
  746. }
  747. void DirectX11::presentFrame()
  748. {
  749. // Set the depth stencil state.
  750. d3d11Context->OMSetDepthStencilState( depthDisabledStencilState, 1 );
  751. uiTextur->updateTextur();
  752. d3d11Context->RSSetViewports( 1, vp );
  753. float screenAspect = (float)backBufferSize.x / (float)backBufferSize.y;
  754. Mat4< float > view = view.translation( Vec3< float >( 0.f, 0.f, backBufferSize.y * 1.2075f ) );
  755. viewAndProj[ 0 ] = view;
  756. viewAndProj[ 1 ] = view.projektion( (float)PI / 4.0f, screenAspect, 0.1f, 10000.f );
  757. kamPos = Vec3< float >( 0.f, 0.f, backBufferSize.y * 1.2075f );
  758. if( vertexShader )
  759. vertexShader->füllConstBuffer( (char*)viewAndProj, 1, sizeof( Mat4< float > ) * 2 );
  760. if( pixelShader )
  761. pixelShader->füllConstBuffer( (char*)&kamPos, 0, sizeof( float ) * 3 );
  762. if( fenster && !IsIconic( fenster->getFensterHandle() ) )
  763. renderObject( texturModel );
  764. HRESULT result = d3d11SpawChain->Present( 0, 0 );
  765. if( !SUCCEEDED( result ) )
  766. {
  767. update();
  768. WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
  769. }
  770. }
  771. Bild* DirectX11::zUIRenderBild() const
  772. {
  773. return uiTextur->zBild();
  774. }
  775. Textur* DirectX11::createOrGetTextur( const char* name, Bild* b )
  776. {
  777. if( !d3d11Device )
  778. {
  779. if( b )
  780. b->release();
  781. return 0;
  782. }
  783. if( texturRegister->hatTextur( name ) )
  784. {
  785. Textur* ret = texturRegister->getTextur( name );
  786. if( b )
  787. ret->setBildZ( b );
  788. return ret;
  789. }
  790. Textur* ret = new DX11Textur( d3d11Device, d3d11Context );
  791. if( b )
  792. ret->setBildZ( b );
  793. texturRegister->addTextur( dynamic_cast<Textur*>(ret->getThis()), name );
  794. return ret;
  795. }
  796. typedef HRESULT( __stdcall* CreateDXGIFactory2Function )(UINT, REFIID, void**);
  797. typedef HRESULT( __stdcall* D3D11CreateDeviceFunction )(IDXGIAdapter*, D3D_DRIVER_TYPE, HMODULE, UINT, D3D_FEATURE_LEVEL*,
  798. UINT, UINT, ID3D11Device**, D3D_FEATURE_LEVEL*, ID3D11DeviceContext**);
  799. bool DirectX11::isAvailable()
  800. {
  801. HINSTANCE dxgiDLL = getDLLRegister()->ladeDLL( "dxgi.dll", "dxgi.dll" );
  802. if( !dxgiDLL )
  803. return 0;
  804. HINSTANCE d3d11DLL = getDLLRegister()->ladeDLL( "d3d11.dll", "d3d11.dll" );
  805. if( !d3d11DLL )
  806. {
  807. getDLLRegister()->releaseDLL( "dxgi.dll" );
  808. return 0;
  809. }
  810. CreateDXGIFactory2Function createFactory = (CreateDXGIFactory2Function)GetProcAddress( dxgiDLL, "CreateDXGIFactory2" );
  811. if( !createFactory )
  812. {
  813. getDLLRegister()->releaseDLL( "dxgi.dll" );
  814. getDLLRegister()->releaseDLL( "d3d11.dll" );
  815. return 0;
  816. }
  817. D3D11CreateDeviceFunction createDevice = (D3D11CreateDeviceFunction)GetProcAddress( d3d11DLL, "D3D11CreateDevice" );
  818. if( !createDevice )
  819. {
  820. getDLLRegister()->releaseDLL( "dxgi.dll" );
  821. getDLLRegister()->releaseDLL( "d3d11.dll" );
  822. return 0;
  823. }
  824. IDXGIFactory4* factory;
  825. UINT createFactoryFlags = 0;
  826. #if defined(_DEBUG)
  827. createFactoryFlags = DXGI_CREATE_FACTORY_DEBUG;
  828. #endif
  829. HRESULT res = createFactory( createFactoryFlags, __uuidof(IDXGIFactory4), (void**)&factory );
  830. if( FAILED( res ) )
  831. {
  832. getDLLRegister()->releaseDLL( "dxgi.dll" );
  833. getDLLRegister()->releaseDLL( "d3d11.dll" );
  834. return 0;
  835. }
  836. int index = 0;
  837. UINT flag = 0;
  838. #ifdef _DEBUG
  839. flag |= D3D11_CREATE_DEVICE_DEBUG;
  840. #endif
  841. do
  842. {
  843. IDXGIAdapter1* current;
  844. res = factory->EnumAdapters1( index++, &current );
  845. if( res == S_OK )
  846. {
  847. DXGI_ADAPTER_DESC1 dxgiAdapterDesc1;
  848. current->GetDesc1( &dxgiAdapterDesc1 );
  849. ID3D11Device* device = 0;
  850. ID3D11DeviceContext* context = 0;
  851. D3D_FEATURE_LEVEL level = D3D_FEATURE_LEVEL_11_0;
  852. if( (dxgiAdapterDesc1.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) == 0 &&
  853. SUCCEEDED( createDevice( current, D3D_DRIVER_TYPE_UNKNOWN, 0, flag, &level, 1, D3D11_SDK_VERSION, &device, 0, &context ) ) )
  854. {
  855. context->Release();
  856. device->Release();
  857. current->Release();
  858. factory->Release();
  859. getDLLRegister()->releaseDLL( "dxgi.dll" );
  860. getDLLRegister()->releaseDLL( "d3d11.dll" );
  861. return 1;
  862. }
  863. current->Release();
  864. }
  865. } while( res != DXGI_ERROR_NOT_FOUND );
  866. factory->Release();
  867. getDLLRegister()->releaseDLL( "dxgi.dll" );
  868. getDLLRegister()->releaseDLL( "d3d11.dll" );
  869. return 0;
  870. }
  871. DXBuffer* DirectX11::createIndexBuffer()
  872. {
  873. return new DX11Buffer( sizeof( int ), d3d11Device, d3d11Context, D3D11_BIND_INDEX_BUFFER );
  874. }
  875. DXBuffer* DirectX11::createVertexBuffer()
  876. {
  877. return new DX11Buffer( sizeof( Vertex3D ), d3d11Device, d3d11Context, D3D11_BIND_VERTEX_BUFFER );
  878. }