From 13305fb5138a6d1df1ac1edd5bd7da5d1a0b54dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Sat, 5 Sep 2020 17:36:53 +0200 Subject: Cleanup: GPUFrameBuffer: Use Texture class instead of gl calls --- source/blender/gpu/intern/gpu_framebuffer.cc | 39 +++++----------------------- 1 file changed, 7 insertions(+), 32 deletions(-) (limited to 'source/blender/gpu/intern') diff --git a/source/blender/gpu/intern/gpu_framebuffer.cc b/source/blender/gpu/intern/gpu_framebuffer.cc index 742fdc6d8b3..6d95e539446 100644 --- a/source/blender/gpu/intern/gpu_framebuffer.cc +++ b/source/blender/gpu/intern/gpu_framebuffer.cc @@ -139,34 +139,20 @@ void FrameBuffer::recursive_downsample(int max_lvl, /* Bind to make sure the frame-buffer is up to date. */ this->bind(true); - if (width_ == 1 && height_ == 1) { - return; - } - /* HACK: Make the frame-buffer appear not bound to avoid assert in GPU_texture_bind. */ - ctx->active_fb = NULL; - - int levels = floor(log2(max_ii(width_, height_))); - max_lvl = min_ii(max_lvl, levels); + /* FIXME(fclem): This assumes all mips are defined which may not be the case. */ + max_lvl = min_ii(max_lvl, floor(log2(max_ii(width_, height_)))); - int current_dim[2] = {width_, height_}; - int mip_lvl; - for (mip_lvl = 1; mip_lvl < max_lvl + 1; mip_lvl++) { - /* calculate next viewport size */ - current_dim[0] = max_ii(current_dim[0] / 2, 1); - current_dim[1] = max_ii(current_dim[1] / 2, 1); + for (int mip_lvl = 1; mip_lvl <= max_lvl; mip_lvl++) { /* Replace attached mip-level for each attachment. */ for (int att = 0; att < ARRAY_SIZE(attachments_); att++) { - GPUTexture *tex = attachments_[att].tex; + Texture *tex = reinterpret_cast(attachments_[att].tex); if (tex != NULL) { /* Some Intel HDXXX have issue with rendering to a mipmap that is below * the texture GL_TEXTURE_MAX_LEVEL. So even if it not correct, in this case * we allow GL_TEXTURE_MAX_LEVEL to be one level lower. In practice it does work! */ - int map_lvl = (GPU_mip_render_workaround()) ? mip_lvl : (mip_lvl - 1); + int mip_max = (GPU_mip_render_workaround()) ? mip_lvl : (mip_lvl - 1); /* Restrict fetches only to previous level. */ - GPU_texture_bind(tex, 0); - glTexParameteri(GPU_texture_target(tex), GL_TEXTURE_BASE_LEVEL, mip_lvl - 1); - glTexParameteri(GPU_texture_target(tex), GL_TEXTURE_MAX_LEVEL, map_lvl); - GPU_texture_unbind(tex); + tex->mip_range_set(mip_lvl - 1, mip_max); /* Bind next level. */ attachments_[att].mip = mip_lvl; } @@ -174,25 +160,14 @@ void FrameBuffer::recursive_downsample(int max_lvl, /* Update the internal attachments and viewport size. */ dirty_attachments_ = true; this->bind(true); - /* HACK: Make the frame-buffer appear not bound to avoid assert in GPU_texture_bind. */ - ctx->active_fb = NULL; callback(userData, mip_lvl); - - /* This is the last mipmap level. Exit loop without incrementing mip_lvl. */ - if (current_dim[0] == 1 && current_dim[1] == 1) { - break; - } } for (int att = 0; att < ARRAY_SIZE(attachments_); att++) { if (attachments_[att].tex != NULL) { /* Reset mipmap level range. */ - GPUTexture *tex = attachments_[att].tex; - GPU_texture_bind(tex, 0); - glTexParameteri(GPU_texture_target(tex), GL_TEXTURE_BASE_LEVEL, 0); - glTexParameteri(GPU_texture_target(tex), GL_TEXTURE_MAX_LEVEL, mip_lvl); - GPU_texture_unbind(tex); + reinterpret_cast(attachments_[att].tex)->mip_range_set(0, max_lvl); /* Reset base level. NOTE: might not be the one bound at the start of this function. */ attachments_[att].mip = 0; } -- cgit v1.2.3