Skip to content

Commit 125bb06

Browse files
committed
RenderedTarget: Use CpuTextureManager::getPointColor() to get color
1 parent 449d736 commit 125bb06

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/renderedtarget.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -636,11 +636,7 @@ QRgb RenderedTarget::colorAtScratchPoint(double x, double y) const
636636
if ((x < 0 || x >= width) || (y < 0 || y >= height))
637637
return qRgba(0, 0, 0, 0);
638638

639-
GLubyte *data = textureManager()->getTextureData(m_cpuTexture);
640-
const int index = (y * width + x) * 4; // RGBA channels
641-
Q_ASSERT(index >= 0 && index < width * height * 4);
642-
// TODO: Apply graphic effects (#117)
643-
return qRgba(data[index], data[index + 1], data[index + 2], data[index + 3]);
639+
return textureManager()->getPointColor(m_cpuTexture, x, y, m_graphicEffects);
644640
}
645641

646642
bool RenderedTarget::touchingClones(const std::vector<libscratchcpp::Sprite *> &clones) const

test/renderedtarget/renderedtarget_test.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,15 @@ TEST_F(RenderedTargetTest, CpuRendering)
459459
ASSERT_EQ(target.colorAtScratchPoint(-225, 162), 4286611456); // [3, 3]
460460
ASSERT_EQ(target.colorAtScratchPoint(-224.7, 161.5), 4286611456); // [3.3, 3.5]
461461

462+
target.setGraphicEffect(ShaderManager::Effect::Color, 50);
463+
ASSERT_EQ(target.colorAtScratchPoint(-227, 162), 4286595072); // [1, 3]
464+
ASSERT_EQ(target.colorAtScratchPoint(-226, 162), 4294934720); // [2, 3]
465+
ASSERT_EQ(target.colorAtScratchPoint(-225, 162), 4278222912); // [3, 3]
466+
ASSERT_EQ(target.colorAtScratchPoint(-224.7, 161.5), 4278222912); // [3.3, 3.5]
467+
target.setGraphicEffect(ShaderManager::Effect::Color, 0);
468+
469+
// TODO: Test point transform (graphic effects that change shape)
470+
462471
// Cleanup
463472
context.doneCurrent();
464473
}

0 commit comments

Comments
 (0)