From 2d9eee15c58ba1d3e2bd05a17ca09d74421c47ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Fri, 17 Jul 2020 15:58:33 +0200 Subject: Cleanup: GPU: Set default GL_UNPACK_ALIGNMENT to 1 Ogl default is 4 but for almost all cases, blender use tightly packed format. This avoid confusion and state change for the common case. The only case that __might__ need alignement is DDS loader (untested) so leaving this as it is. --- source/blender/gpu/intern/gpu_draw.c | 5 +++++ source/blender/gpu/intern/gpu_state.c | 2 ++ source/blender/gpu/intern/gpu_texture.c | 12 ------------ source/blender/windowmanager/intern/wm_gesture.c | 7 ------- 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index 7e6d47636f6..9fdb98cfbf6 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -1195,6 +1195,9 @@ bool GPU_upload_dxt_texture(ImBuf *ibuf, bool use_srgb) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1)); + /* Reset to opengl Defaults. (Untested, might not be needed) */ + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + blocksize = (ibuf->dds_data.fourcc == FOURCC_DXT1) ? 8 : 16; for (i = 0; i < ibuf->dds_data.nummipmaps && (width || height); i++) { if (width == 0) { @@ -1213,6 +1216,8 @@ bool GPU_upload_dxt_texture(ImBuf *ibuf, bool use_srgb) width >>= 1; height >>= 1; } + /* Restore Blender default. */ + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /* set number of mipmap levels we have, needed in case they don't go down to 1x1 */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, i - 1); diff --git a/source/blender/gpu/intern/gpu_state.c b/source/blender/gpu/intern/gpu_state.c index 636a5e2c31d..b52504eb492 100644 --- a/source/blender/gpu/intern/gpu_state.c +++ b/source/blender/gpu/intern/gpu_state.c @@ -412,6 +412,8 @@ void GPU_state_init(void) glCullFace(GL_BACK); glDisable(GL_CULL_FACE); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + /* Is default but better be explicit. */ glEnable(GL_MULTISAMPLE); diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c index c4d7eccf9f9..4c847236f09 100644 --- a/source/blender/gpu/intern/gpu_texture.c +++ b/source/blender/gpu/intern/gpu_texture.c @@ -1465,16 +1465,8 @@ void GPU_texture_update_sub(GPUTexture *tex, BLI_assert((int)tex->format > -1); BLI_assert(tex->components > -1); - const uint bytesize = gpu_get_bytesize(tex->format); GLenum data_format = gpu_get_gl_dataformat(tex->format, &tex->format_flag); GLenum data_type = gpu_get_gl_datatype(gpu_data_format); - GLint alignment; - - /* The default pack size for textures is 4, which won't work for byte based textures */ - if (bytesize == 1) { - glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - } glBindTexture(tex->target, tex->bindcode); switch (tex->target) { @@ -1505,10 +1497,6 @@ void GPU_texture_update_sub(GPUTexture *tex, BLI_assert(!"tex->target mode not supported"); } - if (bytesize == 1) { - glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); - } - glBindTexture(tex->target, 0); } diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c index 52c934424e4..e7cb1c00605 100644 --- a/source/blender/windowmanager/intern/wm_gesture.c +++ b/source/blender/windowmanager/intern/wm_gesture.c @@ -357,11 +357,6 @@ static void draw_filled_lasso(wmGesture *gt) GPU_blend(true); GPU_blend_set_func(GPU_ONE, GPU_ONE); - GLint unpack_alignment; - glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack_alignment); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR); GPU_shader_bind(state.shader); GPU_shader_uniform_vector( @@ -382,8 +377,6 @@ static void draw_filled_lasso(wmGesture *gt) GPU_shader_unbind(); - glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment); - MEM_freeN(pixel_buf); GPU_blend(false); -- cgit v1.2.3