Ejemplo n.º 1
0
void D3D9Mesh::CreateText(const char *string, char *FontName, int FontHeight,
                float deviation, float depth, bool bold, bool italic)
{
    //just call the DirectX function to create the text
    FreeMemory();
    LPD3DXMESH TextMesh;
    
    HDC hdc = CreateCompatibleDC( NULL );
    HFONT hFont;
    HFONT hFontOld;
    
    INT nHeight = -MulDiv( FontHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72 );
    hFont = CreateFont(nHeight, 0, 0, 0, bold ? FW_BOLD : FW_NORMAL, italic, FALSE, FALSE, DEFAULT_CHARSET, 
        OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, FontName);
    hFontOld = (HFONT)SelectObject(hdc, hFont); 

    if(FAILED(D3DXCreateText(GetD3DDevice(), hdc, string, deviation, depth, &TextMesh, NULL, NULL))) _asm int 3;

    SelectObject(hdc, hFontOld);
    DeleteObject( hFont );
    DeleteDC( hdc );

    TextMesh->CloneMeshFVF(D3DMeshOptions, D3DMeshFVF, GetD3DDevice(), &_Mesh);
    TextMesh->Release();
    SetColor(RGBColor::White);
    GenerateNormals();
}
Ejemplo n.º 2
0
void D3D9Mesh::CreateTeapot(float radius)
{
    //just call the DirectX function to create the teapot
    FreeMemory();
    LPD3DXMESH teapot;
    D3DXCreateTeapot(GetD3DDevice(), &teapot, NULL);
    teapot->CloneMeshFVF(D3DMeshOptions, D3DMeshFVF, GetD3DDevice(), &_Mesh);
    teapot->Release();
    Stretch(radius);
    SetColor(RGBColor::White);
    GenerateNormals();
}
Ejemplo n.º 3
0
	ID3D11SamplerState* RenderState::GetComparisonLinear()const{
		if (!pImpl->m_ComparisonLinearPtr){
			auto Dev = App::GetApp()->GetDeviceResources();
			ID3D11Device* pDx11Device = Dev->GetD3DDevice();
			D3D11_SAMPLER_DESC comparisonSamplerDesc;
			ZeroMemory(&comparisonSamplerDesc, sizeof(D3D11_SAMPLER_DESC));
			comparisonSamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_BORDER;
			comparisonSamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_BORDER;
			comparisonSamplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
			comparisonSamplerDesc.BorderColor[0] = 1.0f;
			comparisonSamplerDesc.BorderColor[1] = 1.0f;
			comparisonSamplerDesc.BorderColor[2] = 1.0f;
			comparisonSamplerDesc.BorderColor[3] = 1.0f;
			comparisonSamplerDesc.MinLOD = 0.f;
			comparisonSamplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
			comparisonSamplerDesc.MipLODBias = 0.f;
			comparisonSamplerDesc.MaxAnisotropy = 0;
			comparisonSamplerDesc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
			comparisonSamplerDesc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
			ThrowIfFailed(
				pDx11Device->CreateSamplerState(&comparisonSamplerDesc, &pImpl->m_ComparisonLinearPtr),
				L"比較用サンプラーの作成に失敗しました",
				L"pDx11Device->CreateSamplerState(&comparisonSamplerDesc, &pImpl->m_ComparisonSampler_linear)",
				L"RenderState::GetComparisonLinear()"
				);
		}
		return pImpl->m_ComparisonLinearPtr.Get();
	}
Ejemplo n.º 4
0
//-------------------------------------------------------------
// Trigger the render of indexed primitives
//-------------------------------------------------------------
void VCND3D9Shader::RenderIndexedPrimitive( VCNUInt faceCount, VCNUInt vertexCount, VCNInt primitiveType /*= D3DPT_TRIANGLELIST*/  )
{
	HRESULT hr = S_FALSE;

	// Get a pointer to the D3D device
	LPDIRECT3DDEVICE9 device = GetD3DDevice();

	// Start the technique and commit all the data
	VCNUInt numPasses;
	hr = mShader->Begin( &numPasses, 0 );
	VCN_ASSERT( SUCCEEDED(hr) );

	// Render all the passes of this technique (generally only 1).
	for( VCNUInt i=0; i<numPasses; ++i )
	{
		// Start the pass
		hr = mShader->BeginPass( i );
		VCN_ASSERT( SUCCEEDED(hr) );

		// Render indexed primitives
		hr = device->DrawIndexedPrimitive( (D3DPRIMITIVETYPE)primitiveType, 0, 0, vertexCount, 0, faceCount );
		VCN_ASSERT( hr != D3DERR_INVALIDCALL && "VCNDXShader::RenderIndexedPrimitive - D3DERR_INVALIDCALL!" );
		VCN_ASSERT( SUCCEEDED(hr) && "VCNDXShader::RenderIndexedPrimitive - DRAW FAILED!" );

		// End the pass
		hr = mShader->EndPass();
		VCN_ASSERT( SUCCEEDED(hr) );
	}

	hr = mShader->End();
	VCN_ASSERT( SUCCEEDED(hr) );
}
Ejemplo n.º 5
0
	//--------------------------------------------------------------------------------------
	//	void RenderState::Impl::CreateRasterizerState(
	//	D3D11_CULL_MODE cullMode,			//カリング
	//	D3D11_FILL_MODE fillMode,			//塗り
	//	ID3D11RasterizerState** pResult,		//受け取るインターフェイス
	//	bool Scissor = false				//画面分割するかどうか
	//	);
	//	用途: ラスタライザステートを作成するヘルパー関数
	//	戻り値: なし
	//--------------------------------------------------------------------------------------
	void RenderState::Impl::CreateRasterizerState(D3D11_CULL_MODE cullMode, D3D11_FILL_MODE fillMode,
		ID3D11RasterizerState** pResult, bool Scissor){
		try{
			auto Dev = App::GetApp()->GetDeviceResources();
			auto pDx11Device = Dev->GetD3DDevice();

			D3D11_RASTERIZER_DESC desc;
			ZeroMemory(&desc, sizeof(desc));

			desc.CullMode = cullMode;
			desc.FillMode = fillMode;
			desc.DepthClipEnable = true;
			desc.MultisampleEnable = true;
			desc.ScissorEnable = Scissor;

			HRESULT hr = pDx11Device->CreateRasterizerState(&desc, pResult);
			if (FAILED(hr)){
				// 初期化失敗
				throw BaseException(
					L"ラスタライザステート作成に失敗しました。",
					L"if(FAILED(pDx11Device->CreateRasterizerState()))",
					L"RenderState::Impl::CreateRasterizerState()"
					);
			}
		}
		catch (...){
			throw;
		}
	}
Ejemplo n.º 6
0
	ID3D11BlendState* RenderState::GetAlphaBlendEx()const{
		if (!pImpl->m_AlphaBlendExPtr){
			auto Dev = App::GetApp()->GetDeviceResources();
			auto pDx11Device = Dev->GetD3DDevice();
			D3D11_BLEND_DESC desc;
			ZeroMemory(&desc, sizeof(desc));

			desc.RenderTarget[0].BlendEnable = true;
			desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
			desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
			//		desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
			desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
			desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
			desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
			desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
			desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;

			HRESULT hr = pDx11Device->CreateBlendState(&desc, &pImpl->m_AlphaBlendExPtr);
			if (FAILED(hr)){
				// 初期化失敗
				throw BaseException(
					L"ブレンドステート作成に失敗しました。",
					L"if(FAILED(pDx11Device->CreateBlendState()))",
					L"BasicState::GetAlphaBlendEx()"
					);
			}
		}
		return pImpl->m_AlphaBlendExPtr.Get();
	}
