首页 > 解决方案 > OpenGL 片段着色器未在 Intel HD 4000 图形上编译

问题描述

这个着色器似乎在我的 ryzen 3 2200g 上的 Vega 8 iGPU 上编译得很好,但相同的片段着色器不能在 intel hd 4000 图形上编译。真的有着色器错误还是我做错了什么?我还采取措施不使用int. 请帮忙。

#version 330 core
in vec2 TexCoord;

// I am using a batch rendering method. The "TexElement" is the slot to which the texture is bound to
in flat int TexElement;

// Color to multiply with the texture color also called tint
in flat vec4 MultiplyColor;

// Outputted color
out vec4 color;

uniform sampler2D u_Textures[32];

void main()
{
    switch (TexElement)
    {
        case 0 : color = texture(u_Textures[0], TexCoord) * MultiplyColor; break;
        case 1 : color = texture(u_Textures[1], TexCoord) * MultiplyColor; break;
        case 2 : color = texture(u_Textures[2], TexCoord) * MultiplyColor; break;
        case 3 : color = texture(u_Textures[3], TexCoord) * MultiplyColor; break;
        case 4 : color = texture(u_Textures[4], TexCoord) * MultiplyColor; break;
        case 5 : color = texture(u_Textures[5], TexCoord) * MultiplyColor; break;
        case 6 : color = texture(u_Textures[6], TexCoord) * MultiplyColor; break;
        case 7 : color = texture(u_Textures[7], TexCoord) * MultiplyColor; break;
        case 8 : color = texture(u_Textures[8], TexCoord) * MultiplyColor; break;
        case 9 : color = texture(u_Textures[9], TexCoord) * MultiplyColor; break;
        case 10 : color = texture(u_Textures[10], TexCoord) * MultiplyColor; break;
        case 11 : color = texture(u_Textures[11], TexCoord) * MultiplyColor; break;
        case 12 : color = texture(u_Textures[12], TexCoord) * MultiplyColor; break;
        case 13 : color = texture(u_Textures[13], TexCoord) * MultiplyColor; break;
        case 14 : color = texture(u_Textures[14], TexCoord) * MultiplyColor; break;
        case 15 : color = texture(u_Textures[15], TexCoord) * MultiplyColor; break;
        case 16 : color = texture(u_Textures[16], TexCoord) * MultiplyColor; break;
        case 17 : color = texture(u_Textures[17], TexCoord) * MultiplyColor; break;
        case 18 : color = texture(u_Textures[18], TexCoord) * MultiplyColor; break;
        case 19 : color = texture(u_Textures[19], TexCoord) * MultiplyColor; break;
        case 20 : color = texture(u_Textures[20], TexCoord) * MultiplyColor; break;
        case 21 : color = texture(u_Textures[21], TexCoord) * MultiplyColor; break;
        case 22 : color = texture(u_Textures[22], TexCoord) * MultiplyColor; break;
        case 23 : color = texture(u_Textures[23], TexCoord) * MultiplyColor; break;
        case 24 : color = texture(u_Textures[24], TexCoord) * MultiplyColor; break;
        case 25 : color = texture(u_Textures[25], TexCoord) * MultiplyColor; break;
        case 26 : color = texture(u_Textures[26], TexCoord) * MultiplyColor; break;
        case 27 : color = texture(u_Textures[27], TexCoord) * MultiplyColor; break;
        case 28 : color = texture(u_Textures[28], TexCoord) * MultiplyColor; break;
        case 29 : color = texture(u_Textures[29], TexCoord) * MultiplyColor; break;
        case 30 : color = texture(u_Textures[30], TexCoord) * MultiplyColor; break;
        case 31 : color = texture(u_Textures[31], TexCoord) * MultiplyColor; break;
        default : color = MultiplyColor; break;
    }
}

这是 glInfoLog :

ERROR: 0:19: 'u_Textures' : undeclared identifier 
ERROR: 0:19: 'u_Textures' :  left of '[' is not of type array, matrix, or vector  
ERROR: 0:19: 'texture' : no matching overloaded function found (using implicit conversion) 
ERROR: 0:20: 'u_Textures' :  left of '[' is not of type array, matrix, or vector  
ERROR: 0:20: 'texture' : no matching overloaded function found (using implicit conversion) 
ERROR: 0:21: 'u_Textures' :  left of '[' is not of type array, matrix, o

我还验证了传递给 GLSL 编译器的实际字符串,但没有区别。

我真的不确定问题是什么。

标签: c++openglglslshader

解决方案


Intel HD 4000 显卡最多仅支持 16 个纹理插槽或单元。您正在接收大小为 32 的 sampler2D 数组。大于 16。如果您将数组大小更改为 16 并注释掉多余的情况,它将起作用。这是更新的着色器代码:

#version 330 core
in vec2 TexCoord;

// I am using a batch rendering method. The "TexElement" is the slot to which the texture is bound to
in flat int TexElement;

// Color to multiply with the texture color also called tint
in flat vec4 MultiplyColor;

// Outputted color
out vec4 color;

uniform sampler2D u_Textures[16];

void main()
{
    switch (TexElement)
    {
        case 0 : color = texture(u_Textures[0], TexCoord) * MultiplyColor; break;
        case 1 : color = texture(u_Textures[1], TexCoord) * MultiplyColor; break;
        case 2 : color = texture(u_Textures[2], TexCoord) * MultiplyColor; break;
        case 3 : color = texture(u_Textures[3], TexCoord) * MultiplyColor; break;
        case 4 : color = texture(u_Textures[4], TexCoord) * MultiplyColor; break;
        case 5 : color = texture(u_Textures[5], TexCoord) * MultiplyColor; break;
        case 6 : color = texture(u_Textures[6], TexCoord) * MultiplyColor; break;
        case 7 : color = texture(u_Textures[7], TexCoord) * MultiplyColor; break;
        case 8 : color = texture(u_Textures[8], TexCoord) * MultiplyColor; break;
        case 9 : color = texture(u_Textures[9], TexCoord) * MultiplyColor; break;
        case 10 : color = texture(u_Textures[10], TexCoord) * MultiplyColor; break;
        case 11 : color = texture(u_Textures[11], TexCoord) * MultiplyColor; break;
        case 12 : color = texture(u_Textures[12], TexCoord) * MultiplyColor; break;
        case 13 : color = texture(u_Textures[13], TexCoord) * MultiplyColor; break;
        case 14 : color = texture(u_Textures[14], TexCoord) * MultiplyColor; break;
        case 15 : color = texture(u_Textures[15], TexCoord) * MultiplyColor; break;
        default : color = MultiplyColor; break;
    }
}

谢谢!


推荐阅读