get image function

This commit is contained in:
Бычков Андрей
2022-10-18 18:07:32 +03:00
parent 1afa4ea368
commit 0f993e6c1c
4 changed files with 23 additions and 4 deletions

View File

@@ -23,7 +23,7 @@
GLWidget::GLWidget(QWidget *parent) : QWidget(parent) {
view_ = new QGLView();
view_->setFlags(windowFlags() | Qt::FramelessWindowHint);
//view_->setFlags(windowFlags() | Qt::FramelessWindowHint);
container = QWidget::createWindowContainer(view_, this);
lay = new QVBoxLayout(this);
lay->addWidget(container);

View File

@@ -173,6 +173,9 @@ public:
void setCurrentAction(RendererService::HandleAction ha) {renderer_.rend_service.setCurrentAction(ha);}
void setContextActions(QList<QAction*> al) {context_menu.clear(); context_menu.addActions(al);}
void popupMenu(const QPoint &pos, QAction *at = nullptr) {context_menu.popup(pos, at);}
void setGrabImage(bool on) {renderer_.setGrabImage(on);}
bool isGrabImage() const {return renderer_.isGrabImage();}
QImage getImage() const {return renderer_.getImage();}
GLfloat aspect, iaspect;
Renderer renderer_;

View File

@@ -85,6 +85,7 @@ void Renderer::init(int width, int height) {
initCoeffTextures();
markReloadTextures();
tex_env.init();
if (is_grabbing) fbo_out.enablePixelBuffer();
need_init_shaders = true;
}
@@ -347,18 +348,18 @@ void Renderer::renderScene() {
}
/// tonemapping
if (tone_proc.process()) fbo_out.bind();
tone_proc.process();
if (bindShader(srTonemapPass, &prog)) {
fbo_out.bind();
prog->setUniformValue("gamma", gamma_);
prog->setUniformValue("frame_max", tone_proc.frameMax());
fbo_out.bindColorTexture(obrSum, 0);
fbo_out.setWriteBuffer(obrTonemap);
renderQuad(prog, quad);
fbo_out.release();
} else {
fbo_out.blit(obrSum, fbo_out.id(), obrTonemap, fbo_out.rect(), fbo_out.rect());
}
//glClearFramebuffer(Qt::red, false);
fbo_out.release();
/// apply hovers and selection frame
if (edit_mode) {
@@ -367,6 +368,11 @@ void Renderer::renderScene() {
} else {
fbo_out.blit(obrTonemap, 0, 0, fbo_out.rect(), QRect(QPoint(), view->size()));
}
if (is_grabbing) {
fbo_out.queryImage(0);
last_img = fbo_out.getImage().mirrored();
//qDebug() << last_img.size();
}
}
@@ -374,3 +380,8 @@ void Renderer::setCameraLightMode(int m) {
camera_light_mode = m;
view->scene()->setLightsChanged();
}
void Renderer::setGrabImage(bool on) {
is_grabbing = on;
//fbo_out.enablePixelBuffer();
}

View File

@@ -84,6 +84,9 @@ public:
void renderScene();
void setCameraLightMode(int m);
int cameraLightMode() const {return camera_light_mode;}
void setGrabImage(bool on);
bool isGrabImage() const {return is_grabbing;}
QImage getImage() const {return last_img;}
QImage materialThumbnail(Material * m) {return rend_mat.materialThumbnail(m);}
void recreateMaterialThumbnails(bool force_all = false) {rend_mat.recreateMaterialThumbnails(force_all);}
@@ -125,6 +128,8 @@ private:
QVector4D corner_dirs[4];
QVector<QVector3D> hcontent;
QMap<int, QList<Light*>> cur_lights;
QImage last_img;
bool is_grabbing = false;
};
#endif // RENDERER_H