Ejemplo n.º 7
0
HRESULT WrappedIDXGIFactory2::staticCreateSwapChainForHwnd(
    IDXGIFactory2 *factory, IUnknown *pDevice, HWND hWnd, const DXGI_SWAP_CHAIN_DESC1 *pDesc,
    const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *pFullscreenDesc, IDXGIOutput *pRestrictToOutput,
    IDXGISwapChain1 **ppSwapChain)
{
  ID3DDevice *wrapDevice = GetD3DDevice(pDevice);

  if(wrapDevice)
  {
    if(!RenderDoc::Inst().GetCaptureOptions().AllowFullscreen && pFullscreenDesc)
    {
      pFullscreenDesc = NULL;
    }

    HRESULT ret = factory->CreateSwapChainForHwnd(wrapDevice->GetRealIUnknown(), hWnd, pDesc,
                                                  pFullscreenDesc, pRestrictToOutput, ppSwapChain);

    if(SUCCEEDED(ret))
    {
      *ppSwapChain = new WrappedIDXGISwapChain3(*ppSwapChain, hWnd, wrapDevice);
    }

    return ret;
  }
  else
  {
    RDCERR("Creating swap chain with non-hooked device!");
  }

  return factory->CreateSwapChainForHwnd(pDevice, hWnd, pDesc, pFullscreenDesc, pRestrictToOutput,
                                         ppSwapChain);
}
Ejemplo n.º 8
0
	//--------------------------------------------------------------------------------------
	//	void RenderState::Impl::CreateBlendState(
	//	D3D11_BLEND srcBlend,		//ソースブレンド
	//	D3D11_BLEND destBlend,		//デストブレンド
	//	ID3D11BlendState** pResult	//受け取るインターフェイス
	//	);
	//	用途: ブレンドステートを作成するヘルパー関数
	//	戻り値: なし
	//--------------------------------------------------------------------------------------
	void RenderState::Impl::CreateBlendState(D3D11_BLEND srcBlend, D3D11_BLEND destBlend,
		ID3D11BlendState** pResult){
		try{
			auto Dev = App::GetApp()->GetDeviceResources();
			auto pDx11Device = Dev->GetD3DDevice();

			D3D11_BLEND_DESC desc;
			ZeroMemory(&desc, sizeof(desc));

			desc.RenderTarget[0].BlendEnable = (srcBlend != D3D11_BLEND_ONE) ||
				(destBlend != D3D11_BLEND_ZERO);

			desc.RenderTarget[0].SrcBlend = desc.RenderTarget[0].SrcBlendAlpha = srcBlend;
			desc.RenderTarget[0].DestBlend = desc.RenderTarget[0].DestBlendAlpha = destBlend;
			desc.RenderTarget[0].BlendOp = desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;

			desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;

			HRESULT hr = pDx11Device->CreateBlendState(&desc, pResult);
			if (FAILED(hr)){
				// 初期化失敗
				throw BaseException(
					L"ブレンドステート作成に失敗しました。",
					L"if(FAILED(pDx11Device->CreateBlendState()))",
					L"RenderState::Impl::CreateBlendState()"
					);
			}
		}
		catch (...){
			throw;
		}
	}
Ejemplo n.º 9
0
		bool LoadDDSTextureStatic(const char* texturePath, TextureInfo& o_textureInfo)
		{
			//Get devices context of D3D
			IDirect3DDevice9* pD3DDevice = GetD3DDevice();
			if (!pD3DDevice) return false;

			IDirect3DTexture9* pResultTexture = NULL;

			const unsigned int useDimensionsFromFile = D3DX_DEFAULT_NONPOW2;
			const unsigned int useMipMapsFromFile = D3DX_FROM_FILE;
			const DWORD staticTexture = 0;
			const D3DFORMAT useFormatFromFile = D3DFMT_FROM_FILE;
			const D3DPOOL letD3dManageMemory = D3DPOOL_MANAGED;
			const DWORD useDefaultFiltering = D3DX_DEFAULT;
			const D3DCOLOR noColorKey = 0;
			D3DXIMAGE_INFO imageInfo;
			PALETTEENTRY* noColorPalette = NULL;
			const HRESULT result = D3DXCreateTextureFromFileEx(pD3DDevice, texturePath, useDimensionsFromFile, useDimensionsFromFile, useMipMapsFromFile,
				staticTexture, useFormatFromFile, letD3dManageMemory, useDefaultFiltering, useDefaultFiltering, noColorKey, &imageInfo, noColorPalette, &pResultTexture);
			o_textureInfo._width = (float)imageInfo.Width;
			o_textureInfo._height = (float)imageInfo.Height;
			o_textureInfo._texture = (tTexture)pResultTexture;
			return true;

		}
