suijingfeng / vkQuake3

Its based on ioq3,I add a vulkan based modular render back end which originally from https://github.com/kennyalive/Quake-III-Arena-Kenny-Edition
GNU General Public License v2.0
97 stars 28 forks source link

glrenderer2 fails with opengl2 drivers due textureCubeLod #13

Open infapi00 opened 4 years ago

infapi00 commented 4 years ago

Not sure if the glrenderer2 is maintained, but just in case.

When testing with a opengl2 driver it fails during shader compilation due this error: 0:253(14): error: no function with name 'textureCubeLod'

That function has been changing names through glsl versions, and there is some code at GLSL_GetHeader to handle that:

    // HACK: abuse the GLSL preprocessor to turn GLSL 1.20 shaders into 1.30 ones
    if(glRefConfig.glslMajorVersion > 1 || (glRefConfig.glslMajorVersion == 1 && glRefConfig.glslMinorVersion >= 30))
    {
        if (glRefConfig.glslMajorVersion > 1 || (glRefConfig.glslMajorVersion == 1 && glRefConfig.glslMinorVersion >= 50))
            Q_strcat(dest, size, "#version 150\n");
        else
            Q_strcat(dest, size, "#version 130\n");

        if(shaderType == GL_VERTEX_SHADER)
        {
            Q_strcat(dest, size, "#define attribute in\n");
            Q_strcat(dest, size, "#define varying out\n");
        }
        else
        {
            Q_strcat(dest, size, "#define varying in\n");

            Q_strcat(dest, size, "out vec4 out_Color;\n");
            Q_strcat(dest, size, "#define gl_FragColor out_Color\n");
            Q_strcat(dest, size, "#define texture2D texture\n");
            Q_strcat(dest, size, "#define textureCubeLod textureLod\n");
            Q_strcat(dest, size, "#define shadow2D texture\n");
        }
    }
    else
    {
        Q_strcat(dest, size, "#version 120\n");
        Q_strcat(dest, size, "#define shadow2D(a,b) shadow2D(a,b).r \n");
    }

For our case, it goes through the second else, as on opengl 2.1, it was using GLSL 1.20 so the name was textureCubeLod. But the problem is that on GLSL 1.20 core that function is available but only for vertex shaders. To be used on fragment shaders, it is needed the extension GL_ARB_shader_texture_lod. So a quick workaround (tested and working) would be the following one:

    else
    {
        Q_strcat(dest, size, "#version 120\n");
        Q_strcat(dest, size, "#extension GL_ARB_shader_texture_lod : enable\n");
        Q_strcat(dest, size, "#define shadow2D(a,b) shadow2D(a,b).r \n");
    }

But again, that is a workaround, as we need to check if that extension is available (skimming I see some extension-handling code at tr_extensions.c), and probably something else that Im missing. Also again, not sure if there is a real interest to maintain the non-vulkan renderers.

The specific device tested was the rpi4, which Mesa OpenGL driver exposes 2.1 (as a embedded device, it is more focused on GLES).

nixguru commented 2 years ago

Confirmed this issue when compiling and running on Raspberry Pi 4 with Vulkan drivers on Manjaro Linux. Applied patch to source, recompiled, and issue was resolved. Confirmed fix.

runlevel5 commented 3 months ago

Thanks for the bug report. I do not think OpenGL2 is the main focus of this project. After all there are alternatives ports (such as Quake3e) that has much better support for OpenGL2 renderer. IMHO vkQuake3 should remove OpenGL2 renderer