Esempio n. 1
0
void Initialize(int argc, char* argv[])
{
  GLenum GlewInitResult;

  InitWindow(argc, argv);

  glewExperimental = GL_TRUE;
  GlewInitResult = glewInit();

  if (GLEW_OK != GlewInitResult) {
    fprintf(
      stderr,
      "ERROR: %s\n",
      glewGetErrorString(GlewInitResult)
    );
    exit(EXIT_FAILURE);
  }
  
  fprintf(
    stdout,
    "INFO: OpenGL Version: %s\n",
    glGetString(GL_VERSION)
  );

  CreateShaders();
  CreateVBO();

  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
Esempio n. 2
0
bool Model::Initialize(std::wstring _modelName,
	ID3D11Device* _device)
{
	bool result;

	result = ObjLoader::LoadObj(
		_modelName,
		_device,
		meshVertexBuff,
		meshIndexBuff,
		indexCount,
		pickingPoints,
		pickingIndices,
		objMatrix,
		modelMats
	);
	if (!result)
	{
		return false;
	}

	result = CreateShaders(_device);
	if (!result)
	{
		return false;
	}
	return true;
}
void VCoronaManager::OnWorldInit()
{
#ifdef SUPPORTS_CORONAS
  // Init mesh
  VisMBVertexDescriptor_t CubeFormatDescriptor;
  // now set all used components in the descriptor
  CubeFormatDescriptor.m_iPosOfs = offsetof(VCubeFormat, vPos) | VERTEXDESC_FORMAT_FLOAT3;

  // set the vertex stride
  CubeFormatDescriptor.m_iStride = sizeof(VCubeFormat);

  // first, we create a new mesh buffer
  m_spBillboardMesh = new VisMeshBuffer_cl();
  m_spBillboardMesh->AllocateVertices(CubeFormatDescriptor, 6);
  VCubeFormat *pVertex = (VCubeFormat *)m_spBillboardMesh->LockVertices(VIS_LOCKFLAG_DISCARDABLE);

  pVertex[0].vPos.set(0.0, -1.0, -1.0);
  pVertex[1].vPos.set(0.0, -1.0,  1.0);
  pVertex[2].vPos.set(0.0,  1.0, -1.0);
  pVertex[3].vPos.set(0.0,  1.0, -1.0);
  pVertex[4].vPos.set(0.0, -1.0,  1.0);
  pVertex[5].vPos.set(0.0,  1.0,  1.0);

  m_spBillboardMesh->UnLockVertices();
  m_spBillboardMesh->EnsureLoaded();

  CreateShaders();
#endif
}
Esempio n. 4
0
bool Model::Initialize(std::wstring _modelName, 
	ID3D11Device* _device, 
	std::vector<XMFLOAT3>& _collidableGeometryPositions, 
	std::vector<uint32_t>& _collidableGeometryIndices,
	bool _pickable)
{
	bool result;

	result = ObjLoader::LoadObj(
		_modelName, 
		_device,
		meshVertexBuff,
		meshIndexBuff,
		indexCount,
		pickingPoints,
		pickingIndices,
		objMatrix,
		modelMats,
		&_collidableGeometryPositions, 
		&_collidableGeometryIndices, 
		_pickable
	);
	if (!result)
	{
		return false;
	}

	result = CreateShaders(_device);
	if (!result)
	{
		return false;
	}
	return true;
}
Esempio n. 5
0
	bool Renderer::Initialize()
	{
		// Create/Get required systems		
		g_resource_cache		= m_context->GetSubsystem<ResourceCache>().get();
		m_profiler				= m_context->GetSubsystem<Profiler>().get();
		// Editor specific
		m_gizmo_grid			= make_unique<Grid>(m_rhi_device);
		m_gizmo_transform		= make_unique<Transform_Gizmo>(m_context);
		// Create a constant buffer that will be used for most shaders
		m_buffer_global	= make_shared<RHI_ConstantBuffer>(m_rhi_device);
		m_buffer_global->Create<ConstantBufferGlobal>();
		// Line buffer
		m_vertex_buffer_lines	= make_shared<RHI_VertexBuffer>(m_rhi_device);

#ifdef API_GRAPHICS_VULKAN
		return true;
#endif

		CreateDepthStencilStates();
		CreateRasterizerStates();
		CreateBlendStates();
		CreateRenderTextures();
		CreateFonts();
		CreateShaders();
		CreateSamplers();
		CreateTextures();

		return true;
	}
Esempio n. 6
0
void Initialize (int argc, char *argv[])
{
  GLenum GlewInitResult;
  TempString = (char *) malloc (512 + strlen(WINDOW_TITLE_PREFIX));
  TempString[0]='\0';

  InitWindow (argc, argv);

  glewExperimental = GL_TRUE;
  GlewInitResult = glewInit();

  if (GLEW_OK != GlewInitResult) {
    fprintf (stderr,
	     "ERROR: %s\n",
	     glewGetErrorString (GlewInitResult) );
    exit (EXIT_FAILURE);
  }

  fprintf (stdout, "INFO: OpengGL Version: %s\n", glGetString (GL_VERSION));

  CreateShaders ();
  CreateVBO ();

  glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
}
Esempio n. 7
0
void OpenGLBookApp::setup()
{
    LoadShaders();
    CreateShaders();
    CreateVBO();
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
Esempio n. 8
0
    //
    // Constructor
    //
    CSample03::CSample03( 
                         HINSTANCE Instance, UINT Width, UINT Height, const WCHAR *Caption 
                         ):
        CDemo_GL( Instance, Width, Height, Caption )
    {
        Vec3<float> Eye( 0.0f, 0.0f, 5.0f );
        Vec3<float> At( 0.0f, 0.0f, 0.0f );
        Vec3<float> Up( 0.0f, 1.0f, 0.0f );

        m_View.LookAtRH( Eye, At, Up ); 

        //
        // OpenGL objects
        //

        CreateShaders();
        CreateVertexBuffers();
        CreateIndexBuffers();

        m_OcclusionQuery = new GL::CQuery();

        //
        // App
        //

        m_TrackBall = new UI::CTrackBall( Vec2<float>( m_Width / 2.0f, m_Height / 2.0f ), 250.0f, UI::CTrackBall::RT_TRACKBALL );
    }
bool Tutorial3_Texturing::onCreate(int a_argc, char* a_argv[]) 
{
	// initialise the Gizmos helper class
	//Gizmos::create();

	// create a world-space matrix for a camera
	m_cameraMatrix = glm::inverse( glm::lookAt(glm::vec3(10,10,10),glm::vec3(0,0,0), glm::vec3(0,1,0)) );

	// get window dimensions to calculate aspect ratio
	int width = 0, height = 0;
	glfwGetWindowSize(m_window, &width, &height);

	// create a perspective projection matrix with a 90 degree field-of-view and widescreen aspect ratio
	m_projectionMatrix = glm::perspective(glm::pi<float>() * 0.25f, width / (float)height, 0.1f, 1000.0f);

	// set the clear colour and enable depth testing and backface culling
	glClearColor(0.25f,0.25f,0.25f,1);
	glEnable(GL_DEPTH_TEST);
	//glEnable(GL_CULL_FACE);

	LoadTexture("./textures/steam.png");

	CreateShaders();

	// create a simple plane to render
	Utility::build3DPlane(10, m_VAO, m_VBO, m_IBO);

	return true;
}
	void RenderingContext::Create()
	{
		Microsoft::WRL::ComPtr<ID3DBlob> VertexShaderBlob;
		Microsoft::WRL::ComPtr<ID3DBlob> PixelShaderBlob;

		GraphicsContext::LoadAndCompileShader(VertexShaderBlob, PixelShaderBlob, IDR_SHADER11, "5_0");

		CreateShaders(VertexShaderBlob, PixelShaderBlob);
		CreateInputLayout(VertexShaderBlob);

		CreateConstantBuffer(CameraConstantBuffer, sizeof(CameraConstantBufferType));
		CreateConstantBuffer(ObjectConstantBuffer, sizeof(ObjectConstantBufferType));
	}
Esempio n. 11
0
void VCoronaManager::OnHandleCallback(IVisCallbackDataObject_cl *pData)
{
#ifdef SUPPORTS_CORONAS
  // hook into an existing renderloop to render the lens flares
  if (pData->m_pSender == &Vision::Callbacks.OnRenderHook && m_Instances.Count() )
  {
    if ( ((VisRenderHookDataObject_cl *)pData)->m_iEntryConst == m_iCoronaRenderHookConst)
    {
      RenderAllVisibleCoronas();
    }
    return;
  }

  if (pData->m_pSender == &Vision::Callbacks.OnVisibilityPerformed)
  {
    if (m_Instances.Count())
    {
      if (m_bTeleportedLastFrame && m_bForceQueryOnTeleport)
      {
        UpdateCoronas(VCUF_ADD | VCUF_REMOVE | VCUF_UPDATE | VCUF_FORCE_SCHEDULE);
      }
      else
      {
        UpdateCoronas(VCUF_ADD | VCUF_REMOVE | VCUF_UPDATE);
      }
    }
    return;
  }
#endif

  // UnloadWorld : do some per-scene deinitialisation
  if (pData->m_pSender == &Vision::Callbacks.OnWorldInit)
  {
    OnWorldInit();
    return;
  }

  if (pData->m_pSender == &Vision::Callbacks.OnWorldDeInit)
  {
    OnWorldDeInit();
    return;
  }

  if (pData->m_pSender == &Vision::Callbacks.OnReassignShaders)
  {
    m_spCoronaTechnique = NULL;
    m_spCoronaShader = NULL;
    CreateShaders();
    return;
  }
}
Esempio n. 12
0
void SWRenderer::Prepare()
{
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);  // 4-byte pixel alignment
	glGenTextures(1, &s_RenderTarget);

	CreateShaders();
	// TODO: Enable for GLES once RasterFont supports GLES
#ifndef USE_GLES
	s_pfont = new RasterFont();
	glEnable(GL_TEXTURE_2D);
#endif
	GL_REPORT_ERRORD();
}
Esempio n. 13
0
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
{
	MSG msg = { 0 };
	HWND wndHandle = InitWindow(hInstance); //1. Skapa fönster
	
	if (wndHandle)
	{
		CreateDirect3DContext(wndHandle); //2. Skapa och koppla SwapChain, Device och Device Context

		SetViewport(); //3. Sätt viewport

		CreateShaders(); //4. Skapa vertex- och pixel-shaders

		CreateTriangleData(); //5. Definiera triangelvertiser, 6. Skapa vertex buffer, 7. Skapa input layout

		ShowWindow(wndHandle, nCmdShow);

		while (WM_QUIT != msg.message)
		{
			if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
			else
			{
				Render(); //8. Rendera

				gSwapChain->Present(0, 0); //9. Växla front- och back-buffer
			}
		}

		gVertexBuffer->Release();

		gVertexLayout->Release();
		gVertexShader->Release();
		gPixelShader->Release();

		gBackbufferRTV->Release();
		gSwapChain->Release();
		gDevice->Release();
		gDeviceContext->Release();
		DestroyWindow(wndHandle);
	}

	return (int) msg.wParam;
}
Esempio n. 14
0
TextureShader::TextureShader(ID3D11Device *device, ID3D11DeviceContext *context)
{
	if (!CompileShaders()) {
		DebugOut("TextureShader::CompileShaders failed!\n");
		return;
	}

	if (!CreateShaders(device)) {
		DebugOut("TextureShader::CreateShaders failed!\n");
		return;
	}

	if (!MakeBuffers(device, context)) {
		DebugOut("TextureShader::MakeBuffers failed!\n");
		return;
	}
};
Esempio n. 15
0
bool DemoApp::Init()
{
	if (!DemoBase::Init())
		return false;

	m_pShadowMap = new ShadowMap(md3dDevice, mShadowMapSize, mShadowMapSize);
	m_pSkybox = new SkyBox( md3dDevice,  1000, 50, 50, "test");

	CreateLights();
	CreateShaders();
	CreateGeometry();
	CreateContantBuffers();
	CreateSamplerStates();
	CreateRenderStates();
	SetUpSceneConsts();

	return true;
}
Esempio n. 16
0
void SWRenderer::Prepare()
{
	s_xfbColorTexture[0] = new u8[MAX_XFB_WIDTH * MAX_XFB_HEIGHT * 4];
	s_xfbColorTexture[1] = new u8[MAX_XFB_WIDTH * MAX_XFB_HEIGHT * 4];

	s_currentColorTexture = 0;

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);  // 4-byte pixel alignment
	glGenTextures(1, &s_RenderTarget);

	CreateShaders();
	// TODO: Enable for GLES once RasterFont supports GLES
	if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
	{
		s_pfont = new RasterFont();
		glEnable(GL_TEXTURE_2D);
	}
}
void App::LoadTessellatedTerrain()
{
	//D3DXVECTOR3 vEye(786.1f,  -86.5f,  62.2f);
	//D3DXVECTOR3  vAt(786.3f, -130.0f, 244.1f);
	D3DXVECTOR3 vEye(18595.1f,  200.4f,  -16347.6f);
	D3DXVECTOR3  vAt(18596.1f, 200.315f, -16348.f);

	ActiveCam_->setFrom((float*)vEye);
	ActiveCam_->setTo((float*)vAt);
	ActiveCam_->setFOV(RAD2DEG(noMath::PI / 3));
	ActiveCam_->setNear(CLIP_NEAR);
	ActiveCam_->setFar(CLIP_FAR);
	ActiveCam_->SetAspect(GetAspectRatio());
	ActiveCam_->computeModelView();	
	ActiveCam_->ComputeProjection();
	
	g_ResetTerrain = true;
	ReadStars();
	
	CreateAmplifiedHeights(device);
	
	CreateShaders(device, context);
	CreateDeformEffect(device);

	// This array defines the outer width of each successive ring.
	int widths[] = { 0, 16, 16, 16, 16 };
	g_nRings = sizeof(widths) / sizeof(widths[0]) - 1;		// widths[0] doesn't define a ring hence -1
	assert(g_nRings <= MAX_RINGS);

	float tileWidth = 0.125f;
	for (int i=0; i!=g_nRings && i!=MAX_RINGS; ++i)
	{
		g_pTileRings[i] = new TileRing(device, widths[i]/2, widths[i+1], tileWidth);
		tileWidth *= 2.0f;
	}
	CreateMeshes(device, context);

	OnSizeTerrain();
}
Esempio n. 18
0
/* Constructor
 */
