ptitSeb / gl4es

GL4ES is a OpenGL 2.1/1.5 to GL ES 2.0/1.1 translation library, with support for Pandora, ODroid, OrangePI, CHIP, Raspberry PI, Android, Emscripten and AmigaOS4.
http://ptitseb.github.io/gl4es/
MIT License
699 stars 159 forks source link

L8A8 (monochrome alpha) textures in Xash3D are broken (no alpha) #146

Closed mittorn closed 4 years ago

mittorn commented 4 years ago

Affected fonts and decals (texture loader detects monochrome textures automatically), decals just turns black, fonts have solid background

EGL_CLIENT_APIS: OpenGL OpenGL_ES
GL_VERSION: OpenGL ES 3.2 Mesa 19.3.0-devel (git-40087ffc5b)
GL_RENDERER: AMD RAVEN (DRM 3.32.0, 5.2.0-rc2+, LLVM 9.0.0)
GL_EXTENSIONS:
    GL_EXT_blend_minmax, GL_EXT_multi_draw_arrays,
    GL_EXT_texture_filter_anisotropic, GL_EXT_texture_compression_s3tc,
    GL_EXT_texture_compression_dxt1, GL_EXT_texture_compression_rgtc,
    GL_EXT_texture_format_BGRA8888, GL_OES_compressed_ETC1_RGB8_texture,
    GL_OES_depth24, GL_OES_element_index_uint, GL_OES_fbo_render_mipmap,
    GL_OES_mapbuffer, GL_OES_rgb8_rgba8, GL_OES_standard_derivatives,
    GL_OES_stencil8, GL_OES_texture_3D, GL_OES_texture_float,
    GL_OES_texture_float_linear, GL_OES_texture_half_float,
    GL_OES_texture_half_float_linear, GL_OES_texture_npot,
    GL_OES_vertex_half_float, GL_EXT_texture_sRGB_decode, GL_OES_EGL_image,
    GL_OES_depth_texture, GL_AMD_performance_monitor,
    GL_OES_packed_depth_stencil, GL_EXT_texture_type_2_10_10_10_REV,
    GL_NV_conditional_render, GL_OES_get_program_binary,
    GL_APPLE_texture_max_level, GL_EXT_discard_framebuffer,
    GL_EXT_read_format_bgra, GL_EXT_frag_depth, GL_NV_fbo_color_attachments,
    GL_OES_EGL_image_external, GL_OES_EGL_sync, GL_OES_vertex_array_object,
    GL_OES_viewport_array, GL_ANGLE_texture_compression_dxt3,
    GL_ANGLE_texture_compression_dxt5, GL_EXT_occlusion_query_boolean,
    GL_EXT_robustness, GL_EXT_texture_rg, GL_EXT_unpack_subimage,
    GL_NV_draw_buffers, GL_NV_read_buffer, GL_NV_read_depth,
    GL_NV_read_depth_stencil, GL_NV_read_stencil, GL_EXT_draw_buffers,
    GL_EXT_map_buffer_range, GL_KHR_debug, GL_KHR_robustness,
    GL_KHR_texture_compression_astc_ldr, GL_OES_depth_texture_cube_map,
    GL_OES_required_internalformat, GL_OES_surfaceless_context,
    GL_EXT_color_buffer_float, GL_EXT_sRGB_write_control,
    GL_EXT_separate_shader_objects, GL_EXT_shader_implicit_conversions,
    GL_EXT_shader_integer_mix, GL_EXT_tessellation_point_size,
    GL_EXT_tessellation_shader, GL_ANDROID_extension_pack_es31a,
    GL_EXT_base_instance, GL_EXT_compressed_ETC1_RGB8_sub_texture,
    GL_EXT_copy_image, GL_EXT_draw_buffers_indexed,
    GL_EXT_draw_elements_base_vertex, GL_EXT_gpu_shader5,
    GL_EXT_polygon_offset_clamp, GL_EXT_primitive_bounding_box,
    GL_EXT_render_snorm, GL_EXT_shader_io_blocks, GL_EXT_texture_border_clamp,
    GL_EXT_texture_buffer, GL_EXT_texture_cube_map_array,
    GL_EXT_texture_norm16, GL_EXT_texture_view,
    GL_KHR_blend_equation_advanced, GL_KHR_context_flush_control,
    GL_KHR_robust_buffer_access_behavior, GL_NV_image_formats,
    GL_OES_copy_image, GL_OES_draw_buffers_indexed,
    GL_OES_draw_elements_base_vertex, GL_OES_gpu_shader5,
    GL_OES_primitive_bounding_box, GL_OES_sample_shading,
    GL_OES_sample_variables, GL_OES_shader_io_blocks,
    GL_OES_shader_multisample_interpolation, GL_OES_tessellation_point_size,
    GL_OES_tessellation_shader, GL_OES_texture_border_clamp,
    GL_OES_texture_buffer, GL_OES_texture_cube_map_array,
    GL_OES_texture_stencil8, GL_OES_texture_storage_multisample_2d_array,
    GL_OES_texture_view, GL_EXT_blend_func_extended, GL_EXT_buffer_storage,
    GL_EXT_float_blend, GL_EXT_geometry_point_size, GL_EXT_geometry_shader,
    GL_KHR_no_error, GL_KHR_texture_compression_astc_sliced_3d,
    GL_OES_EGL_image_external_essl3, GL_OES_geometry_point_size,
    GL_OES_geometry_shader, GL_OES_shader_image_atomic,
    GL_EXT_clip_cull_distance, GL_EXT_disjoint_timer_query,
    GL_EXT_texture_compression_s3tc_srgb, GL_EXT_window_rectangles,
    GL_MESA_shader_integer_functions, GL_EXT_clip_control,
    GL_EXT_memory_object, GL_EXT_memory_object_fd, GL_EXT_semaphore,
    GL_EXT_semaphore_fd, GL_EXT_texture_compression_bptc,
    GL_KHR_parallel_shader_compile, GL_AMD_framebuffer_multisample_advanced,
    GL_EXT_texture_sRGB_R8, GL_EXT_depth_clamp, GL_EXT_texture_query_lod
