Beispiel #1
0
//==============================================================================
//
//------------------------------------------------------------------------------
void Sprite3D::draw(const  Renderer* renderer) {
  auto pDevice = renderer->getDevice();
  auto shader = renderer->getShader();

  shader->setVtxShader(_vtxShaderID);
  auto vtxShader = shader->getNowVtxShader();

  UINT nSamplerIndex = shader->getNowPixShader()->_constTable->GetSamplerIndex("TexSamp0");
  if(UINT_MAX != nSamplerIndex) {
    pDevice->SetTexture(nSamplerIndex,renderer->getTexture()->getTexture(_textureID));
  }

  // 色
  vtxShader->_constTable->SetFloatArray(pDevice,"gMaterial",_color,4);

  Matrix norMtx;
  D3DXMatrixInverse(&norMtx,nullptr,&getWorldMtx());
  D3DXMatrixTranspose(&norMtx,&norMtx);
  vtxShader->_constTable->SetMatrix(pDevice,"gNorWorld",&norMtx);

  Matrix wvp = getWorldMtx() * renderer->getCamera()->getViewMtx() * renderer->getProjMtx();
  vtxShader->_constTable->SetMatrix(pDevice,"gWorld",&getWorldMtx());
  vtxShader->_constTable->SetMatrix(pDevice,"gWVP",&wvp);

  // デクラレーション設定
  pDevice->SetVertexDeclaration(_p3DDec);

  // 頂点送信
  pDevice->SetStreamSource(0,_vtxBuff,0,sizeof(VERTEX_3D));

  // 描画
  pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
}
void RenderSystem::DrawIndexedPrimitive(sVertexBuffer& vb, int offestVertex, int nVertex, sIndexBuffer& ib, int offsetPolygon, int nPolygon)
{
	SetVertexDeclaration(vb);
	SetIndices(ib);
	SetStreamSource(vb);
	HRESULT hr = lpD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,offestVertex,nVertex,3*offsetPolygon,nPolygon);
	assert(hr== D3D_OK);
}
Beispiel #3
0
void TerrainBorderRenderable::Render(HippoD3d9Device* pdevice, unsigned int escapeTime)
{
	auto device = Globals::GetDevice()->GetDeviceD3D9();

	RS_HELP_OBJ(device, D3DRS_ALPHABLENDENABLE, TRUE);
	RS_HELP_OBJ(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	RS_HELP_OBJ(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	//RS_HELP_OBJ(device, D3DRS_ZWRITEENABLE, false);
	RS_HELP_OBJ(device, D3DRS_CULLMODE, D3DCULL_CCW);

	D3DXMATRIX matrix;
	D3DXMatrixIdentity(&matrix);
	HRESULT v = m_fxhandle->SetMatrix("g_mWorld", &matrix);

	//wvp matrix
	auto proj = Globals::GetRender()->GetProjMatrix();
	auto view = Globals::GetRender()->GetViewMatrix();
	D3DXMATRIX vp = (*view)*(*proj);
	v = m_fxhandle->SetMatrix("g_mViewProjection", &vp);

	//time
	float time = GetTickCount()*0.001f;
	v = m_fxhandle->SetValue("g_fTime", &time, sizeof(float));

	//viewmatrix
	const D3DXVECTOR3* camPos = Globals::GetCurrentCamera()->GetPos();
	v = m_fxhandle->SetMatrix("ViewMatrix", view);
	v = m_fxhandle->SetValue("g_camerapos", camPos, sizeof(D3DXVECTOR3));

	//texture
	v = m_fxhandle->SetTexture("g_MeshTexture", m_pTextrue.get());

	//threshold
	D3DXVECTOR4 threshold = D3DXVECTOR4(800.f, 0.99f, 0, 0);
	v = m_fxhandle->SetValue("threshold", &threshold, sizeof(D3DXVECTOR4));

	device->SetStreamSource(0, m_pVB.get(), 0, sizeof(TerrainVertex));
	device->SetVertexDeclaration(m_pVertexDecl.get());
	device->SetIndices(m_pIB.get());

	UINT iPass, totalPasses;
	m_fxhandle->Begin(&totalPasses, 0);
	m_fxhandle->BeginPass(0);

	device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
		0,   // 将要绘制的索引缓冲区的起始地址
		0, // 索引数组中最小的索引值
		16,   // 要绘制的索引数组中的顶点数量
		0, // 从索引数组中的第几个元素开始绘制图元
		8); // 绘制的图元数量

	m_fxhandle->EndPass();
	m_fxhandle->End();
}
Beispiel #4
0
void Arrow::draw() {
	auto device = ShaderDevise::device();

	device->SetTransform(D3DTS_WORLD, &world);
	device->SetFVF(D3DFVF_CUSTOMVERTEX);
	device->SetRenderState(D3DRS_LIGHTING, false);
	device->SetStreamSource(0, vbuf, 0, sizeof(CUSTOMVERTEX));
	device->DrawPrimitive(D3DPT_LINELIST, 0, 2);
	device->SetRenderState(D3DRS_LIGHTING, true);

}
Beispiel #5
0
static GLboolean _gld_mesa_render_stage_run(
	struct gl_context *ctx,
	struct tnl_pipeline_stage *stage)
{
	GLD_context				*gldCtx	= GLD_GET_CONTEXT(ctx);
	GLD_driver_dx9			*gld	= GLD_GET_DX9_DRIVER(gldCtx);
		
	TNLcontext				*tnl = TNL_CONTEXT(ctx);
	struct vertex_buffer	*VB = &tnl->vb;
	tnl_render_func				*tab;
	GLint					pass = 0;
	GLD_pb_dx9				*gldPB;

	/* Allow the drivers to lock before projected verts are built so
    * that window coordinates are guarenteed not to change before
    * rendering.
    */
	ASSERT(tnl->Driver.Render.Start);
	
	tnl->Driver.Render.Start( ctx );
	
	// NOTE: Setting D3DRS_SOFTWAREVERTEXPROCESSING for a mixed-mode device resets
	//       stream, indices and shader to default values of NULL or 0.
/*	if ((ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE) &&
		gld->VStwosidelight.hShader &&
		!ctx->Fog.Enabled)
	{
		IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, !gld->VStwosidelight.bHardware);
		_GLD_DX9_DEV(SetVertexShader(gld->pDev, gld->VStwosidelight.hShader));
		gldPB = &gld->PBtwosidelight;
		tnl->Driver.Render.Points	= gld_Points2DTwoside_DX9;
		if (ctx->_TriangleCaps & DD_FLATSHADE) {
			tnl->Driver.Render.Line		= gld_Line2DFlatTwoside_DX9;
			tnl->Driver.Render.Triangle	= gld_Triangle2DFlatTwoside_DX9;
			tnl->Driver.Render.Quad		= gld_Quad2DFlatTwoside_DX9;
		} else {
			tnl->Driver.Render.Line		= gld_Line2DSmoothTwoside_DX9;
			tnl->Driver.Render.Triangle	= gld_Triangle2DSmoothTwoside_DX9;
			tnl->Driver.Render.Quad		= gld_Quad2DSmoothTwoside_DX9;
		}
	} else {*/
//		IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, TRUE);
		IDirect3DDevice9_SetSoftwareVertexProcessing(gld->pDev, TRUE);
		gldPB = &gld->PB2d;
		_GLD_DX9_DEV(SetVertexShader(gld->pDev, NULL));
		_GLD_DX9_DEV(SetFVF(gld->pDev, gldPB->dwFVF));
		tnl->Driver.Render.Points	= _gldSetupPoints[gld->iSetupFunc];
		tnl->Driver.Render.Line		= _gldSetupLine[gld->iSetupFunc];
		tnl->Driver.Render.Triangle	= _gldSetupTriangle[gld->iSetupFunc];
		tnl->Driver.Render.Quad		= _gldSetupQuad[gld->iSetupFunc];
//	}

	_GLD_DX9_VB(Lock(gldPB->pVB, 0, 0, &gldPB->pPoints, D3DLOCK_DISCARD));
	gldPB->nPoints = gldPB->nLines = gldPB->nTriangles = 0;
	// Allocate primitive pointers
	// gldPB->pPoints is always first
	gldPB->pLines		= gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstLine);
	gldPB->pTriangles	= gldPB->pPoints + (gldPB->dwStride * gldPB->iFirstTriangle);

	ASSERT(tnl->Driver.Render.BuildVertices);
	ASSERT(tnl->Driver.Render.PrimitiveNotify);
	ASSERT(tnl->Driver.Render.Points);
	ASSERT(tnl->Driver.Render.Line);
	ASSERT(tnl->Driver.Render.Triangle);
	ASSERT(tnl->Driver.Render.Quad);
	ASSERT(tnl->Driver.Render.ResetLineStipple);
	ASSERT(tnl->Driver.Render.Interp);
	ASSERT(tnl->Driver.Render.CopyPV);
	ASSERT(tnl->Driver.Render.ClippedLine);
	ASSERT(tnl->Driver.Render.ClippedPolygon);
	ASSERT(tnl->Driver.Render.Finish);
	
	tnl->Driver.Render.BuildVertices( ctx, 0, VB->Count, ~0 );
	
	if (VB->ClipOrMask) {
		tab = VB->Elts ? clip_render_tab_elts : clip_render_tab_verts;
		clip_render_tab_elts[GL_TRIANGLES] = clip_elt_triangles;
	}
	else {
		tab = (VB->Elts ? 
			tnl->Driver.Render.PrimTabElts : 
		tnl->Driver.Render.PrimTabVerts);
	}
	
	do {
		GLuint i, length, flags = 0;
		for (i = 0 ; !(flags & PRIM_END) ; i += length) {
			flags = VB->Primitive[i].mode;
			length= VB->Primitive[i].count;
			ASSERT(length || (flags & PRIM_END));
			ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1);
			if (length)
				tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags );
		}
	} while (tnl->Driver.Render.Multipass &&
		tnl->Driver.Render.Multipass( ctx, ++pass ));
	
	
