Example #1
0
bool D3D9Sprite::DrawShapedFast(const Vector2 &v2Pos, const Vector2 &v2Size, const Color& color)
{
	if (v2Size == Vector2(0,0))
	{
		return true;
	}

	Video* video = m_video.lock().get();
	ShaderPtr pCurrentVS = video->GetVertexShader();

	// rounds up the final position to avoid alpha distortion
	Vector2 v2FinalPos;
	if (video->IsRoundingUpPosition())
	{
		v2FinalPos.x = floor(v2Pos.x);
		v2FinalPos.y = floor(v2Pos.y);
	}
	else
	{
		v2FinalPos = v2Pos;
	}

	// subtract 0.5 to align pixel-texel
	v2FinalPos -= math::constant::HALF_VECTOR2;

	pCurrentVS->SetConstant(L"size", v2Size);
	pCurrentVS->SetConstant(L"entityPos", v2FinalPos);
	pCurrentVS->SetConstant(L"color0", color);

	if (m_rect.size.x == 0 || m_rect.size.y == 0)
	{
		pCurrentVS->SetConstant(L"rectSize", GetBitmapSizeF());
		pCurrentVS->SetConstant(L"rectPos", 0, 0);
	}
	else
	{
		pCurrentVS->SetConstant(L"rectSize", m_rect.size);
		pCurrentVS->SetConstant(L"rectPos", m_rect.pos);
	}

	pCurrentVS->SetShader();

	// draw the one-pixel-quad applying the vertex shader
	m_pVideoInfo->DrawSpriteFast(m_pDevice, m_rectMode);

	return true;
}
Example #2
0
void D3D9Sprite::BeginFastRendering()
{
	Video* video = m_video.lock().get();
	video->SetVertexShader(video->GetFontShader());
	ShaderPtr pCurrentVS = video->GetVertexShader();
	pCurrentVS->SetConstant(L"bitmapSize", GetBitmapSizeF());

	// apply textures according to the rendering mode (pixel shaded or not)
	ShaderPtr pCurrentPS = video->GetPixelShader();
	if (!pCurrentPS)
	{
		m_pDevice->SetTexture(0, m_pTexture);
		//for (unsigned int t=1; t<GS_TEXTURE_CHANNELS; t++)
		//	pDevice->SetTexture(t, NULL);
	}
	else
	{
		pCurrentPS->SetShader();
		pCurrentPS->SetTexture(L"diffuse", GetTexture());
	}
	m_pVideoInfo->BeginFastDraw(m_pDevice, m_rectMode);
}
Example #3
0
bool D3D9Sprite::DrawShaped(
	const Vector2& v2Pos,
	const Vector2& v2Size,
	const Color& color0,
	const Color& color1,
	const Color& color2,
	const Color& color3,
	const float angle)
{
	if (v2Size == Vector2(0,0))
	{
		return true;
	}

	// do the flip (parameters that will be send to the VS)
	Vector2 flipMul(1,1), flipAdd(0,0);
	if (m_flipX)
	{
		flipMul.x =-1;
		flipAdd.x = 1;
	}
	if (m_flipY)
	{
		flipMul.y =-1;
		flipAdd.y = 1;
	}

	// centralizes the sprite according to the origin
	Vector2 v2Center = m_normalizedOrigin*v2Size;

	Video* video = m_video.lock().get();
	ShaderPtr pCurrentVS = video->GetVertexShader();

	Matrix4x4 mRot;
	if (angle != 0.0f)
		mRot = RotateZ(DegreeToRadian(angle));
	pCurrentVS->SetMatrixConstant(L"rotationMatrix", mRot);

	// rounds up the final position to avoid alpha distortion
	Vector2 v2FinalPos;
	if (video->IsRoundingUpPosition())
	{
		v2FinalPos.x = floor(v2Pos.x);
		v2FinalPos.y = floor(v2Pos.y);
	}
	else
	{
		v2FinalPos = v2Pos;
	}

	// subtract 0.5 to align pixel-texel
	v2FinalPos -= math::constant::HALF_VECTOR2;

	pCurrentVS->SetConstant(L"size", v2Size);
	pCurrentVS->SetConstant(L"entityPos", v2FinalPos);
	pCurrentVS->SetConstant(L"center", v2Center);
	pCurrentVS->SetConstant(L"flipMul", flipMul);
	pCurrentVS->SetConstant(L"flipAdd", flipAdd);
	pCurrentVS->SetConstant(L"bitmapSize", GetBitmapSizeF());
	pCurrentVS->SetConstant(L"scroll", GetScroll());
	pCurrentVS->SetConstant(L"multiply", GetMultiply());

	const bool setCameraPos = pCurrentVS->ConstantExist(L"cameraPos");
	if (setCameraPos)
		pCurrentVS->SetConstant(L"cameraPos", video->GetCameraPos());

	if (m_rect.size.x == 0 || m_rect.size.y == 0)
	{
		pCurrentVS->SetConstant(L"rectSize", GetBitmapSizeF());
		pCurrentVS->SetConstant(L"rectPos", 0, 0);
	}
	else
	{
		pCurrentVS->SetConstant(L"rectSize", m_rect.size);
		pCurrentVS->SetConstant(L"rectPos", m_rect.pos);
	}

	pCurrentVS->SetConstant(L"color0", color0);
	pCurrentVS->SetConstant(L"color1", color1);
	pCurrentVS->SetConstant(L"color2", color2);
	pCurrentVS->SetConstant(L"color3", color3);

	if (pCurrentVS->ConstantExist(L"depth"))
		pCurrentVS->SetConstant(L"depth", video->GetSpriteDepth());

	pCurrentVS->SetShader();

	// apply textures according to the rendering mode (pixel shaded or not)
	ShaderPtr pCurrentPS = video->GetPixelShader();
	if (!pCurrentPS)
	{
		m_pDevice->SetTexture(0, m_pTexture);
		//for (unsigned int t=1; t<GS_TEXTURE_CHANNELS; t++)
		//	pDevice->SetTexture(t, NULL);
	}
	else
	{
		pCurrentPS->SetShader();
		pCurrentPS->SetTexture(L"diffuse", GetTexture());
	}

	// draw the one-pixel-quad applying the vertex shader
	m_pVideoInfo->DrawSprite(m_pDevice, m_rectMode);

	m_pDevice->SetVertexShader(NULL);

	return true;
}