X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexture3d.cpp;h=d22070e680e9d67272a0a7e47d71ffd8aa1a7233;hb=73eec11d44a24bac121f1b0d85f20d58005f3545;hp=36afa9bcdfe9b3fc2dc1e72c5ef8d19bce06f8aa;hpb=194f960f91041ebee44e2745627d5e480e893d82;p=libs%2Fgl.git diff --git a/source/texture3d.cpp b/source/texture3d.cpp index 36afa9bc..d22070e6 100644 --- a/source/texture3d.cpp +++ b/source/texture3d.cpp @@ -1,6 +1,9 @@ #include +#include +#include #include #include +#include #include #include "bindable.h" #include "error.h" @@ -14,7 +17,6 @@ namespace GL { Texture3D::Texture3D(GLenum t): Texture(t), - ifmt(RGB), width(0), height(0), depth(0), @@ -23,7 +25,6 @@ Texture3D::Texture3D(GLenum t): Texture3D::Texture3D(): Texture(GL_TEXTURE_3D), - ifmt(RGB), width(0), height(0), depth(0), @@ -32,34 +33,40 @@ Texture3D::Texture3D(): static Require _req(EXT_texture3D); } -void Texture3D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp) +void Texture3D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned dp, unsigned lv) { if(width>0) throw invalid_operation("Texture3D::storage"); if(wd==0 || ht==0 || dp==0) throw invalid_argument("Texture3D::storage"); - if(MSP_sized_internal_formats) - fmt = get_sized_pixelformat(fmt); - require_pixelformat(fmt); - - ifmt = fmt; + set_internal_format(fmt); width = wd; height = ht; depth = dp; + levels = get_n_levels(); + if(lv>0) + levels = min(levels, lv); } void Texture3D::allocate(unsigned level) { + if(width==0 || height==0 || depth==0) + throw invalid_operation("Texture3D::allocate"); + if(level>=levels) + throw invalid_argument("Texture3D::allocate"); if(allocated&(1< _bind(!ARB_direct_state_access, this); + if(ARB_direct_state_access) + glTextureStorage3D(id, levels, ifmt, width, height, depth); + else + glTexStorage3D(target, levels, ifmt, width, height, depth); + apply_swizzle(); + allocated |= (1< _bind(!ARB_direct_state_access, this); allocate(level); - glTexSubImage3D(target, level, x, y, z, wd, ht, dp, fmt, type, data); + fmt = get_upload_format(fmt); + if(ARB_direct_state_access) + glTextureSubImage3D(id, level, x, y, z, wd, ht, dp, fmt, type, data); + else + glTexSubImage3D(target, level, x, y, z, wd, ht, dp, fmt, type, data); - if(gen_mipmap && level==0) - auto_generate_mipmap(); + if(auto_gen_mipmap && level==0) + generate_mipmap(); } void Texture3D::load_image(const string &fn, int dp) @@ -152,7 +169,7 @@ void Texture3D::load_image(const string &fn, int dp) image(0, fmt, UNSIGNED_BYTE, img.get_data()); } -void Texture3D::image(const Graphics::Image &img, bool srgb) +void Texture3D::image(const Graphics::Image &img, unsigned lv, bool srgb) { unsigned w = img.get_width(); unsigned h = img.get_height(); @@ -175,7 +192,7 @@ void Texture3D::image(const Graphics::Image &img, bool srgb) PixelFormat fmt = pixelformat_from_graphics(img.get_format()); if(width==0) - storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, h, d); + storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, h, d, lv); else if(w!=width || h!=height || d!=depth) throw incompatible_data("Texture3D::load_image"); @@ -232,6 +249,7 @@ void Texture3D::Loader::init() { add("raw_data", &Loader::raw_data); add("storage", &Loader::storage); + add("storage", &Loader::storage_levels); } void Texture3D::Loader::raw_data(const string &data) @@ -241,10 +259,13 @@ void Texture3D::Loader::raw_data(const string &data) void Texture3D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h, unsigned d) { - if(srgb) - fmt = get_srgb_pixelformat(fmt); obj.storage(fmt, w, h, d); } +void Texture3D::Loader::storage_levels(PixelFormat fmt, unsigned w, unsigned h, unsigned d, unsigned l) +{ + obj.storage(fmt, w, h, d, l); +} + } // namespace GL } // namespace Msp