Skip to content

Commit

Permalink
Invalidate alpha cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
gregersn committed Sep 30, 2024
1 parent c8dd134 commit 44fb080
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 2 deletions.
3 changes: 3 additions & 0 deletions include/pyro/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ namespace Pyro
virtual float screen_x(float x, float y, float z = 0.0f);
virtual float screen_y(float x, float y, float z = 0.0f);

virtual void begindraw() {load_pixels();};
virtual void enddraw() {update_pixels();};

// Drawing functions
void background(Color c)
{
Expand Down
2 changes: 1 addition & 1 deletion include/pyro/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace Pyro
unsigned int density{1};
float pixel_multiplier{1.0f};

bool modified{false};
bool modified{true};
int mx1{0}, my1{0}, mx2{0}, my2{0};
bool initialized{false};

Expand Down
1 change: 1 addition & 0 deletions screenshot-tests/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
test_sources = [
'test-main.cpp',
'test-graphics.cpp',
'test-image.cpp',
'test-image-composition.cpp',
'test-image-blend.cpp',
Expand Down
41 changes: 41 additions & 0 deletions screenshot-tests/test-graphics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <catch2/catch_all.hpp>
#include "test-settings.h"

#include <filesystem>

TEST_CASE("Draw multiple times") {
Pyro::Graphics *a = Pyro::creategraphics(100, 40);
Pyro::Graphics *b = Pyro::creategraphics(100, 40);

a->begindraw();
a->background(0.0f, 1.0f);
a->fill(1.0f, 0.0f, 0.0f, 1.0f);
a->rect(10,10,60, 20);
a->enddraw();

a->save("multidraw_a_1.png");

b->begindraw();
b->image(a, 0, 0);
b->enddraw();

b->save("multidraw_b_1.png");

CHECK_THAT("multidraw_a_1.png", LooksLike("multidraw_b_1.png"));

a->begindraw();
a->background(0.0f, 1.0f);
a->fill(0.0f, 1.0f, 0.0f, 1.0f);
a->rect(5, 5, 60, 20);
a->enddraw();

a->save("multidraw_a_2.png");

b->begindraw();
b->image(a, 0, 0);
b->enddraw();

b->save("multidraw_b_2.png");

CHECK_THAT("multidraw_a_2.png", LooksLike("multidraw_b_2.png"));
}
3 changes: 2 additions & 1 deletion screenshot-tests/test-image-placements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ TEST_CASE("Place image full screen")
}

Pyro::Graphics *p = Pyro::creategraphics(img->width(), img->height(), testmode);
p->begindraw();
p->image(img, 0, 0);

p->enddraw();
p->save(current_folder / filename);

delete img;
Expand Down
2 changes: 2 additions & 0 deletions src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ namespace Pyro
if (this->cache == nullptr)
{
this->cache = malloc(this->_pixelwidth * this->_pixelheight * sizeof(unsigned char) * this->format);
}
if(this->modified) {
unsigned char *_cache = static_cast<unsigned char *>(this->cache);
const unsigned char *source = this->load_bytes();

Expand Down

0 comments on commit 44fb080

Please sign in to comment.