49 glGenTextures(1, &tex_id_);
58 if (ctx !=
nullptr && is_bound_) {
85 if (!this->proxy_check(0)) {
89 this->ensure_mipmaps(0);
93 glTextureParameteri(tex_id_, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
96 glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
115 glTextureBuffer(tex_id_, internal_format, gl_vbo->vbo_id_);
118 glTexBuffer(target_, internal_format, gl_vbo->vbo_id_);
127 void GLTexture::ensure_mipmaps(
int miplvl)
131 int max_dimension =
max_iii(
w_, effective_h, effective_d);
132 int max_miplvl =
floor(log2(max_dimension));
133 miplvl =
min_ii(miplvl, max_miplvl);
149 for (
int i = 0; i < d; i++) {
150 GLenum target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;
151 glTexImage2D(target, mip, internal_format,
w, h, 0, gl_format, gl_type,
nullptr);
156 switch (dimensions) {
159 glCompressedTexImage1D(target_, mip, internal_format,
w, 0,
size,
nullptr);
162 glCompressedTexImage2D(target_, mip, internal_format,
w, h, 0,
size,
nullptr);
165 glCompressedTexImage3D(target_, mip, internal_format,
w, h, d, 0,
size,
nullptr);
170 switch (dimensions) {
173 glTexImage1D(target_, mip, internal_format,
w, 0, gl_format, gl_type,
nullptr);
176 glTexImage2D(target_, mip, internal_format,
w, h, 0, gl_format, gl_type,
nullptr);
179 glTexImage3D(target_, mip, internal_format,
w, h, d, 0, gl_format, gl_type,
nullptr);
194 void GLTexture::update_sub_direct_state_access(
195 int mip,
int offset[3],
int extent[3], GLenum
format, GLenum
type,
const void *
data)
202 glCompressedTextureSubImage1D(tex_id_, mip, offset[0], extent[0],
format,
size,
data);
205 glCompressedTextureSubImage2D(
209 glCompressedTextureSubImage3D(
218 glTextureSubImage1D(tex_id_, mip, offset[0], extent[0],
format,
type,
data);
238 this->ensure_mipmaps(mip);
251 this->update_sub_direct_state_access(mip, offset, extent, gl_format, gl_type,
data);
257 for (
int i = 0; i < extent[2]; i++) {
258 GLenum target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + offset[2] + i;
259 glTexSubImage2D(target, mip,
UNPACK2(offset),
UNPACK2(extent), gl_format, gl_type,
data);
264 switch (dimensions) {
267 glCompressedTexSubImage1D(target_, mip, offset[0], extent[0], gl_format,
size,
data);
270 glCompressedTexSubImage2D(
274 glCompressedTexSubImage3D(
280 switch (dimensions) {
283 glTexSubImage1D(target_, mip, offset[0], extent[0], gl_format, gl_type,
data);
286 glTexSubImage2D(target_, mip,
UNPACK2(offset),
UNPACK2(extent), gl_format, gl_type,
data);
289 glTexSubImage3D(target_, mip,
UNPACK3(offset),
UNPACK3(extent), gl_format, gl_type,
data);
305 this->ensure_mipmaps(9999);
326 glGenerateTextureMipmap(tex_id_);
330 glGenerateMipmap(target_);
341 GLenum gl_type =
to_gl(data_format);
342 glClearTexImage(tex_id_, mip, gl_format, gl_type,
data);
372 int extent[3] = {1, 1, 1};
375 src->tex_id_, target_, mip, 0, 0, 0, dst->tex_id_, target_, mip, 0, 0, 0,
UNPACK3(extent));
393 int extent[3] = {1, 1, 1};
396 size_t sample_len = extent[0] * extent[1] * extent[2];
398 size_t texture_size = sample_len * sample_size;
408 glGetTextureImage(tex_id_, mip, gl_format, gl_type, texture_size,
data);
413 size_t cube_face_size = texture_size / 6;
414 char *face_data = (
char *)
data;
415 for (
int i = 0; i < 6; i++, face_data += cube_face_size) {
416 glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, mip, gl_format, gl_type, face_data);
420 glGetTexImage(target_, mip, gl_format, gl_type,
data);
439 glTextureParameteriv(tex_id_, GL_TEXTURE_SWIZZLE_RGBA, gl_swizzle);
443 glTexParameteriv(target_, GL_TEXTURE_SWIZZLE_RGBA, gl_swizzle);
453 glTextureParameteri(tex_id_, GL_TEXTURE_BASE_LEVEL,
min);
454 glTextureParameteri(tex_id_, GL_TEXTURE_MAX_LEVEL,
max);
458 glTexParameteri(target_, GL_TEXTURE_BASE_LEVEL,
min);
459 glTexParameteri(target_, GL_TEXTURE_MAX_LEVEL,
max);
500 glSamplerParameteri(samplers_[i], GL_TEXTURE_WRAP_S, wrap_s);
501 glSamplerParameteri(samplers_[i], GL_TEXTURE_WRAP_T, wrap_t);
502 glSamplerParameteri(samplers_[i], GL_TEXTURE_WRAP_R, wrap_r);
503 glSamplerParameteri(samplers_[i], GL_TEXTURE_MIN_FILTER, min_filter);
504 glSamplerParameteri(samplers_[i], GL_TEXTURE_MAG_FILTER, mag_filter);
505 glSamplerParameteri(samplers_[i], GL_TEXTURE_COMPARE_MODE, compare_mode);
506 glSamplerParameteri(samplers_[i], GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
515 char sampler_name[128] =
"\0\0";
517 "%s%s%s%s%s%s%s%s%s%s",
534 glSamplerParameteri(icon_sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
535 glSamplerParameteri(icon_sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
536 glSamplerParameterf(icon_sampler, GL_TEXTURE_LOD_BIAS, -0.5f);
547 float max_anisotropy = 1.0f;
548 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy);
550 float aniso_filter =
min_ff(max_anisotropy,
U.anisotropic_filter);
555 glSamplerParameterf(samplers_[i], GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso_filter);
575 bool GLTexture::proxy_check(
int mip)
581 int size[3] = {1, 1, 1};
591 if (size[0] > max_3d_size ||
size[1] > max_3d_size ||
size[2] > max_3d_size) {
596 if (
size[0] > max_size ||
size[1] > max_size) {
601 if (
size[0] > max_size) {
606 if (
size[0] > max_cube_size) {
638 switch (dimensions) {
641 glCompressedTexImage1D(gl_proxy, mip,
size[0], 0, gl_format, img_size,
nullptr);
644 glCompressedTexImage2D(gl_proxy, mip,
UNPACK2(
size), 0, gl_format, img_size,
nullptr);
647 glCompressedTexImage3D(gl_proxy, mip,
UNPACK3(
size), 0, gl_format, img_size,
nullptr);
652 switch (dimensions) {
655 glTexImage1D(gl_proxy, mip, internal_format,
size[0], 0, gl_format, gl_type,
nullptr);
659 gl_proxy, mip, internal_format,
UNPACK2(
size), 0, gl_format, gl_type,
nullptr);
663 gl_proxy, mip, internal_format,
UNPACK3(
size), 0, gl_format, gl_type,
nullptr);
669 glGetTexLevelParameteriv(gl_proxy, 0, GL_TEXTURE_WIDTH, &
width);
690 "Feedback loop: Trying to bind a texture (%s) with mip range %d-%d but mip %d is "
691 "attached to the active framebuffer (%s)",
MINLINE int min_ii(int a, int b)
MINLINE float min_ff(float a, float b)
MINLINE int max_iii(int a, int b, int c)
#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 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
_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
@ 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 GLint max_texture_3d_size
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)
static void samplers_free(void)
void copy_to(Texture *dst) override
void mip_range_set(int min, int max) override
void check_feedback_loop(void)
uint gl_bindcode_get(void) const override
void generate_mipmap(void) override
void * read(int mip, eGPUDataFormat type) override
static void samplers_update(void)
bool init_internal(void) override
static void samplers_init(void)
void update_sub(int mip, int offset[3], int extent[3], eGPUDataFormat type, const void *data) override
void clear(eGPUDataFormat format, const void *data) override
void swizzle_set(const char swizzle_mask[4]) override
virtual void texture_unbind(Texture *tex)=0
int mip_width_get(int mip) const
eGPUTextureFormat format_
int mip_depth_get(int mip) const
eGPUTextureFormatFlag format_flag_
char name_[DEBUG_NAME_LEN]
FrameBuffer * fb_[GPU_TEX_MAX_FBO_ATTACHED]
GPUAttachmentType fb_attachment_[GPU_TEX_MAX_FBO_ATTACHED]
GPUAttachmentType attachment_type(int slot) const
int mip_height_get(int mip) const
int layer_count(void) const
int dimensions_count(void) const
void mip_size_get(int mip, int r_size[3]) const
Texture(const char *name)
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)
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)
ccl_device_inline float2 floor(const float2 &a)