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.
This commit is contained in:
Clément Foucault 2020-07-17 15:58:33 +02:00
parent 0ef57d3fc0
commit 2d9eee15c5
4 changed files with 7 additions and 19 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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);