Skip to content

Commit 9aa85b9

Browse files
committed
Do not use scaled texture for convex hull points
1 parent df85658 commit 9aa85b9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/renderedtarget.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ void RenderedTarget::setEngine(IEngine *newEngine)
214214
m_skin = nullptr;
215215
m_texture = Texture();
216216
m_oldTexture = Texture();
217+
m_cpuTexture = Texture();
217218
m_convexHullDirty = true;
218219
clearGraphicEffects();
219220
m_hullPoints.clear();
@@ -547,6 +548,9 @@ const std::vector<QPoint> &RenderedTarget::hullPoints() const
547548

548549
bool RenderedTarget::contains(const QPointF &point) const
549550
{
551+
if (!m_costume || !m_texture.isValid() || !m_cpuTexture.isValid())
552+
return false;
553+
550554
if (m_stageModel)
551555
return true; // the stage contains any point within the scene
552556

@@ -555,7 +559,8 @@ bool RenderedTarget::contains(const QPointF &point) const
555559

556560
const std::vector<QPoint> &points = hullPoints();
557561

558-
QPoint intPoint = point.toPoint();
562+
const double scaleRatio = m_skin->getTextureScale(m_texture) / m_skin->getTextureScale(m_cpuTexture);
563+
QPoint intPoint = (point / scaleRatio).toPoint();
559564
auto it = std::lower_bound(points.begin(), points.end(), intPoint, [](const QPointF &lhs, const QPointF &rhs) { return (lhs.y() < rhs.y()) || (lhs.y() == rhs.y() && lhs.x() < rhs.x()); });
560565

561566
if (it == points.end()) {
@@ -638,14 +643,15 @@ void RenderedTarget::calculateRotation()
638643
void RenderedTarget::calculateSize()
639644
{
640645
if (m_skin && m_costume) {
641-
GLuint oldTexture = m_texture.handle();
642-
bool wasValid = m_texture.isValid();
646+
GLuint oldTexture = m_cpuTexture.handle();
647+
bool wasValid = m_cpuTexture.isValid();
643648
m_texture = m_skin->getTexture(m_size * m_stageScale);
649+
m_cpuTexture = m_skin->getTexture(m_size);
644650
m_width = m_texture.width();
645651
m_height = m_texture.height();
646652
setScale(m_size * m_stageScale / m_skin->getTextureScale(m_texture) / m_costume->bitmapResolution());
647653

648-
if (wasValid && m_texture.handle() != oldTexture)
654+
if (wasValid && m_cpuTexture.handle() != oldTexture)
649655
m_convexHullDirty = true;
650656
}
651657
}
@@ -677,7 +683,7 @@ void RenderedTarget::updateHullPoints()
677683
return;
678684
}
679685

680-
m_hullPoints = textureManager()->getTextureConvexHullPoints(m_texture);
686+
m_hullPoints = textureManager()->getTextureConvexHullPoints(m_cpuTexture);
681687
// TODO: Apply graphic effects (#117)
682688
}
683689

src/renderedtarget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class RenderedTarget : public IRenderedTarget
129129
Skin *m_skin = nullptr;
130130
Texture m_texture;
131131
Texture m_oldTexture;
132+
Texture m_cpuTexture; // without stage scale
132133
std::shared_ptr<CpuTextureManager> m_textureManager; // NOTE: Use textureManager()!
133134
std::unique_ptr<QOpenGLFunctions> m_glF;
134135
std::unordered_map<ShaderManager::Effect, double> m_graphicEffects;

0 commit comments

Comments
 (0)