]> git.tdb.fi Git - libs/gl.git/commitdiff
Allow retrieving data from Mesh
authorMikko Rasa <tdb@tdb.fi>
Wed, 17 Oct 2007 06:22:28 +0000 (06:22 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 17 Oct 2007 06:22:28 +0000 (06:22 +0000)
Make use of DataFile::Collection in loading Font

source/font.cpp
source/font.h
source/mesh.h

index 7cea86957dc16568c4119de3943a66e9c1c8e5d4..a19a94e5d13b22670e13c361689669b3d5b71db4 100644 (file)
@@ -16,19 +16,12 @@ namespace GL {
 
 Font::Font():
        tex(0),
-       own_tex(false),
        default_size(1),
        ascent(1),
        descent(0),
        varray((TEXCOORD2, VERTEX2))
 { }
 
-Font::~Font()
-{
-       if(own_tex)
-               delete tex;
-}
-
 void Font::set_texture(const Texture2D &t)
 {
        tex=&t;
@@ -148,13 +141,24 @@ float Font::get_glyph_advance(unsigned code) const
 
 
 Font::Loader::Loader(Font &f):
-       font(f)
+       font(f),
+       coll(0)
 {
-       add("default_size", &Font::default_size);
-       add("ascent",  &Font::ascent);
-       add("descent", &Font::descent);
-       add("texture", &Loader::texture);
-       add("glyph",   &Loader::glyph);
+       init();
+}
+
+Font::Loader::Loader(Font &f, Collection &c):
+       font(f),
+       coll(&c)
+{
+       init();
+}
+
+DataFile::Collection &Font::Loader::get_collection()
+{
+       if(!coll)
+               throw InvalidState("No collection");
+       return *coll;
 }
 
 Font::Loader::~Loader()
@@ -162,13 +166,13 @@ Font::Loader::~Loader()
        font.create_glyph_vertices();
 }
 
-void Font::Loader::texture(const string &t)
+void Font::Loader::init()
 {
-       Texture2D *tex=new Texture2D;
-       tex->parameter(GL_GENERATE_MIPMAP, 1);
-       font.tex=tex;
-       tex->image(t);
-       font.own_tex=true;
+       add("default_size", &Font::default_size);
+       add("ascent",  &Font::ascent);
+       add("descent", &Font::descent);
+       add("texture", &Font::tex);
+       add("glyph",   &Loader::glyph);
 }
 
 void Font::Loader::glyph(unsigned c)
index a55933519b6c792a72bf967a7bdce2d7514afdf1..3178a4c2717ed2f64d6d4e2c72bb413b84056a60 100644 (file)
@@ -10,7 +10,7 @@ Distributed under the LGPL
 
 #include <map>
 #include <string>
-#include <msp/datafile/loader.h>
+#include <msp/datafile/collection.h>
 #include <msp/strings/codec.h>
 #include "vertexarray.h"
 
@@ -22,21 +22,27 @@ class Texture2D;
 class Font
 {
 public:
-       class Loader: public Msp::DataFile::Loader
+       class Loader: public DataFile::Loader
        {
+       private:
+               Font &font;
+               DataFile::Collection *coll;
+
        public:
+               typedef DataFile::Collection Collection;
+
                Loader(Font &);
+               Loader(Font &, DataFile::Collection &);
                ~Loader();
                Font &get_object() { return font; }
+               DataFile::Collection &get_collection();
        private:
-               Font &font;
-
+               void init();
                void texture(const std::string &);
                void glyph(unsigned);
        };
 
        Font();
-       ~Font();
 
        void  set_texture(const Texture2D &);
        void  add_glyph(unsigned, float, float, float, float, float, float, float, float, float);
@@ -88,7 +94,6 @@ private:
        typedef std::map<unsigned, Glyph> GlyphMap;
 
        const Texture2D *tex;
-       bool     own_tex;
        float    default_size;
        float    ascent;
        float    descent;
index 7c80d32263d0b45f7d1bf46c62b33fe992b3f632..4af66a39e25555a7432d90439045f3ba3d8abb10 100644 (file)
@@ -33,6 +33,8 @@ public:
        Mesh(VertexFormat f);
        RefPtr<VertexArrayBuilder> modify_vertices() { return vertices.modify(); }
        void add_batch(const Batch &b);
+       const VertexArray &get_vertices() const { return vertices; }
+       const std::list<Batch> &get_batches() { return batches; }
        void draw() const;
 private:
        VertexArray vertices;