//	tnl->Driver.Render.Finish( ctx );
	
	_GLD_DX9_VB(Unlock(gldPB->pVB));

	_GLD_DX9_DEV(SetStreamSource(gld->pDev, 0, gldPB->pVB, 0, gldPB->dwStride));

	if (gldPB->nPoints) {
		_GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_POINTLIST, 0, gldPB->nPoints));
		gldPB->nPoints = 0;
	}

	if (gldPB->nLines) {
		_GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_LINELIST, gldPB->iFirstLine, gldPB->nLines));
		gldPB->nLines = 0;
	}

	if (gldPB->nTriangles) {
		_GLD_DX9_DEV(DrawPrimitive(gld->pDev, D3DPT_TRIANGLELIST, gldPB->iFirstTriangle, gldPB->nTriangles));
		gldPB->nTriangles = 0;
	}

	return GL_FALSE;		/* finished the pipe */
}
Beispiel #6
0
void TerrainRenderablePlane::Render(HippoD3d9Device* pdevice, unsigned int escapeTime)
{
	auto d3d9device = pdevice->GetDeviceD3D9();

	//d3d9device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
	//world matrix
	D3DXMATRIX tmpMatrix;
	D3DXMatrixMultiply(&tmpMatrix, &m_local_matrix, m_parent->GetWorldTransform());
	HRESULT v = m_fxhandle->SetMatrix("g_mWorld", &tmpMatrix);

	//wvp matrix
	auto proj = Globals::GetRender()->GetProjMatrix();
	auto view = Globals::GetRender()->GetViewMatrix();
	D3DXMATRIX vp = (*view)*(*proj);
	v = m_fxhandle->SetMatrix("g_mViewProjection", &vp);

	//camera
	const D3DXVECTOR3* pos = Globals::GetCurrentCamera()->GetPos();
	v = m_fxhandle->SetValue("g_camera_pos", pos, sizeof(D3DXVECTOR3));

	//material
	D3DXCOLOR vWhite = D3DXCOLOR(0.5, 0.3, 0.2, 1);
	v = m_fxhandle->SetValue("g_MaterialDiffuseColor", &vWhite, sizeof(D3DXCOLOR));

	//texture
	v = m_fxhandle->SetTexture("g_MeshTexture", m_pTextrue[0]);

	//tower info
	auto alltowers = Globals::GetWorld()->GetAllTower();
	auto itr = alltowers.begin();
	D3DXVECTOR4 tmp[2];
	int idx = 0;
	while (itr != alltowers.end())
	{
		TowerEntity* pEntity = (TowerEntity*)((*itr).get());
		D3DXVECTOR3* pos = pEntity->GetPos();
		float r = pEntity->GetRange();
		tmp[idx] = D3DXVECTOR4(pos->x, pos->y, pos->z, r);
		++itr;
		++idx;
	}
	v = m_fxhandle->SetVectorArray("towerInfo", tmp, 2);

	//robot info
	auto player = Globals::GetWorld()->GetPlayer();
	pos = player->GetPos();
	D3DXVECTOR4 robotpos = D3DXVECTOR4(pos->x, pos->z, 12.f, 1.0f);
	v = m_fxhandle->SetVector("robotInfo", &robotpos);


	d3d9device->SetStreamSource(0, m_pVB, 0, sizeof(TerrainVertex));
	d3d9device->SetVertexDeclaration(m_pVertexDecl);
	d3d9device->SetIndices(m_pIB);	UINT iPass, totalPasses;
	m_fxhandle->Begin(&totalPasses, 0);

	for (iPass = 0; iPass < totalPasses; iPass++)
	{
		m_fxhandle->BeginPass(iPass);

		d3d9device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
			0,   // 将要绘制的索引缓冲区的起始地址
			0, // 索引数组中最小的索引值
			GetVertexNum(),   // 要绘制的索引数组中的顶点数量
			0, // 从索引数组中的第几个元素开始绘制图元
			GetTriangleNum()); // 绘制的图元数量

		m_fxhandle->EndPass();
	}

	m_fxhandle->End();

	m_border_renderable->Render(pdevice, escapeTime);
}
Beispiel #7
0
void TerrainRenderable::Render(HippoD3d9Device* pdevice, unsigned int escapeTime)
{
	auto d3d9device = pdevice->GetDeviceD3D9();

	//*d3d9device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);*/
	//world matrix
	D3DXMATRIX tmpMatrix;
	D3DXMatrixMultiply(&tmpMatrix, &m_local_matrix, m_parent->GetWorldTransform());
	HRESULT v = m_fxhandle->SetMatrix("g_mWorld", &tmpMatrix);

	//wvp matrix
	auto proj = Globals::GetRender()->GetProjMatrix();
	auto view = Globals::GetRender()->GetViewMatrix();
	D3DXMATRIX vp = (*view)*(*proj);
	v = m_fxhandle->SetMatrix("g_mViewProjection", &vp);

	//camera
	const D3DXVECTOR3* pos=Globals::GetCurrentCamera()->GetPos();
	v = m_fxhandle->SetValue("g_camera_pos", pos, sizeof(D3DXVECTOR3));


	//texture
	v = m_fxhandle->SetTexture("g_DiffuseTex", m_pTextrue[0]);
	v = m_fxhandle->SetTexture("g_DetailTex", m_pTextrue[1]);
	v = m_fxhandle->SetTexture("g_NormalTex", m_pTextrue[2]);

	//tower info
	const GameEntityPtrCon& con = Globals::GetWorld()->GetAllTower();
	GameEntityPtrCon::const_iterator itr = con.begin();
	GameEntityPtrCon::const_iterator itrend = con.end();
	D3DXVECTOR4 tmp[2];
	int idx = 0;
	while (itr != itrend)
	{
		auto towerptr = (TowerEntity*)itr->get();
		D3DXVECTOR3* pos = towerptr->GetPos();
		float r = towerptr->GetRange();
		tmp[idx] = D3DXVECTOR4(pos->x, pos->y, pos->z, r);
		++itr;
		++idx;
	}
	v=m_fxhandle->SetVectorArray("towerInfo", tmp, 2);

	//robot info
	auto robot=Globals::GetWorld()->GetPlayer();
	D3DXVECTOR4 robotpos = D3DXVECTOR4(robot->GetPos()->x, robot->GetPos()->z, 2, 1);
	v=m_fxhandle->SetVector("robotInfo", &robotpos);

	d3d9device->SetStreamSource(0, m_pVB, 0, sizeof(TerrainVertex));
	d3d9device->SetVertexDeclaration(m_pVertexDecl);
	d3d9device->SetIndices(m_pIB);	UINT iPass, totalPasses;
	m_fxhandle->Begin(&totalPasses, 0);

	for (iPass = 0; iPass < totalPasses; iPass++)
	{
		m_fxhandle->BeginPass(iPass);
		//d3d9device->DrawPrimitive(D3DPT_POINTLIST,
		//	0,   // 将要绘制的索引缓冲区的起始地址
		//	GetVertexNum()); // 绘制的图元数量

		d3d9device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
			0,   // 将要绘制的索引缓冲区的起始地址
			0, // 索引数组中最小的索引值
			GetVertexNum(),   // 要绘制的索引数组中的顶点数量
			0, // 从索引数组中的第几个元素开始绘制图元
			GetTriangleNum()); // 绘制的图元数量
		
		m_fxhandle->EndPass();
	}

	m_fxhandle->End();
	return;
	//patch
	auto pthitr = m_all_patch.begin();
	while (pthitr != m_all_patch.end())
	{
		auto patch_fx =  (*pthitr)->GetPatchFx();
		auto patch_ib = (*pthitr)->GetIB();
		int tri_count = (*pthitr)->GetIndexCount() / 3;
		d3d9device->SetStreamSource(0, m_pVB, 0, sizeof(TerrainVertex));
		d3d9device->SetVertexDeclaration(m_pVertexDecl);

		HRESULT v = d3d9device->SetIndices(patch_ib);
		
		v=patch_fx->SetMatrix("g_mWorld", &tmpMatrix);
		v = patch_fx->SetMatrix("g_mViewProjection", &vp);
		v = patch_fx->SetValue("g_camera_pos", pos, sizeof(D3DXVECTOR3));
		
		
		UINT totalPasses;
		v=patch_fx->Begin(&totalPasses, 0);
		v = patch_fx->BeginPass(0);
		v = d3d9device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
			0,   // 将要绘制的索引缓冲区的起始地址
			0, // 索引数组中最小的索引值
			GetVertexNum(),   // 要绘制的索引数组中的顶点数量
			0, // 从索引数组中的第几个元素开始绘制图元
			tri_count); // 绘制的图元数量
		v = patch_fx->EndPass();

		++pthitr;
	}
}
Beispiel #8
0
DataStream_Pipe::~DataStream_Pipe()
{
	SetStreamSource(NULL);
}