#include <msp/gl/extensions/arb_direct_state_access.h>
#include <msp/gl/extensions/arb_shadow.h>
+#include <msp/gl/extensions/arb_texture_swizzle.h>
#include <msp/gl/extensions/ext_framebuffer_object.h>
#include <msp/gl/extensions/ext_texture3d.h>
#include <msp/gl/extensions/ext_texture_filter_anisotropic.h>
}
+int Texture::swizzle_orders[] =
+{
+ GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA,
+ GL_RED, GL_RED, GL_RED, GL_ONE,
+ GL_RED, GL_RED, GL_RED, GL_GREEN
+};
+
Texture::Texture(GLenum t, ResourceManager *m):
id(0),
target(t),
fmt = get_sized_pixelformat(fmt, size);
}
+ FormatSwizzle swiz = NO_SWIZZLE;
+ if(ARB_texture_rg && ARB_texture_swizzle)
+ {
+ if(fmt==LUMINANCE8 || fmt==SLUMINANCE8)
+ {
+ fmt = R8;
+ swiz = R_TO_LUMINANCE;
+ }
+ else if(fmt==LUMINANCE8_ALPHA8 || fmt==SLUMINANCE8_ALPHA8)
+ {
+ fmt = RG8;
+ swiz = RG_TO_LUMINANCE_ALPHA;
+ }
+ }
+
require_pixelformat(fmt);
ifmt = fmt;
+ swizzle = swiz;
+ if(swizzle)
+ update_parameter(FORMAT_SWIZZLE);
+}
+
+PixelFormat Texture::get_upload_format(PixelFormat fmt) const
+{
+ if(fmt==LUMINANCE || fmt==LUMINANCE_ALPHA)
+ return get_base_pixelformat(ifmt);
+ else
+ return fmt;
}
void Texture::update_parameter(int mask) const
set_parameter_i(GL_TEXTURE_COMPARE_MODE, (compare ? GL_COMPARE_R_TO_TEXTURE : GL_NONE));
if(mask&COMPARE_FUNC)
set_parameter_i(GL_TEXTURE_COMPARE_FUNC, cmp_func);
+ if(mask&FORMAT_SWIZZLE)
+ {
+ if(ARB_direct_state_access)
+ glTextureParameteriv(id, GL_TEXTURE_SWIZZLE_RGBA, swizzle_orders+swizzle*4);
+ else
+ glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzle_orders+swizzle*4);
+ }
}
void Texture::set_parameter_i(GLenum param, int value) const
update_parameter(WRAP_R);
}
+bool Texture::can_generate_mipmap()
+{
+ return (EXT_framebuffer_object || SGIS_generate_mipmap);
+}
+
void Texture::set_generate_mipmap(bool gm)
{
if(gm && !EXT_framebuffer_object)