3 This file is part of gldbg
4 Copyright © 2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the GPL
8 #include <msp/strings/formatter.h>
10 #include "texturestate.h"
15 TexImageState::TexImageState():
22 void TexImageState::set_2d(GLenum ifmt, unsigned wd, unsigned ht)
27 internal_format = ifmt;
30 string TexImageState::describe() const
32 string descr = format("%d", width);
35 descr += format("x%d", height);
37 descr += format("x%d", height);
39 descr += format(", %s", describe_enum(internal_format, "PixelFormat"));
44 TextureState::TextureState():
47 min_filter(GL_LINEAR_MIPMAP_LINEAR),
48 mag_filter(GL_LINEAR),
52 compare_mode(GL_NONE),
53 compare_func(GL_LEQUAL),
54 generate_mipmap(false)
57 void TextureState::set_image_2d(unsigned level, GLenum ifmt, unsigned wd, unsigned ht)
61 if(images.size()<=level)
62 images.resize(level+1);
63 images[level].set_2d(ifmt, wd, ht);
80 void TextureState::set_parameter(GLenum pname, const int *values)
82 if(pname==GL_TEXTURE_MIN_FILTER)
83 min_filter = values[0];
84 else if(pname==GL_TEXTURE_MAG_FILTER)
85 mag_filter = values[0];
86 else if(pname==GL_TEXTURE_WRAP_S)
88 else if(pname==GL_TEXTURE_WRAP_T)
90 else if(pname==GL_TEXTURE_WRAP_R)
92 else if(pname==GL_TEXTURE_COMPARE_MODE)
93 compare_mode = values[0];
94 else if(pname==GL_TEXTURE_COMPARE_FUNC)
95 compare_func = values[0];
96 else if(pname==GL_GENERATE_MIPMAP)
97 generate_mipmap = values[0];
100 string TextureState::describe() const
102 string descr = describe_enum(target, "TextureTarget");
104 descr += ", undefined";
106 descr += format(", %s", images.front().describe());
111 TexUnitState::TexUnitState():
116 void TexUnitState::set_current_texture(GLenum target, TextureState *tex)
118 if(target==GL_TEXTURE_2D)
120 else if(target==GL_TEXTURE_3D)
124 TextureState *TexUnitState::get_current_texture(GLenum target)
126 if(target==GL_TEXTURE_2D)
128 else if(target==GL_TEXTURE_3D)
134 const TextureState *TexUnitState::get_current_texture(GLenum target) const
136 return const_cast<TexUnitState *>(this)->get_current_texture(target);
139 string TexUnitState::describe_binding(GLenum target) const
141 if(const TextureState *tex = get_current_texture(target))
143 string descr = format("%d ", tex->id);
144 if(tex->images.empty())
145 descr += "(undefined)";
147 descr += format("(%s)", tex->images.front().describe());