void	HUDManager::Render()
{
    HRESULT hr;
    IDirect3DDevice9 *Device;

    Device = GetD3DDevice();

    if (!Device)
    {
        _MESSAGE("No valid D3D Device.");
        return;
    }

    if(!sprite)
    {
        hr=D3DXCreateSprite(Device,&sprite);
        if (FAILED(hr)||!sprite)
        {
            _MESSAGE("Create sprite failed.");
            return;
        }
    }

    sprite->Begin(0);

    for(::std::vector<Sprite*>::iterator i=ScreenElementList.begin(); i!=ScreenElementList.end(); i++)
    {
        (*i)->Render(sprite);
    }

    sprite->End();
    return;
}
Ejemplo n.º 11
0
	//レンダリングターゲットを開始する
	void DefaultRenderTarget::StartRenderTarget(){
		auto Dev = App::GetApp()->GetDeviceResources();
		auto pD3D11Device = Dev->GetD3DDevice();
		auto pD3D11DeviceContext = Dev->GetD3DDeviceContext();

		ID3D11RenderTargetView* pV = pImpl->m_D3D11RenderTargetView.Get();
		//レンダリングターゲットとステンシルを設定
		pD3D11DeviceContext->OMSetRenderTargets(1, &pV, pImpl->m_DepthStencilView.Get());
		//ビューポートの設定
		if (pImpl->m_Stage.expired()){
			throw BaseException(
				L"ステージが無効です",
				L"if (pImpl->m_Stage.expired())",
				L"DefaultRenderTarget::StartRenderTarget()"
				);
		}
		auto StagePtr = pImpl->m_Stage.lock();

		pD3D11DeviceContext->RSSetViewports(1, StagePtr->GetTargetViewPortRealPtr());

		//シェーダーリソースビューのクリア
		ID3D11ShaderResourceView* pNull[1] = { nullptr };
		pD3D11DeviceContext->PSSetShaderResources(0, _countof(pNull), pNull);
		pD3D11DeviceContext->PSSetShaderResources(1, _countof(pNull), pNull);
		//シェーダーは指定しない
		pD3D11DeviceContext->VSSetShader(nullptr, nullptr, 0);
		pD3D11DeviceContext->PSSetShader(nullptr, nullptr, 0);
		pD3D11DeviceContext->GSSetShader(nullptr, nullptr, 0);
		//ブレンドは指定しない
		pD3D11DeviceContext->OMSetBlendState(nullptr, nullptr, 0xffffffff);

	}
Ejemplo n.º 12
0
	//レンダリングターゲットをクリアする
	void ShadowMapRenderTarget::ClearViews(){
		auto Dev = App::GetApp()->GetDeviceResources();
		auto pD3D11Device = Dev->GetD3DDevice();
		auto pD3D11DeviceContext = Dev->GetD3DDeviceContext();
		//シャドウマップクリア
		pD3D11DeviceContext->ClearDepthStencilView(pImpl->m_DepthStencilView.Get(), D3D11_CLEAR_DEPTH, 1.0, 0);
	}
Ejemplo n.º 13
0
HRESULT WrappedIDXGIFactory2::staticCreateSwapChainForComposition(IDXGIFactory2 *factory,
                                                                  IUnknown *pDevice,
                                                                  const DXGI_SWAP_CHAIN_DESC1 *pDesc,
                                                                  IDXGIOutput *pRestrictToOutput,
                                                                  IDXGISwapChain1 **ppSwapChain)
{
  ID3DDevice *wrapDevice = GetD3DDevice(pDevice);

  if(!RenderDoc::Inst().GetCaptureOptions().AllowFullscreen)
  {
    RDCWARN("Impossible to disallow fullscreen on call to CreateSwapChainForComposition");
  }

  if(wrapDevice)
  {
    HRESULT ret = factory->CreateSwapChainForComposition(wrapDevice->GetRealIUnknown(), pDesc,
                                                         pRestrictToOutput, ppSwapChain);

    if(SUCCEEDED(ret))
    {
      HWND wnd = NULL;
      (*ppSwapChain)->GetHwnd(&wnd);
      *ppSwapChain = new WrappedIDXGISwapChain3(*ppSwapChain, wnd, wrapDevice);
    }

    return ret;
  }
  else
  {
    RDCERR("Creating swap chain with non-hooked device!");
  }

  return factory->CreateSwapChainForComposition(pDevice, pDesc, pRestrictToOutput, ppSwapChain);
}
Ejemplo n.º 14
0
HRESULT WrappedIDXGIFactory::staticCreateSwapChain(IDXGIFactory *factory, IUnknown *pDevice,
                                                   DXGI_SWAP_CHAIN_DESC *pDesc,
                                                   IDXGISwapChain **ppSwapChain)
{
  ID3DDevice *wrapDevice = GetD3DDevice(pDevice);

  if(wrapDevice)
  {
    if(!RenderDoc::Inst().GetCaptureOptions().AllowFullscreen && pDesc)
    {
      pDesc->Windowed = TRUE;
    }

    HRESULT ret = factory->CreateSwapChain(wrapDevice->GetRealIUnknown(), pDesc, ppSwapChain);

    if(SUCCEEDED(ret))
    {
      *ppSwapChain =
          new WrappedIDXGISwapChain3(*ppSwapChain, pDesc ? pDesc->OutputWindow : NULL, wrapDevice);
    }

    return ret;
  }

  RDCERR("Creating swap chain with non-hooked device!");

  return factory->CreateSwapChain(pDevice, pDesc, ppSwapChain);
}
Ejemplo n.º 15
0
	//シェーダリソースビューの作成
	ComPtr<ID3D11ShaderResourceView> GameObject::CreateShaderResView(const wstring& TextureFileName){
		//テクスチャ作成
		DirectX::TexMetadata metadata;
		DirectX::ScratchImage image;
		ThrowIfFailed(
			DirectX::LoadFromWICFile(TextureFileName.c_str(), 0, &metadata, image),
			L"テクスチャの読み込みに失敗しました",
			TextureFileName,
			L"GameObject::CreateShaderResView()"
			);
		//デバイスとコンテキストインターフェイスの取得
		//デバイスの取得
		auto Dev = App::GetApp()->GetDeviceResources();
		ID3D11Device* pDx11Device = Dev->GetD3DDevice();
		ID3D11DeviceContext* pID3D11DeviceContex = Dev->GetD3DDeviceContext();
		//ミューテックス
		std::mutex Mutex;
		ComPtr<ID3D11ShaderResourceView> ResView;
		Util::DemandCreate(ResView, Mutex, [&](ID3D11ShaderResourceView** pResult) -> HRESULT
		{
			// 画像からシェーダリソースViewの作成
			return ThrowIfFailed(CreateShaderResourceView(pDx11Device, image.GetImages(), image.GetImageCount(), metadata, pResult),
				L"シェーダーリソースビューを作成できません",
				L"if( FAILED( CreateShaderResourceView() ) )",
				L"Texture::Impl::Impl()"
				);
		});
		return ResView;
	}
Ejemplo n.º 16
0
void D3D9Mesh::LoadFromXFile(const String &Filename)
{
    String FilenameCopy = Filename;
    FreeMemory();
    LPD3DXBUFFER Adjacency, Materials, EffectInstances;
    DWORD MaterialCount;
    LPD3DXMESH LoadedMesh;

    //call the DirectX function to load from an XFile,
    D3DXLoadMeshFromX(FilenameCopy.CString(), D3DMeshOptions, GetD3DDevice(), &Adjacency, &Materials, &EffectInstances, &MaterialCount, &LoadedMesh);

    //get rid of the components we don't care about
    Adjacency->Release(); Materials->Release(); EffectInstances->Release();

    //and copy the part we do care about (the _Mesh) into our _Mesh in the right format.
    LoadedMesh->CloneMeshFVF(D3DMeshOptions, D3DMeshFVF, GetD3DDevice(), &_Mesh);
    LoadedMesh->Release();
}
Ejemplo n.º 17
0
//-------------------------------------------------------------
// Make the shader active
//-------------------------------------------------------------
void VCND3D9Shader::Bind()
{
	// Select the technique
	HRESULT hr = mShader->SetTechnique( mTechnique );
	VCN_ASSERT( SUCCEEDED(hr) );

	// Set the vertex declaration for this kind of shader
	hr = GetD3DDevice()->SetVertexDeclaration( mVertexDeclaration->GetDeclaration() );
	VCN_ASSERT( SUCCEEDED(hr) );
}
Ejemplo n.º 18
0
IDirect3DVertexDeclaration9* RenderCore::CreateVertexDeclaration(D3DVERTEXELEMENT9* pVertexElements)
{
	IDirect3DVertexDeclaration9* ret = 0;
	if(FAILED(GetD3DDevice()->CreateVertexDeclaration(pVertexElements, &ret)))
	{
		// Push error-code into the error-pipeline
		return 0;
	}

	return ret;
}
Ejemplo n.º 19
0
void RenderCore::Clear(D3DCOLOR Color, float Z, DWORD Stencil, DWORD Count, const D3DRECT *pRects)
{

	DWORD Flags = D3DCLEAR_TARGET;
	if(m_RCDesc.m_PresentParameters.EnableAutoDepthStencil)
	{
		Flags |= D3DCLEAR_ZBUFFER;
	}

	GetD3DDevice()->Clear(Count, pRects, Flags, Color, Z, Stencil);
}
Ejemplo n.º 20
0
IDirect3DIndexBuffer9* RenderCore::CreateIndexBuffer(unsigned int NumOfIndices, D3DFORMAT Format, D3DPOOL Pool, DWORD Usage)
{
	IDirect3DIndexBuffer9* ret = 0;
	if(FAILED(GetD3DDevice()->CreateIndexBuffer(NumOfIndices * GetSizeOfIndex(Format), Usage, Format, Pool, &ret, 0)))
	{
		// Push error-code into the error-pipeline
		return 0;
	}

	return ret;
}
Ejemplo n.º 21
0
IDirect3DVertexBuffer9* RenderCore::CreateVertexBuffer(unsigned int NumOfVertices, unsigned int SizeOfVertex, DWORD dwFVF, D3DPOOL Pool, DWORD Usage)
{
	IDirect3DVertexBuffer9* ret = 0;
	if(FAILED(GetD3DDevice()->CreateVertexBuffer(NumOfVertices * SizeOfVertex, Usage, dwFVF, Pool, &ret, 0)))
	{
		// Push error-code into the error-pipeline
		return 0;
	}

	return ret;
}
Ejemplo n.º 22
0
		void TextureDesc::SetTexture() 
		{
			//Get devices context of D3D
			IDirect3DDevice9* pD3DDevice = GetD3DDevice();
			if (!pD3DDevice) return;
			if (_samplerID == UINT_MAX)
				return;
			//Set the Texture
			IDirect3DBaseTexture9* pTexture = _pTextureInfo? (IDirect3DBaseTexture9*)_pTextureInfo->_texture : NULL;
			HRESULT result = pD3DDevice->SetTexture(_samplerID, pTexture);
			assert(SUCCEEDED(result));
		}
