Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_draw.c
| Show First 20 Lines • Show All 322 Lines • ▼ Show 20 Lines | static uint gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf) | ||||
| /* create image */ | /* create image */ | ||||
| int bindcode; | int bindcode; | ||||
| glGenTextures(1, (GLuint *)&bindcode); | glGenTextures(1, (GLuint *)&bindcode); | ||||
| glBindTexture(GL_TEXTURE_2D_ARRAY, bindcode); | glBindTexture(GL_TEXTURE_2D_ARRAY, bindcode); | ||||
| GLenum data_type, internal_format; | GLenum data_type, internal_format; | ||||
| if (main_ibuf->rect_float) { | if (main_ibuf->rect_float) { | ||||
| data_type = GL_FLOAT; | data_type = GL_FLOAT; | ||||
| internal_format = GL_RGBA16F; | internal_format = (!(main_ibuf->flags & IB_halffloat) && (ima->flag & IMA_HIGH_BITDEPTH)) ? | ||||
| GL_RGBA32F : | |||||
| GL_RGBA16F; | |||||
brecht: Is this test correct? I would expect:
```
(!(main_ibuf->flags & IB_halffloat) || (ima->flag &… | |||||
Not Done Inline ActionsSorry, that should be: (!(main_ibuf->flags & IB_halffloat) && (ima->flag & IMA_HIGH_BITDEPTH)) brecht: Sorry, that should be:
```
(!(main_ibuf->flags & IB_halffloat) && (ima->flag &… | |||||
| } | } | ||||
| else { | else { | ||||
| data_type = GL_UNSIGNED_BYTE; | data_type = GL_UNSIGNED_BYTE; | ||||
| internal_format = GL_RGBA8; | internal_format = GL_RGBA8; | ||||
| if (!IMB_colormanagement_space_is_data(main_ibuf->rect_colorspace) && | if (!IMB_colormanagement_space_is_data(main_ibuf->rect_colorspace) && | ||||
| !IMB_colormanagement_space_is_scene_linear(main_ibuf->rect_colorspace)) { | !IMB_colormanagement_space_is_scene_linear(main_ibuf->rect_colorspace)) { | ||||
| internal_format = GL_SRGB8_ALPHA8; | internal_format = GL_SRGB8_ALPHA8; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | static uint gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf) | ||||
| return bindcode; | return bindcode; | ||||
| } | } | ||||
| static uint gpu_texture_create_from_ibuf(Image *ima, ImBuf *ibuf, int textarget) | static uint gpu_texture_create_from_ibuf(Image *ima, ImBuf *ibuf, int textarget) | ||||
| { | { | ||||
| uint bindcode = 0; | uint bindcode = 0; | ||||
| const bool mipmap = GPU_get_mipmap(); | const bool mipmap = GPU_get_mipmap(); | ||||
| const bool half_float = (ibuf->flags & IB_halffloat) != 0; | |||||
| #ifdef WITH_DDS | #ifdef WITH_DDS | ||||
| if (ibuf->ftype == IMB_FTYPE_DDS) { | if (ibuf->ftype == IMB_FTYPE_DDS) { | ||||
| /* DDS is loaded directly in compressed form. */ | /* DDS is loaded directly in compressed form. */ | ||||
| GPU_create_gl_tex_compressed(&bindcode, textarget, ima, ibuf); | GPU_create_gl_tex_compressed(&bindcode, textarget, ima, ibuf); | ||||
| return bindcode; | return bindcode; | ||||
| } | } | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | #endif | ||||
| /* Create OpenGL texture. */ | /* Create OpenGL texture. */ | ||||
| GPU_create_gl_tex(&bindcode, | GPU_create_gl_tex(&bindcode, | ||||
| (uint *)rect, | (uint *)rect, | ||||
| rect_float, | rect_float, | ||||
| ibuf->x, | ibuf->x, | ||||
| ibuf->y, | ibuf->y, | ||||
| textarget, | textarget, | ||||
| mipmap, | mipmap, | ||||
| half_float, | |||||
| compress_as_srgb, | compress_as_srgb, | ||||
| ima); | ima); | ||||
| /* Free buffers if needed. */ | /* Free buffers if needed. */ | ||||
| if (rect && rect != (uchar *)ibuf->rect) { | if (rect && rect != (uchar *)ibuf->rect) { | ||||
| MEM_freeN(rect); | MEM_freeN(rect); | ||||
| } | } | ||||
| if (rect_float && rect_float != ibuf->rect_float) { | if (rect_float && rect_float != ibuf->rect_float) { | ||||
| ▲ Show 20 Lines • Show All 491 Lines • ▼ Show 20 Lines | |||||
| /* Image *ima can be NULL */ | /* Image *ima can be NULL */ | ||||
| void GPU_create_gl_tex(uint *bind, | void GPU_create_gl_tex(uint *bind, | ||||
| uint *rect, | uint *rect, | ||||
| float *frect, | float *frect, | ||||
| int rectw, | int rectw, | ||||
| int recth, | int recth, | ||||
| int textarget, | int textarget, | ||||
| bool mipmap, | bool mipmap, | ||||
| bool half_float, | |||||
| bool use_srgb, | bool use_srgb, | ||||
| Image *ima) | Image *ima) | ||||
| { | { | ||||
| ImBuf *ibuf = NULL; | ImBuf *ibuf = NULL; | ||||
| if (textarget == GL_TEXTURE_2D && is_over_resolution_limit(textarget, rectw, recth)) { | if (textarget == GL_TEXTURE_2D && is_over_resolution_limit(textarget, rectw, recth)) { | ||||
| int tpx = rectw; | int tpx = rectw; | ||||
| int tpy = recth; | int tpy = recth; | ||||
| Show All 13 Lines | else { | ||||
| rect = ibuf->rect; | rect = ibuf->rect; | ||||
| } | } | ||||
| } | } | ||||
| /* create image */ | /* create image */ | ||||
| glGenTextures(1, (GLuint *)bind); | glGenTextures(1, (GLuint *)bind); | ||||
| glBindTexture(textarget, *bind); | glBindTexture(textarget, *bind); | ||||
| GLenum internal_format = (frect) ? GL_RGBA16F : (use_srgb) ? GL_SRGB8_ALPHA8 : GL_RGBA8; | GLenum float_format = (!half_float && ima->flag & IMA_HIGH_BITDEPTH) ? GL_RGBA32F : GL_RGBA16F; | ||||
| GLenum internal_format = (frect) ? float_format : (use_srgb) ? GL_SRGB8_ALPHA8 : GL_RGBA8; | |||||
| if (textarget == GL_TEXTURE_2D) { | if (textarget == GL_TEXTURE_2D) { | ||||
| if (frect) { | if (frect) { | ||||
| glTexImage2D(GL_TEXTURE_2D, 0, internal_format, rectw, recth, 0, GL_RGBA, GL_FLOAT, frect); | glTexImage2D(GL_TEXTURE_2D, 0, internal_format, rectw, recth, 0, GL_RGBA, GL_FLOAT, frect); | ||||
| } | } | ||||
| else { | else { | ||||
| glTexImage2D( | glTexImage2D( | ||||
| GL_TEXTURE_2D, 0, internal_format, rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, rect); | GL_TEXTURE_2D, 0, internal_format, rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, rect); | ||||
| ▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | |||||
| void GPU_create_gl_tex_compressed(unsigned int *bind, int textarget, Image *ima, ImBuf *ibuf) | void GPU_create_gl_tex_compressed(unsigned int *bind, int textarget, Image *ima, ImBuf *ibuf) | ||||
| { | { | ||||
| /* For DDS we only support data, scene linear and sRGB. Converting to | /* For DDS we only support data, scene linear and sRGB. Converting to | ||||
| * different colorspace would break the compression. */ | * different colorspace would break the compression. */ | ||||
| const bool use_srgb = !(IMB_colormanagement_space_is_data(ibuf->rect_colorspace) || | const bool use_srgb = !(IMB_colormanagement_space_is_data(ibuf->rect_colorspace) || | ||||
| IMB_colormanagement_space_is_scene_linear(ibuf->rect_colorspace)); | IMB_colormanagement_space_is_scene_linear(ibuf->rect_colorspace)); | ||||
| const bool mipmap = GPU_get_mipmap(); | const bool mipmap = GPU_get_mipmap(); | ||||
| const bool half_float = (ibuf->flags & IB_halffloat) != 0; | |||||
| #ifndef WITH_DDS | #ifndef WITH_DDS | ||||
| (void)ibuf; | (void)ibuf; | ||||
| /* Fall back to uncompressed if DDS isn't enabled */ | /* Fall back to uncompressed if DDS isn't enabled */ | ||||
| GPU_create_gl_tex(bind, ibuf->rect, NULL, ibuf->x, ibuf->y, textarget, mipmap, use_srgb, ima); | GPU_create_gl_tex( | ||||
| bind, ibuf->rect, NULL, ibuf->x, ibuf->y, textarget, mipmap, half_float, use_srgb, ima); | |||||
| #else | #else | ||||
| glGenTextures(1, (GLuint *)bind); | glGenTextures(1, (GLuint *)bind); | ||||
| glBindTexture(textarget, *bind); | glBindTexture(textarget, *bind); | ||||
| if (textarget == GL_TEXTURE_2D && GPU_upload_dxt_texture(ibuf, use_srgb) == 0) { | if (textarget == GL_TEXTURE_2D && GPU_upload_dxt_texture(ibuf, use_srgb) == 0) { | ||||
| glDeleteTextures(1, (GLuint *)bind); | glDeleteTextures(1, (GLuint *)bind); | ||||
| GPU_create_gl_tex(bind, ibuf->rect, NULL, ibuf->x, ibuf->y, textarget, mipmap, use_srgb, ima); | GPU_create_gl_tex( | ||||
| bind, ibuf->rect, NULL, ibuf->x, ibuf->y, textarget, mipmap, half_float, use_srgb, ima); | |||||
| } | } | ||||
| glBindTexture(textarget, 0); | glBindTexture(textarget, 0); | ||||
| #endif | #endif | ||||
| } | } | ||||
| /* these two functions are called on entering and exiting texture paint mode, | /* these two functions are called on entering and exiting texture paint mode, | ||||
| * temporary disabling/enabling mipmapping on all images for quick texture | * temporary disabling/enabling mipmapping on all images for quick texture | ||||
| ▲ Show 20 Lines • Show All 434 Lines • Show Last 20 Lines | |||||
Is this test correct? I would expect: