Skip to content

Commit

Permalink
⏪ Revert ImagePreview changes
Browse files Browse the repository at this point in the history
  • Loading branch information
riidefi committed Jan 14, 2021
1 parent 8992759 commit 6d9da04
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
23 changes: 11 additions & 12 deletions source/core/3d/ui/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ ImagePreview::~ImagePreview() {
}
}

void ImagePreview::setFromImage(u32 _width, u32 _height, u32 _num_mip,
std::vector<u8>&& _buffer) {
width = _width;
height = _height;
mNumMipMaps = _num_mip;
mDecodeBuf = std::move(_buffer);

void ImagePreview::setFromImage(const lib3d::Texture& tex) {
width = tex.getWidth();
height = tex.getHeight();
mNumMipMaps = tex.getMipmapCount();
mLod = std::min(static_cast<u32>(mLod), mNumMipMaps);
tex.decode(mDecodeBuf, true);

if (mTexUploaded) {
glDeleteTextures(1, &mGpuTexId);
Expand All @@ -42,12 +40,13 @@ void ImagePreview::setFromImage(u32 _width, u32 _height, u32 _num_mip,
GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mNumMipMaps);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, tex.getMipmapCount());
u32 slide = 0;
for (u32 i = 0; i <= mNumMipMaps; ++i) {
glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, width, height >> i, 0, GL_RGBA,
GL_UNSIGNED_BYTE, mDecodeBuf.data() + slide);
slide += (width >> i) * (height >> i) * 4;
for (u32 i = 0; i <= tex.getMipmapCount(); ++i) {
glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, tex.getWidth() >> i,
tex.getHeight() >> i, 0, GL_RGBA, GL_UNSIGNED_BYTE,
mDecodeBuf.data() + slide);
slide += (tex.getWidth() >> i) * (tex.getHeight() >> i) * 4;
}
mDecodeBuf.clear();
}
Expand Down
10 changes: 1 addition & 9 deletions source/core/3d/ui/Image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ class ImagePreview {
public:
ImagePreview();
~ImagePreview();

void setFromImage(u32 width, u32 height,
u32 mNumMipMaps /* image_count - 1 */,
std::vector<u8>&& buffer);
void setFromImage(const lib3d::Texture& tex) {
std::vector<u8> buf(tex.getDecodedSize(true));
tex.decode(buf, true);
setFromImage(tex.getWidth(), tex.getHeight(), tex.getMipmapCount(), std::move(buf));
}
void setFromImage(const lib3d::Texture& tex);

void draw(float width = -1.0f, float height = -1.0f, bool mip_slider = true);

Expand Down

0 comments on commit 6d9da04

Please sign in to comment.