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));
163 BLI_assert(layer_len == 1 && layer_start == 0);
177 return this->
init_internal(src_, mip_start, layer_start, use_stencil);
205 if (
fb_[
i] ==
nullptr) {
223 BLI_assert_msg(0,
"GPU: Error: Texture: Framebuffer is not attached");
229 int extent[3] = {1, 1, 1};
230 int offset[3] = {0, 0, 0};
271 bool success =
false;
275 success = tex->
init_1D(
w, h, mip_len, tex_format);
279 success = tex->
init_2D(
w, h, d, mip_len, tex_format);
282 success = tex->
init_3D(
w, h, d, mip_len, tex_format);
297 tex->
update(data_format, pixels);
299 return reinterpret_cast<GPUTexture *
>(tex);
393 bool success = tex->
init_2D(width, height, 0, mip_len, tex_format);
401 for (
int mip = 0; mip < mip_len; mip++) {
402 int extent[3], offset[3] = {0, 0, 0};
405 size_t size = ((extent[0] + 3) / 4) * ((extent[1] + 3) / 4) *
to_block_size(tex_format);
411 return reinterpret_cast<GPUTexture *
>(tex);
420 "Vertex Buffers used for textures should have usage flag "
421 "GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY.");
431 return reinterpret_cast<GPUTexture *
>(tex);
436 const float pixel[4] = {1.0f, 0.0f, 1.0f, 1.0f};
438 int h = (dimension < 2 && !is_array) ? 0 : 1;
439 int d = (dimension < 3 && !is_array) ? 0 : 1;
450 GPUTexture *source_texture,
463 "Source texture of TextureView must have GPU_TEXTURE_USAGE_FORMAT_VIEW usage "
464 "flag if view texture uses stencil texturing.");
467 "Source texture of TextureView must have GPU_TEXTURE_USAGE_FORMAT_VIEW usage "
468 "flag if view texture format is different.");
470 view->init_view(source_texture,
472 unwrap(source_texture)->type_get(),
496 int extent[3] = {1, 1, 1}, offset[3] = {0, 0, 0};
498 unwrap(
texture)->update_sub(mip_level, offset, extent, data_format, pixels);
511 int offset[3] = {offset_x, offset_y, offset_z};
512 int extent[3] = {width, height, depth};
513 unwrap(tex)->update_sub(0, offset, extent, data_format, pixels);
518 GPUPixelBuffer *pixel_buf,
526 int offset[3] = {offset_x, offset_y, offset_z};
527 int extent[3] = {width, height, depth};
528 unwrap(
texture)->update_sub(offset, extent, data_format, pixel_buf);
535 "The host-read usage flag must be specified up-front. Only textures which require data "
536 "reads should be flagged, allowing the backend to make certain optimizations.");
599 unwrap(tex)->generate_mipmap();
675 fprintf(stderr,
"GPUTexture: negative refcount\n");
755 switch (texture_format) {
823 return "R11F_G11F_B10F";
825 return "DEPTH32F_STENCIL8";
827 return "DEPTH24_STENCIL8";
834 return "RGB16_SNORM";
842 return "RGBA16_SNORM";
844 return "RGBA8_SNORM";
869 return "SRGB8_A8_DXT1";
871 return "SRGB8_A8_DXT3";
873 return "SRGB8_A8_DXT5";
886 return "DEPTH_COMPONENT32F";
888 return "DEPTH_COMPONENT24";
890 return "DEPTH_COMPONENT16";
936#ifndef GPU_NO_USE_PY_REFERENCES
989 return unwrap(pixel_buf)->map();
994 unwrap(pixel_buf)->unmap();
999 return unwrap(pixel_buf)->get_size();
1004 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
int GPU_texture_height(const GPUTexture *texture)
GPUTexture * GPU_texture_create_compressed_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const void *data)
void GPU_texture_bind(GPUTexture *texture, int unit)
int GPU_texture_original_height(const GPUTexture *texture)
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_extend_mode_y(GPUTexture *texture, GPUSamplerExtendMode extend_mode)
GPUTexture * GPU_texture_create_1d(const char *name, int width, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
const char * GPU_texture_format_name(eGPUTextureFormat format)
void GPU_texture_free(GPUTexture *texture)
void GPU_pixel_buffer_unmap(GPUPixelBuffer *pixel_buf)
int GPU_texture_width(const GPUTexture *texture)
void GPU_texture_clear(GPUTexture *texture, eGPUDataFormat data_format, const void *data)
void GPU_texture_ref(GPUTexture *texture)
void ** GPU_texture_py_reference_get(GPUTexture *texture)
void GPU_texture_bind_ex(GPUTexture *texture, GPUSamplerState state, int unit)
int GPU_texture_dimensions(const GPUTexture *texture)
void GPU_texture_copy(GPUTexture *dst, GPUTexture *src)
size_t GPU_texture_dataformat_size(eGPUDataFormat data_format)
void * GPU_texture_read(GPUTexture *texture, eGPUDataFormat data_format, int mip_level)
bool GPU_texture_has_float_format(const GPUTexture *texture)
bool GPU_texture_is_cube(const GPUTexture *texture)
void GPU_texture_image_unbind_all()
int GPU_texture_depth(const GPUTexture *texture)
GPUPixelBufferNativeHandle GPU_pixel_buffer_get_native_handle(GPUPixelBuffer *pixel_buf)
void GPU_texture_unbind(GPUTexture *texture)
size_t GPU_pixel_buffer_size(GPUPixelBuffer *pixel_buf)
int GPU_texture_mip_count(const GPUTexture *texture)
int GPU_texture_original_width(const GPUTexture *texture)
@ GPU_SAMPLER_STATE_TYPE_CUSTOM
@ GPU_SAMPLER_STATE_TYPE_PARAMETERS
@ GPU_SAMPLER_STATE_TYPE_INTERNAL
void GPU_texture_py_reference_set(GPUTexture *texture, void **py_ref)
void * GPU_pixel_buffer_map(GPUPixelBuffer *pixel_buf)
void GPU_pixel_buffer_free(GPUPixelBuffer *pixel_buf)
void GPU_texture_update_sub_from_pixel_buffer(GPUTexture *texture, eGPUDataFormat data_format, GPUPixelBuffer *pixel_buf, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
void GPU_texture_anisotropic_filter(GPUTexture *texture, bool use_aniso)
GPUTexture * GPU_texture_create_error(int dimension, bool array)
GPUTexture * GPU_texture_create_cube_array(const char *name, int width, int layer_len, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_compare_mode(GPUTexture *texture, bool use_compare)
bool GPU_texture_has_normalized_format(const GPUTexture *texture)
void GPU_texture_extend_mode_x(GPUTexture *texture, GPUSamplerExtendMode extend_mode)
void GPU_texture_extend_mode(GPUTexture *texture, GPUSamplerExtendMode extend_mode)
bool GPU_texture_has_integer_format(const GPUTexture *texture)
GPUTexture * GPU_texture_create_from_vertbuf(const char *name, blender::gpu::VertBuf *vertex_buf)
GPUTexture * GPU_texture_create_view(const char *name, GPUTexture *source_texture, eGPUTextureFormat view_format, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array, bool use_stencil)
bool GPU_texture_is_array(const GPUTexture *texture)
int GPU_texture_opengl_bindcode(const GPUTexture *texture)
@ GPU_TEXTURE_USAGE_HOST_READ
@ GPU_TEXTURE_USAGE_GENERAL
@ GPU_TEXTURE_USAGE_FORMAT_VIEW
bool GPU_texture_has_stencil_format(const GPUTexture *texture)
void GPU_texture_update_sub(GPUTexture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
void GPU_texture_update_mipmap(GPUTexture *texture, int mip_level, eGPUDataFormat data_format, const void *pixels)
GPUTexture * GPU_texture_create_2d_array(const char *name, int width, int height, int layer_len, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_mipmap_mode(GPUTexture *texture, bool use_mipmap, bool use_filter)
void GPU_texture_image_unbind(GPUTexture *texture)
GPUTexture * GPU_texture_create_3d(const char *name, int width, int height, int depth, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const void *data)
void GPU_texture_image_bind(GPUTexture *texture, int unit)
void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter)
void GPU_texture_unbind_all()
GPUTexture * GPU_texture_create_cube(const char *name, int width, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_update_mipmap_chain(GPUTexture *texture)
eGPUTextureUsage GPU_texture_usage(const GPUTexture *texture)
bool GPU_texture_has_signed_format(const GPUTexture *texture)
GPUPixelBuffer * GPU_pixel_buffer_create(size_t byte_size)
GPUTexture * GPU_texture_create_1d_array(const char *name, int width, int layer_len, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_unpack_row_length_set(uint len)
@ GPU_SAMPLER_FILTERING_MIPMAP
@ GPU_SAMPLER_FILTERING_ANISOTROPIC
@ GPU_SAMPLER_FILTERING_LINEAR
void GPU_texture_original_size_set(GPUTexture *texture, int width, int height)
int GPU_texture_layer_count(const GPUTexture *texture)
bool GPU_texture_has_depth_format(const GPUTexture *texture)
void GPU_samplers_update()
size_t GPU_texture_component_len(eGPUTextureFormat format)
void GPU_texture_update(GPUTexture *texture, eGPUDataFormat data_format, const void *data)
void GPU_texture_get_mipmap_size(GPUTexture *texture, int mip_level, int *r_size)
unsigned int GPU_texture_memory_usage_get()
eGPUTextureFormat GPU_texture_format(const GPUTexture *texture)
void GPU_texture_swizzle_set(GPUTexture *texture, const char swizzle[4])
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_view(GPUTexture *src, eGPUTextureFormat format, eGPUTextureType type, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array, bool use_stencil)
eGPUTextureFormat format_
eGPUTextureFormatFlag format_flag_get() const
eGPUTextureFormatFlag format_flag_
void update(eGPUDataFormat format, const void *data)
eGPUTextureUsage gpu_image_usage_flags_
eGPUTextureUsage usage_get() const
char name_[DEBUG_NAME_LEN]
FrameBuffer * fb_[GPU_TEX_MAX_FBO_ATTACHED]
GPUAttachmentType fb_attachment_[GPU_TEX_MAX_FBO_ATTACHED]
bool init_1D(int w, int layers, int mip_len, eGPUTextureFormat format)
bool init_buffer(VertBuf *vbo, eGPUTextureFormat format)
virtual bool init_internal()=0
bool init_cubemap(int w, int layers, int mip_len, eGPUTextureFormat format)
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)
bool init_3D(int w, int h, int d, int mip_len, eGPUTextureFormat format)
Texture(const char *name)
void detach_from(FrameBuffer *fb)
bool init_2D(int w, int h, int layers, int mip_len, eGPUTextureFormat format)
GPUUsageType extended_usage_
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
static GPUTexture * gpu_texture_create(const char *name, const int w, const int h, const int d, const eGPUTextureType type, int mip_len, eGPUTextureFormat 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)
size_t to_block_size(eGPUTextureFormat data_type)
static GPUContext * wrap(Context *ctx)
@ GPU_FORMAT_NORMALIZED_INTEGER
@ GPU_FORMAT_DEPTH_STENCIL
int to_bytesize(const DataFormat format)
eGPUTextureFormatFlag to_format_flag(eGPUTextureFormat format)
int to_component_len(eGPUTextureFormat format)
constexpr DataFormat to_data_format(TextureFormat format)
constexpr TextureFormat to_texture_format(TextureTargetFormat format)
GPUSamplerCustomType custom_type
void set_filtering_flag_from_test(GPUSamplerFiltering filtering_flags, bool test)