diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-05-16 13:35:57 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-05-16 13:52:04 +0300 |
commit | a9b393c3675ae8fd47aee217653dc8ba0e002b1c (patch) | |
tree | c8eee13684bb092ab093319739fda289f3e08b68 /source | |
parent | f30921fc6879f0018f63352f404b6d4b41fbacf9 (diff) |
Fix T64678: wrong DDS normal map rendering after recent changes
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/gpu/GPU_draw.h | 6 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_draw.c | 29 |
2 files changed, 19 insertions, 16 deletions
diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h index eb54ff127d8..8b830aadbba 100644 --- a/source/blender/gpu/GPU_draw.h +++ b/source/blender/gpu/GPU_draw.h @@ -87,14 +87,10 @@ void GPU_create_gl_tex(unsigned int *bind, bool use_srgb, struct Image *ima); void GPU_create_gl_tex_compressed(unsigned int *bind, - unsigned int *pix, - int x, - int y, - int mipmap, int textarget, struct Image *ima, struct ImBuf *ibuf); -bool GPU_upload_dxt_texture(struct ImBuf *ibuf); +bool GPU_upload_dxt_texture(struct ImBuf *ibuf, bool use_srgb); void GPU_free_image(struct Image *ima); void GPU_free_images(struct Main *bmain); void GPU_free_images_anim(struct Main *bmain); diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index f1c82dc53a7..aea7d2389b0 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -216,8 +216,7 @@ static uint gpu_texture_create_from_ibuf(Image *ima, ImBuf *ibuf, int textarget) #ifdef WITH_DDS if (ibuf->ftype == IMB_FTYPE_DDS) { /* DDS is loaded directly in compressed form. */ - GPU_create_gl_tex_compressed( - &bindcode, ibuf->rect, ibuf->x, ibuf->y, textarget, mipmap, ima, ibuf); + GPU_create_gl_tex_compressed(&bindcode, textarget, ima, ibuf); return bindcode; } #endif @@ -668,7 +667,7 @@ void GPU_create_gl_tex(uint *bind, * This is so the viewport and the BGE can share some code. * Returns false if the provided ImBuf doesn't have a supported DXT compression format */ -bool GPU_upload_dxt_texture(ImBuf *ibuf) +bool GPU_upload_dxt_texture(ImBuf *ibuf, bool use_srgb) { #ifdef WITH_DDS GLint format = 0; @@ -679,13 +678,16 @@ bool GPU_upload_dxt_texture(ImBuf *ibuf) if (GLEW_EXT_texture_compression_s3tc) { if (ibuf->dds_data.fourcc == FOURCC_DXT1) { - format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; + format = (use_srgb) ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT : + GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; } else if (ibuf->dds_data.fourcc == FOURCC_DXT3) { - format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + format = (use_srgb) ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT : + GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; } else if (ibuf->dds_data.fourcc == FOURCC_DXT5) { - format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + format = (use_srgb) ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT : + GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; } } @@ -737,20 +739,25 @@ bool GPU_upload_dxt_texture(ImBuf *ibuf) #endif } -void GPU_create_gl_tex_compressed( - uint *bind, uint *pix, int x, int y, int textarget, int mipmap, 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 + * different colorspace would break the compression. */ + const bool use_srgb = !(IMB_colormanagement_space_is_data(ibuf->rect_colorspace) || + IMB_colormanagement_space_is_scene_linear(ibuf->rect_colorspace)); + const bool mipmap = GPU_get_mipmap(); + #ifndef WITH_DDS (void)ibuf; /* Fall back to uncompressed if DDS isn't enabled */ - GPU_create_gl_tex(bind, pix, NULL, x, y, textarget, mipmap, true, ima); + GPU_create_gl_tex(bind, ibuf->rect, NULL, ibuf->x, ibuf->y, textarget, mipmap, use_srgb, ima); #else glGenTextures(1, (GLuint *)bind); glBindTexture(textarget, *bind); - if (textarget == GL_TEXTURE_2D && GPU_upload_dxt_texture(ibuf) == 0) { + if (textarget == GL_TEXTURE_2D && GPU_upload_dxt_texture(ibuf, use_srgb) == 0) { glDeleteTextures(1, (GLuint *)bind); - GPU_create_gl_tex(bind, pix, NULL, x, y, textarget, mipmap, true, ima); + GPU_create_gl_tex(bind, ibuf->rect, NULL, ibuf->x, ibuf->x, textarget, mipmap, use_srgb, ima); } glBindTexture(textarget, 0); |