3 This file is part of gldbg
4 Copyright © 2009-2011 Mikko Rasa, Mikkosoft Productions
5 Distributed under the GPL
10 #include "texturestate.h"
14 TexImageState::TexImageState():
21 void TexImageState::set_2d(GLenum ifmt, unsigned wd, unsigned ht)
26 internal_format = ifmt;
29 string TexImageState::describe() const
31 string descr = strformat("%d", width);
34 descr += strformat("x%d", height);
36 descr += strformat("x%d", height);
38 descr += strformat(", %s", describe_enum(internal_format, "PixelFormat"));
43 TextureState::TextureState():
46 min_filter(GL_LINEAR_MIPMAP_LINEAR),
47 mag_filter(GL_LINEAR),
51 compare_mode(GL_NONE),
52 compare_func(GL_LEQUAL),
53 generate_mipmap(false)
56 void TextureState::set_image_2d(unsigned level, GLenum ifmt, unsigned wd, unsigned ht)
60 if(images.size()<=level)
61 images.resize(level+1);
62 images[level].set_2d(ifmt, wd, ht);
79 void TextureState::set_parameter(GLenum pname, const int *values)
81 if(pname==GL_TEXTURE_MIN_FILTER)
82 min_filter = values[0];
83 else if(pname==GL_TEXTURE_MAG_FILTER)
84 mag_filter = values[0];
85 else if(pname==GL_TEXTURE_WRAP_S)
87 else if(pname==GL_TEXTURE_WRAP_T)
89 else if(pname==GL_TEXTURE_WRAP_R)
91 else if(pname==GL_TEXTURE_COMPARE_MODE)
92 compare_mode = values[0];
93 else if(pname==GL_TEXTURE_COMPARE_FUNC)
94 compare_func = values[0];
95 else if(pname==GL_GENERATE_MIPMAP)
96 generate_mipmap = values[0];
99 string TextureState::describe() const
101 string descr = describe_enum(target, "TextureTarget");
103 descr += ", undefined";
105 descr += ", "+images.front().describe();
110 TexUnitState::TexUnitState():
115 void TexUnitState::set_current_texture(GLenum target, TextureState *tex)
117 if(target==GL_TEXTURE_2D)
119 else if(target==GL_TEXTURE_3D)
123 TextureState *TexUnitState::get_current_texture(GLenum target)
125 if(target==GL_TEXTURE_2D)
127 else if(target==GL_TEXTURE_3D)
133 const TextureState *TexUnitState::get_current_texture(GLenum target) const
135 return const_cast<TexUnitState *>(this)->get_current_texture(target);
138 string TexUnitState::describe_binding(GLenum target) const
140 if(const TextureState *tex = get_current_texture(target))
142 string descr = strformat("%d ", tex->id);
143 if(tex->images.empty())
144 descr += "(undefined)";
146 descr += "("+tex->images.front().describe()+")";