From 11302ac36380f0111b294fb66a2c821bb7bc3b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Thu, 19 Apr 2018 20:10:15 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/libs@375 a8b55f48-bf90-11e4-a774-851b48703e85 --- qglview/glmaterial.cpp | 32 +++++++++++++++++++++++++++++++- qglview/glmaterial.h | 3 +++ qglview/gltypes.cpp | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/qglview/glmaterial.cpp b/qglview/glmaterial.cpp index 0f93702..f222137 100644 --- a/qglview/glmaterial.cpp +++ b/qglview/glmaterial.cpp @@ -82,9 +82,15 @@ void GLCubeTexture::loadPathesFromDirectory(const QString & dir) { +QString GLTextureManagerBase::findFile(const QString & path) { + if (!currentGLTextureManager) return QString(); + return ::findFile(path, currentGLTextureManager->search_pathes); +} + + GLuint GLTextureManagerBase::loadTexture(const QString & path, bool ownership, bool bump) { if (!currentGLTextureManager) return 0; - QString p = findFile(path, search_pathes); + QString p = findFile(path); if (p.isEmpty()) return 0; int tid = ((GLTextureManagerBase*)currentGLTextureManager)->textureID(p, bump); if (tid > 0) { @@ -124,6 +130,30 @@ GLuint GLTextureManagerBase::loadTexture(const QImage & im, bool ownership, bool return tid; } + +void GLTextureManagerBase::reloadTexture(GLuint tid, const QString & path) { + if (!currentGLTextureManager) return; + QString p = findFile(path); + if (p.isEmpty()) return; + QImage image(p); + createGLTexture(tid, image); + if (tid == 0) { + qDebug() << "[TextureManager] Can`t load" << p; + return; + } + qDebug() << "[TextureManager] Reloaded" << p << "as" << tid; +} + + +void GLTextureManagerBase::reloadTexture(GLuint tid, const QImage & im) { + if (!currentGLTextureManager) return; + if (im.isNull()) return; + QImage image(im); + createGLTexture(tid, image); + qDebug() << "[TextureManager] Reloaded" << tid; +} + + Vector3d colorVector(QRgb c) {return Vector3d(((uchar*)(&c))[0] / 255., ((uchar*)(&c))[1] / 255., ((uchar*)(&c))[2] / 255.);} void GLTextureManagerBase::convertToNormal(QImage & im) { diff --git a/qglview/glmaterial.h b/qglview/glmaterial.h index fd2a4c7..1b570c3 100644 --- a/qglview/glmaterial.h +++ b/qglview/glmaterial.h @@ -78,8 +78,11 @@ class GLTextureManagerBase { public: static void addSearchPath(const QString & path) {search_pathes << path;} static QStringList searchPathes() {return search_pathes;} + static QString findFile(const QString & path); static GLuint loadTexture(const QString & path, bool ownership = true, bool bump = false); static GLuint loadTexture(const QImage & image, bool ownership = true, bool bump = false); + static void reloadTexture(GLuint tid, const QString & path); + static void reloadTexture(GLuint tid, const QImage & image); int textureID(const QString & path, bool bump = false) {return tex_ids[bump ? 1 : 0][path];} protected: diff --git a/qglview/gltypes.cpp b/qglview/gltypes.cpp index 5d5bc1b..46d05f5 100644 --- a/qglview/gltypes.cpp +++ b/qglview/gltypes.cpp @@ -141,8 +141,8 @@ void createGLTexture(GLuint & tex, int width, int height, const GLenum & format, void createGLTexture(GLuint & tex, const QImage & image, const GLenum & format, const GLenum & target) { if (tex == 0) { glGenTextures(1, &tex); - glBindTexture(target, tex); } + glBindTexture(target, tex); QImage im = image.mirrored(false, true);///__GLWidget__::convertToGLFormat(image); //const QImage & cim(im); //glClearError();