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

List:       kde-commits
Subject:    playground/libs/kgllib/extras/kgllib
From:       Rivo Laks <rivolaks () hot ! ee>
Date:       2008-03-30 15:56:33
Message-ID: 1206892593.137147.10026.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 791870 by rivol:

Mesh can now have multiple textures (for multitexturing)

 M  +25 -8     mesh.cpp  
 M  +7 -3      mesh.h  


--- trunk/playground/libs/kgllib/extras/kgllib/mesh.cpp #791869:791870
@@ -26,7 +26,6 @@
 
 Mesh::Mesh() : Batch()
 {
-    mTexture = 0;
     mProgram = 0;
 }
 
@@ -34,11 +33,23 @@
 {
 }
 
-void Mesh::setTexture(KGLLib::Texture* tex)
+void Mesh::setTexture(int index, KGLLib::Texture* tex)
 {
-    mTexture = tex;
+    if (index >= mTextures.count()) {
+        mTextures.resize(index+1);
+    }
+    mTextures[index] = tex;
 }
 
+KGLLib::Texture* Mesh::texture(int index) const
+{
+    if (index < 0 || index >= mTextures.count()) {
+        return 0;
+    } else {
+        return mTextures[index];
+    }
+}
+
 void Mesh::setProgram(KGLLib::Program* program)
 {
     mProgram = program;
@@ -47,8 +58,11 @@
 void Mesh::render()
 {
     // Bind texture and program if they're set
-    if (mTexture) {
-        mTexture->enable();
+    for (int i = mTextures.count()-1; i >= 0; i--) {
+        if (mTextures[i]) {
+            glActiveTexture(GL_TEXTURE0 + i);
+            mTextures[i]->enable();
+        }
     }
     if (mProgram) {
         mProgram->bind();
@@ -58,9 +72,12 @@
     Batch::render();
 
     // Unbind
-    if (mTexture) {
-        // TODO: maybe just unbind? Maybe do nothing? Maybe have an option?
-        mTexture->disable();
+    for (int i = mTextures.count()-1; i >= 0; i--) {
+        if (mTextures[i]) {
+            // TODO: maybe just unbind? Maybe do nothing? Maybe have an option?
+            glActiveTexture(GL_TEXTURE0 + i);
+            mTextures[i]->disable();
+        }
     }
     if (mProgram) {
         mProgram->unbind();
--- trunk/playground/libs/kgllib/extras/kgllib/mesh.h #791869:791870
@@ -20,7 +20,9 @@
 
 #include "batch.h"
 
+#include <QtCore/QVector>
 
+
 namespace KGLLib
 {
 class Texture;
@@ -34,8 +36,10 @@
 
     virtual void render();
 
-    virtual void setTexture(KGLLib::Texture* tex);
-    KGLLib::Texture* texture() const  { return mTexture; }
+    void setTexture(KGLLib::Texture* tex)  { setTexture(0, tex); }
+    KGLLib::Texture* texture() const  { return texture(0); }
+    virtual void setTexture(int index, KGLLib::Texture* tex);
+    KGLLib::Texture* texture(int index) const;
 
     virtual void setProgram(KGLLib::Program* program);
     KGLLib::Program* program() const  { return mProgram; }
@@ -43,7 +47,7 @@
 protected:
 
 private:
-    KGLLib::Texture* mTexture;
+    QVector<KGLLib::Texture*> mTextures;
     KGLLib::Program* mProgram;
 };
 
[prev in list] [next in list] [prev in thread] [next in thread] 

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