3 #include "texturestate.h"
7 TexImageState::TexImageState():
14 void TexImageState::set_2d(GLenum ifmt, unsigned wd, unsigned ht)
19 internal_format = ifmt;
22 string TexImageState::describe() const
24 string descr = strformat("%d", width);
27 descr += strformat("x%d", height);
29 descr += strformat("x%d", height);
31 descr += strformat(", %s", describe_enum(internal_format, "PixelFormat"));
36 TextureState::TextureState():
39 min_filter(GL_LINEAR_MIPMAP_LINEAR),
40 mag_filter(GL_LINEAR),
44 compare_mode(GL_NONE),
45 compare_func(GL_LEQUAL),
46 generate_mipmap(false)
49 void TextureState::set_image_2d(unsigned level, GLenum ifmt, unsigned wd, unsigned ht)
53 if(images.size()<=level)
54 images.resize(level+1);
55 images[level].set_2d(ifmt, wd, ht);
72 void TextureState::set_parameter(GLenum pname, const int *values)
74 if(pname==GL_TEXTURE_MIN_FILTER)
75 min_filter = values[0];
76 else if(pname==GL_TEXTURE_MAG_FILTER)
77 mag_filter = values[0];
78 else if(pname==GL_TEXTURE_WRAP_S)
80 else if(pname==GL_TEXTURE_WRAP_T)
82 else if(pname==GL_TEXTURE_WRAP_R)
84 else if(pname==GL_TEXTURE_COMPARE_MODE)
85 compare_mode = values[0];
86 else if(pname==GL_TEXTURE_COMPARE_FUNC)
87 compare_func = values[0];
88 else if(pname==GL_GENERATE_MIPMAP)
89 generate_mipmap = values[0];
92 string TextureState::describe() const
94 string descr = describe_enum(target, "TextureTarget");
96 descr += ", undefined";
98 descr += ", "+images.front().describe();
103 TexUnitState::TexUnitState():
108 void TexUnitState::set_current_texture(GLenum target, TextureState *tex)
110 if(target==GL_TEXTURE_2D)
112 else if(target==GL_TEXTURE_3D)
116 TextureState *TexUnitState::get_current_texture(GLenum target)
118 if(target==GL_TEXTURE_2D)
120 else if(target==GL_TEXTURE_3D)
126 const TextureState *TexUnitState::get_current_texture(GLenum target) const
128 return const_cast<TexUnitState *>(this)->get_current_texture(target);
131 string TexUnitState::describe_binding(GLenum target) const
133 if(const TextureState *tex = get_current_texture(target))
135 string descr = strformat("%d ", tex->id);
136 if(tex->images.empty())
137 descr += "(undefined)";
139 descr += "("+tex->images.front().describe()+")";