OpenGL片段着色器未在Intel HD 4000图形上编译

问题描述 投票:2回答:1

此着色器在我的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++ opengl glsl shader
1个回答
2
投票

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;
    }
}

谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.