It was a bad idea and would not translate well to Vulkan.
if st:
mat_res.statements.append(st)
textures = [p.texture for p in material.properties if p.texture]
- if textures and not all(t.default_filter for t in textures):
+ if textures:
from .export_texture import SamplerExporter
- sampler_tex = next(t for t in textures if not t.default_filter)
sampler_export = SamplerExporter()
- mat_res.statements.append(mat_res.create_reference_statement("sampler", resources[sampler_export.get_sampler_name(sampler_tex)]))
+ mat_res.statements.append(mat_res.create_reference_statement("sampler", resources[sampler_export.get_sampler_name(textures[0])]))
return mat_res
if prop.texture:
tex_res = resources[prop.texture.image.name+".tex2d"]
from .util import basename
- fn = basename(prop.texture.image.filepath)
- if prop.texture.default_filter and fn:
- return Statement(prop.tex_keyword, fn)
- else:
- return mat_res.create_reference_statement(prop.tex_keyword, tex_res)
+ return mat_res.create_reference_statement(prop.tex_keyword, tex_res)
elif not prop.keyword:
return
elif type(prop.value)==tuple:
sampler_settings = None
for p in self.properties:
if p.texture:
- settings = (p.texture.default_filter, p.texture.interpolation, p.texture.use_mipmap, p.texture.max_anisotropy)
+ settings = (p.texture.interpolation, p.texture.use_mipmap, p.texture.max_anisotropy)
if sampler_settings is None:
sampler_settings = settings
elif settings!=sampler_settings:
if not node:
return
- self.layout.prop(node, "default_filter")
- if not node.default_filter:
- self.layout.prop(node, "use_mipmap")
- self.layout.prop(node, "max_anisotropy")
+ self.layout.prop(node, "use_mipmap")
+ self.layout.prop(node, "max_anisotropy")
class MspGLLightProperties(bpy.types.Panel):
bl_idname = "LIGHT_PT_mspgl_properties"
bpy.types.Material.uniforms = bpy.props.CollectionProperty(type=MspGLUniform, name="Uniform", description="Uniform variables to add to the technique")
bpy.types.Material.active_uniform_index = bpy.props.IntProperty("Active uniform index")
- bpy.types.ShaderNodeTexImage.default_filter = bpy.props.BoolProperty(name="Default filter", description="Let the loading program determine filtering options")
bpy.types.ShaderNodeTexImage.use_mipmap = bpy.props.BoolProperty(name="Use mipmaps", description="Use mipmaps (automatically generated) for the texture", default=True)
bpy.types.ShaderNodeTexImage.max_anisotropy = bpy.props.FloatProperty(name="Maximum anisotropy", description="Maximum anisotropy to use in texture filtering", min=1, max=16, default=1)
namespace GL {
Sampler::Sampler():
- owner(0)
+ min_filter(NEAREST_MIPMAP_LINEAR),
+ mag_filter(LINEAR),
+ max_anisotropy(1.0f),
+ wrap_s(REPEAT),
+ wrap_t(REPEAT),
+ wrap_r(REPEAT),
+ border_color(Color(0.0f, 0.0f, 0.0f, 0.0f)),
+ compare(false),
+ cmp_func(LEQUAL),
+ dirty_params(0)
{
- init();
-
Require _req(ARB_sampler_objects);
if(ARB_direct_state_access)
glCreateSamplers(1, &id);
glGenSamplers(1, &id);
}
-Sampler::Sampler(const Texture &tex):
- id(0),
- owner(&tex)
-{
- if(this!=&tex.get_default_sampler())
- throw invalid_argument("Sampler::Sampler");
-
- init();
-}
-
-void Sampler::init()
-{
- min_filter = NEAREST_MIPMAP_LINEAR;
- mag_filter = LINEAR;
- max_anisotropy = 1.0f;
- wrap_s = REPEAT;
- wrap_t = REPEAT;
- wrap_r = REPEAT;
- border_color = Color(0.0f, 0.0f, 0.0f, 0.0f);
- compare = false;
- cmp_func = LEQUAL;
- dirty_params = 0;
-}
-
void Sampler::update_parameter(int mask) const
{
- if(owner)
- {
- if(!owner->get_id())
- {
- dirty_params |= mask;
- return;
- }
-
- if(!ARB_direct_state_access && TexUnit::current().get_texture()!=owner)
- {
- TexUnit *unit = TexUnit::find_unit(owner);
- if(!unit)
- {
- dirty_params |= mask;
- return;
- }
-
- unit->bind();
- }
- }
-
if(mask&MIN_FILTER)
- set_parameter_i(GL_TEXTURE_MIN_FILTER, min_filter);
+ glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, min_filter);
if(mask&MAG_FILTER)
- set_parameter_i(GL_TEXTURE_MAG_FILTER, mag_filter);
+ glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, mag_filter);
if(mask&MAX_ANISOTROPY)
- set_parameter_f(GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy);
+ glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy);
if(mask&WRAP_S)
- set_parameter_i(GL_TEXTURE_WRAP_S, wrap_s);
+ glSamplerParameteri(id, GL_TEXTURE_WRAP_S, wrap_s);
if(mask&WRAP_T)
- set_parameter_i(GL_TEXTURE_WRAP_T, wrap_t);
+ glSamplerParameteri(id, GL_TEXTURE_WRAP_T, wrap_t);
if(mask&WRAP_R)
- set_parameter_i(GL_TEXTURE_WRAP_R, wrap_r);
+ glSamplerParameteri(id, GL_TEXTURE_WRAP_R, wrap_r);
if(mask&BORDER_COLOR)
- set_parameter_fv(GL_TEXTURE_BORDER_COLOR, &border_color.r);
+ glSamplerParameterfv(id, GL_TEXTURE_BORDER_COLOR, &border_color.r);
if(mask&COMPARE)
{
- set_parameter_i(GL_TEXTURE_COMPARE_MODE, (compare ? GL_COMPARE_R_TO_TEXTURE : GL_NONE));
+ glSamplerParameteri(id, GL_TEXTURE_COMPARE_MODE, (compare ? GL_COMPARE_R_TO_TEXTURE : GL_NONE));
if(compare)
- set_parameter_i(GL_TEXTURE_COMPARE_FUNC, cmp_func);
+ glSamplerParameteri(id, GL_TEXTURE_COMPARE_FUNC, cmp_func);
}
}
-void Sampler::set_parameter_i(unsigned param, int value) const
-{
- if(id)
- glSamplerParameteri(id, param, value);
- else if(ARB_direct_state_access)
- glTextureParameteri(owner->get_id(), param, value);
- else
- glTexParameteri(owner->get_target(), param, value);
-}
-
-void Sampler::set_parameter_f(unsigned param, float value) const
-{
- if(id)
- glSamplerParameterf(id, param, value);
- else if(ARB_direct_state_access)
- glTextureParameterf(owner->get_id(), param, value);
- else
- glTexParameterf(owner->get_target(), param, value);
-}
-
-void Sampler::set_parameter_fv(unsigned param, const float *value) const
-{
- if(id)
- glSamplerParameterfv(id, param, value);
- else if(ARB_direct_state_access)
- glTextureParameterfv(owner->get_id(), param, value);
- else
- glTexParameterfv(owner->get_target(), param, value);
-}
-
void Sampler::set_min_filter(TextureFilter f)
{
min_filter = f;
static Require _req(ARB_shadow);
compare = true;
cmp_func = f;
- update_parameter(COMPARE);
+ dirty_params |= COMPARE;
}
void Sampler::bind_to(unsigned i) const
{
TexUnit &unit = TexUnit::get_unit(i);
- if(owner && owner!=unit.get_texture())
- throw invalid_operation("Sampler::bind_to");
- const Sampler *cur = unit.get_sampler();
if(unit.set_sampler(this))
{
- if(!owner || (cur && cur->id))
- glBindSampler(i, id);
+ glBindSampler(i, id);
if(dirty_params)
{
void Sampler::unbind_from(unsigned i)
{
TexUnit &unit = TexUnit::get_unit(i);
- const Sampler *cur = unit.get_sampler();
- if(unit.set_sampler(0) && cur->id)
+ if(unit.set_sampler(0))
glBindSampler(i, 0);
}
-void Sampler::unload()
-{
- if(owner && !owner->get_id())
- {
- if(min_filter!=NEAREST_MIPMAP_LINEAR)
- dirty_params |= MIN_FILTER;
- if(mag_filter!=LINEAR)
- dirty_params |= MAG_FILTER;
- if(max_anisotropy!=1.0f)
- dirty_params |= MAX_ANISOTROPY;
- if(wrap_s!=REPEAT)
- dirty_params |= WRAP_S;
- if(wrap_t!=REPEAT)
- dirty_params |= WRAP_T;
- if(wrap_r!=REPEAT)
- dirty_params |= WRAP_R;
- if(compare || cmp_func!=LEQUAL)
- dirty_params |= COMPARE;
- }
-}
-
void Sampler::set_debug_name(const string &name)
{
#ifdef DEBUG
};
unsigned id;
- const Texture *owner;
TextureFilter min_filter;
TextureFilter mag_filter;
float max_anisotropy;
public:
Sampler();
- Sampler(const Texture &);
-private:
- void init();
+private:
void update_parameter(int) const;
void set_parameter_i(unsigned, int) const;
void set_parameter_f(unsigned, float) const;
static void unbind() { unbind_from(0); }
static void unbind_from(unsigned);
- void unload();
-
void set_debug_name(const std::string &);
};
storage_fmt(RGB8),
swizzle(NO_SWIZZLE),
use_srgb_format(false),
- auto_gen_mipmap(false),
- default_sampler(*this)
+ auto_gen_mipmap(false)
{
if(m)
set_manager(m);
glTexParameteri(target, param, value);
}
-void Texture::set_min_filter(TextureFilter f)
-{
- default_sampler.set_min_filter(f);
-}
-
-void Texture::set_mag_filter(TextureFilter f)
-{
- default_sampler.set_mag_filter(f);
-}
-
-void Texture::set_filter(TextureFilter f)
-{
- default_sampler.set_filter(f);
-}
-
-void Texture::set_max_anisotropy(float a)
-{
- default_sampler.set_max_anisotropy(a);
-}
-
-void Texture::set_wrap(TextureWrap w)
-{
- default_sampler.set_wrap(w);
-}
-
-void Texture::set_wrap_s(TextureWrap w)
-{
- default_sampler.set_wrap_s(w);
-}
-
-void Texture::set_wrap_t(TextureWrap w)
-{
- default_sampler.set_wrap_t(w);
-}
-
-void Texture::set_wrap_r(TextureWrap w)
-{
- default_sampler.set_wrap_r(w);
-}
-
bool Texture::can_generate_mipmap()
{
return EXT_framebuffer_object;
auto_gen_mipmap = gm;
}
-void Texture::set_compare_enabled(bool c)
-{
- if(c)
- default_sampler.set_compare(default_sampler.get_compare_function());
- else
- default_sampler.disable_compare();
-}
-
-void Texture::set_compare_func(Predicate f)
-{
- default_sampler.set_compare(f);
-}
-
void Texture::load_image(const string &fn, bool)
{
load_image(fn, 0U);
}
TexUnit &unit = TexUnit::get_unit(i);
- const Texture *cur = unit.get_texture();
if(unit.set_texture(this))
{
if(manager)
unit.bind();
glBindTexture(target, id);
}
-
- if(!unit.get_sampler() || unit.get_sampler()==&cur->default_sampler)
- default_sampler.bind_to(i);
}
}
unit.bind();
glBindTexture(cur->target, 0);
}
-
- if(unit.get_sampler()==&cur->default_sampler)
- Sampler::unbind_from(i);
}
}
add("external_image", &Loader::external_image);
add("external_image_srgb", &Loader::external_image_srgb);
- add("filter", &Loader::filter);
add("generate_mipmap", &Loader::generate_mipmap);
add("image_data", &Loader::image_data);
- add("mag_filter", &Loader::mag_filter);
- add("max_anisotropy", &Loader::max_anisotropy);
- add("min_filter", &Loader::min_filter);
add("mipmap_levels", &Loader::mipmap_levels);
- add("sampler", &Loader::sampler);
- add("wrap", &Loader::wrap);
- add("wrap_r", &Loader::wrap_r);
- add("wrap_s", &Loader::wrap_s);
- add("wrap_t", &Loader::wrap_t);
-}
-
-unsigned Texture::Loader::get_levels() const
-{
- return (is_mipmapped(obj.default_sampler.get_min_filter()) ? levels : 1);
}
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
void Texture::Loader::load_external_image(Graphics::Image &img, const string &fn)
{
RefPtr<IO::Seekable> io = get_collection().open_raw(fn);
{
Graphics::Image img;
load_external_image(img, fn);
- obj.image(img, get_levels());
+ obj.image(img, levels);
}
}
-void Texture::Loader::filter(TextureFilter f)
-{
- obj.set_filter(f);
-}
-
void Texture::Loader::generate_mipmap(bool gm)
{
obj.set_auto_generate_mipmap(gm);
IO::Memory mem(data.data(), data.size());
img.load_io(mem);
- obj.image(img, get_levels());
-}
-
-void Texture::Loader::mag_filter(TextureFilter f)
-{
- obj.set_mag_filter(f);
-}
-
-void Texture::Loader::max_anisotropy(float a)
-{
- obj.set_max_anisotropy(a);
-}
-
-void Texture::Loader::min_filter(TextureFilter f)
-{
- obj.set_min_filter(f);
+ obj.image(img, levels);
}
void Texture::Loader::mipmap_levels(unsigned l)
levels = l;
}
-void Texture::Loader::sampler()
-{
- load_sub(obj.default_sampler);
-}
-
-void Texture::Loader::wrap(TextureWrap w)
-{
- obj.set_wrap(w);
-}
-
-void Texture::Loader::wrap_r(TextureWrap w)
-{
- obj.set_wrap_r(w);
-}
-
-void Texture::Loader::wrap_s(TextureWrap w)
-{
- obj.set_wrap_s(w);
-}
-
-void Texture::Loader::wrap_t(TextureWrap w)
-{
- obj.set_wrap_t(w);
-}
-#pragma GCC diagnostic pop
-
} // namespace GL
} // namespace Msp
private:
void init();
- unsigned get_levels() const;
protected:
void load_external_image(Graphics::Image &, const std::string &);
void external_image(const std::string &);
void external_image_srgb(const std::string &);
void external_image_common(const std::string &);
- void filter(TextureFilter);
void generate_mipmap(bool);
void image_data(const std::string &);
- void mag_filter(TextureFilter);
- void max_anisotropy(float);
- void min_filter(TextureFilter);
void mipmap_levels(unsigned);
- void sampler();
- void wrap(TextureWrap);
- void wrap_r(TextureWrap);
- void wrap_s(TextureWrap);
- void wrap_t(TextureWrap);
};
enum ParameterMask
FormatSwizzle swizzle;
bool use_srgb_format;
bool auto_gen_mipmap;
- Sampler default_sampler;
std::string debug_name;
static int swizzle_orders[];
void set_parameter_i(GLenum, int) const;
public:
- Sampler &get_default_sampler() { return default_sampler; }
- const Sampler &get_default_sampler() const { return default_sampler; }
-
- DEPRECATED void set_min_filter(TextureFilter);
- DEPRECATED void set_mag_filter(TextureFilter);
-
- /** Sets filter for both minification and magnification. Since mipmapping
- is not applicable to magnification, LINEAR is used instead. */
- DEPRECATED void set_filter(TextureFilter);
-
- DEPRECATED void set_mipmap_levels(unsigned) { }
-
- DEPRECATED void set_max_anisotropy(float);
-
- /** Sets the wrapping mode for all coordinates. */
- DEPRECATED void set_wrap(TextureWrap);
-
- DEPRECATED void set_wrap_s(TextureWrap);
- DEPRECATED void set_wrap_t(TextureWrap);
- DEPRECATED void set_wrap_r(TextureWrap);
-
static bool can_generate_mipmap();
void generate_mipmap();
/// Deprecated. Use set_auto_generate_mipmap instead.
DEPRECATED void set_generate_mipmap(bool g) { set_auto_generate_mipmap(g); }
- /** Sets depth texture comparison. Has no effect on other formats. When
- comparison is enabled, the third component of the texture coordinate is
- compared against the texel value, and the result is returned as the texture
- sample. */
- DEPRECATED void set_compare_enabled(bool);
-
- /** Sets the function to use for depth comparison. */
- DEPRECATED void set_compare_func(Predicate);
-
/// Loads a Graphics::Image from a file and uploads it to the texture.
virtual void load_image(const std::string &, unsigned = 0);
glDeleteTextures(1, &id);
id = 0;
allocated = 0;
- default_sampler.unload();
}
{
tgt.texture = new Texture2D;
tgt.texture->storage(pf, width, height, 1);
- Sampler &sampler = tgt.texture->get_default_sampler();
- sampler.set_filter(NEAREST);
- sampler.set_wrap(CLAMP_TO_EDGE);
fbo.attach(att, *tgt.texture);
}
buffers.push_back(tgt);
}
}
-void RenderTarget::set_texture_filter(TextureFilter filt)
-{
- if(!samples)
- {
- for(vector<TargetBuffer>::iterator i=buffers.begin(); i!=buffers.end(); ++i)
- i->texture->get_default_sampler().set_filter(filt);
- }
-}
-
const Texture2D &RenderTarget::get_target_texture(unsigned i) const
{
if(i>=buffers.size())
unsigned get_height() const { return height; }
const RenderTargetFormat &get_format() const { return format; }
Framebuffer &get_framebuffer() { return fbo; }
- void set_texture_filter(TextureFilter);
const Texture2D &get_target_texture(unsigned) const;
const Texture2D &get_target_texture(RenderOutput) const;
void blit_from(const RenderTarget &);
Resources *Resources::global_resources = 0;
Resources::Resources(bool set_as_global):
- default_tex_filter(Texture::can_generate_mipmap() ? LINEAR_MIPMAP_LINEAR : LINEAR),
- default_tex_anisotropy(1.0f),
srgb_conversion(false),
resource_manager(0)
{
return builtins;
}
-void Resources::set_default_texture_filter(TextureFilter tf)
-{
- default_tex_filter = tf;
-}
-
-void Resources::set_default_texture_anisotropy(float a)
-{
- default_tex_anisotropy = a;
-}
-
void Resources::set_srgb_conversion(bool c)
{
srgb_conversion = c;
image.load_io(*io);
tex = new Texture2D(resource_manager);
- Sampler &samp = tex->get_default_sampler();
- if(is_mipmapped(default_tex_filter))
- {
- tex->set_auto_generate_mipmap(true);
- samp.set_mag_filter(LINEAR);
- }
- else
- samp.set_mag_filter(default_tex_filter);
- samp.set_min_filter(default_tex_filter);
- samp.set_max_anisotropy(default_tex_anisotropy);
if(resource_manager)
resource_manager->set_resource_location(*tex, *this, name);
};
private:
- TextureFilter default_tex_filter;
- float default_tex_anisotropy;
bool srgb_conversion;
ResourceManager *resource_manager;
static Resources &get_global();
static const DataFile::CollectionSource &get_builtins();
- void set_default_texture_filter(TextureFilter);
- void set_default_texture_anisotropy(float);
-
/** Enables or disables sRGB conversion. If enabled, textures and material
colors are converted from sRGB to linear color space when loaded. */
DEPRECATED void set_srgb_conversion(bool);