MandelWidget.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. #include "MandelWidget.h"
  2. #include <cmath>
  3. using namespace mnd;
  4. #include <QOpenGLVertexArrayObject>
  5. Texture::Texture(const Bitmap<RGBColor>& bitmap) :
  6. context{ nullptr }
  7. {
  8. glGenTextures(1, &id);
  9. glBindTexture(GL_TEXTURE_2D, id);
  10. long lineLength = (bitmap.width * 3 + 3) & ~3;
  11. unsigned char* pixels = new unsigned char[lineLength * bitmap.height];
  12. for (int i = 0; i < bitmap.width; i++) {
  13. for (int j = 0; j < bitmap.height; j++) {
  14. int index = i * 3 + j * lineLength;
  15. RGBColor c = bitmap.get(i, j);
  16. pixels[index] = c.r;
  17. pixels[index + 1] = c.g;
  18. pixels[index + 2] = c.b;
  19. }
  20. }
  21. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, int(bitmap.width), int(bitmap.height), 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
  22. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  23. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  24. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  25. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  26. }
  27. Texture::Texture(const Bitmap<RGBColor>& bitmap, QOpenGLContext* context) :
  28. context{ context }
  29. {
  30. context->functions()->glGenTextures(1, &id);
  31. context->functions()->glBindTexture(GL_TEXTURE_2D, id);
  32. long lineLength = (bitmap.width * 3 + 3) & ~3;
  33. unsigned char* pixels = new unsigned char[lineLength * bitmap.height];
  34. for (int i = 0; i < bitmap.width; i++) {
  35. for (int j = 0; j < bitmap.height; j++) {
  36. int index = i * 3 + j * lineLength;
  37. RGBColor c = bitmap.get(i, j);
  38. pixels[index] = c.r;
  39. pixels[index + 1] = c.g;
  40. pixels[index + 2] = c.b;
  41. }
  42. }
  43. context->functions()->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, int(bitmap.width), int(bitmap.height), 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
  44. context->functions()->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  45. context->functions()->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  46. context->functions()->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  47. context->functions()->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  48. }
  49. Texture::~Texture(void)
  50. {
  51. if (id != 0)
  52. glDeleteTextures(1, &id);
  53. }
  54. Texture::Texture(Texture&& other) :
  55. id{ other.id },
  56. context{ other.context }
  57. {
  58. other.id = 0;
  59. }
  60. Texture& Texture::operator=(Texture&& other)
  61. {
  62. this->id = other.id;
  63. this->context = other.context;
  64. other.id = 0;
  65. return *this;
  66. }
  67. void Texture::bind(void) const
  68. {
  69. glBindTexture(GL_TEXTURE_2D, id);
  70. }
  71. void Texture::drawRect(float x, float y, float width, float height)
  72. {
  73. glColor3ub(255, 255, 255);
  74. glEnable(GL_TEXTURE_2D);
  75. bind();
  76. glBegin(GL_TRIANGLE_STRIP);
  77. glTexCoord2f(0, 0);
  78. glVertex2f(x, y);
  79. glTexCoord2f(1, 0);
  80. glVertex2f(x + width, y);
  81. glTexCoord2f(0, 1);
  82. glVertex2f(x, y + height);
  83. glTexCoord2f(1, 1);
  84. glVertex2f(x + width, y + height);
  85. glEnd();
  86. glDisable(GL_TEXTURE_2D);
  87. }
  88. std::pair<int, int> TexGrid::getCellIndices(double x, double y)
  89. {
  90. return { ::floor(x / dpp / MandelV::chunkSize), ::floor(y / dpp / MandelV::chunkSize) };
  91. }
  92. std::pair<double, double> TexGrid::getPositions(int x, int y)
  93. {
  94. return { x * dpp * MandelV::chunkSize, y * dpp * MandelV::chunkSize };
  95. }
  96. Texture* TexGrid::getCell(int i, int j)
  97. {
  98. auto cIt = cells.find({i, j});
  99. if (cIt != cells.end()) {
  100. return cIt->second.get();
  101. }
  102. else {
  103. return nullptr;
  104. }
  105. }
  106. void TexGrid::setCell(int i, int j, std::unique_ptr<Texture> tex)
  107. {
  108. cells[{i, j}] = std::move(tex);
  109. }
  110. void TexGrid::clearCells(void)
  111. {
  112. cells.clear();
  113. }
  114. void Job::run(void)
  115. {
  116. auto [absX, absY] = grid->getPositions(i, j);
  117. double gw = grid->dpp * MandelV::chunkSize;
  118. Bitmap<float> f(MandelV::chunkSize, MandelV::chunkSize);
  119. mnd::MandelInfo mi;
  120. mi.view.x = absX;
  121. mi.view.y = absY;
  122. mi.view.width = mi.view.height = gw;
  123. mi.bWidth = mi.bHeight = MandelV::chunkSize;
  124. mi.maxIter = 500;
  125. mndContext.getDefaultGenerator().generate(mi, f.pixels.get());
  126. Bitmap<RGBColor>* rgb = new Bitmap<RGBColor>(f.map<RGBColor>([] (float f) {
  127. return RGBColor{ uint8_t(f / 2), uint8_t(f / 2), uint8_t(f / 2) };
  128. }));
  129. emit done(level, i, j, rgb);
  130. }
  131. void Calcer::calc(TexGrid& grid, int level, int i, int j)
  132. {
  133. if (jobs.find({ level, i, j }) == jobs.end()) {
  134. Job* job = new Job(mndContext, &grid, level, i, j);
  135. connect(job, &Job::done, this, &Calcer::redirect);
  136. jobs.insert({ level, i, j });
  137. //jobs.push_back(std::move(job));
  138. threadPool->start(job);
  139. }
  140. }
  141. void Calcer::redirect(int level, int i, int j, Bitmap<RGBColor>* bmp)
  142. {
  143. jobs.erase({ level, i, j });
  144. emit done(level, i, j, bmp);
  145. }
  146. MandelV::MandelV(mnd::MandelContext& mndContext) :
  147. mndContext{ mndContext },
  148. calcThread{ std::make_unique<Calcer>(mndContext) }
  149. {
  150. Bitmap<RGBColor> emp(8, 8);
  151. for(auto i = 0; i < emp.width; i++) {
  152. for(auto j = 0; j < emp.height; j++) {
  153. if((i + j) & 0x1) { // if i+j is odd
  154. emp.get(i, j) = RGBColor{ 255, 255, 255 };
  155. }
  156. else {
  157. emp.get(i, j) = RGBColor{ 120, 120, 120 };
  158. }
  159. }
  160. }
  161. empty = std::make_unique<Texture>(emp);
  162. connect(calcThread.get(), &Calcer::done, this, &MandelV::cellReady);
  163. }
  164. int MandelV::getLevel(double dpp) {
  165. return -int(::log2(dpp / chunkSize));
  166. }
  167. double MandelV::getDpp(int level)
  168. {
  169. return ::pow(2, -level) * chunkSize;
  170. }
  171. TexGrid& MandelV::getGrid(int level)
  172. {
  173. auto it = levels.find(level);
  174. if (it != levels.end())
  175. return it->second;
  176. else {
  177. levels.insert({ level, TexGrid(getDpp(level)) });
  178. return levels[level];
  179. }
  180. }
  181. void MandelV::paint(const mnd::MandelViewport& mvp)
  182. {
  183. double dpp = mvp.width / width;
  184. int level = getLevel(dpp);
  185. auto& grid = getGrid(level);
  186. double gw = getDpp(level) * chunkSize;
  187. double w = width * gw / mvp.width;
  188. //double h = height * gw / mvp.height;
  189. auto [left, top] = grid.getCellIndices(mvp.x, mvp.y);
  190. auto [right, bottom] = grid.getCellIndices(mvp.right(), mvp.bottom());
  191. auto [realXLeft, realYTop] = grid.getPositions(left, top);
  192. realXLeft = (realXLeft - mvp.x) * width / mvp.width;
  193. realYTop = (realYTop - mvp.y) * height / mvp.height;
  194. for(int i = left; i <= right; i++) {
  195. for(int j = top; j <= bottom; j++) {
  196. double x = realXLeft + (i - left) * w;
  197. double y = realYTop + (j - top) * w;
  198. Texture* t = grid.getCell(i, j);
  199. if (t != nullptr) {
  200. t->drawRect(x, y, w, w);
  201. /*glBegin(GL_LINE_LOOP);
  202. glVertex2f(x, y);
  203. glVertex2f(x + w, y);
  204. glVertex2f(x + w, y + w);
  205. glVertex2f(x, y + w);
  206. glEnd();*/
  207. }
  208. else {
  209. calcThread->calc(grid, level, i, j);
  210. this->empty->drawRect(x, y, w, w);
  211. }
  212. }
  213. }
  214. }
  215. void MandelV::cellReady(int level, int i, int j, Bitmap<RGBColor>* bmp)
  216. {
  217. this->getGrid(level).setCell(i, j, std::make_unique<Texture>(*bmp));
  218. delete bmp;
  219. printf("cellReady: %d --> %d, %d\n", level, i, j);
  220. emit redrawRequested();
  221. }
  222. MandelView::MandelView(mnd::Generator& generator, Gradient &gradient, MandelWidget* mWidget) :
  223. generator{ &generator },
  224. gradient{ gradient },
  225. mWidget{ mWidget }
  226. //context{ new QOpenGLContext(this) }
  227. {
  228. //context->setShareContext(mWidget->context()->contextHandle());
  229. hasToCalc.store(false);
  230. finish.store(false);
  231. }
  232. MandelView::~MandelView(void)
  233. {
  234. finish.store(true);
  235. condVar.notify_one();
  236. //calcThread.wait(100);
  237. calcThread.wait(100);
  238. calcThread.terminate();
  239. }
  240. void MandelView::setGenerator(mnd::Generator& value)
  241. {
  242. generator = &value;
  243. }
  244. void MandelView::start(void)
  245. {
  246. this->moveToThread(&calcThread);
  247. connect(&calcThread, SIGNAL(started()), this, SLOT(loop()));
  248. calcThread.start();
  249. }
  250. void MandelView::loop(void)
  251. {
  252. printf("thread!\n"); fflush(stdout);
  253. //QGLWidget* hiddenWidget = new QGLWidget(nullptr, mWidget);
  254. //hiddenWidget->setVisible(false);
  255. //hiddenWidget->context()->contextHandle()->moveToThread(&calcThread);
  256. //QOpenGLContext* context = hiddenWidget->context()->contextHandle();
  257. //context->setShareContext(mWidget->context()->contextHandle());
  258. //context->create();
  259. //printf("sharing: %d\n", QOpenGLContext::areSharing(hiddenWidget->context()->contextHandle(), mWidget->context()->contextHandle()));
  260. //fflush(stdout);
  261. //std::this_thread::sleep_for(std::chrono::milliseconds(3000));
  262. std::unique_lock<std::mutex> lock(mut);
  263. while(true) {
  264. printf("calcing!\n"); fflush(stdout);
  265. if (finish.load()) {
  266. break;
  267. }
  268. if (hasToCalc.exchange(false)) {
  269. const MandelInfo& mi = toCalc.load();
  270. auto fmap = Bitmap<float>(mi.bWidth, mi.bHeight);
  271. generator->generate(mi, fmap.pixels.get());
  272. auto* bitmap = new Bitmap<RGBColor>(fmap.map<RGBColor>([&mi, this](float i) {
  273. return i >= mi.maxIter ? RGBColor{ 0, 0, 0 } : gradient.get(i);
  274. }));
  275. /*return i >= mi.maxIter ?
  276. RGBColor{ 0,0,0 } :
  277. RGBColor{ uint8_t(cos(i * 0.015f) * 127 + 127),
  278. uint8_t(sin(i * 0.01f) * 127 + 127),
  279. uint8_t(i) }; }));//uint8_t(::sin(i * 0.01f) * 100 + 100), uint8_t(i) }; });
  280. */
  281. //hiddenWidget->makeCurrent();
  282. //Texture* tex = new Texture(bitmap);
  283. //hiddenWidget->doneCurrent();
  284. //Texture* tex = 0;
  285. emit updated(bitmap);
  286. }
  287. printf("finished calcing!\n"); fflush(stdout);
  288. condVar.wait(lock);
  289. printf("waking!\n"); fflush(stdout);
  290. }
  291. }
  292. void MandelView::adaptViewport(const MandelInfo mi)
  293. {
  294. //bmp->get(0, 0) = RGBColor{ 10, uint8_t(sin(1 / vp.width) * 127 + 127), 10 };
  295. /*printf("adapted\n");
  296. if (calc.valid()) {
  297. auto status = calc.wait_for(std::chrono::milliseconds(0));
  298. if (status == std::future_status::deferred) {
  299. printf("deferred\n");
  300. } else if (status == std::future_status::timeout) {
  301. printf("timeout\n");
  302. } else if (status == std::future_status::ready) {
  303. printf("ready!\n");
  304. }
  305. }*/
  306. /*if (!calc.valid() || calc.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready) {
  307. toCalc = mi;
  308. hasToCalc = true;
  309. calc = std::async([this, mi] () {
  310. QGLWidget* hiddenWidget = new QGLWidget(nullptr, (QGLWidget*) mWidget);
  311. QOpenGLContext* context = hiddenWidget->context()->contextHandle();
  312. hiddenWidget->makeCurrent();
  313. //context->setShareContext(mWidget->context()->contextHandle());
  314. //context->create();
  315. printf("sharing: %d\n", QOpenGLContext::areSharing(context, mWidget->context()->contextHandle()));
  316. fflush(stdout);
  317. //std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  318. do {
  319. auto fmap = Bitmap<float>(mi.bWidth, mi.bHeight);
  320. generator->generate(mi, fmap.pixels.get());
  321. auto bitmap = fmap.map<RGBColor>([&mi](float i) { return i > mi.maxIter ?
  322. RGBColor{ 0,0,0 } :
  323. RGBColor{ uint8_t(cos(i * 0.015f) * 127 + 127),
  324. uint8_t(sin(i * 0.01f) * 127 + 127),
  325. uint8_t(i) }; });//uint8_t(::sin(i * 0.01f) * 100 + 100), uint8_t(i) }; });
  326. Texture* tex = new Texture(bitmap, context);
  327. //Texture* tex = 0;
  328. emit updated(tex);
  329. } while(hasToCalc.exchange(false));
  330. });
  331. }
  332. else {*/
  333. //std::unique_lock<std::mutex> lock(mut, std::try_to_lock);
  334. toCalc = mi;
  335. hasToCalc.exchange(true);
  336. condVar.notify_one();
  337. //}
  338. }
  339. MandelWidget::MandelWidget(mnd::MandelContext& ctxt, QWidget* parent) :
  340. QOpenGLWidget{ parent },
  341. mndContext{ ctxt },
  342. mv{ ctxt.getDefaultGenerator(), gradient, this }
  343. {
  344. this->setContentsMargins(0, 0, 0, 0);
  345. this->setSizePolicy(QSizePolicy::Expanding,
  346. QSizePolicy::Expanding);
  347. QObject::connect(&mv, &MandelView::updated, this, &MandelWidget::viewUpdated, Qt::AutoConnection);
  348. QObject::connect(this, &MandelWidget::needsUpdate, &mv, &MandelView::adaptViewport, Qt::DirectConnection);
  349. /*if (!ctxt.getDevices().empty()) {
  350. if (auto* gen = ctxt.getDevices()[0].getGeneratorDouble(); gen) {
  351. mv.setGenerator(*gen);
  352. }
  353. }*/
  354. }
  355. MandelWidget::~MandelWidget()
  356. {
  357. }
  358. void MandelWidget::initializeGL(void)
  359. {
  360. this->context()->functions()->glClearColor(0, 0, 0, 0);
  361. this->context()->makeCurrent(nullptr);
  362. glDisable(GL_DEPTH_TEST);
  363. // looks not even better
  364. //glDisable(GL_FRAMEBUFFER_SRGB);
  365. //glShadeModel(GL_SMOOTH);
  366. /*CpuGenerator<double> cpg;
  367. MandelInfo mi;
  368. mi.bWidth = this->width();//ql.geometry().width();
  369. mi.bHeight = this->height(); //ql.geometry().height();
  370. mi.maxIter = 250;
  371. mi.view = viewport;
  372. auto bitmap = cpg.generate(mi);*/
  373. Bitmap<RGBColor> bitmap(1, 1);
  374. bitmap.get(0, 0) = RGBColor{50, 50, 50};
  375. v = nullptr;
  376. tex = std::make_unique<Texture>(bitmap, context());
  377. mv.start();
  378. requestRecalc();
  379. }
  380. void MandelWidget::paintGL(void)
  381. {
  382. if (v == nullptr) {
  383. v = std::make_unique<MandelV>(mndContext);
  384. QObject::connect(v.get(), &MandelV::redrawRequested, this, static_cast<void(QOpenGLWidget::*)(void)>(&QOpenGLWidget::update));
  385. }
  386. /*if (!initialized) {
  387. emit needsUpdate(viewport);
  388. initialized = true;
  389. }*/
  390. int width = this->width();
  391. int height = this->height();
  392. v->width = width;
  393. v->height = height;
  394. //v = std::make_unique<MandelV>(context());
  395. /*CpuGenerator<double> cpg;
  396. ClGenerator clg;
  397. MandelGenerator& mg = cpg;
  398. MandelInfo mi;
  399. mi.bWidth = width;
  400. mi.bHeight = height;
  401. mi.maxIter = 5000;
  402. mi.view = viewport;*/
  403. //auto bitmap = mg.generate(mi);
  404. /*Bitmap<RGBColor> bitmap(1000, 1000);
  405. for (int i = 0; i < 1000 * 1000; i++)
  406. bitmap.pixels[i] = RGBColor{5, uint8_t((i % 1000) ^ (i / 1000)), 50};
  407. tex = std::make_unique<Texture>(bitmap);*/
  408. glViewport(0, 0, width, height);
  409. glMatrixMode(GL_PROJECTION);
  410. glLoadIdentity();
  411. #ifdef QT_OPENGL_ES_1
  412. glOrthof(0, width, height, 0, -1.0, 1.0);
  413. #else
  414. glOrtho(0, width, height, 0, -1.0, 1.0);
  415. #endif
  416. glMatrixMode(GL_MODELVIEW);
  417. glClear(GL_COLOR_BUFFER_BIT);
  418. glLoadIdentity();
  419. //tex->drawRect(0, 0, width, height);
  420. //v->empty = std::move(*tex)
  421. //v->empty.bind();
  422. v->paint(this->viewport);
  423. //*tex = std::move(v->empty);
  424. if (rubberbandDragging)
  425. drawRubberband();
  426. printf("painted GL\n");
  427. }
  428. void MandelWidget::drawRubberband(void)
  429. {
  430. glColor3ub(10, 200, 10);
  431. glBegin(GL_LINE_LOOP);
  432. glVertex2d(rubberband.x(), rubberband.y());
  433. glVertex2d(rubberband.right(), rubberband.y());
  434. glVertex2d(rubberband.right(), rubberband.bottom());
  435. glVertex2d(rubberband.x(), rubberband.bottom());
  436. glEnd();
  437. }
  438. void MandelWidget::zoom(float scale)
  439. {
  440. viewport.zoomCenter(scale);
  441. requestRecalc();
  442. }
  443. void MandelWidget::setMaxIterations(int maxIter)
  444. {
  445. this->maxIterations = maxIter;
  446. requestRecalc();
  447. }
  448. void MandelWidget::requestRecalc()
  449. {
  450. //emit needsUpdate(MandelInfo{ viewport, this->width(), this->height(), maxIterations });
  451. this->update();
  452. }
  453. void MandelWidget::resizeGL(int width, int height)
  454. {
  455. //glViewport(0, 0, (GLint) width, (GLint) height);
  456. }
  457. /*void MandelWidget::redraw(void)
  458. {
  459. /*CpuGenerator<double> cpg;
  460. MandelInfo mi;
  461. mi.bWidth = this->geometry().width();//ql.geometry().width();
  462. mi.bHeight = this->geometry().height(); //ql.geometry().height();
  463. mi.maxIter = 250;
  464. mi.view = viewport;*/
  465. //update();
  466. //emit needsUpdate(viewport);
  467. //auto bitmap = cpg.generate(mi).map<uint32_t>([](RGBColor rgb) { return 255 << 24 | rgb.b << 16 | rgb.g << 8 | rgb.r; });
  468. //}
  469. void MandelWidget::resizeEvent(QResizeEvent* re)
  470. {
  471. double aspect = double(geometry().width()) / geometry().height();
  472. //if (viewport.width > viewport.height * aspect)
  473. viewport.height = (viewport.width / aspect);
  474. //else
  475. // viewport.width = (viewport.height * aspect);
  476. requestRecalc();
  477. //redraw();
  478. }
  479. void MandelWidget::mousePressEvent(QMouseEvent* me)
  480. {
  481. rubberband.setCoords(me->x(), me->y(), 0, 0);
  482. rubberbandDragging = true;
  483. }
  484. void MandelWidget::mouseMoveEvent(QMouseEvent* me)
  485. {
  486. QRectF& rect = rubberband;
  487. float aspect = float(geometry().width()) / geometry().height();
  488. rect.setBottomRight(QPoint(me->x(), me->y()));
  489. if (rect.width() > rect.height() * aspect)
  490. rect.setHeight(rect.width() / aspect);
  491. else
  492. rect.setWidth(rect.height() * aspect);
  493. if (rubberbandDragging)
  494. emit repaint();
  495. }
  496. void MandelWidget::mouseReleaseEvent(QMouseEvent* me)
  497. {
  498. QRect rect = rubberband.toRect();
  499. QRect full = this->geometry();
  500. viewport.x += double(rect.left()) * viewport.width / full.width();
  501. viewport.y += double(rect.top()) * viewport.height / full.height();
  502. viewport.width *= double(rect.width()) / full.width();
  503. viewport.height *= double(rect.height()) / full.height();
  504. viewport.normalize();
  505. rubberbandDragging = false;
  506. requestRecalc();
  507. }
  508. void MandelWidget::viewUpdated(Bitmap<RGBColor>* bitmap)
  509. {
  510. if (bitmap != nullptr) {
  511. tex = std::make_unique<Texture>(*bitmap);
  512. delete bitmap;
  513. printf("viewUpdated\n");
  514. emit repaint();
  515. }
  516. }