Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_texture.cc
| Show First 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | bool Texture::init_buffer(GPUVertBuf *vbo, eGPUTextureFormat format) | ||||
| format_ = format; | format_ = format; | ||||
| format_flag_ = to_format_flag(format); | format_flag_ = to_format_flag(format); | ||||
| type_ = GPU_TEXTURE_BUFFER; | type_ = GPU_TEXTURE_BUFFER; | ||||
| return this->init_internal(vbo); | return this->init_internal(vbo); | ||||
| } | } | ||||
| bool Texture::init_view(const GPUTexture *src_, | bool Texture::init_view(const GPUTexture *src_, | ||||
| eGPUTextureFormat format, | eGPUTextureFormat format, | ||||
| eGPUTextureType type, | |||||
| int mip_start, | int mip_start, | ||||
| int mip_len, | int mip_len, | ||||
| int layer_start, | int layer_start, | ||||
| int layer_len, | int layer_len, | ||||
| bool cube_as_array) | bool cube_as_array) | ||||
| { | { | ||||
| const Texture *src = unwrap(src_); | const Texture *src = unwrap(src_); | ||||
| w_ = src->w_; | w_ = src->w_; | ||||
| h_ = src->h_; | h_ = src->h_; | ||||
| d_ = src->d_; | d_ = src->d_; | ||||
| layer_start = min_ii(layer_start, src->layer_count() - 1); | layer_start = min_ii(layer_start, src->layer_count() - 1); | ||||
| layer_len = min_ii(layer_len, (src->layer_count() - layer_start)); | layer_len = min_ii(layer_len, (src->layer_count() - layer_start)); | ||||
| switch (src->type_) { | switch (type) { | ||||
| case GPU_TEXTURE_1D_ARRAY: | case GPU_TEXTURE_1D_ARRAY: | ||||
| h_ = layer_len; | h_ = layer_len; | ||||
| break; | break; | ||||
| case GPU_TEXTURE_CUBE_ARRAY: | case GPU_TEXTURE_CUBE_ARRAY: | ||||
| BLI_assert(layer_len % 6 == 0); | BLI_assert(layer_len % 6 == 0); | ||||
| ATTR_FALLTHROUGH; | ATTR_FALLTHROUGH; | ||||
| case GPU_TEXTURE_2D_ARRAY: | case GPU_TEXTURE_2D_ARRAY: | ||||
| d_ = layer_len; | d_ = layer_len; | ||||
| break; | break; | ||||
| default: | default: | ||||
| BLI_assert(layer_len == 1 && layer_start == 0); | BLI_assert(layer_len == 1 && layer_start == 0); | ||||
| break; | break; | ||||
| } | } | ||||
| mip_start = min_ii(mip_start, src->mipmaps_ - 1); | mip_start = min_ii(mip_start, src->mipmaps_ - 1); | ||||
| mip_len = min_ii(mip_len, (src->mipmaps_ - mip_start)); | mip_len = min_ii(mip_len, (src->mipmaps_ - mip_start)); | ||||
| mipmaps_ = mip_len; | mipmaps_ = mip_len; | ||||
| format_ = format; | format_ = format; | ||||
| format_flag_ = to_format_flag(format); | format_flag_ = to_format_flag(format); | ||||
| /* For now always copy the target. Target aliasing could be exposed later. */ | type_ = type; | ||||
| type_ = src->type_; | |||||
| if (cube_as_array) { | if (cube_as_array) { | ||||
| BLI_assert(type_ & GPU_TEXTURE_CUBE); | BLI_assert(type_ & GPU_TEXTURE_CUBE); | ||||
| type_ = (type_ & ~GPU_TEXTURE_CUBE) | GPU_TEXTURE_2D_ARRAY; | type_ = (type_ & ~GPU_TEXTURE_CUBE) | GPU_TEXTURE_2D_ARRAY; | ||||
| } | } | ||||
| sampler_state = src->sampler_state; | sampler_state = src->sampler_state; | ||||
| return this->init_internal(src_, mip_start, layer_start); | return this->init_internal(src_, mip_start, layer_start); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 223 Lines • ▼ Show 20 Lines | GPUTexture *GPU_texture_create_view(const char *name, | ||||
| int mip_len, | int mip_len, | ||||
| int layer_start, | int layer_start, | ||||
| int layer_len, | int layer_len, | ||||
| bool cube_as_array) | bool cube_as_array) | ||||
| { | { | ||||
| BLI_assert(mip_len > 0); | BLI_assert(mip_len > 0); | ||||
| BLI_assert(layer_len > 0); | BLI_assert(layer_len > 0); | ||||
| Texture *view = GPUBackend::get()->texture_alloc(name); | Texture *view = GPUBackend::get()->texture_alloc(name); | ||||
| view->init_view(src, format, mip_start, mip_len, layer_start, layer_len, cube_as_array); | view->init_view(src, | ||||
| format, | |||||
| unwrap(src)->type_get(), | |||||
| mip_start, | |||||
| mip_len, | |||||
| layer_start, | |||||
| layer_len, | |||||
| cube_as_array); | |||||
| return wrap(view); | |||||
| } | |||||
| GPUTexture *GPU_texture_create_single_layer_view(const char *name, const GPUTexture *src) | |||||
| { | |||||
| eGPUTextureFormat format = unwrap(src)->format_get(); | |||||
| eGPUTextureType type = unwrap(src)->type_get(); | |||||
| BLI_assert(ELEM(type, GPU_TEXTURE_1D, GPU_TEXTURE_2D, GPU_TEXTURE_CUBE)); | |||||
| type |= GPU_TEXTURE_ARRAY; | |||||
| Texture *view = GPUBackend::get()->texture_alloc(name); | |||||
| view->init_view(src, format, type, 0, 9999, 0, 1, false); | |||||
| return wrap(view); | return wrap(view); | ||||
| } | } | ||||
| /* ------ Update ------ */ | /* ------ Update ------ */ | ||||
| void GPU_texture_update_mipmap(GPUTexture *tex_, | void GPU_texture_update_mipmap(GPUTexture *tex_, | ||||
| int miplvl, | int miplvl, | ||||
| eGPUDataFormat data_format, | eGPUDataFormat data_format, | ||||
| ▲ Show 20 Lines • Show All 425 Lines • Show Last 20 Lines | |||||