X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Ftexture.cpp;h=b747a2a6b0d7001b3d06e7a2811f91e93f075e78;hb=42293e1bd6f3d6297a1d0207ca69e7864a7d76e8;hp=90e3bb17f11de1c318f6670a28ce61a17a13a88b;hpb=73eec11d44a24bac121f1b0d85f20d58005f3545;p=libs%2Fgl.git diff --git a/source/texture.cpp b/source/texture.cpp index 90e3bb17..b747a2a6 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -18,13 +18,15 @@ 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), + format(RGB8), + storage_fmt(RGB8), swizzle(NO_SWIZZLE), auto_gen_mipmap(false), default_sampler(*this) @@ -46,41 +48,40 @@ Texture::~Texture() glDeleteTextures(1, &id); } -DataType Texture::get_alloc_type(PixelFormat fmt) +void Texture::set_format(PixelFormat fmt) { - return (get_base_pixelformat(fmt)==DEPTH_COMPONENT ? UNSIGNED_SHORT : UNSIGNED_BYTE); -} - -void Texture::set_internal_format(PixelFormat fmt) -{ - swizzle = NO_SWIZZLE; - if(ARB_texture_rg && ARB_texture_swizzle) + PixelComponents comp = get_components(fmt); + PixelComponents st_comp = comp; + FormatSwizzle swiz = NO_SWIZZLE; + switch(comp) { - if(fmt==LUMINANCE) - { - fmt = RED; - swizzle = R_TO_LUMINANCE; - } - else if(fmt==LUMINANCE_ALPHA) - { - fmt = RG; - swizzle = RG_TO_LUMINANCE_ALPHA; - } + case LUMINANCE: + st_comp = RED; + swiz = R_TO_LUMINANCE; + break; + case LUMINANCE_ALPHA: + st_comp = RG; + swiz = RG_TO_LUMINANCE_ALPHA; + break; + case BGR: + st_comp = RGB; + swiz = RGB_TO_BGR; + break; + case BGRA: + st_comp = RGBA; + swiz = RGB_TO_BGR; + break; + default:; } - if(!get_component_size(fmt) && OES_required_internalformat) - fmt = get_default_sized_pixelformat(fmt); - - require_pixelformat(fmt); - ifmt = fmt; -} + PixelFormat st_fmt = make_pixelformat(st_comp, get_component_type(fmt)); + require_pixelformat(st_fmt); + if(swiz!=NO_SWIZZLE) + static Require _req(ARB_texture_swizzle); -PixelFormat Texture::get_upload_format(PixelFormat fmt) const -{ - if(fmt==LUMINANCE || fmt==LUMINANCE_ALPHA) - return get_base_pixelformat(ifmt); - else - return fmt; + format = fmt; + storage_fmt = st_fmt; + swizzle = swiz; } void Texture::apply_swizzle()