当前位置: 首页>>代码示例>>C++>>正文


C++ ConstantBuffer类代码示例

本文整理汇总了C++中ConstantBuffer的典型用法代码示例。如果您正苦于以下问题:C++ ConstantBuffer类的具体用法?C++ ConstantBuffer怎么用?C++ ConstantBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ConstantBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Color

void BloomFilter::render() {
	// draw RT1 using bloom shader to RT2
	// RT1 = original source
	// RT2 = bloom
	ID3D11ShaderResourceView* srv1 = gfx::getRenderTargetSRV(_rt1);	
	gfx::setRenderTarget(_rt2);
	gfx::clearRenderTarget(_rt2, Color(0, 0, 0));
	_quad.render(_bloomShader, srv1);
	// RT3 - horizontal blur
	ID3D11ShaderResourceView* srv2 = gfx::getRenderTargetSRV(_rt2);
	gfx::setRenderTarget(_rt3);
	gfx::clearRenderTarget(_rt3, Color(0, 0, 0));
	_quad.render(_hBlurShader, srv2);
	// RT2 vertical blur
	ID3D11ShaderResourceView* srv3 = gfx::getRenderTargetSRV(_rt3);
	gfx::setRenderTarget(_rt2);
	gfx::clearRenderTarget(_rt2, Color(0, 0, 0));
	_quad.render(_vBlurShader, srv3);
	
	// draw RT1 and RT4 using combine shader
	gfx::restoreBackBuffer();
	gfx::beginRendering(Color(0, 0, 0));

	BloomSettings settings;
	settings.intensity = 1.0f;
	settings.originalIntensity = 0.7f;
	settings.saturation = 0.8f;
	settings.originalSaturation = 1.0f;
	ConstantBuffer* cb = gfx::getConstantBuffer(_blCB);
	cb->setData(gfx::getDeviceContext(), settings);
	cb->setPSBuffer(gfx::getDeviceContext(), 0);
	_quad.render(_combineShader, srv1,srv2);	
	//gfx::drawRenderTarget(_rt2);

}
开发者ID:amecky,项目名称:DT,代码行数:35,代码来源:BloomFilter.cpp

示例2: createConstantBuffer

	int createConstantBuffer(int elementSize) {
		// FIXME: elementsize must be multiple of 16!!!!
		ConstantBuffer* buffer = new ConstantBuffer;
		buffer->create(ctx->device,elementSize);
		ctx->constantBuffers.push_back(buffer);
		return ctx->constantBuffers.size() - 1;
	}
开发者ID:amecky,项目名称:DT,代码行数:7,代码来源:gfx.cpp

示例3: build

	HRESULT ShaderBase::processLoadedShaderBlob( ID3DBlob *shaderSource )
	{
		HRESULT res = build( shaderSource );
		if ( FAILED(res) )
		{
			std::cout << "Error (ShaderBase::processLoadedShaderBlob): Error creating shader" << std::endl;
			return res;
		}


		// setup buffers using the shader reflection
		ID3D11ShaderReflection *reflector;
		res = D3DReflect( shaderSource->GetBufferPointer(), shaderSource->GetBufferSize(),
							IID_ID3D11ShaderReflection, (void**)&reflector );
		if ( FAILED( res ) )
		{
			std::cout << "Error (ShaderBase::processLoadedShaderBlob): Error creating shader reflection" << std::endl;
			return res;
		}


		D3D11_SHADER_DESC shaderDesc;
		ZeroMemory( &shaderDesc, sizeof( D3D11_SHADER_DESC ) );
		res = reflector->GetDesc( &shaderDesc );
		if ( FAILED( res ) )
		{
			std::cout << "Error (ShaderBase::processLoadedShaderBlob): Error creating shader reflection description" << std::endl;
			reflector->Release();
			return res;
		}


		for ( UINT i = 0U; i < shaderDesc.ConstantBuffers; ++i )
		{
			ID3D11ShaderReflectionConstantBuffer *constBuffReflection = reflector->GetConstantBufferByIndex( i );
			D3D11_SHADER_BUFFER_DESC shaderBuffDesc;
			constBuffReflection->GetDesc( &shaderBuffDesc );

			//TODO: these can be put on the stack
			ConstantBuffer *cBuff = new ConstantBuffer( m_dxDev, i, shaderBuffDesc.Name );
			cBuff->create( shaderBuffDesc.Size );
			for ( UINT j = 0U; j < shaderBuffDesc.Variables; ++j )
			{
				ID3D11ShaderReflectionVariable *variableRefl = constBuffReflection->GetVariableByIndex( j );
				D3D11_SHADER_VARIABLE_DESC shaderVarDesc;
				variableRefl->GetDesc( &shaderVarDesc );

				cBuff->addVariableDefinition( shaderVarDesc.Name, shaderVarDesc.StartOffset, shaderVarDesc.Size );
			}

			m_constBuffers.push_back( cBuff );
			m_dxConstBuffers.push_back( cBuff->getDxBufferPtr() );
		}

		reflector->Release();

		return S_OK;
	}
开发者ID:krienie,项目名称:KrienGraphiX,代码行数:58,代码来源:ShaderBase.cpp

示例4: BuildLandGeometryBuffers

bool LightingApp::Init()
{
	if(!D3DApp::Init())
		return false;

	mWaves.Init(160, 160, 1.0f, 0.03f, 3.25f, 0.4f);

	BuildLandGeometryBuffers();
	BuildWaveGeometryBuffers();
	BuildFX();
	BuildVertexLayout();
	mObjectConstantBuffer.Initialize(md3dDevice);
	mFrameConstantBuffer.Initialize(md3dDevice);
	return true;
}
开发者ID:neropsys,项目名称:D3D11CodeSet,代码行数:15,代码来源:LightingDemo.cpp

示例5: TexturePtr

void ParticleSystemEffectBinder::Init(DeviceDependableFactory * factory)
{
	colorTexture = TexturePtr(true);
	dataBuffer = factory->CreateConstantBuffer();
	ConstantBuffer * b = dataBuffer.Get();

	b->InitBuffer(sizeof(ParticleGPUData) * MAX_PARTICLES_IN_SYSTEM);

	cameraVectorsBuffer = factory->CreateConstantBuffer();
	b = cameraVectorsBuffer.Get();

	b->InitBuffer(sizeof(CameraVectorsChunck));
	camVectorsChunck.padding1 = 0;
	camVectorsChunck.padding2 = 0;

}
开发者ID:dgi09,项目名称:3DRenderingEngine,代码行数:16,代码来源:ParticleSystemEffectBinder.cpp

示例6:

void	ComputeShader::SetConstantBuffer( int _BufferSlot, ConstantBuffer& _Buffer )
{
	if ( !Lock() )
		return;	// Someone else is locking it !

	ID3D11Buffer*	pBuffer = _Buffer.GetBuffer();
	m_Device.DXContext().CSSetConstantBuffers( _BufferSlot, 1, &pBuffer );

	Unlock();
}
开发者ID:,项目名称:,代码行数:10,代码来源:

示例7: Init

void AnimatedEntity::Init(ModelHandler model,SkeletonHandler skeleton,ResourceManager * resMgr, DeviceDependableFactory * factory)
{
	EntityBase::Init(model,resMgr, factory);

	this->skeletonHandler = skeleton;


	palleteBuffer = factory->CreateConstantBuffer();
	ConstantBuffer * buffer = palleteBuffer.Get();
	buffer->InitBuffer(sizeof(DirectX::XMFLOAT4X4) * MAX_BONES);

	currentAnimController = nullptr;

	DirectX::XMFLOAT4X4 id;
	DirectX::XMStoreFloat4x4(&id,DirectX::XMMatrixIdentity());
	FillBindPosePallete(0,id);

	EffectMaskUtil::Bind(effectMask,SKINNING);
}
开发者ID:dgi09,项目名称:3DRenderingEngine,代码行数:19,代码来源:AnimatedEntity.cpp

示例8: BuildGeometryBuffers

bool HillsApp::Init()
{
	if(!D3DApp::Init())
		return false;

	BuildGeometryBuffers();
	BuildFX();
	BuildVertexLayout();
	BuildRasterState();
	mObjectConstantBuffer.Initialize(md3dDevice);
	return true;
}
开发者ID:neropsys,项目名称:D3D11CodeSet,代码行数:12,代码来源:HillsDemo.cpp

示例9: sizeof

