add textureTransform to ObjectBase
before textures load refactoring
This commit is contained in:
@@ -28,6 +28,10 @@ QVector3D colorVector(QRgb c) {
|
||||
}
|
||||
|
||||
|
||||
void TextureManager::addSearchPath(const QString & path) {
|
||||
if (!search_pathes.contains(path)) search_pathes << path;
|
||||
}
|
||||
|
||||
QString TextureManager::findFile(const QString & path) {
|
||||
return ::findFile(path, search_pathes);
|
||||
}
|
||||
@@ -38,7 +42,7 @@ GLuint TextureManager::loadTexture(const QString & path, bool ownership, bool bu
|
||||
if (p.isEmpty()) return 0;
|
||||
int tid = textureID(p, bump);
|
||||
if (tid > 0) {
|
||||
// qDebug() << "[TextureManager] Found" << path << "as" << tid;
|
||||
qDebug() << "[TextureManager] Found" << path << "as" << tid;
|
||||
return tid;
|
||||
}
|
||||
QImage image(p);
|
||||
@@ -70,7 +74,7 @@ GLuint TextureManager::loadTexture(const QImage & im, bool ownership, bool bump)
|
||||
qDebug() << "[TextureManager] Can`t load image";
|
||||
return tid;
|
||||
}
|
||||
// qDebug() << "[TextureManager] Loaded image as" << tid;
|
||||
qDebug() << "[TextureManager] Loaded image as" << tid;
|
||||
return tid;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,7 @@ public:
|
||||
virtual ~TextureManager() {}
|
||||
|
||||
static void addSearchPath(const QString & path) {
|
||||
if (!search_pathes.contains(path)) search_pathes << path;
|
||||
}
|
||||
static void clearSearchPathes() { search_pathes.clear(); }
|
||||
if (!search_pathes; { search_pathes.clear(); }
|
||||
static QStringList searchPathes() { return search_pathes; }
|
||||
static QString findFile(const QString & path);
|
||||
GLuint loadTexture(const QString & path, bool ownership = true, bool bump = false);
|
||||
|
||||
@@ -160,16 +160,12 @@ void Renderer::initShaders() {
|
||||
if (!need_init_shaders) return;
|
||||
need_init_shaders = false;
|
||||
initUniformBuffer(shaders.value(srGeometryPass), &buffer_materials, bpMaterials, "QGLMaterialData");
|
||||
initUniformBuffer(shaders.value(srLightOmniPass), &buffer_materials, bpMaterials, "QGLMaterialData");
|
||||
initUniformBuffer(shaders.value(srLightOmniPass), &buffer_lights, bpLightParameters, "QGLLightParameterData");
|
||||
initUniformBuffer(shaders.value(srLightOmniPass), &buffer_lights_pos, bpLightPositions, "QGLLightPositionData");
|
||||
initUniformBuffer(shaders.value(srLightSpotPass), &buffer_materials, bpMaterials, "QGLMaterialData");
|
||||
initUniformBuffer(shaders.value(srLightSpotPass), &buffer_lights, bpLightParameters, "QGLLightParameterData");
|
||||
initUniformBuffer(shaders.value(srLightSpotPass), &buffer_lights_pos, bpLightPositions, "QGLLightPositionData");
|
||||
ShaderRole roles[] = {srLightOmniPass, srLightSpotPass};
|
||||
QOpenGLShaderProgram * prog = 0;
|
||||
for (int p = 0; p < 2; ++p) {
|
||||
if (!bindShader(roles[p], &prog)) continue;
|
||||
for (ShaderRole role: {srLightOmniPass, srLightSpotPass}) {
|
||||
initUniformBuffer(shaders.value(role), &buffer_materials, bpMaterials, "QGLMaterialData");
|
||||
initUniformBuffer(shaders.value(role), &buffer_lights, bpLightParameters, "QGLLightParameterData");
|
||||
initUniformBuffer(shaders.value(role), &buffer_lights_pos, bpLightPositions, "QGLLightPositionData");
|
||||
if (!bindShader(role, &prog)) continue;
|
||||
for (int i = 0; i < 5; ++i)
|
||||
prog->setUniformValue(QString("tex_%1").arg(i).toLatin1().constData(), i);
|
||||
prog->setUniformValue("tex_coeffs[0]", (int)Renderer::dbrBuffersCount);
|
||||
@@ -232,7 +228,8 @@ void Renderer::fillObjectsBuffer(const ObjectBaseList & ol, RenderPass pass) {
|
||||
}
|
||||
so.object_id = o->id();
|
||||
o->worldTransform().transposed().copyDataTo(so.modelmatrix);
|
||||
// qDebug() << "load obj" << o->name() << o->worldTransform();
|
||||
o->textureGLMatrix().copyDataTo(so.texturematrix);
|
||||
// qDebug() << "load obj" << o->name() << o->textureMatrix() << tmat;
|
||||
}
|
||||
// qDebug() << "fillObjectsBuffer" << ol.size();
|
||||
}
|
||||
@@ -300,6 +297,10 @@ void Renderer::renderLight(int first_wr_buff, bool clear_only) {
|
||||
|
||||
|
||||
void Renderer::renderScene() {
|
||||
timings.clear();
|
||||
Measurer phase(&timings);
|
||||
|
||||
phase.begin("init");
|
||||
initShaders();
|
||||
tex_env.load();
|
||||
QOpenGLExtraFunctions * f = view;
|
||||
@@ -308,21 +309,27 @@ void Renderer::renderScene() {
|
||||
QOpenGLShaderProgram * prog = 0;
|
||||
bool scene_changed = scene.prepare();
|
||||
scene.destroyUnused(f);
|
||||
phase.end();
|
||||
|
||||
/// reload materials on change
|
||||
phase.begin("scene reload");
|
||||
if (scene_changed || scene.need_reload_materials) {
|
||||
rend_selection.generateObjectsID(scene);
|
||||
reloadMaterials(scene);
|
||||
if (edit_mode) recreateMaterialThumbnails();
|
||||
emit view->materialsChanged();
|
||||
}
|
||||
phase.end();
|
||||
|
||||
/// material thumbnails
|
||||
phase.begin("materials");
|
||||
if (edit_mode && !scene_changed) {
|
||||
rend_mat.procQueue();
|
||||
}
|
||||
phase.end();
|
||||
|
||||
/// lights
|
||||
phase.begin("lights prepare");
|
||||
cur_lights = scene.lights_used;
|
||||
bool use_camlight = (camera_light_mode == QGLView::clmOn);
|
||||
if ((camera_light_mode == QGLView::clmAuto) && cur_lights.isEmpty()) {
|
||||
@@ -337,13 +344,17 @@ void Renderer::renderScene() {
|
||||
reloadLightsParameters(cur_lights);
|
||||
}
|
||||
reloadLightsPositions(cam);
|
||||
phase.end();
|
||||
|
||||
/// selection
|
||||
phase.begin("selection");
|
||||
if (edit_mode) {
|
||||
rend_selection.renderSelection(scene);
|
||||
}
|
||||
phase.end();
|
||||
|
||||
/// solid geometry pass
|
||||
phase.begin("geometry solid");
|
||||
fbo_ds.bind();
|
||||
glEnableDepth();
|
||||
glClearFramebuffer();
|
||||
@@ -356,11 +367,15 @@ void Renderer::renderScene() {
|
||||
fbo_ds.blit(dbrNormalZ, fbo_ds.id(), dbrNormalZSolid, fbo_ds.rect(), fbo_ds.rect());
|
||||
fbo_ds.blit(dbrSpecularReflect, fbo_ds.id(), dbrSpecularReflectSolid, fbo_ds.rect(), fbo_ds.rect());
|
||||
fbo_ds.release();
|
||||
phase.end();
|
||||
|
||||
/// lighting passes
|
||||
phase.begin("... light");
|
||||
renderLight(obrSolidOmni, scene.geometries_used[rpSolid].isEmpty());
|
||||
phase.end();
|
||||
|
||||
/// transparent geometry pass
|
||||
phase.begin("geometry trans");
|
||||
fbo_ds.bind();
|
||||
glEnableDepth();
|
||||
fbo_ds.setWriteBuffers({0, 1, 2, 3, 4});
|
||||
@@ -370,11 +385,15 @@ void Renderer::renderScene() {
|
||||
renderObjects(scene, rpTransparent);
|
||||
}
|
||||
fbo_ds.release();
|
||||
phase.end();
|
||||
|
||||
/// lighting passes
|
||||
phase.begin("... light");
|
||||
renderLight(obrTransparentOmni, scene.geometries_used[rpTransparent].isEmpty());
|
||||
phase.end();
|
||||
|
||||
/// blending layers
|
||||
phase.begin("blending");
|
||||
if (bindShader(srFinalPass, &prog)) {
|
||||
fbo_out.bindColorTexture(obrSolidOmni, 1);
|
||||
fbo_out.bindColorTexture(obrSolidSpot, 2);
|
||||
@@ -383,10 +402,12 @@ void Renderer::renderScene() {
|
||||
fbo_out.setWriteBuffer(obrGeneral0);
|
||||
renderQuad(prog, quad);
|
||||
}
|
||||
phase.end();
|
||||
|
||||
cur_write_plane = obrGeneral0;
|
||||
|
||||
/// tonemapping
|
||||
phase.begin("tonemap");
|
||||
tone_proc.process();
|
||||
auto free = getFreePlanes(0);
|
||||
if (bindShader(srTonemapPass, &prog)) {
|
||||
@@ -398,8 +419,10 @@ void Renderer::renderScene() {
|
||||
} else {
|
||||
fbo_out.blit(prev_write_plane, fbo_out.id(), cur_write_plane, fbo_out.rect(), fbo_out.rect());
|
||||
}
|
||||
phase.end();
|
||||
|
||||
/// FXAA
|
||||
phase.begin("fxaa");
|
||||
if (view->isFeatureEnabled(QGLView::qglFXAA)) {
|
||||
prog = shader_fxaa;
|
||||
if (bindShader(prog)) {
|
||||
@@ -409,27 +432,37 @@ void Renderer::renderScene() {
|
||||
renderQuad(prog, quad, 0, false);
|
||||
}
|
||||
}
|
||||
phase.end();
|
||||
|
||||
/// custom effects
|
||||
for (auto * e: fb_effects) {
|
||||
if (!e->isEnabled()) continue;
|
||||
phase.begin("fb effect " + e->name());
|
||||
e->reloadShadersInternal();
|
||||
e->drawInternal();
|
||||
phase.end();
|
||||
}
|
||||
|
||||
fbo_out.release();
|
||||
|
||||
/// apply hovers and selection frame
|
||||
phase.begin("service");
|
||||
if (edit_mode) {
|
||||
rend_selection.drawSelection(fbo_out, cur_write_plane);
|
||||
rend_service.renderService();
|
||||
} else {
|
||||
fbo_out.blit(cur_write_plane, 0, 0, fbo_out.rect(), QRect(QPoint(), view->size()));
|
||||
}
|
||||
phase.end();
|
||||
|
||||
/// grab framebuffer
|
||||
phase.begin("grab");
|
||||
if (is_grabbing) {
|
||||
fbo_out.queryImage(0);
|
||||
last_img = fbo_out.getImage().mirrored();
|
||||
// qDebug() << last_img.size();
|
||||
}
|
||||
phase.end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -99,6 +99,7 @@ public:
|
||||
QImage getImage() const { return last_img; }
|
||||
void addFramebufferEffect(FramebufferEffectBase * e);
|
||||
void clearFramebufferEffects() { fb_effects.clear(); }
|
||||
QString getTimings() const { return timings; }
|
||||
|
||||
QImage materialThumbnail(Material * m) { return rend_mat.materialThumbnail(m); }
|
||||
void recreateMaterialThumbnails(bool force_all = false) { rend_mat.recreateMaterialThumbnails(force_all); }
|
||||
@@ -144,6 +145,7 @@ private:
|
||||
QMap<int, QList<Light *>> cur_lights;
|
||||
QVector<FramebufferEffectBase *> fb_effects;
|
||||
QImage last_img;
|
||||
QString timings;
|
||||
bool is_grabbing = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "glbuffer.h"
|
||||
#include "glshaders_types.h"
|
||||
#include "gltexturearray.h"
|
||||
#include "measurer.h"
|
||||
|
||||
|
||||
class QGLENGINE_CORE_EXPORT RendererBase {
|
||||
|
||||
@@ -31,7 +31,7 @@ TonemappingProc::TonemappingProc(Renderer * rend)
|
||||
: QThread()
|
||||
, r(rend)
|
||||
, fbo_1x1(r->view, 1, false, GL_RGB32F)
|
||||
, fbomm(r->fbo_out, Renderer::obrGeneral1, 3)
|
||||
, fbomm(r->fbo_out, Renderer::obrGeneral0, 3)
|
||||
, buffer_vbo(GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW) {
|
||||
shader_sum = 0;
|
||||
timer_delim = 0;
|
||||
|
||||
Reference in New Issue
Block a user