|
@@ -1,22 +1,10 @@
|
|
|
#include "GraphicsApi.h"
|
|
|
#include "Fenster.h"
|
|
|
#include "Bild.h"
|
|
|
-#include "TexturModel.h"
|
|
|
-#include "Textur.h"
|
|
|
-#include "Shader.h"
|
|
|
-#include "Globals.h"
|
|
|
-#include "UIVertexShader.h"
|
|
|
-#include "UIPixelShader.h"
|
|
|
-#include "TexturList.h"
|
|
|
-#include "Kam3D.h"
|
|
|
-#include "DLLRegister.h"
|
|
|
-#include "Welt3D.h"
|
|
|
-#include "Model2D.h"
|
|
|
-#include "DXBuffer.h"
|
|
|
-#include <d3d11.h>
|
|
|
-#include <d3d9.h>
|
|
|
|
|
|
using namespace Framework;
|
|
|
+
|
|
|
+
|
|
|
GraphicsApi::GraphicsApi( GraphicApiType typ )
|
|
|
{
|
|
|
this->typ = typ;
|
|
@@ -37,6 +25,8 @@ void GraphicsApi::initialize( WFenster * fenster, Vec2<int> backBufferSize, bool
|
|
|
if( this->fenster )
|
|
|
this->fenster->release();
|
|
|
this->fenster = fenster;
|
|
|
+ if( !backBufferSize.x || !backBufferSize.y )
|
|
|
+ backBufferSize = fenster ? fenster->getKörperGröße() : Punkt( 0, 0 );
|
|
|
this->backBufferSize = backBufferSize;
|
|
|
this->fullScreen = fullScreen;
|
|
|
}
|
|
@@ -92,1008 +82,4 @@ GraphicsApi *GraphicsApi::release()
|
|
|
if( !--ref )
|
|
|
delete this;
|
|
|
return 0;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-DirectX9::DirectX9()
|
|
|
- : GraphicsApi( DIRECTX9 ),
|
|
|
- pDirect3D( 0 ),
|
|
|
- pDevice( 0 ),
|
|
|
- pBackBuffer( 0 ),
|
|
|
- backRect( new D3DLOCKED_RECT() )
|
|
|
-{
|
|
|
- uiBild = new Bild( 1 );
|
|
|
-}
|
|
|
-
|
|
|
-DirectX9::~DirectX9()
|
|
|
-{
|
|
|
- backRect->pBits = NULL;
|
|
|
- delete backRect;
|
|
|
- if( pBackBuffer )
|
|
|
- {
|
|
|
- pBackBuffer->Release();
|
|
|
- pBackBuffer = NULL;
|
|
|
- }
|
|
|
- if( pDevice )
|
|
|
- {
|
|
|
- pDevice->Release();
|
|
|
- pDevice = NULL;
|
|
|
- }
|
|
|
- if( pDirect3D )
|
|
|
- {
|
|
|
- pDirect3D->Release();
|
|
|
- pDirect3D = NULL;
|
|
|
- }
|
|
|
- uiBild->release();
|
|
|
-}
|
|
|
-
|
|
|
-typedef IDirect3D9 *( *D3D9CreateFunction )( UINT );
|
|
|
-
|
|
|
-void DirectX9::initialize( WFenster * fenster, Vec2<int> backBufferSize, bool fullScreen )
|
|
|
-{
|
|
|
- if( pDirect3D )
|
|
|
- return GraphicsApi::initialize( fenster, backBufferSize, fullScreen );
|
|
|
- GraphicsApi::initialize( fenster, backBufferSize, fullScreen );
|
|
|
-
|
|
|
- HINSTANCE dll = getDLLRegister()->ladeDLL( "d3d9.dll", "d3d9.dll" );
|
|
|
- if( !dll )
|
|
|
- {
|
|
|
- WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 9 konnte nicht gefunden werden." ), MB_ICONERROR );
|
|
|
- return;
|
|
|
- }
|
|
|
- D3D9CreateFunction direct3DCreate9 = (D3D9CreateFunction)GetProcAddress( dll, "Direct3DCreate9" );
|
|
|
- if( !direct3DCreate9 )
|
|
|
- {
|
|
|
- WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "Der Einstiegspunkt Direct3DCreate9 fon DirectX 9 konnte nicht gefunden werden." ), MB_ICONERROR );
|
|
|
- return;
|
|
|
- }
|
|
|
- pDirect3D = direct3DCreate9( D3D_SDK_VERSION );
|
|
|
-
|
|
|
- D3DPRESENT_PARAMETERS d3dpp;
|
|
|
- ZeroMemory( &d3dpp, sizeof( d3dpp ) );
|
|
|
- d3dpp.Windowed = !fullScreen;
|
|
|
- d3dpp.hDeviceWindow = fenster->getFensterHandle();
|
|
|
- d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
|
|
- d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
|
|
|
- d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
|
|
|
- d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
|
|
|
- if( !backBufferSize.x || !backBufferSize.y )
|
|
|
- backBufferSize = fenster->getKörperGröße();
|
|
|
- d3dpp.BackBufferHeight = backBufferSize.y;
|
|
|
- d3dpp.BackBufferWidth = backBufferSize.x;
|
|
|
-
|
|
|
- uiBild->neuBild( backBufferSize.x, backBufferSize.y, 0xFF000000 );
|
|
|
-
|
|
|
- HRESULT result = pDirect3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, fenster->getFensterHandle(),
|
|
|
- D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &pDevice );
|
|
|
- if( result != S_OK )
|
|
|
- WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 9 konnte nicht initialisiert werden." ), MB_ICONERROR );
|
|
|
- if( pDevice )
|
|
|
- result = pDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
|
|
|
- if( result != S_OK )
|
|
|
- WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 9 konnte nicht initialisiert werden." ), MB_ICONERROR );
|
|
|
-}
|
|
|
-
|
|
|
-void DirectX9::update()
|
|
|
-{
|
|
|
- if( !pDirect3D )
|
|
|
- return;
|
|
|
- backRect->pBits = NULL;
|
|
|
- if( pBackBuffer )
|
|
|
- {
|
|
|
- pBackBuffer->Release();
|
|
|
- pBackBuffer = NULL;
|
|
|
- }
|
|
|
- if( pDevice )
|
|
|
- {
|
|
|
- pDevice->Release();
|
|
|
- pDevice = NULL;
|
|
|
- }
|
|
|
- D3DPRESENT_PARAMETERS d3dpp;
|
|
|
- ZeroMemory( &d3dpp, sizeof( d3dpp ) );
|
|
|
- d3dpp.Windowed = !fullScreen;
|
|
|
- d3dpp.hDeviceWindow = fenster->getFensterHandle();
|
|
|
- d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
|
|
- d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
|
|
|
- d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
|
|
|
- d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
|
|
|
- if( !backBufferSize.x || !backBufferSize.y )
|
|
|
- backBufferSize = fenster->getKörperGröße();
|
|
|
- d3dpp.BackBufferHeight = backBufferSize.y;
|
|
|
- d3dpp.BackBufferWidth = backBufferSize.x;
|
|
|
-
|
|
|
- uiBild->neuBild( backBufferSize.x, backBufferSize.y, 0xFF000000 );
|
|
|
-
|
|
|
- HRESULT result = pDirect3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, fenster->getFensterHandle(),
|
|
|
- D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &pDevice );
|
|
|
- if( result != S_OK )
|
|
|
- WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 9 konnte nicht initialisiert werden." ), MB_ICONERROR );
|
|
|
- if( pDevice )
|
|
|
- result = pDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
|
|
|
- if( result != S_OK )
|
|
|
- WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 9 konnte nicht initialisiert werden." ), MB_ICONERROR );
|
|
|
-}
|
|
|
-
|
|
|
-void DirectX9::beginFrame( bool fill2D, bool fill3D, int fillColor )
|
|
|
-{
|
|
|
- if( fill2D )
|
|
|
- uiBild->setFarbe( fillColor );
|
|
|
-}
|
|
|
-
|
|
|
-void DirectX9::presentFrame()
|
|
|
-{
|
|
|
- if( !uiBild->getBuffer() )
|
|
|
- return;
|
|
|
- HRESULT result;
|
|
|
- result = pBackBuffer->LockRect( backRect, 0, 0 );
|
|
|
- if( result != S_OK )
|
|
|
- {
|
|
|
- WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
|
|
|
- update();
|
|
|
- }
|
|
|
-
|
|
|
- int *bgBuff = uiBild->getBuffer();
|
|
|
- int tmpBr = sizeof( D3DCOLOR ) * uiBild->getBreite();
|
|
|
- for( int y = 0, pitch = 0, bry = 0; y < uiBild->getHeight(); ++y, pitch += backRect->Pitch, bry += uiBild->getBreite() )
|
|
|
- memcpy( &( (BYTE *)backRect->pBits )[ pitch ], ( void * ) & ( bgBuff[ bry ] ), tmpBr );
|
|
|
-
|
|
|
- result = pBackBuffer->UnlockRect();
|
|
|
- if( result != S_OK )
|
|
|
- {
|
|
|
- WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
|
|
|
- update();
|
|
|
- }
|
|
|
- if( result != S_OK )
|
|
|
- {
|
|
|
- WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
|
|
|
- update();
|
|
|
- }
|
|
|
- result = pDevice->Present( 0, 0, 0, 0 );
|
|
|
- if( result != S_OK )
|
|
|
- {
|
|
|
- WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
|
|
|
- update();
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-Bild *DirectX9::zUIRenderBild() const
|
|
|
-{
|
|
|
- return uiBild;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-DirectX11::DirectX11()
|
|
|
- : GraphicsApi( DIRECTX11 ),
|
|
|
- d3d11Device( 0 ),
|
|
|
- d3d11Context( 0 ),
|
|
|
- d3d11SpawChain( 0 ),
|
|
|
- uiTextur( 0 ),
|
|
|
- vertexShader( 0 ),
|
|
|
- pixelShader( 0 ),
|
|
|
- sampleState( 0 ),
|
|
|
- rtview( 0 ),
|
|
|
- dsView( 0 ),
|
|
|
- depthStencilBuffer( 0 ),
|
|
|
- depthStencilState( 0 ),
|
|
|
- depthDisabledStencilState( 0 ),
|
|
|
- blendStateAlphaBlend( 0 ),
|
|
|
- vp( 0 ),
|
|
|
- texturModel( new TexturModel() ),
|
|
|
- texturRegister( new TexturList() ),
|
|
|
- texturRS( 0 ),
|
|
|
- meshRS( 0 ),
|
|
|
- defaultTextur( 0 ),
|
|
|
- diffuseLights( 0 ),
|
|
|
- pointLights( 0 ),
|
|
|
- vertexBuffer( 0 ),
|
|
|
- indexBuffer( 0 )
|
|
|
-{}
|
|
|
-
|
|
|
-DirectX11::~DirectX11()
|
|
|
-{
|
|
|
- if( vertexBuffer )
|
|
|
- vertexBuffer->release();
|
|
|
- if( indexBuffer )
|
|
|
- indexBuffer->release();
|
|
|
- if( diffuseLights )
|
|
|
- diffuseLights->release();
|
|
|
- if( pointLights )
|
|
|
- pointLights->release();
|
|
|
- if( defaultTextur )
|
|
|
- defaultTextur->release();
|
|
|
- if( texturRS )
|
|
|
- texturRS->Release();
|
|
|
- if( meshRS )
|
|
|
- meshRS->Release();
|
|
|
- texturModel->release();
|
|
|
- texturRegister->release();
|
|
|
- if( blendStateAlphaBlend )
|
|
|
- {
|
|
|
- blendStateAlphaBlend->Release();
|
|
|
- blendStateAlphaBlend = NULL;
|
|
|
- }
|
|
|
- if( uiTextur )
|
|
|
- {
|
|
|
- uiTextur->release();
|
|
|
- uiTextur = NULL;
|
|
|
- }
|
|
|
- if( sampleState )
|
|
|
- {
|
|
|
- sampleState->Release();
|
|
|
- sampleState = NULL;
|
|
|
- }
|
|
|
- if( pixelShader )
|
|
|
- {
|
|
|
- pixelShader->release();
|
|
|
- pixelShader = NULL;
|
|
|
- }
|
|
|
- if( vertexShader )
|
|
|
- {
|
|
|
- vertexShader->release();
|
|
|
- vertexShader = NULL;
|
|
|
- }
|
|
|
- if( depthDisabledStencilState )
|
|
|
- {
|
|
|
- depthDisabledStencilState->Release();
|
|
|
- depthDisabledStencilState = NULL;
|
|
|
- }
|
|
|
- delete vp;
|
|
|
- vp = 0;
|
|
|
- if( dsView )
|
|
|
- {
|
|
|
- dsView->Release();
|
|
|
- dsView = NULL;
|
|
|
- }
|
|
|
- if( depthStencilState )
|
|
|
- {
|
|
|
- depthStencilState->Release();
|
|
|
- depthStencilState = NULL;
|
|
|
- }
|
|
|
- if( depthStencilBuffer )
|
|
|
- {
|
|
|
- depthStencilBuffer->Release();
|
|
|
- depthStencilBuffer = NULL;
|
|
|
- }
|
|
|
- if( rtview )
|
|
|
- {
|
|
|
- rtview->Release();
|
|
|
- rtview = NULL;
|
|
|
- }
|
|
|
- if( d3d11SpawChain )
|
|
|
- {
|
|
|
- d3d11SpawChain->Release();
|
|
|
- d3d11SpawChain = NULL;
|
|
|
- }
|
|
|
- if( d3d11Device )
|
|
|
- {
|
|
|
- d3d11Device->Release();
|
|
|
- d3d11Device = NULL;
|
|
|
- }
|
|
|
- if( d3d11Context )
|
|
|
- {
|
|
|
- d3d11Context->Release();
|
|
|
- d3d11Context = NULL;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-typedef HRESULT( *D3D11CreateDeviceAndSwapChainFunction )( IDXGIAdapter *, D3D_DRIVER_TYPE,
|
|
|
- HMODULE, UINT, const D3D_FEATURE_LEVEL *,
|
|
|
- UINT, UINT, const DXGI_SWAP_CHAIN_DESC *,
|
|
|
- IDXGISwapChain * *, ID3D11Device * *,
|
|
|
- D3D_FEATURE_LEVEL *, ID3D11DeviceContext * * );
|
|
|
-
|
|
|
-void DirectX11::initialize( WFenster * fenster, Vec2<int> backBufferSize, bool fullScreen )
|
|
|
-{
|
|
|
- if( d3d11Device )
|
|
|
- return GraphicsApi::initialize( fenster, backBufferSize, fullScreen );
|
|
|
- GraphicsApi::initialize( fenster, backBufferSize, fullScreen );
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- HINSTANCE dll = getDLLRegister()->ladeDLL( "d3d11.dll", "d3d11.dll" );
|
|
|
- if( !dll )
|
|
|
- {
|
|
|
- WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht gefunden werden." ), MB_ICONERROR );
|
|
|
- return;
|
|
|
- }
|
|
|
- D3D11CreateDeviceAndSwapChainFunction createDeviceAndSwapChain = (D3D11CreateDeviceAndSwapChainFunction)GetProcAddress( dll, "D3D11CreateDeviceAndSwapChain" );
|
|
|
- if( !createDeviceAndSwapChain )
|
|
|
- {
|
|
|
- WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "Der Einstiegspunkt D3D11CreateDeviceAndSwapChain fon DirectX 11 konnte nicht gefunden werden." ), MB_ICONERROR );
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- DXGI_SWAP_CHAIN_DESC scd;
|
|
|
-
|
|
|
-
|
|
|
- ZeroMemory( &scd, sizeof( DXGI_SWAP_CHAIN_DESC ) );
|
|
|
-
|
|
|
-
|
|
|
- scd.BufferCount = 1;
|
|
|
- scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
|
|
- scd.OutputWindow = fenster ? fenster->getFensterHandle() : 0;
|
|
|
- scd.SampleDesc.Count = 1;
|
|
|
-
|
|
|
- scd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
|
|
|
- scd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
|
|
|
- scd.Windowed = !fullScreen;
|
|
|
- if( !backBufferSize.x || !backBufferSize.y )
|
|
|
- backBufferSize = fenster ? fenster->getKörperGröße() : Punkt( 0, 0 );
|
|
|
- scd.BufferDesc.Width = backBufferSize.x;
|
|
|
- scd.BufferDesc.Height = backBufferSize.y;
|
|
|
- scd.BufferDesc.RefreshRate.Denominator = 1;
|
|
|
- scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
|
-
|
|
|
- scd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
|
|
-
|
|
|
- D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
|
|
|
- D3D_FEATURE_LEVEL support = D3D_FEATURE_LEVEL_11_0;
|
|
|
-
|
|
|
- UINT flag = 0;
|
|
|
-#ifdef _DEBUG
|
|
|
- flag |= D3D11_CREATE_DEVICE_DEBUG;
|
|
|
-#endif
|
|
|
- HRESULT result = createDeviceAndSwapChain( NULL,
|
|
|
- D3D_DRIVER_TYPE_HARDWARE,
|
|
|
- NULL,
|
|
|
- flag,
|
|
|
- &featureLevel,
|
|
|
- 1,
|
|
|
- D3D11_SDK_VERSION,
|
|
|
- &scd,
|
|
|
- &d3d11SpawChain,
|
|
|
- &d3d11Device,
|
|
|
- &support,
|
|
|
- &d3d11Context );
|
|
|
- if( result != S_OK )
|
|
|
- {
|
|
|
- std::cout << "ERROR: D3D11CreateDeviceAndSwapChain returned " << result << "\n";
|
|
|
- WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
|
|
|
- return;
|
|
|
- }
|
|
|
- ID3D11Texture2D *backBufferPtr;
|
|
|
-
|
|
|
- result = d3d11SpawChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (LPVOID *)& backBufferPtr );
|
|
|
- if( result != S_OK )
|
|
|
- {
|
|
|
- std::cout << "ERROR: d3d11SpawChain->GetBuffer returned " << result << "\n";
|
|
|
- WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- result = d3d11Device->CreateRenderTargetView( backBufferPtr, NULL, &rtview );
|
|
|
- if( result != S_OK )
|
|
|
- {
|
|
|
- std::cout << "ERROR: d3d11Device->CreateRenderTargetView returned " << result << "\n";
|
|
|
- WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- backBufferPtr->Release();
|
|
|
-
|
|
|
- D3D11_TEXTURE2D_DESC depthBufferDesc;
|
|
|
- ZeroMemory( &depthBufferDesc, sizeof( depthBufferDesc ) );
|
|
|
-
|
|
|
- depthBufferDesc.Width = backBufferSize.x;
|
|
|
- depthBufferDesc.Height = backBufferSize.y;
|
|
|
- depthBufferDesc.MipLevels = 1;
|
|
|
- depthBufferDesc.ArraySize = 1;
|
|
|
- depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
|
|
- depthBufferDesc.SampleDesc.Count = 1;
|
|
|
- depthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
|
|
|
- depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
|
|
|
-
|
|
|
- result = d3d11Device->CreateTexture2D( &depthBufferDesc, NULL, &depthStencilBuffer );
|
|
|
- if( result != S_OK )
|
|
|
- {
|
|
|
- std::cout << "ERROR: d3d11Device->CreateTexture2D returned " << result << "\n";
|
|
|
- WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
|
|
|
- ZeroMemory( &depthStencilDesc, sizeof( depthStencilDesc ) );
|
|
|
-
|
|
|
-
|
|
|
- depthStencilDesc.DepthEnable = true;
|
|
|
- depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
|
|
|
- depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
|
|
|
- depthStencilDesc.StencilEnable = true;
|
|
|
- depthStencilDesc.StencilReadMask = 0xFF;
|
|
|
- depthStencilDesc.StencilWriteMask = 0xFF;
|
|
|
-
|
|
|
- depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
|
|
|
- depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
|
|
|
- depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
|
|
- depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
|
|
-
|
|
|
- depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
|
|
|
- depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
|
|
|
- depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
|
|
- depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
|
|
-
|
|
|
- result = d3d11Device->CreateDepthStencilState( &depthStencilDesc, &depthStencilState );
|
|
|
- if( result != S_OK )
|
|
|
- {
|
|
|
- std::cout << "ERROR: d3d11Device->CreateDepthStencilState returned " << result << "\n";
|
|
|
- WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
|
|
|
- return;
|
|
|
- }
|
|
|
- d3d11Context->OMSetDepthStencilState( depthStencilState, 1 );
|
|
|
-
|
|
|
-
|
|
|
- D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
|
|
|
- ZeroMemory( &depthStencilViewDesc, sizeof( depthStencilViewDesc ) );
|
|
|
-
|
|
|
-
|
|
|
- depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
|
|
- depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
|
|
|
-
|
|
|
-
|
|
|
- result = d3d11Device->CreateDepthStencilView( depthStencilBuffer, &depthStencilViewDesc, &dsView );
|
|
|
- if( result != S_OK )
|
|
|
- {
|
|
|
- std::cout << "ERROR: d3d11Device->CreateDepthStencilView returned " << result << "\n";
|
|
|
- WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
|
|
|
- return;
|
|
|
- }
|
|
|
- d3d11Context->OMSetRenderTargets( 1, &rtview, dsView );
|
|
|
-
|
|
|
- vp = new D3D11_VIEWPORT();
|
|
|
- memset( vp, 0, sizeof( D3D11_VIEWPORT ) );
|
|
|
- vp->Width = (float)backBufferSize.x;
|
|
|
- vp->Height = (float)backBufferSize.y;
|
|
|
- vp->MinDepth = 0.0f;
|
|
|
- vp->MaxDepth = 1.0f;
|
|
|
- vp->TopLeftX = 0.0f;
|
|
|
- vp->TopLeftY = 0.0f;
|
|
|
-
|
|
|
- d3d11Context->RSSetViewports( 1, vp );
|
|
|
-
|
|
|
- D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
|
|
|
-
|
|
|
- ZeroMemory( &depthDisabledStencilDesc, sizeof( depthDisabledStencilDesc ) );
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- depthDisabledStencilDesc.DepthEnable = false;
|
|
|
- depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
|
|
|
- depthDisabledStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
|
|
|
- depthDisabledStencilDesc.StencilEnable = true;
|
|
|
- depthDisabledStencilDesc.StencilReadMask = 0xFF;
|
|
|
- depthDisabledStencilDesc.StencilWriteMask = 0xFF;
|
|
|
- depthDisabledStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
|
|
|
- depthDisabledStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
|
|
|
- depthDisabledStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
|
|
- depthDisabledStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
|
|
- depthDisabledStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
|
|
|
- depthDisabledStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
|
|
|
- depthDisabledStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
|
|
- depthDisabledStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
|
|
-
|
|
|
-
|
|
|
- result = d3d11Device->CreateDepthStencilState( &depthDisabledStencilDesc, &depthDisabledStencilState );
|
|
|
- if( result != S_OK )
|
|
|
- {
|
|
|
- std::cout << "ERROR: d3d11Device->CreateDepthStencilState returned " << result << "\n";
|
|
|
- WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- vertexShader = new DX11VertexShader( d3d11Device, d3d11Context );
|
|
|
- vertexShader->setCompiledByteArray( (unsigned char *)UIVertexShader, sizeof( UIVertexShader ) );
|
|
|
-
|
|
|
- pixelShader = new DX11PixelShader( d3d11Device, d3d11Context );
|
|
|
- pixelShader->setCompiledByteArray( (unsigned char *)UIPixelShader, sizeof( UIPixelShader ) );
|
|
|
-
|
|
|
- D3D11_INPUT_ELEMENT_DESC polygonLayout[ 4 ];
|
|
|
-
|
|
|
-
|
|
|
- polygonLayout[ 0 ].SemanticName = "POSITION";
|
|
|
- polygonLayout[ 0 ].SemanticIndex = 0;
|
|
|
- polygonLayout[ 0 ].Format = DXGI_FORMAT_R32G32B32_FLOAT;
|
|
|
- polygonLayout[ 0 ].InputSlot = 0;
|
|
|
- polygonLayout[ 0 ].AlignedByteOffset = 0;
|
|
|
- polygonLayout[ 0 ].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
|
|
|
- polygonLayout[ 0 ].InstanceDataStepRate = 0;
|
|
|
-
|
|
|
- polygonLayout[ 1 ].SemanticName = "TEXCOORD";
|
|
|
- polygonLayout[ 1 ].SemanticIndex = 0;
|
|
|
- polygonLayout[ 1 ].Format = DXGI_FORMAT_R32G32_FLOAT;
|
|
|
- polygonLayout[ 1 ].InputSlot = 0;
|
|
|
- polygonLayout[ 1 ].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
|
|
|
- polygonLayout[ 1 ].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
|
|
|
- polygonLayout[ 1 ].InstanceDataStepRate = 0;
|
|
|
-
|
|
|
- polygonLayout[ 2 ].SemanticName = "NORMAL";
|
|
|
- polygonLayout[ 2 ].SemanticIndex = 0;
|
|
|
- polygonLayout[ 2 ].Format = DXGI_FORMAT_R32G32B32_FLOAT;
|
|
|
- polygonLayout[ 2 ].InputSlot = 0;
|
|
|
- polygonLayout[ 2 ].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
|
|
|
- polygonLayout[ 2 ].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
|
|
|
- polygonLayout[ 2 ].InstanceDataStepRate = 0;
|
|
|
-
|
|
|
- polygonLayout[ 3 ].SemanticName = "KNOCHEN_ID";
|
|
|
- polygonLayout[ 3 ].SemanticIndex = 0;
|
|
|
- polygonLayout[ 3 ].Format = DXGI_FORMAT_R32_UINT;
|
|
|
- polygonLayout[ 3 ].InputSlot = 0;
|
|
|
- polygonLayout[ 3 ].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
|
|
|
- polygonLayout[ 3 ].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
|
|
|
- polygonLayout[ 3 ].InstanceDataStepRate = 0;
|
|
|
-
|
|
|
- vertexShader->erstelleInputLayout( polygonLayout, 4 );
|
|
|
- vertexShader->erstelleConstBuffer( sizeof( Mat4< float > ) * MAX_KNOCHEN_ANZ, 0 );
|
|
|
- vertexShader->erstelleConstBuffer( sizeof( Mat4< float > ) * 2, 1 );
|
|
|
-
|
|
|
- pixelShader->erstelleConstBuffer( sizeof( float ) * 3, 0 );
|
|
|
- pixelShader->erstelleConstBuffer( sizeof( float ) * 3, 1 );
|
|
|
- pixelShader->erstelleConstBuffer( sizeof( int ) * 2, 2 );
|
|
|
-
|
|
|
- int lc[] = { 1, 6 };
|
|
|
- pixelShader->füllConstBuffer( (char *)lc, 2, sizeof( int ) * 2 );
|
|
|
-
|
|
|
-
|
|
|
- D3D11_SAMPLER_DESC samplerDesc;
|
|
|
- samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
|
|
- samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
|
|
- samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
|
|
- samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
|
|
- samplerDesc.MipLODBias = 0.0f;
|
|
|
- samplerDesc.MaxAnisotropy = 1;
|
|
|
- samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
|
|
|
- samplerDesc.BorderColor[ 0 ] = 0;
|
|
|
- samplerDesc.BorderColor[ 1 ] = 0;
|
|
|
- samplerDesc.BorderColor[ 2 ] = 0;
|
|
|
- samplerDesc.BorderColor[ 3 ] = 0;
|
|
|
- samplerDesc.MinLOD = 0;
|
|
|
- samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
|
|
|
-
|
|
|
-
|
|
|
- result = d3d11Device->CreateSamplerState( &samplerDesc, &sampleState );
|
|
|
- if( result != S_OK )
|
|
|
- {
|
|
|
- std::cout << "ERROR: d3d11Device->CreateSamplerState returned " << result << "\n";
|
|
|
- WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- Bild *renderB = new Bild( 1 );
|
|
|
- renderB->setAlpha3D( 1 );
|
|
|
- renderB->neuBild( backBufferSize.x, backBufferSize.y, 0 );
|
|
|
-
|
|
|
- uiTextur = createOrGetTextur( "_f_Render_Bild", renderB );
|
|
|
-
|
|
|
- texturModel->setSize( backBufferSize );
|
|
|
- texturModel->setTextur( uiTextur->getThis() );
|
|
|
-
|
|
|
- D3D11_BLEND_DESC blendState;
|
|
|
- ZeroMemory( &blendState, sizeof( D3D11_BLEND_DESC ) );
|
|
|
- blendState.AlphaToCoverageEnable = false;
|
|
|
- blendState.IndependentBlendEnable = false;
|
|
|
- blendState.RenderTarget[ 0 ].BlendEnable = true;
|
|
|
- blendState.RenderTarget[ 0 ].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
|
|
- blendState.RenderTarget[ 0 ].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
|
|
- blendState.RenderTarget[ 0 ].BlendOp = D3D11_BLEND_OP_ADD;
|
|
|
- blendState.RenderTarget[ 0 ].SrcBlendAlpha = D3D11_BLEND_ZERO;
|
|
|
- blendState.RenderTarget[ 0 ].DestBlendAlpha = D3D11_BLEND_ONE;
|
|
|
- blendState.RenderTarget[ 0 ].BlendOpAlpha = D3D11_BLEND_OP_ADD;
|
|
|
- blendState.RenderTarget[ 0 ].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
|
|
|
-
|
|
|
- d3d11Device->CreateBlendState( &blendState, &blendStateAlphaBlend );
|
|
|
- d3d11Context->OMSetBlendState( blendStateAlphaBlend, 0, 0xFFFFFFFF );
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- vertexShader->benutzeShader();
|
|
|
- d3d11Context->PSSetSamplers( 0, 1, &sampleState );
|
|
|
- pixelShader->benutzeShader();
|
|
|
-
|
|
|
- D3D11_RASTERIZER_DESC rasterDesc;
|
|
|
- ZeroMemory( &rasterDesc, sizeof( rasterDesc ) );
|
|
|
- rasterDesc.AntialiasedLineEnable = false;
|
|
|
- rasterDesc.CullMode = D3D11_CULL_BACK;
|
|
|
- rasterDesc.DepthBiasClamp = 0.0f;
|
|
|
- rasterDesc.DepthClipEnable = true;
|
|
|
- rasterDesc.FillMode = D3D11_FILL_SOLID;
|
|
|
- rasterDesc.FrontCounterClockwise = false;
|
|
|
- rasterDesc.MultisampleEnable = false;
|
|
|
- rasterDesc.ScissorEnable = false;
|
|
|
- rasterDesc.SlopeScaledDepthBias = 0.0f;
|
|
|
- d3d11Device->CreateRasterizerState( &rasterDesc, &texturRS );
|
|
|
-
|
|
|
- ZeroMemory( &rasterDesc, sizeof( rasterDesc ) );
|
|
|
- rasterDesc.AntialiasedLineEnable = false;
|
|
|
- rasterDesc.CullMode = D3D11_CULL_BACK;
|
|
|
- rasterDesc.DepthBiasClamp = 0.0f;
|
|
|
- rasterDesc.DepthClipEnable = true;
|
|
|
- rasterDesc.FillMode = D3D11_FILL_WIREFRAME;
|
|
|
- rasterDesc.FrontCounterClockwise = false;
|
|
|
- rasterDesc.MultisampleEnable = false;
|
|
|
- rasterDesc.ScissorEnable = false;
|
|
|
- rasterDesc.SlopeScaledDepthBias = 0.0f;
|
|
|
- d3d11Device->CreateRasterizerState( &rasterDesc, &meshRS );
|
|
|
-
|
|
|
- d3d11Context->RSSetState( texturRS );
|
|
|
-
|
|
|
- Bild *b = new Bild();
|
|
|
- b->neuBild( 10, 10, 0xFFFFFFFF );
|
|
|
- defaultTextur = createOrGetTextur( "_default_textur", b );
|
|
|
-
|
|
|
- vertexBuffer = new DX11Buffer( sizeof( Vertex3D ), d3d11Device, d3d11Context, D3D11_BIND_VERTEX_BUFFER );
|
|
|
- indexBuffer = new DX11Buffer( sizeof( int ), d3d11Device, d3d11Context, D3D11_BIND_INDEX_BUFFER );
|
|
|
-
|
|
|
- DiffuseLight dl[ 1 ];
|
|
|
- dl[ 0 ].direction = Vec3< float >( -0.5f, -0.5f, -0.5f ).normalize();
|
|
|
- dl[ 0 ].color = Vec3<float>( 1.f, 0.f, 0.f );
|
|
|
- diffuseLights = new DX11StructuredBuffer( sizeof( DiffuseLight ), d3d11Device, d3d11Context );
|
|
|
- diffuseLights->setData( dl );
|
|
|
- diffuseLights->setLength( sizeof( dl ) );
|
|
|
- diffuseLights->copieren();
|
|
|
- PointLight pl[ 6 ];
|
|
|
- pl[ 0 ].position = Vec3< float >( 0, 130, 0 );
|
|
|
- pl[ 0 ].color = Vec3< float >( 1.f, 1.f, 0.f );
|
|
|
- pl[ 0 ].radius = 100;
|
|
|
- pl[ 1 ].position = Vec3< float >( 150, 130, 0 );
|
|
|
- pl[ 1 ].color = Vec3< float >( 0.f, 1.f, 0.f );
|
|
|
- pl[ 1 ].radius = 100;
|
|
|
- pl[ 2 ].position = Vec3< float >( 150, 130, 150 );
|
|
|
- pl[ 2 ].color = Vec3< float >( 0.f, 0.f, 1.f );
|
|
|
- pl[ 2 ].radius = 100;
|
|
|
- pl[ 3 ].position = Vec3< float >( -150, 130, 0 );
|
|
|
- pl[ 3 ].color = Vec3< float >( 1.f, 0.f, 1.f );
|
|
|
- pl[ 3 ].radius = 100;
|
|
|
- pl[ 4 ].position = Vec3< float >( 0, 130, 150 );
|
|
|
- pl[ 4 ].color = Vec3< float >( 0.f, 1.f, 1.f );
|
|
|
- pl[ 4 ].radius = 100;
|
|
|
- pl[ 5 ].position = Vec3< float >( -150, 130, 150 );
|
|
|
- pl[ 5 ].color = Vec3< float >( 1.f, 0.f, 0.f );
|
|
|
- pl[ 5 ].radius = 100;
|
|
|
- pointLights = new DX11StructuredBuffer( sizeof( PointLight ), d3d11Device, d3d11Context );
|
|
|
- pointLights->setData( pl );
|
|
|
- pointLights->setLength( sizeof( pl ) * 6 );
|
|
|
- pointLights->copieren();
|
|
|
-}
|
|
|
-
|
|
|
-void DirectX11::update()
|
|
|
-{
|
|
|
- if( vertexBuffer )
|
|
|
- vertexBuffer = (DX11Buffer *)vertexBuffer->release();
|
|
|
- if( indexBuffer )
|
|
|
- indexBuffer = (DX11Buffer *)indexBuffer->release();
|
|
|
- if( texturRS )
|
|
|
- {
|
|
|
- texturRS->Release();
|
|
|
- texturRS = NULL;
|
|
|
- }
|
|
|
- if( meshRS )
|
|
|
- {
|
|
|
- meshRS->Release();
|
|
|
- meshRS = NULL;
|
|
|
- }
|
|
|
- texturRegister->leeren();
|
|
|
- if( defaultTextur )
|
|
|
- defaultTextur = defaultTextur->release();
|
|
|
- if( blendStateAlphaBlend )
|
|
|
- {
|
|
|
- blendStateAlphaBlend->Release();
|
|
|
- blendStateAlphaBlend = NULL;
|
|
|
- }
|
|
|
- if( uiTextur )
|
|
|
- {
|
|
|
- uiTextur->release();
|
|
|
- uiTextur = NULL;
|
|
|
- }
|
|
|
- if( sampleState )
|
|
|
- {
|
|
|
- sampleState->Release();
|
|
|
- sampleState = NULL;
|
|
|
- }
|
|
|
- if( pixelShader )
|
|
|
- {
|
|
|
- pixelShader->release();
|
|
|
- pixelShader = NULL;
|
|
|
- }
|
|
|
- if( vertexShader )
|
|
|
- {
|
|
|
- vertexShader->release();
|
|
|
- vertexShader = NULL;
|
|
|
- }
|
|
|
- if( depthDisabledStencilState )
|
|
|
- {
|
|
|
- depthDisabledStencilState->Release();
|
|
|
- depthDisabledStencilState = NULL;
|
|
|
- }
|
|
|
- delete vp;
|
|
|
- vp = 0;
|
|
|
- if( dsView )
|
|
|
- {
|
|
|
- dsView->Release();
|
|
|
- dsView = NULL;
|
|
|
- }
|
|
|
- if( depthStencilState )
|
|
|
- {
|
|
|
- depthStencilState->Release();
|
|
|
- depthStencilState = NULL;
|
|
|
- }
|
|
|
- if( depthStencilBuffer )
|
|
|
- {
|
|
|
- depthStencilBuffer->Release();
|
|
|
- depthStencilBuffer = NULL;
|
|
|
- }
|
|
|
- if( rtview )
|
|
|
- {
|
|
|
- rtview->Release();
|
|
|
- rtview = NULL;
|
|
|
- }
|
|
|
- if( d3d11SpawChain )
|
|
|
- {
|
|
|
- d3d11SpawChain->Release();
|
|
|
- d3d11SpawChain = NULL;
|
|
|
- }
|
|
|
- if( d3d11Device )
|
|
|
- {
|
|
|
- d3d11Device->Release();
|
|
|
- d3d11Device = NULL;
|
|
|
- }
|
|
|
- if( d3d11Context )
|
|
|
- {
|
|
|
- d3d11Context->Release();
|
|
|
- d3d11Context = NULL;
|
|
|
- }
|
|
|
- initialize( fenster->getThis(), backBufferSize, fullScreen );
|
|
|
-}
|
|
|
-
|
|
|
-void DirectX11::beginFrame( bool fill2D, bool fill3D, int fillColor )
|
|
|
-{
|
|
|
- if( fill2D )
|
|
|
- uiTextur->zBild()->setFarbe( fillColor );
|
|
|
- if( fill3D )
|
|
|
- {
|
|
|
- float color[ 4 ];
|
|
|
-
|
|
|
- color[ 0 ] = ( ( fillColor >> 16 ) & 0xFF ) / 255.f;
|
|
|
- color[ 1 ] = ( ( fillColor >> 8 ) & 0xFF ) / 255.f;
|
|
|
- color[ 2 ] = ( fillColor & 0xFF ) / 255.f;
|
|
|
- color[ 3 ] = ( ( fillColor >> 24 ) & 0xFF ) / 255.f;
|
|
|
- d3d11Context->ClearRenderTargetView( rtview, color );
|
|
|
-
|
|
|
- d3d11Context->ClearDepthStencilView( dsView, D3D11_CLEAR_DEPTH, 1, 0 );
|
|
|
- }
|
|
|
-
|
|
|
- d3d11Context->OMSetRenderTargets( 1, &rtview, dsView );
|
|
|
-
|
|
|
- d3d11Context->OMSetDepthStencilState( depthStencilState, 1 );
|
|
|
-}
|
|
|
-
|
|
|
-void DirectX11::renderObject( Model3D * zObj )
|
|
|
-{
|
|
|
- vertexBuffer->setData( (void *)zObj->zVertexBuffer() );
|
|
|
- vertexBuffer->setLength( sizeof( Vertex3D ) * zObj->getVertexAnzahl() );
|
|
|
- vertexBuffer->copieren();
|
|
|
- Mat4< float > trans = Mat4< float >::identity();
|
|
|
- int anz = zObj->errechneMatrizen( trans, matrixBuffer );
|
|
|
- if( vertexShader )
|
|
|
- vertexShader->füllConstBuffer( (char *)matrixBuffer, 0, sizeof( Mat4< float > ) * anz );
|
|
|
- float matirialBuffer[ 3 ];
|
|
|
- matirialBuffer[ 0 ] = zObj->getAmbientFactor();
|
|
|
- matirialBuffer[ 1 ] = zObj->getDiffusFactor();
|
|
|
- matirialBuffer[ 2 ] = zObj->getSpecularFactor();
|
|
|
- if( pixelShader )
|
|
|
- pixelShader->füllConstBuffer( (char *)matirialBuffer, 1, sizeof( float ) * 3 );
|
|
|
- unsigned int offset = 0;
|
|
|
- unsigned int es = (unsigned)vertexBuffer->getElementLength();
|
|
|
- ID3D11Buffer * vBuffer = vertexBuffer->zBuffer();
|
|
|
- d3d11Context->IASetVertexBuffers( 0, 1, &vBuffer, &es, &offset );
|
|
|
- Model3DTextur * zTextur = zObj->zTextur();
|
|
|
- int ind = 0;
|
|
|
- for( auto i = zObj->zModelData()->getPolygons(); i; i++ )
|
|
|
- {
|
|
|
- indexBuffer->setData( i->indexList );
|
|
|
- indexBuffer->setLength( sizeof( int ) * i->indexAnz );
|
|
|
- indexBuffer->copieren();
|
|
|
- Textur *t = zTextur->zPolygonTextur( ind );
|
|
|
- if( t &&t->brauchtUpdate() )
|
|
|
- t->updateTextur();
|
|
|
- DXGI_FORMAT f = DXGI_FORMAT_R32_UINT;
|
|
|
- if( indexBuffer->getElementLength() == 2 )
|
|
|
- f = DXGI_FORMAT_R16_UINT;
|
|
|
- if( indexBuffer->getElementLength() == 1 )
|
|
|
- f = DXGI_FORMAT_R8_UINT;
|
|
|
- d3d11Context->IASetIndexBuffer( indexBuffer->zBuffer(), f, 0 );
|
|
|
- d3d11Context->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
|
|
|
- if( t )
|
|
|
- {
|
|
|
- ID3D11ShaderResourceView *v[ 3 ];
|
|
|
- v[ 0 ] = *(DX11Textur *)t;
|
|
|
- v[ 1 ] = *diffuseLights;
|
|
|
- v[ 2 ] = *pointLights;
|
|
|
- d3d11Context->PSSetShaderResources( 0, 3, v );
|
|
|
- d3d11Context->DrawIndexed( indexBuffer->getElementAnzahl(), 0, 0 );
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- d3d11Context->RSSetState( meshRS );
|
|
|
- ID3D11ShaderResourceView *v[ 3 ];
|
|
|
- v[ 0 ] = *(DX11Textur *)defaultTextur;
|
|
|
- v[ 1 ] = *diffuseLights;
|
|
|
- v[ 2 ] = *pointLights;
|
|
|
- d3d11Context->PSSetShaderResources( 0, 3, v );
|
|
|
- d3d11Context->DrawIndexed( indexBuffer->getElementAnzahl(), 0, 0 );
|
|
|
- d3d11Context->RSSetState( texturRS );
|
|
|
- }
|
|
|
- ind++;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-bool DirectX11::isInFrustrum( const Vec3< float > & pos, float radius, float *dist ) const
|
|
|
-{
|
|
|
- for( int i = 0; i < 6; i++ )
|
|
|
- {
|
|
|
- if( frustrum[ i ] * pos + radius < 0 )
|
|
|
- return 0;
|
|
|
- }
|
|
|
- if( dist )
|
|
|
- * dist = kamPos.abstand( pos );
|
|
|
- return 1;
|
|
|
-}
|
|
|
-
|
|
|
-void DirectX11::renderKamera( Kam3D * zKamera )
|
|
|
-{
|
|
|
- d3d11Context->RSSetViewports( 1, (D3D11_VIEWPORT *)zKamera->zViewPort() );
|
|
|
-
|
|
|
- Mat4< float > tmp = zKamera->getProjectionMatrix() * zKamera->getViewMatrix();
|
|
|
-
|
|
|
- frustrum[ 0 ].x = tmp.elements[ 3 ][ 0 ] + tmp.elements[ 0 ][ 0 ];
|
|
|
- frustrum[ 0 ].y = tmp.elements[ 3 ][ 1 ] + tmp.elements[ 0 ][ 1 ];
|
|
|
- frustrum[ 0 ].z = tmp.elements[ 3 ][ 2 ] + tmp.elements[ 0 ][ 2 ];
|
|
|
- frustrum[ 0 ].w = tmp.elements[ 3 ][ 3 ] + tmp.elements[ 0 ][ 3 ];
|
|
|
-
|
|
|
- frustrum[ 1 ].x = tmp.elements[ 3 ][ 0 ] - tmp.elements[ 0 ][ 0 ];
|
|
|
- frustrum[ 1 ].y = tmp.elements[ 3 ][ 1 ] - tmp.elements[ 0 ][ 1 ];
|
|
|
- frustrum[ 1 ].z = tmp.elements[ 3 ][ 2 ] - tmp.elements[ 0 ][ 2 ];
|
|
|
- frustrum[ 1 ].w = tmp.elements[ 3 ][ 3 ] - tmp.elements[ 0 ][ 3 ];
|
|
|
-
|
|
|
- frustrum[ 2 ].x = tmp.elements[ 3 ][ 0 ] - tmp.elements[ 1 ][ 0 ];
|
|
|
- frustrum[ 2 ].y = tmp.elements[ 3 ][ 1 ] - tmp.elements[ 1 ][ 1 ];
|
|
|
- frustrum[ 2 ].z = tmp.elements[ 3 ][ 2 ] - tmp.elements[ 1 ][ 2 ];
|
|
|
- frustrum[ 2 ].w = tmp.elements[ 3 ][ 3 ] - tmp.elements[ 1 ][ 3 ];
|
|
|
-
|
|
|
- frustrum[ 3 ].x = tmp.elements[ 3 ][ 0 ] + tmp.elements[ 1 ][ 0 ];
|
|
|
- frustrum[ 3 ].y = tmp.elements[ 3 ][ 1 ] + tmp.elements[ 1 ][ 1 ];
|
|
|
- frustrum[ 3 ].z = tmp.elements[ 3 ][ 2 ] + tmp.elements[ 1 ][ 2 ];
|
|
|
- frustrum[ 3 ].w = tmp.elements[ 3 ][ 3 ] + tmp.elements[ 1 ][ 3 ];
|
|
|
-
|
|
|
- frustrum[ 4 ].x = tmp.elements[ 2 ][ 0 ];
|
|
|
- frustrum[ 4 ].y = tmp.elements[ 2 ][ 1 ];
|
|
|
- frustrum[ 4 ].z = tmp.elements[ 2 ][ 2 ];
|
|
|
- frustrum[ 4 ].w = tmp.elements[ 2 ][ 3 ];
|
|
|
-
|
|
|
- frustrum[ 5 ].x = tmp.elements[ 3 ][ 0 ] - tmp.elements[ 2 ][ 0 ];
|
|
|
- frustrum[ 5 ].y = tmp.elements[ 3 ][ 1 ] - tmp.elements[ 2 ][ 1 ];
|
|
|
- frustrum[ 5 ].z = tmp.elements[ 3 ][ 2 ] - tmp.elements[ 2 ][ 2 ];
|
|
|
- frustrum[ 5 ].w = tmp.elements[ 3 ][ 3 ] - tmp.elements[ 2 ][ 3 ];
|
|
|
-
|
|
|
- for( int i = 0; i < 6; i++ )
|
|
|
- frustrum[ i ].normalize();
|
|
|
-
|
|
|
- viewAndProj[ 0 ] = zKamera->getViewMatrix();
|
|
|
- viewAndProj[ 1 ] = zKamera->getProjectionMatrix();
|
|
|
- kamPos = zKamera->getWorldPosition();
|
|
|
- if( vertexShader )
|
|
|
- vertexShader->füllConstBuffer( (char *)viewAndProj, 1, sizeof( Mat4< float > ) * 2 );
|
|
|
- if( pixelShader )
|
|
|
- pixelShader->füllConstBuffer( (char *)& kamPos, 0, sizeof( float ) * 3 );
|
|
|
- Welt3D * w = zKamera->zWelt();
|
|
|
- w->lock();
|
|
|
- int alphaAnzahl = 0;
|
|
|
- int maxDist = 0;
|
|
|
- int minDist = 0x7FFFFFFF;
|
|
|
- for( auto obj = w->getMembers(); obj; obj++ )
|
|
|
- {
|
|
|
- float dist;
|
|
|
- if( isInFrustrum( obj->getPos(), obj->getRadius(), &dist ) )
|
|
|
- {
|
|
|
- if( (int)dist > maxDist )
|
|
|
- maxDist = (int)dist;
|
|
|
- if( minDist < (int)dist )
|
|
|
- minDist = (int)dist;
|
|
|
- if( obj->hatAlpha() )
|
|
|
- alphaAnzahl++;
|
|
|
- else
|
|
|
- renderObject( obj._ );
|
|
|
- }
|
|
|
- }
|
|
|
- maxDist++;
|
|
|
- if( alphaAnzahl )
|
|
|
- {
|
|
|
- int size = maxDist - minDist;
|
|
|
- int *index = new int[ size ];
|
|
|
- Model3D **sorted = new Model3D * [ size * alphaAnzahl ];
|
|
|
- for( auto obj = w->getMembers(); obj; obj++ )
|
|
|
- {
|
|
|
- float dist;
|
|
|
- if( isInFrustrum( obj->getPos(), obj->getRadius(), &dist ) )
|
|
|
- {
|
|
|
- if( obj->hatAlpha() )
|
|
|
- {
|
|
|
- int pos = (int)dist - minDist;
|
|
|
- sorted[ pos * alphaAnzahl + index[ pos ]++ ] = obj._;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- for( int i = 0; i < size; i++ )
|
|
|
- {
|
|
|
- for( int j = 0; j < index[ i ]; j++ )
|
|
|
- {
|
|
|
- renderObject( sorted[ i * alphaAnzahl + j ] );
|
|
|
- }
|
|
|
- }
|
|
|
- delete[] index;
|
|
|
- delete[] sorted;
|
|
|
- }
|
|
|
- w->unlock();
|
|
|
-}
|
|
|
-
|
|
|
-void DirectX11::presentFrame()
|
|
|
-{
|
|
|
-
|
|
|
- d3d11Context->OMSetDepthStencilState( depthDisabledStencilState, 1 );
|
|
|
-
|
|
|
- uiTextur->updateTextur();
|
|
|
-
|
|
|
- d3d11Context->RSSetViewports( 1, vp );
|
|
|
-
|
|
|
- float screenAspect = (float)backBufferSize.x / (float)backBufferSize.y;
|
|
|
- Mat4< float > view = view.translation( Vec3< float >( 0.f, 0.f, backBufferSize.y * 1.2075f ) );
|
|
|
- viewAndProj[ 0 ] = view;
|
|
|
- viewAndProj[ 1 ] = view.projektion( (float)PI / 4.0f, screenAspect, 0.1f, 10000.f );
|
|
|
- kamPos = Vec3< float >( 0.f, 0.f, backBufferSize.y * 1.2075f );
|
|
|
- if( vertexShader )
|
|
|
- vertexShader->füllConstBuffer( (char *)viewAndProj, 1, sizeof( Mat4< float > ) * 2 );
|
|
|
- if( pixelShader )
|
|
|
- pixelShader->füllConstBuffer( (char *)& kamPos, 0, sizeof( float ) * 3 );
|
|
|
-
|
|
|
- if( fenster && !IsIconic( fenster->getFensterHandle() ) )
|
|
|
- renderObject( texturModel );
|
|
|
-
|
|
|
- HRESULT result = d3d11SpawChain->Present( 0, 0 );
|
|
|
- if( !SUCCEEDED( result ) )
|
|
|
- {
|
|
|
- update();
|
|
|
- WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-Bild *DirectX11::zUIRenderBild() const
|
|
|
-{
|
|
|
- return uiTextur->zBild();
|
|
|
-}
|
|
|
-
|
|
|
-Textur *DirectX11::createOrGetTextur( const char *name, Bild * b )
|
|
|
-{
|
|
|
- if( !d3d11Device )
|
|
|
- {
|
|
|
- if( b )
|
|
|
- b->release();
|
|
|
- return 0;
|
|
|
- }
|
|
|
- if( texturRegister->hatTextur( name ) )
|
|
|
- {
|
|
|
- Textur *ret = texturRegister->getTextur( name );
|
|
|
- if( b )
|
|
|
- ret->setBildZ( b );
|
|
|
- return ret;
|
|
|
- }
|
|
|
- Textur *ret = new DX11Textur( d3d11Device, d3d11Context );
|
|
|
- if( b )
|
|
|
- ret->setBildZ( b );
|
|
|
- texturRegister->addTextur( ret->getThis(), name );
|
|
|
- return ret;
|
|
|
}
|