mittorn commented 4 years ago

Changing format to GL_RGBA fixed decals in VBO renderer, but not in legacy renderer and not fixed fonts. Alpha test seems broken somewhere too

ptitSeb commented 4 years ago

I need to try it at home. I may have broken a conversion somehow, and the intermediary format is not correct in the end. What is the internal and external format used for it? (that's an impressive list of extension, AMD Raven?)

mittorn commented 4 years ago

https://github.com/FWGS/xash3d-fwgs/blob/master/ref_gl/gl_rsurf.c#L2361 - vbo decal render (works after setting GL_RGBA) https://github.com/FWGS/xash3d-fwgs/blob/master/ref_gl/gl_decals.c#L883 - legacy decal code (GL_RGBA does not help, black quads) https://github.com/FWGS/xash3d-fwgs/blob/master/ref_gl/gl_image.c#L717 - internal format selection format is usually GL_RGBA. imagelib unpacks all uncompressed textures to RGBA and hopes that driver will convert it. On all gles targets texture format selection was not used before (bits=0) and set as internalformat=format at wrapper side (causing bugs with menu buttons and hud with holes), but now it helps only for decals fonts and sprites enables ALPHA_TEST with rendermode switch, non-monochrome sprites and alpha-tested world geometry seems draw correctly

mittorn commented 4 years ago

As we do not have any texture converters in gl-wes-v2/nanogl, we use internalformat=format everywhere and if required internalformat does not have alpha, set alpha to 0xFF in TexImage wrapper, it solves bugs with hud holes and menu buttons

ptitSeb commented 4 years ago

I have to test that, and make some traces. Format L8A8 should be supported by gl4es.

mittorn commented 4 years ago

Also, decal code in XashXT renderer renders nothing: https://github.com/FWGS/xashxt-fwgs/blob/master/client/render/r_brushdecals.cpp#L109 but i do not know if vertex attribs in glBegin even supported and first, need to fix texturre and alpha test issues

ptitSeb commented 4 years ago

Oh no, glVertexAttribXX inside glBegin() / glEnd() is not supported. Adding support for that doesn't seems easy. I'll think about it.

mittorn commented 4 years ago

I'll rewrite this code to DrawArrays. There is no reason to keep glBegin/glEnd here. And maybe need to move decals to VBO like in engine vbo render, as it does not change between frames

mittorn commented 4 years ago

in r_showtextures decals are solid squares too and not only L8 affected, so it is separate bug xashxt1 xashxt2 xashxt3 Also, screen depth texture seems to copy screen image. Is it possible to read depth in gles?

mittorn commented 4 years ago

decals:

[21:18:08]  801:   48   48     11.99 Kb RGBA   2D   diffuse default   clamp     1    {blood2
[21:18:08]  802:   96   96     47.99 Kb RGBA   2D   diffuse default   clamp     1    {scorch2
[21:18:08]  803:   16   16      1.33 Kb RGBA   2D   diffuse default   clamp     1    {shot4
[21:18:08]  804:   16   16      1.33 Kb RGBA   2D   diffuse default   clamp     1    {shot5
[21:18:08]  805:   16   16      1.33 Kb RGBA   2D   diffuse default   clamp     1    {shot1
[21:18:08]  806:   16   16      1.33 Kb RGBA   2D   diffuse default   clamp     1    {shot2
[21:18:08]  807:   16   16      1.33 Kb RGBA   2D   diffuse default   clamp     1    {shot3
[21:18:08]  808:   48   48     11.99 Kb RGBA   2D   diffuse default   clamp     1    {blood3
[21:18:08]  809:   32   32      5.33 Kb RGBA   2D   diffuse default   clamp     1    {yblood5
[21:18:08]  810:   32   32      5.33 Kb RGBA   2D   diffuse default   clamp     1    {yblood4
[21:18:08]  811:   48   48     11.99 Kb RGBA   2D   diffuse default   clamp     1    {yblood1
[21:18:08]  812:   16   16      1.33 Kb RGBA   2D   diffuse default   clamp     1    {yblood6
[21:18:08]  813:   48   48     11.99 Kb RGBA   2D   diffuse default   clamp     1    {blood1
[21:18:08]  814:   64   64     21.33 Kb RGBA   2D   diffuse default   clamp     1    {blood5

sprites that are working correctly:

[21:18:08]  778:   64   64     16.00 Kb RGB    2D   diffuse default   repeat    1    #sprites/muzzleflash1(frame:00).spr
[21:18:08]  779:   64   64     16.00 Kb RGB    2D   diffuse default   repeat    1    #sprites/muzzleflash1(frame:01).spr
[21:18:08]  780:  256  256    341.33 Kb RGBA   2D   diffuse default   repeat    1    #HUD/sprites/640hud3(frame:00).spr
[21:18:08]  781:  256  128    170.67 Kb RGBA   2D   diffuse default   repeat    1    #HUD/sprites/640hud7(frame:00).spr
[21:18:08]  782:  256   64     85.34 Kb RGBA   2D   diffuse default   repeat    1    #HUD/sprites/640hud8(frame:00).spr
[21:18:08]  783:  256   64     85.34 Kb RGBA   2D   diffuse default   repeat    1    #HUD/sprites/640hud9(frame:00).spr
[21:18:08]  784:  256  256    341.33 Kb RGBA   2D   diffuse default   repeat    1    #HUD/sprites/640hud5(frame:00).spr

seems that clamp is broken

mittorn commented 4 years ago

It is after enabling 16TMU before enabling it:

[01:52:42] GL_MAX_TEXTURE_SIZE: 16384
[01:52:42] GL_MAX_TEXTURE_UNITS_ARB: 8
[01:52:42] GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB: 16384
[01:52:42] GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: 16.0
[01:52:42] GL_MAX_RECTANGLE_TEXTURE_SIZE: 16384
[01:52:42] GL_MAX_TEXTURE_COORDS_ARB: 8
[01:52:42] GL_MAX_TEXTURE_IMAGE_UNITS_ARB: 8
[01:52:42] GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB: 16384
[01:52:42] GL_MAX_VERTEX_ATTRIBS_ARB: 16
[01:52:42]

After:

[01:51:12] GL_MAX_TEXTURE_SIZE: 16384
[01:51:12] GL_MAX_TEXTURE_UNITS_ARB: 16
[01:51:12] GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB: 16384
[01:51:12] GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: 16.0
[01:51:12] GL_MAX_RECTANGLE_TEXTURE_SIZE: 16384
[01:51:12] GL_MAX_TEXTURE_COORDS_ARB: 16
[01:51:12] GL_MAX_TEXTURE_IMAGE_UNITS_ARB: 16
[01:51:12] GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB: 16384
[01:51:12] GL_MAX_VERTEX_ATTRIBS_ARB: 16
[01:51:12]

Before this commit decals/sprites/fonts works correctly

ptitSeb commented 4 years ago

Ah ok. So there is a bug that is left somewhere.

Can you try something? Using latest sources, in src/hardext.c, ca you change lines 330-331 from

    if(hardext.maxtex>MAX_TEX) hardext.maxtex=MAX_TEX;      // caping, as there are some fixed-sized array...
    if(hardext.maxteximage>MAX_TEX) hardext.maxteximage=MAX_TEX;

to

    if(hardext.maxtex>8) hardext.maxtex=8;      // caping, as there are some fixed-sized array...
    if(hardext.maxteximage>8) hardext.maxteximage=8;

I guess it will not work, but that's just to be sure.

mittorn commented 4 years ago

No, it does not help. It seems not bug in tmu detection, but somewhere in tmu code or data structures in fpe

ptitSeb commented 4 years ago

Yeah, it's some flags of the fpe structure I guess. I'll try to reproduce on my side.

mittorn commented 4 years ago

Changing MAX_TEX to 8 seems to fix it

ptitSeb commented 4 years ago

Oh, so maybe I forgot to resize a structure somewhere!

ptitSeb commented 4 years ago

I couldn't reproduce the issue on the Pandora, using latest xash3d code... I'll try tomorow on other platform if I can.

In the mean time, I tried, blindly, a potential fix with commit 1e7e87e726a9bc8f582312ff90385aee26f6dba7 , if you can try it...

ptitSeb commented 4 years ago

About reading depth: most GLES hardware (at least until GLES2) doesn't let read depth. It seems your hardware support it with GL_NV_read_depth, but it seems to have some restrictions (and gl4es doesn't enforce them for now: I'll add that to my TODO).

mittorn commented 4 years ago

no, still black font backgrounds

ptitSeb commented 4 years ago

I have changed again the FPE flags, but I'm still unable to reproduce the issue.

Can you use "LIBGL_DBGSHADERCONV=1" to get all shader generated, and try to isolate the one used in font drawing (not an easy task), and put fragment shader here?

mittorn commented 4 years ago

It is FPE, not shaderconv as happens in pure xash3d (not xashxt mod) without any shaders. Latest commit helped

ptitSeb commented 4 years ago

Ah it's fixed, great ! Now I'm just missing the glVertexAttribXX things inside glBegin(...) / glEnd(). I'll work on that soon.

mittorn commented 4 years ago

I rewrited this code to VAO. And rewrited postprocess code depth texture usage too, it uses FBO instead of texture copy now and shows. XashXT seems to fully work on mesa (except of features using texture arrays), but i have not tested on mobile device. Need to implement API to pass gl4es from engine renderer to mod renderer, it exist now, but not implemented correctly on engine side

mittorn commented 4 years ago

xashxt10 postprocessing (sunshafts effect) and 3d sky

mittorn commented 4 years ago

Is it possible to get original gl vendor and extensions with gl4es?

ptitSeb commented 4 years ago

Oh, wow, that look nice! Looks like some HDR effect like in latest HalfLife2 Lost Coast episode!

ptitSeb commented 4 years ago

Is it possible to get original gl vendor and extensions with gl4es?

For now, there is no mecanism, but I can think of something, some pass-through mecanism in glGetString(...), using special GL_XXXX constants.

mittorn commented 4 years ago

Maybe add somethink like GL_GL4ES_GL_VENDOR? Or any api that returns unwrapped glGetString?

ptitSeb commented 4 years ago

What about glGetString(GL_VENDOR | 0x10000) and glGetString(GL_EXTENSIONS | 0x10000), with also those GL_GL4ES_VENDOR and GL_GL4ES_EXTENSIONS defined in "gl4eshint.h" ?

ptitSeb commented 4 years ago

Ok, more like:

#define GL_VENDOR_GL4ES                 (GL_VENDOR | 0x10000)
#define GL_EXTENSIONS_GL4ES             (GL_EXTENSIONS | 0x10000)

For consistancy

mittorn commented 4 years ago

seems to be ok user may request this only if detected gl4es as GL_VENDOR. I want to add extra lines to r_info command command to allow testers collect all data by single command

ptitSeb commented 4 years ago

yeah sure, seems handy.

ptitSeb commented 4 years ago

Ok, done and pushed... using GL_VERSION | 0x10000 you can also query the version of the GLES2 driver...

mittorn commented 4 years ago

Thank you