axmolengine / axmol

Axmol Engine – A Multi-platform Engine for Desktop, XBOX (UWP) and Mobile games. (A fork of Cocos2d-x-4.0)
https://axmol.dev
MIT License
868 stars 195 forks source link

PixelFormat::R8/A8 and GLES 2.0 #1829

Closed smilediver closed 5 months ago

smilediver commented 5 months ago

GLES 2.0 for single channel textures used PixelFormat::A8, but in GLES 3.0 it was removed in favor of PixelFormat::R8. It seems like all other graphics APIs also use PixelFormat::R8. Our and Axmol code is full of hacks like these:

auto pixelFormat = AX_GLES_PROFILE == 200 ? PixelFormat::A8 : PixelFormat::R8;

Maybe it's worth to make PixelFormat::A8 = PixelFormat::R8 and deal with the difference on the backend side when calling GLES api, so all code could use PixelFormat::R8 everywhere? I'm not aware of unintended consequences, but at first sight it seems it would work. There could also be a macro to help on the shader code side, something like:

#ifdef GLES2
    #define R8_CHANNEL a
#else
    #define R8_CHANNEL r
#endif

What do you think?

aismann commented 5 months ago

@smilediver I found only 3 times like you means:

image

aismann commented 5 months ago

Our ... code is full of hacks like these:

auto pixelFormat = AX_GLES_PROFILE == 200 ? PixelFormat::A8 : PixelFormat::R8;

@smilediver May a "global pixelFormat" member is the solution on your code, defined only one times? Can you close this issue?

smilediver commented 5 months ago

I would prefer for this to be handled on the engine side, since the engine's whole purpose is to abstract out such minor platform differences. But if people don't see this as something useful, then I'll close the issue.

aismann commented 5 months ago

@halx99 @rh101 What are you meaning?

halx99 commented 5 months ago

Can by done #1839 and GLES2 will emulate R8 RG8 via: