Skip to content

Commit c1db5f0

Browse files
committed
Add CPU texture getter to RenderedTarget
1 parent 9bf9f6b commit c1db5f0

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

src/irenderedtarget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class IRenderedTarget : public QNanoQuickItem
7878
virtual bool mirrorHorizontally() const = 0;
7979

8080
virtual Texture texture() const = 0;
81+
virtual const Texture &cpuTexture() const = 0;
8182
virtual int costumeWidth() const = 0;
8283
virtual int costumeHeight() const = 0;
8384

src/renderedtarget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,11 @@ Texture RenderedTarget::texture() const
529529
return m_texture;
530530
}
531531

532+
const Texture &RenderedTarget::cpuTexture() const
533+
{
534+
return m_cpuTexture;
535+
}
536+
532537
int RenderedTarget::costumeWidth() const
533538
{
534539
if (!m_skin || !m_costume)

src/renderedtarget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class RenderedTarget : public IRenderedTarget
8686
bool mirrorHorizontally() const override;
8787

8888
Texture texture() const override;
89+
const Texture &cpuTexture() const override;
8990
int costumeWidth() const override;
9091
int costumeHeight() const override;
9192

test/mocks/renderedtargetmock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class RenderedTargetMock : public IRenderedTarget
6262
MOCK_METHOD(bool, mirrorHorizontally, (), (const, override));
6363

6464
MOCK_METHOD(Texture, texture, (), (const, override));
65+
MOCK_METHOD(const Texture &, cpuTexture, (), (const, override));
6566
MOCK_METHOD(int, costumeWidth, (), (const, override));
6667
MOCK_METHOD(int, costumeHeight, (), (const, override));
6768

test/renderedtarget/renderedtarget_test.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ TEST_F(RenderedTargetTest, UpdateMethods)
106106
ASSERT_EQ(texture.width(), 4);
107107
ASSERT_EQ(texture.height(), 6);
108108

109+
texture = target.cpuTexture();
110+
ASSERT_TRUE(texture.isValid());
111+
ASSERT_EQ(texture.width(), 4);
112+
ASSERT_EQ(texture.height(), 6);
113+
109114
// Sprite
110115
Sprite sprite;
111116
sprite.setVisible(true);
@@ -145,6 +150,11 @@ TEST_F(RenderedTargetTest, UpdateMethods)
145150
ASSERT_EQ(texture.width(), 4);
146151
ASSERT_EQ(texture.height(), 6);
147152

153+
texture = target.cpuTexture();
154+
ASSERT_TRUE(texture.isValid());
155+
ASSERT_EQ(texture.width(), 4);
156+
ASSERT_EQ(texture.height(), 6);
157+
148158
// Visibility
149159
target.updateVisibility(false);
150160
ASSERT_FALSE(target.isVisible());
@@ -290,6 +300,11 @@ TEST_F(RenderedTargetTest, UpdateMethods)
290300
ASSERT_EQ(target.costumeWidth(), 13);
291301
ASSERT_EQ(target.costumeHeight(), 13);
292302

303+
texture = target.cpuTexture();
304+
ASSERT_TRUE(texture.isValid());
305+
ASSERT_EQ(texture.width(), 13);
306+
ASSERT_EQ(texture.height(), 13);
307+
293308
// Stage scale (SVG) - should update width and height
294309
EXPECT_CALL(engine, stageWidth()).WillOnce(Return(480));
295310
EXPECT_CALL(engine, stageHeight()).WillOnce(Return(360));
@@ -299,6 +314,16 @@ TEST_F(RenderedTargetTest, UpdateMethods)
299314
ASSERT_EQ(target.costumeWidth(), 13);
300315
ASSERT_EQ(target.costumeHeight(), 13);
301316

317+
texture = target.texture();
318+
ASSERT_TRUE(texture.isValid());
319+
ASSERT_EQ(texture.width(), 52);
320+
ASSERT_EQ(texture.height(), 52);
321+
322+
texture = target.cpuTexture();
323+
ASSERT_TRUE(texture.isValid());
324+
ASSERT_EQ(texture.width(), 13);
325+
ASSERT_EQ(texture.height(), 13);
326+
302327
context.doneCurrent();
303328
}
304329

0 commit comments

Comments
 (0)