D3DRenderer::D3DRenderer(HWND hWnd)
{	
	mD3D = NULL;
	mD3DDevice = NULL;

	mVertexBuffer = NULL;
	mVertexDeclaration = NULL;
	
	InitD3D(hWnd);
	CreateBuffers();
	CreateShaders();

	D3DXMatrixIdentity(&mModel);
	D3DXMatrixIdentity(&mView);
	D3DXMatrixIdentity(&mProjection);

	mNextSwapChainID = 1000;
	mNextShaderID = 1000;
	mCurrentShaderID = 0;

	mDeviceLost = false;
}
Esempio n. 19
0
	void Prepare()
	{
		//legacy multitexturing: select texture channel only.
		glActiveTexture(GL_TEXTURE0);
		glPixelStorei(GL_UNPACK_ALIGNMENT, 4);  // 4-byte pixel alignment
		if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
		{
			glShadeModel(GL_SMOOTH);
			glDisable(GL_BLEND);
			glClearDepth(1.0f);
			glEnable(GL_SCISSOR_TEST);
			glDisable(GL_LIGHTING);
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();

			glClientActiveTexture(GL_TEXTURE0);
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
			glEnable(GL_TEXTURE_RECTANGLE_ARB);
			glStencilFunc(GL_ALWAYS, 0, 0);
			glDisable(GL_STENCIL_TEST);
		}
		// used by hw rasterizer if it enables blending and depth test
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glDepthFunc(GL_LEQUAL);

		glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

		CreateShaders();
		if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
			texType = GL_TEXTURE_RECTANGLE;
		else
			texType = GL_TEXTURE_2D;

		GL_REPORT_ERRORD();
	}
