]> git.tdb.fi Git - gldbg.git/blobdiff - flavors/gl/source/texturestate.cpp
Move the profiler and inspector tools to the gl flavor
[gldbg.git] / flavors / gl / source / texturestate.cpp
diff --git a/flavors/gl/source/texturestate.cpp b/flavors/gl/source/texturestate.cpp
new file mode 100644 (file)
index 0000000..187707c
--- /dev/null
@@ -0,0 +1,152 @@
+/* $Id$
+
+This file is part of gldbg
+Copyright © 2009  Mikko Rasa, Mikkosoft Productions
+Distributed under the GPL
+*/
+
+#include <msp/strings/formatter.h>
+#include "enums.h"
+#include "texturestate.h"
+
+using namespace std;
+using namespace Msp;
+
+TexImageState::TexImageState():
+       width(0),
+       height(0),
+       depth(0),
+       internal_format(0)
+{ }
+
+void TexImageState::set_2d(GLenum ifmt, unsigned wd, unsigned ht)
+{
+       width = wd;
+       height = ht;
+       depth = 0;
+       internal_format = ifmt;
+}
+
+string TexImageState::describe() const
+{
+       string descr = format("%d", width);
+       if(height)
+       {
+               descr += format("x%d", height);
+               if(depth)
+                       descr += format("x%d", height);
+       }
+       descr += format(", %s", describe_enum(internal_format, "PixelFormat"));
+       return descr;
+}
+
+
+TextureState::TextureState():
+       id(0),
+       target(0),
+       min_filter(GL_LINEAR_MIPMAP_LINEAR),
+       mag_filter(GL_LINEAR),
+       wrap_s(GL_REPEAT),
+       wrap_t(GL_REPEAT),
+       wrap_r(GL_REPEAT),
+       compare_mode(GL_NONE),
+       compare_func(GL_LEQUAL),
+       generate_mipmap(false)
+{ }
+
+void TextureState::set_image_2d(unsigned level, GLenum ifmt, unsigned wd, unsigned ht)
+{
+       while(1)
+       {
+               if(images.size()<=level)
+                       images.resize(level+1);
+               images[level].set_2d(ifmt, wd, ht);
+
+               if(generate_mipmap)
+               {
+                       if(wd==1 && ht==1)
+                               break;
+                       ++level;
+                       if(wd>1)
+                               wd /= 2;
+                       if(ht>1)
+                               ht /= 2;
+               }
+               else
+                       break;
+       }
+}
+
+void TextureState::set_parameter(GLenum pname, const int *values)
+{
+       if(pname==GL_TEXTURE_MIN_FILTER)
+               min_filter = values[0];
+       else if(pname==GL_TEXTURE_MAG_FILTER)
+               mag_filter = values[0];
+       else if(pname==GL_TEXTURE_WRAP_S)
+               wrap_s = values[0];
+       else if(pname==GL_TEXTURE_WRAP_T)
+               wrap_t = values[0];
+       else if(pname==GL_TEXTURE_WRAP_R)
+               wrap_r = values[0];
+       else if(pname==GL_TEXTURE_COMPARE_MODE)
+               compare_mode = values[0];
+       else if(pname==GL_TEXTURE_COMPARE_FUNC)
+               compare_func = values[0];
+       else if(pname==GL_GENERATE_MIPMAP)
+               generate_mipmap = values[0];
+}
+
+string TextureState::describe() const
+{
+       string descr = describe_enum(target, "TextureTarget");
+       if(images.empty())
+               descr += ", undefined";
+       else
+               descr += format(", %s", images.front().describe());
+       return descr;
+}
+
+
+TexUnitState::TexUnitState():
+       current_2d(0),
+       current_3d(0)
+{ }
+
+void TexUnitState::set_current_texture(GLenum target, TextureState *tex)
+{
+       if(target==GL_TEXTURE_2D)
+               current_2d = tex;
+       else if(target==GL_TEXTURE_3D)
+               current_3d = tex;
+}
+
+TextureState *TexUnitState::get_current_texture(GLenum target)
+{
+       if(target==GL_TEXTURE_2D)
+               return current_2d;
+       else if(target==GL_TEXTURE_3D)
+               return current_3d;
+       else
+               return 0;
+}
+
+const TextureState *TexUnitState::get_current_texture(GLenum target) const
+{
+       return const_cast<TexUnitState *>(this)->get_current_texture(target);
+}
+
+string TexUnitState::describe_binding(GLenum target) const
+{
+       if(const TextureState *tex = get_current_texture(target))
+       {
+               string descr = format("%d ", tex->id);
+               if(tex->images.empty())
+                       descr += "(undefined)";
+               else
+                       descr += format("(%s)", tex->images.front().describe());
+               return descr;
+       }
+       else
+               return "None";
+}