[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/libs/kgllib/core/kgllib
From:       Rivo Laks <rivolaks () hot ! ee>
Date:       2008-01-24 18:49:52
Message-ID: 1201200592.492301.9019.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 765821 by rivol:

Add name/setName() and debugString() methods to TextureBase to ease debugging

 M  +4 -4      renderer.cpp  
 M  +22 -1     texture.cpp  
 M  +24 -1     texture.h  


--- trunk/playground/libs/kgllib/core/kgllib/renderer.cpp #765820:765821
@@ -45,24 +45,24 @@
 bool Renderer::bindTexture(const TextureBase* tex)
 {
     glBindTexture(tex->glTarget(), tex->glId());
-    return checkGLError("Renderer::bindTexture()");
+    return checkGLError("Renderer::bindTexture(" + tex->debugString() + ")");
 }
 
 bool Renderer::unbindTexture(const TextureBase* tex)
 {
     glBindTexture(tex->glTarget(), 0);
-    return checkGLError("Renderer::unbindTexture()");
+    return checkGLError("Renderer::unbindTexture(" + tex->debugString() + ")");
 }
 bool Renderer::enableTexture(const TextureBase* tex)
 {
     glEnable(tex->glTarget());
-    return checkGLError("Renderer::enableTexture()");
+    return checkGLError("Renderer::enableTexture(" + tex->debugString() + ")");
 }
 
 bool Renderer::disableTexture(const TextureBase* tex)
 {
     glDisable(tex->glTarget());
-    return checkGLError("Renderer::disableTexture()");
+    return checkGLError("Renderer::disableTexture(" + tex->debugString() + ")");
 }
 
 void Renderer::setAutoBind(bool bind)
--- trunk/playground/libs/kgllib/core/kgllib/texture.cpp #765820:765821
@@ -36,6 +36,13 @@
     mGLId = 0;
 }
 
+TextureBase::TextureBase(const QString& name)
+{
+    mValid = false;
+    mGLId = 0;
+    setName(name);
+}
+
 TextureBase::~TextureBase()
 {
     if (mGLId) {
@@ -81,7 +88,21 @@
     glTexParameteri(glTarget(), coordinate, mode);
 }
 
+void TextureBase::setName(const QString& name)
+{
+    mName = name;
+}
 
+QString TextureBase::debugString() const
+{
+    if (name().isEmpty()) {
+        return QString("<Texture id %1>").arg(glId());
+    } else {
+        return QString("<Texture name %1>").arg(name());
+    }
+}
+
+
 /*** Texture ***/
 Texture::Texture(int width, int height)
 {
@@ -93,7 +114,7 @@
     mValid = init(img, filter);
 }
 
-Texture::Texture(const QString& filename, GLenum filter)
+Texture::Texture(const QString& filename, GLenum filter) : TextureBase(filename)
 {
     mValid = init(filename, filter);
 }
--- trunk/playground/libs/kgllib/core/kgllib/texture.h #765820:765821
@@ -20,10 +20,12 @@
 
 #include "kgllib.h"
 
+#include <QtCore/QString>
+
+
 class QPixmap;
 class QImage;
 class QRectF;
-class QString;
 
 namespace KGLLib
 {
@@ -44,6 +46,10 @@
      **/
     TextureBase();
     /**
+     * Same as above but also sets texture name to @p name.
+     **/
+    TextureBase(const QString& name);
+    /**
      * Deletes the OpenGL texture associated with this object.
      **/
     virtual ~TextureBase();
@@ -120,6 +126,21 @@
     virtual void setWrapMode(GLenum mode) = 0;
 
     /**
+     * @return name of this texture.
+     * It can be used to identify textures e.g. to ease debugging.
+     **/
+    QString name() const  { return mName; }
+    /**
+     * Sets texture's name to @p name.
+     * The name doesn't have any connection with OpenGL but it can be used
+     *  to identify textures when debugging.
+     **/
+    void setName(const QString& name);
+
+    // TODO: rename?
+    virtual QString debugString() const;
+
+    /**
      * TODO: maybe rename to glType()
      * @return type of this texture (e.g. GL_TEXTURE_2D)
      **/
@@ -135,8 +156,10 @@
 protected:
     bool mValid;
     GLuint mGLId;
+    QString mName;
 };
 
+
 /**
  * @short 2D texture class
  *
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic