31 glGenTextures(1, &tex_id_);
40 if (ctx !=
nullptr && is_bound_) {
66 if (!this->proxy_check(0)) {
78 auto mip_size = [&](
int h,
int w = 1,
int d = 1) ->
size_t {
86 glTexStorage1D(target_,
mipmaps_, internal_format,
w_);
91 glCompressedTexImage1D(target_, i, internal_format,
w, 0, mip_size(
w),
nullptr);
94 glTexImage1D(target_, i, internal_format,
w, 0, gl_format, gl_type,
nullptr);
102 glTexStorage2D(target_,
mipmaps_, internal_format,
w_,
h_);
106 for (
int f = 0; f < (is_cubemap ? 6 : 1); f++) {
107 GLenum target = (is_cubemap) ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + f : target_;
109 glCompressedTexImage2D(target, i, internal_format,
w, h, 0, mip_size(
w, h),
nullptr);
112 glTexImage2D(target, i, internal_format,
w, h, 0, gl_format, gl_type,
nullptr);
116 h = is_layered ?
h_ :
max_ii(1, (h / 2));
127 glCompressedTexImage3D(
128 target_, i, internal_format,
w, h, d, 0, mip_size(
w, h, d),
nullptr);
131 glTexImage3D(target_, i, internal_format,
w, h, d, 0, gl_format, gl_type,
nullptr);
135 d = is_layered ?
d_ :
max_ii(1, (d / 2));
144 glTextureParameteri(tex_id_, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
147 glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
165 glTextureBuffer(tex_id_, internal_format, gl_vbo->vbo_id_);
168 glTexBuffer(target_, internal_format, gl_vbo->vbo_id_);
184 glTextureView(tex_id_,
191 this->layer_count());
204 void GLTexture::update_sub_direct_state_access(
215 glCompressedTextureSubImage2D(
219 glCompressedTextureSubImage3D(
259 this->update_sub_direct_state_access(mip,
offset, extent, gl_format, gl_type,
data);
265 for (
int i = 0; i < extent[2]; i++) {
266 GLenum target = GL_TEXTURE_CUBE_MAP_POSITIVE_X +
offset[2] + i;
272 switch (dimensions) {
275 glCompressedTexSubImage1D(target_, mip,
offset[0], extent[0], gl_format,
size,
data);
278 glCompressedTexSubImage2D(
282 glCompressedTexSubImage3D(
288 switch (dimensions) {
291 glTexSubImage1D(target_, mip,
offset[0], extent[0], gl_format, gl_type,
data);
339 glGenerateTextureMipmap(tex_id_);
343 glGenerateMipmap(target_);
354 GLenum gl_type =
to_gl(data_format);
355 glClearTexImage(tex_id_, mip, gl_format, gl_type,
data);
385 int extent[3] = {1, 1, 1};
388 src->tex_id_, target_, mip, 0, 0, 0, dst->tex_id_, target_, mip, 0, 0, 0,
UNPACK3(extent));
406 int extent[3] = {1, 1, 1};
409 size_t sample_len = extent[0] * extent[1] * extent[2];
411 size_t texture_size = sample_len * sample_size;
421 glGetTextureImage(tex_id_, mip, gl_format, gl_type, texture_size,
data);
426 size_t cube_face_size = texture_size / 6;
427 char *face_data = (
char *)
data;
428 for (
int i = 0; i < 6; i++, face_data += cube_face_size) {
429 glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, mip, gl_format, gl_type, face_data);
433 glGetTexImage(target_, mip, gl_format, gl_type,
data);
452 glTextureParameteriv(tex_id_, GL_TEXTURE_SWIZZLE_RGBA, gl_swizzle);
456 glTexParameteriv(target_, GL_TEXTURE_SWIZZLE_RGBA, gl_swizzle);
463 GLint value = use_stencil ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT;
465 glTextureParameteri(tex_id_, GL_DEPTH_STENCIL_TEXTURE_MODE, value);
469 glTexParameteri(target_, GL_DEPTH_STENCIL_TEXTURE_MODE, value);
479 glTextureParameteri(tex_id_, GL_TEXTURE_BASE_LEVEL,
min);
480 glTextureParameteri(tex_id_, GL_TEXTURE_MAX_LEVEL,
max);
484 glTexParameteri(target_, GL_TEXTURE_BASE_LEVEL,
min);
485 glTexParameteri(target_, GL_TEXTURE_MAX_LEVEL,
max);
526 glSamplerParameteri(samplers_[i], GL_TEXTURE_WRAP_S, wrap_s);
527 glSamplerParameteri(samplers_[i], GL_TEXTURE_WRAP_T, wrap_t);
528 glSamplerParameteri(samplers_[i], GL_TEXTURE_WRAP_R, wrap_r);
529 glSamplerParameteri(samplers_[i], GL_TEXTURE_MIN_FILTER, min_filter);
530 glSamplerParameteri(samplers_[i], GL_TEXTURE_MAG_FILTER, mag_filter);
531 glSamplerParameteri(samplers_[i], GL_TEXTURE_COMPARE_MODE, compare_mode);
532 glSamplerParameteri(samplers_[i], GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
541 char sampler_name[128] =
"\0\0";
543 "%s%s%s%s%s%s%s%s%s%s",
560 glSamplerParameteri(icon_sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
561 glSamplerParameteri(icon_sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
562 glSamplerParameterf(icon_sampler, GL_TEXTURE_LOD_BIAS, -0.5f);
573 float max_anisotropy = 1.0f;
574 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy);
576 float aniso_filter =
min_ff(max_anisotropy,
U.anisotropic_filter);
581 glSamplerParameterf(samplers_[i], GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso_filter);
601 bool GLTexture::proxy_check(
int mip)
607 int size[3] = {1, 1, 1};
617 if (size[0] > max_3d_size ||
size[1] > max_3d_size ||
size[2] > max_3d_size) {
622 if (
size[0] > max_size ||
size[1] > max_size) {
627 if (
size[0] > max_size) {
632 if (
size[0] > max_cube_size) {
664 switch (dimensions) {
667 glCompressedTexImage1D(gl_proxy, mip,
size[0], 0, gl_format, img_size,
nullptr);
670 glCompressedTexImage2D(gl_proxy, mip,
UNPACK2(
size), 0, gl_format, img_size,
nullptr);
673 glCompressedTexImage3D(gl_proxy, mip,
UNPACK3(
size), 0, gl_format, img_size,
nullptr);
678 switch (dimensions) {
681 glTexImage1D(gl_proxy, mip, internal_format,
size[0], 0, gl_format, gl_type,
nullptr);
685 gl_proxy, mip, internal_format,
UNPACK2(
size), 0, gl_format, gl_type,
nullptr);
689 gl_proxy, mip, internal_format,
UNPACK3(
size), 0, gl_format, gl_type,
nullptr);
695 glGetTexLevelParameteriv(gl_proxy, 0, GL_TEXTURE_WIDTH, &
width);
710 if (
sh &&
sh->is_compute()) {
721 "Feedback loop: Trying to bind a texture (%s) with mip range %d-%d but mip %d is "
722 "attached to the active framebuffer (%s)",
MINLINE uint divide_ceil_u(uint a, uint b)
MINLINE float min_ff(float a, float b)
MINLINE int max_ii(int a, int b)
#define SNPRINTF(dst, format,...)
int GPU_max_texture_size(void)
bool GPU_depth_blitting_workaround(void)
int GPU_max_texture_layers(void)
bool GPU_mip_render_workaround(void)
struct GPUFrameBuffer GPUFrameBuffer
GPUFrameBuffer * GPU_framebuffer_active_get(void)
void GPU_framebuffer_free(GPUFrameBuffer *fb)
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
GPUFrameBuffer * GPU_framebuffer_create(const char *name)
_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
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
static bool stencil_texturing_support
static GLint max_texture_3d_size
static bool texture_storage_support
static bool copy_image_support
static bool direct_state_access_support
static void tex_free(GLuint tex_id)
static bool texture_filter_anisotropic_support
static GLStateManager * state_manager_active_get()
static bool clear_texture_support
static GLint max_cubemap_size
static bool texture_cube_map_array_support
static bool generate_mipmap_workaround
void texture_bind_temp(GLTexture *tex)
GLTexture(const char *name)
void copy_to(Texture *dst) override
void swizzle_set(const char swizzle_mask[4]) override
bool init_internal() override
void clear(eGPUDataFormat format, const void *data) override
static void samplers_free()
uint gl_bindcode_get() const override
void * read(int mip, eGPUDataFormat type) override
static void samplers_update()
void check_feedback_loop()
static void samplers_init()
void mip_range_set(int min, int max) override
void stencil_texture_mode_set(bool use_stencil) override
void generate_mipmap() override
void update_sub(int mip, int offset[3], int extent[3], eGPUDataFormat type, const void *data) override
virtual void texture_unbind(Texture *tex)=0
eGPUTextureFormat format_
eGPUTextureFormatFlag format_flag_
char name_[DEBUG_NAME_LEN]
FrameBuffer * fb_[GPU_TEX_MAX_FBO_ATTACHED]
int dimensions_count() const
GPUAttachmentType fb_attachment_[GPU_TEX_MAX_FBO_ATTACHED]
GPUAttachmentType attachment_type(int slot) const
void mip_size_get(int mip, int r_size[3]) const
Texture(const char *name)
SyclQueue void void * src
void GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int mip)
void GPU_framebuffer_blit(GPUFrameBuffer *gpufb_read, int read_slot, GPUFrameBuffer *gpufb_write, int write_slot, eGPUFrameBufferBits blit_buffers)
BLI_INLINE float fb(float length, float L)
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_gpu_kernel_postfix ccl_global float int int int int sh
void *(* MEM_mallocN)(size_t len, const char *str)
void raise_gl_error(const char *info)
void object_label(GLenum type, GLuint object, const char *name)
GLenum to_gl_target(eGPUTextureType type)
bool validate_data_format(eGPUTextureFormat tex_format, eGPUDataFormat data_format)
size_t to_block_size(eGPUTextureFormat data_type)
GLenum to_gl_internal_format(eGPUTextureFormat format)
static Context * unwrap(GPUContext *ctx)
eGPUFrameBufferBits to_framebuffer_bits(eGPUTextureFormat tex_format)
GLenum to_gl_proxy(eGPUTextureType type)
GLenum to_gl_data_format(eGPUTextureFormat format)
eGPUDataFormat to_data_format(eGPUTextureFormat tex_format)
GLenum swizzle_to_gl(const char swizzle)
static size_t to_bytesize(GPUIndexBufType type)
static GLenum to_gl(const GPUAttachmentType type)