void HillsApp::DrawScene()
{
	md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::LightSteelBlue));
	md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);

	md3dImmediateContext->IASetInputLayout(mInputLayout);
    md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	md3dImmediateContext->PSSetShader(mPixelShader, NULL, 0);
	md3dImmediateContext->VSSetShader(mVertexShader, NULL, 0);
 
	UINT stride = sizeof(Vertex);
    UINT offset = 0;
    md3dImmediateContext->IASetVertexBuffers(0, 1, &mVB, &stride, &offset);
	md3dImmediateContext->IASetIndexBuffer(mIB, DXGI_FORMAT_R32_UINT, 0);

	// Set constants
	
	XMMATRIX view  = XMLoadFloat4x4(&mView);
	XMMATRIX proj  = XMLoadFloat4x4(&mProj);
	XMMATRIX world = XMLoadFloat4x4(&mGridWorld);
	XMMATRIX worldViewProj = XMMatrixTranspose(world*view*proj);


	cbPerObject mPerObjectCB;


	XMStoreFloat4x4(&mPerObjectCB.mWorldViewProj, worldViewProj);
	mObjectConstantBuffer.Data = mPerObjectCB;
	mObjectConstantBuffer.ApplyChanges(md3dImmediateContext);

	auto buffer = mObjectConstantBuffer.Buffer();
	md3dImmediateContext->VSSetConstantBuffers(0, 1, &buffer);

	// Set raster state
	md3dImmediateContext->RSSetState(mRasterState);

	// Draw
	md3dImmediateContext->DrawIndexed(mGridIndexCount, 0, 0);
	HR(mSwapChain->Present(0, 0));
}
开发者ID:neropsys,项目名称:D3D11CodeSet,代码行数:40,代码来源:HillsDemo.cpp

示例10: Init

void SceneShaderData::Init(DeviceDependableFactory * factory)
{
	cameraPtr = factory->CreateConstantBuffer();
	globalAmbiantPtr = factory->CreateConstantBuffer();
	illuminationInfoPtr = factory->CreateConstantBuffer();
	directionLightsPtr = factory->CreateConstantBuffer();
	pointLightsPtr = factory->CreateConstantBuffer();

	ConstantBuffer * buffer = cameraPtr.Get();
	buffer->InitBuffer(sizeof(CameraData));

	buffer = globalAmbiantPtr.Get();
	buffer->InitBuffer(sizeof(Vector4));

	buffer = illuminationInfoPtr.Get();
	buffer->InitBuffer(sizeof(IlluminationInfo));

	buffer = directionLightsPtr.Get();
	buffer->InitBuffer(sizeof(DLData) * MAX_DIRECTIONAL_LIGHTS);

	buffer = pointLightsPtr.Get();
	buffer->InitBuffer(sizeof(PLData) * MAX_POINT_LIGHTS);
}
开发者ID:dgi09,项目名称:3DRenderingEngine,代码行数:23,代码来源:SceneShaderData.cpp

示例11: Initialize

namespace AppSettings
{
    MSAAModesSetting MSAAMode;
    FilterTypesSetting ResolveFilterType;
    FloatSetting ResolveFilterDiameter;
    FloatSetting GaussianSigma;
    FloatSetting CubicB;
    FloatSetting CubicC;
    BoolSetting UseStandardResolve;
    BoolSetting InverseLuminanceFiltering;
    BoolSetting UseExposureFiltering;
    FloatSetting ExposureFilterOffset;
    BoolSetting UseGradientMipLevel;
    BoolSetting CentroidSampling;
    BoolSetting EnableTemporalAA;
    FloatSetting TemporalAABlendFactor;
    BoolSetting UseTemporalColorWeighting;
    ClampModesSetting NeighborhoodClampMode;
    FloatSetting VarianceClipGamma;
    JitterModesSetting JitterMode;
    FloatSetting JitterScale;
    FloatSetting LowFreqWeight;
    FloatSetting HiFreqWeight;
    FloatSetting SharpeningAmount;
    DilationModesSetting DilationMode;
    FloatSetting MipBias;
    FilterTypesSetting ReprojectionFilter;
    BoolSetting UseStandardReprojection;
    ScenesSetting CurrentScene;
    DirectionSetting LightDirection;
    ColorSetting LightColor;
    BoolSetting EnableDirectLighting;
    BoolSetting EnableAmbientLighting;
    BoolSetting RenderBackground;
    BoolSetting EnableShadows;
    BoolSetting EnableNormalMaps;
    FloatSetting NormalMapIntensity;
    FloatSetting DiffuseIntensity;
    FloatSetting Roughness;
    FloatSetting SpecularIntensity;
    OrientationSetting ModelOrientation;
    FloatSetting ModelRotationSpeed;
    BoolSetting DoubleSyncInterval;
    FloatSetting ExposureScale;
    BoolSetting EnableZoom;
    FloatSetting BloomExposure;
    FloatSetting BloomMagnitude;
    FloatSetting BloomBlurSigma;
    FloatSetting ManualExposure;