Esempio n. 20
0
//----------------------------------------------------------------------------
void ShadowMaps::CreateScene ()
{
    CreateScreenSpaceObjects();
    CreateShaders();

    // Create a scene graph containing a sphere and a plane.  The sphere will
    // cast a shadow on the plane.
    mScene = new0 Node();

    VertexFormat* vformat = VertexFormat::Create(3,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_NORMAL, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);

    StandardMesh sm(vformat);
    TriMesh* plane = sm.Rectangle(128, 128, 16.0f, 16.0f);
    plane->SetEffectInstance(mPlaneSceneInstance);
    mScene->AttachChild(plane);

    TriMesh* sphere = sm.Sphere(64, 64, 1.0f);
    sphere->LocalTransform.SetTranslate(APoint(0.0f, 0.0f, 1.0f));
    sphere->SetEffectInstance(mSphereSceneInstance);
    mScene->AttachChild(sphere);
}
Esempio n. 21
0
D3D::D3D(HWND win)
{
    windowWidth = WINDOWSWIDTH;
    windowHeight = WINDOWSHEIGHT;
    // create a struct to hold information about the swap chain
    DXGI_SWAP_CHAIN_DESC scd;

    // clear out the struct for use
    ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));

    // fill the swap chain description struct
    scd.BufferCount = 1;                                    // one back buffer
    scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;     // use 32-bit color
    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;      // how swap chain is to be used
    scd.OutputWindow = win;                           // the window to be used
    scd.SampleDesc.Count = 1;                               // how many multisamples
    scd.SampleDesc.Quality = 0;
    scd.Windowed = TRUE;                                    // windowed/full-screen mode

    // create a device, device context and swap chain using the information in the scd struct
    HRESULT hr = D3D11CreateDeviceAndSwapChain(NULL,
                 D3D_DRIVER_TYPE_HARDWARE,
                 NULL,
                 NULL,
                 NULL,
                 NULL,
                 D3D11_SDK_VERSION,
                 &scd,
                 &swapChain,
                 &device,
                 NULL,
                 &devcon);

    if (SUCCEEDED(hr))
    {
        // get the address of the back buffer
        ID3D11Texture2D* pBackBuffer = nullptr;
        swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);

        // use the back buffer address to create the render target
        device->CreateRenderTargetView(pBackBuffer, NULL, &backbuffer);
        pBackBuffer->Release();

        D3D11_TEXTURE2D_DESC depthStencilDesc;
        ZeroMemory(&depthStencilDesc, sizeof(depthStencilDesc));
        depthStencilDesc.Width = 640;
        depthStencilDesc.Height = 480;
        depthStencilDesc.MipLevels = 0;
        depthStencilDesc.ArraySize = 1;
        depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
        depthStencilDesc.SampleDesc.Count = 1;
        depthStencilDesc.SampleDesc.Quality = 0;
        depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
        depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
        depthStencilDesc.MiscFlags = 0;
        depthStencilDesc.CPUAccessFlags = 0;

        ID3D11Texture2D* pStencilTexture;
        device->CreateTexture2D(&depthStencilDesc, NULL, &pStencilTexture);
        device->CreateDepthStencilView(pStencilTexture, NULL, &depthStencilView);
        pStencilTexture->Release();

        // set the render target as the back buffer
        devcon->OMSetRenderTargets(1, &backbuffer, depthStencilView);

        ID3D11RasterizerState* p_RasterState;					// disables default backface culling
        D3D11_RASTERIZER_DESC descRaster;
        ZeroMemory(&descRaster, sizeof(D3D11_RASTERIZER_DESC));
        descRaster.FillMode = D3D11_FILL_SOLID;					// WIREFRAME;
        descRaster.CullMode = D3D11_CULL_NONE;
        descRaster.MultisampleEnable = TRUE;

        device->CreateRasterizerState(&descRaster, &p_RasterState);
        devcon->RSSetState(p_RasterState);
    }

    viewPort.Width = (float)WINDOWSWIDTH;
    viewPort.Height = (float)WINDOWSHEIGHT;
    viewPort.MinDepth = 0.0f;
    viewPort.MaxDepth = 1.0f;
    viewPort.TopLeftX = 0;
    viewPort.TopLeftY = 0;
    devcon->RSSetViewports(1, &viewPort);

    CreateShaders();
    Create();
}
Esempio n. 22
0
bool Lighting::Init(LPDIRECT3DDEVICE9 Device)
{

	if(!m_InitDone)
	{
		m_Device = Device;

		m_VertexFile[SHADER_DIR]				= _T("DL1.nvo");
		m_VertexRes[SHADER_DIR]					=  IDR_DL1_NVO;

		m_PixelFile[SHADER_DIR]					= _T("DL1.pso");
		m_PixelRes[SHADER_DIR]					=  IDR_DL1_PSO;

		m_VertexFile[SHADER_DIR_SPEC]			= _T("DL2.nvo");
		m_VertexRes[SHADER_DIR_SPEC]			=  IDR_DL2_NVO;

		m_PixelFile[SHADER_DIR_SPEC]			= _T("DL2.pso");
		m_PixelRes[SHADER_DIR_SPEC]				=  IDR_DL2_PSO;

		m_VertexFile[SHADER_DIR_NORMAL]			= _T("DL3.nvo");
		m_VertexRes[SHADER_DIR_NORMAL]			=  IDR_DL3_NVO;

		m_PixelFile[SHADER_DIR_NORMAL]			= _T("DL3.pso");
		m_PixelRes[SHADER_DIR_NORMAL]			=  IDR_DL3_PSO;

		m_VertexFile[SHADER_DIR_NORMAL_SPEC]	= _T("DL4.nvo");
		m_VertexRes[SHADER_DIR_NORMAL_SPEC]		=  IDR_DL4_NVO;

		m_PixelFile[SHADER_DIR_NORMAL_SPEC]		= _T("DL4.pso");
		m_PixelRes[SHADER_DIR_NORMAL_SPEC]		=  IDR_DL4_PSO;

		m_VertexFile[SHADER_OMNI]				= _T("OL1.nvo");
		m_VertexRes[SHADER_OMNI]				=  IDR_OL1_NVO;

		m_PixelFile[SHADER_OMNI]				= _T("OL1.pso");
		m_PixelRes[SHADER_OMNI]					=  IDR_OL1_PSO;

		m_VertexFile[SHADER_OMNI_SPEC]			= _T("OL2.nvo");
		m_VertexRes[SHADER_OMNI_SPEC]			=  IDR_OL2_NVO;

		m_PixelFile[SHADER_OMNI_SPEC]			= _T("OL2.pso");
		m_PixelRes[SHADER_OMNI_SPEC]			=  IDR_OL2_PSO;

		m_VertexFile[SHADER_OMNI_NORMAL]		= _T("OL3.nvo");
		m_VertexRes[SHADER_OMNI_NORMAL]			=  IDR_OL3_NVO;

		m_PixelFile[SHADER_OMNI_NORMAL]			= _T("OL3.pso");
		m_PixelRes[SHADER_OMNI_NORMAL]			=  IDR_OL3_PSO;

		m_VertexFile[SHADER_OMNI_NORMAL_SPEC]	= _T("OL4.nvo");
		m_VertexRes[SHADER_OMNI_NORMAL_SPEC]	=  IDR_OL4_NVO;

		m_PixelFile[SHADER_OMNI_NORMAL_SPEC]	= _T("OL4.pso");
		m_PixelRes[SHADER_OMNI_NORMAL_SPEC]		=  IDR_OL4_PSO;

		m_VertexFile[SHADER_SPOT]				= _T("SL1.nvo");
		m_VertexRes[SHADER_SPOT]				=  IDR_SL1_NVO;

		m_PixelFile[SHADER_SPOT]				= _T("SL1.pso");
		m_PixelRes[SHADER_SPOT]					=  IDR_SL1_PSO;

		m_VertexFile[SHADER_SPOT_SPEC]			= _T("SL2.nvo");
		m_VertexRes[SHADER_SPOT_SPEC]			=  IDR_SL2_NVO;

		m_PixelFile[SHADER_SPOT_SPEC]			= _T("SL2.pso");
		m_PixelRes[SHADER_SPOT_SPEC]			=  IDR_SL2_PSO;

		m_VertexFile[SHADER_SPOT_NORMAL]		= _T("SL3.nvo");
		m_VertexRes[SHADER_SPOT_NORMAL]			=  IDR_SL3_NVO;

		m_PixelFile[SHADER_SPOT_NORMAL]			= _T("SL3.pso");
		m_PixelRes[SHADER_SPOT_NORMAL]			=  IDR_SL3_PSO;

		m_VertexFile[SHADER_SPOT_NORMAL_SPEC]	= _T("SL4.nvo");
		m_VertexRes[SHADER_SPOT_NORMAL_SPEC]	=  IDR_SL4_NVO;

		m_PixelFile[SHADER_SPOT_NORMAL_SPEC]	= _T("SL4.pso");
		m_PixelRes[SHADER_SPOT_NORMAL_SPEC]		=  IDR_SL4_PSO;

		m_VertexFile[SHADER_SPEC]				= _T("SP.nvo");
		m_VertexRes[SHADER_SPEC]				=  IDR_SP_NVO;

		m_PixelFile[SHADER_SPEC]				= _T("SP.pso");
		m_PixelRes[SHADER_SPEC]					=  IDR_SP_PSO;

		m_VertexFile[SHADER_AMBIENT]			= _T("A.nvo");
		m_VertexRes[SHADER_AMBIENT]				=  IDR_A_NVO;

		m_PixelFile[SHADER_AMBIENT]				= _T("A.pso");
		m_PixelRes[SHADER_AMBIENT]				=  IDR_A_PSO;


		DestroyShaders();

		if(!CreateShaders(true))
		{
			return(false);
		}

		TSTR textureName = _T("GAM.tga");
		if(!LoadAttenTexture(textureName, Device))
		{
			return(false);
		}

		textureName = _T("GSPM.tga");
		if(!LoadSpotTexture(textureName, Device))
		{
			return(false);
		}

		if(!CreateNormalizationCubeMap(Device,256))
		{
			return(false);
		}

		// do it when we get going......Should only be one time
		m_InitDone = true;
		m_Ready    = true;

	}

	return(true);

}
Esempio n. 23
0
bool Mesh_D3D11::CreateBuffers(void)
{
  // Define the input layout
  D3D11_INPUT_ELEMENT_DESC layout[] =
  {
      { "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_R32G32B32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 }, 
  };
  unsigned int iElements = sizeof(layout)/sizeof(layout[0]);

  // create shaders if not created yet
  if(g_pTechniqueShadows == NULL)
  {
    if(!CreateShaders()) return false;
  }

  // Create the input layout
  HRESULT hr;
  D3DX11_PASS_DESC PassDesc;
  hr = g_pTechniqueShadows->GetPassByIndex(0)->GetDesc(&PassDesc);
  if(FAILED(hr))
  {
    MessageBox(NULL, TEXT("Getting technique pass description failed!"), TEXT("Error!"), MB_OK);
    return false;
  }

  hr = GetApp()->GetDevice()->CreateInputLayout(layout, iElements, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &m_pVertexLayout);
  if(FAILED(hr))
  {
    MessageBox(NULL, TEXT("Creating input layout failed!"), TEXT("Error!"), MB_OK);
    return false;
  }

  // Create vertex buffer
  D3D11_BUFFER_DESC bd;
  bd.Usage = D3D11_USAGE_DEFAULT;
  bd.ByteWidth = m_iVertexSize * m_iNumVertices;
  bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
  bd.CPUAccessFlags = 0;
  bd.MiscFlags = 0;
  D3D11_SUBRESOURCE_DATA InitData;
  InitData.pSysMem = m_pVertices;
  hr = GetApp()->GetDevice()->CreateBuffer( &bd, &InitData, &m_pVertexBuffer );
  if(FAILED(hr))
  {
    MessageBox(NULL, TEXT("Creating vertex buffer failed!"), TEXT("Error!"), MB_OK);
    return false;
  }

  // Create index buffer
  bd.Usage = D3D11_USAGE_DEFAULT;
  bd.ByteWidth = sizeof(unsigned short) * m_iNumTris * 3;
  bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
  bd.CPUAccessFlags = 0;
  bd.MiscFlags = 0;
  InitData.pSysMem = m_pIndices;
  hr = GetApp()->GetDevice()->CreateBuffer( &bd, &InitData, &m_pIndexBuffer );
  if(FAILED(hr))
  {
    MessageBox(NULL, TEXT("Creating index buffer failed!"), TEXT("Error!"), MB_OK);
    return false;
  }

  return true;
}
Esempio n. 24
0
bool
CompositorD3D11::Initialize()
{
  bool force = gfxPrefs::LayersAccelerationForceEnabled();

  ScopedGfxFeatureReporter reporter("D3D11 Layers", force);

  if (!gfxPlatform::CanUseDirect3D11()) {
    NS_WARNING("Direct3D 11-accelerated layers are not supported on this system.");
    return false;
  }

  HRESULT hr;

  mDevice = gfxWindowsPlatform::GetPlatform()->GetD3D11Device();

  if (!mDevice) {
    return false;
  }

  mDevice->GetImmediateContext(byRef(mContext));

  if (!mContext) {
    return false;
  }

  mFeatureLevel = mDevice->GetFeatureLevel();

  mHwnd = (HWND)mWidget->GetNativeData(NS_NATIVE_WINDOW);

  memset(&mVSConstants, 0, sizeof(VertexShaderConstants));

  int referenceCount = 0;
  UINT size = sizeof(referenceCount);
  // If this isn't there yet it'll fail, count will remain 0, which is correct.
  mDevice->GetPrivateData(sLayerManagerCount, &size, &referenceCount);
  referenceCount++;
  mDevice->SetPrivateData(sLayerManagerCount,
                          sizeof(referenceCount),
                          &referenceCount);

  size = sizeof(DeviceAttachmentsD3D11*);
  if (FAILED(mDevice->GetPrivateData(sDeviceAttachmentsD3D11,
                                     &size,
                                     &mAttachments))) {
    mAttachments = new DeviceAttachmentsD3D11;
    mDevice->SetPrivateData(sDeviceAttachmentsD3D11,
                            sizeof(mAttachments),
                            &mAttachments);

    D3D11_INPUT_ELEMENT_DESC layout[] =
    {
      { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    };

    hr = mDevice->CreateInputLayout(layout,
                                    sizeof(layout) / sizeof(D3D11_INPUT_ELEMENT_DESC),
                                    LayerQuadVS,
                                    sizeof(LayerQuadVS),
                                    byRef(mAttachments->mInputLayout));

    if (FAILED(hr)) {
      return false;
    }

    Vertex vertices[] = { {{0.0, 0.0}}, {{1.0, 0.0}}, {{0.0, 1.0}}, {{1.0, 1.0}} };
    CD3D11_BUFFER_DESC bufferDesc(sizeof(vertices), D3D11_BIND_VERTEX_BUFFER);
    D3D11_SUBRESOURCE_DATA data;
    data.pSysMem = (void*)vertices;

    hr = mDevice->CreateBuffer(&bufferDesc, &data, byRef(mAttachments->mVertexBuffer));

    if (FAILED(hr)) {
      return false;
    }

    if (!CreateShaders()) {
      return false;
    }

    CD3D11_BUFFER_DESC cBufferDesc(sizeof(VertexShaderConstants),
                                   D3D11_BIND_CONSTANT_BUFFER,
                                   D3D11_USAGE_DYNAMIC,
                                   D3D11_CPU_ACCESS_WRITE);

    hr = mDevice->CreateBuffer(&cBufferDesc, nullptr, byRef(mAttachments->mVSConstantBuffer));
    if (FAILED(hr)) {
      return false;
    }

    cBufferDesc.ByteWidth = sizeof(PixelShaderConstants);
    hr = mDevice->CreateBuffer(&cBufferDesc, nullptr, byRef(mAttachments->mPSConstantBuffer));
    if (FAILED(hr)) {
      return false;
    }

    CD3D11_RASTERIZER_DESC rastDesc(D3D11_DEFAULT);
    rastDesc.CullMode = D3D11_CULL_NONE;
    rastDesc.ScissorEnable = TRUE;

    hr = mDevice->CreateRasterizerState(&rastDesc, byRef(mAttachments->mRasterizerState));
    if (FAILED(hr)) {
      return false;
    }

    CD3D11_SAMPLER_DESC samplerDesc(D3D11_DEFAULT);
    hr = mDevice->CreateSamplerState(&samplerDesc, byRef(mAttachments->mLinearSamplerState));
    if (FAILED(hr)) {
      return false;
    }

    samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
    hr = mDevice->CreateSamplerState(&samplerDesc, byRef(mAttachments->mPointSamplerState));
    if (FAILED(hr)) {
      return false;
    }

    CD3D11_BLEND_DESC blendDesc(D3D11_DEFAULT);
    D3D11_RENDER_TARGET_BLEND_DESC rtBlendPremul = {
      TRUE,
      D3D11_BLEND_ONE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
      D3D11_BLEND_ONE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
      D3D11_COLOR_WRITE_ENABLE_ALL
    };
    blendDesc.RenderTarget[0] = rtBlendPremul;
    hr = mDevice->CreateBlendState(&blendDesc, byRef(mAttachments->mPremulBlendState));
    if (FAILED(hr)) {
      return false;
    }

    D3D11_RENDER_TARGET_BLEND_DESC rtBlendNonPremul = {
      TRUE,
      D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
      D3D11_BLEND_ONE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
      D3D11_COLOR_WRITE_ENABLE_ALL
    };
    blendDesc.RenderTarget[0] = rtBlendNonPremul;
    hr = mDevice->CreateBlendState(&blendDesc, byRef(mAttachments->mNonPremulBlendState));
    if (FAILED(hr)) {
      return false;
    }

    if (gfxPrefs::ComponentAlphaEnabled()) {
      D3D11_RENDER_TARGET_BLEND_DESC rtBlendComponent = {
        TRUE,
        D3D11_BLEND_ONE,
        D3D11_BLEND_INV_SRC1_COLOR,
        D3D11_BLEND_OP_ADD,
        D3D11_BLEND_ONE,
        D3D11_BLEND_INV_SRC_ALPHA,
        D3D11_BLEND_OP_ADD,
        D3D11_COLOR_WRITE_ENABLE_ALL
      };
      blendDesc.RenderTarget[0] = rtBlendComponent;
      hr = mDevice->CreateBlendState(&blendDesc, byRef(mAttachments->mComponentBlendState));
      if (FAILED(hr)) {
        return false;
      }
    }

    D3D11_RENDER_TARGET_BLEND_DESC rtBlendDisabled = {
      FALSE,
      D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
      D3D11_BLEND_ONE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
      D3D11_COLOR_WRITE_ENABLE_ALL
    };
    blendDesc.RenderTarget[0] = rtBlendDisabled;
    hr = mDevice->CreateBlendState(&blendDesc, byRef(mAttachments->mDisabledBlendState));
    if (FAILED(hr)) {
      return false;
    }
  }

  nsRefPtr<IDXGIDevice> dxgiDevice;
  nsRefPtr<IDXGIAdapter> dxgiAdapter;

  mDevice->QueryInterface(dxgiDevice.StartAssignment());
  dxgiDevice->GetAdapter(getter_AddRefs(dxgiAdapter));

#ifdef MOZ_METRO
  if (IsRunningInWindowsMetro()) {
    nsRefPtr<IDXGIFactory2> dxgiFactory;
    dxgiAdapter->GetParent(IID_PPV_ARGS(dxgiFactory.StartAssignment()));

    nsIntRect rect;
    mWidget->GetClientBounds(rect);

    DXGI_SWAP_CHAIN_DESC1 swapDesc = { 0 };
    // Automatically detect the width and the height from the winrt CoreWindow
    swapDesc.Width = rect.width;
    swapDesc.Height = rect.height;
    // This is the most common swapchain format
    swapDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
    swapDesc.Stereo = false;
    // Don't use multi-sampling
    swapDesc.SampleDesc.Count = 1;
    swapDesc.SampleDesc.Quality = 0;
    swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    // Use double buffering to enable flip
    swapDesc.BufferCount = 2;
    swapDesc.Scaling = DXGI_SCALING_NONE;
    // All Metro style apps must use this SwapEffect
    swapDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
    swapDesc.Flags = 0;

    /**
     * Create a swap chain, this swap chain will contain the backbuffer for
     * the window we draw to. The front buffer is the full screen front
     * buffer.
    */
    nsRefPtr<IDXGISwapChain1> swapChain1;
    hr = dxgiFactory->CreateSwapChainForCoreWindow(
           dxgiDevice, (IUnknown *)mWidget->GetNativeData(NS_NATIVE_ICOREWINDOW),
           &swapDesc, nullptr, getter_AddRefs(swapChain1));
    if (FAILED(hr)) {
        return false;
    }
    mSwapChain = swapChain1;
  } else
#endif
  {
    nsRefPtr<IDXGIFactory> dxgiFactory;
    dxgiAdapter->GetParent(IID_PPV_ARGS(dxgiFactory.StartAssignment()));

    DXGI_SWAP_CHAIN_DESC swapDesc;
    ::ZeroMemory(&swapDesc, sizeof(swapDesc));
    swapDesc.BufferDesc.Width = 0;
    swapDesc.BufferDesc.Height = 0;
    swapDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
    swapDesc.BufferDesc.RefreshRate.Numerator = 60;
    swapDesc.BufferDesc.RefreshRate.Denominator = 1;
    swapDesc.SampleDesc.Count = 1;
    swapDesc.SampleDesc.Quality = 0;
    swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    swapDesc.BufferCount = 1;
    swapDesc.OutputWindow = mHwnd;
    swapDesc.Windowed = TRUE;
    swapDesc.Flags = 0;


    /**
     * Create a swap chain, this swap chain will contain the backbuffer for
     * the window we draw to. The front buffer is the full screen front
     * buffer.
     */
    hr = dxgiFactory->CreateSwapChain(dxgiDevice, &swapDesc, byRef(mSwapChain));
    if (FAILED(hr)) {
     return false;
    }

    // We need this because we don't want DXGI to respond to Alt+Enter.
    dxgiFactory->MakeWindowAssociation(swapDesc.OutputWindow,
                                       DXGI_MWA_NO_WINDOW_CHANGES);
  }

  reporter.SetSuccessful();
  return true;
}
Esempio n. 25
0
	Renderer::Renderer() : probe_object(0), render_mode(render_tmu), do_lerp(true)
	{
		RenderStateManager &render_state_manager = engine.GetRenderStateManager();
		ID3D10Device *d3d10_device = engine.GetDevice();

		// Create shaders
		CreateShaders();

		// vertex buffers
		tmu_filtering_render_state.vertex_buffer_offsets.resize(1);
		tmu_filtering_render_state.vertex_buffers.resize(1);
		tmu_filtering_render_state.vertex_buffer_strides.push_back(sizeof(ProbeVertex));	

		alu_filtering_render_state.vertex_buffer_offsets.resize(1);
		alu_filtering_render_state.vertex_buffers.resize(1);
		alu_filtering_render_state.vertex_buffer_strides.push_back(sizeof(ProbeVertex));	

		// Topologies		
		tmu_filtering_render_state.topology = D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
		alu_filtering_render_state.topology = D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
		separator_render_state.topology = D3D10_PRIMITIVE_TOPOLOGY_LINELIST;

		// Depth stencil states
		D3D10_DEPTH_STENCIL_DESC depth_stencil_desc = render_state_manager.GetDefaultDepthStencilDesc();
		depth_stencil_desc.DepthEnable = false;
		
		d3d10_device->CreateDepthStencilState(&depth_stencil_desc, &tmu_filtering_render_state.depth_stencil_state);
		d3d10_device->CreateDepthStencilState(&depth_stencil_desc, &alu_filtering_render_state.depth_stencil_state);
		d3d10_device->CreateDepthStencilState(&depth_stencil_desc, &separator_render_state.depth_stencil_state);		
		
		// Blend states		
		d3d10_device->CreateBlendState(&render_state_manager.GetDefaultBlendDesc(), &tmu_filtering_render_state.blend_state);
		d3d10_device->CreateBlendState(&render_state_manager.GetDefaultBlendDesc(), &alu_filtering_render_state.blend_state);
		d3d10_device->CreateBlendState(&render_state_manager.GetDefaultBlendDesc(), &separator_render_state.blend_state);

		// Shader resources		
		tmu_filtering_render_state.ps_resources.resize(1);
		alu_filtering_render_state.ps_resources.resize(1);

		// Sampler states
		ID3D10SamplerState *sampler_state;
		D3D10_SAMPLER_DESC sampler_desc = render_state_manager.GetDefaultSamplerDesc();
		
		for(unsigned int i=0; i<5; ++i) {
			sampler_desc.Filter = D3D10_FILTER_ANISOTROPIC;
			sampler_desc.MaxAnisotropy = 1 << i;
			d3d10_device->CreateSamplerState(&sampler_desc, &aniso_sampler_states[i]);
		}
		tmu_filtering_render_state.ps_sampler_states.push_back(aniso_sampler_states[0]);		
		
		sampler_desc.Filter = D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT;		
		sampler_desc.MaxAnisotropy = 1;
		d3d10_device->CreateSamplerState(&sampler_desc, &sampler_state);
		alu_filtering_render_state.ps_sampler_states.push_back(sampler_state);
		
		// Initialize global render states		
		d3d10_device->CreateRasterizerState(&render_state_manager.GetDefaultRasterizerDesc(), &global_render_state.rasterizer_state);		
		global_render_state.viewports.resize(1);
		global_render_state.render_targets.push_back(0);		

		D3D10_RASTERIZER_DESC rasterizer_desc = render_state_manager.GetDefaultRasterizerDesc();
		rasterizer_desc.ScissorEnable = true;
		d3d10_device->CreateRasterizerState(&rasterizer_desc, &scissor_global_render_state.rasterizer_state);
		scissor_global_render_state.scissor_rects.resize(1);

		// Initialize filter parameter dynamic constant buffer
		unsigned int cbuffer_size = sizeof(FilterParameterConstants);
		filter_parameter_constant_buffer = new DynamicConstantBuffer(d3d10_device, cbuffer_size);
		tmu_filtering_render_state.vs_constant_buffers.push_back(filter_parameter_constant_buffer->GetConstantBuffer());
		tmu_filtering_render_state.ps_constant_buffers.push_back(filter_parameter_constant_buffer->GetConstantBuffer());
		alu_filtering_render_state.vs_constant_buffers.push_back(filter_parameter_constant_buffer->GetConstantBuffer());
		alu_filtering_render_state.ps_constant_buffers.push_back(filter_parameter_constant_buffer->GetConstantBuffer());		

		// Initialize filter parameter constants
		filter_parameter_constants.texture_size = Vector2(0.0f, 0.0f);
		filter_parameter_constants.max_anisotropy = 1.0f;
		filter_parameter_constants.lod_bias = 0.0f;
		filter_parameter_constants.texcoord_translation = Vector2(0.0f, 0.0f);
		filter_parameter_constants.tex_scale = 1.0f;
		filter_parameter_constants.filter_mode = 0.0f;
		filter_parameter_constants.do_lerp = do_lerp;
		filter_parameter_constants.gamma_correction = true;
		filter_parameter_constant_buffer->Fill(&filter_parameter_constants);	
		texture_movement = Vector2(0.0f, 0.0f);

		// Load default texture
		LoadTexture(L"Resources/default.dds");

		// Create font renderer
		font_renderer = new FontRenderer(L"Resources/font");
	}
Esempio n. 26
0
/* Called when a drawing pass has ended
 */
void D3DRenderer::OnDrawEnd()
{
	mDeviceLost = false;

	mD3DDevice->SetSamplerState(0, D3DSAMP_MIPMAPLODBIAS, 0);
	mD3DDevice->EndScene();

	HRESULT result = 0;

	result = mD3DDevice->TestCooperativeLevel();
	if(result == D3DERR_DEVICELOST)
		return;

	if(result == D3DERR_DEVICENOTRESET)
	{
		mDeviceLost = true;

		// Release the existing swap chains
		SwapChainMap::iterator swapChainIt = mSwapChains.begin();
		for(; swapChainIt != mSwapChains.end(); swapChainIt++)
		{
			IDirect3DSwapChain9* pSwapChain = swapChainIt->second.mD3DSwapChain;
			if(pSwapChain)
			{
				pSwapChain->Release();
			}
		}

		// Release the shaders
		ShaderMap::iterator shaderIt = mShaders.begin();
		for(; shaderIt != mShaders.end(); shaderIt++)
		{
			(*shaderIt).second.mEffect->Release();
		}

		// Release the vbuffer
		mVertexBuffer->Release();
		mVertexBuffer = NULL;

		// Release the vertex decl
		mVertexDeclaration->Release();
		mVertexDeclaration = NULL;

		// Reset the device
		D3DPRESENT_PARAMETERS d3dpp;
		GetPresentParams(d3dpp);   
		HRESULT hr = mD3DDevice->Reset(&d3dpp);
		if(FAILED(hr))
		{
			printf("FAILED\n");
		}

		// Recreate the swap chains
		swapChainIt = mSwapChains.begin();
		for(; swapChainIt != mSwapChains.end(); swapChainIt++)
		{
			SwapChain swapChain = swapChainIt->second;
			CreateContext(swapChain.mWindow, swapChain.mWidth, swapChain.mHeight, swapChainIt->first);
		}

		// Create the Vertex Buffer
		CreateBuffers();

		// Recreate the shaders
		ShaderMap tmp = mShaders;
		mShaders.clear();

		CreateShaders();

		shaderIt = tmp.begin();
		for(; shaderIt != tmp.end(); shaderIt++)
		{
			Shader& shader = shaderIt->second;
			if(shader.mSource != "")
				LoadShader(shader.mName.c_str(), shader.mSource.c_str());
		}

		// By setting mContext to zero, we force the back-buffer changes in the next frame
		long oldContext = mContext;
		mContext = 0;
		SetContext(oldContext);
	}

	SwapChainMap::iterator it = mSwapChains.find(mContext);
	if(it != mSwapChains.end())
	{
		IDirect3DSwapChain9* pSwapChain = it->second.mD3DSwapChain;
		if(pSwapChain)
			result = pSwapChain->Present(NULL, NULL, NULL, NULL, 0);
	}
}