gpt4 book ai didi

c++ - 'texture2D' : function is removed in Forward Compatibile context

转载 作者:搜寻专家 更新时间:2023-10-31 00:10:04 25 4
gpt4 key购买 nike

我正在尝试使用 GLSL 实现 5x5 卷积滤波器(查找边),这是我的 .glsl 源代码:

#version 150
#define SIZE 25

// A texture is expected
uniform sampler2D Texture;

// The vertex shader fill feed this input
in vec2 FragTexCoord;

// The final color
out vec4 FragmentColor;

float matr[25];
float matg[25];
float matb[25];

vec4 get_pixel(in vec2 coords, in float x, in float y) {
return texture2D(Texture, coords + vec2(x, y));
}

float convolve(in float[SIZE] kernel, in float[SIZE] matrix) {
float res = 0.0;
for (int i = 0; i < 25; i++)
res += kernel[i] * matrix[i];
return clamp(res, 0.0, 1.0);
}

void fill_matrix() {
float dxtex = 1.0 / float(textureSize(Texture, 0));
float dytex = 1.0 / float(textureSize(Texture, 0));
float[25] mat;
for (int i = 0; i < 5; i++)
for(int j = 0; j < 5; j++) {
vec4 pixel = get_pixel(FragTexCoord,float(i - 2) * dxtex, float(j - 2) * dytex);
matr[i * 5 + j] = pixel[0];
matg[i * 5 + j] = pixel[1];
matb[i * 5 + j] = pixel[2];
}
}

void main() {

float[SIZE] ker_edge_detection = float[SIZE] (
.0,.0, -1., .0, .0,
.0, .0,-1., .0, .0,
.0, .0, 4., .0, .0,
.0, .0, -1., .0,.0,
.0, .0, -1., .0, .0
);

fill_matrix();

FragmentColor = vec4(convolve(ker_edge_detection,matr), convolve(ker_edge_detection,matg), convolve(ker_edge_detection,matb), 1.0);
}

当我运行我的代码时出现错误:

Error Compiling Fragment Shader ...
ERROR: 0:17: 'texture2D' : function is removed in Forward Compatibile context
ERROR: 0:17: 'texture2D' : no matching overloaded function found (using implicit conversion)


Error Linking Shader Program ...
Attached fragment shader is not compiled.

Function is removed in Forward Compatibile context

奇怪的是,当我尝试在其他 Linux 和 Windows 机器上运行代码时,它运行良好。此外,当我在 get_pixel() 函数中更改 texture2D 以返回 texture 时,它就像一个魅力。谁能解释一下哪里出了问题?

最佳答案

该错误说明了您需要知道的一切。 texture2D 是 GLSL 1.00 时代的一个旧函数。它已被删除并替换为 texture,它使用函数重载来处理大多数采样器类型,而不是仅限于 sampler2D。因此,在核心配置文件或向前兼容上下文中,您不能调用 texture2D

关于c++ - 'texture2D' : function is removed in Forward Compatibile context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40095192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com