コード例 #1
0
ファイル: Controller.cpp プロジェクト: Shada/edit87
bool Controller::init(RenderDX11* _renderer, string _workingDirectory)
{
	m_terrain = new Terrain();
	HRESULT hr;
	bool res;

	if(!_renderer)					// no rendering available, go home
		return false;
	if(_workingDirectory == "")		// dont set the current environment as a working directory you bozo
		return false;

	m_pWorkingDirectory	= _workingDirectory;
	m_renderer			= _renderer;

	/*	--- Overview of how the data linking and abstraction works --- 

		Property { struct<T>[] }				--- Refs by Id (explicit) --->				Resources<T>[Id]
		Composition { Interface<Property>[] }	--- Refs by Datatype (Id is implicit) --->	Property<T>[Id]

		LLC: Create raw data
		MLL: Create 'property struct', link to desired raw data
		HLC: Create 'composition struct', link to all desired properties		(note: as of now only one property per type is allowed)
	*/

	/************************
		LOW LEVEL CREATION 
	*************************/

	/* init default render resources  */
	
	// blendstates
	unsigned int ref;
	hr = createBlendState(ref, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, TRUE);
	hr = createBlendState(ref, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, FALSE);
	hr = createBlendState(ref, D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_SRC_ALPHA, TRUE);

	D3D11_SAMPLER_DESC sampDesc;
	ZeroMemory( &sampDesc, sizeof(sampDesc));
	sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
	sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
	sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
	sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
	sampDesc.MinLOD = 0;
	sampDesc.MaxLOD = D3D11_FLOAT32_MAX;

	hr = createSamplerState(ref, sampDesc);

	sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
	sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
	sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;

	hr = createSamplerState(ref, sampDesc);

	// cbuffers
	unsigned onceRef, changeRef;
	hr = createCBuffer(onceRef, sizeof(CBOnce));
	hr = createCBuffer(changeRef, sizeof(CBOnChange));

	m_renderer->cbOnceID		= onceRef;
	m_renderer->cbOnChangeID	= changeRef;

	// shaders
	unsigned int vRef, pRef;
	hr = createShader<ID3D11VertexShader>(vRef, standardLayout, "defaultVS", "vs_4_0");
	hr = createShader<ID3D11PixelShader>(pRef, standardLayout, "defaultPS", "ps_4_0");

	// SRV's
	hr = createSRV(ref, "grass.png");
	hr = createSRV(ref, "bozo.jpg");

	/***************************
		MEDIUM LEVEL LINKING
	****************************/

	/* Init default properties */
	unsigned int sRef, mRef, tRef;
	// Shader
	Shader*			s	= new Shader(vRef, pRef);
	CModel<Shader>* cs	= new CModel<Shader>("default_shader", s);
	
	// Mesh
	createCube(vRef, pRef);	// notice reuse of paramaters
	Mesh*			m	= new Mesh(vRef, pRef, 36, ref);
	CModel<Mesh>*	cm	= new CModel<Mesh>("default_mesh", m);

	// Transform
	Transform*			t	= new Transform(elm::vec3(100,100,100), elm::vec3(0), elm::vec3(10));
	CModel<Transform>*	ct	= new CModel<Transform>("default_transform", t);

	/* register properties */
	addProperty(cs);
	addProperty(cm);
	addProperty(ct);

	/*****************************
		HIGH LEVEL COMPOSITION
	******************************/

	// Composition
	Composition* c = new Composition();
	c->setName("default_object");

	c->setProperty<Shader>(cs);
	c->setProperty<Mesh>(cm);
	c->setProperty<Transform>(ct);

	addComposition(c);

	return true;
}
コード例 #2
0
ファイル: Controller.cpp プロジェクト: Shada/edit87
bool Controller::createTerrain(int width, int height, float pointStep, bool fromPerlinMap)
{
	HRESULT hr;
	unsigned int vRef, iRef;
	vector<unsigned int> indexBuffer;
	vector<Vertex> vertexBuffer;

	m_terrain->createTerrain(width, height, pointStep, fromPerlinMap, vertexBuffer, indexBuffer);

	int w = abs(m_renderer->r.right - m_renderer->r.left);
	int h = abs(m_renderer->r.bottom - m_renderer->r.top);
	if(!m_renderer->camera)
		m_renderer->camera = new Camera(w, h, m_terrain);
	else
		m_renderer->camera->resizeWindow(w, h);

	hr = createBuffer<Vertex>(vRef, vertexBuffer, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
	if( FAILED(hr) )
		return false;

	hr = createBuffer<unsigned int>(iRef, indexBuffer, D3D11_BIND_INDEX_BUFFER, D3D11_USAGE_IMMUTABLE);
	if( FAILED(hr) )
		return false;

	/* construct mesh */
	Mesh*			m	= new Mesh(vRef, iRef, indexBuffer.size(), 0);
	CModel<Mesh>*	im	= new CModel<Mesh>("terrain_mesh", m);
	addProperty(im);

	/* construct shader */
	Shader*			s	= new Shader();
	CModel<Shader>* sm	= new CModel<Shader>("terrain_shader", s);
	addProperty(sm);

	/* construct transformation */
	Transform*			t	= new Transform();
	CModel<Transform>*	tm	= new CModel<Transform>("terrain_transform", t);
	addProperty(tm);

	/* construct composition */
	Composition* c = new Composition();
	
	c->setProperty<Mesh>(im);
	c->setProperty<Shader>(sm);
	c->setProperty<Transform>(tm);

	c->setName("terrain_object");
	addComposition(c);

	/* for fun create a mini duplicate */
	//t = new Transform(elm::vec3(200,500,200), elm::vec3(0), elm::vec3(0.25));
	t = new Transform(elm::vec3(50,100,100), elm::vec3(0), elm::vec3(0.25));
	tm	= new CModel<Transform>("terrain_transform", t);

	m	= new Mesh(vRef, iRef, indexBuffer.size(), 1);
	im	= new CModel<Mesh>("terrain_mesh", m);
	addProperty(im);

	c = new Composition();
	c->setProperty<Mesh>(im);
	c->setProperty<Shader>(sm);
	c->setProperty<Transform>(tm);
	addComposition(c);

	return true;
}