X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexture.cpp;h=cf32ca301cab4bf10bc513ad65de9546c1b757e4;hb=2edfcf08707c3627b6b27289ba607a7183d63b01;hp=772f2d16e8b578fac2fbadbb6ef0f3da6f6f8954;hpb=2ed67ce59027c34f0ae78118d82c70eb1577e949;p=libs%2Fgl.git diff --git a/source/texture.cpp b/source/texture.cpp index 772f2d16..cf32ca30 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -18,13 +18,14 @@ 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 + GL_RED, GL_RED, GL_RED, GL_GREEN, + GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA }; Texture::Texture(GLenum t, ResourceManager *m): id(0), target(t), - ifmt(RGB), + ifmt(RGB8), swizzle(NO_SWIZZLE), auto_gen_mipmap(false), default_sampler(*this) @@ -46,30 +47,32 @@ Texture::~Texture() glDeleteTextures(1, &id); } -DataType Texture::get_alloc_type(PixelFormat fmt) -{ - return (get_base_pixelformat(fmt)==DEPTH_COMPONENT ? UNSIGNED_SHORT : UNSIGNED_BYTE); -} - void Texture::set_internal_format(PixelFormat fmt) { + PixelComponents comp = get_components(fmt); FormatSwizzle swiz = NO_SWIZZLE; - switch(get_base_pixelformat(fmt)) + switch(comp) { case LUMINANCE: - fmt = RED; + comp = RED; swiz = R_TO_LUMINANCE; break; case LUMINANCE_ALPHA: - fmt = RG; + comp = RG; swiz = RG_TO_LUMINANCE_ALPHA; break; + case BGR: + comp = RGB; + swiz = RGB_TO_BGR; + break; + case BGRA: + comp = RGBA; + swiz = RGB_TO_BGR; + break; default:; } - if(!get_component_size(fmt) && OES_required_internalformat) - fmt = get_default_sized_pixelformat(fmt); - + fmt = make_pixelformat(comp, get_component_type(fmt)); require_pixelformat(fmt); if(swiz!=NO_SWIZZLE) static Require _req(ARB_texture_swizzle); @@ -77,12 +80,12 @@ void Texture::set_internal_format(PixelFormat fmt) swizzle = swiz; } -PixelFormat Texture::get_upload_format(PixelFormat fmt) const +PixelComponents Texture::get_upload_components(PixelComponents comp) const { - if(fmt==LUMINANCE || fmt==LUMINANCE_ALPHA) - return get_base_pixelformat(ifmt); + if(comp==LUMINANCE || comp==LUMINANCE_ALPHA || comp==BGR || comp==BGRA) + return get_components(ifmt); else - return fmt; + return comp; } void Texture::apply_swizzle()