Ejemplo n.º 23
0
void D3D9Mesh::Allocate(UINT VertexCount, UINT FaceCount)
{
    FreeMemory();
    if(VertexCount == 0 || FaceCount == 0)
    {
        return;
    }

    D3DXCreateMeshFVF(FaceCount, VertexCount, D3DMeshOptions, D3DMeshFVF, GetD3DDevice(), &_Mesh);    //tell DirectX to allocate space for the _Mesh
    Lock();        //toggle the buffer locking just to clear things up
    Unlock();    //we want the buffers unlocked whenever possible
}
Ejemplo n.º 24
0
void RenderManager::Init(int32 _frameBufferWidth, int32 _frameBufferHeight)
{
    DetectRenderingCapabilities();

    if (!FLAT_COLOR)
        FLAT_COLOR = ColorOnlyEffect::Create(renderer);
    if (!TEXTURE_MUL_FLAT_COLOR) 
        TEXTURE_MUL_FLAT_COLOR= TextureMulColorEffect::Create(renderer);
    if (!TEXTURE_MUL_FLAT_COLOR_ALPHA_TEST)
        TEXTURE_MUL_FLAT_COLOR_ALPHA_TEST = TextureMulColorAlphaTestEffect::Create(renderer);

#if defined(__DAVAENGINE_DIRECTX9__)
	currentState.direct3DDevice = GetD3DDevice();
#endif
    
    RenderManager::LockNonMain();
	currentState.Reset(false);
    hardwareState.Reset(true);

#if defined(__DAVAENGINE_OPENGL__)
#if !defined(__DAVAENGINE_IPHONE__) && !defined(__DAVAENGINE_ANDROID__)//Dizz: glDisableClientState functions are not supported by GL ES 2.0
    glDisableClientState(GL_VERTEX_ARRAY);
    oldVertexArrayEnabled = 0;                      

    glDisableClientState(GL_NORMAL_ARRAY);
    oldNormalArrayEnabled = 0;                      
	for (int k = 0; k < RenderState::MAX_TEXTURE_LEVELS; ++k)
    {
        glClientActiveTexture(GL_TEXTURE0 + k);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
        oldTextureCoordArrayEnabled[k] = 0;                
    }
    glClientActiveTexture(GL_TEXTURE0);
    
    glDisableClientState(GL_COLOR_ARRAY);
    oldColorArrayEnabled = 0;                       

    RenderManager::UnlockNonMain();
#endif    
#endif
    
	frameBufferWidth = _frameBufferWidth;
	frameBufferHeight = _frameBufferHeight;
#if defined (__DAVAENGINE_OPENGL__)
//	Logger::Debug("[RenderManager::Init] orientation: %d x %d", frameBufferWidth, frameBufferHeight);
#else
//	Logger::Debug("[RenderManager::Init] orientation: %d x %d ", frameBufferWidth, frameBufferHeight);
#endif
    // TODO: Rethink of initialization concepts because they changed
    pointerArraysRendererState = pointerArraysCurrentState = 0;
}
Ejemplo n.º 25
0
void VCND3D9Shader::RenderIndexedPrimitive(
	VCNPrimitiveType primitiveType, VCNInt baseVertexIndex, 
	VCNUInt minVertexIndex, VCNUInt numVertices, VCNUInt startIndex, VCNUInt primCount)
{
	HRESULT hr = S_FALSE;

	// Get a pointer to the D3D device
	LPDIRECT3DDEVICE9 device = GetD3DDevice();

	// Render primitives
	hr = device->DrawIndexedPrimitive( 
		(D3DPRIMITIVETYPE)primitiveType, baseVertexIndex, minVertexIndex, numVertices, startIndex, primCount);
	VCN_ASSERT( hr != D3DERR_INVALIDCALL && "VCNDXShader::RenderIndexedPrimitive - D3DERR_INVALIDCALL!" );
	VCN_ASSERT( SUCCEEDED(hr) && "VCNDXShader::RenderIndexedPrimitive - DRAW FAILED!" );
}
Ejemplo n.º 26
0
	//レンダリングターゲットを終了する
	void DefaultRenderTarget::EndRenderTarget(){
		auto Dev = App::GetApp()->GetDeviceResources();
		auto pD3D11Device = Dev->GetD3DDevice();
		auto pD3D11DeviceContext = Dev->GetD3DDeviceContext();
		//ステータスのポインタ
		//auto RenderStatePtr = App::GetApp()->GetRenderState();
		//シェーダーリソースビューのクリア
		ID3D11ShaderResourceView* pNull[1] = { nullptr };
		pD3D11DeviceContext->PSSetShaderResources(0, _countof(pNull), pNull);
		pD3D11DeviceContext->PSSetShaderResources(1, _countof(pNull), pNull);
		//シェーダーは指定しない
		pD3D11DeviceContext->VSSetShader(nullptr, nullptr, 0);
		pD3D11DeviceContext->PSSetShader(nullptr, nullptr, 0);
		pD3D11DeviceContext->GSSetShader(nullptr, nullptr, 0);
		//ブレンドは指定しない
		pD3D11DeviceContext->OMSetBlendState(nullptr, nullptr, 0xffffffff);
	}
Ejemplo n.º 27
0
void D3D9Mesh::NPatchEnhance(float segs, bool quadratic)
{
    DWORD *adj;
    Unlock();

    //get the _Mesh adjacency (needed by NPatchEnhance)
    GenerateAdj(adj);
    LPD3DXMESH sphere;

    //do the n-patching using the DirectX function
    D3DXTessellateNPatches(_Mesh, adj, segs, quadratic, &sphere, NULL);
    FreeMemory();

    //load the data into 
    sphere->CloneMeshFVF(D3DMeshOptions, D3DMeshFVF, GetD3DDevice(), &_Mesh);
    sphere->Release();
    delete[] adj;
}
Ejemplo n.º 28
0
void D3D9Mesh::SimplifyToVertices(UINT Count)
{
    Lock();
    Unlock();

    DWORD *Adj;
    Clean(1e-6f, Adj);

    LPD3DXMESH NewMesh = NULL;
    D3DAlwaysValidate(D3DXSimplifyMesh(_Mesh, Adj, NULL, NULL, Count, D3DXMESHSIMP_VERTEX, &NewMesh), "D3DXSimplifyMesh");
    _Mesh->Release();
    D3DAlwaysValidate(NewMesh->CloneMeshFVF(D3DMeshOptions, D3DMeshFVF, GetD3DDevice(), &_Mesh), "CloneMeshFVF");
    NewMesh->Release();
    delete[] Adj;

    Lock();
    Unlock();
}
Ejemplo n.º 29
0
/*
-----------------------------------------------------------------------------
	TextureManager
-----------------------------------------------------------------------------
*/
rxTextureManager::rxTextureManager()
{
	gCore.resources->SetManager( Asset_Texture2D, this );

	// Create a 1x1 texture filled with white color.
	{
		const DXGI_FORMAT textureFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
		const UINT textureWidth = 1;
		const UINT textureHeight = 1;

		DX11::Texture2DDescription	texDesc( textureFormat, textureWidth, textureHeight );
		texDesc
			.ArraySize_(1)
			.MipLevels_(1)
			.SampleCount_(1)
			.SampleQuality_(0)
			.Usage_(D3D11_USAGE_IMMUTABLE)
			.BindFlags_(D3D11_BIND_SHADER_RESOURCE)
			.CPUAccessFlags_(0)
			;

		R8G8B8A8	whiteColorRGBA;
		whiteColorRGBA.asU32 = BITS_ALL;

		D3D11_SUBRESOURCE_DATA	initialData;
		initialData.pSysMem = &whiteColorRGBA;
		initialData.SysMemPitch = sizeof whiteColorRGBA;
		initialData.SysMemSlicePitch = nil;

		ID3D11Device* pD3DDevice = GetD3DDevice();

		dxchk(pD3DDevice->CreateTexture2D(
			&texDesc, &initialData, c_cast(ID3D11Texture2D**) &m_defaultTexture.pTexture.Ptr
		));


		D3D11_SHADER_RESOURCE_VIEW_DESC		srvDesc;
		D3D_GetTexture2D_ShaderResourceView_Desc( textureFormat, srvDesc );

		dxchk(pD3DDevice->CreateShaderResourceView(
			m_defaultTexture.pTexture, &srvDesc, &m_defaultTexture.pSRV.Ptr
		));
	}
}
Ejemplo n.º 30
0
void D3D9Mesh::Clean(float Epsilon, DWORD* &AdjDataOut)
{
    Assert(_Mesh != NULL, "Clean called on empty _Mesh.");

    LPD3DXMESH NewMesh;
    DWORD *AdjData = new DWORD[3 * _Mesh->GetNumFaces()];
    AdjDataOut = new DWORD[3 * _Mesh->GetNumFaces()];
    DWORD *FaceRemap = new DWORD[3 * _Mesh->GetNumFaces()];

    /*D3DXWELDEPSILONS Eps;
    Eps.Position = Epsilon;
    Eps.BlendWeights = 1.0f;
    Eps.Normal = 1.0f;
    Eps.PSize = 1.0f;
    Eps.Specular = 1.0f;
    Eps.Diffuse = 1.0f;
    Eps.Tangent = 1.0f;
    Eps.Binormal = 1.0f;
    Eps.TessFactor = 1.0f;
    for(UINT _Indices = 0; _Indices < 8; _Indices++)
    {
        Eps.Texcoord[_Indices] = 1.0f;
    }*/

    CleanVerticesAndTriangles();
    Unlock();
    //D3DAlwaysValidate(_Mesh->GenerateAdjacency(Epsilon, AdjDataOut));
    //D3DAlwaysValidate(D3DXWeldVertices(_Mesh, D3DXWELDEPSILONS_WELDPARTIALMATCHES, &Eps, AdjDataOut, AdjData, FaceRemap, NULL));
    //D3DAlwaysValidate(D3DXWeldVertices(_Mesh, D3DXWELDEPSILONS_WELDALL | D3DXWELDEPSILONS_WELDPARTIALMATCHES, NULL, AdjDataOut, AdjData, FaceRemap, NULL));
    //CleanTriangles();
    D3DAlwaysValidate(_Mesh->GenerateAdjacency(Epsilon, AdjData), "GenerateAdjacency");
    D3DAlwaysValidate(D3DXCleanMesh(D3DXCLEAN_SIMPLIFICATION, _Mesh, AdjData, &NewMesh, AdjDataOut, NULL), "D3DXCleanMesh");
    _Mesh->Release();
    D3DAlwaysValidate(NewMesh->CloneMeshFVF(D3DMeshOptions, D3DMeshFVF, GetD3DDevice(), &_Mesh), "CloneMeshFVF");
    NewMesh->Release();

    Lock();
    Unlock();

    delete[] AdjData;
    delete[] FaceRemap;
}