Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GL Grayscale 8-bit texture alignment #767

Closed
fafok29 opened this issue Dec 28, 2022 · 4 comments
Closed

GL Grayscale 8-bit texture alignment #767

fafok29 opened this issue Dec 28, 2022 · 4 comments
Assignees
Labels

Comments

@fafok29
Copy link

fafok29 commented Dec 28, 2022

I haven't found a way to specify pixel storage modes, so I can't use grayscale textures, which are not 4bytes aligned. Is there a way to do this?

@floooh
Copy link
Owner

floooh commented Dec 31, 2022

Looks like you found an oversight in the backend code (using textures with an row-pitch that isn't a multiple of 4 on GL). I modified the texcube-sapp.c sample to use a 5x5 SG_PIXELFORMAT_R8 texture, and that looks correct in the Metal backend, but messed up in the GL backend (on macOS).

I general, odd row pitches should be allowed as input, no matter what the alignment requirements are for the backend 3D API (because those alignment requirements wildly differ, with WebGPU currently being the worst offender) - only for textures without mipmaps of though.

I'll try to look into the issue when I'm back in Berlin and have access to my Windows machine again (need to check behaviour on D3D11 first).

Until then the only workaround I can think of without modifying sokol_gfx.h is to use SG_PIXELFORMAT_R8 textures with a width that's a multiple of 4.

@floooh floooh self-assigned this Dec 31, 2022
@floooh
Copy link
Owner

floooh commented Jan 15, 2023

Looking into this now. D3D11 accepts textures with odd rowpitch, and WebGL has the required PixelStore API function, so it should be possible to fix (https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/pixelStorei)

@floooh floooh closed this as completed in 7300b14 Jan 15, 2023
@floooh
Copy link
Owner

floooh commented Jan 15, 2023

Ok, this should be fixed now. I'm globally setting GL_UNPACK_ALIGNMENT to 1, which should make GL behave the same as the other backends.

Be aware though the GLES2/WebGL1 generally don't support any textures that are not 2^N in size.

@fafok29
Copy link
Author

fafok29 commented Jan 15, 2023

Great, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants