Exemple #1
0
//--------------------------------------------------------------------------------------
// Release D3D9 resources created in the OnD3D9CreateDevice callback 
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10DestroyDevice( void* pUserContext )
{
    g_DialogResourceManager.OnD3D10DestroyDevice();
    g_SettingsDlg.OnD3D10DestroyDevice();
    DXUTGetGlobalResourceCache().OnDestroyDevice();

    g_Terrain.OnDestroyDevice();
    g_BallMesh.Destroy();
    g_SkyMesh.Destroy();

    SAFE_RELEASE( g_pFont10 );
    SAFE_RELEASE( g_pSprite10 );
    SAFE_DELETE( g_pTxtHelper );

    SAFE_RELEASE( g_pEffect10 );
    SAFE_RELEASE( g_pBasicDecl10 );
    SAFE_RELEASE( g_pBallDecl10 );
    SAFE_RELEASE( g_pGrassDecl10 );

    SAFE_RELEASE( g_pHeightTexRV );
    SAFE_RELEASE( g_pNormalTexRV );
    SAFE_RELEASE( g_pGrassTexRV );
    SAFE_RELEASE( g_pDirtTexRV );
    SAFE_RELEASE( g_pGroundGrassTexRV );
    SAFE_RELEASE( g_pMaskTexRV );
    SAFE_RELEASE( g_pShadeNormalTexRV );
    SAFE_RELEASE( g_pStreamDataVB10 );
    SAFE_RELEASE( g_pGrassDataVB10 );
}
//--------------------------------------------------------------------------------------
// Release D3D11 resources created in OnD3D11CreateDevice 
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11DestroyDevice( void* pUserContext )
{
    g_DialogResourceManager.OnD3D11DestroyDevice();
    g_D3DSettingsDlg.OnD3D11DestroyDevice();
    DXUTGetGlobalResourceCache().OnDestroyDevice();
    SAFE_DELETE( g_pTxtHelper );
    SAFE_DELETE( g_pTxtHelper1 );

    g_SceneMesh.Destroy();
    g_Poles.Destroy();

    SAFE_RELEASE( g_pSceneVS );
    SAFE_RELEASE( g_pScenePS );
    SAFE_RELEASE( g_pSM_VS );
    SAFE_RELEASE( g_pcbConstants );
    SAFE_RELEASE( g_pRSMDepthStencilTexture );
    SAFE_RELEASE( g_pDepthStencilTextureDSV );
    SAFE_RELEASE( g_pDepthTextureSRV );
    SAFE_RELEASE( g_pSceneVertexLayout );
    SAFE_RELEASE( g_pBlendStateNoBlend );
    SAFE_RELEASE( g_pBlendStateColorWritesOff );
    SAFE_RELEASE( g_pSamplePoint );
    SAFE_RELEASE( g_pSamplePointCmp );
    SAFE_RELEASE( g_pSampleLinear );
}
//--------------------------------------------------------------------------------------
// Release D3D11 resources created in OnD3D11CreateDevice 
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11DestroyDevice( void* pUserContext )
{
    g_DialogResourceManager.OnD3D11DestroyDevice();
    g_D3DSettingsDlg.OnD3D11DestroyDevice();
    //CDXUTDirectionWidget::StaticOnD3D11DestroyDevice();
    DXUTGetGlobalResourceCache().OnDestroyDevice();
	test.destroy();
	tessplane.destroy();
	lightsphere.destroy();
	tesscube.destroy();
	fuse.destroy();
	deboard.destroy();
	board1.destroy();
	geo_alien.destroy();
	FirePart.destroy();
    SAFE_DELETE( g_pTxtHelper );
	SAFE_RELEASE(g_DepthState);
    //g_Mesh11.Destroy();
    //            
    //SAFE_RELEASE( g_pVertexLayout11 );
    //SAFE_RELEASE( g_pVertexBuffer );
    //SAFE_RELEASE( g_pIndexBuffer );
    //SAFE_RELEASE( g_pVertexShader );
    //SAFE_RELEASE( g_pPixelShader );
    //SAFE_RELEASE( g_pSamLinear );

 /*   SAFE_RELEASE( g_pcbVSPerObject );
    SAFE_RELEASE( g_pcbPSPerObject );
    SAFE_RELEASE( g_pcbPSPerFrame );*/
}
//--------------------------------------------------------------------------------------
// Release D3D11 resources created in OnD3D11CreateDevice 
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11DestroyDevice( void* pUserContext )
{
	DXUTGetGlobalResourceCache().OnDestroyDevice();
	dialogResourceManager.OnD3D11DestroyDevice();

	vegetationRendering->release();
	delete vegetationRendering;
	vegetationRendering = 0;
}
Exemple #5
0
//--------------------------------------------------------------------------------------
// Release D3D9 resources created in the OnD3D9CreateDevice callback 
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D9DestroyDevice( void* pUserContext )
{
    g_DialogResourceManager.OnD3D9DestroyDevice();
    g_SettingsDlg.OnD3D9DestroyDevice();
    DXUTGetGlobalResourceCache().OnDestroyDevice();
    SAFE_RELEASE( g_pEffect9 );
    SAFE_RELEASE( g_pFont9 );
    SAFE_RELEASE( g_pDecl9 );
}
Exemple #6
0
void CALLBACK OnD3D11DestroyDevice(void* userContext)
{
    DestroyApp();
    DestroyScene();
    
    gDialogResourceManager.OnD3D11DestroyDevice();
    gD3DSettingsDlg.OnD3D11DestroyDevice();
    DXUTGetGlobalResourceCache().OnDestroyDevice();
    SAFE_DELETE(gTextHelper);
}
//--------------------------------------------------------------------------------------
// Release D3D11 resources created in OnD3D11CreateDevice 
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11DestroyDevice(void* /*pUserContext*/)
{
    g_DialogResourceManager.OnD3D11DestroyDevice();
    g_D3DSettingsDlg.OnD3D11DestroyDevice();
    DXUTGetGlobalResourceCache().OnDestroyDevice();
    SAFE_DELETE(g_pTxtHelper);

    g_Scene.OnD3D11DestroyDevice();
    g_OIT.OnD3D11DestroyDevice();

}
HRESULT DestroyD3DComponents()
{
    g_DialogResourceManager.OnD3D11DestroyDevice();
    g_D3DSettingsDlg.OnD3D11DestroyDevice();
    DXUTGetGlobalResourceCache().OnDestroyDevice();
    SAFE_DELETE(g_pTxtHelper);

    g_CascadedShadow.DestroyAndDeallocateShadowResources();
    return S_OK;

}
//--------------------------------------------------------------------------------------
// Release D3D10 resources created in OnD3D10CreateDevice
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10DestroyDevice(void* pUserContext)
{
	g_DialogResourceManager.OnD3D10DestroyDevice();
	g_D3DSettingsDlg.OnD3D10DestroyDevice();
	CDXUTDirectionWidget::StaticOnD3D10DestroyDevice();
	DXUTGetGlobalResourceCache().OnDestroyDevice();
	SAFE_DELETE(g_pTxtHelper);
	SAFE_RELEASE(g_pFont10);
	SAFE_RELEASE(g_pSprite10);
	SAFE_RELEASE(g_pEffect10);
	SAFE_DELETE(g_vsObj);
}
//--------------------------------------------------------------------------------------
// Release D3D11 resources created in OnD3D11CreateDevice 
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11DestroyDevice( void* pUserContext )
{
    g_DialogResourceManager.OnD3D11DestroyDevice();
    g_SettingsDlg.OnD3D11DestroyDevice();
    DXUTGetGlobalResourceCache().OnDestroyDevice();
    SAFE_DELETE( g_pTxtHelper );

    SAFE_RELEASE( g_pVSTransform );
    SAFE_RELEASE( g_pPSSceneRender );
    SAFE_RELEASE( g_pPSSceneRenderArray );
    SAFE_RELEASE( g_pPSSceneRenderQuilt );

    SAFE_RELEASE( g_pDefaultInputLayout );
    SAFE_RELEASE( g_pSamLinear );

    SAFE_RELEASE( g_pBlendState );
    SAFE_RELEASE( g_pDepthStencilState );
    SAFE_RELEASE( g_pRasterizerState );

    SAFE_RELEASE( g_pcbVSPerObject11 );
    SAFE_RELEASE( g_pQuadVB );
    SAFE_RELEASE( g_pQuiltQuadVB );
    SAFE_RELEASE( g_pArrayQuadsVB );

    g_PageDebugRender.Terminate();
    ResidencySampleRender::Terminate();

    SAFE_DELETE( g_pTitleResidencyManager );

    g_pInspectionTexture = NULL;

    for( UINT i = 0; i < g_SceneObjects.size(); ++i )
    {
        SceneObject* pSO = g_SceneObjects[i];
        SAFE_RELEASE( pSO->m_pLayoutResidencySample );
        SAFE_RELEASE( pSO->m_pLayoutSceneRender );
        SAFE_RELEASE( pSO->pVertexBuffer );
        SAFE_RELEASE( pSO->pIndexBuffer );

        for( UINT j = 0; j < pSO->TextureCount; ++j )
        {
            pSO->Textures[j].Release();
        }

        delete pSO;
    }
    g_SceneObjects.clear();

    SAFE_DELETE( g_pTerrainView );

    SAFE_RELEASE( g_pTilePool );
    SAFE_RELEASE( g_pd3dDeviceEx );
}
Exemple #11
0
//--------------------------------------------------------------------------------------
// Release D3D10 resources created in OnD3D10CreateDevice 
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10DestroyDevice( void* pUserContext )
{
    g_DialogResourceManager.OnD3D10DestroyDevice();
    g_D3DSettingsDlg.OnD3D10DestroyDevice();
    DXUTGetGlobalResourceCache().OnDestroyDevice();
    SAFE_RELEASE( g_pFont );
    SAFE_RELEASE( g_pSprite );
    SAFE_DELETE( g_pTxtHelper );
    SAFE_RELEASE( g_pVertexLayout );
    SAFE_RELEASE( g_pEffect );
    g_Mesh.Destroy();
}
Exemple #12
0
//--------------------------------------------------------------------------------------
// Release D3D9 resources created in the OnD3D9ResetDevice callback 
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D9LostDevice( void* pUserContext )
{
    g_DialogResourceManager.OnD3D9LostDevice();
    g_SettingsDlg.OnD3D9LostDevice();
    DXUTGetGlobalResourceCache().OnLostDevice();
    if( g_pFont9 ) g_pFont9->OnLostDevice();
    if( g_pEffect9 ) g_pEffect9->OnLostDevice();
    SAFE_RELEASE( g_pSprite9 );
    SAFE_DELETE( g_pTxtHelper );
    g_Mesh.Destroy();
    SAFE_RELEASE( g_pTexture9 );
}
//--------------------------------------------------------------------------------------
// Release D3D10 resources created in OnD3D10CreateDevice 
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10DestroyDevice( void* pUserContext )
{
    g_DialogResourceManager.OnD3D10DestroyDevice();
    g_SettingsDlg.OnD3D10DestroyDevice();
    DXUTGetGlobalResourceCache().OnDestroyDevice();
    SAFE_DELETE( g_pTxtHelper );
    SAFE_RELEASE( g_pVertexLayout );
    SAFE_RELEASE( g_pFont10 );
    SAFE_RELEASE( g_pSprite10 );
    SAFE_RELEASE( g_pEffect10 );
	delete g_DumpMesh;
    g_MeshLoader.Destroy();

	for( UINT i = 0; i < MAX_RASTERIZER_MODES; i++ )
        SAFE_RELEASE( g_pRasterStates[i] );

	SAFE_RELEASE(g_TransparentBS);

	SAFE_RELEASE(g_TrialCube);
	delete g_pBox;
	delete g_AABBConstructor;

	delete g_FunctionDraw;
	g_FunctionDraw=NULL;

	if (!g_Parabola)
	{
		delete g_Parabola;
		g_Parabola = NULL;
	}
	
	
	if (!g_ParabolaDis)
	{
		delete g_ParabolaDis;
		g_ParabolaDis = NULL;
	}

	if (!g_UVImport)
	{
		delete g_UVImport;
		g_UVImport = NULL;
	}

	if (!g_UVFileDisp)
	{
		delete g_UVFileDisp;
		g_UVFileDisp = NULL;
	}
}
Exemple #14
0
// Release D3D11 resources created in OnD3D11CreateDevice 
void CALLBACK OnD3D11DestroyDevice( void* pUserContext )
{
    gDialogResourceManager.OnD3D11DestroyDevice();
    gD3DSettingsDlg.OnD3D11DestroyDevice();
    //CDXUTDirectionWidget::StaticOnD3D11DestroyDevice();
    DXUTGetGlobalResourceCache().OnDestroyDevice();
    SAFE_DELETE( gTxtHelper );

    SAFE_RELEASE( gVertexLayout );
    SAFE_RELEASE( gVertexBuffer );
    SAFE_RELEASE( gQuadVB );
    SAFE_RELEASE( gIndexBuffer );
    SAFE_RELEASE( gConstantBuffer );
    SAFE_RELEASE( gVertexShader );
    SAFE_RELEASE( gRenderFramePS );
    SAFE_RELEASE( gRenderTexturePS );
    SAFE_RELEASE( gRenderAlphaPS );
    SAFE_RELEASE( gSamPoint );

	DestroyTextures();
}
//--------------------------------------------------------------------------------------
// This callback function will be called immediately after the Direct3D device has 
// been destroyed, which generally happens as a result of application termination or 
// windowed/full screen toggles.
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11DestroyDevice(void* pUserContext)
{
    DXUTTRACE(L"OnD3D11DestroyDevice called\n");

    g_DialogResourceManager.OnD3D11DestroyDevice();
    g_SettingsDlg.OnD3D11DestroyDevice();
    DXUTGetGlobalResourceCache().OnDestroyDevice();
    SAFE_DELETE(g_pTxtHelper);

    g_pSceneRenderer.OnDestroyDevice();

    for (int i = 0; i < ARRAYSIZE(g_MeshDesc); i++)
    {
        g_SceneMeshes[i].OnDestroyDevice();
    }

    ReleaseRenderTargets();
    ReleaseDepthBuffer();

    g_AORenderer.Release();
}
//--------------------------------------------------------------------------------------
// Release D3D10 resources created in OnD3D10CreateDevice 
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10DestroyDevice( void* pUserContext )
{
    g_DialogResourceManager.OnD3D10DestroyDevice();
    g_D3DSettingsDlg.OnD3D10DestroyDevice();
    CDXUTDirectionWidget::StaticOnD3D10DestroyDevice();
    DXUTGetGlobalResourceCache().OnDestroyDevice();

    SAFE_RELEASE( g_pEffect );
    SAFE_RELEASE( g_pFont10 );
    SAFE_RELEASE( g_pSprite10 );
    SAFE_DELETE( g_pTxtHelper );
    SAFE_RELEASE( g_pStaticVertexLayout );
    SAFE_RELEASE( g_pSkinnedVertexLayout );

    g_SceneMesh.Destroy();
    g_FanMesh.Destroy();
    for( UINT iMesh = 0; iMesh < g_NumLinkedMeshes; iMesh++ )
        g_pLinkedMeshes[iMesh].Destroy();
    SAFE_DELETE_ARRAY( g_pLinkedMeshes );

    g_AnimMesh.Destroy();
}
Exemple #17
0
//--------------------------------------------------------------------------------------
// Release D3D11 resources created in OnD3D11CreateDevice 
//--------------------------------------------------------------------------------------
void CALLBACK DXUTHelper::AppD3D11DestroyDevice(void* pUserContext)
{
	DXUTGetGlobalResourceCache().OnDestroyDevice();

	g_RenderSystem.Shutdown();
}
Exemple #18
0
void Gui::OnD3D11DestroyDevice()
{
	settingsDlg.OnD3D11DestroyDevice();
	DXUTGetGlobalResourceCache().OnDestroyDevice();
}
void Terrain::init(ID3D11Device* device)
{
    ID3D11DeviceContext* deviceContext;
    device->GetImmediateContext(&deviceContext);

    ID3DBlob* errorBlob;
    ID3DBlob* shaderBlob;

    HRESULT result = D3DX11CompileFromFileA("Content\\Effects\\SimpleTerrain.fx", 0, 0, 0, "fx_5_0", 0, 0, 0, &shaderBlob, &errorBlob, 0);

    char* errorBuffer;
    if(errorBlob)
    {
        errorBuffer = (char*)errorBlob->GetBufferPointer();
    }

    result = D3DX11CreateEffectFromMemory(shaderBlob->GetBufferPointer(), shaderBlob->GetBufferSize(), 0, device, &effect);

    if(shaderBlob)
        shaderBlob->Release();
    if(errorBlob)
        errorBlob->Release();

    // vertex buffer
    TerrainVertex vertices[] =
    {
        {Vector3(0.0f, 0, INSTANCE_SIZE), Vector3::up, D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f), Vector2(0, 0)},
        {Vector3(INSTANCE_SIZE, 0, INSTANCE_SIZE), Vector3::up, D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f), Vector2(1, 0)},
        {Vector3(0.0f, 0, 0.0f), Vector3::up, D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f), Vector2(0, 1)},
        {Vector3(INSTANCE_SIZE, 0, 0.0f), Vector3::up, D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f), Vector2(1, 1)}
    };

    D3D11_BUFFER_DESC vertexBufferDesc;
    ZeroMemory(&vertexBufferDesc, sizeof(vertexBufferDesc));

    vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
    vertexBufferDesc.ByteWidth = sizeof(vertices);
    vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vertexBufferDesc.CPUAccessFlags = 0;

    D3D11_SUBRESOURCE_DATA vertexData;
    ZeroMemory( &vertexData, sizeof(D3D11_SUBRESOURCE_DATA) );
    vertexData.pSysMem = vertices;

    device->CreateBuffer(&vertexBufferDesc, &vertexData, &vertexBuffer);

    // Instance Buffer
    TerrainInstance instances[INSTANCE_COUNT];
    for(int i = 0; i < INSTANCE_COUNT_X; ++i)
        for(int j = 0; j < INSTANCE_COUNT_Y; ++j)
            instances[i * INSTANCE_COUNT_X + j].position = Vector3((float)i*INSTANCE_SIZE, 0, (float)j*INSTANCE_SIZE);

    D3D11_BUFFER_DESC instanceBufferDesc;
    ZeroMemory(&instanceBufferDesc, sizeof(D3D11_BUFFER_DESC));

    instanceBufferDesc.Usage = D3D11_USAGE_DEFAULT;
    instanceBufferDesc.ByteWidth = sizeof(instances);
    instanceBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    instanceBufferDesc.CPUAccessFlags = 0;

    D3D11_SUBRESOURCE_DATA instanceData;
    ZeroMemory(&instanceData, sizeof(D3D11_SUBRESOURCE_DATA));
    instanceData.pSysMem = instances;

    device->CreateBuffer(&instanceBufferDesc, &instanceData, &instanceBuffer);

    // index buffer
    unsigned indices[] = { 0, 1, 2, 3 };
    indexCount = sizeof(indices) / sizeof(unsigned);

    D3D11_BUFFER_DESC indexBufferDesc;
    ZeroMemory(&indexBufferDesc, sizeof(D3D11_BUFFER_DESC));
    indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
    indexBufferDesc.ByteWidth = sizeof(indices);
    indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
    indexBufferDesc.CPUAccessFlags = 0;

    D3D11_SUBRESOURCE_DATA indexData;
    ZeroMemory(&indexData, sizeof(D3D11_SUBRESOURCE_DATA));
    indexData.pSysMem = indices;

    device->CreateBuffer(&indexBufferDesc, &indexData, &indexBuffer);

    D3D11_INPUT_ELEMENT_DESC inputElementDesc[] =
    {
        {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
        {"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
        {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
        {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 40, D3D11_INPUT_PER_VERTEX_DATA, 0},
        {"TEXCOORD", 1, DXGI_FORMAT_R32G32B32_FLOAT, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1}
    };

    int inputElementCount = sizeof(inputElementDesc) / sizeof(D3D11_INPUT_ELEMENT_DESC);

    technique = effect->GetTechniqueByIndex(0);
    pass = technique->GetPassByIndex(0);

    D3DX11_PASS_DESC passDesc;
    pass->GetDesc(&passDesc);

    result = device->CreateInputLayout(inputElementDesc, inputElementCount,
                                       passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &inputLayout);

    DXUTGetGlobalResourceCache().CreateTextureFromFile(device, deviceContext, L"Content/Textures/Terrain/Grass.dds", &surfaceTexture);
    evSurfaceTexture = effect->GetVariableByName("SurfaceTexture")->AsShaderResource();
    evWorld = effect->GetVariableByName("World")->AsMatrix();
    evViewProjection = effect->GetVariableByName("ViewProjection")->AsMatrix();

    evSurfaceTexture->SetResource(surfaceTexture);

    world = Matrix::createTranslation((-INSTANCE_COUNT_X * INSTANCE_SIZE) / 2, 0, (-INSTANCE_COUNT_Y * INSTANCE_SIZE) / 2);

    deviceContext->Release();
}
void ComplexTree::init(ID3D11Device* device)
{
	ID3D11DeviceContext* deviceContext;
	device->GetImmediateContext(&deviceContext);

	HRESULT result = trunkMesh.Create(device, trunkPath, true);

	boundingBoxCenter = trunkMesh.GetMeshBBoxCenter(0);
	boundingBoxExtents = trunkMesh.GetMeshBBoxExtents(0);

	ID3DBlob* errorBlob;
	ID3DBlob* shaderBlob;

	result = D3DX11CompileFromFileA("Content/Effects/Trunk.fx", 0, 0, 0, "fx_5_0", 0, 0, 0, &shaderBlob, &errorBlob, 0);

	char* errorBuffer;
	if(errorBlob)
	{
		errorBuffer = (char*)errorBlob->GetBufferPointer();
	}

	result = D3DX11CreateEffectFromMemory(shaderBlob->GetBufferPointer(), shaderBlob->GetBufferSize(), 0, device, &effect);
	
	if(shaderBlob)
		shaderBlob->Release();
	if(errorBlob)
		errorBlob->Release();

	for(int i = 0; i < TREE_INSTANCE_COUNT; ++i)
	{
		treePositions[i].x = (rand() / (float)RAND_MAX) * TREE_BORDER - TREE_BORDER / 2.0f;
		treePositions[i].y = 0;
		treePositions[i].z = (rand() / (float)RAND_MAX) * TREE_BORDER - TREE_BORDER / 2.0f;
	}

	D3D11_BUFFER_DESC instanceBufferDesc;
	ZeroMemory(&instanceBufferDesc, sizeof(D3D11_BUFFER_DESC));

	instanceBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	instanceBufferDesc.ByteWidth = sizeof(treePositions);
	instanceBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	instanceBufferDesc.CPUAccessFlags = 0;

	D3D11_SUBRESOURCE_DATA instanceData;
	ZeroMemory(&instanceData, sizeof(D3D11_SUBRESOURCE_DATA));
	instanceData.pSysMem = treePositions;

	device->CreateBuffer(&instanceBufferDesc, &instanceData, &instanceBuffer);

	technique = effect->GetTechniqueByName("Trunk");
	techniqueLOD1 = effect->GetTechniqueByName("TrunkLOD1");
	pass = technique->GetPassByIndex(0);
	passLOD1 = techniqueLOD1->GetPassByIndex(0);

	D3D11_INPUT_ELEMENT_DESC inputElementDescLOD0[] =
	{
		{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"TEXCOORD", 1, DXGI_FORMAT_R32G32B32_FLOAT, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1}
	};

	int inputElementCount = sizeof(inputElementDescLOD0) / sizeof(D3D11_INPUT_ELEMENT_DESC);

	D3DX11_PASS_DESC passDesc;
	pass->GetDesc(&passDesc);
	result = device->CreateInputLayout(inputElementDescLOD0, inputElementCount,
		passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &inputLayout);

	D3D11_INPUT_ELEMENT_DESC inputElementDescLOD1[] =
	{
		{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}
	};

	inputElementCount = sizeof(inputElementDescLOD1) / sizeof(D3D11_INPUT_ELEMENT_DESC);

	passLOD1->GetDesc(&passDesc);
	device->CreateInputLayout(inputElementDescLOD1, inputElementCount,
		passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &inputLayoutLOD1);

	CDXUTResourceCache& resourceCache = DXUTGetGlobalResourceCache();
	resourceCache.CreateTextureFromFile(device, deviceContext, L"Content/Textures/Trees/rinde_bumpmap.dds", &bumpMap);
	resourceCache.CreateTextureFromFile(device, deviceContext, L"Content/Textures/Trees/rinde.dds", &alternativeTrunkTexture);
	resourceCache.CreateTextureFromFile(device, deviceContext, L"Content/Textures/Trees/trunk414_normalmap.dds", &normalMap);
	resourceCache.CreateTextureFromFile(device, deviceContext, L"Content/Textures/Trees/trunk414_front.dds", &billboardFront);
	resourceCache.CreateTextureFromFile(device, deviceContext, L"Content/Textures/Trees/trunk414_side.dds", &billboardSide);
	resourceCache.CreateTextureFromFile(device, deviceContext, L"Content/Textures/Trees/trunk414_top.dds", &billboardTop);

	evViewProjection = effect->GetVariableByName("ViewProjection")->AsMatrix();
	evWorld = effect->GetVariableByName("World")->AsMatrix();
	evTrunkTexture = effect->GetVariableByName("TrunkTexture")->AsShaderResource();
	evBumpMap = effect->GetVariableByName("BumpMapTexture")->AsShaderResource();
	evNormalMap = effect->GetVariableByName("NormalMapTexture")->AsShaderResource();
	evBillboardTop = effect->GetVariableByName("BillboardTop")->AsShaderResource();
	evBillboardSide = effect->GetVariableByName("BillboardSide")->AsShaderResource();
	evBillboardFront = effect->GetVariableByName("BillboardFront")->AsShaderResource();
	evEdgeFactor = effect->GetVariableByName("EdgeFactor")->AsScalar();
	evInsideFactor = effect->GetVariableByName("InsideFactor")->AsScalar();
	evMinDistance = effect->GetVariableByName("MinDistance")->AsScalar();
	evMaxDistance = effect->GetVariableByName("MaxDistance")->AsScalar();
	evBoundingBoxCenter = effect->GetVariableByName("BoundingBoxCenter")->AsScalar();
	evBoundingBoxExtents = effect->GetVariableByName("BoundingBoxExtents")->AsScalar();
	evGSCulling = effect->GetVariableByName("GSCulling")->AsScalar();
	evShowSavedCulling = effect->GetVariableByName("ShowSavedCulling")->AsScalar();
	evSavedViewProjection = effect->GetVariableByName("SavedViewProjection")->AsMatrix();

	evCameraPosition = effect->GetVariableByName("CameraPosition")->AsVector();
	evLightVector = effect->GetVariableByName("LightVector")->AsVector();
	evAmbientLight = effect->GetVariableByName("AmbientLight")->AsVector();
	evDiffuseLight = effect->GetVariableByName("DiffuseLight")->AsVector();
	evSpecularLight = effect->GetVariableByName("SpecularLight")->AsVector();
	evShininess = effect->GetVariableByName("Shininess")->AsScalar();

	evBumpMap->SetResource(bumpMap);
	evTrunkTexture->SetResource(alternativeTrunkTexture);
	evNormalMap->SetResource(normalMap);
	evBillboardTop->SetResource(billboardTop);
	evBillboardFront->SetResource(billboardFront);
	evBillboardSide->SetResource(billboardSide);
	evEdgeFactor->SetFloat(TREE_TESSELLATION_FACTOR_EDGES);
	evInsideFactor->SetFloat(TREE_TESSELLATION_FACTOR_INSIDE);
	evMinDistance->SetFloat(TREE_MIN_DISTANCE);
	evMaxDistance->SetFloat(TREE_MAX_DISTANCE);
	evBoundingBoxCenter->SetFloatArray(boundingBoxCenter, 0, 3);
	evBoundingBoxExtents->SetFloatArray(boundingBoxExtents, 0, 3);

	deviceContext->Release();
}