Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/graphics/Canvas2D.cpp
Show First 20 Lines • Show All 325 Lines • ▼ Show 20 Lines | void CCanvas2D::DrawRect(const CRect& rect, const CColor& color) | ||||
m->BindTechIfNeeded(); | m->BindTechIfNeeded(); | ||||
DrawTextureImpl( | DrawTextureImpl( | ||||
m->DeviceCommandContext, | m->DeviceCommandContext, | ||||
g_Renderer.GetTextureManager().GetTransparentTexture(), | g_Renderer.GetTextureManager().GetTransparentTexture(), | ||||
vertices, uvs, CColor(0.0f, 0.0f, 0.0f, 0.0f), color, 0.0f, | vertices, uvs, CColor(0.0f, 0.0f, 0.0f, 0.0f), color, 0.0f, | ||||
m->BindingSlots); | m->BindingSlots); | ||||
} | } | ||||
void CCanvas2D::DrawTexture(CTexturePtr texture, const CRect& destination) | void CCanvas2D::DrawTexture(const CTexturePtr& texture, const CRect& destination) | ||||
{ | { | ||||
DrawTexture(texture, | DrawTexture(texture, | ||||
destination, CRect(0, 0, texture->GetWidth(), texture->GetHeight()), | destination, CRect(0, 0, texture->GetWidth(), texture->GetHeight()), | ||||
CColor(1.0f, 1.0f, 1.0f, 1.0f), CColor(0.0f, 0.0f, 0.0f, 0.0f), 0.0f); | CColor(1.0f, 1.0f, 1.0f, 1.0f), CColor(0.0f, 0.0f, 0.0f, 0.0f), 0.0f); | ||||
} | } | ||||
void CCanvas2D::DrawTexture( | void CCanvas2D::DrawTexture( | ||||
CTexturePtr texture, const CRect& destination, const CRect& source, | const CTexturePtr& texture, const CRect& destination, const CRect& source, | ||||
const CColor& multiply, const CColor& add, const float grayscaleFactor) | const CColor& multiply, const CColor& add, const float grayscaleFactor) | ||||
{ | { | ||||
const PlaneArray2D uvs = | const PlaneArray2D uvs = | ||||
{ | { | ||||
source.left, source.bottom, | source.left, source.bottom, | ||||
source.right, source.bottom, | source.right, source.bottom, | ||||
source.right, source.top, | source.right, source.top, | ||||
source.left, source.bottom, | source.left, source.bottom, | ||||
Show All 11 Lines | void CCanvas2D::DrawTexture( | ||||
}; | }; | ||||
m->BindTechIfNeeded(); | m->BindTechIfNeeded(); | ||||
DrawTextureImpl( | DrawTextureImpl( | ||||
m->DeviceCommandContext, texture, vertices, uvs, | m->DeviceCommandContext, texture, vertices, uvs, | ||||
multiply, add, grayscaleFactor, m->BindingSlots); | multiply, add, grayscaleFactor, m->BindingSlots); | ||||
} | } | ||||
void CCanvas2D::DrawRotatedTexture( | |||||
const CTexturePtr& texture, const CRect& destination, const CRect& source, | |||||
const CColor& multiply, const CColor& add, const float grayscaleFactor, | |||||
const CVector2D& origin, const float angle) | |||||
{ | |||||
const PlaneArray2D uvs = | |||||
{ | |||||
source.left, source.bottom, | |||||
source.right, source.bottom, | |||||
source.right, source.top, | |||||
source.left, source.bottom, | |||||
source.right, source.top, | |||||
source.left, source.top | |||||
}; | |||||
std::array<CVector2D, 6> corners = | |||||
{ | |||||
destination.BottomLeft(), | |||||
destination.BottomRight(), | |||||
destination.TopRight(), | |||||
destination.BottomLeft(), | |||||
destination.TopRight(), | |||||
destination.TopLeft() | |||||
}; | |||||
PlaneArray2D vertices; | |||||
static_assert(vertices.size() == corners.size() * 2, "We need two coordinates from each corner."); | |||||
auto it = vertices.begin(); | |||||
for (const CVector2D& corner : corners) | |||||
{ | |||||
const CVector2D vertex = origin + (corner - origin).Rotated(angle); | |||||
*it++ = vertex.X; | |||||
*it++ = vertex.Y; | |||||
} | |||||
m->BindTechIfNeeded(); | |||||
DrawTextureImpl( | |||||
m->DeviceCommandContext, texture, vertices, uvs, | |||||
multiply, add, grayscaleFactor, m->BindingSlots); | |||||
} | |||||
void CCanvas2D::DrawText(CTextRenderer& textRenderer) | void CCanvas2D::DrawText(CTextRenderer& textRenderer) | ||||
{ | { | ||||
m->BindTechIfNeeded(); | m->BindTechIfNeeded(); | ||||
m->DeviceCommandContext->SetUniform( | m->DeviceCommandContext->SetUniform( | ||||
m->BindingSlots.grayscaleFactor, 0.0f); | m->BindingSlots.grayscaleFactor, 0.0f); | ||||
textRenderer.Render(m->DeviceCommandContext, m->Tech->GetShader(), GetDefaultGuiMatrix()); | textRenderer.Render(m->DeviceCommandContext, m->Tech->GetShader(), GetDefaultGuiMatrix()); | ||||
} | } | ||||
void CCanvas2D::Flush() | void CCanvas2D::Flush() | ||||
{ | { | ||||
m->UnbindTech(); | m->UnbindTech(); | ||||
} | } |
Wildfire Games · Phabricator