X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphic.cpp;h=75e10888ecde2eebef7202659aaf21320520fba8;hb=b3234ca0277c5e282a2a0a2558b58edb25750653;hp=01bfcdb6a177db0fc16d8acf04498fcb4db47124;hpb=a38c924ff32081f5cd67c2b0e2d5ca61f0e99de2;p=libs%2Fgltk.git diff --git a/source/graphic.cpp b/source/graphic.cpp index 01bfcdb..75e1088 100644 --- a/source/graphic.cpp +++ b/source/graphic.cpp @@ -1,4 +1,3 @@ -#include #include "graphic.h" #include "resources.h" @@ -12,11 +11,8 @@ Graphic::Graphic(): repeat(false) { } -void Graphic::render(unsigned wd, unsigned ht) const +void Graphic::build(unsigned wd, unsigned ht, GL::PrimitiveBuilder &bld) const { - GL::VertexArray varr((GL::TEXCOORD2, GL::VERTEX2)); - RefPtr vab=varr.modify(); - vector x, y; create_coords(0.0f-shadow.left, wd+shadow.right, border.left, border.right, slice.w-border.left-border.right, x); create_coords(0.0f-shadow.bottom, ht+shadow.top, border.bottom, border.top, slice.h-border.bottom-border.top, y); @@ -25,31 +21,35 @@ void Graphic::render(unsigned wd, unsigned ht) const create_texcoords(slice.x, slice.x+slice.w, border.left, border.right, texture->get_width(), u); create_texcoords(slice.y, slice.y+slice.h, border.bottom, border.top, texture->get_height(), v); - unsigned xmin=border.left ? 0 : 1; - unsigned xmax=x.size()-(border.right ? 2 : 3); - unsigned ymin=border.bottom ? 0 : 1; - unsigned ymax=y.size()-(border.top ? 2 : 3); + unsigned xmin = border.left ? 0 : 1; + unsigned xmax = x.size()-(border.right ? 2 : 3); + unsigned ymin = border.bottom ? 0 : 1; + unsigned ymax = y.size()-(border.top ? 2 : 3); - texture->bind(); - GL::Immediate imm((GL::TEXCOORD2,GL::VERTEX2)); - imm.begin(GL::QUADS); + bld.color(1.0f, 1.0f, 1.0f); for(unsigned i=ymin; i<=ymax; ++i) { - unsigned i2=(i==0 ? 0 : i==y.size()-2 ? 2 : 1); + 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]); + unsigned j2 = (j==0 ? 0 : j==x.size()-2 ? 2 : 1); + if(j==xmin || (j>1 && jxmin) + bld.end(); + bld.begin(GL::TRIANGLE_STRIP); + bld.texcoord(u[j2], v[i2+1]); + bld.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+1]); + bld.vertex(x[j+1], y[i+1]); + bld.texcoord(u[j2+1], v[i2]); + bld.vertex(x[j+1], y[i]); } + bld.end(); } - imm.end(); } void Graphic::create_coords(float low, float high, float brd1, float brd2, float block, vector &coords) const @@ -58,9 +58,9 @@ void Graphic::create_coords(float low, float high, float brd1, float brd2, float coords.push_back(low+brd1); if(repeat) { - float space=high-low-brd1-brd2; - unsigned div=max(static_cast(space/block), 1U); - float delta=space/div; + float space = high-low-brd1-brd2; + unsigned div = max(static_cast(space/block), 1U); + float delta = space/div; for(unsigned i=1; i(g, &r) { add("texture", &Loader::texture); add("slice", &Loader::slice); @@ -90,23 +89,23 @@ Graphic::Loader::Loader(Graphic &g, Resources &r): void Graphic::Loader::texture(const string &n) { - graph.texture=res.get(n); - graph.slice=Geometry(0, 0, graph.texture->get_width(), graph.texture->get_height()); + obj.texture = &get_collection().get(n); + obj.slice = Geometry(0, 0, obj.texture->get_width(), obj.texture->get_height()); } void Graphic::Loader::slice(unsigned x, unsigned y, unsigned w, unsigned h) { - graph.slice=Geometry(x, y, w, h); + obj.slice = Geometry(x, y, w, h); } void Graphic::Loader::border() { - load_sub(graph.border); + load_sub(obj.border); } void Graphic::Loader::shadow() { - load_sub(graph.shadow); + load_sub(obj.shadow); } } // namespace GLtk