    ConstantBuffer<AppSettingsCBuffer> CBuffer;

    void Initialize(ID3D11Device* device)
    {
        TwBar* tweakBar = Settings.TweakBar();

        MSAAMode.Initialize(tweakBar, "MSAAMode", "Anti Aliasing", "MSAAMode", "", MSAAModes::MSAA4x, 4, MSAAModesLabels);
        Settings.AddSetting(&MSAAMode);

        ResolveFilterType.Initialize(tweakBar, "ResolveFilterType", "Anti Aliasing", "Resolve Filter Type", "", FilterTypes::BSpline, 10, FilterTypesLabels);
        Settings.AddSetting(&ResolveFilterType);

        ResolveFilterDiameter.Initialize(tweakBar, "ResolveFilterDiameter", "Anti Aliasing", "Resolve Filter Diameter", "", 2.0000f, 0.0000f, 6.0000f, 0.0100f, ConversionMode::None, 1.0000f);
        Settings.AddSetting(&ResolveFilterDiameter);

        GaussianSigma.Initialize(tweakBar, "GaussianSigma", "Anti Aliasing", "Gaussian Sigma", "", 0.5000f, 0.0100f, 1.0000f, 0.0100f, ConversionMode::None, 1.0000f);
        Settings.AddSetting(&GaussianSigma);

        CubicB.Initialize(tweakBar, "CubicB", "Anti Aliasing", "Cubic B", "", 0.3300f, 0.0000f, 1.0000f, 0.0100f, ConversionMode::None, 1.0000f);
        Settings.AddSetting(&CubicB);

        CubicC.Initialize(tweakBar, "CubicC", "Anti Aliasing", "Cubic C", "", 0.3300f, 0.0000f, 1.0000f, 0.0100f, ConversionMode::None, 1.0000f);
        Settings.AddSetting(&CubicC);

        UseStandardResolve.Initialize(tweakBar, "UseStandardResolve", "Anti Aliasing", "Use Standard Resolve", "", false);
        Settings.AddSetting(&UseStandardResolve);

        InverseLuminanceFiltering.Initialize(tweakBar, "InverseLuminanceFiltering", "Anti Aliasing", "Inverse Luminance Filtering", "", true);
        Settings.AddSetting(&InverseLuminanceFiltering);

        UseExposureFiltering.Initialize(tweakBar, "UseExposureFiltering", "Anti Aliasing", "Use Exposure Filtering", "", true);
        Settings.AddSetting(&UseExposureFiltering);

        ExposureFilterOffset.Initialize(tweakBar, "ExposureFilterOffset", "Anti Aliasing", "Exposure Filter Offset", "", 2.0000f, -16.0000f, 16.0000f, 0.0100f, ConversionMode::None, 1.0000f);
        Settings.AddSetting(&ExposureFilterOffset);

        UseGradientMipLevel.Initialize(tweakBar, "UseGradientMipLevel", "Anti Aliasing", "Use Gradient Mip Level", "", false);
        Settings.AddSetting(&UseGradientMipLevel);

        CentroidSampling.Initialize(tweakBar, "CentroidSampling", "Anti Aliasing", "Centroid Sampling", "", true);
        Settings.AddSetting(&CentroidSampling);

        EnableTemporalAA.Initialize(tweakBar, "EnableTemporalAA", "Anti Aliasing", "Enable Temporal AA", "", true);
        Settings.AddSetting(&EnableTemporalAA);

        TemporalAABlendFactor.Initialize(tweakBar, "TemporalAABlendFactor", "Anti Aliasing", "Temporal AABlend Factor", "", 0.9000f, 0.0000f, 1.0000f, 0.0010f, ConversionMode::None, 1.0000f);
        Settings.AddSetting(&TemporalAABlendFactor);

        UseTemporalColorWeighting.Initialize(tweakBar, "UseTemporalColorWeighting", "Anti Aliasing", "Use Temporal Color Weighting", "", false);
        Settings.AddSetting(&UseTemporalColorWeighting);
//.........这里部分代码省略.........
开发者ID:TheRealMJP,项目名称:MSAAFilter,代码行数:101,代码来源:AppSettings.cpp

示例12: BuildCBFPRLights

	AEResult BuildCBFPRLights(GraphicDevice* graphicDevice, ConstantBuffer** cb)
	{
		AEAssert(graphicDevice != nullptr);
		if (graphicDevice == nullptr)
		{
			return AEResult::GraphicDeviceNull;
		}

		AEAssert(cb != nullptr);
		if (cb == nullptr)
		{
			return AEResult::NullParameter;
		}

		AEResult ret = AEResult::Ok;
		uint32_t offset = 0;

		/////////////////////////////////////////////////////
		//Create Constant Buffer _AE_CB_FPR_LightCulling
		//
		//		cbuffer _AE_CB_FPR_Lights : register(b0)
		//		{
		//			float3	_AE_CameraPos			: packoffset(c0);
		//			uint	_AE_WindowWidth			: packoffset(c0.w);
		//		};
		//

		/****************************************************************************
		*Constant Buffer: _AE_CB_HalfPixel
		****************************************************************************/
		ConstantBuffer* tempCB = new ConstantBuffer(graphicDevice, 0, AE_CB_FPR_LIGHTS_NAME);

		/**************************************
		*Add Var 1: _AE_CameraPos
		***************************************/
		ShaderCustomVariable* scv = new ShaderCustomVariable();
		scv->m_Name = AE_CB_CAMERA_POS_VAR_NAME;
		scv->m_StartOffset = offset;
		scv->m_Columns = 3;
		scv->m_Rows = 1;
		scv->m_Elements = 0;
		scv->m_IsArray = false;
		scv->m_ElementSize = sizeof(glm::vec3);
		scv->m_Offset = 0;
		scv->m_UserVariable = false;
		scv->m_Size = sizeof(glm::vec3);
		scv->m_ShaderVariableClass = ShaderVariableClass::Vector;
		scv->m_ShaderVariableType = ShaderVariableType::Float;

		ret = tempCB->AddVariable(scv);

		offset = (scv->m_StartOffset + scv->m_Offset + scv->m_Size);

		if (ret != AEResult::Ok)
		{
			DeleteMem(tempCB);

			DeleteMem(scv);

			return AEResult::ConstantBufferInitFailed;
		}

		/**************************************
		*Add Var 2: _AE_WindowWidth
		***************************************/
		scv = new ShaderCustomVariable();
		scv->m_Name = AE_CB_WINDOW_WIDTH_VAR_NAME;
		scv->m_StartOffset = offset;
		scv->m_Columns = 1;
		scv->m_Rows = 1;
		scv->m_Elements = 0;
		scv->m_IsArray = false;
		scv->m_ElementSize = sizeof(uint32_t);
		scv->m_Offset = 0;
		scv->m_UserVariable = false;
		scv->m_Size = sizeof(uint32_t);
		scv->m_ShaderVariableClass = ShaderVariableClass::Scalar;
		scv->m_ShaderVariableType = ShaderVariableType::UInt;

		ret = tempCB->AddVariable(scv);

		offset = (scv->m_StartOffset + scv->m_Offset + scv->m_Size);

		if (ret != AEResult::Ok)
		{
			DeleteMem(tempCB);

			DeleteMem(scv);

			return AEResult::ConstantBufferInitFailed;
		}

		/**************************************
		*Constant Buffer Initialize
		***************************************/

		ret = tempCB->Initialize();

		if (ret != AEResult::Ok)
		{
//.........这里部分代码省略.........
开发者ID:dtbinh,项目名称:Arenal-Engine,代码行数:101,代码来源:BuiltInMaterialsDefs.cpp

示例13: AEAssert

AEResult GameLightsUpdate::ShadowLightRenderGameObject(GameObject* gameObject, const glm::mat4& lightView, const glm::mat4& lightProj)
{
	AEAssert(gameObject != nullptr);
	if (gameObject == nullptr)
	{
		return AEResult::NullParameter;
	}

	if (gameObject->HasMeshGOC() && gameObject->HasMaterialGOCs())
	{
		Mesh* mesh = gameObject->GetMeshGOC()->GetMeshResource();

		if (mesh != nullptr)
		{
			ConstantBuffer* cb = nullptr;
			Material* mat = nullptr;
			bool hasAnimation = gameObject->HasMeshAnimationGOC();

			if (hasAnimation)
			{
				mat = m_VarianceSkinningShadowMaterial;
				ShaderProperties* vsProps = m_VarianceSkinningShadowMaterial->GetVSProps();
				cb = vsProps->GetConstantBuffer(AE_CB_WORLD_VIEW_PROJ_NAME);

				ConstantBuffer* cbBones = vsProps->GetConstantBuffer(AE_CB_BONES_NAME);
				if (cbBones != nullptr)
				{
					AnimationPlayer* player = gameObject->GetMeshAnimationGOC()->GetAnimationPlayer();
					cbBones->SetValue(AE_CB_BONE_TRANSFORMS_VAR_NAME, player->GetBoneTransforms(), sizeof(glm::mat4) * AE_MAX_BONES);
				}
			}
			else
			{
				mat = m_VarianceShadowMaterial;
				ShaderProperties* vsProps = m_VarianceShadowMaterial->GetVSProps();
				cb = vsProps->GetConstantBuffer(AE_CB_WORLD_VIEW_PROJ_NAME);
			}

			cb->SetValueT<glm::mat4>(AE_CB_WORLD_VAR_NAME, gameObject->GetWorldTransform());
			cb->SetValueT<glm::mat4>(AE_CB_VIEW_VAR_NAME, lightView);
			cb->SetValueT<glm::mat4>(AE_CB_PROJECTION_VAR_NAME, lightProj);

			AETODO("check return");
			mat->Apply();

			for (uint32_t i = 0; i < mesh->GetNumberMeshParts(); i++)
			{
				MeshPart* meshPart = mesh->GetMeshPart(i);

				m_GraphicDevice->SetVertexBuffer(meshPart->GetVertexBuffer());
				m_GraphicDevice->SetIndexBuffer(meshPart->GetIndexBuffer());

				m_GraphicDevice->SetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

				m_GraphicDevice->DrawIndexed(0, 0, meshPart->GetIndexBuffer()->GetSize());
			}

			AETODO("check return");
			mat->UnApply();
		}
	}

	for (auto goIt : *gameObject)
	{
		ShadowLightRenderGameObject(goIt.second, lightView, lightProj);
	}

	return AEResult::Ok;
}
开发者ID:dtbinh,项目名称:Arenal-Engine,代码行数:69,代码来源:GameLightsUpdate.cpp

示例14: sizeof

void LightingApp::DrawScene()
{
	md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::LightSteelBlue));
	md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);

	md3dImmediateContext->IASetInputLayout(mInputLayout);
	md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	md3dImmediateContext->PSSetShader(mPixelShader, NULL, 0);
	md3dImmediateContext->VSSetShader(mVertexShader, NULL, 0);

	UINT stride = sizeof(Vertex);
	UINT offset = 0;

	XMMATRIX view = XMLoadFloat4x4(&mView);
	XMMATRIX proj = XMLoadFloat4x4(&mProj);
	XMMATRIX viewProj = view*proj;

	// Set per frame constants.
	mFrameConstantBuffer.Data.mDirLight = mDirLight;
	mFrameConstantBuffer.Data.mPointLight = mPointLight;
	mFrameConstantBuffer.Data.mSpotLight = mSpotLight;
	mFrameConstantBuffer.Data.mEyePosW = mEyePosW;

	//
	// Draw the hills.
	//
	md3dImmediateContext->IASetVertexBuffers(0, 1, &mLandVB, &stride, &offset);
	md3dImmediateContext->IASetIndexBuffer(mLandIB, DXGI_FORMAT_R32_UINT, 0);

	// Set per object constants.
	XMMATRIX world = XMLoadFloat4x4(&mLandWorld);
	XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
	XMMATRIX worldViewProj = XMMatrixTranspose(world*view*proj);

	mObjectConstantBuffer.Data.mWorld = mLandWorld;
	XMStoreFloat4x4(&mObjectConstantBuffer.Data.mWorldInvTranspose, worldInvTranspose);
	XMStoreFloat4x4(&mObjectConstantBuffer.Data.mWorldViewProj, worldViewProj);
	mObjectConstantBuffer.Data.mMaterial = mLandMat;

	mObjectConstantBuffer.ApplyChanges(md3dImmediateContext);
	mFrameConstantBuffer.ApplyChanges(md3dImmediateContext);

	ID3D11Buffer* buffer[2] = { mObjectConstantBuffer.Buffer(), mFrameConstantBuffer.Buffer() };
	md3dImmediateContext->VSSetConstantBuffers(0, 1, &buffer[0]);
	md3dImmediateContext->PSSetConstantBuffers(0, 2, buffer);


	md3dImmediateContext->DrawIndexed(mLandIndexCount, 0, 0);

	//
	// Draw the waves.
	//
	md3dImmediateContext->IASetVertexBuffers(0, 1, &mWavesVB, &stride, &offset);
	md3dImmediateContext->IASetIndexBuffer(mWavesIB, DXGI_FORMAT_R32_UINT, 0);

	// Set per object constants.
	world = XMLoadFloat4x4(&mWavesWorld);
	worldInvTranspose = MathHelper::InverseTranspose(world);
	worldViewProj = XMMatrixTranspose(world*view*proj);

	mObjectConstantBuffer.Data.mWorld = mWavesWorld;
	XMStoreFloat4x4(&mObjectConstantBuffer.Data.mWorldInvTranspose, worldInvTranspose);
	XMStoreFloat4x4(&mObjectConstantBuffer.Data.mWorldViewProj, worldViewProj);
	mObjectConstantBuffer.Data.mMaterial = mWavesMat;

	mObjectConstantBuffer.ApplyChanges(md3dImmediateContext);
	mFrameConstantBuffer.ApplyChanges(md3dImmediateContext);

	md3dImmediateContext->VSSetConstantBuffers(0, 1, &buffer[0]);
	md3dImmediateContext->PSSetConstantBuffers(0, 2, buffer);

	md3dImmediateContext->DrawIndexed(3 * mWaves.TriangleCount(), 0, 0);


	HR(mSwapChain->Present(0, 0));
}
开发者ID:neropsys,项目名称:D3D11CodeSet,代码行数:76,代码来源:LightingDemo.cpp

示例15: BuildCBBones

	AEResult BuildCBBones(GraphicDevice* graphicDevice, ConstantBuffer** cb)
	{
		AEAssert(graphicDevice != nullptr);
		if (graphicDevice == nullptr)
		{
			return AEResult::GraphicDeviceNull;
		}

		AEAssert(cb != nullptr);
		if (cb == nullptr)
		{
			return AEResult::NullParameter;
		}

		AEResult ret = AEResult::Ok;
		uint32_t offset = 0;

		/////////////////////////////////////////////////////
		//Create Constant Buffer _AE_CB_Bones
		//
		//	cbuffer _AE_CB_Bones : register(b1)
		//	{
		//		matrix _AE_BoneTransforms[MAX_BONES] : packoffset(c0);
		//	};
		//

		/****************************************************************************
		*Constant Buffer: _AE_CB_Bones
		****************************************************************************/
		ConstantBuffer* tempCB = new ConstantBuffer(graphicDevice, 1, AE_CB_BONES_NAME);

		/**************************************
		*Add Var 1: _AE_World
		***************************************/
		ShaderCustomVariable* scv = new ShaderCustomVariable();
		scv->m_Name = AE_CB_BONE_TRANSFORMS_VAR_NAME;
		scv->m_StartOffset = offset;
		scv->m_Columns = 4;
		scv->m_Rows = 4;
		scv->m_Elements = AE_MAX_BONES;
		scv->m_IsArray = true;
		scv->m_ElementSize = sizeof(glm::mat4);
		scv->m_Offset = 0;
		scv->m_UserVariable = false;
		scv->m_Size = sizeof(glm::mat4) * AE_MAX_BONES;
		scv->m_ShaderVariableClass = ShaderVariableClass::Matrix;
		scv->m_ShaderVariableType = ShaderVariableType::Float;

		ret = tempCB->AddVariable(scv);

		offset = (scv->m_StartOffset + scv->m_Offset + scv->m_Size);

		if (ret != AEResult::Ok)
		{
			DeleteMem(tempCB);

			DeleteMem(scv);

			return AEResult::ConstantBufferInitFailed;
		}

		/**************************************
		*Constant Buffer Initialize
		***************************************/

		ret = tempCB->Initialize();

		if (ret != AEResult::Ok)
		{
			DeleteMem(cb);

			return AEResult::ConstantBufferInitFailed;
		}

		/**************************************
		*Constant Buffer Finish
		***************************************/
		*cb = tempCB;

		return AEResult::Ok;
	}
开发者ID:dtbinh,项目名称:Arenal-Engine,代码行数:81,代码来源:BuiltInMaterialsDefs.cpp


注:本文中的ConstantBuffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。