Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/opengl/gl_texture.cc
| Show All 19 Lines | |||||
| /** \file | /** \file | ||||
| * \ingroup gpu | * \ingroup gpu | ||||
| */ | */ | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "DNA_userdef_types.h" | #include "DNA_userdef_types.h" | ||||
| #include "GPU_extensions.h" | #include "GPU_capabilities.h" | ||||
| #include "GPU_framebuffer.h" | #include "GPU_framebuffer.h" | ||||
| #include "GPU_platform.h" | #include "GPU_platform.h" | ||||
| #include "gl_backend.hh" | #include "gl_backend.hh" | ||||
| #include "gl_debug.hh" | #include "gl_debug.hh" | ||||
| #include "gl_state.hh" | #include "gl_state.hh" | ||||
| #include "gpu_vertex_buffer_private.hh" /* TODO shoud be gl_vertex_buffer.hh */ | #include "gpu_vertex_buffer_private.hh" /* TODO shoud be gl_vertex_buffer.hh */ | ||||
| Show All 17 Lines | GLTexture::~GLTexture() | ||||
| if (framebuffer_) { | if (framebuffer_) { | ||||
| GPU_framebuffer_free(framebuffer_); | GPU_framebuffer_free(framebuffer_); | ||||
| } | } | ||||
| GPUContext *ctx = GPU_context_active_get(); | GPUContext *ctx = GPU_context_active_get(); | ||||
| if (ctx != NULL && is_bound_) { | if (ctx != NULL && is_bound_) { | ||||
| /* This avoid errors when the texture is still inside the bound texture array. */ | /* This avoid errors when the texture is still inside the bound texture array. */ | ||||
| ctx->state_manager->texture_unbind(this); | ctx->state_manager->texture_unbind(this); | ||||
| } | } | ||||
| GLBackend::get()->tex_free(tex_id_); | GLContext::tex_free(tex_id_); | ||||
| } | } | ||||
| /* Return true on success. */ | /* Return true on success. */ | ||||
| bool GLTexture::init_internal(void) | bool GLTexture::init_internal(void) | ||||
| { | { | ||||
| if ((format_ == GPU_DEPTH24_STENCIL8) && GPU_depth_blitting_workaround()) { | if ((format_ == GPU_DEPTH24_STENCIL8) && GPU_depth_blitting_workaround()) { | ||||
| /* MacOS + Radeon Pro fails to blit depth on GPU_DEPTH24_STENCIL8 | /* MacOS + Radeon Pro fails to blit depth on GPU_DEPTH24_STENCIL8 | ||||
| * but works on GPU_DEPTH32F_STENCIL8. */ | * but works on GPU_DEPTH32F_STENCIL8. */ | ||||
| format_ = GPU_DEPTH32F_STENCIL8; | format_ = GPU_DEPTH32F_STENCIL8; | ||||
| } | } | ||||
| if ((type_ == GPU_TEXTURE_CUBE_ARRAY) && !GPU_arb_texture_cube_map_array_is_supported()) { | if ((type_ == GPU_TEXTURE_CUBE_ARRAY) && (GLContext::texture_cube_map_array_support == false)) { | ||||
| debug::raise_gl_error("Attempt to create a cubemap array without hardware support!"); | /* Silently fail and let the caller handle the error. */ | ||||
| // debug::raise_gl_error("Attempt to create a cubemap array without hardware support!"); | |||||
| return false; | return false; | ||||
| } | } | ||||
| target_ = to_gl_target(type_); | target_ = to_gl_target(type_); | ||||
| /* We need to bind once to define the texture type. */ | /* We need to bind once to define the texture type. */ | ||||
| GLContext::state_manager_active_get()->texture_bind_temp(this); | GLContext::state_manager_active_get()->texture_bind_temp(this); | ||||
| Show All 22 Lines | #endif | ||||
| GL_CHECK_ERROR("Post-texture creation"); | GL_CHECK_ERROR("Post-texture creation"); | ||||
| return true; | return true; | ||||
| } | } | ||||
| /* Return true on success. */ | /* Return true on success. */ | ||||
| bool GLTexture::init_internal(GPUVertBuf *vbo) | bool GLTexture::init_internal(GPUVertBuf *vbo) | ||||
| { | { | ||||
| GLVertBuf *gl_vbo = static_cast<GLVertBuf *>(unwrap(vbo)); | |||||
| target_ = to_gl_target(type_); | target_ = to_gl_target(type_); | ||||
| /* We need to bind once to define the texture type. */ | /* We need to bind once to define the texture type. */ | ||||
| GLContext::state_manager_active_get()->texture_bind_temp(this); | GLContext::state_manager_active_get()->texture_bind_temp(this); | ||||
| GLenum internal_format = to_gl_internal_format(format_); | GLenum internal_format = to_gl_internal_format(format_); | ||||
| if (GLEW_ARB_direct_state_access) { | if (GLEW_ARB_direct_state_access) { | ||||
| glTextureBuffer(tex_id_, internal_format, vbo->vbo_id); | glTextureBuffer(tex_id_, internal_format, gl_vbo->vbo_id_); | ||||
| } | } | ||||
| else { | else { | ||||
| glTexBuffer(target_, internal_format, vbo->vbo_id); | glTexBuffer(target_, internal_format, gl_vbo->vbo_id_); | ||||
| } | } | ||||
| #ifndef __APPLE__ | #ifndef __APPLE__ | ||||
| if ((G.debug & G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) { | if ((G.debug & G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) { | ||||
| char sh_name[64]; | char sh_name[64]; | ||||
| SNPRINTF(sh_name, "Texture-%s", name_); | SNPRINTF(sh_name, "Texture-%s", name_); | ||||
| /* Binding before setting the label is needed on some drivers. */ | /* Binding before setting the label is needed on some drivers. */ | ||||
| glObjectLabel(GL_TEXTURE, tex_id_, -1, sh_name); | glObjectLabel(GL_TEXTURE, tex_id_, -1, sh_name); | ||||
| ▲ Show 20 Lines • Show All 229 Lines • ▼ Show 20 Lines | void GLTexture::copy_to(Texture *dst_) | ||||
| GLTexture *src = this; | GLTexture *src = this; | ||||
| BLI_assert((dst->w_ == src->w_) && (dst->h_ == src->h_) && (dst->d_ == src->d_)); | BLI_assert((dst->w_ == src->w_) && (dst->h_ == src->h_) && (dst->d_ == src->d_)); | ||||
| BLI_assert(dst->format_ == src->format_); | BLI_assert(dst->format_ == src->format_); | ||||
| BLI_assert(dst->type_ == src->type_); | BLI_assert(dst->type_ == src->type_); | ||||
| /* TODO support array / 3D textures. */ | /* TODO support array / 3D textures. */ | ||||
| BLI_assert(dst->d_ == 0); | BLI_assert(dst->d_ == 0); | ||||
| if (GLEW_ARB_copy_image && !GPU_texture_copy_workaround()) { | if (GLEW_ARB_copy_image && !GLContext::texture_copy_workaround) { | ||||
| /* Opengl 4.3 */ | /* Opengl 4.3 */ | ||||
| int mip = 0; | int mip = 0; | ||||
| /* NOTE: mip_size_get() won't override any dimension that is equal to 0. */ | /* NOTE: mip_size_get() won't override any dimension that is equal to 0. */ | ||||
| int extent[3] = {1, 1, 1}; | int extent[3] = {1, 1, 1}; | ||||
| this->mip_size_get(mip, extent); | this->mip_size_get(mip, extent); | ||||
| glCopyImageSubData( | glCopyImageSubData( | ||||
| src->tex_id_, target_, mip, 0, 0, 0, dst->tex_id_, target_, mip, 0, 0, 0, UNPACK3(extent)); | src->tex_id_, target_, mip, 0, 0, 0, dst->tex_id_, target_, mip, 0, 0, 0, UNPACK3(extent)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | |||||
| * \{ */ | * \{ */ | ||||
| /* NOTE: This only checks if this mipmap is valid / supported. | /* NOTE: This only checks if this mipmap is valid / supported. | ||||
| * TODO(fclem) make the check cover the whole mipmap chain. */ | * TODO(fclem) make the check cover the whole mipmap chain. */ | ||||
| bool GLTexture::proxy_check(int mip) | bool GLTexture::proxy_check(int mip) | ||||
| { | { | ||||
| /* Manual validation first, since some implementation have issues with proxy creation. */ | /* Manual validation first, since some implementation have issues with proxy creation. */ | ||||
| int max_size = GPU_max_texture_size(); | int max_size = GPU_max_texture_size(); | ||||
| int max_3d_size = GPU_max_texture_3d_size(); | int max_3d_size = GLContext::max_texture_3d_size; | ||||
| int max_cube_size = GPU_max_cube_map_size(); | int max_cube_size = GLContext::max_cubemap_size; | ||||
| int size[3] = {1, 1, 1}; | int size[3] = {1, 1, 1}; | ||||
| this->mip_size_get(mip, size); | this->mip_size_get(mip, size); | ||||
| if (type_ & GPU_TEXTURE_ARRAY) { | if (type_ & GPU_TEXTURE_ARRAY) { | ||||
| if (this->layer_count() > GPU_max_texture_layers()) { | if (this->layer_count() > GPU_max_texture_layers()) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines | |||||