45 if (
fb_[
i] !=
nullptr) {
50#ifndef GPU_NO_USE_PY_REFERENCES
62 int mip_len_max = 1 +
floorf(log2f(
w));
110 int mip_len_max = 1 +
floorf(log2f(
w));
159 BLI_assert(layer_len == 1 && layer_start == 0);
173 return this->
init_internal(src, mip_start, layer_start, use_stencil);
201 if (
fb_[
i] ==
nullptr) {
219 BLI_assert_msg(0,
"GPU: Error: Texture: Framebuffer is not attached");
225 int extent[3] = {1, 1, 1};
226 int offset[3] = {0, 0, 0};
267 bool success =
false;
271 success = tex->
init_1D(
w, h, mip_len, tex_format);
275 success = tex->
init_2D(
w, h, d, mip_len, tex_format);
278 success = tex->
init_3D(
w, h, d, mip_len, tex_format);
293 tex->
update(data_format, pixels);
389 bool success = tex->
init_2D(width, height, 0, mip_len, tex_format);
397 for (
int mip = 0; mip < mip_len; mip++) {
398 int extent[3], offset[3] = {0, 0, 0};
401 size_t size = ((extent[0] + 3) / 4) * ((extent[1] + 3) / 4) *
to_block_size(tex_format);
417 "Vertex Buffers used for textures should have usage flag "
418 "GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY.");
433 const float pixel[4] = {1.0f, 0.0f, 1.0f, 1.0f};
435 int h = (dimension < 2 && !is_array) ? 0 : 1;
436 int d = (dimension < 3 && !is_array) ? 0 : 1;
448 TextureFormat::UNORM_8_8_8_8,
467 "Source texture of TextureView must have GPU_TEXTURE_USAGE_FORMAT_VIEW usage "
468 "flag if view texture uses stencil texturing.");
471 "Source texture of TextureView must have GPU_TEXTURE_USAGE_FORMAT_VIEW usage "
472 "flag if view texture format is different.");
474 view->init_view(source_texture,
500 int extent[3] = {1, 1, 1}, offset[3] = {0, 0, 0};
501 texture->mip_size_get(mip_level, extent);
502 texture->update_sub(mip_level, offset, extent, data_format, pixels);
515 int offset[3] = {offset_x, offset_y, offset_z};
516 int extent[3] = {width, height, depth};
517 tex->
update_sub(0, offset, extent, data_format, pixels);
522 GPUPixelBuffer *pixel_buf,
530 int offset[3] = {offset_x, offset_y, offset_z};
531 int extent[3] = {width, height, depth};
532 texture->update_sub(offset, extent, data_format, pixel_buf);
539 "The host-read usage flag must be specified up-front. Only textures which require data "
540 "reads should be flagged, allowing the backend to make certain optimizations.");
541 return texture->read(mip_level, data_format);
654 texture->sampler_state.extend_x = extend_mode;
659 texture->sampler_state.extend_yz = extend_mode;
664 texture->sampler_state.extend_x = extend_mode;
665 texture->sampler_state.extend_yz = extend_mode;
679 fprintf(stderr,
"gpu::Texture: negative refcount\n");
759 switch (texture_format) {
761 case TextureFormat::UINT_8_8_8_8:
763 case TextureFormat::SINT_8_8_8_8:
765 case TextureFormat::UNORM_8_8_8_8:
767 case TextureFormat::UINT_32_32_32_32:
769 case TextureFormat::SINT_32_32_32_32:
771 case TextureFormat::SFLOAT_32_32_32_32:
773 case TextureFormat::UINT_16_16_16_16:
775 case TextureFormat::SINT_16_16_16_16:
777 case TextureFormat::SFLOAT_16_16_16_16:
779 case TextureFormat::UNORM_16_16_16_16:
781 case TextureFormat::UINT_8_8:
783 case TextureFormat::SINT_8_8:
785 case TextureFormat::UNORM_8_8:
787 case TextureFormat::UINT_32_32:
789 case TextureFormat::SINT_32_32:
791 case TextureFormat::SFLOAT_32_32:
793 case TextureFormat::UINT_16_16:
795 case TextureFormat::SINT_16_16:
797 case TextureFormat::SFLOAT_16_16:
799 case TextureFormat::UNORM_16_16:
801 case TextureFormat::UINT_8:
803 case TextureFormat::SINT_8:
805 case TextureFormat::UNORM_8:
807 case TextureFormat::UINT_32:
809 case TextureFormat::SINT_32:
811 case TextureFormat::SFLOAT_32:
813 case TextureFormat::UINT_16:
815 case TextureFormat::SINT_16:
817 case TextureFormat::SFLOAT_16:
819 case TextureFormat::UNORM_16:
822 case TextureFormat::UNORM_10_10_10_2:
824 case TextureFormat::UINT_10_10_10_2:
826 case TextureFormat::UFLOAT_11_11_10:
827 return "R11F_G11F_B10F";
828 case TextureFormat::SFLOAT_32_DEPTH_UINT_8:
829 return "DEPTH32F_STENCIL8";
830 case TextureFormat::SRGBA_8_8_8_8:
833 case TextureFormat::SFLOAT_16_16_16:
835 case TextureFormat::SNORM_16_16_16:
836 return "RGB16_SNORM";
837 case TextureFormat::SINT_16_16_16:
839 case TextureFormat::UINT_16_16_16:
841 case TextureFormat::UNORM_16_16_16:
843 case TextureFormat::SNORM_16_16_16_16:
844 return "RGBA16_SNORM";
845 case TextureFormat::SNORM_8_8_8_8:
846 return "RGBA8_SNORM";
847 case TextureFormat::SFLOAT_32_32_32:
849 case TextureFormat::SINT_32_32_32:
851 case TextureFormat::UINT_32_32_32:
853 case TextureFormat::SNORM_8_8_8:
855 case TextureFormat::UNORM_8_8_8:
857 case TextureFormat::SINT_8_8_8:
859 case TextureFormat::UINT_8_8_8:
861 case TextureFormat::SNORM_16_16:
863 case TextureFormat::SNORM_8_8:
865 case TextureFormat::SNORM_16:
867 case TextureFormat::SNORM_8:
870 case TextureFormat::SRGB_DXT1:
871 return "SRGB8_A8_DXT1";
872 case TextureFormat::SRGB_DXT3:
873 return "SRGB8_A8_DXT3";
874 case TextureFormat::SRGB_DXT5:
875 return "SRGB8_A8_DXT5";
876 case TextureFormat::SNORM_DXT1:
878 case TextureFormat::SNORM_DXT3:
880 case TextureFormat::SNORM_DXT5:
882 case TextureFormat::SRGBA_8_8_8:
884 case TextureFormat::UFLOAT_9_9_9_EXP_5:
887 case TextureFormat::SFLOAT_32_DEPTH:
888 return "DEPTH_COMPONENT32F";
889 case TextureFormat::UNORM_16_DEPTH:
890 return "DEPTH_COMPONENT16";
940#ifndef GPU_NO_USE_PY_REFERENCES
955 texture->mip_size_get(mip_level, r_size);
987 return unwrap(pixel_buf)->map();
992 unwrap(pixel_buf)->unmap();
997 return unwrap(pixel_buf)->get_size();
1002 return unwrap(pixel_buf)->get_native_handle();
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
MINLINE int max_iii(int a, int b, int c)
MINLINE uint64_t ceil_to_multiple_ul(uint64_t a, uint64_t b)
char * STRNCPY(char(&dst)[N], const char *src)
@ GPU_SAMPLER_CUSTOM_COMPARE
void GPU_texture_extend_mode_y(blender::gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
int GPU_texture_mip_count(const blender::gpu::Texture *texture)
void GPU_texture_swizzle_set(blender::gpu::Texture *texture, const char swizzle[4])
void GPU_texture_clear(blender::gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
void GPU_texture_update_sub(blender::gpu::Texture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
int GPU_texture_original_height(const blender::gpu::Texture *texture)
void GPU_pixel_buffer_unmap(GPUPixelBuffer *pixel_buf)
void GPU_texture_extend_mode_x(blender::gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
void GPU_texture_copy(blender::gpu::Texture *dst, blender::gpu::Texture *src)
blender::gpu::Texture * GPU_texture_create_view(const char *name, blender::gpu::Texture *source_texture, blender::gpu::TextureFormat view_format, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array, bool use_stencil)
blender::gpu::Texture * GPU_texture_create_2d_array(const char *name, int width, int height, int layer_len, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_get_mipmap_size(blender::gpu::Texture *texture, int mip_level, int *r_size)
void GPU_texture_update_sub_from_pixel_buffer(blender::gpu::Texture *texture, eGPUDataFormat data_format, GPUPixelBuffer *pixel_buf, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
size_t GPU_texture_component_len(blender::gpu::TextureFormat format)
size_t GPU_texture_dataformat_size(eGPUDataFormat data_format)
void ** GPU_texture_py_reference_get(blender::gpu::Texture *texture)
void GPU_texture_image_unbind_all()
GPUPixelBufferNativeHandle GPU_pixel_buffer_get_native_handle(GPUPixelBuffer *pixel_buf)
int GPU_texture_height(const blender::gpu::Texture *texture)
void GPU_texture_anisotropic_filter(blender::gpu::Texture *texture, bool use_aniso)
blender::gpu::Texture * GPU_texture_create_cube(const char *name, int width, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
size_t GPU_pixel_buffer_size(GPUPixelBuffer *pixel_buf)
void GPU_texture_update_mipmap(blender::gpu::Texture *texture, int mip_level, eGPUDataFormat data_format, const void *pixels)
blender::gpu::Texture * GPU_texture_create_compressed_2d(const char *name, int width, int height, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const void *data)
bool GPU_texture_has_integer_format(const blender::gpu::Texture *texture)
bool GPU_texture_has_depth_format(const blender::gpu::Texture *texture)
@ GPU_SAMPLER_STATE_TYPE_CUSTOM
@ GPU_SAMPLER_STATE_TYPE_PARAMETERS
@ GPU_SAMPLER_STATE_TYPE_INTERNAL
blender::gpu::Texture * GPU_texture_create_1d_array(const char *name, int width, int layer_len, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void * GPU_pixel_buffer_map(GPUPixelBuffer *pixel_buf)
void GPU_texture_update_mipmap_chain(blender::gpu::Texture *texture)
blender::gpu::TextureFormat GPU_texture_format(const blender::gpu::Texture *texture)
int GPU_texture_original_width(const blender::gpu::Texture *texture)
void GPU_texture_unbind(blender::gpu::Texture *texture)
void GPU_pixel_buffer_free(GPUPixelBuffer *pixel_buf)
bool GPU_texture_has_stencil_format(const blender::gpu::Texture *texture)
int GPU_texture_width(const blender::gpu::Texture *texture)
void GPU_texture_bind_ex(blender::gpu::Texture *texture, GPUSamplerState state, int unit)
bool GPU_texture_has_signed_format(const blender::gpu::Texture *texture)
void GPU_texture_original_size_set(blender::gpu::Texture *texture, int width, int height)
void GPU_texture_extend_mode(blender::gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
blender::gpu::Texture * GPU_texture_create_cube_array(const char *name, int width, int layer_len, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_mipmap_mode(blender::gpu::Texture *texture, bool use_mipmap, bool use_filter)
void GPU_texture_ref(blender::gpu::Texture *texture)
@ GPU_TEXTURE_USAGE_HOST_READ
@ GPU_TEXTURE_USAGE_GENERAL
@ GPU_TEXTURE_USAGE_FORMAT_VIEW
void * GPU_texture_read(blender::gpu::Texture *texture, eGPUDataFormat data_format, int mip_level)
void GPU_texture_image_bind(blender::gpu::Texture *texture, int unit)
bool GPU_texture_is_cube(const blender::gpu::Texture *texture)
eGPUTextureUsage GPU_texture_usage(const blender::gpu::Texture *texture)
void GPU_texture_py_reference_set(blender::gpu::Texture *texture, void **py_ref)
bool GPU_texture_has_float_format(const blender::gpu::Texture *texture)
void GPU_texture_image_unbind(blender::gpu::Texture *texture)
blender::gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
int GPU_texture_dimensions(const blender::gpu::Texture *texture)
void GPU_texture_unbind_all()
void GPU_texture_compare_mode(blender::gpu::Texture *texture, bool use_compare)
blender::gpu::Texture * GPU_texture_create_from_vertbuf(const char *name, blender::gpu::VertBuf *vertex_buf)
void GPU_texture_filter_mode(blender::gpu::Texture *texture, bool use_filter)
GPUPixelBuffer * GPU_pixel_buffer_create(size_t byte_size)
void GPU_unpack_row_length_set(uint len)
@ GPU_SAMPLER_FILTERING_MIPMAP
@ GPU_SAMPLER_FILTERING_ANISOTROPIC
@ GPU_SAMPLER_FILTERING_LINEAR
const char * GPU_texture_format_name(blender::gpu::TextureFormat format)
int GPU_texture_layer_count(const blender::gpu::Texture *texture)
void GPU_samplers_update()
void GPU_texture_bind(blender::gpu::Texture *texture, int unit)
blender::gpu::Texture * GPU_texture_create_error(int dimension, bool array)
int GPU_texture_depth(const blender::gpu::Texture *texture)
bool GPU_texture_has_normalized_format(const blender::gpu::Texture *texture)
void GPU_texture_free(blender::gpu::Texture *texture)
blender::gpu::Texture * GPU_texture_create_3d(const char *name, int width, int height, int depth, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const void *data)
blender::gpu::Texture * GPU_texture_create_1d(const char *name, int width, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_update(blender::gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
unsigned int GPU_texture_memory_usage_get()
bool GPU_texture_is_array(const blender::gpu::Texture *texture)
const GPUVertFormat * GPU_vertbuf_get_format(const blender::gpu::VertBuf *verts)
uint GPU_vertbuf_get_vertex_len(const blender::gpu::VertBuf *verts)
@ GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY
BMesh const char void * data
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
StateManager * state_manager
static GPUBackend * get()
virtual void samplers_update()=0
virtual PixelBuffer * pixelbuf_alloc(size_t size)=0
virtual Texture * texture_alloc(const char *name)=0
virtual void texture_unbind_all()=0
virtual void texture_unbind(Texture *tex)=0
virtual void image_unbind_all()=0
virtual void image_unbind(Texture *tex)=0
virtual void image_bind(Texture *tex, int unit)=0
virtual void texture_bind(Texture *tex, GPUSamplerState sampler, int unit)=0
virtual void texture_unpack_row_length_set(uint len)=0
GPUSamplerState sampler_state
void attach_to(FrameBuffer *fb, GPUAttachmentType type)
bool init_1D(int w, int layers, int mip_len, TextureFormat format)
virtual void generate_mipmap()=0
GPUTextureType type_get() const
GPUTextureFormatFlag format_flag_get() const
void update(eGPUDataFormat format, const void *data)
eGPUTextureUsage gpu_image_usage_flags_
eGPUTextureUsage usage_get() const
bool init_cubemap(int w, int layers, int mip_len, TextureFormat format)
char name_[DEBUG_NAME_LEN]
bool init_view(Texture *src, TextureFormat format, GPUTextureType type, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array, bool use_stencil)
FrameBuffer * fb_[GPU_TEX_MAX_FBO_ATTACHED]
bool init_2D(int w, int h, int layers, int mip_len, TextureFormat format)
bool init_3D(int w, int h, int d, int mip_len, TextureFormat format)
GPUAttachmentType fb_attachment_[GPU_TEX_MAX_FBO_ATTACHED]
bool init_buffer(VertBuf *vbo, TextureFormat format)
virtual void clear(eGPUDataFormat format, const void *data)=0
virtual bool init_internal()=0
virtual void update_sub(int mip, int offset[3], int extent[3], eGPUDataFormat format, const void *data)=0
void mip_size_get(int mip, int r_size[3]) const
virtual void copy_to(Texture *tex)=0
void usage_set(eGPUTextureUsage usage_flags)
Texture(const char *name)
void detach_from(FrameBuffer *fb)
GPUTextureFormatFlag format_flag_
GPUUsageType extended_usage_
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
static gpu::Texture * gpu_texture_create(const char *name, const int w, const int h, const int d, const GPUTextureType type, int mip_len, TextureFormat tex_format, eGPUTextureUsage usage, const void *pixels, eGPUDataFormat data_format=GPU_DATA_FLOAT)
BLI_INLINE float fb(float length, float L)
static Context * unwrap(GPUContext *ctx)
eGPUDataFormat to_texture_data_format(TextureFormat tex_format)
static GPUContext * wrap(Context *ctx)
@ GPU_FORMAT_NORMALIZED_INTEGER
@ GPU_FORMAT_DEPTH_STENCIL
size_t to_block_size(TextureFormat data_type)
int to_bytesize(const DataFormat format)
int to_component_len(TextureFormat format)
GPUTextureFormatFlag to_format_flag(TextureFormat format)
constexpr TextureFormat to_texture_format(TextureTargetFormat format)
GPUSamplerCustomType custom_type
void set_filtering_flag_from_test(GPUSamplerFiltering filtering_flags, bool test)