42 if (
fb_[i] !=
nullptr) {
47 #ifndef GPU_NO_USE_PY_REFERENCES
59 int mip_len_max = 1 +
floorf(log2f(
w));
107 int mip_len_max = 1 +
floorf(log2f(
w));
145 layer_start =
min_ii(layer_start,
src->layer_count() - 1);
146 layer_len =
min_ii(layer_len, (
src->layer_count() - layer_start));
147 switch (
src->type_) {
158 BLI_assert(layer_len == 1 && layer_start == 0);
161 mip_start =
min_ii(mip_start,
src->mipmaps_ - 1);
162 mip_len =
min_ii(mip_len, (
src->mipmaps_ - mip_start));
185 if (
fb_[i] ==
nullptr) {
203 BLI_assert_msg(0,
"GPU: Error: Texture: Framebuffer is not attached");
209 int extent[3],
offset[3] = {0, 0, 0};
247 bool success =
false;
251 success =
tex->init_1D(
w, h, mip_len, tex_format);
255 success =
tex->init_2D(
w, h, d, mip_len, tex_format);
258 success =
tex->init_3D(
w, h, d, mip_len, tex_format);
262 success =
tex->init_cubemap(
w, d, mip_len, tex_format);
273 tex->update(data_format, pixels);
340 bool success =
tex->init_2D(
w, h, 0, miplen, tex_format);
348 for (
int mip = 0; mip < miplen; mip++) {
349 int extent[3],
offset[3] = {0, 0, 0};
350 tex->mip_size_get(mip, extent);
352 size_t size = ((extent[0] + 3) / 4) * ((extent[1] + 3) / 4) *
to_block_size(tex_format);
366 bool success =
tex->init_buffer(vert, tex_format);
376 float pixel[4] = {1.0f, 0.0f, 1.0f, 1.0f};
378 int h = (dimension < 2 && !is_array) ? 0 : 1;
379 int d = (dimension < 3 && !is_array) ? 0 : 1;
400 view->init_view(
src,
format, mip_start, mip_len, layer_start, layer_len, cube_as_array);
412 int extent[3] = {1, 1, 1},
offset[3] = {0, 0, 0};
413 tex->mip_size_get(miplvl, extent);
414 reinterpret_cast<Texture *
>(
tex)->update_sub(miplvl,
offset, extent, data_format, pixels);
427 int offset[3] = {offset_x, offset_y, offset_z};
429 reinterpret_cast<Texture *
>(
tex)->update_sub(0,
offset, extent, data_format, pixels);
435 return tex->read(miplvl, data_format);
459 const bool UNUSED(set_number))
500 reinterpret_cast<Texture *
>(
tex)->generate_mipmap();
555 reinterpret_cast<Texture *
>(
tex)->swizzle_set(swizzle);
561 reinterpret_cast<Texture *
>(
tex)->stencil_texture_mode_set(use_stencil);
569 if (
tex->refcount < 0) {
570 fprintf(stderr,
"GPUTexture: negative refcount\n");
573 if (
tex->refcount == 0) {
604 return reinterpret_cast<const Texture *
>(
tex)->width_get();
609 return reinterpret_cast<const Texture *
>(
tex)->height_get();
614 return reinterpret_cast<const Texture *
>(
tex)->layer_count();
619 return reinterpret_cast<const Texture *
>(
tex)->mip_count();
624 return reinterpret_cast<const Texture *
>(
tex)->src_w;
629 return reinterpret_cast<const Texture *
>(
tex)->src_h;
641 return reinterpret_cast<const Texture *
>(
tex)->format_get();
669 #ifndef GPU_NO_USE_PY_REFERENCES
685 return reinterpret_cast<const Texture *
>(
tex)->gl_bindcode_get();
690 return reinterpret_cast<Texture *
>(
tex)->mip_size_get(lvl, r_size);
#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)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
#define SET_FLAG_FROM_TEST(value, test, flag)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
@ GPU_SAMPLER_CLAMP_BORDER
struct GPUTexture GPUTexture
static const int GPU_SAMPLER_MAX
const GPUVertFormat * GPU_vertbuf_get_format(const GPUVertBuf *verts)
uint GPU_vertbuf_get_vertex_len(const GPUVertBuf *verts)
struct GPUVertBuf GPUVertBuf
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
StateManager * state_manager
void attachment_remove(GPUAttachmentType type)
static GPUBackend * get()
virtual Texture * texture_alloc(const char *name)=0
virtual void samplers_update()=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 texture_bind(Texture *tex, eGPUSamplerState sampler, int unit)=0
virtual void image_bind(Texture *tex, int unit)=0
virtual void texture_unpack_row_length_set(uint len)=0
void attach_to(FrameBuffer *fb, GPUAttachmentType type)
eGPUTextureFormat format_
bool init_view(const GPUTexture *src, eGPUTextureFormat format, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array)
eGPUTextureFormatFlag format_flag_
void update(eGPUDataFormat format, const void *data)
char name_[DEBUG_NAME_LEN]
FrameBuffer * fb_[GPU_TEX_MAX_FBO_ATTACHED]
bool init_buffer(GPUVertBuf *vbo, eGPUTextureFormat format)
GPUAttachmentType fb_attachment_[GPU_TEX_MAX_FBO_ATTACHED]
bool init_1D(int w, int layers, int mip_len, eGPUTextureFormat format)
eGPUSamplerState sampler_state
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
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)
SyclQueue void void * src
GPUTexture * GPU_texture_create_2d_array(const char *name, int w, int h, int d, int mip_len, eGPUTextureFormat format, const float *data)
bool GPU_texture_cube(const GPUTexture *tex)
size_t GPU_texture_component_len(eGPUTextureFormat tex_format)
GPUTexture * GPU_texture_create_1d_array(const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
void GPU_texture_py_reference_set(GPUTexture *tex, void **py_ref)
void GPU_texture_swizzle_set(GPUTexture *tex, const char swizzle[4])
void GPU_texture_compare_mode(GPUTexture *tex_, bool use_compare)
void GPU_texture_filter_mode(GPUTexture *tex_, bool use_filter)
void GPU_texture_image_bind(GPUTexture *tex, int unit)
void GPU_texture_bind_ex(GPUTexture *tex_, eGPUSamplerState state, int unit, const bool UNUSED(set_number))
void GPU_texture_update_sub(GPUTexture *tex, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
void ** GPU_texture_py_reference_get(GPUTexture *tex)
size_t GPU_texture_dataformat_size(eGPUDataFormat data_format)
void GPU_texture_image_unbind_all()
uint GPU_texture_memory_usage_get()
int GPU_texture_height(const GPUTexture *tex)
void GPU_texture_mipmap_mode(GPUTexture *tex_, bool use_mipmap, bool use_filter)
void GPU_texture_orig_size_set(GPUTexture *tex_, int w, int h)
GPUTexture * GPU_texture_create_1d(const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
void GPU_texture_clear(GPUTexture *tex, eGPUDataFormat data_format, const void *data)
GPUTexture * GPU_texture_create_error(int dimension, bool is_array)
void * GPU_texture_read(GPUTexture *tex_, eGPUDataFormat data_format, int miplvl)
void GPU_texture_get_mipmap_size(GPUTexture *tex, int lvl, int *r_size)
int GPU_texture_dimensions(const GPUTexture *tex_)
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, eGPUDataFormat data_format, const void *pixels)
int GPU_texture_width(const GPUTexture *tex)
void GPU_texture_unbind(GPUTexture *tex_)
GPUTexture * GPU_texture_create_from_vertbuf(const char *name, GPUVertBuf *vert)
void GPU_texture_image_unbind(GPUTexture *tex)
int GPU_texture_mip_count(const GPUTexture *tex)
int GPU_texture_opengl_bindcode(const GPUTexture *tex)
bool GPU_texture_integer(const GPUTexture *tex)
bool GPU_texture_array(const GPUTexture *tex)
void GPU_texture_update(GPUTexture *tex, eGPUDataFormat data_format, const void *data)
GPUTexture * GPU_texture_create_view(const char *name, const GPUTexture *src, eGPUTextureFormat format, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array)
void GPU_texture_ref(GPUTexture *tex)
int GPU_texture_layer_count(const GPUTexture *tex)
void GPU_texture_free(GPUTexture *tex_)
void GPU_texture_stencil_texture_mode_set(GPUTexture *tex, bool use_stencil)
GPUTexture * GPU_texture_create_2d(const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
void GPU_texture_bind(GPUTexture *tex_, int unit)
void GPU_texture_unbind_all()
bool GPU_texture_stencil(const GPUTexture *tex)
int GPU_texture_orig_width(const GPUTexture *tex)
GPUTexture * GPU_texture_create_compressed_2d(const char *name, int w, int h, int miplen, eGPUTextureFormat tex_format, const void *data)
void GPU_texture_anisotropic_filter(GPUTexture *tex_, bool use_aniso)
GPUTexture * GPU_texture_create_3d(const char *name, int w, int h, int d, int mip_len, eGPUTextureFormat texture_format, eGPUDataFormat data_format, const void *data)
eGPUTextureFormat GPU_texture_format(const GPUTexture *tex)
bool GPU_texture_depth(const GPUTexture *tex)
void GPU_unpack_row_length_set(uint len)
int GPU_texture_orig_height(const GPUTexture *tex)
GPUTexture * GPU_texture_create_cube(const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
void GPU_texture_wrap_mode(GPUTexture *tex_, bool use_repeat, bool use_clamp)
void GPU_samplers_update()
void GPU_texture_update_mipmap(GPUTexture *tex_, int miplvl, eGPUDataFormat data_format, const void *pixels)
GPUTexture * GPU_texture_create_cube_array(const char *name, int w, int d, int mip_len, eGPUTextureFormat format, const float *data)
void GPU_texture_copy(GPUTexture *dst_, GPUTexture *src_)
void GPU_texture_generate_mipmap(GPUTexture *tex)
BLI_INLINE float fb(float length, float L)
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
static void clear(Message *msg)
size_t to_block_size(eGPUTextureFormat data_type)
static GPUContext * wrap(Context *ctx)
static Context * unwrap(GPUContext *ctx)
@ GPU_FORMAT_DEPTH_STENCIL
eGPUDataFormat to_data_format(eGPUTextureFormat tex_format)
static eGPUTextureFormat to_texture_format(const GPUVertFormat *format)
eGPUTextureFormatFlag to_format_flag(eGPUTextureFormat format)
static size_t to_bytesize(GPUIndexBufType type)
int to_component_len(eGPUTextureFormat format)
static void update(bNodeTree *ntree)