]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/graphic.cpp
Cache widget parts in meshes
[libs/gltk.git] / source / graphic.cpp
index 005d30fb4ef8f7929326093766d49ae62332dcbe..0b0ba0e6ef055ee23251b3b40338479f34674a65 100644 (file)
@@ -1,4 +1,3 @@
-#include <msp/gl/immediate.h>
 #include "graphic.h"
 #include "resources.h"
 
@@ -12,7 +11,7 @@ Graphic::Graphic():
        repeat(false)
 { }
 
-void Graphic::render(unsigned wd, unsigned ht) const
+void Graphic::build(unsigned wd, unsigned ht, GL::PrimitiveBuilder &bld) const
 {
        vector<float> x, y;
        create_coords(0.0f-shadow.left, wd+shadow.right, border.left, border.right, slice.w-border.left-border.right, x);
@@ -27,27 +26,25 @@ void Graphic::render(unsigned wd, unsigned ht) const
        unsigned ymin = border.bottom ? 0 : 1;
        unsigned ymax = y.size()-(border.top ? 2 : 3);
 
-       texture->bind();
-       GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
-       imm.color(1.0f, 1.0f, 1.0f);
-       imm.begin(GL::QUADS);
+       bld.color(1.0f, 1.0f, 1.0f);
+       bld.begin(GL::QUADS);
        for(unsigned i=ymin; i<=ymax; ++i)
        {
                unsigned i2 = (i==0 ? 0 : i==y.size()-2 ? 2 : 1);
                for(unsigned j=xmin; j<=xmax; ++j)
                {
                        unsigned j2 = (j==0 ? 0 : j==x.size()-2 ? 2 : 1);
-                       imm.texcoord(u[j2], v[i2]);
-                       imm.vertex(x[j], y[i]);
-                       imm.texcoord(u[j2+1], v[i2]);
-                       imm.vertex(x[j+1], y[i]);
-                       imm.texcoord(u[j2+1], v[i2+1]);
-                       imm.vertex(x[j+1], y[i+1]);
-                       imm.texcoord(u[j2], v[i2+1]);
-                       imm.vertex(x[j], y[i+1]);
+                       bld.texcoord(u[j2], v[i2]);
+                       bld.vertex(x[j], y[i]);
+                       bld.texcoord(u[j2+1], v[i2]);
+                       bld.vertex(x[j+1], y[i]);
+                       bld.texcoord(u[j2+1], v[i2+1]);
+                       bld.vertex(x[j+1], y[i+1]);
+                       bld.texcoord(u[j2], v[i2+1]);
+                       bld.vertex(x[j], y[i+1]);
                }
        }
-       imm.end();
+       bld.end();
 }
 
 void Graphic::create_coords(float low, float high, float brd1, float brd2, float block, vector<float> &coords) const