vkQuake3 icon indicating copy to clipboard operation
vkQuake3 copied to clipboard

glrenderer2 fails with opengl2 drivers due textureCubeLod

Open infapi00 opened this issue 4 years ago • 2 comments

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).

infapi00 avatar Jul 17 '20 22:07 infapi00

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.

nixguru avatar Aug 25 '22 13:08 nixguru