コード例 #1
0
void Particle::render()
{
	// Set the input layout
	getDevice()->IASetInputLayout(getEffect()->getInputLayoutHandler().getInputLayout(getEffectLayoutIndex())->getDXInputLayout());
	getDevice()->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);

	UINT stride = getEffect()->getInputLayoutHandler().getInputLayout(getEffectLayoutIndex())->getLayoutSize();
    UINT offset = 0;

	// Init vertex buffers
	if(mFlagInit)
		getDevice()->IASetVertexBuffers(0, 1, &mpInitVB, &stride, &offset);
	else
		getDevice()->IASetVertexBuffers(0, 1, &mpDrawVB, &stride, &offset);

	getDevice()->SOSetTargets(1, &mpStreamOutVB, &offset);

	ID3D10EffectTechnique *pEffectTechnique = getEffect()->getEffect()->GetTechniqueByIndex(getEffectTechIndex());

	// Render pass for streaming out particles
	pEffectTechnique->GetPassByIndex(getEffectPassIndex())->Apply(0);

	/** 
	 * Initialize system by streaming 1 emitter,
	 * else stream all particles that are alive
	 */
	if(mFlagInit)
	{
		getDevice()->Draw(mEmitParticles, 0);
		mFlagInit = false;
	}
	else
	{
		getDevice()->DrawAuto();
	}

	// Unbind the vertex buffer when done streaming out
	ID3D10Buffer *bufferArray[1] = {0};
	getDevice()->SOSetTargets(1, bufferArray, &offset);

	/** 
	 * Swap buffers so that they switch their tasks (streaming - drawing)
	 * and repeat this with each render-call
	 */
	std::swap(mpDrawVB, mpStreamOutVB);

	// Draw particles using getEffectPassIndex() + 1 to have the right pass for drawing
	getDevice()->IASetVertexBuffers(0, 1, &mpDrawVB, &stride, &offset);
	pEffectTechnique->GetPassByIndex(getEffectPassIndex() + 1)->Apply(0);
	getDevice()->DrawAuto();
}
コード例 #2
0
ファイル: render_dx10.cpp プロジェクト: as2120/ZNginx
bool InitResourceDX10(void)
{
	g_pDevice = GutGetGraphicsDeviceDX10();

	// 載入Shader
	{
		g_pRefractionFX = GutLoadFXShaderDX10("../../shaders/Refraction_dx10.fx");
		if ( NULL==g_pRefractionFX )
			return false;

		ID3D10EffectTechnique *pShader = g_pRefractionFX->GetTechniqueByName("Refraction");
		const sVertexDecl *pVertexDecl = g_Model.GetVertexFormat();

		D3D10_PASS_DESC PassDesc;
		pShader->GetPassByIndex(0)->GetDesc(&PassDesc);

		g_pRefractionLayout = GutCreateInputLayoutDX10(pVertexDecl, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize);
	}

	g_pPostFX = GutLoadFXShaderDX10("../../shaders/Posteffect_dx10.fx");
	if ( NULL==g_pPostFX )
		return false;

	{
		g_pVertexBuffer = GutCreateVertexBuffer_DX10(sizeof(Vertex_VT)*4, g_FullScreenQuad);

		D3D10_INPUT_ELEMENT_DESC layout[] =
		{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
			{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
		};

		ID3D10EffectTechnique *pShader = g_pPostFX->GetTechniqueByName("DrawIcon");

		D3D10_PASS_DESC PassDesc;
		pShader->GetPassByIndex(0)->GetDesc(&PassDesc);

		if ( D3D_OK != g_pDevice->CreateInputLayout( layout, 2, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &g_pVertexLayout ) )
			return false;
	}

	if ( !ReInitResourceDX10() )
		return false;

	CGutModel_DX10::LoadDefaultShader("../../shaders/gmodel_dx10.hlsl");
	g_Model_DX10.ConvertToDX10Model(&g_Model);

	g_pTexture = GutLoadTexture_DX10("../../textures/lena.dds");

	return true;
}
コード例 #3
0
void
ThebesLayerD3D10::RenderLayer()
{
  if (!mTexture) {
    return;
  }

  SetEffectTransformAndOpacity();

  ID3D10EffectTechnique *technique;
  switch (mCurrentSurfaceMode) {
  case SURFACE_COMPONENT_ALPHA:
    technique = SelectShader(SHADER_COMPONENT_ALPHA | LoadMaskTexture());
    break;
  case SURFACE_OPAQUE:
    technique = SelectShader(SHADER_RGB | SHADER_PREMUL | LoadMaskTexture());
    break;
  case SURFACE_SINGLE_CHANNEL_ALPHA:
    technique = SelectShader(SHADER_RGBA | SHADER_PREMUL | LoadMaskTexture());
    break;
  default:
    NS_ERROR("Unknown mode");
    return;
  }

  nsIntRegionRectIterator iter(mVisibleRegion);

  const nsIntRect *iterRect;
  if (mSRView) {
    effect()->GetVariableByName("tRGB")->AsShaderResource()->SetResource(mSRView);
  }
  if (mSRViewOnWhite) {
    effect()->GetVariableByName("tRGBWhite")->AsShaderResource()->SetResource(mSRViewOnWhite);
  }

  while ((iterRect = iter.Next())) {
    effect()->GetVariableByName("vLayerQuad")->AsVector()->SetFloatVector(
      ShaderConstantRectD3D10(
        (float)iterRect->x,
        (float)iterRect->y,
        (float)iterRect->width,
        (float)iterRect->height)
      );

    effect()->GetVariableByName("vTextureCoords")->AsVector()->SetFloatVector(
      ShaderConstantRectD3D10(
        (float)(iterRect->x - mTextureRect.x) / (float)mTextureRect.width,
        (float)(iterRect->y - mTextureRect.y) / (float)mTextureRect.height,
        (float)iterRect->width / (float)mTextureRect.width,
        (float)iterRect->height / (float)mTextureRect.height)
      );

    technique->GetPassByIndex(0)->Apply(0);
    device()->Draw(4, 0);
  }

  // Set back to default.
  effect()->GetVariableByName("vTextureCoords")->AsVector()->
    SetFloatVector(ShaderConstantRectD3D10(0, 0, 1.0f, 1.0f));
}
コード例 #4
0
ファイル: render_dx10.cpp プロジェクト: as2120/ZNginx
void DrawImage(ID3D10ShaderResourceView *pTexture, float x=-1, float y=-1, float w=2, float h=2)
{
	Vector4 vtable[4];

	vtable[0].Set(x, y, 0.0f, 1.0f);
	vtable[1].Set(x+w, y, 0.0f, 1.0f);
	vtable[2].Set(x, y+h, 0.0f, 1.0f);
	vtable[3].Set(x+w, y+h, 0.0f, 1.0f);

	Vector4 ttable[4] =
	{
		Vector4(0.0f, 1.0f, 0.0f, 1.0f),
		Vector4(1.0f, 1.0f, 0.0f, 1.0f),
		Vector4(0.0f, 0.0f, 0.0f, 1.0f),
		Vector4(1.0f, 0.0f, 0.0f, 1.0f)
	};

	ID3D10EffectTechnique *pShader = g_pPostFX->GetTechniqueByName("DrawIcon");

	ID3D10EffectShaderResourceVariable *pInputTexture = g_pPostFX->GetVariableByName("Image")->AsShaderResource();
	ID3D10EffectVectorVariable *vertex_table = g_pPostFX->GetVariableByName("vertex_table")->AsVector();
	ID3D10EffectVectorVariable *texcoord_table = g_pPostFX->GetVariableByName("texcoord_table")->AsVector();

	pInputTexture->SetResource(pTexture);
	vertex_table->SetFloatVectorArray( (float*)vtable, 0, 4);
	texcoord_table->SetFloatVectorArray( (float*)ttable, 0, 4);

	pShader->GetPassByIndex(0)->Apply(0);

	DrawFullScreenQuad();
}
コード例 #5
0
void ColoredCubeApp::drawScene()
{
    D3DApp::drawScene();

    // Restore default states, input layout and primitive topology
    // because mFont->DrawText changes them.  Note that we can
    // restore the default states by passing null.
    md3dDevice->OMSetDepthStencilState(0, 0);
    float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
    md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);
    md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINELIST);

    // set constants
    mWVP = mView*mProj;
    mfxWVPVar->SetMatrix((float*)&mWVP);

    D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );
    for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex( p )->Apply(0);

        //mBox.draw();
        mLine1.draw();
        mLine2.draw();
        mLine3.draw();
    }

    // We specify DT_NOCLIP, so we do not care about width/height of the rect.
    RECT R = {5, 5, 0, 0};
    mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);

    mSwapChain->Present(0, 0);
}
コード例 #6
0
void WaterLandscapeDemoScene::BuildInputLayout(DXRenderer& dx)
{
    // Describe the vertex input layout.
    D3D10_INPUT_ELEMENT_DESC vertexDescription[] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "DIFFUSE", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "SPECULAR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 40, D3D10_INPUT_PER_VERTEX_DATA, 0 }
    };

    // Load the default pass from the .fx file we loaded earlier
    D3D10_PASS_DESC passDescription;
    ID3D10EffectTechnique * pTechnique = mLandscapeEffect->GetTechniqueByName("LandscapeTechnique");

    VerifyNotNull(pTechnique);

    pTechnique->GetPassByIndex(0)->GetDesc(&passDescription);

    // Create the vertex input layout.
    HRESULT hr = dx.GetDevice()->CreateInputLayout(
        vertexDescription,
        4,
        passDescription.pIAInputSignature,
        passDescription.IAInputSignatureSize,
        &mVertexLayout);

    // Make sure it worked
    if (FAILED(hr))
    {
        throw new DirectXException(hr, L"Creating input layout", L"Water landscape demo scene", __FILE__, __LINE__);
    }

    LOG_DEBUG("Renderer") << "Created the vertex input layout.";
}
コード例 #7
0
void
SimpleTrackballDX10::render(double elapsedTime)
{  
  Star::float4 color(0.f, 1.f, 0.f, 1.f);  
  m_renderDeviceDX10->clearRenderTargetView(color);  

  D3DXVECTOR3 eye = D3DXVECTOR3(0, 0, -3);
  D3DXVECTOR3 lookAt = D3DXVECTOR3(0, 0, 0);
  D3DXVECTOR3 up = D3DXVECTOR3(0, 1, 0);

  //One turn every 4 seconds
  float da = 2*3.14159265358979323846f/(4/elapsedTime);
  alpha += da;
  
  D3DXMatrixRotationY(&m_world, alpha);
  D3DXMatrixLookAtLH(&m_view, &eye, &lookAt, &up);
  D3DXMatrixPerspectiveFovLH(&m_projection, D3DXToRadian(60.f), m_width/float(m_height), 0.001f, 100.f);

  m_worldVariable->SetMatrix( (float*)&m_world );
  m_viewVariable->SetMatrix( (float*)&m_view );
  m_projectionVariable->SetMatrix( (float*)&m_projection );

  ID3D10EffectTechnique* tech = m_cubeEffect->GetTechniqueByIndex(0);
  tech->GetPassByIndex(0)->Apply(0);
  m_cube->begin();
  m_cube->render();  
  m_cube->end();
}
コード例 #8
0
void
SimpleTrackballDX10::init()
{
  alpha = 0.f;
  HRESULT hr;
  hr = D3DX10CreateEffectFromFile("C:/Users/gandalf/Documents/devel/cpp/starengine/stargraphics/tests/simpleTrackballDX10/cube.fx", 
                                  NULL, NULL, "fx_4_0",
                                  D3D10_SHADER_ENABLE_STRICTNESS, 0, 
                                  g_StarRenderDeviceDX10.getD3dDevice(), 
                                  NULL, NULL, &m_cubeEffect,
                                  NULL, NULL);
 
  if(FAILED(hr))
    throw Star::Exception("SimpleTrackballDX10::init: can't create effect");

  m_cube = new Star::Cube(1.0f);

  ID3D10EffectTechnique* tech = m_cubeEffect->GetTechniqueByIndex(0);

  D3D10_PASS_DESC passDesc;
  hr = tech->GetPassByIndex(0)->GetDesc(&passDesc);
  if(FAILED(hr))
    throw Star::Exception("SimpleTrackballDX10::init: can't get pass description");

  m_cubeLayout = m_cube->createInputLayout(passDesc);
  g_StarRenderDeviceDX10.getD3dDevice()->IASetInputLayout(m_cubeLayout);
     
  m_worldVariable = m_cubeEffect->GetVariableByName("World")->AsMatrix();
  m_viewVariable = m_cubeEffect->GetVariableByName("View")->AsMatrix();
  m_projectionVariable = m_cubeEffect->GetVariableByName("Projection")->AsMatrix();
}
コード例 #9
0
ファイル: Mesh.cpp プロジェクト: pocketninja25/TankAssignment
// Render the model using the given matrix list as a hierarchy (must be one matrix per node)
void CMesh::Render(	CMatrix4x4* matrices )
{
	if (!m_HasGeometry) return;

	for (TUInt32 subMesh = 0; subMesh < m_NumSubMeshes; ++subMesh)
	{
		// Get a reference to the submesh and its material to reduce code clutter
		SSubMeshDX& subMeshDX = m_SubMeshesDX[subMesh];
		SMeshMaterialDX& material = m_Materials[subMeshDX.material];

		// Set up render method passing material colours & textures and the sub-mesh's world matrix, also get back the fx file technique to use
		SetRenderMethod( material.renderMethod, &material.diffuseColour, &material.specularColour, material.specularPower, material.textures, &matrices[subMeshDX.node] );
		ID3D10EffectTechnique* technique = GetRenderMethodTechnique( material.renderMethod );

		// Select vertex and index buffer for sub-mesh - assuming all geometry data is triangle lists
		UINT offset = 0;
		g_pd3dDevice->IASetVertexBuffers( 0, 1, &subMeshDX.vertexBuffer, &subMeshDX.vertexSize, &offset );
		g_pd3dDevice->IASetInputLayout(subMeshDX.vertexLayout );
		g_pd3dDevice->IASetIndexBuffer(subMeshDX.indexBuffer, DXGI_FORMAT_R16_UINT, 0 );
		g_pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

		// Render the sub-mesh. Geometry buffers and shader variables, just select the technique for this method and draw.
		D3D10_TECHNIQUE_DESC techDesc;
		technique->GetDesc( &techDesc );
		for( UINT p = 0; p < techDesc.Passes; ++p )
		{
			technique->GetPassByIndex( p )->Apply( 0 );
			g_pd3dDevice->DrawIndexed( subMeshDX.numIndices, 0, 0 );
		}
		g_pd3dDevice->DrawIndexed( subMeshDX.numIndices, 0, 0 );
	}
}
コード例 #10
0
bool BufferObject::render()
{
	if(TransformObject::render())
	{
		ID3D10Buffer *buffers[2];
		buffers[0] = mpVertexBufferStatic;
		buffers[1] = mpVertexBufferDynamic;
		unsigned int stride[2];
		stride[0] = getEffect()->getInputLayoutHandler().getInputLayout(getEffectTechIndex())->getLayoutSizeStatic();
		stride[1] = getEffect()->getInputLayoutHandler().getInputLayout(getEffectTechIndex())->getLayoutSizeDynamic();
		unsigned int offset[2];
		offset[0] = 0;
		offset[1] = 0;
		getDevice()->IASetVertexBuffers(0, 2, buffers, stride, offset);
		getDevice()->IASetIndexBuffer(mpIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
		getDevice()->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ);
		getDevice()->IASetInputLayout(getEffect()->getInputLayoutHandler().getInputLayout(getEffectTechIndex())->getDXInputLayout());

		ID3D10EffectTechnique *pEffectTechnique = getEffect()->getEffect()->GetTechniqueByIndex(getEffectTechIndex());
		
		if(getRenderPass() == -1)
		{
			D3D10_TECHNIQUE_DESC techDesc;
			pEffectTechnique->GetDesc(&techDesc);
			for(unsigned int n = 0; n < techDesc.Passes; ++n)
			{
				pEffectTechnique->GetPassByIndex(n)->Apply(0);
				getDevice()->DrawIndexed(mIndexCount, 0, 0);
			}
			return true;
		}
		else
		{
			// To render a single pass decided with setRenderPass()
			pEffectTechnique->GetPassByIndex(getRenderPass())->Apply(0);
			getDevice()->DrawIndexed(mIndexCount, 0, 0);

			return true;
		}
	}
	return false;
}
コード例 #11
0
ファイル: main.cpp プロジェクト: Team306/BigProject
void CubeMapApp::drawScene()
{
	D3DApp::drawScene();
	
	
	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactor, 0xffffffff);
	
	md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	md3dDevice->IASetInputLayout(InputLayout::PosNormalTex);

	// Set per frame constants.
	mfxEyePosVar->SetRawValue(&GetCamera().position(), 0, sizeof(D3DXVECTOR3));
	mfxLightVar->SetRawValue(&mParallelLight, 0, sizeof(Light));
	
	mfxCubeMapVar->SetResource(mEnvMapRV);
	

	D3DXMATRIX view = GetCamera().view();
	D3DXMATRIX proj = GetCamera().proj();

    D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );

    for(UINT i = 0; i < techDesc.Passes; ++i)
    {
        ID3D10EffectPass* pass = mTech->GetPassByIndex(i);

		//
		// draw center ball
		//
		D3DXMATRIX centerBallWVP = mCenterBallWorld*view*proj;
		mfxWVPVar->SetMatrix((float*)&centerBallWVP);
		mfxWorldVar->SetMatrix((float*)&mCenterBallWorld);
		mfxTexMtxVar->SetMatrix((float*)&mIdentityTexMtx);
		mfxDiffuseMapVar->SetResource(mBallMapRV);
		mfxSpecMapVar->SetResource(mDefaultSpecMapRV);
		mfxCubeMapEnabledVar->SetBool(true);
		mfxReflectMtrlVar->SetFloatVector((float*)&mReflectAll);
		pass->Apply(0);
		mBall.draw();		
    }

	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	md3dDevice->RSSetState(0);
	mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, WHITE);

	mSwapChain->Present(0, 0);
}
コード例 #12
0
ファイル: Exercise01_D3D10.cpp プロジェクト: KNeal/Oculus
//--------------------------------------------------------------------------------------
// RenderGrass
//--------------------------------------------------------------------------------------
void RenderGrass( ID3D10Device* pd3dDevice )
{
    D3DXMATRIX mWorld;
    D3DXMatrixIdentity( &mWorld );

    D3DXVECTOR3 vEye;
    D3DXVECTOR3 vDir;
    D3DXMATRIX mCamWorld;
    D3DXMATRIX mView;
    D3DXMATRIX mProj;
    GetCameraData( &mCamWorld, &mView, &mProj, &vEye, &vDir );
    D3DXMATRIX mWVP = mCamWorld * mView * mProj;

    // set vb streams
    ID3D10Buffer* pBuffers[1];
    pBuffers[0] = g_pGrassDataVB10;
    UINT strides[1];
    strides[0] = sizeof( D3DXVECTOR3 );
    UINT offsets[1] = {0};
    pd3dDevice->IASetVertexBuffers( 1, 1, pBuffers, strides, offsets );

    SetNumVisibleGrassTiles( g_NumGrassTiles );

    // set effect variables
    g_pmWorldViewProj->SetMatrix( ( float* )&mWVP );
    g_pfWorldScale->SetFloat( g_fWorldScale );
    g_pfHeightScale->SetFloat( g_fHeightScale );
    D3DXVECTOR4 vEye4( vEye, 1 );
    g_pvEyePt->SetFloatVector( ( float* )&vEye4 );
    g_pfFadeStart->SetFloat( g_fFadeStart );
    g_pfFadeEnd->SetFloat( g_fFadeEnd );

    g_ptxDiffuse->SetResource( g_pGrassTexRV );
    g_ptxHeight->SetResource( g_pHeightTexRV );
    g_ptxMask->SetResource( g_pMaskTexRV );
    g_ptxShadeNormals->SetResource( g_pShadeNormalTexRV );

    ID3D10EffectTechnique* pTechnique = g_pRenderGrass;

    pd3dDevice->IASetInputLayout( g_pGrassDecl10 );

    D3D10_TECHNIQUE_DESC techDesc;
    pTechnique->GetDesc( &techDesc );

    for( UINT p = 0; p < techDesc.Passes; p++ )
    {
        pTechnique->GetPassByIndex( p )->Apply( 0 );

        g_Terrain.RenderGrass( &vDir, g_NumGrassTiles );
    }

    pBuffers[0] = NULL;
    pd3dDevice->IASetVertexBuffers( 1, 1, pBuffers, strides, offsets );
}
コード例 #13
0
void ColoredTriangleApp::DrawTriangle(D3D10_TECHNIQUE_DESC techDesc){

	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
		mTech->GetPassByIndex( p )->Apply(0);        
		UINT stride = sizeof(Vertex);
		UINT offset = 0;
		md3dDevice->IASetVertexBuffers(0, 1, &mVB, &stride, &offset);
		md3dDevice->Draw(3, 0);
    }
}
コード例 #14
0
void
CanvasLayerD3D10::RenderLayer()
{
  FirePreTransactionCallback();
  UpdateSurface();
  FireDidTransactionCallback();

  if (!mTexture)
    return;

  nsIntRect visibleRect = mVisibleRegion.GetBounds();

  SetEffectTransformAndOpacity();

  uint8_t shaderFlags = 0;
  shaderFlags |= LoadMaskTexture();
  shaderFlags |= mDataIsPremultiplied
                ? SHADER_PREMUL : SHADER_NON_PREMUL | SHADER_RGBA;
  shaderFlags |= mHasAlpha ? SHADER_RGBA : SHADER_RGB;
  shaderFlags |= mFilter == GraphicsFilter::FILTER_NEAREST
                ? SHADER_POINT : SHADER_LINEAR;
  ID3D10EffectTechnique* technique = SelectShader(shaderFlags);

  if (mSRView) {
    effect()->GetVariableByName("tRGB")->AsShaderResource()->SetResource(mSRView);
  }

  effect()->GetVariableByName("vLayerQuad")->AsVector()->SetFloatVector(
    ShaderConstantRectD3D10(
      (float)mBounds.x,
      (float)mBounds.y,
      (float)mBounds.width,
      (float)mBounds.height)
    );

  if (mNeedsYFlip) {
    effect()->GetVariableByName("vTextureCoords")->AsVector()->SetFloatVector(
      ShaderConstantRectD3D10(
        0,
        1.0f,
        1.0f,
        -1.0f)
      );
  }

  technique->GetPassByIndex(0)->Apply(0);
  device()->Draw(4, 0);

  if (mNeedsYFlip) {
    effect()->GetVariableByName("vTextureCoords")->AsVector()->
      SetFloatVector(ShaderConstantRectD3D10(0, 0, 1.0f, 1.0f));
  }
}
コード例 #15
0
ファイル: render_dx10.cpp プロジェクト: chenbk85/3dlearn
bool InitResourceDX10(void)
{
	g_pDevice = GutGetGraphicsDeviceDX10();
	ID3D10Blob *pVSCode = NULL;

	for ( int i=0; i<NUM_FRAMEBUFFERS; i++ )
	{
		g_pTextures[i] = NULL;
		g_pSRView[i] = NULL;
		g_pRTView[i] = NULL;
	}

	// 載入Shader
	{
		g_pPostFX = GutLoadFXShaderDX10("../../shaders/Posteffect_dx10.fx");
		if ( NULL==g_pPostFX )
			return false;

		g_pExposureFX = GutLoadFXShaderDX10("../../shaders/Exposure_dx10.fx");
		if ( NULL==g_pExposureFX )
			return false;
	}

	// 設定Vertex資料格式
	{
		ID3D10EffectTechnique *pShader = g_pExposureFX->GetTechniqueByName("AutoExposure");

		D3D10_INPUT_ELEMENT_DESC layout[] =
		{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },
			{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
		};

		D3D10_PASS_DESC PassDesc;
		pShader->GetPassByIndex(0)->GetDesc(&PassDesc);

		if ( D3D_OK != g_pDevice->CreateInputLayout( layout, 2, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &g_pVertexLayout ) )
			return false;

		SAFE_RELEASE(pVSCode);
	}

	if ( !ReInitResourceDX10() )
		return false;

	CGutModel_DX10::LoadDefaultShader("../../shaders/gmodel_dx10.hlsl");
	g_Model_DX10.ConvertToDX10Model(&g_Model);

	g_pVertexBuffer = GutCreateVertexBuffer_DX10(sizeof(Vertex_VT)*4, g_FullScreenQuad);

	return true;
}
コード例 #16
0
void
ShadowThebesLayerD3D10::RenderLayer()
{
  if (!mTexture) {
    return;
  }

  // FIXME/bug 662109: synchronize using KeyedMutex
  
  nsRefPtr<ID3D10ShaderResourceView> srView;
  HRESULT hr = device()->CreateShaderResourceView(mTexture, NULL, getter_AddRefs(srView));
  if (FAILED(hr)) {
      NS_WARNING("Failed to create shader resource view for ThebesLayerD3D10.");
  }


  SetEffectTransformAndOpacity();

  ID3D10EffectTechnique *technique = SelectShader(SHADER_RGB | SHADER_PREMUL | LoadMaskTexture());

  effect()->GetVariableByName("tRGB")->AsShaderResource()->SetResource(srView);

  nsIntRect textureRect = GetVisibleRegion().GetBounds();

  nsIntRegionRectIterator iter(mVisibleRegion);
  while (const nsIntRect *iterRect = iter.Next()) {
    effect()->GetVariableByName("vLayerQuad")->AsVector()->SetFloatVector(
      ShaderConstantRectD3D10(
        (float)iterRect->x,
        (float)iterRect->y,
        (float)iterRect->width,
        (float)iterRect->height)
      );

    effect()->GetVariableByName("vTextureCoords")->AsVector()->SetFloatVector(
      ShaderConstantRectD3D10(
        (float)(iterRect->x - textureRect.x) / (float)textureRect.width,
        (float)(iterRect->y - textureRect.y) / (float)textureRect.height,
        (float)iterRect->width / (float)textureRect.width,
        (float)iterRect->height / (float)textureRect.height)
      );

    technique->GetPassByIndex(0)->Apply(0);
    device()->Draw(4, 0);
  }

  // FIXME/bug 662109: synchronize using KeyedMutex

  // Set back to default.
  effect()->GetVariableByName("vTextureCoords")->AsVector()->
    SetFloatVector(ShaderConstantRectD3D10(0, 0, 1.0f, 1.0f));
}
コード例 #17
0
ファイル: render_dx10.cpp プロジェクト: chenbk85/3dlearn
static void ExpLuminance(void)
{
	ID3D10EffectTechnique *pShader = g_pExposureFX->GetTechniqueByName("ExpLuminance");
	ID3D10EffectShaderResourceVariable *pImage0_var = g_pExposureFX->GetVariableByName("Image0")->AsShaderResource();

	g_pDevice->OMSetRenderTargets(1, &g_pRTView[LUMINANCE_TEMP], NULL);

	pImage0_var->SetResource(g_pSRView[LUMINANCE_CURRENT]);
	pShader->GetPassByIndex(0)->Apply(0);

	DrawFullScreenQuad();

	SwapRenderTarget(LUMINANCE_CURRENT, LUMINANCE_TEMP);
}
コード例 #18
0
ファイル: Model3D.cpp プロジェクト: drsoxen/Pinball
void Model3D::Draw(D3DXMATRIX WorldMatrix,D3DXMATRIX ViewMatrix,D3DXMATRIX ProjectionMatrix,float DeltaTime,Light lights[],Vector3 CurrentCam)
{
	D3DXMATRIX transMatrix;
	if(ChangedOrigin == true)
		D3DXMatrixTranslation(&transMatrix, newOrigin.X, newOrigin.Y, newOrigin.Z);
	else
		D3DXMatrixTranslation(&transMatrix, m_Position.X, m_Position.Y, m_Position.Z);


	D3DXMATRIX rot;
	D3DXMatrixRotationYawPitchRoll(&rot,m_Rotation.X, m_Rotation.Y, m_Rotation.Z);

	D3DXMATRIX scale;
	D3DXMatrixIdentity(&scale);

	D3DXMATRIX World = scale * rot * transMatrix;
	World = World * WorldMatrix;

	D3DXMATRIX WVP = World * ViewMatrix * ProjectionMatrix;

	m_Shader->SetWorld(World);
	m_Shader->SetWVP(WVP);
	m_Shader->SetLight(lights);
	m_Shader->SetCurrentCamera(CurrentCam);

	m_ShaderTexture = m_Shader->m_Texture;

	if(m_Texture != NULL)
	{
		m_ShaderTexture->SetResource(m_Texture);
	}

	ID3D10EffectTechnique* tech = m_Shader->GetTech();
	ID3D10InputLayout* layout = m_Shader->GetVertexLayout();

	D3D10_TECHNIQUE_DESC techDesc;
	tech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
	{
		tech->GetPassByIndex( p )->Apply(0);   
		UINT stride = sizeof(Vertex);
		UINT offset = 0;
		m_Device->IASetVertexBuffers(0, 1, &m_VertexBuffer, &stride, &offset);
		m_Device->Draw(m_VertexCount,0);
	}

	if(m_Child != NULL)
		m_Child->Draw(World,ViewMatrix,ProjectionMatrix,DeltaTime,lights,CurrentCam);
}
コード例 #19
0
void TestApplication1::OnFrameRender(ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext)
{
	HRESULT hr;

	//Render
	ID3D10EffectTechnique* pRenderTechnique;
	D3D10_TECHNIQUE_DESC techDesc;
	pRenderTechnique = _shaderutil.GetTechnique();
	pRenderTechnique->GetDesc(&techDesc);
	SDKMESH_SUBSET* pSubset = NULL;
	ID3D10ShaderResourceView* pDiffuseRV = NULL;
	D3D10_PRIMITIVE_TOPOLOGY PrimType;

	D3DXMATRIX mWorldViewProjection;
	//D3DXVECTOR3 vLightDir[MAX_LIGHTS];
	//D3DXVECTOR4 vLightDiffuse[MAX_LIGHTS];
	D3DXMATRIX mWorld;
	D3DXMATRIX mView;
	D3DXMATRIX mProj;

	// Get the projection & view matrix from the camera class
	mWorld = _mCenterMesh * *_camera.GetWorldMatrix();
	mProj = *_camera.GetProjMatrix();
	mView = *_camera.GetViewMatrix();

	mWorldViewProjection = mWorld * mView * mProj;

	_shaderutil.SetWorldMatrix(mWorld);
	_shaderutil.SetViewMatrix(mView);
	_shaderutil.SetProjectionMatrix(mProj);

	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		for (UINT subset = 0; subset < _Mesh.GetNumSubsets(0); ++subset)
		{
			// Get the subset
			pSubset = _Mesh.GetSubset(0, subset);

			PrimType = CDXUTSDKMesh::GetPrimitiveType10((SDKMESH_PRIMITIVE_TYPE)pSubset->PrimitiveType);
			pd3dDevice->IASetPrimitiveTopology(PrimType);

			//pDiffuseRV = _Mesh.GetMaterial(pSubset->MaterialID)->pDiffuseRV10;
			//g_ptxDiffuse->SetResource(pDiffuseRV);

			pRenderTechnique->GetPassByIndex(p)->Apply(0);
			pd3dDevice->DrawIndexed((UINT)pSubset->IndexCount, 0, (UINT)pSubset->VertexStart);
		}
	}
}
コード例 #20
0
void ColoredCubeApp::buildVertexLayouts()
{
	// Create the vertex input layout.
	D3D10_INPUT_ELEMENT_DESC vertexDesc[] =
	{
		{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
		{"COLOR",    0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0}
	};

	// Create the input layout
    D3D10_PASS_DESC PassDesc;
    mTech->GetPassByIndex(0)->GetDesc(&PassDesc);
    HR(md3dDevice->CreateInputLayout(vertexDesc, 2, PassDesc.pIAInputSignature,
		PassDesc.IAInputSignatureSize, &mVertexLayout));
}
コード例 #21
0
ファイル: Cube.cpp プロジェクト: BillyKim/directxcode
void Cube::Draw(ID3D10Effect* effects, D3DXMATRIX& view_matrix, D3DXMATRIX& proj_matrix, D3DXVECTOR3& eye_pos)
{
	 // Obtain shader variables
	texture_id_        = effects->GetVariableByName("TextureId")->AsScalar();
 	wvp_matrix_ = effects->GetVariableByName("WVPMatrix")->AsMatrix();

	// Set world view projection matrix
	D3DXMATRIX wvp_matrix = world_matrix_ * view_matrix * proj_matrix;
	wvp_matrix_->SetMatrix((float*)wvp_matrix);

	// Set vertex buffer
	UINT stride = sizeof(Vertex);
	UINT offset = 0;
	d3d_device_->IASetVertexBuffers(0, 1, &vertex_buffer_, &stride, &offset);

	// Set geometry type
	d3d_device_->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);

	// Obtain the technique
    ID3D10EffectTechnique* technique = effects->GetTechniqueByName("Render");
	if (technique == NULL)
	{
		MessageBox(NULL, L"Get technique failed", L"Error", 0);
	}

	// Apply each pass in technique and draw triangle.
	D3D10_TECHNIQUE_DESC techDesc;
	technique->GetDesc(&techDesc);
	for (unsigned int i = 0; i < techDesc.Passes; ++i)
	{
		ID3D10EffectPass* pass = technique->GetPassByIndex(i);
		pass->Apply(0);
		
		// Draw cube by draw every face of the cube
		for(int i = 0; i < kNumFaces_; ++i)
		{
			// Set texture id
			texture_id_->SetInt(textureId[i]);

			// Set index buffer
			d3d_device_->IASetIndexBuffer(pIB[i], DXGI_FORMAT_R16_UINT, 0);

			pass->Apply(0);
			
			d3d_device_->DrawIndexed(4, 0, 0);
		}
	}
}
コード例 #22
0
ファイル: d3d10.cpp プロジェクト: LordMartyCorp/mumble
void D10State::draw() {
	clock_t t = clock();
	float elapsed = static_cast<float>(t - timeT) / CLOCKS_PER_SEC;
	++frameCount;
	if (elapsed > OVERLAY_FPS_INTERVAL) {
		OverlayMsg om;
		om.omh.uiMagic = OVERLAY_MAGIC_NUMBER;
		om.omh.uiType = OVERLAY_MSGTYPE_FPS;
		om.omh.iLength = sizeof(OverlayMsgFps);
		om.omf.fps = frameCount / elapsed;

		sendMessage(om);

		frameCount = 0;
		timeT = t;
	}

	dwMyThread = GetCurrentThreadId();

	checkMessage(vp.Width, vp.Height);

	if (a_ucTexture && pSRView && (uiLeft != uiRight)) {
		HRESULT hr;
		pOrigStateBlock->Capture();
		pMyStateBlock->Apply();

		D3D10_TECHNIQUE_DESC techDesc;
		pTechnique->GetDesc(&techDesc);

		// Set vertex buffer
		UINT stride = sizeof(SimpleVertex);
		UINT offset = 0;
		pDevice->IASetVertexBuffers(0, 1, &pVertexBuffer, &stride, &offset);

		hr = pDiffuseTexture->SetResource(pSRView);
		if (! SUCCEEDED(hr))
			ods("D3D10: Failed to set resource");

		for (UINT p = 0; p < techDesc.Passes; ++p) {
			pTechnique->GetPassByIndex(p)->Apply(0);
			pDevice->DrawIndexed(6, 0, 0);
		}
		pOrigStateBlock->Apply();
	}

	dwMyThread = 0;
}
コード例 #23
0
ファイル: DispObj.cpp プロジェクト: Ochakko/MameBake3D
int CDispObj::RenderLine( ChaVector4 diffusemult )
{
	if( !m_extline ){
		return 0;
	}
	if( m_extline->m_linenum <= 0 ){
		return 0;
	}

	HRESULT hr;

	ChaVector4 diffuse;
	diffuse.w = m_extline->m_color.w * diffusemult.w;
	diffuse.x = m_extline->m_color.x * diffusemult.x;
	diffuse.y = m_extline->m_color.y * diffusemult.y;
	diffuse.z = m_extline->m_color.z * diffusemult.z;

	hr = g_hdiffuse->SetRawValue(&diffuse, 0, sizeof(ChaVector4));
	_ASSERT(!hr);

	m_pdev->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINELIST);

	ID3D10EffectTechnique* curtech = g_hRenderLine;
	m_pdev->IASetInputLayout(m_layoutLine);

	UINT vbstride = sizeof(EXTLINEV);
	UINT offset = 0;
	m_pdev->IASetVertexBuffers(0, 1, &m_VB, &vbstride, &offset);
	//m_pdev->IASetIndexBuffer(m_IB, DXGI_FORMAT_R32_UINT, 0);

	int curnumprim;
	curnumprim = m_extline->m_linenum;


	//D3D10_TECHNIQUE_DESC techDesc;
	//curtech->GetDesc(&techDesc);
	UINT p = 0;
	//for (UINT p = 0; p < techDesc.Passes; ++p)
	//{
		curtech->GetPassByIndex(p)->Apply(0);
		//m_pdev->DrawIndexed(curnumprim * 2, 0, 0);
		m_pdev->Draw(curnumprim * 2, 0);
	//}


	return 0;
}
コード例 #24
0
ファイル: render_dx10.cpp プロジェクト: chenbk85/3dlearn
static void ConvertToLogLuminance(void)
{
	g_pDevice->OMSetRenderTargets(1, &g_pRTView[DOWNSAMPLED_256x256], NULL);

	SetViewport(DOWNSAMPLED_256x256);

	ID3D10EffectTechnique *pShader = g_pExposureFX->GetTechniqueByName("LogLuminance");
	ID3D10EffectShaderResourceVariable *pImage_var = g_pExposureFX->GetVariableByName("Image0")->AsShaderResource();
	ID3D10EffectVectorVariable *pLuminanceTable_var = g_pExposureFX->GetVariableByName("vLuminanceTable")->AsVector();

	pImage_var->SetResource(g_pSRView[FULLSIZE]);
	pLuminanceTable_var->SetFloatVector( &vLuminanceTable[0] );

	pShader->GetPassByIndex(0)->Apply(0);

	DrawFullScreenQuad();
}
コード例 #25
0
void CrateApp::drawScene()
{
	D3DApp::drawScene();

	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);
    md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

 
	// set constants
	mfxEyePosVar->SetRawValue(&mEyePos, 0, sizeof(D3DXVECTOR3));
	mfxLightVar->SetRawValue(&mParallelLight, 0, sizeof(Light));
	mWVP = mCrateWorld*mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
	mfxWorldVar->SetMatrix((float*)&mCrateWorld);
	mfxDiffuseMapVar->SetResource(mDiffuseMapRV);
	mfxSpecMapVar->SetResource(mSpecMapRV);
 
	// Don't transform texture coordinates, so just use identity transformation.
	D3DXMATRIX texMtx;
	D3DXMatrixIdentity(&texMtx);
	mfxTexMtxVar->SetMatrix((float*)&texMtx);

    D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );
    for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex( p )->Apply(0);
        
		mCrateMesh.draw();
    }

	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);

	mSwapChain->Present(0, 0);
}
コード例 #26
0
ファイル: render_dx10.cpp プロジェクト: chenbk85/3dlearn
static void AdaptiveLuminance(void)
{
	ID3D10EffectTechnique *pShader = g_pExposureFX->GetTechniqueByName("AdaptiveLuminance");
	ID3D10EffectShaderResourceVariable *pImage0_var = g_pExposureFX->GetVariableByName("Image0")->AsShaderResource();
	ID3D10EffectShaderResourceVariable *pImage1_var = g_pExposureFX->GetVariableByName("Image1")->AsShaderResource();
	ID3D10EffectVectorVariable *pAdaptiveSpeed_var = g_pExposureFX->GetVariableByName("vAdaptiveSpeed")->AsVector();

	Vector4 vSpeed(0.1f);

	pImage0_var->SetResource(g_pSRView[LUMINANCE_PREVIOUS]);
	pImage1_var->SetResource(g_pSRView[LUMINANCE_CURRENT]);
	pAdaptiveSpeed_var->SetFloatVector( (float*)&vSpeed[0] );

	g_pDevice->OMSetRenderTargets(1, &g_pRTView[LUMINANCE_TEMP], NULL);

	pShader->GetPassByIndex(0)->Apply(0);
	DrawFullScreenQuad();

	SwapRenderTarget(LUMINANCE_TEMP, LUMINANCE_PREVIOUS);
}
コード例 #27
0
ファイル: render_dx10.cpp プロジェクト: as2120/ZNginx
void RenderFrameDX10(void)
{
	Vector4 vClearColor(0.0f);
	Vector4 vObjectColor(0.0f, 1.0f, 0.0f);

	ID3D10RenderTargetView *pRenderTargetView = GutGetDX10RenderTargetView(); //frame buffer
	ID3D10DepthStencilView *pDepthStencilView = GutGetDX10DepthStencilView(); //depth/stencil buffer
	g_pDevice->ClearRenderTargetView(pRenderTargetView, &vClearColor[0]);
	g_pDevice->ClearDepthStencilView(pDepthStencilView, D3D10_CLEAR_DEPTH|D3D10_CLEAR_STENCIL, 1.0f, 0);

	// background image
	DrawImage(g_pTexture);

	// refraction

	Matrix4x4 view_matrix = g_Control.GetViewMatrix();
	Matrix4x4 world_matrix = g_Control.GetObjectMatrix();
	Matrix4x4 wvp_matrix = world_matrix * view_matrix * g_proj_matrix;
	Matrix4x4 wv_matrix = world_matrix * view_matrix;

	ID3D10EffectTechnique *pShader = g_pRefractionFX->GetTechniqueByName("Refraction");
	ID3D10EffectShaderResourceVariable *texture_param = g_pRefractionFX->GetVariableByName("BackgroundImage")->AsShaderResource();
	ID3D10EffectMatrixVariable *wvpmatrix_param = g_pRefractionFX->GetVariableByName("wvp_matrix")->AsMatrix();
	ID3D10EffectMatrixVariable *wvmatrix_param = g_pRefractionFX->GetVariableByName("wv_matrix")->AsMatrix();
	ID3D10EffectVectorVariable *color_param = g_pRefractionFX->GetVariableByName("object_color")->AsVector();

	texture_param->SetResource(g_pTexture);
	wvpmatrix_param->SetMatrix( (float *)&wvp_matrix );
	wvmatrix_param->SetMatrix( (float *)&wv_matrix );
	color_param->SetFloatVector( (float *)&vObjectColor );

	pShader->GetPassByIndex(0)->Apply(0);
	g_pDevice->IASetInputLayout(g_pRefractionLayout);

	g_Model_DX10.Render(SUBMIT_CULLFACE);

	// 等待硬體掃結束, 然後才更新畫面
	IDXGISwapChain *pSwapChain = GutGetDX10SwapChain();
	pSwapChain->Present(1, 0);
}
コード例 #28
0
ファイル: LineModel.cpp プロジェクト: drsoxen/Pinball
void LineModel::Draw(D3DXMATRIX WorldMatrix,D3DXMATRIX ViewMatrix,D3DXMATRIX ProjectionMatrix,float DeltaTime)
{
	D3DXMATRIX transMatrix;
	if(ChangedOrigin == true)
		D3DXMatrixTranslation(&transMatrix, newOrigin.X, newOrigin.Y, newOrigin.Z);
	else
		D3DXMatrixTranslation(&transMatrix, m_Position.X, m_Position.Y, m_Position.Z);

	D3DXMATRIX rot;
	D3DXMatrixRotationYawPitchRoll(&rot,m_Rotation.X, m_Rotation.Y, m_Rotation.Z);

	D3DXMATRIX scale;
	D3DXMatrixIdentity(&scale);

	D3DXMATRIX World = scale * rot * transMatrix;
	World = World * WorldMatrix;

	D3DXMATRIX WVP = World * ViewMatrix * ProjectionMatrix;

	m_Shader->SetWorld(World);
	m_Shader->SetWVP(WVP);

	ID3D10EffectTechnique* tech = m_Shader->GetTech();
	ID3D10InputLayout* layout = m_Shader->GetVertexLayout();

	D3D10_TECHNIQUE_DESC techDesc;
	tech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
	{
		tech->GetPassByIndex( p )->Apply(0);   
		UINT stride = sizeof(Vector3);
		UINT offset = 0;
		m_Device->IASetVertexBuffers(0, 1, &m_VertexBuffer, &stride, &offset);
		m_Device->Draw(m_VertexCount, 0);
	}
}
コード例 #29
0
ファイル: render_dx10.cpp プロジェクト: chenbk85/3dlearn
static void AutoExposure(void)
{
	ID3D10RenderTargetView *pRenderTargetView = GutGetDX10RenderTargetView();

	ID3D10EffectTechnique *pShader = g_pExposureFX->GetTechniqueByName("AutoExposure");
	ID3D10EffectShaderResourceVariable *pImage0_var = g_pExposureFX->GetVariableByName("Image0")->AsShaderResource();
	ID3D10EffectShaderResourceVariable *pImage1_var = g_pExposureFX->GetVariableByName("Image1")->AsShaderResource();
	ID3D10EffectVectorVariable *pMulClamp_var = g_pExposureFX->GetVariableByName("vMultiplierClamp")->AsVector();
	ID3D10EffectVectorVariable *pMiddle_var = g_pExposureFX->GetVariableByName("vMiddleGray")->AsVector();

	Vector4 vMiddleGray(0.5f);
	Vector4 vMultiplierClamp(0.2f, 3.0f, 0.0f, 0.0f);

	pImage0_var->SetResource(g_pSRView[FULLSIZE]);
	pImage1_var->SetResource(g_pSRView[LUMINANCE_PREVIOUS]);
	pMulClamp_var->SetFloatVector( (float*)&vMultiplierClamp[0] );
	pMiddle_var->SetFloatVector( (float*)&vMiddleGray[0] );

	g_pDevice->OMSetRenderTargets(1, &pRenderTargetView, NULL);
	SetViewport(FULLSIZE);

	pShader->GetPassByIndex(0)->Apply(0);
	DrawFullScreenQuad();
}
コード例 #30
0
void
ContainerLayerD3D10::RenderLayer()
{
  float renderTargetOffset[] = { 0, 0 };

  nsIntRect visibleRect = mVisibleRegion.GetBounds();
  float opacity = GetEffectiveOpacity();
  bool useIntermediate = UseIntermediateSurface();

  nsRefPtr<ID3D10RenderTargetView> previousRTView;
  nsRefPtr<ID3D10Texture2D> renderTexture;
  nsRefPtr<ID3D10RenderTargetView> rtView;
  float previousRenderTargetOffset[2];
  nsIntSize previousViewportSize;

  gfx3DMatrix oldViewMatrix;

  if (useIntermediate) {
    device()->OMGetRenderTargets(1, getter_AddRefs(previousRTView), NULL);
 
    D3D10_TEXTURE2D_DESC desc;
    memset(&desc, 0, sizeof(D3D10_TEXTURE2D_DESC));
    desc.ArraySize = 1;
    desc.MipLevels = 1;
    desc.Width = visibleRect.width;
    desc.Height = visibleRect.height;
    desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
    desc.SampleDesc.Count = 1;
    desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
    HRESULT hr;
    hr = device()->CreateTexture2D(&desc, NULL, getter_AddRefs(renderTexture));

    if (FAILED(hr)) {
      LayerManagerD3D10::ReportFailure(NS_LITERAL_CSTRING("Failed to create new texture for ContainerLayerD3D10!"), 
                                       hr);
      return;
    }

    hr = device()->CreateRenderTargetView(renderTexture, NULL, getter_AddRefs(rtView));
    NS_ASSERTION(SUCCEEDED(hr), "Failed to create render target view for ContainerLayerD3D10!");

    effect()->GetVariableByName("vRenderTargetOffset")->
      GetRawValue(previousRenderTargetOffset, 0, 8);

    previousViewportSize = mD3DManager->GetViewport();

    if (mVisibleRegion.GetNumRects() != 1 || !(GetContentFlags() & CONTENT_OPAQUE)) {
      const gfx3DMatrix& transform3D = GetEffectiveTransform();
      gfxMatrix transform;
      // If we have an opaque ancestor layer, then we can be sure that
      // all the pixels we draw into are either opaque already or will be
      // covered by something opaque. Otherwise copying up the background is
      // not safe.
      if (mSupportsComponentAlphaChildren) {
        bool is2d = transform3D.Is2D(&transform);
        NS_ASSERTION(is2d, "Transform should be 2d when mSupportsComponentAlphaChildren.");

        // Copy background up from below. This applies any 2D transform that is
        // applied to use relative to our parent, and compensates for the offset
        // that was applied on our parent's rendering.
        D3D10_BOX srcBox;
        srcBox.left = std::max<int32_t>(visibleRect.x + int32_t(transform.x0) - int32_t(previousRenderTargetOffset[0]), 0);
        srcBox.top = std::max<int32_t>(visibleRect.y + int32_t(transform.y0) - int32_t(previousRenderTargetOffset[1]), 0);
        srcBox.right = std::min<int32_t>(srcBox.left + visibleRect.width, previousViewportSize.width);
        srcBox.bottom = std::min<int32_t>(srcBox.top + visibleRect.height, previousViewportSize.height);
        srcBox.back = 1;
        srcBox.front = 0;

        nsRefPtr<ID3D10Resource> srcResource;
        previousRTView->GetResource(getter_AddRefs(srcResource));

        device()->CopySubresourceRegion(renderTexture, 0,
                                        0, 0, 0,
                                        srcResource, 0,
                                        &srcBox);
      } else {
        float black[] = { 0, 0, 0, 0};
        device()->ClearRenderTargetView(rtView, black);
      }
    }

    ID3D10RenderTargetView *rtViewPtr = rtView;
    device()->OMSetRenderTargets(1, &rtViewPtr, NULL);

    renderTargetOffset[0] = (float)visibleRect.x;
    renderTargetOffset[1] = (float)visibleRect.y;
    effect()->GetVariableByName("vRenderTargetOffset")->
      SetRawValue(renderTargetOffset, 0, 8);

    mD3DManager->SetViewport(nsIntSize(visibleRect.Size()));
  }
    
  D3D10_RECT oldD3D10Scissor;
  UINT numRects = 1;
  device()->RSGetScissorRects(&numRects, &oldD3D10Scissor);
  // Convert scissor to an nsIntRect. D3D10_RECT's are exclusive
  // on the bottom and right values.
  nsIntRect oldScissor(oldD3D10Scissor.left,
                       oldD3D10Scissor.top,
                       oldD3D10Scissor.right - oldD3D10Scissor.left,
                       oldD3D10Scissor.bottom - oldD3D10Scissor.top);

  nsAutoTArray<Layer*, 12> children;
  SortChildrenBy3DZOrder(children);

  /*
   * Render this container's contents.
   */
  for (uint32_t i = 0; i < children.Length(); i++) {
    LayerD3D10* layerToRender = static_cast<LayerD3D10*>(children.ElementAt(i)->ImplData());

    if (layerToRender->GetLayer()->GetEffectiveVisibleRegion().IsEmpty()) {
      continue;
    }
    
    nsIntRect scissorRect =
        layerToRender->GetLayer()->CalculateScissorRect(oldScissor, nullptr);
    if (scissorRect.IsEmpty()) {
      continue;
    }

    D3D10_RECT d3drect;
    d3drect.left = scissorRect.x;
    d3drect.top = scissorRect.y;
    d3drect.right = scissorRect.x + scissorRect.width;
    d3drect.bottom = scissorRect.y + scissorRect.height;
    device()->RSSetScissorRects(1, &d3drect);

    layerToRender->RenderLayer();
  }

  device()->RSSetScissorRects(1, &oldD3D10Scissor);

  if (useIntermediate) {
    mD3DManager->SetViewport(previousViewportSize);
    ID3D10RenderTargetView *rtView = previousRTView;
    device()->OMSetRenderTargets(1, &rtView, NULL);
    effect()->GetVariableByName("vRenderTargetOffset")->
      SetRawValue(previousRenderTargetOffset, 0, 8);

    SetEffectTransformAndOpacity();

    ID3D10EffectTechnique *technique;
    if (LoadMaskTexture()) {
      if (GetTransform().CanDraw2D()) {
        technique = SelectShader(SHADER_RGBA | SHADER_PREMUL | SHADER_MASK);
      } else {
        technique = SelectShader(SHADER_RGBA | SHADER_PREMUL | SHADER_MASK_3D);
      }
    } else {
        technique = SelectShader(SHADER_RGBA | SHADER_PREMUL | SHADER_NO_MASK);
    }

    effect()->GetVariableByName("vLayerQuad")->AsVector()->SetFloatVector(
      ShaderConstantRectD3D10(
        (float)visibleRect.x,
        (float)visibleRect.y,
        (float)visibleRect.width,
        (float)visibleRect.height)
      );

    technique->GetPassByIndex(0)->Apply(0);

    ID3D10ShaderResourceView *view;
    device()->CreateShaderResourceView(renderTexture, NULL, &view);
    device()->PSSetShaderResources(0, 1, &view);    
    device()->Draw(4, 0);
    view->Release();
  }
}